"use client"; import Link from "next/link"; import { useMemo, useState } from "react"; import { useSnap } from "@/lib/client"; import { Meter, Panel } from "@/components/portal"; import { heldByStaff, setsCap } from "@/lib/compute"; import styles from "./counter.module.css"; /* No person chosen yet: find one by name or staff number (a badge scan types the number). */ export default function PersonPicker({ onPick }: { onPick: (id: string) => void }) { const { s } = useSnap(); const [q, setQ] = useState(""); // One walk of the issues for the whole register, not one per row. const held = useMemo(() => heldByStaff(s), [s]); const cap = setsCap(s.settings.capSets); const qq = q.trim().toLowerCase(); const active = s.staff.filter((st) => !st.inactive); const matches = active .filter((st) => !qq || `${st.first} ${st.last}`.toLowerCase().includes(qq) || `${st.last} ${st.first}`.toLowerCase().includes(qq) || st.num.toLowerCase().includes(qq)) .slice(0, 8); function onKey(e: React.KeyboardEvent) { if (e.key !== "Enter") return; const exact = qq ? s.staff.find((st) => st.num.toLowerCase() === qq) : undefined; const first = exact || matches[0]; if (first) { e.preventDefault(); onPick(first.id); } } return (
setQ(e.target.value)} onKeyDown={onKey} autoFocus />
{s.staff.length === 0 ? (
No staff on the register yet. Add staff
) : matches.length === 0 ? (
Nobody matches โ€œ{q.trim()}โ€.
) : (
{matches.map((st) => { const h = held[st.id] || { tops: 0, pants: 0, other: 0, sets: 0 }; return ( ); })}
)}
); }