@atyaio/ledgr-web 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/assets/badge-DCLlsDNI.js +55 -0
  2. package/dist/assets/{breakdown-D9nBrbad.js → breakdown-B7xclB2-.js} +1 -1
  3. package/dist/assets/{categories-B7jajln6.js → categories-C9LvkWNc.js} +1 -1
  4. package/dist/assets/{color-picker-DLlr-Cq6.js → color-picker-DUPZPbk3.js} +1 -1
  5. package/dist/assets/{custom-cell-Wgh3D7lb.js → custom-cell-DOJAsRPW.js} +1 -1
  6. package/dist/assets/data-BX7xFZfR.js +1 -0
  7. package/dist/assets/{download-CIyMPSgr.js → download-gNHw92Vi.js} +1 -1
  8. package/dist/assets/expenses-Ct1Tk3pC.js +1 -0
  9. package/dist/assets/index-B9WjaP25.js +31 -0
  10. package/dist/assets/index-YWd9JGBA.css +2 -0
  11. package/dist/assets/insights-C0cl4vss.js +1 -0
  12. package/dist/assets/integrations-CueFg-5F.js +1 -0
  13. package/dist/assets/{ledger-toolbar-yj0u4-Rm.js → ledger-toolbar-B_Gbv5Ws.js} +1 -1
  14. package/dist/assets/{media-Cr7juL5w.js → media-D6XgVZ7M.js} +1 -1
  15. package/dist/assets/{menu-BDGd2JUq.js → menu-C-8r2BNA.js} +1 -1
  16. package/dist/assets/{money-Ch2MLu6J.js → money-OFUBQ3gl.js} +1 -1
  17. package/dist/assets/{money-input-C8ZuBxvX.js → money-input-DQaEauAw.js} +1 -1
  18. package/dist/assets/{overview-Ddn6RbvU.js → overview-CZMXeLeG.js} +1 -1
  19. package/dist/assets/payments-D9NCfpzJ.js +1 -0
  20. package/dist/assets/project-CYHaWZqH.js +1 -0
  21. package/dist/assets/{pull-shift-sheet-DTwTC0rg.js → pull-shift-sheet-BaOiY46Z.js} +1 -1
  22. package/dist/assets/queries-CxLQqNqz.js +1 -0
  23. package/dist/assets/recurring-e7X3okBc.js +1 -0
  24. package/dist/assets/revenue-TPYHnUaW.js +1 -0
  25. package/dist/assets/{search-jkqZqVJy.js → search-CnrmI1BH.js} +1 -1
  26. package/dist/assets/settings-mDly_aVZ.js +4 -0
  27. package/dist/assets/{shift-sales-B0yokKuf.js → shift-sales-BpOCNuGY.js} +1 -1
  28. package/dist/assets/stakeholders-DzTfUHX0.js +1 -0
  29. package/dist/assets/{star-cwF2fEe6.js → star-DZj1Tpai.js} +1 -1
  30. package/dist/assets/{table-DQsx5_iN.js → table-QAdUTXQz.js} +1 -1
  31. package/dist/assets/{tooltip-CKyX36D7.js → tooltip-CYNpGhCZ.js} +7 -7
  32. package/dist/index.html +8 -8
  33. package/package.json +2 -2
  34. package/dist/assets/badge-BTiDEJlh.js +0 -55
  35. package/dist/assets/data-DLjPdfYn.js +0 -1
  36. package/dist/assets/expenses-DglPf9Hj.js +0 -1
  37. package/dist/assets/index-B3RS60Xw.css +0 -2
  38. package/dist/assets/index-DOwVPfdT.js +0 -31
  39. package/dist/assets/insights-C_lA_1Ig.js +0 -1
  40. package/dist/assets/integrations-C4NPnoJ4.js +0 -1
  41. package/dist/assets/payments-q8beCPp-.js +0 -1
  42. package/dist/assets/project-Bgpq3nFR.js +0 -1
  43. package/dist/assets/queries-IGiwF8nF.js +0 -1
  44. package/dist/assets/recurring-xqowgQWt.js +0 -1
  45. package/dist/assets/revenue-CB8ggUDa.js +0 -1
  46. package/dist/assets/settings-DJ670Ax6.js +0 -4
  47. package/dist/assets/stakeholders-wioC2mrf.js +0 -1
@@ -1 +1 @@
1
- import{dt as e,v as t}from"./badge-BTiDEJlh.js";import{n}from"./project-Bgpq3nFR.js";var r=e();function i({def:e,value:i}){let{t:a}=t(),{money:o,date:s}=n();if(i==null||i===``)return(0,r.jsx)(`span`,{className:`text-ink-4`,children:`—`});switch(e.type){case`money`:return(0,r.jsx)(`span`,{className:`num`,children:o(Number(i))});case`number`:return(0,r.jsx)(`span`,{className:`num`,children:Number(i).toLocaleString()});case`date`:return(0,r.jsx)(`span`,{className:`num text-ink-2`,children:s(String(i))});case`boolean`:return(0,r.jsx)(`span`,{className:i?`text-good`:`text-ink-3`,children:a(i?`Yes`:`No`)});case`select`:return(0,r.jsx)(`span`,{className:`inline-flex h-6 items-center px-2 rounded-full bg-sunken text-[12px]`,children:String(i)});default:return(0,r.jsx)(`span`,{className:`text-ink-2 truncate inline-block max-w-[200px] align-middle`,children:String(i)})}}export{i as t};
1
+ import{ft as e,v as t}from"./badge-DCLlsDNI.js";import{n}from"./project-CYHaWZqH.js";var r=e();function i({def:e,value:i}){let{t:a}=t(),{money:o,date:s}=n();if(i==null||i===``)return(0,r.jsx)(`span`,{className:`text-ink-4`,children:`—`});switch(e.type){case`money`:return(0,r.jsx)(`span`,{className:`num`,children:o(Number(i))});case`number`:return(0,r.jsx)(`span`,{className:`num`,children:Number(i).toLocaleString()});case`date`:return(0,r.jsx)(`span`,{className:`num text-ink-2`,children:s(String(i))});case`boolean`:return(0,r.jsx)(`span`,{className:i?`text-good`:`text-ink-3`,children:a(i?`Yes`:`No`)});case`select`:return(0,r.jsx)(`span`,{className:`inline-flex h-6 items-center px-2 rounded-full bg-sunken text-[12px]`,children:String(i)});default:return(0,r.jsx)(`span`,{className:`text-ink-2 truncate inline-block max-w-[200px] align-middle`,children:String(i)})}}export{i as t};
@@ -0,0 +1 @@
1
+ import{S as e,U as t,V as n,_t as r,d as i,dt as a,ft as o,g as s,h as c,mt as l,n as u,o as d,p as ee,v as f}from"./badge-DCLlsDNI.js";import{t as p}from"./download-gNHw92Vi.js";import{a as m,n as h,r as g}from"./media-D6XgVZ7M.js";import{f as _,h as te,m as v,p as ne,u as re}from"./index-B9WjaP25.js";var y={name:`file-up`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M12 12v6`,key:`3ahymv`}],[`path`,{d:`m15 15-3-3-3 3`,key:`15xj92`}]]};y.node;var b=s(y),x={name:`shield-check`,size:24,node:[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]};x.node;var S=s(x),C={name:`upload`,size:24,node:[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]};C.node;var w=s(C),T=r(l(),1),E=o(),D={expenses:`Expenses`,revenue:`Revenue`,stakeholders:`Stakeholders`,categories:`Categories`,settlements:`Settlements`};function O(){let r=te(),{t:o}=f(),s=a(),{range:l}=ne(),[y,x]=(0,T.useState)(`expenses`),[C,O]=(0,T.useState)(null),[k,A]=(0,T.useState)(null),[j,M]=(0,T.useState)({}),[N,P]=(0,T.useState)(`auto`),[F,I]=(0,T.useState)(!0),[L,R]=(0,T.useState)(!1),[z,B]=(0,T.useState)(!0),[V,H]=(0,T.useState)(!1),[U,W]=(0,T.useState)(null),[G,K]=(0,T.useState)(!1),q=(0,T.useRef)(null),[ie,J]=(0,T.useState)(!1),[Y,ae]=(0,T.useState)(null),[X,oe]=(0,T.useState)(!1),Z=async e=>{O(e),W(null),H(!0);try{let t=new FormData;t.append(`file`,e);let r=await n.upload(`/import/${y}/preview`,t);A(r),M(r.suggestedMapping),P(r.detectedDateFormat)}catch(e){r.error(o(`Could not read file`),v(e)),A(null)}finally{H(!1)}},Q=k?.targets.filter(e=>e.required&&!j[e.key])??[],se=async()=>{if(C){H(!0);try{let e=new FormData;e.append(`file`,C),e.append(`mapping`,JSON.stringify(j)),e.append(`options`,JSON.stringify({dateFormat:N,createMissingCategories:F,createMissingStakeholders:L,skipDuplicates:z}));let t=await n.upload(`/import/${y}/commit`,e);W(t),await s.invalidateQueries(),r.success(o(`Imported {n} {entity}`,{n:t.inserted,entity:o(D[y]).toLowerCase()}),t.skipped?o(`{n} skipped`,{n:t.skipped}):void 0)}catch(e){r.error(o(`Import failed`),v(e))}finally{H(!1)}}},$=()=>{O(null),A(null),W(null),M({}),q.current&&(q.current.value=``)};return(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(i,{title:o(`Import & export`),subtitle:o(`Bulk-load from spreadsheets, export any ledger, back up the whole project.`)}),(0,E.jsxs)(`div`,{className:`grid grid-cols-1 xl:grid-cols-3 gap-4`,children:[(0,E.jsx)(d,{className:`xl:col-span-2`,title:o(`Import a spreadsheet`),children:(0,E.jsxs)(`div`,{className:`space-y-4`,children:[(0,E.jsx)(ee,{value:y,onChange:e=>{x(e),$()},items:e.map(e=>({id:e,label:o(D[e])}))}),!k&&(0,E.jsxs)(`div`,{className:c(`rounded-[16px] border-2 border-dashed p-8 text-center transition-colors cursor-pointer`,G?`border-accent bg-accent-soft`:`border-line-strong hover:border-ink-3 bg-sunken/40`),onDragOver:e=>{e.preventDefault(),K(!0)},onDragLeave:()=>K(!1),onDrop:e=>{e.preventDefault(),K(!1);let t=e.dataTransfer.files[0];t&&Z(t)},onClick:()=>q.current?.click(),children:[(0,E.jsx)(b,{className:`size-7 mx-auto text-ink-3 mb-2`}),(0,E.jsx)(`div`,{className:`text-[15px] font-medium`,children:o(`Choose an Excel or CSV file`)}),(0,E.jsx)(`div`,{className:`text-[13px] text-ink-3 mt-1`,children:o(`Any column names: you map them next. Dates, money formats and category names are matched for you.`)}),(0,E.jsx)(`input`,{ref:q,type:`file`,accept:`.xlsx,.csv,text/csv,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&Z(t)}})]}),!k&&(0,E.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,E.jsx)(_,{size:`xs`,variant:`soft`,icon:(0,E.jsx)(p,{className:`size-3.5`}),onClick:()=>t(`/export/template/${y}.xlsx`,`${y}-template.xlsx`).catch(e=>r.error(o(`Failed`),v(e))),children:o(`Excel template`)}),(0,E.jsx)(_,{size:`xs`,variant:`ghost`,icon:(0,E.jsx)(p,{className:`size-3.5`}),onClick:()=>t(`/export/template/${y}.csv`,`${y}-template.csv`).catch(e=>r.error(o(`Failed`),v(e))),children:o(`CSV template`)}),(0,E.jsx)(`span`,{className:`text-[12px] text-ink-3`,children:o(`The Excel template has dropdowns for categories, partners and choice fields.`)})]}),V&&!k&&(0,E.jsx)(`div`,{className:`text-[13px] text-ink-3`,children:o(`Reading…`)}),k&&(0,E.jsxs)(`div`,{className:`space-y-4`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-[13.5px]`,children:[(0,E.jsxs)(`span`,{className:`min-w-0 truncate`,children:[(0,E.jsx)(`span`,{className:`font-medium`,children:C?.name}),` `,(0,E.jsxs)(`span`,{className:`text-ink-3 num`,children:[`· `,o(`{n} rows`,{n:k.rowCount})]})]}),(0,E.jsx)(_,{size:`xs`,variant:`ghost`,onClick:$,children:o(`Change file`)})]}),(0,E.jsxs)(`div`,{className:`rounded-[14px] border border-line overflow-hidden`,children:[(0,E.jsxs)(`div`,{className:`hidden md:grid grid-cols-[1fr_1fr_1.4fr] label px-3.5 h-9 items-center border-b border-line bg-sunken/60`,children:[(0,E.jsx)(`span`,{children:o(`Field`)}),(0,E.jsx)(`span`,{children:o(`CSV column`)}),(0,E.jsx)(`span`,{children:o(`Sample`)})]}),k.targets.map(e=>{let t=j[e.key],n=t?k.headers.indexOf(t):-1;return(0,E.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-[1fr_1fr_1.4fr] items-center gap-1.5 md:gap-2 px-3.5 py-2.5 border-b border-line last:border-b-0 text-[13.5px]`,children:[(0,E.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 font-medium`,children:[o(e.label),e.required&&(0,E.jsx)(`span`,{className:`text-critical`,children:`*`}),e.description&&(0,E.jsx)(`span`,{className:`text-[12px] text-ink-3 font-normal truncate`,children:o(e.description)})]}),(0,E.jsxs)(m,{compact:!0,className:c(e.required&&!t&&`border-critical/60`),value:t??``,onChange:t=>M(n=>({...n,[e.key]:t.target.value||null})),children:[(0,E.jsx)(`option`,{value:``,children:o(`— skip —`)}),k.headers.map(e=>(0,E.jsx)(`option`,{value:e,children:e},e))]}),(0,E.jsx)(`span`,{className:`num text-ink-3 truncate text-[12.5px]`,children:n>=0?k.sampleRows.slice(0,3).map(e=>e[n]).filter(Boolean).join(` · `):``})]},e.key)})]}),(0,E.jsxs)(`div`,{className:`flex flex-col md:flex-row md:items-end gap-4`,children:[(0,E.jsx)(g,{label:o(`Date format`),className:`md:w-48`,children:(0,E.jsxs)(m,{compact:!0,value:N,onChange:e=>P(e.target.value),children:[(0,E.jsx)(`option`,{value:`auto`,children:o(`Auto-detect`)}),(0,E.jsx)(`option`,{value:`iso`,children:o(`ISO (YYYY-MM-DD)`)}),(0,E.jsx)(`option`,{value:`dmy`,children:o(`Day / Month / Year`)}),(0,E.jsx)(`option`,{value:`mdy`,children:o(`Month / Day / Year`)})]})}),(0,E.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,E.jsx)(h,{label:o(`Create missing categories`),checked:F,onChange:e=>I(e.target.checked)}),(0,E.jsx)(h,{label:o(`Create missing stakeholders (0% share)`),checked:L,onChange:e=>R(e.target.checked)}),(0,E.jsx)(h,{label:o(`Skip rows that already exist`),checked:z,onChange:e=>B(e.target.checked)})]})]}),(0,E.jsxs)(`div`,{className:`flex flex-col md:flex-row md:items-center md:justify-between gap-3`,children:[(0,E.jsx)(`span`,{className:`text-[13px] text-ink-3`,children:Q.length?(0,E.jsx)(`span`,{className:`text-critical`,children:o(`Map required fields: {fields}`,{fields:Q.map(e=>o(e.label)).join(`, `)})}):o(`Ready to import.`)}),(0,E.jsx)(_,{variant:`primary`,size:`md`,icon:(0,E.jsx)(w,{className:`size-4`}),loading:V,disabled:!!Q.length,onClick:se,children:o(`Import {n} rows`,{n:k.rowCount})})]}),U&&(0,E.jsxs)(`div`,{className:`rounded-[14px] bg-sunken/60 p-3.5 text-[13.5px]`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,E.jsx)(u,{tone:`good`,children:o(`{n} inserted`,{n:U.inserted})}),U.skipped>0&&(0,E.jsx)(u,{children:o(`{n} skipped`,{n:U.skipped})}),U.errors.length>0&&(0,E.jsx)(u,{tone:`critical`,children:o(`{n} errors`,{n:U.errors.length})})]}),U.errors.length>0&&(0,E.jsx)(`ul`,{className:`mt-2 max-h-40 overflow-y-auto space-y-0.5 num text-[12.5px] text-ink-2`,children:U.errors.slice(0,100).map((e,t)=>(0,E.jsxs)(`li`,{children:[(0,E.jsx)(`span`,{className:`text-ink-3`,children:o(`row {n}`,{n:e.row})}),` `,e.message]},t))})]})]})]})}),(0,E.jsxs)(`div`,{className:`space-y-4`,children:[(0,E.jsx)(d,{title:o(`Export`),subtitle:o(`Excel files keep the dropdowns, so they re-import without typos.`),flush:!0,children:(0,E.jsx)(`ul`,{className:`divide-y divide-line`,children:e.map(e=>{let n=e===`stakeholders`||e===`categories`?void 0:{from:l.from,to:l.to};return(0,E.jsxs)(`li`,{className:`flex items-center justify-between gap-2 px-4 md:px-5 h-13 text-[14px]`,children:[(0,E.jsxs)(`span`,{className:`min-w-0`,children:[o(D[e]),n&&(0,E.jsx)(`span`,{className:`block text-ink-3 num text-[12px]`,children:o(`{from} → {to}`,{from:l.from,to:l.to})})]}),(0,E.jsxs)(`span`,{className:`flex items-center gap-1.5 shrink-0`,children:[(0,E.jsx)(_,{size:`xs`,variant:`soft`,className:`rounded-full`,icon:(0,E.jsx)(p,{className:`size-3.5`}),onClick:()=>t(`/export/${e}.xlsx`,`${e}.xlsx`,n).catch(e=>r.error(o(`Export failed`),v(e))),children:o(`Excel`)}),(0,E.jsx)(_,{size:`xs`,variant:`ghost`,className:`rounded-full`,onClick:()=>t(`/export/${e}.csv`,`${e}.csv`,n).catch(e=>r.error(o(`Export failed`),v(e))),children:o(`CSV`)})]})]},e)})})}),(0,E.jsxs)(d,{title:o(`Backup & restore`),children:[(0,E.jsx)(`p`,{className:`text-[13.5px] text-ink-2 mb-3`,children:o(`One JSON file with every table, custom field and rule. Keep one before big imports.`)}),(0,E.jsxs)(`div`,{className:`flex gap-2 flex-wrap`,children:[(0,E.jsx)(_,{variant:`secondary`,icon:(0,E.jsx)(S,{className:`size-4`}),onClick:()=>t(`/export/backup.json`,`ledgr-backup.json`).catch(e=>r.error(o(`Backup failed`),v(e))),children:o(`Download backup`)}),(0,E.jsx)(_,{variant:`ghost`,icon:(0,E.jsx)(w,{className:`size-4`}),onClick:()=>J(!0),children:o(`Restore…`)})]})]})]})]}),(0,E.jsx)(re,{open:ie,onClose:()=>J(!1),title:o(`Restore from backup`),description:o(`Restores a ledgr-backup.json. Only allowed into an empty project unless you choose to replace everything.`),footer:(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(_,{variant:`ghost`,size:`md`,onClick:()=>J(!1),children:o(`Cancel`)}),(0,E.jsx)(_,{variant:X?`danger`:`primary`,size:`md`,loading:V,disabled:!Y,onClick:async()=>{if(Y){H(!0);try{let e=JSON.parse(await Y.text());await n.post(`/import/backup${X?`?replace=true`:``}`,e),await s.invalidateQueries(),r.success(o(`Backup restored`)),J(!1)}catch(e){r.error(o(`Restore failed`),v(e))}finally{H(!1)}}},children:o(X?`Replace all data`:`Restore`)})]}),children:(0,E.jsxs)(`div`,{className:`space-y-3`,children:[(0,E.jsx)(`input`,{type:`file`,accept:`application/json,.json`,onChange:e=>ae(e.target.files?.[0]??null),className:`text-[13.5px]`}),(0,E.jsx)(h,{label:o(`Wipe current data first (irreversible)`),checked:X,onChange:e=>oe(e.target.checked)})]})})]})}export{O as DataPage};
@@ -1 +1 @@
1
- import{g as e}from"./badge-BTiDEJlh.js";var t={name:`download`,size:24,node:[[`path`,{d:`M12 15V3`,key:`m9g1x1`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}],[`path`,{d:`m7 10 5 5 5-5`,key:`brsn70`}]]};t.node;var n=e(t);export{n as t};
1
+ import{g as e}from"./badge-DCLlsDNI.js";var t={name:`download`,size:24,node:[[`path`,{d:`M12 15V3`,key:`m9g1x1`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}],[`path`,{d:`m7 10 5 5 5-5`,key:`brsn70`}]]};t.node;var n=e(t);export{n as t};
@@ -0,0 +1 @@
1
+ import{U as e,_t as t,d as n,ft as r,h as i,i as a,mt as o,o as s,r as c,s as l,t as u,v as ee}from"./badge-DCLlsDNI.js";import{O as te,i as d,l as ne,s as re,u as ie,v as ae}from"./queries-CxLQqNqz.js";import{n as f}from"./project-CYHaWZqH.js";import{a as p,i as m,n as oe,o as se,r as ce,t as le}from"./table-QAdUTXQz.js";import{a as ue,i as h,n as g,o as de,r as _,t as fe}from"./menu-C-8r2BNA.js";import{a as pe,i as me,n as he,r as ge,t as _e}from"./ledger-toolbar-B_Gbv5Ws.js";import{n as v}from"./search-CnrmI1BH.js";import{n as y,t as ve}from"./media-D6XgVZ7M.js";import{b as ye,f as b,h as be,l as xe,m as x,o as Se,p as Ce,u as S}from"./index-B9WjaP25.js";import{t as C}from"./money-OFUBQ3gl.js";import{t as w}from"./custom-cell-DOJAsRPW.js";var T=t(o(),1),E=r(),we=50;function D(){let{t,name:r,label:o}=ee(),S=e=>r({name:e.name??``,nameAr:e.nameAr}),{range:D}=Ce(),{date:O,money:k}=f(),A=he(),j=be(),Ee=ve(),De=d(`expense`,!0),Oe=te(),ke=re(`expense`),M=ae(!0),N=(0,T.useMemo)(()=>(M.data?.items??[]).filter(e=>!e.archived),[M.data]),[Ae,P]=(0,T.useState)(null),je=(0,T.useMemo)(()=>({from:D.from,to:D.to,q:A.q,categoryId:A.categoryId,stakeholderId:A.stakeholderId,paymentMethodId:A.paymentMethodId,sort:A.sort,order:A.order,page:A.page,pageSize:we}),[D,A.q,A.categoryId,A.stakeholderId,A.paymentMethodId,A.sort,A.order,A.page]),F=ie(je),{remove:I,bulkDelete:Me,recompute:Ne,recomputeRange:Pe}=ne(),[Fe,L]=(0,T.useState)(void 0),[R,z]=(0,T.useState)(null),[B,V]=(0,T.useState)(new Set),[H,U]=(0,T.useState)(!1),[Ie,W]=(0,T.useState)(!1),[G,K]=(0,T.useState)(null),q=F.data?.items??[],J=ke.data?.items??[],Y=q.length>0&&q.every(e=>B.has(e.id)),Le=()=>V(Y?new Set:new Set(q.map(e=>e.id))),X=e=>V(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),Z=e=>A.set({sort:e,order:A.sort===e&&A.order===`desc`?`asc`:`desc`}),Q=e=>A.sort===e?A.order:null,Re=async()=>{if(R)try{await I.mutateAsync(R.id),j.success(t(`Expense deleted`)),z(null),K(null)}catch(e){j.error(t(`Delete failed`),x(e))}},ze=async()=>{try{await Me.mutateAsync([...B]),j.success(t(`{n} expenses deleted`,{n:B.size})),V(new Set),U(!1),W(!1)}catch(e){j.error(t(`Delete failed`),x(e))}},$=async e=>{try{await Ne.mutateAsync(e.id),j.success(t(`Split recomputed`))}catch(e){j.error(t(`Recompute failed`),x(e))}},Be=(n=`xlsx`)=>e(`/export/expenses.${n}`,`expenses.${n}`,{from:D.from,to:D.to}).catch(e=>j.error(t(`Export failed`),x(e))),Ve=(0,T.useMemo)(()=>{let e=new Map;for(let t of q)e.set(t.date,[...e.get(t.date)??[],t]);return[...e.entries()]},[q]);return(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(n,{title:t(`Expenses`),subtitle:F.data?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(C,{minor:F.data.totals.amountMinor,className:`text-ink font-medium`}),` `,t(`across {n} entries`,{n:F.data.totals.count})]}):t(`Loading…`),actions:(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(fe,{trigger:()=>(0,E.jsx)(b,{variant:`secondary`,size:`sm`,icon:(0,E.jsx)(de,{className:`size-4`}),className:`rounded-full`,children:t(`More`)}),title:t(`Expenses`),children:e=>(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(g,{icon:H?(0,E.jsx)(pe,{}):(0,E.jsx)(me,{}),onClick:()=>{e(),U(e=>!e),V(new Set)},children:t(H?`Done selecting`:`Select entries`)}),(0,E.jsx)(g,{icon:(0,E.jsx)(v,{}),onClick:async()=>{e();try{let e=await Pe.mutateAsync({from:D.from,to:D.to});j.success(t(`Re-split {n} ownership-mode expenses`,{n:e.updated}))}catch(e){j.error(t(`Recompute failed`),x(e))}},children:t(`Re-split range by current ownership`)}),(0,E.jsx)(_,{}),(0,E.jsx)(g,{icon:(0,E.jsx)(h,{}),danger:!0,disabled:!B.size,onClick:()=>{e(),W(!0)},children:t(`Delete {n} selected`,{n:B.size||``})})]})}),(0,E.jsx)(b,{variant:`primary`,size:`sm`,className:`rounded-full max-md:hidden`,icon:(0,E.jsx)(ye,{className:`size-4`}),onClick:()=>L(null),children:t(`New expense`)})]})}),(0,E.jsx)(`div`,{className:`mb-3`,children:(0,E.jsx)(_e,{categories:De.data?.items.filter(e=>!e.archived)??[],stakeholders:Oe.data?.items??[],paymentMethods:N,stakeholderLabel:`Paid by`,onExport:Be})}),H&&q.length>0&&(0,E.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-2 card px-4 py-2 fade-up`,children:[(0,E.jsx)(y,{label:t(Y?`Deselect all on page`:`Select all on page`),checked:Y,onChange:Le}),(0,E.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,E.jsx)(b,{size:`xs`,variant:`ghost`,onClick:()=>{U(!1),V(new Set)},children:t(`Done`)}),(0,E.jsx)(b,{size:`xs`,variant:`danger`,disabled:!B.size,icon:(0,E.jsx)(h,{className:`size-3.5`}),onClick:()=>W(!0),children:t(`Delete {n}`,{n:B.size||``})})]})]}),Ee?(0,E.jsxs)(`div`,{className:`space-y-4`,children:[F.isPending&&(0,E.jsx)(s,{children:(0,E.jsx)(`div`,{className:`py-10 text-center text-ink-3`,children:t(`Loading…`)})}),!F.isPending&&!q.length&&(0,E.jsx)(s,{children:(0,E.jsx)(l,{title:t(`No expenses`),description:t(`Nothing matches this period and filters.`)})}),Ve.map(([e,n])=>(0,E.jsxs)(`section`,{children:[(0,E.jsxs)(`div`,{className:`flex items-baseline justify-between px-1 mb-1.5`,children:[(0,E.jsx)(`span`,{className:`label`,children:O(e,`long`)}),(0,E.jsx)(`span`,{className:`num text-[12px] text-ink-3`,children:k(n.reduce((e,t)=>e+t.amountMinor,0))})]}),(0,E.jsx)(`ul`,{className:`card divide-y divide-line overflow-hidden`,children:n.map(e=>(0,E.jsx)(`li`,{children:(0,E.jsxs)(`button`,{type:`button`,onClick:()=>H?X(e.id):K(e),className:i(`pressable w-full flex items-center gap-3 px-4 py-3 text-start`,B.has(e.id)&&`bg-accent-soft/50`),children:[H?(0,E.jsx)(`span`,{className:i(`size-6 rounded-full border-2 inline-flex items-center justify-center shrink-0`,B.has(e.id)?`bg-accent border-accent text-white`:`border-line-strong`),children:B.has(e.id)&&(0,E.jsx)(pe,{className:`size-3.5`})}):(0,E.jsx)(`span`,{className:`inline-flex items-center justify-center size-10 rounded-[12px] shrink-0`,style:{background:`${e.category?.color??`#999`}1f`},children:(0,E.jsx)(a,{color:e.category?.color??`#999`,size:10})}),(0,E.jsxs)(`span`,{className:`flex-1 min-w-0`,children:[(0,E.jsx)(`span`,{dir:`auto`,className:`block text-[15px] font-medium truncate`,children:e.description}),(0,E.jsxs)(`span`,{className:`block text-[12.5px] text-ink-3 truncate`,children:[e.category?r(e.category):``,e.payments.filter(e=>e.amountMinor>0).length>1?` · ${e.payments.filter(e=>e.amountMinor>0).map(e=>`${S(e)} ${k(e.amountMinor,{compact:!0})}`).join(` + `)}`:e.payments[0]?` · ${S(e.payments[0])}`:``,e.paidBy?` · ${r(e.paidBy)}`:` · ${t(`Company`)}`,e.splitMode===`custom`?` · ${t(`custom split`)}`:``]})]}),(0,E.jsx)(C,{minor:e.amountMinor,className:`text-[15px] font-semibold shrink-0`})]})},e.id))})]},e)),F.data&&(0,E.jsx)(`div`,{className:`card`,children:(0,E.jsx)(oe,{page:F.data.page,pageSize:F.data.pageSize,total:F.data.total,onPage:e=>A.set({page:String(e)})})})]}):(0,E.jsxs)(s,{flush:!0,children:[(0,E.jsxs)(ce,{children:[(0,E.jsx)(`thead`,{children:(0,E.jsxs)(`tr`,{children:[H&&(0,E.jsx)(p,{className:`w-10`,children:(0,E.jsx)(y,{checked:Y,onChange:Le,"aria-label":t(`Select all`)})}),(0,E.jsx)(p,{sortable:!0,sorted:Q(`date`),onSort:()=>Z(`date`),className:`w-28`,children:t(`Date`)}),(0,E.jsx)(p,{sortable:!0,sorted:Q(`description`),onSort:()=>Z(`description`),children:t(`Description`)}),(0,E.jsx)(p,{children:t(`Category`)}),(0,E.jsx)(p,{children:t(`Paid by`)}),J.map(e=>(0,E.jsx)(p,{align:e.type===`money`||e.type===`number`?`right`:`left`,children:o(e)},e.id)),N.map(e=>(0,E.jsx)(p,{align:`right`,children:(0,E.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,E.jsx)(a,{color:e.color}),r(e)]})},e.id)),(0,E.jsx)(p,{align:`right`,sortable:!0,sorted:Q(`amountMinor`),onSort:()=>Z(`amountMinor`),className:`w-36`,children:N.length?t(`Total`):t(`Amount`)}),(0,E.jsx)(p,{className:`w-12`})]})}),(0,E.jsxs)(`tbody`,{children:[F.isPending&&(0,E.jsx)(le,{colSpan:8+J.length+N.length,children:t(`Loading…`)}),!F.isPending&&!q.length&&(0,E.jsx)(le,{colSpan:8+J.length+N.length,children:t(`No expenses match. Try a wider period or clear filters.`)}),q.map(e=>(0,E.jsxs)(se,{selected:B.has(e.id),className:`cursor-pointer`,onClick:()=>H?X(e.id):K(e),children:[H&&(0,E.jsx)(m,{onClick:e=>e.stopPropagation(),children:(0,E.jsx)(y,{checked:B.has(e.id),onChange:()=>X(e.id),"aria-label":t(`Select`)})}),(0,E.jsx)(m,{className:`num text-ink-2 whitespace-nowrap`,children:O(e.date)}),(0,E.jsxs)(m,{children:[(0,E.jsx)(`div`,{dir:`auto`,className:`font-medium truncate max-w-[380px]`,children:e.description}),(e.vendor||e.recurringRuleId||e.splitMode===`custom`)&&(0,E.jsx)(`div`,{className:`text-[12px] text-ink-3 truncate`,children:[e.vendor,e.recurringRuleId&&t(`recurring`),e.splitMode===`custom`&&t(`custom split`)].filter(Boolean).join(` · `)})]}),(0,E.jsx)(m,{children:e.category&&(0,E.jsx)(c,{color:e.category.color,children:r(e.category)})}),(0,E.jsx)(m,{children:e.paidBy?(0,E.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,E.jsx)(u,{name:r(e.paidBy),color:e.paidBy.color,size:22}),(0,E.jsx)(`span`,{className:`truncate`,children:r(e.paidBy)})]}):(0,E.jsx)(`span`,{className:`text-ink-3`,children:t(`Company`)})}),J.map(t=>(0,E.jsx)(m,{align:t.type===`money`||t.type===`number`?`right`:`left`,children:(0,E.jsx)(w,{def:t,value:e.customFields?.[t.key]})},t.id)),N.map(n=>{let i=e.payments.find(e=>e.paymentMethodId===n.id);return(0,E.jsx)(m,{align:`right`,onClick:e=>e.stopPropagation(),children:i&&i.amountMinor>0?(0,E.jsx)(`button`,{type:`button`,className:`num hover:text-accent`,title:t(`Edit {method} amount`,{method:r(n)}),onClick:()=>P({kind:`expense`,entry:e,method:n}),children:k(i.amountMinor)}):(0,E.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 text-[12.5px] font-medium text-accent/80 hover:text-accent whitespace-nowrap`,onClick:()=>P({kind:`expense`,entry:e,method:n}),children:[(0,E.jsx)(ye,{className:`size-3.5`}),t(`Add {method}`,{method:r(n)})]})},n.id)}),(0,E.jsx)(m,{align:`right`,children:(0,E.jsx)(C,{minor:e.amountMinor,className:`font-semibold`})}),(0,E.jsx)(m,{onClick:e=>e.stopPropagation(),children:(0,E.jsx)(fe,{trigger:()=>(0,E.jsx)(`button`,{type:`button`,className:`size-8 inline-flex items-center justify-center rounded-full text-ink-3 hover:text-ink hover:bg-card-hover`,"aria-label":t(`Actions`),children:(0,E.jsx)(de,{className:`size-4`})}),children:n=>(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(g,{icon:(0,E.jsx)(ue,{}),onClick:()=>{n(),L(e)},children:t(`Edit`)}),(0,E.jsx)(g,{icon:(0,E.jsx)(v,{}),onClick:()=>{n(),$(e)},children:t(`Re-split by current ownership`)}),(0,E.jsx)(_,{}),(0,E.jsx)(g,{icon:(0,E.jsx)(h,{}),danger:!0,onClick:()=>{n(),z(e)},children:t(`Delete`)})]})})})]},e.id))]})]}),F.data&&(0,E.jsx)(oe,{page:F.data.page,pageSize:F.data.pageSize,total:F.data.total,onPage:e=>A.set({page:String(e)})})]}),(0,E.jsx)(Te,{expense:G,onClose:()=>K(null),onEdit:()=>{L(G),K(null)},onDelete:()=>z(G),onRecompute:()=>G&&$(G),defs:J}),(0,E.jsx)(Se,{open:Fe!==void 0,onClose:()=>L(void 0),expense:Fe??null}),(0,E.jsx)(ge,{target:Ae,onClose:()=>P(null)}),(0,E.jsx)(xe,{open:!!R,onClose:()=>z(null),onConfirm:Re,loading:I.isPending,title:t(`Delete this expense?`),description:R?t(`{description} · {amount} on {date}.`,{description:R.description,amount:k(R.amountMinor),date:O(R.date)}):``}),(0,E.jsx)(xe,{open:Ie,onClose:()=>W(!1),onConfirm:ze,loading:Me.isPending,title:t(`Delete {n} expenses?`,{n:B.size}),description:t(`This cannot be undone. Export first if you want a copy.`)})]})}function Te({expense:e,onClose:t,onEdit:n,onDelete:r,onRecompute:i,defs:a}){let{t:o,name:s,label:c}=ee(),l=e=>s({name:e.name??``,nameAr:e.nameAr}),{money:u,date:te}=f(),d=e;return(0,E.jsx)(S,{open:!!d,onClose:t,title:d?.description??``,description:d?`${te(d.date,`long`)} · ${d.category?s(d.category):``}`:``,width:480,footer:d&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(b,{variant:`ghost`,size:`md`,onClick:()=>{i()},children:o(`Re-split`)}),(0,E.jsx)(b,{variant:`danger`,size:`md`,onClick:()=>{r()},children:o(`Delete`)}),(0,E.jsx)(b,{variant:`primary`,size:`md`,onClick:n,children:o(`Edit`)})]}),children:d&&(0,E.jsxs)(`div`,{className:`space-y-4`,children:[(0,E.jsx)(`div`,{className:`num text-[32px] font-semibold tracking-tight`,children:u(d.amountMinor)}),(0,E.jsxs)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-4 gap-y-2 text-[14px]`,children:[d.payments.filter(e=>e.amountMinor>0).map(e=>(0,E.jsxs)(`span`,{className:`contents`,children:[(0,E.jsx)(`dt`,{className:`text-ink-3`,children:l(e)}),(0,E.jsx)(`dd`,{className:`num`,children:u(e.amountMinor)})]},e.paymentMethodId)),(0,E.jsx)(`dt`,{className:`text-ink-3`,children:o(`Paid by`)}),(0,E.jsx)(`dd`,{className:`font-medium`,children:d.paidBy?s(d.paidBy):o(`Company account`)}),d.vendor&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`dt`,{className:`text-ink-3`,children:o(`Vendor`)}),(0,E.jsx)(`dd`,{children:d.vendor})]}),a.map(e=>(0,E.jsxs)(`span`,{className:`contents`,children:[(0,E.jsx)(`dt`,{className:`text-ink-3`,children:c(e)}),(0,E.jsx)(`dd`,{children:(0,E.jsx)(w,{def:e,value:d.customFields?.[e.key]})})]},e.id)),d.notes&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`dt`,{className:`text-ink-3`,children:o(`Notes`)}),(0,E.jsx)(`dd`,{className:`whitespace-pre-wrap`,children:d.notes})]})]}),(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`div`,{className:`label mb-2`,children:d.splitMode===`custom`?o(`Split (custom)`):o(`Split (by ownership)`)}),(0,E.jsxs)(`ul`,{className:`rounded-[14px] border border-line divide-y divide-line`,children:[d.splits.map(e=>(0,E.jsxs)(`li`,{className:`flex items-center justify-between px-3.5 h-11 text-[14px]`,children:[(0,E.jsxs)(`span`,{children:[e.stakeholderName??e.stakeholderId,` `,(0,E.jsxs)(`span`,{className:`num text-ink-3 text-[12.5px]`,children:[e.sharePercent.toFixed(e.sharePercent%1?2:0),`%`]})]}),(0,E.jsx)(`span`,{className:`num font-medium`,children:u(e.amountMinor)})]},e.id)),!d.splits.length&&(0,E.jsx)(`li`,{className:`px-3.5 py-3 text-[13px] text-ink-3`,children:o(`No stakeholders at the time of entry.`)})]})]})]})})}export{D as ExpensesPage};