import{a as _,r as c,j as e,L as j,P as v,s as w,d as C}from"./index-D4ZMoJFe.js";import{f as b,a as N}from"./formatters-jmx2pV9o.js";function I(){var m;const{selectedCompanyId:g,user:a}=_(),r=g||(a==null?void 0:a.companyId)||((m=a==null?void 0:a.company)==null?void 0:m.id)||"",[d,f]=c.useState([]),[y,o]=c.useState(!0),[i,x]=c.useState("");return c.useEffect(()=>{(async()=>{var t,n;if(r){o(!0),x("");try{const s=await C.get("/mgx/rentals",{params:{company_id:r}});f(s.data.items||[])}catch(s){x(((n=(t=s==null?void 0:s.response)==null?void 0:t.data)==null?void 0:n.message)||"Impossible de charger les locations.")}finally{o(!1)}}})()},[r]),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 · Locations"}),e.jsx("h1",{className:"mt-3 text-3xl font-semibold text-text",children:"Locations de Camion"})]}),e.jsxs(j,{to:"/mgx/rentals/new",className:"btn-primary inline-flex items-center gap-2",children:[e.jsx(v,{size:16}),"Nouvelle location"]})]})}),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:["Véhicule","Loueur","Type","Début","Fin","Tarif/jour","Total","Statut","Alerte","Actions"].map(l=>e.jsx("th",{className:"table-cell",children:l},l))})}),e.jsx("tbody",{children:y?e.jsx("tr",{children:e.jsx("td",{colSpan:10,className:"table-cell text-textMuted",children:"Chargement..."})}):d.length?d.map(l=>{var t,n,s,u,p,h;return e.jsxs("tr",{className:"table-row",children:[e.jsx("td",{className:"table-cell",children:((t=l.vehicle)==null?void 0:t.plate_number)||"—"}),e.jsx("td",{className:"table-cell",children:((n=l.supplier)==null?void 0:n.name)||"—"}),e.jsx("td",{className:"table-cell",children:l.rental_type==="internal"?"Interne":"Externe"}),e.jsx("td",{className:"table-cell",children:b(l.start_date)}),e.jsx("td",{className:"table-cell",children:b(l.end_date)}),e.jsx("td",{className:"table-cell amount-cell",children:l.daily_rate!==null?N(l.daily_rate):"—"}),e.jsx("td",{className:"table-cell amount-cell font-semibold",children:l.total_amount!==null?N(l.total_amount):"—"}),e.jsx("td",{className:"table-cell",children:e.jsx("span",{className:"rounded-full border px-3 py-1 text-xs font-semibold",style:{borderColor:`${((s=l.status)==null?void 0:s.color)||"#CBD5E1"}66`,backgroundColor:`${((u=l.status)==null?void 0:u.color)||"#CBD5E1"}16`,color:((p=l.status)==null?void 0:p.color)||"#475569"},children:((h=l.status)==null?void 0:h.label)||"—"})}),e.jsx("td",{className:"table-cell",children:l.expiring_soon?e.jsxs("span",{className:"rounded-full border border-gold/30 bg-gold/10 px-3 py-1 text-xs font-semibold text-gold",children:[l.days_remaining," j"]}):"—"}),e.jsx("td",{className:"table-cell",children:e.jsx(j,{to:`/mgx/rentals/${l.id}/edit`,className:"btn-secondary px-3 py-2",children:e.jsx(w,{size:15})})})]},l.id)}):e.jsx("tr",{children:e.jsx("td",{colSpan:10,className:"table-cell text-textMuted",children:"Aucune location trouvée."})})})]})})]})}export{I as default};
