"use client"; import Link from "next/link"; import { Fragment } from "react"; import { useSnap } from "@/lib/client"; import { Meter, Tag } from "@/components/portal"; import { allowanceRouteOf, capCheck, ccOf, fmtDate, type StaffRec } from "@/lib/compute"; import { fullName, pl } from "./shared"; const dot = (parts: React.ReactNode[]) => parts.map((p, i) => {i > 0 && " · "}{p}); export default function Summary({ st, editHref }: { st: StaffRec; editHref: string }) { const { s, isAdmin } = useSnap(); /* The counter's own question, so the meters and the counter never quote two figures. */ const held = capCheck(s, st); const owed = held.owed.tops + held.owed.pants + held.owed.other; const route = allowanceRouteOf(s, st); const cc = ccOf(s, st); const details: React.ReactNode[] = []; if (st.group) details.push(st.group); if (st.dept) details.push(st.dept); if (cc) details.push({cc}); if (st.uniformStyle) details.push(`${st.uniformStyle.replace("'", "’")} cut`); if (st.top || st.pants) details.push(<>{st.top || "–"} / {st.pants || "–"}); if (route === "fte" && st.fte) details.push(<>FTE {st.fte}); if (st.start) details.push(`started ${fmtDate(st.start)}`); const reports = s.staff.filter((x) => x.managerId === st.id && !x.inactive); const mgr = st.managerId ? s.staff.find((x) => x.id === st.managerId) : undefined; const people: React.ReactNode[] = []; if (reports.length) { people.push(<>Approves requests for {pl(reports.length, "person", "people")}{st.dept && <> on {st.dept}}); } if (mgr) { people.push(<>Manager {fullName(mgr)}{mgr.id === st.id && <> Self-approved}{mgr.inactive && <> Inactive}); } if (st.phone) people.push({st.phone}); return (

{fullName(st)}

{st.num} {st.selfEmail && Staff app} {st.wardDesk && {st.dept ? `Ward desk · ${st.dept}` : "Ward desk"}} {st.inactive && Inactive}
{details.length > 0 &&
{dot(details)}
} {people.length > 0 &&
{dot(people)}
}
{held.other > 0 && } {owed > 0 &&
{owed} still on order or waiting
}
{!st.inactive && Open at the counter} {isAdmin && Edit details}
); }