import{a as j,r,j as e,L as b,P as f,d as N}from"./index-D4ZMoJFe.js";import{f as g,a as y}from"./formatters-jmx2pV9o.js";function _(){var x;const{selectedCompanyId:u,user:t}=j(),c=u||(t==null?void 0:t.companyId)||((x=t==null?void 0:t.company)==null?void 0:x.id)||"",[n,h]=r.useState([]),[p,o]=r.useState(!0),[d,i]=r.useState("");return r.useEffect(()=>{(async()=>{var a,m;if(c){o(!0),i("");try{const l=await N.get("/mgx/purchase-returns",{params:{company_id:c}});h(l.data.items||[])}catch(l){i(((m=(a=l==null?void 0:l.response)==null?void 0:a.data)==null?void 0:m.message)||"Impossible de charger les retours fournisseur.")}finally{o(!1)}}})()},[c]),e.jsxs("div",{className:"space-y-6",children:[e.jsx("section",{className:"card-panel p-6 sm:p-8",children:e.jsxs("div",{className:"flex flex-col gap-5 xl:flex-row xl:items-end xl:justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs uppercase tracking-[0.2em] text-gold",children:"MGX · Achats"}),e.jsx("h1",{className:"mt-3 text-3xl font-semibold text-text",children:"Retours fournisseur"}),e.jsx("p",{className:"mt-2 max-w-2xl text-sm text-textMuted",children:"Retours liés aux réceptions, avec sortie de stock et avoir fournisseur automatique."})]}),e.jsxs(b,{to:"/mgx/purchases/returns/new",className:"btn-primary inline-flex items-center gap-2",children:[e.jsx(f,{size:16}),"Nouveau retour"]})]})}),d?e.jsx("div",{className:"rounded-2xl border border-danger/20 bg-danger/5 p-4 text-sm text-danger",children:d}):null,e.jsx("section",{className:"table-shell overflow-x-auto",children:e.jsxs("table",{className:"min-w-[1100px] w-full",children:[e.jsx("thead",{className:"table-head",children:e.jsx("tr",{children:["N° retour","Date","Réception","BC source","Fournisseur","Avoir","Motif"].map(s=>e.jsx("th",{className:"table-cell",children:s},s))})}),e.jsx("tbody",{children:p?e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"table-cell text-textMuted",children:"Chargement..."})}):n.length?n.map(s=>{var a;return e.jsxs("tr",{className:"table-row",children:[e.jsx("td",{className:"table-cell font-mono font-semibold",children:s.return_number}),e.jsx("td",{className:"table-cell",children:g(s.return_date)}),e.jsx("td",{className:"table-cell",children:s.reception_number||"—"}),e.jsx("td",{className:"table-cell",children:s.order_number||"—"}),e.jsx("td",{className:"table-cell",children:((a=s.supplier)==null?void 0:a.name)||"—"}),e.jsx("td",{className:"table-cell amount-cell",children:y(s.payable_credit_amount||0)}),e.jsx("td",{className:"table-cell",children:s.reason||"—"})]},s.id)}):e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"table-cell text-textMuted",children:"Aucun retour fournisseur trouvé."})})})]})})]})}export{_ as default};
