import{u as C,a as _,r as t,k as w,j as e,L as j,P as N,w as E,a1 as k,d as A}from"./index-D4ZMoJFe.js";import{E as P}from"./EmptyStateCard-CTb0IPeU.js";import{E as z}from"./ErrorStateCard-Cx3jyhWy.js";import{P as I}from"./PaginationBar-VjpdrgpZ.js";import{T as M}from"./TableSkeleton-DEtZA9xr.js";import{A as R}from"./AdminSubnav-B96tphNW.js";import{f as F}from"./adminUtils-Qmlne9KJ.js";import"./refresh-ccw-DqBcVzHT.js";import"./SkeletonBlock-BzjAsBLJ.js";function J(){const g=C(),{setSelectedCompanyId:f}=_(),[n,d]=t.useState(!0),[l,x]=t.useState(""),[a,y]=t.useState([]),[m,v]=t.useState(""),[r,p]=t.useState(1),o=50,i=w(m,300),u=async()=>{var s,h;d(!0),x("");try{const c=await A.get("/companies",{params:{search:i||void 0}});y(c.data.items||[])}catch(c){x(((h=(s=c==null?void 0:c.response)==null?void 0:s.data)==null?void 0:h.message)||"Impossible de charger la liste des sociétés.")}finally{d(!1)}};t.useEffect(()=>{u()},[i]),t.useEffect(()=>{p(1)},[i]);const b=t.useMemo(()=>a.slice((r-1)*o,r*o),[a,r]),S=s=>{f(String(s.id)),g("/settings/company")};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("section",{className:"card-panel p-6 sm:p-8",children:[e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-end lg:justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs uppercase tracking-[0.2em] text-accent",children:"Administration"}),e.jsx("h1",{className:"mt-3 text-3xl font-semibold text-text",children:"Sociétés"}),e.jsx("p",{className:"mt-3 max-w-3xl text-sm leading-7 text-textMuted",children:"Centralisez la création des sociétés et ouvrez ensuite leur configuration comptable depuis le cockpit SCF."})]}),e.jsxs(j,{to:"/admin/companies/new",className:"btn-primary inline-flex items-center gap-2",children:[e.jsx(N,{size:16}),"Nouvelle société"]})]}),e.jsx("div",{className:"mt-6",children:e.jsx(R,{})})]}),e.jsx("section",{className:"card-panel p-5",children:e.jsxs("label",{className:"space-y-2",children:[e.jsx("span",{className:"text-sm font-medium text-text",children:"Recherche"}),e.jsx("input",{className:"input-dark",value:m,onChange:s=>v(s.target.value),placeholder:"Nom, NIF, RC ou ville"})]})}),n?e.jsx(M,{columns:8,rows:8}):null,!n&&l?e.jsx(z,{title:"Impossible de charger les sociétés",message:l,onRetry:u,compact:!0}):null,!n&&!l&&!a.length?e.jsx(P,{icon:E,title:"Aucune société",description:i?"Aucune société ne correspond à votre recherche.":"Créez votre première société pour initialiser un nouveau périmètre comptable.",action:e.jsxs(j,{to:"/admin/companies/new",className:"btn-primary inline-flex items-center gap-2",children:[e.jsx(N,{size:16}),"Nouvelle société"]}),compact:!0}):null,!n&&!l&&a.length?e.jsxs(e.Fragment,{children:[e.jsx("section",{className:"table-shell overflow-x-auto",children:e.jsxs("table",{className:"min-w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-surface2 text-left text-xs uppercase tracking-[0.16em] text-textMuted",children:[e.jsx("th",{className:"px-4 py-3",children:"Société"}),e.jsx("th",{className:"px-4 py-3",children:"NIF"}),e.jsx("th",{className:"px-4 py-3",children:"RC"}),e.jsx("th",{className:"px-4 py-3",children:"Ville"}),e.jsx("th",{className:"px-4 py-3",children:"Devise"}),e.jsx("th",{className:"px-4 py-3",children:"Exercice courant"}),e.jsx("th",{className:"px-4 py-3",children:"Utilisateurs"}),e.jsx("th",{className:"px-4 py-3 text-right",children:"Actions"})]})}),e.jsx("tbody",{children:b.map(s=>e.jsxs("tr",{className:"border-t border-border/70 align-top text-text",children:[e.jsxs("td",{className:"px-4 py-4",children:[e.jsx("div",{className:"font-medium",children:s.name}),e.jsxs("div",{className:"mt-1 text-xs text-textMuted",children:["Créée le ",F(s.created_at)]})]}),e.jsx("td",{className:"px-4 py-4 font-mono text-textMuted",children:s.nif}),e.jsx("td",{className:"px-4 py-4 font-mono text-textMuted",children:s.rc}),e.jsx("td",{className:"px-4 py-4",children:s.city||"—"}),e.jsx("td",{className:"px-4 py-4",children:s.currency}),e.jsx("td",{className:"px-4 py-4",children:s.current_fiscal_year?e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:s.current_fiscal_year.label}),e.jsxs("div",{className:"mt-1 text-xs text-textMuted",children:[s.current_fiscal_year.start_date," →"," ",s.current_fiscal_year.end_date]})]}):"—"}),e.jsx("td",{className:"px-4 py-4",children:s.users_count}),e.jsx("td",{className:"px-4 py-4",children:e.jsx("div",{className:"flex justify-end gap-2",children:e.jsxs("button",{type:"button",className:"btn-secondary inline-flex items-center gap-2 px-3 py-2",onClick:()=>S(s),children:[e.jsx(k,{size:15}),"Paramètres"]})})})]},s.id))})]})}),e.jsx(I,{page:r,pageSize:o,total:a.length,onPageChange:p})]}):null]})}export{J as default};
