"use client"; import { useId } from "react"; import { useDerived, useSnap } from "@/lib/client"; import { Icon, Kbd, Panel, QtyStepper, Seg, Tag } from "@/components/portal"; import { ccOf, genderLabel, groupsLabel, key, label, money, onhand, plOf, setHalf, type StaffRec } from "@/lib/compute"; import { plural, pronoun, sizeOf, type Source } from "./lib"; import type { CounterCart } from "./useCounterCart"; import styles from "./counter.module.css"; export default function PickupCart({ st, cart: c, mac, onRecord }: { st: StaffRec; cart: CounterCart; mac: boolean; onRecord: () => void }) { const { s } = useSnap(); const { L, byId } = useDerived(); const reasonsId = useId(); const pr = pronoun(st); const cap = c.cap; const costCentre = ccOf(s, st); const apClause = c.apN > 0 ? (c.apN === c.apRem ? ` · uses the last ${c.apN} signed` : ` · uses ${c.apN} signed`) : ""; return ( {c.cart.length === 0 &&
Scan, type or tap a usual to add garments.
} {c.cart.length > 0 && (
{c.cart.map((line, i) => { const it = byId[line.itemId]; const size = sizeOf(it, line.si); const k = key(line.itemId, line.si); const oh = onhand(s, L, k), pl = plOf(s, k); const opts: Source[] = pl > 0 || line.src === "preloved" ? ["stock", "preloved", "order"] : ["stock", "order"]; const half = setHalf(it); const want = half === "top" ? st.top : half === "pants" ? st.pants : ""; const offUsual = !!want && !!it && it.sizes.map(String).includes(String(want)) && size !== String(want); const shortShelf = line.src === "stock" && line.qty > oh; const shortPool = line.src === "preloved" && line.qty > pl; return (
{label(it)} · {size}
size="sm" label={`Where ${label(it)} ${size} comes from`} opts={opts} value={(line.src ?? "") as Source} onChange={(v) => c.setLine(i, { src: v })} labels={{ stock: <>Shelf {oh}, preloved: <>Pre-loved {pl}, order: "Order in", }} /> {line.src === null && Pick a source} {shortShelf && Not enough on the shelf} {shortPool && Not enough pre-loved}
{offUsual &&
Usual size {want}
}
c.setQty(i, n)} />
{money(line.src === "preloved" ? 0 : line.qty * (it?.cost || 0))}
); })}
)} {c.cart.length > 0 && cap && (
{c.needsTick ?
{c.needsTick && ( <>
{c.overCap && (
{cap.breach === "other" ? `Past ${cap.otherCap} garments outside a set — holds ${cap.afterOther}` : `Past ${cap.cap} sets — holds ${cap.afterTops} tops and ${cap.afterPants} pairs`}
)} {c.offItems.map((it) =>
{it.item} is for {groupsLabel(it.groups)}
)} {c.offStyleItems.map((it) =>
{it.item} is the {genderLabel(it.gender)} cut
)}
)} {c.ap && (
Sets off the signed form c.setApDeduct(n)} /> {c.apRem} left
)}
)}
Charged to {costCentre || "no cost centre"}
{money(c.cartVal)}
{c.inactive &&
Inactive on the register: reactivate to issue
}
); }