import{a as v,r,j as e,L as n,P as C,s as w,T as _,d as D}from"./index-D4ZMoJFe.js";import{f as N,a as S}from"./formatters-jmx2pV9o.js";function E(){var p;const{selectedCompanyId:f,user:l}=v(),d=f||(l==null?void 0:l.companyId)||((p=l==null?void 0:l.company)==null?void 0:p.id)||"",[o,g]=r.useState([]),[y,x]=r.useState(!0),[i,m]=r.useState("");return r.useEffect(()=>{(async()=>{var t,c;if(d){x(!0),m("");try{const a=await D.get("/mgx/purchase-orders",{params:{company_id:d}});g(a.data.items||[])}catch(a){m(((c=(t=a==null?void 0:a.response)==null?void 0:t.data)==null?void 0:c.message)||"Impossible de charger les bons de commande.")}finally{x(!1)}}})()},[d]),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:"Bons de Commande"})]}),e.jsx("div",{className:"flex flex-wrap gap-3",children:e.jsxs(n,{to:"/mgx/purchases/orders/new",className:"btn-primary inline-flex items-center gap-2",children:[e.jsx(C,{size:16}),"Créer BC"]})})]})}),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-[1120px] w-full",children:[e.jsx("thead",{className:"table-head",children:e.jsx("tr",{children:["N° BC","Date","Fournisseur","Dépôt","Catégorie","Total HT","Statut","Livraison prévue","Actions"].map(s=>e.jsx("th",{className:"table-cell",children:s},s))})}),e.jsx("tbody",{children:y?e.jsx("tr",{children:e.jsx("td",{colSpan:9,className:"table-cell text-textMuted",children:"Chargement..."})}):o.length?o.map(s=>{var t,c,a,h,u,j,b;return e.jsxs("tr",{className:"table-row",children:[e.jsx("td",{className:"table-cell font-mono font-semibold",children:s.order_number}),e.jsx("td",{className:"table-cell",children:N(s.order_date)}),e.jsx("td",{className:"table-cell",children:((t=s.supplier)==null?void 0:t.name)||"—"}),e.jsx("td",{className:"table-cell",children:((c=s.depot)==null?void 0:c.label)||"—"}),e.jsx("td",{className:"table-cell",children:((a=s.category)==null?void 0:a.label)||"—"}),e.jsx("td",{className:"table-cell amount-cell font-semibold",children:S(s.total_ht)}),e.jsx("td",{className:"table-cell",children:e.jsx("span",{className:"rounded-full border px-3 py-1 text-xs font-semibold",style:{borderColor:`${((h=s.status)==null?void 0:h.color)||"#CBD5E1"}66`,backgroundColor:`${((u=s.status)==null?void 0:u.color)||"#CBD5E1"}16`,color:((j=s.status)==null?void 0:j.color)||"#475569"},children:((b=s.status)==null?void 0:b.label)||"—"})}),e.jsx("td",{className:"table-cell",children:N(s.delivery_date_expected)}),e.jsx("td",{className:"table-cell",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx(n,{to:`/mgx/purchases/orders/${s.id}/edit`,className:"btn-secondary px-3 py-2",children:e.jsx(w,{size:15})}),e.jsx(n,{to:`/mgx/purchases/receptions/new?order_id=${s.id}`,className:"btn-secondary px-3 py-2",title:"Réception",children:e.jsx(_,{size:15})})]})})]},s.id)}):e.jsx("tr",{children:e.jsx("td",{colSpan:9,className:"table-cell text-textMuted",children:"Aucun bon de commande trouvé."})})})]})})]})}export{E as default};
