import { useSyncExternalStore } from "react"; import { checkoutUrl, clear, count, load, remove, server, setQty, subscribe, total } from "../lib/cart.ts"; import { designOf, GIFT_PREFIX, lineUrl, money } from "../lib/shop.ts"; import { Icon } from "../components/Icon.jsx"; function Line({ item }) { const href = lineUrl(item.key); return (
{item.key.startsWith(GIFT_PREFIX) ? item.title : `${item.title} (${designOf(item.key)})`}

{`${item.size} · ${money(item.price)}`}

{item.qty}

{money(Number(item.price) * item.qty)}

); } export function Cart() { const items = useSyncExternalStore(subscribe, load, server); const n = count(items); return (

Bag

{items.map((item) => ( ))}
{items.length ? (

{`${n} item${n === 1 ? "" : "s"} · ${money(total(items))}`}

Checkout Continue shopping
) : (

Your bag is empty.

Browse the shop
)}
); }