import { requireOperator } from "@/lib/ops/session"; import { facilities } from "@/lib/ops/projections"; /* Every facility: counts, dates, state. No customer records are reachable from this screen, and * no contact appears on it at all — a reveal is a separate, trailed act on the facility's own page. */ export const dynamic = "force-dynamic"; const PILL: Record = { live: { text: "Live", color: "#2f6b4f" }, dormant: { text: "Dormant", color: "var(--color-neutral-600)" }, unconfigured: { text: "Never set up", color: "var(--color-neutral-600)" }, demo: { text: "Demo", color: "var(--color-neutral-600)" }, }; function Pill({ state }: { state: string }) { const p = PILL[state] || PILL.dormant; return {p.text}; } export default async function OpsFacilities() { await requireOperator(); const rows = await facilities(); const real = rows.filter((f) => !f.isDemo); const demo = rows.filter((f) => f.isDemo); const fmt = (d: Date) => d.toLocaleDateString("en-AU", { day: "numeric", month: "short" }); const n = (x: number) => x.toLocaleString(); const th = (t: string, right = false) => {t}; const td = (c: React.ReactNode, right = false) => {c}; return ( <>
Facilities

Every facility

Counts and dates only. No customer records are reachable from this screen.
{real.length} facilities{demo.length ? "demo shown last" : "no demo facility"}
{th("Facility")}{th("State")}{th("Plan")}{th("Created")}{th("Users", true)}{th("Staff", true)}{th("Items", true)}{th("Issues", true)}{th("Requests", true)}{th("rev", true)}{th("Backup")} {[...real, ...demo].map((f) => ( {td({f.name})} {td()} {td(f.isDemo ? "—" : ( {f.planView.grandfathered ? `${f.planView.label} · grandfathered` : `${f.planView.label} · ${f.planView.state.replace("_", "-")}`} ))} {td(f.isDemo ? "—" : fmt(f.createdAt))} {td(n(f.users), true)}{td(n(f.staff), true)}{td(n(f.items), true)}{td(n(f.issues), true)}{td(n(f.requests), true)}{td(f.isDemo ? "—" : n(f.rev), true)} {td(f.isDemo ? "—" : f.backupAgeDays === null ? never : f.backupAgeDays > 7 ? {f.backupAgeDays}d : `${f.backupAgeDays}d`)} ))} {rows.length === 0 && {td("No facilities yet.")}}
); }