"use client"; /* Count a shelf: every location holding garments, plus the unplaced bucket, each shelf with a shelf-label print chip. Mounted by app/m/(app)/count/page.tsx (a Stock detail, no tab bar). */ import { useMemo } from "react"; import { useDerived, useSnap } from "@/lib/client"; import { UNPLACED, daysBetween } from "@/lib/compute"; import { printShelfLabel } from "@/lib/nativeprint"; import { isNative } from "@/lib/nativescan"; import { INK, MBody, MEmpty, MRow, MRule, MSection, MTop, MTopCount, useToast } from "@/components/m"; import { countRows } from "@/components/m/stock/stockdata"; function lastCounted(last: string | undefined, today: string): string { if (!last) return "Never counted"; const n = daysBetween(last, today); if (n <= 0) return "Counted today"; if (n === 1) return "Counted yesterday"; return `Counted ${n} days ago`; } export default function CountList() { const { s } = useSnap(); const { L, variants } = useDerived(); const toast = useToast(); const rows = useMemo(() => countRows(s, L, variants), [s, L, variants]); const print = async (id: string, name: string) => { const r = await printShelfLabel({ locationId: id, copies: 1 }); if (!r.ok) toast(r.error); else if (isNative()) toast(`${name} label sent to the shelf printer`); }; const chip: React.CSSProperties = { minHeight: 44, minWidth: 64, padding: "0 12px", border: "2px solid " + INK, background: "transparent", color: INK, fontFamily: "inherit", fontSize: 13, fontWeight: 800, letterSpacing: "0.05em", textTransform: "uppercase", cursor: "pointer", flex: "none", }; return ( <> {rows.length}} /> {rows.length === 0 ? ( ) : ( <> {rows.map((r) => (
{r.name}} sub={{lastCounted(r.last, s.today)}} right={`${r.lines} · ${r.units}`} />
{r.id !== UNPLACED && ( )}
))} )}
); }