import{a as b,r as c,j as e,L as r,P as N,d as f}from"./index-D4ZMoJFe.js";import{f as g,a as y}from"./formatters-jmx2pV9o.js";function _(){var m;const{selectedCompanyId:h,user:a}=b(),n=h||(a==null?void 0:a.companyId)||((m=a==null?void 0:a.company)==null?void 0:m.id)||"",[d,u]=c.useState([]),[j,o]=c.useState(!0),[i,x]=c.useState("");return c.useEffect(()=>{(async()=>{var t,p;if(n){o(!0),x("");try{const l=await f.get("/mgx/receptions",{params:{company_id:n}});u(l.data.items||[])}catch(l){x(((p=(t=l==null?void 0:l.response)==null?void 0:t.data)==null?void 0:p.message)||"Impossible de charger les réceptions.")}finally{o(!1)}}})()},[n]),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:"Réceptions"})]}),e.jsxs(r,{to:"/mgx/purchases/receptions/new",className:"btn-primary inline-flex items-center gap-2",children:[e.jsx(N,{size:16}),"Nouvelle réception"]})]})}),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:["N° réception","Date","BC source","Dépôt","Facture","Montant","Actions"].map(s=>e.jsx("th",{className:"table-cell",children:s},s))})}),e.jsx("tbody",{children:j?e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"table-cell text-textMuted",children:"Chargement..."})}):d.length?d.map(s=>{var t;return e.jsxs("tr",{className:"table-row",children:[e.jsx("td",{className:"table-cell font-mono font-semibold",children:s.reception_number}),e.jsx("td",{className:"table-cell",children:g(s.reception_date)}),e.jsx("td",{className:"table-cell",children:s.order_number||"—"}),e.jsx("td",{className:"table-cell",children:((t=s.depot)==null?void 0:t.label)||"—"}),e.jsx("td",{className:"table-cell",children:s.invoice_number||"—"}),e.jsx("td",{className:"table-cell amount-cell",children:s.invoice_amount!==null?y(s.invoice_amount):"—"}),e.jsx("td",{className:"table-cell",children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(r,{to:`/mgx/purchases/returns/new?reception_id=${s.id}`,className:"btn-secondary",children:"Retour"}),e.jsx(r,{to:`/mgx/purchases/receptions/new?order_id=${s.order_id||""}`,className:"btn-secondary",children:"Nouvelle sur BC"})]})})]},s.id)}):e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"table-cell text-textMuted",children:"Aucune réception trouvée."})})})]})})]})}export{_ as default};
