"use client"; import { useMemo, useState } from "react"; import Link from "next/link"; import type { AssignmentStatus } from "@prisma/client"; import { Badge } from "@/components/ui/badge"; type CrewRow = { id: string; name: string; employeeId: string; rank: string; location: string; status: AssignmentStatus | null; }; const INPUT = "rounded-lg border border-neutral-300 px-3 py-2 text-sm focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20"; function StatusBadge({ status }: { status: AssignmentStatus | null }) { if (status === "ACTIVE") return Active; if (status === "ON_LEAVE") return On leave; return ; } export function CrewDirectory({ crew }: { crew: CrewRow[] }) { const [search, setSearch] = useState(""); const [location, setLocation] = useState("ALL"); const locations = useMemo( () => Array.from(new Set(crew.map((c) => c.location).filter((l) => l !== "—"))).sort(), [crew] ); const filtered = useMemo(() => { const q = search.trim().toLowerCase(); return crew.filter((c) => { if (location !== "ALL" && c.location !== location) return false; if (q && !`${c.name} ${c.employeeId} ${c.rank}`.toLowerCase().includes(q)) return false; return true; }); }, [crew, search, location]); return (

Crew

{crew.length} active crew member{crew.length === 1 ? "" : "s"}

setSearch(e.target.value)} />
{filtered.length === 0 ? ( ) : ( filtered.map((c) => ( )) )}
Name Employee Rank Vessel / site Status
{crew.length === 0 ? "No crew onboarded yet." : "No crew match these filters."}
{c.name} {c.employeeId} {c.rank} {c.location}
); }