import{a as p,r as a,d as b,j as e}from"./index-D4ZMoJFe.js";import{f}from"./settingsConfig-Cot6R3JK.js";import{C as N,a as y}from"./closureUtils-Bz_-xG_V.js";import{R as g}from"./refresh-ccw-DqBcVzHT.js";function A(){var u;const{selectedCompanyId:j,user:s}=p(),c=j||((u=s==null?void 0:s.company)==null?void 0:u.id)||(s==null?void 0:s.companyId)||"",[n,r]=a.useState(!0),[i,o]=a.useState(""),[x,m]=a.useState([]),d=a.useCallback(async()=>{var t,h;if(!c){m([]),r(!1);return}r(!0),o("");try{const l=await b.get("/closure/audit-log",{params:{company_id:c}});m(l.data.items||[])}catch(l){o(((h=(t=l==null?void 0:l.response)==null?void 0:t.data)==null?void 0:h.message)||"Impossible de charger le journal d'audit de clôture.")}finally{r(!1)}},[c]);return a.useEffect(()=>{d()},[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-4 xl:flex-row xl:items-start xl:justify-between",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs uppercase tracking-[0.2em] text-accent",children:"Clôture"}),e.jsx("h1",{className:"mt-3 text-3xl font-semibold text-text",children:"Journal d'Audit"}),e.jsx("p",{className:"mt-3 max-w-3xl text-sm leading-7 text-textMuted",children:"Historique complet des clôtures et réouvertures, avec auteur, justification et volume d'écritures impactées."})]}),e.jsx(N,{})]}),e.jsxs("button",{type:"button",className:"btn-secondary inline-flex items-center gap-2",onClick:d,disabled:n,children:[e.jsx(g,{size:16}),"Actualiser"]})]})}),i?e.jsx("section",{className:"rounded-xl border border-danger/25 bg-danger/10 px-5 py-4 text-sm text-danger",children:i}):null,e.jsx("section",{className:"table-shell",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full",children:[e.jsx("thead",{className:"table-head",children:e.jsxs("tr",{children:[e.jsx("th",{className:"table-cell",children:"Date"}),e.jsx("th",{className:"table-cell",children:"Action"}),e.jsx("th",{className:"table-cell",children:"Période"}),e.jsx("th",{className:"table-cell",children:"Effectué par"}),e.jsx("th",{className:"table-cell",children:"Justification"}),e.jsx("th",{className:"table-cell",children:"Nb écritures modifiées"})]})}),e.jsx("tbody",{children:n?e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"table-cell py-10 text-center text-textMuted",children:"Chargement du journal d'audit..."})}):x.length?x.map(t=>e.jsxs("tr",{className:"table-row border-b border-border",children:[e.jsx("td",{className:"table-cell",children:f(t.created_at)}),e.jsx("td",{className:"table-cell",children:e.jsx("span",{className:`inline-flex rounded-full border px-2.5 py-1 text-xs font-semibold ${y[t.action]||"border-border bg-surface2 text-text"}`,children:t.action_label})}),e.jsx("td",{className:"table-cell",children:e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-text",children:t.period_label}),e.jsx("p",{className:"text-xs text-textMuted",children:t.fiscal_year_label})]})}),e.jsx("td",{className:"table-cell",children:t.performed_by}),e.jsx("td",{className:"table-cell text-textMuted",children:t.justification||"—"}),e.jsx("td",{className:"table-cell font-mono text-text",children:t.modified_entries_count})]},t.id)):e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"table-cell py-10 text-center text-textMuted",children:"Aucun événement de clôture n'a encore été journalisé."})})})]})})})]})}export{A as default};
