import{a as v,a4 as _,r as c,j as e,L as o,P as S,S as C,s as w,d as M}from"./index-D4ZMoJFe.js";import{a as I,f as k}from"./formatters-jmx2pV9o.js";function E(){var j;const{selectedCompanyId:f,user:t}=v(),d=f||(t==null?void 0:t.companyId)||((j=t==null?void 0:t.company)==null?void 0:j.id)||"",N=_("supplier_type"),[r,i]=c.useState({search:"",type:"",active:"true"}),[x,g]=c.useState([]),[y,p]=c.useState(!0),[u,m]=c.useState(""),h=c.useMemo(()=>({company_id:d,...r}),[d,r]);return c.useEffect(()=>{(async()=>{var a,n;if(d){p(!0),m("");try{const l=await M.get("/mgx/suppliers",{params:h});g(l.data.items||[])}catch(l){m(((n=(a=l==null?void 0:l.response)==null?void 0:a.data)==null?void 0:n.message)||"Impossible de charger les fournisseurs.")}finally{p(!1)}}})()},[d,h]),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 · Fournisseurs"}),e.jsx("h1",{className:"mt-3 text-3xl font-semibold text-text",children:"Fournisseurs & Prestataires"})]}),e.jsxs(o,{to:"/mgx/suppliers/new",className:"btn-primary inline-flex items-center gap-2",children:[e.jsx(S,{size:16}),"Nouveau fournisseur"]})]})}),e.jsx("section",{className:"card-panel p-5",children:e.jsxs("div",{className:"grid gap-3 xl:grid-cols-[minmax(0,1fr)_220px_180px]",children:[e.jsxs("label",{className:"relative",children:[e.jsx(C,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-textMuted",size:16}),e.jsx("input",{className:"input-dark pl-10",value:r.search,onChange:s=>i(a=>({...a,search:s.target.value})),placeholder:"Recherche nom / code"})]}),e.jsxs("select",{className:"input-dark",value:r.type,onChange:s=>i(a=>({...a,type:s.target.value})),children:[e.jsx("option",{value:"",children:"Tous types"}),N.map(s=>e.jsx("option",{value:s.id,children:s.label},s.id))]}),e.jsxs("select",{className:"input-dark",value:r.active,onChange:s=>i(a=>({...a,active:s.target.value})),children:[e.jsx("option",{value:"true",children:"Actifs"}),e.jsx("option",{value:"false",children:"Inactifs"}),e.jsx("option",{value:"",children:"Tous"})]})]})}),u?e.jsx("div",{className:"rounded-2xl border border-danger/20 bg-danger/5 p-4 text-sm text-danger",children:u}):null,e.jsx("section",{className:"table-shell overflow-x-auto",children:e.jsxs("table",{className:"min-w-[1180px] w-full",children:[e.jsx("thead",{className:"table-head",children:e.jsx("tr",{children:["Code","Nom","Type","Ville","Téléphone","Solde initial","Balance dûe","Dernier achat","Statut","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:10,className:"table-cell text-textMuted",children:"Chargement..."})}):x.length?x.map(s=>{var a,n,l,b;return e.jsxs("tr",{className:"table-row",children:[e.jsx("td",{className:"table-cell font-mono font-semibold",children:s.code}),e.jsxs("td",{className:"table-cell",children:[e.jsx("p",{className:"font-semibold text-text",children:s.name}),e.jsx("p",{className:"text-xs text-textMuted",children:s.email||"—"})]}),e.jsx("td",{className:"table-cell",children:e.jsx("span",{className:"rounded-full border px-3 py-1 text-xs font-semibold",style:{borderColor:`${((a=s.supplier_type)==null?void 0:a.color)||"#CBD5E1"}66`,backgroundColor:`${((n=s.supplier_type)==null?void 0:n.color)||"#CBD5E1"}16`,color:((l=s.supplier_type)==null?void 0:l.color)||"#475569"},children:((b=s.supplier_type)==null?void 0:b.label)||"—"})}),e.jsx("td",{className:"table-cell",children:s.city||"—"}),e.jsx("td",{className:"table-cell",children:s.phone||"—"}),e.jsx("td",{className:"table-cell amount-cell font-semibold",children:s.current_balance_formatted||I(s.current_balance||0)}),e.jsx("td",{className:"table-cell amount-cell font-semibold",children:s.balance_due_formatted}),e.jsx("td",{className:"table-cell",children:k(s.last_purchase_date)}),e.jsx("td",{className:"table-cell",children:e.jsx("span",{className:`status-pill ${s.is_active?"border-accent2/30 bg-accent2/10 text-accent2":"border-border bg-surface2 text-textMuted"}`,children:s.is_active?"Actif":"Inactif"})}),e.jsx("td",{className:"table-cell",children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(o,{to:`/mgx/suppliers/${s.id}/edit`,className:"btn-secondary px-3 py-2",children:e.jsx(w,{size:15})}),e.jsx(o,{to:`/mgx/suppliers/${s.id}/statement`,className:"btn-secondary",children:"Relevé"})]})})]},s.id)}):e.jsx("tr",{children:e.jsx("td",{colSpan:10,className:"table-cell text-textMuted",children:"Aucun fournisseur trouvé."})})})]})})]})}export{E as default};
