import{a as g,r as n,j as e,d as b}from"./index-D4ZMoJFe.js";import{f as j}from"./formatters-jmx2pV9o.js";function y(){var u;const{selectedCompanyId:m,user:a}=g(),r=m||(a==null?void 0:a.companyId)||((u=a==null?void 0:a.company)==null?void 0:u.id)||"",[d,p]=n.useState([]),[h,o]=n.useState(!0),[i,x]=n.useState("");return n.useEffect(()=>{(async()=>{var c,t;if(r){o(!0),x("");try{const l=await b.get("/mgx/suppliers/schedule",{params:{company_id:r}});p(l.data.items||[])}catch(l){x(((t=(c=l==null?void 0:l.response)==null?void 0:c.data)==null?void 0:t.message)||"Impossible de charger l'échéancier fournisseurs.")}finally{o(!1)}}})()},[r]),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("section",{className:"card-panel p-6 sm:p-8",children:[e.jsx("p",{className:"text-xs uppercase tracking-[0.2em] text-gold",children:"MGX · Fournisseurs"}),e.jsx("h1",{className:"mt-3 text-3xl font-semibold text-text",children:"Échéancier fournisseurs"})]}),i?e.jsx("div",{className:"rounded-2xl border border-danger/20 bg-danger/5 p-4 text-sm text-danger",children:i}):null,e.jsx("section",{className:"table-shell overflow-x-auto",children:e.jsxs("table",{className:"min-w-[980px] w-full",children:[e.jsx("thead",{className:"table-head",children:e.jsx("tr",{children:["Date échéance","Fournisseur","Type","Référence","Montant","Statut"].map(s=>e.jsx("th",{className:"table-cell",children:s},s))})}),e.jsx("tbody",{children:h?e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"table-cell text-textMuted",children:"Chargement..."})}):d.length?d.map((s,c)=>{var t;return e.jsxs("tr",{className:`table-row ${s.is_overdue?"bg-danger/5":s.is_due_soon?"bg-gold/5":""}`,children:[e.jsx("td",{className:"table-cell",children:j(s.date_echeance)}),e.jsx("td",{className:"table-cell",children:((t=s.supplier)==null?void 0:t.name)||"—"}),e.jsx("td",{className:"table-cell",children:s.type}),e.jsx("td",{className:"table-cell font-mono",children:s.reference}),e.jsx("td",{className:"table-cell amount-cell font-semibold",children:s.outstanding_amount_formatted}),e.jsx("td",{className:"table-cell",children:e.jsx("span",{className:`status-pill ${s.status==="En retard"?"border-danger/30 bg-danger/10 text-danger":s.status==="En attente"?"border-gold/30 bg-gold/10 text-gold":"border-accent2/30 bg-accent2/10 text-accent2"}`,children:s.status})})]},`${s.supplier_id}-${c}`)}):e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"table-cell text-textMuted",children:"Aucune échéance trouvée."})})})]})})]})}export{y as default};
