import{j as e}from"./ui-vendor-DUfjpZ4p.js";import{h as S,r as t,L as b}from"./react-vendor-DlVMRrtE.js";import{s as i,am as p,B as l,b4 as B,e as C,H as k,D as L,b7 as R,t as q}from"./index-BKwmLAPt.js";import{I as z}from"./ImporterReport-D9UG_J_9.js";import{P as A}from"./printer-CZ36GdKY.js";import"./charts-vendor-wgDUSDZK.js";import"./supabase-vendor-Bd7R0Yn5.js";const Q=()=>{const{id:a,type:f}=S(),o=f==="full"?"full":"basic",[u,c]=t.useState(!0),[r,x]=t.useState(null),[h,w]=t.useState({}),[g,j]=t.useState([]),[_,v]=t.useState([]),[m,d]=t.useState(!1),n=t.useRef(null),N=async()=>{if(!(!n.current||!r)){d(!0);try{const s=String(r.company_name||"importer").replace(/[^A-Za-z0-9]+/g,"_");await R(n.current,`ABTC_Importer_${s}_${o}.pdf`)}catch(s){console.error(s),q({title:"Download failed",description:(s==null?void 0:s.message)||"Could not generate PDF.",variant:"destructive"})}d(!1)}};return t.useEffect(()=>{a&&(async()=>{c(!0);const[{data:s},{data:y},{data:D},{data:P}]=await Promise.all([i.from("importer_profiles").select("*").eq("id",a).maybeSingle(),i.from("importer_verifications").select("*").eq("importer_profile_id",a).maybeSingle(),i.from("importer_officials").select("*").eq("importer_profile_id",a),i.from("importer_documents").select("id,document_type,file_name").eq("importer_profile_id",a)]);x(s),w(y||{}),j(D||[]),v(P||[]),c(!1)})()},[a]),u?e.jsxs("div",{className:"flex items-center gap-2 p-6 text-muted-foreground",children:[e.jsx(p,{className:"h-4 w-4 animate-spin"})," Loading report…"]}):r?e.jsxs("div",{className:"space-y-4 print:space-y-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 print:hidden",children:[e.jsx(l,{asChild:!0,variant:"ghost",size:"sm",children:e.jsxs(b,{to:`/portal/importer-network/admin/${a}`,children:[e.jsx(B,{className:"h-4 w-4 mr-1"})," Back to review"]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(C,{className:"bg-accent/20 text-accent border-accent/30 gap-1",children:[e.jsx(k,{className:"h-3 w-3"})," QA Preview · ",o==="full"?"Full Due Diligence":"Basic"]}),e.jsxs(l,{size:"sm",variant:"outline",onClick:()=>window.print(),children:[e.jsx(A,{className:"h-4 w-4 mr-1"})," Print"]}),e.jsxs(l,{size:"sm",onClick:N,disabled:m,className:"gap-1",children:[m?e.jsx(p,{className:"h-4 w-4 animate-spin"}):e.jsx(L,{className:"h-4 w-4"}),"Download PDF"]})]})]}),e.jsx("div",{ref:n,children:e.jsx(z,{profile:r,verif:h,officials:g,documents:_,reportType:o})})]}):e.jsx("div",{className:"p-6",children:"Profile not found."})};export{Q as default};
