import { redirect } from "next/navigation"; import { currentUser } from "@/lib/session"; import { prisma } from "@/lib/db"; import AutoPrint from "@/components/AutoPrint"; export const dynamic = "force-dynamic"; type SP = Record; const lb: React.CSSProperties = { fontSize: 10, fontWeight: 600, letterSpacing: ".08em", textTransform: "uppercase" }; const val = (big?: boolean): React.CSSProperties => ({ borderBottom: big ? "2px solid #201e1d" : "1.5px solid #201e1d", minHeight: big ? 30 : 24, fontSize: big ? 17 : 13, fontWeight: big ? 700 : 600, padding: "2px 2px 0", display: "flex", alignItems: "flex-end" }); const F = ({ label, v, big }: { label: string; v?: string; big?: boolean }) => (
{label}
{v || " "}
); const CB = ({ label, on }: { label: string; on: boolean }) => ( {on ? "✕" : " "} {label} ); export default async function PrintPage({ searchParams }: { searchParams: Promise }) { const user = await currentUser(); if (!user) redirect("/auth"); const fac = await prisma.facility.findUniqueOrThrow({ where: { id: user.facilityId } }); const q = await searchParams; const type = q.type === "delivery" ? "delivery" : "collection"; const copies = Math.min(3, Math.max(1, parseInt(q.copies || "1", 10) || 1)); const org = fac.slipOrg || fac.name; /* What is actually in the bag, one garment to a line. * * A ward request now covers several garments under one code, so a slip that only carried a total * would be signed for without anybody being able to check it. The caller passes the approved * lines already worded ("2 × Tunic — 16"), newline separated; the counter's own issue slip passes * nothing and the block simply doesn't appear. Capped so a very long request can't push the * signature block off the page — the number is still printed in full beside it. */ const garments = String(q.lines || "").split("\n").map((l) => l.trim()).filter(Boolean); const shown = garments.slice(0, 10); const spilled = garments.length - shown.length; const title = type === "delivery" ? "Uniform ward delivery" : "Uniform ready for collection"; const foot = type === "delivery" ? fac.slipDeliveryFooter : fac.slipCollectionFooter; const Slip = () => (
{title}
{fac.logoData ? {org} :
{org}
}
{/* One code, one bag. It sits beside the name because that is the pair the counter matches. */} {q.code && }
{shown.length > 0 && (
Garments — tick each one as it goes in the bag
4 ? "1fr 1fr" : "1fr", columnGap: 18, rowGap: 3 }}> {shown.map((g, i) =>
)}
{spilled > 0 &&
+{spilled} more line{spilled === 1 ? "" : "s"} — see the request in ThreadCount.
}
)} {type === "delivery" ? ( <>
) : ( <>
Staff notified
Date notified
{q.dateNotified || " "}
)}
{foot}
); return (
{title}Print preview — use your browser's print dialog if it didn't open.
{Array.from({ length: copies }).map((_, i) => (
{i > 0 &&
}
))}
); }