1import{r as v,j as e,Y as Z,a9 as R}from"./vendor-CGb3fyhz.js";import{a as O,u as D}from"./tanstack-CQjmdu51.js";import{C as F,b as S,c as P,d as A,a as $}from"./card-B7H4po1A.js";import{u as E,B as h,D as T,d as B,e as _,f as q,g as H,X as W,Y as Q,Z as V,_ as U,H as X,G as J,c as I}from"./index-CEVAfBHH.js";import{S as b}from"./skeleton-CX_X8VfR.js";import{L as z,as as ee,h as Y,D as k,H as G,bZ as se,a0 as ae,cD as te,d as C,A as ne,aq as le,ae as M,aM as de}from"./lucide-Bd2YFRao.js";import"./radix-DKVS-WnT.js";function oe({loanId:d,loanNumber:s,variant:o="outline",size:p="default"}){const{toast:t}=E(),[u,n]=v.useState(!1),[i,y]=v.useState(""),w=O({mutationFn:async()=>{var N;const l=`/api/loans/${d}/examiner-binder/download`,a=await fetch(l,{credentials:"include"});if(!a.ok){const x=await a.json();throw new Error(x.error||"Failed to download Loan Lifecycle Record")}const j=a.headers.get("Content-Disposition"),c=((N=j==null?void 0:j.match(/filename="(.+)"/))==null?void 0:N[1])||`Loan_Lifecycle_Record_${s||d}.pdf`,g=await a.blob(),f=window.URL.createObjectURL(g),m=document.createElement("a");return m.href=f,m.download=c,document.body.appendChild(m),m.click(),document.body.removeChild(m),window.URL.revokeObjectURL(f),c},onSuccess:l=>{y(l),n(!0),t({title:"Download Complete",description:`Loan Lifecycle Record saved as ${l}`})},onError:l=>{t({title:"Download Failed",description:l.message,variant:"destructive"})}}),r=w.isPending;return e.jsxs(e.Fragment,{children:[e.jsxs(h,{variant:o,size:p,disabled:r,onClick:()=>w.mutate(),"data-testid":"button-download-examiner-binder",children:[r?e.jsx(z,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(ee,{className:"mr-2 h-4 w-4"}),r?"Generating...":"Loan Lifecycle Record"]}),e.jsx(T,{open:u,onOpenChange:n,children:e.jsxs(B,{children:[e.jsxs(_,{children:[e.jsxs(q,{className:"flex items-center gap-2",children:[e.jsx(Y,{className:"h-5 w-5 text-green-500"}),"Loan Lifecycle Record Ready"]}),e.jsx(H,{children:"Your complete system-of-record snapshot has been downloaded."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3 p-4 bg-muted rounded-lg",children:[e.jsx(k,{className:"h-8 w-8 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:i}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Complete loan management record from approval through close-out"})]})]}),e.jsxs("div",{className:"flex items-start gap-3 p-4 bg-primary/5 rounded-lg border border-primary/20",children:[e.jsx(G,{className:"h-5 w-5 text-primary mt-0.5"}),e.jsxs("div",{className:"text-sm",children:[e.jsx("p",{className:"font-medium text-primary",children:"Audit-Ready Package"}),e.jsx("p",{className:"text-muted-foreground",children:"A portable system-of-record snapshot showing every decision made throughout the loan lifecycle."})]})]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium mb-1",children:"LLR Contents:"}),e.jsxs("ul",{className:"list-disc list-inside space-y-1",children:[e.jsx("li",{children:"Loan Summary & Cover Page"}),e.jsx("li",{children:"Timeline of Activities"}),e.jsx("li",{children:"Draw Request History"}),e.jsx("li",{children:"Milestone Tracking"}),e.jsx("li",{children:"Vendor/Contractor Documentation"}),e.jsx("li",{children:"Lien Waiver Register"}),e.jsx("li",{children:"Disbursement Ledger"}),e.jsx("li",{children:"Document Audit Trail"}),e.jsx("li",{children:"Approval Workflow Records"})]})]}),e.jsx(h,{className:"w-full",onClick:()=>n(!1),"data-testid":"button-close-binder-success-dialog",children:"Done"})]})]})})]})}function ie({loanId:d,drawId:s,drawNumber:o,variant:p="outline",size:t="default"}){const{toast:u}=E(),[n,i]=v.useState(!1),[y,w]=v.useState(""),r=O({mutationFn:async a=>{var L;const j=s?`/api/draws/${s}/compliance-packet/download?format=${a}`:`/api/loans/${d}
1/compliance-packet/download?format=${a}`,c=await fetch(j,{credentials:"include"});if(!c.ok){const K=await c.json();throw new Error(K.error||"Failed to download compliance packet")}const g=c.headers.get("Content-Disposition"),f=((L=g==null?void 0:g.match(/filename="(.+)"/))==null?void 0:L[1])||`compliance_packet.${a}`,m=await c.blob(),N=window.URL.createObjectURL(m),x=document.createElement("a");return x.href=N,x.download=f,document.body.appendChild(x),x.click(),document.body.removeChild(x),window.URL.revokeObjectURL(N),f},onSuccess:a=>{w(a),i(!0),u({title:"Download Complete",description:`Compliance packet saved as ${a}`})},onError:a=>{u({title:"Download Failed",description:a.message,variant:"destructive"})}}),l=r.isPending;return e.jsxs(e.Fragment,{children:[e.jsxs(W,{children:[e.jsx(Q,{asChild:!0,children:e.jsxs(h,{variant:p,size:t,disabled:l,"data-testid":"button-download-compliance-packet",children:[l?e.jsx(z,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(se,{className:"mr-2 h-4 w-4"}),l?"Preparing...":"Compliance Packet",e.jsx(ae,{className:"ml-2 h-4 w-4"})]})}),e.jsxs(V,{align:"end",children:[e.jsxs(U,{onClick:()=>r.mutate("zip"),disabled:l,"data-testid":"menu-item-download-zip",children:[e.jsx(te,{className:"mr-2 h-4 w-4"}),"Download as ZIP",e.jsx("span",{className:"ml-auto text-xs text-muted-foreground",children:"All PDFs"})]}),e.jsxs(U,{onClick:()=>r.mutate("pdf"),disabled:l,"data-testid":"menu-item-download-pdf",children:[e.jsx(C,{className:"mr-2 h-4 w-4"}),"Download Cover Sheet",e.jsx("span",{className:"ml-auto text-xs text-muted-foreground",children:"Summary"})]})]})]}),e.jsx(T,{open:n,onOpenChange:i,children:e.jsxs(B,{children:[e.jsxs(_,{children:[e.jsxs(q,{className:"flex items-center gap-2",children:[e.jsx(Y,{className:"h-5 w-5 text-green-500"}),"Download Complete"]}),e.jsx(H,{children:"Your compliance packet has been downloaded successfully."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3 p-4 bg-muted rounded-lg",children:[e.jsx(k,{className:"h-8 w-8 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:y}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s?`Draw #${o||"N/A"} compliance packet`:"Full loan compliance packet"})]})]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium mb-1",children:"Package Contents:"}),e.jsxs("ul",{className:"list-disc list-inside space-y-1",children:[e.jsx("li",{children:"Cover sheet with summary"}),e.jsx("li",{children:"All signed lien waivers (PDF)"}),e.jsx("li",{children:"Manifest file with details"})]})]}),e.jsx(h,{className:"w-full",onClick:()=>i(!1),"data-testid":"button-close-success-dialog",children:"Done"})]})]})})]})}function je(){const[,d]=Z("/loans/:id/documents"),s=d==null?void 0:d.id,{data:o,isLoading:p}=D({queryKey:["/api/loans",s],enabled:!!s}),{data:t,isLoading:u}=D({queryKey:["/api/loans",s,"master-plan"],enabled:!!s}),{data:n}=D({queryKey:["/api/auth/user"]}),i=(n==null?void 0:n.role)==="loan_originator"?"lender":(n==null?void 0:n.role)||"lender";return p?e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsx(b,{className:"h-8 w-64"}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsx(b,{className:"h-64 w-full"}),e.jsx(b,{className:"h-64 w-full"})]})]}):o?e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(R,{href:`/loans/${s}`,children:e.jsx(h,{variant:"ghost",size:"icon","data-testid":"button-back-to-loan",children:e.jsx(ne,{className:"h-4 w-4"})})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold","data-testid":"text-page-title",children:"Documents"}),e.jsxs("p",{className:"text-muted-foreground",children:["Loan #",o.loanNumber||(s==null?void 0:s.slice(0,8))]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsx("div",{className:"space-y-4","data-testid":"section-uploaded-documents",children:e.jsxs(F,{children:[e.jsxs(S,{className:"pb-3",children:[e.jsxs(P,{className:"flex items-center gap-2 text-lg",children:[e.jsx(le,{className:"h-5 w-5"}),"Uploaded Documents"]}),e.jsx(A,{children:"Documents uploaded to this loan"})]}),e.jsxs($,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h4",{className:"text-sm font-medium text-muted-foreground flex items-center gap-2",children:[e.jsx(C,{className:"h-4 w-4"}),"Master Project Plan"]}),u?e.jsx(b,{className:"h-16 w-full"}):t?e.jsxs("div",{className:"flex items-center justify-between gap-3 p-3 border rounded-lg bg-muted/30 hover-elevate",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10 shrink-0",children:e.jsx(C,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-medium text-sm truncate","data-testid":"text-plan-filename",children:t.fileName}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[X(t.createdAt),t.totalBudget&&` ⢠${J(t.totalBudget)}`]})]})]}),e.jsx(I,{variant:t.status==="approved"?"default":"secondary",className:"shrink-0 text-xs","data-testid":"badge-plan-status",children:t.status.replace("_"," ").toUpperCase()})]}):e.jsxs("div",{className:"p-4 border-2 border-dashed rounded-lg text-center",children:[e.jsx(M,{className:"h-6 w-6 mx-auto mb-2 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No project plan uploaded"}),e.jsx(R,{href:`/loans/${s}`,children:e.jsxs(h,{variant:"outline",size:"sm",className:"mt-2",children:[e.jsx(M,{className:"h-3 w-3 mr-1"}),"Upload from Overview"]})})]})]}),e.jsxs("div",{className:"pt-4 border-t",children:[e.jsx("h4",{className:"text-sm font-medium text-muted-foreground mb-3",children:"Other Documents"}),e.jsxs("div",{className:"p-4 border-2 border-dashed rounded-lg text-center text-muted-foreground",children:[e.jsx("p",{className:"text-sm",children:"Additional document uploads coming soon"}),e.jsx("p",{className:"text-xs mt-1",children:"Insurance, permits, contracts, etc."})]})]})]})]})}),i==="lender"&&s&&e.jsx("div",{className:"space-y-4","data-testid":"section-regulatory-documents",children:e.jsxs(F,{children:[e.jsxs(S,{className:"pb-3",children:[e.jsxs(P,{className:"flex items-center gap-2 text-lg",children:[e.jsx(G,{className:"h-5 w-5"}),"Regulatory Documents"]}),e.jsx(A,{children:"Generate audit-ready documentation for examiners"})]}),e.jsxs($,{className:"space-y-4",children:[e.jsxs("div",{className:"p-4 border rounded-lg space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-blue-100 dar
1k:bg-blue-900/30 shrink-0",children:e.jsx(de,{className:"h-4 w-4 text-blue-600 dark:text-blue-400"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h4",{className:"font-medium text-sm",children:"Loan Lifecycle Record (LLR)"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Complete system-of-record snapshot showing how this loan was managed, decision-by-decision"})]})]}),e.jsx(oe,{loanId:s,loanNumber:o.loanNumber||void 0})]}),e.jsxs("div",{className:"p-4 border rounded-lg space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-green-100 dark:bg-green-900/30 shrink-0",children:e.jsx(k,{className:"h-4 w-4 text-green-600 dark:text-green-400"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h4",{className:"font-medium text-sm",children:"Compliance Packet"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Lien waivers and compliance documentation bundle"})]})]}),e.jsx(ie,{loanId:s})]}),e.jsx("div",{className:"pt-3 border-t",children:e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:"Documents are generated in real-time with the latest loan data"})})]})]})})]})]}):e.jsx("div",{className:"p-6",children:e.jsx("p",{className:"text-muted-foreground",children:"Loan not found"})})}export{je as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.