"use client"; import { useEffect, useRef, useState } from "react"; import { X, Pencil, Upload, ExternalLink, FileText } from "lucide-react"; import { api, apiBase } from "@/lib/api"; function imgSrc(url?: string) { if (!url) return ""; if (url.startsWith("data:") || url.startsWith("http")) return url; return `${apiBase}${url}`; } type Tab = "overview" | "documents" | "history"; const STATUS: Record = { complete: "bg-emerald-50 text-emerald-700", pending: "bg-amber-50 text-amber-700", expiring: "bg-amber-50 text-amber-700", expired: "bg-rose-50 text-rose-700", }; export default function ComplianceDetailModal({ cid, onClose, onEdit, onChanged }: { cid: string; onClose: () => void; onEdit: () => void; onChanged: () => void; }) { const [d, setD] = useState(null); const [tab, setTab] = useState("overview"); const fileRef = useRef(null); function load() { api(`/compliance/${cid}/detail`).then(setD).catch(() => {}); } useEffect(() => { load(); }, [cid]); async function onUpload(e: React.ChangeEvent) { const file = e.target.files?.[0]; if (!file) return; const r = new FileReader(); r.onload = async () => { await api(`/compliance/${cid}/document`, { method: "POST", body: JSON.stringify({ data_url: r.result, filename: file.name }), }); load(); onChanged(); }; r.readAsDataURL(file); } if (!d) return (
e.stopPropagation()}>
); const expColor = d.days_left != null && d.days_left < 0 ? "text-rose-600" : d.days_left != null && d.days_left < 30 ? "text-amber-600" : "text-slate-700"; return (
e.stopPropagation()}>

Compliance Details

{d.product_image ? :
}
{d.product_name ?? "—"}
SKU: {d.sku ?? "—"}
{d.status}
{([["overview", "Overview"], ["documents", `Documents (${d.documents?.length ?? 0})`], ["history", "History"]] as const).map(([t, l]) => ( ))}
{tab === "overview" && (
Expiry Date {fmt(d.expiry_date)} {d.days_left != null && {d.days_left < 0 ? "(Expired)" : `(In ${d.days_left} days)`} }
)} {tab === "documents" && (
{(d.documents ?? []).map((doc: any, i: number) => ( {doc.name} ))} {(!d.documents || d.documents.length === 0) &&

No documents uploaded.

}
)} {tab === "history" && (
{(d.history ?? []).map((h: any, i: number) => (
{h.action} {h.by ? `· ${h.by}` : ""} {fmt(h.at, true)}
))}
)}
e.preventDefault()} className="flex items-center justify-center gap-1 border border-brand-200 text-brand-700 rounded-lg py-2 text-sm font-medium"> View on Verification Page
); } function fmt(d?: string, time = false) { if (!d) return "—"; const dt = new Date(d); return isNaN(+dt) ? "—" : time ? dt.toLocaleString() : dt.toLocaleDateString(); } function Row({ label, value, cap }: any) { return (
{label} {value ?? "—"}
); }