"use client"; import Link from "next/link"; import { useMemo, useState } from "react"; import { Empty, Field } from "@/components/ui"; import type { StaffRec } from "@/lib/compute"; import { fullName, type Act } from "./shared"; /* Who this person approves for: the Manager arrow drawn from the manager's end. Adding somebody here * rewrites THEIR record, so the confirm card names that person and the manager they leave first. */ export default function ReportsBox({ subject, reports, people, isAdmin, act }: { subject: StaffRec; reports: StaffRec[]; people: StaffRec[]; isAdmin: boolean; act: Act }) { const [q, setQ] = useState(""); const [pick, setPick] = useState(null); const needle = q.trim().toLowerCase(); const matches = useMemo(() => { if (!needle) return []; return people.filter((x) => !x.inactive && x.id !== subject.id && x.managerId !== subject.id && (`${x.first} ${x.last}`.toLowerCase().includes(needle) || x.num.toLowerCase().includes(needle))).slice(0, 8); }, [people, subject.id, needle]); const from = pick ? people.find((x) => x.id === pick.managerId) : undefined; return (
{reports.length === 0 ?
Nobody reports to {subject.first || "them"} yet.
: (
{reports.map((x) => (
{fullName(x)}{x.id === subject.id ? " (themselves)" : ""} {[x.num, x.dept].filter(Boolean).join(" · ") || "–"} {isAdmin && ( )}
))}
)} {isAdmin && (
{subject.inactive ? (
Reactivate {subject.first} to give them reports.
) : pick ? (
Send {fullName(pick)}’s requests to {fullName(subject)}{from ? <> instead of {fullName(from)} : null}?
) : ( <> {(c) => setQ(e.target.value)} />} {needle !== "" && (
{matches.map((x) => ( ))} {matches.length === 0 &&
Nobody else on the register matches that.
}
)} )}
)}
); }