import{t as _,a as g,r as n,j as e,L as i,d as k}from"./index-D4ZMoJFe.js";import{g as j,R as y}from"./treasuryUtils-CbCB_fwd.js";import{A as C}from"./arrow-left-DvOngpmh.js";import{R as S}from"./refresh-ccw-DqBcVzHT.js";import"./formatters-jmx2pV9o.js";function R(){var u,p;const{id:s}=_(),{selectedCompanyId:N,user:c}=g(),[o,d]=n.useState(!0),[x,m]=n.useState(""),[a,f]=n.useState(null),r=N||((u=c==null?void 0:c.company)==null?void 0:u.id)||(c==null?void 0:c.companyId)||"",h=async()=>{var t,b;if(!(!r||!s)){d(!0),m("");try{const l=await k.get("/reconciliations",{params:{company_id:r,bank_account_id:s}});f(l.data)}catch(l){m(((b=(t=l==null?void 0:l.response)==null?void 0:t.data)==null?void 0:b.message)||"Impossible de charger l'historique des rapprochements.")}finally{d(!1)}}};return n.useEffect(()=>{h()},[r,s]),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-end xl:justify-between",children:[e.jsxs("div",{children:[e.jsxs(i,{to:`/treasury/bank/${s}/reconciliation`,className:"inline-flex items-center gap-2 text-sm font-medium text-accent transition hover:text-accent/80",children:[e.jsx(C,{size:16}),"Retour au rapprochement"]}),e.jsx("h1",{className:"mt-4 text-3xl font-semibold text-text",children:"Historique des rapprochements"}),e.jsx("p",{className:"mt-3 max-w-3xl text-sm leading-7 text-textMuted",children:"Consultez les sessions ouvertes et clôturées pour le compte bancaire sélectionné."})]}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsxs("button",{type:"button",className:"btn-secondary inline-flex items-center gap-2",onClick:h,disabled:o,children:[e.jsx(S,{size:16}),"Actualiser"]}),e.jsx(i,{to:`/treasury/bank/${s}/reconciliation`,className:"btn-primary",children:a!=null&&a.open_reconciliation_id?"Continuer le rapprochement":"Nouveau rapprochement"})]})]})}),a!=null&&a.bank_account?e.jsxs("section",{className:"grid gap-4 lg:grid-cols-3",children:[e.jsxs("div",{className:"card-panel p-5 lg:col-span-2",children:[e.jsx("p",{className:"text-xs uppercase tracking-[0.18em] text-textMuted",children:"Compte bancaire"}),e.jsx("h2",{className:"mt-2 text-2xl font-semibold text-text",children:a.bank_account.bank_name}),e.jsx("p",{className:"mt-2 font-mono text-sm text-textMuted",children:a.bank_account.account_number})]}),e.jsxs("div",{className:"card-panel p-5",children:[e.jsx("p",{className:"text-xs uppercase tracking-[0.18em] text-textMuted",children:"Solde courant"}),e.jsx("p",{className:`mt-2 font-mono text-2xl ${j(a.bank_account.current_balance)}`,children:a.bank_account.formatted_current_balance})]})]}):null,o?e.jsx("section",{className:"card-panel p-8",children:e.jsx("p",{className:"text-sm text-textMuted",children:"Chargement de l'historique..."})}):x?e.jsx("section",{className:"card-panel p-8",children:e.jsx("p",{className:"text-sm text-danger",children:x})}):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 amount-cell",children:"Solde banque"}),e.jsx("th",{className:"table-cell amount-cell",children:"Solde comptable"}),e.jsx("th",{className:"table-cell amount-cell",children:"Écart"}),e.jsx("th",{className:"table-cell",children:"Statut"}),e.jsx("th",{className:"table-cell",children:"Appariements"}),e.jsx("th",{className:"table-cell",children:"Action"})]})}),e.jsx("tbody",{children:(p=a==null?void 0:a.items)!=null&&p.length?a.items.map(t=>e.jsxs("tr",{className:"table-row border-b border-border",children:[e.jsx("td",{className:"table-cell",children:t.reconciliation_date}),e.jsx("td",{className:"table-cell amount-cell text-text",children:t.formatted_bank_balance}),e.jsx("td",{className:"table-cell amount-cell text-text",children:t.formatted_book_balance}),e.jsx("td",{className:`table-cell amount-cell ${t.difference===0?"text-accent2":j(t.difference)}`,children:t.formatted_difference}),e.jsx("td",{className:"table-cell",children:e.jsx("span",{className:`status-pill ${y[t.status]}`,children:t.status_label})}),e.jsxs("td",{className:"table-cell text-sm text-textMuted",children:["Banque ",t.matched_bank_count," · Compta ",t.matched_book_count]}),e.jsx("td",{className:"table-cell",children:e.jsx(i,{to:`/treasury/bank/${s}/reconciliation?reconciliation_id=${t.id}`,className:"text-sm font-medium text-accent transition hover:text-accent/80",children:t.status==="open"?"Continuer":"Voir détail"})})]},t.id)):e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"table-cell py-10 text-center text-textMuted",children:"Aucun rapprochement enregistré pour ce compte bancaire."})})})]})})})]})}export{R as default};
