import{a as e,n as t,t as n}from"./jsx-runtime-B-hcVAMW.js";import{r}from"./api-Duu96wkE.js";import{E as i,j as a}from"./index-DyQEyT-0.js";import{t as o}from"./Badge-BGqYAYKM.js";import{t as s}from"./ErrorState-BkSpMSl3.js";import{t as c}from"./statusTones-pNiETXbA.js";import{a as l,r as u}from"./hooks-C59jCzc-2.js";var d=e(t(),1),f=n();function p(){let{data:e,isPending:t,error:n,refetch:r}=u(),[a,o]=(0,d.useState)(null);if(t)return(0,f.jsx)(i,{label:`Loading your documents`});if(n)return(0,f.jsx)(s,{error:n,onRetry:()=>r()});let c=e.filter(e=>e.needs_action),l=e.filter(e=>!e.needs_action);return(0,f.jsxs)(`div`,{className:`space-y-6`,children:[(0,f.jsxs)(`header`,{children:[(0,f.jsx)(`h1`,{className:`text-lg font-semibold text-slate-900`,children:`My documents`}),(0,f.jsx)(`p`,{className:`mt-1 text-sm text-slate-600`,children:`Upload clear photos or scans. Our team checks each one before it is accepted.`})]}),c.length>0&&(0,f.jsxs)(`section`,{className:`space-y-3`,children:[(0,f.jsx)(`h2`,{className:`text-sm font-semibold text-slate-900`,children:`Needs your attention`}),c.map(e=>(0,f.jsx)(m,{item:e,onUpload:o},e.document_type.name))]}),l.length>0&&(0,f.jsxs)(`section`,{className:`space-y-3`,children:[(0,f.jsx)(`h2`,{className:`text-sm font-semibold text-slate-900`,children:`Submitted`}),l.map(e=>(0,f.jsx)(m,{item:e,onUpload:o},e.document_type.name))]}),e.length===0&&(0,f.jsx)(`p`,{className:`rounded-2xl bg-white p-5 text-sm text-slate-600 shadow-sm ring-1 ring-slate-200`,children:`No documents have been requested yet. We will let you know when something is needed.`}),a&&(0,f.jsx)(h,{item:a,onClose:()=>o(null)})]})}function m({item:e,onUpload:t}){return(0,f.jsxs)(`article`,{className:`space-y-3 rounded-2xl bg-white p-4 shadow-sm ring-1 ring-slate-200`,children:[(0,f.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,f.jsxs)(`div`,{className:`min-w-0`,children:[(0,f.jsx)(`h3`,{className:`text-sm font-medium text-slate-900`,children:e.document_type.name}),(0,f.jsxs)(`p`,{className:`text-xs text-slate-500`,children:[e.is_mandatory?`Required`:`Optional`,` · `,e.document_type.category_label]})]}),(0,f.jsx)(o,{tone:c[e.status]??`neutral`,children:e.status_label})]}),e.rejection_reason&&(0,f.jsx)(`p`,{className:`rounded-lg bg-amber-50 p-3 text-sm text-amber-900`,children:e.rejection_reason}),e.expiring_soon&&(0,f.jsxs)(`p`,{className:`text-sm text-amber-700`,children:[`This expires on `,e.expiry_date,`. Please send an updated copy.`]}),e.needs_action&&(0,f.jsx)(a,{onClick:()=>t(e),children:e.uploaded_at?`Upload again`:`Upload`})]})}function h({item:e,onClose:t}){let n=l(),[i,o]=(0,d.useState)(null),[c,u]=(0,d.useState)(null);return(0,f.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-end justify-center bg-slate-900/40 p-0 sm:items-center sm:p-4`,children:(0,f.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":`portal-upload-title`,className:`w-full max-w-md rounded-t-2xl bg-white p-5 shadow-xl sm:rounded-2xl`,children:[(0,f.jsxs)(`h2`,{id:`portal-upload-title`,className:`text-base font-semibold text-slate-900`,children:[`Upload `,e.document_type.name]}),(0,f.jsx)(`p`,{className:`mt-1 text-sm text-slate-600`,children:`Make sure the whole document is visible and the text is readable.`}),(0,f.jsxs)(`form`,{onSubmit:async a=>{if(a.preventDefault(),!i||!e.document_type.id)return;u(null);let o=new FormData;o.append(`document_type_id`,e.document_type.id),o.append(`file`,i);try{await n.mutateAsync(o),t()}catch(e){let t=r(e);u(t.fieldError(`file`)??t.message)}},className:`mt-4 space-y-4`,children:[c&&(0,f.jsx)(s,{error:Error(c)}),(0,f.jsx)(`input`,{type:`file`,required:!0,accept:`image/*,application/pdf`,capture:`environment`,onChange:e=>o(e.target.files?.[0]??null),className:`block w-full rounded-lg text-sm text-slate-700 file:mr-3 file:rounded-lg file:border-0 file:bg-slate-100 file:px-3 file:py-2 file:text-sm file:font-medium`}),(0,f.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,f.jsx)(a,{type:`button`,variant:`secondary`,onClick:t,children:`Cancel`}),(0,f.jsx)(a,{type:`submit`,loading:n.isPending,disabled:!i,children:`Send`})]})]})]})})}export{p as default};