@accounter/client
Version:
Accounter client application
1 lines • 23.8 kB
JavaScript
import{s as e}from"./dist-ypP48_Ax.js";import{i as t,o as n,t as r}from"./utils-CbS-oR5I.js";import{r as i}from"./error-handling-CKe_iwSC.js";import{t as a}from"./createLucideIcon-BK8Z-P8J.js";import{Hr as o,St as s,Vr as c,X as l,ar as u,f as d,gt as f,lr as ee,n as te,ot as p,qt as ne,tt as m,wr as h,yt as re}from"./common-DtCH-1rN.js";import{a as ie,c as ae,f as oe,i as se,l as ce,lt as le,m as ue,n as de,o as fe,p as pe,r as me,s as he,t as ge,u as _e,ut as ve}from"./select-DrAHsHyM.js";import{b as ye}from"./separator-C_NTzotM.js";import{t as be}from"./funnel-CtGZVesZ.js";import{t as xe}from"./info-DVp5JTix.js";import{n as Se}from"./routes-4W-duEv9.js";import{t as g}from"./button-DUNsVBiu.js";import{i as Ce,n as we,r as Te,t as Ee}from"./accordion-Bfa7-As4.js";import{$c as _,Bc as v,Fl as y,Gc as b,Hc as x,Ht as S,Il as C,Kc as w,Ln as T,Pl as De,Qc as E,Rl as D,Rt as O,Vc as Oe,Wc as k,Xn as A,Yc as ke,Zc as Ae,du as je,f as Me,jt as j,nl as Ne,qc as M,tu as N}from"./table-BXolY871.js";import{Zt as P,i as F,ln as I,ls as Pe,sn as L,v as Fe,xr as R}from"./graphql-HKLcNTdf.js";import{t as Ie}from"./subDays-DkM1tAkf.js";import{t as z}from"./dates-B0_BnCV6.js";import{D as B}from"./index-U1vN7cBF.js";import{t as Le}from"./use-url-query-C3m3Z87n.js";import{t as Re}from"./use-get-financial-accounts-D8VMrCHV.js";var ze=a(`rotate-ccw`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}]]);function Be(e,t){let n=je(e,t?.in),r=n.getMonth(),i=r-r%3;return n.setMonth(i,1),n.setHours(0,0,0,0),n}var V=e(n(),1),Ve=e(De(),1),H=[`withoutInvoice`,`withoutReceipt`,`withoutDocuments`,`withoutTransactions`,`withoutLedger`,`withoutTags`,`withOpenDocuments`,`withMissingCounterparty`,`unbalanced`],U=e=>+!!e.fromAnyDate+ +!!e.toAnyDate,W=e=>(e.byOwners?.length??0)+(e.byBusinesses?.length??0)+(e.excludedBusinesses?.length??0)+(e.byFinancialAccounts?.length??0)+(e.excludedFinancialAccounts?.length??0)+(e.byTags?.length??0)+(e.excludedTags?.length??0)+(e.byBusinessTrips?.length??0),He=e=>(e.chargesType&&e.chargesType!==P.All?1:0)+(e.byChargeTypes?.length??0)+(e.accountantStatus?.length??0),Ue=e=>H.filter(t=>e[t]).length,We=e=>+!!e.freeText+ +!!e.excludedFreeText,Ge=e=>U(e)+W(e)+He(e)+Ue(e)+We(e),G=t(),Ke=8,qe={withoutInvoice:`Without invoice`,withoutReceipt:`Without receipts`,withoutDocuments:`Without documents`,withoutTransactions:`Without transactions`,withoutLedger:`Without ledger`,withoutTags:`Without tags`,withOpenDocuments:`With open documents`,withMissingCounterparty:`Missing counterparty`,unbalanced:`Unbalanced businesses`};function Je(e,t,n){let r=[],i={shouldDirty:!0,shouldValidate:!0},a=(e,t)=>e.find(e=>e.value===t)?.label??t,o=(t,o,s=!1)=>{for(let c of e[t]??[])r.push({key:`${t}-${c}`,label:a(o,c),excluded:s,onRemove:()=>{let r=e[t].filter(e=>e!==c);n(t,r.length>0?r:void 0,i)}})};e.freeText&&r.push({key:`freeText`,label:`"${e.freeText}"`,onRemove:()=>n(`freeText`,void 0,i)}),e.excludedFreeText&&r.push({key:`excludedFreeText`,label:`"${e.excludedFreeText}"`,excluded:!0,onRemove:()=>n(`excludedFreeText`,void 0,i)}),e.fromAnyDate&&r.push({key:`fromAnyDate`,label:`From ${e.fromAnyDate}`,onRemove:()=>n(`fromAnyDate`,void 0,i)}),e.toAnyDate&&r.push({key:`toAnyDate`,label:`To ${e.toAnyDate}`,onRemove:()=>n(`toAnyDate`,void 0,i)}),o(`byOwners`,t.owners),o(`byBusinesses`,t.businesses),o(`excludedBusinesses`,t.businesses,!0),o(`byFinancialAccounts`,t.financialAccounts),o(`excludedFinancialAccounts`,t.financialAccounts,!0),o(`byTags`,t.tags),o(`excludedTags`,t.tags,!0),o(`byBusinessTrips`,t.businessTrips),e.chargesType&&e.chargesType!==P.All&&r.push({key:`chargesType`,label:e.chargesType===P.Income?`Income`:`Expense`,onRemove:()=>n(`chargesType`,P.All,i)}),o(`byChargeTypes`,t.chargeTypes),o(`accountantStatus`,t.accountantStatus);for(let t of H)e[t]&&r.push({key:t,label:qe[t],onRemove:()=>n(t,void 0,i)});return r}function Ye({sources:e,onClearAll:t}){let{setValue:n}=E(),i=_(),a=(0,V.useMemo)(()=>Je(i,e,n),[i,e,n]);if(a.length===0)return null;let o=a.length>Ke?a.slice(0,7):a,s=a.length-o.length;return(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[o.map(e=>(0,G.jsxs)(v,{variant:`outline`,className:r(`gap-1 py-1 pr-1`,e.excluded?`border-destructive/40 bg-destructive/5 text-destructive`:`border-border bg-secondary text-secondary-foreground`),children:[e.excluded&&(0,G.jsx)(h,{className:`size-3 shrink-0`}),(0,G.jsx)(`span`,{className:`max-w-48 truncate`,children:e.label}),(0,G.jsx)(`button`,{type:`button`,onClick:e.onRemove,"aria-label":`Remove ${e.label}`,className:`flex items-center rounded-sm opacity-60 hover:opacity-100`,children:(0,G.jsx)(le,{className:`size-3`})})]},e.key)),s>0&&(0,G.jsx)(v,{variant:`secondary`,className:`py-1 font-normal text-muted-foreground`,children:`${s} more filters`}),(0,G.jsx)(g,{type:`button`,variant:`ghost`,size:`sm`,onClick:t,className:`h-6 px-2 text-xs text-muted-foreground`,children:`Clear all`})]})}var Xe=[{label:`All`,value:P.All},{label:`Income`,value:P.Income},{label:`Expense`,value:P.Expense}],Ze=[{label:`Bank Deposit`,value:I.BankDeposit},{label:`Business Trip`,value:I.BusinessTrip},{label:`Common`,value:I.Common},{label:`Conversion`,value:I.Conversion},{label:`Credit Card Bank`,value:I.CreditcardBank},{label:`Dividend`,value:I.Dividend},{label:`Financial`,value:I.Financial},{label:`Foreign Securities`,value:I.ForeignSecurities},{label:`Internal Transfer`,value:I.Internal},{label:`Monthly VAT`,value:I.Vat},{label:`Salary`,value:I.Payroll}],Qe=[{label:`Date`,value:L.Date},{label:`Amount`,value:L.Amount},{label:`Abs Amount`,value:L.AbsAmount}],K={[R.BankAccount]:`Bank Accounts`,[R.CreditCard]:`Credit Cards`,[R.CryptoWallet]:`Crypto Wallets`,[R.BankDepositAccount]:`Bank Deposits`,[R.ForeignSecurities]:`Foreign Securities`},$e=[K[R.BankAccount],K[R.CreditCard],K[R.BankDepositAccount],K[R.ForeignSecurities],K[R.CryptoWallet]],et=[{label:`Last 30 days`,range:()=>({fromAnyDate:z(Ie(new Date,30)),toAnyDate:z(new Date)})},{label:`This quarter`,range:()=>({fromAnyDate:z(Be(new Date)),toAnyDate:z(new Date)})},{label:`This year`,range:()=>({fromAnyDate:z(N(new Date)),toAnyDate:z(new Date)})},{label:`Last year`,range:()=>{let e=B(new Date,1);return{fromAnyDate:z(N(e)),toAnyDate:z(ee(e))}}},{label:`No range`,range:()=>({fromAnyDate:void 0,toAnyDate:void 0})}];function q(){return{sortBy:{field:L.Date,asc:!1},chargesType:P.All}}function tt({adminBusinessId:e,withDefaultDateRange:t}){return{...q(),byOwners:e?[e]:void 0,...t?{fromAnyDate:z(B(new Date,1)),toAnyDate:z(new Date)}:{}}}function nt({selector:e}){let t=e(_());return t?(0,G.jsx)(v,{className:`size-5 shrink-0 justify-center rounded-full p-0 text-xs tabular-nums`,children:t}):null}function J({value:e,label:t,selector:n,children:r}){return(0,G.jsxs)(Te,{value:e,className:`border-b last:border-b-0`,children:[(0,G.jsx)(Ce,{className:`mx-0 my-0 px-4 py-3 hover:no-underline`,children:(0,G.jsxs)(`span`,{className:`flex items-center gap-2 text-sm font-medium`,children:[t,n&&(0,G.jsx)(nt,{selector:n})]})}),(0,G.jsx)(we,{className:`mx-0 space-y-4 px-4 pb-4`,children:r})]})}function rt({control:e}){let{setValue:t}=E(),n=_({control:e,name:`freeText`}),i=_({control:e,name:`excludedFreeText`}),a=!!i,o=a?`excludedFreeText`:`freeText`;function s(){let e=a?i:n,r={shouldDirty:!0,shouldValidate:!0};a?(t(`excludedFreeText`,void 0,r),t(`freeText`,e,r)):(t(`freeText`,void 0,r),t(`excludedFreeText`,e,r))}return(0,G.jsxs)(`div`,{className:`border-b px-4 py-3`,children:[(0,G.jsxs)(`div`,{className:`mb-2 flex items-center justify-between`,children:[(0,G.jsx)(fe,{htmlFor:`charges-free-text`,children:`Free Text`}),(0,G.jsxs)(y,{children:[(0,G.jsx)(D,{asChild:!0,children:(0,G.jsxs)(`button`,{type:`button`,onClick:s,"aria-label":a?`Switch to include`:`Switch to exclude`,className:r(`inline-flex items-center gap-0.5 rounded-md border px-1.5 py-0.5 text-xs font-medium transition-colors`,a?`border-destructive/40 bg-destructive/5 text-destructive hover:bg-destructive/10`:`border-border bg-secondary text-muted-foreground hover:bg-muted`),children:[a?(0,G.jsx)(h,{className:`size-3`}):(0,G.jsx)(ve,{className:`size-3`}),a?`Excludes`:`Contains`]})}),(0,G.jsx)(C,{children:(0,G.jsxs)(`p`,{children:[`Click to `,a?`include`:`exclude`,` charges matching this text`]})})]})]}),(0,G.jsx)(k,{control:e,name:o,render:({field:e,fieldState:t})=>(0,G.jsxs)(b,{className:`h-min`,children:[(0,G.jsx)(x,{children:(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(ye,{className:`pointer-events-none absolute top-1/2 left-2.5 size-4 -translate-y-1/2 text-muted-foreground`}),(0,G.jsx)(he,{...e,id:`charges-free-text`,value:e.value??``,onChange:t=>e.onChange(t.target.value||void 0),placeholder:a?`Exclude charges containing...`:`Search descriptions, references...`,"aria-invalid":!!t.error,className:r(`pl-8`,a&&`border-destructive/40 bg-destructive/5`)})]})}),(0,G.jsx)(M,{})]})})]})}var it=A().regex(u,`Date must be in format yyyy-mm-dd`).optional(),Y=O(A()).optional(),at=A().optional().refine(e=>!e||e.trim().length===0||e.trim().length>=2,`Must be at least 2 characters`),ot=T({fromAnyDate:it,toAnyDate:it,byOwners:Y,byBusinesses:Y,excludedBusinesses:Y,byFinancialAccounts:Y,excludedFinancialAccounts:Y,byTags:Y,excludedTags:Y,byBusinessTrips:Y,chargesType:j(P).optional(),byChargeTypes:O(j(I)).optional(),accountantStatus:O(j(F)).optional(),freeText:at,excludedFreeText:at,withoutInvoice:S().optional(),withoutReceipt:S().optional(),withoutDocuments:S().optional(),withoutTransactions:S().optional(),withoutLedger:S().optional(),withoutTags:S().optional(),withOpenDocuments:S().optional(),withMissingCounterparty:S().optional(),unbalanced:S().optional(),sortBy:T({field:j(L),asc:S()})}).refine(e=>!e.fromAnyDate||!e.toAnyDate||e.fromAnyDate<=e.toAnyDate,{message:`From date must not be after To date`,path:[`fromAnyDate`]});function st(e,t){let n=Object.fromEntries(Object.entries(e).filter(([,e])=>e!=null)),r={...t,...n},i=ot.safeParse(r);return i.success?i.data:t}function ct(e){let t=e=>e?.trim()||void 0,n=e=>e&&e.length>0?e:void 0,r=e=>e||void 0;return{fromAnyDate:e.fromAnyDate,toAnyDate:e.toAnyDate,byOwners:n(e.byOwners),byBusinesses:n(e.byBusinesses),excludedBusinesses:n(e.excludedBusinesses),byFinancialAccounts:n(e.byFinancialAccounts),excludedFinancialAccounts:n(e.excludedFinancialAccounts),byTags:n(e.byTags),excludedTags:n(e.excludedTags),byBusinessTrips:n(e.byBusinessTrips),chargesType:e.chargesType&&e.chargesType!==P.All?e.chargesType:void 0,byChargeTypes:n(e.byChargeTypes),accountantStatus:n(e.accountantStatus),freeText:t(e.freeText),excludedFreeText:t(e.excludedFreeText),withoutInvoice:r(e.withoutInvoice),withoutReceipt:r(e.withoutReceipt),withoutDocuments:r(e.withoutDocuments),withoutTransactions:r(e.withoutTransactions),withoutLedger:r(e.withoutLedger),withoutTags:r(e.withoutTags),withOpenDocuments:r(e.withOpenDocuments),withMissingCounterparty:r(e.withMissingCounterparty),unbalanced:r(e.unbalanced),sortBy:e.sortBy}}var X=e=>e.length>0?e:void 0;function Z({control:e,include:t,exclude:n,label:r,options:i,loading:a,placeholder:o,searchPlaceholder:s,groupBy:c,groupOrder:l,renderOption:u}){let{field:d}=ke({control:e,name:n});return(0,G.jsx)(k,{control:e,name:t,render:({field:e})=>(0,G.jsxs)(b,{className:`h-min`,children:[(0,G.jsx)(w,{children:r}),(0,G.jsx)(x,{children:(0,G.jsx)(m,{ref:e.ref,onBlur:e.onBlur,negatable:!0,options:i,value:e.value??[],onValueChange:t=>e.onChange(X(t)),excludedValue:d.value??[],onExcludedChange:e=>d.onChange(X(e)),loading:a,placeholder:o,searchPlaceholder:s,groupBy:c,groupOrder:l,renderOption:u,"aria-label":r})}),(0,G.jsx)(M,{})]})})}function Q({control:e,name:t,label:n,options:r,loading:i,placeholder:a,searchPlaceholder:o,renderOption:s}){return(0,G.jsx)(k,{control:e,name:t,render:({field:e})=>(0,G.jsxs)(b,{className:`h-min`,children:[(0,G.jsx)(w,{children:n}),(0,G.jsx)(x,{children:(0,G.jsx)(m,{ref:e.ref,onBlur:e.onBlur,options:r,value:e.value??[],onValueChange:t=>e.onChange(X(t)),loading:i,placeholder:a,searchPlaceholder:o,renderOption:s,"aria-label":n})}),(0,G.jsx)(M,{})]})})}var lt=[F.Approved,F.Pending,F.Unapproved];function ut({control:e}){return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(k,{name:`chargesType`,control:e,render:({field:e})=>(0,G.jsxs)(b,{className:`h-min`,children:[(0,G.jsx)(w,{children:`Income / Expense`}),(0,G.jsx)(x,{children:(0,G.jsx)(`div`,{className:`flex gap-1.5`,children:Xe.map(t=>{let n=(e.value??P.All)===t.value;return(0,G.jsx)(g,{type:`button`,variant:n?`default`:`outline`,size:`sm`,className:`flex-1`,"aria-pressed":n,onClick:()=>e.onChange(t.value),children:t.label},t.value)})})}),(0,G.jsx)(M,{})]})}),(0,G.jsx)(Q,{control:e,name:`byChargeTypes`,label:`Charge Type`,options:Ze,placeholder:`All charge types`,searchPlaceholder:`Search charge types...`}),(0,G.jsx)(k,{name:`accountantStatus`,control:e,render:({field:e})=>(0,G.jsxs)(b,{className:`h-min`,children:[(0,G.jsx)(w,{children:`Accountant Status`}),(0,G.jsx)(x,{children:(0,G.jsx)(`div`,{className:`flex gap-2`,children:lt.map(t=>{let n=l[t],i=n.icon,a=(e.value??[]).includes(t);return(0,G.jsxs)(g,{type:`button`,variant:`outline`,"aria-pressed":a,className:r(`h-auto flex-1 flex-col gap-1 py-2 text-xs font-medium`,a?`border-primary bg-accent`:n.bgColor),onClick:()=>{let n=e.value??[],r=a?n.filter(e=>e!==t):[...n,t];e.onChange(r.length>0?r:void 0)},children:[(0,G.jsx)(i,{className:r(`size-4`,a?n.color:`text-muted-foreground`)}),n.label]},t)})})}),(0,G.jsx)(M,{})]})})]})}var dt=[{name:`withoutInvoice`,label:`Without Invoice`},{name:`withoutReceipt`,label:`Without Receipts`},{name:`withoutDocuments`,label:`Without Documents`},{name:`withoutTransactions`,label:`Without Transactions`},{name:`withoutLedger`,label:`Without Ledger`},{name:`withoutTags`,label:`Without Tags`}],ft=[{name:`withOpenDocuments`,label:`With Open Documents`,tooltip:`Show only charges with documents that are currently open`},{name:`withMissingCounterparty`,label:`Missing Counterparty`,tooltip:`Show charges with a transaction missing a business, or a document missing a creditor / debtor`},{name:`unbalanced`,label:`Unbalanced Businesses`}];function $({control:e,def:t}){return(0,G.jsx)(k,{control:e,name:t.name,render:({field:e})=>(0,G.jsxs)(b,{className:`flex flex-row items-center justify-between px-3 py-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(w,{className:`font-normal`,children:t.label}),t.tooltip&&(0,G.jsxs)(y,{children:[(0,G.jsx)(D,{asChild:!0,children:(0,G.jsx)(`button`,{type:`button`,"aria-label":`About ${t.label}`,className:`flex`,children:(0,G.jsx)(xe,{className:`size-3.5 text-muted-foreground`})})}),(0,G.jsx)(C,{className:`max-w-56`,children:(0,G.jsx)(`p`,{children:t.tooltip})})]})]}),(0,G.jsx)(x,{children:(0,G.jsx)(re,{checked:e.value??!1,onCheckedChange:t=>e.onChange(t||void 0)})})]})})}function pt({control:e}){return(0,G.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs font-medium tracking-wide text-muted-foreground uppercase`,children:`Missing data`}),(0,G.jsx)(`div`,{className:`divide-y rounded-lg border`,children:dt.map(t=>(0,G.jsx)($,{control:e,def:t},t.name))})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs font-medium tracking-wide text-muted-foreground uppercase`,children:`Charge state`}),(0,G.jsx)(`div`,{className:`divide-y rounded-lg border`,children:ft.map(t=>(0,G.jsx)($,{control:e,def:t},t.name))})]})]})}function mt({control:e}){let{setValue:t}=E();return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:et.map(e=>(0,G.jsx)(g,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 rounded-full text-xs font-normal`,onClick:()=>{let{fromAnyDate:n,toAnyDate:r}=e.range(),i={shouldDirty:!0,shouldValidate:!0};t(`fromAnyDate`,n,i),t(`toAnyDate`,r,i)},children:e.label},e.label))}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsx)(k,{name:`fromAnyDate`,control:e,render:({field:e,fieldState:t})=>(0,G.jsxs)(b,{className:`h-min`,children:[(0,G.jsx)(w,{htmlFor:`from-any-date`,children:`From Date`}),(0,G.jsx)(x,{children:(0,G.jsx)(p,{id:`from-any-date`,value:e.value??void 0,onChange:t=>{t!==e.value&&e.onChange(t??void 0)},"aria-invalid":!!t.error})}),(0,G.jsx)(M,{})]})}),(0,G.jsx)(k,{name:`toAnyDate`,control:e,render:({field:e,fieldState:t})=>(0,G.jsxs)(b,{className:`h-min`,children:[(0,G.jsx)(w,{htmlFor:`to-any-date`,children:`To Date`}),(0,G.jsx)(x,{children:(0,G.jsx)(p,{id:`to-any-date`,value:e.value??void 0,onChange:t=>{t!==e.value&&e.onChange(t??void 0)},"aria-invalid":!!t.error})}),(0,G.jsx)(M,{})]})})]})]})}var ht=()=>{let[{data:e,fetching:t,error:n},r]=Pe({query:Fe});n&&(console.error(`Error fetching business trips: ${n}`),i.error(`Error`,{description:`Unable to fetch business trips`}));let a=(0,V.useMemo)(()=>[...e?.allBusinessTrips??[]].sort((e,t)=>e.name>t.name?1:-1),[e]);return{fetching:t,refresh:()=>r(),businessTrips:a,selectableBusinessTrips:(0,V.useMemo)(()=>a.map(e=>({value:e.id,label:e.name})),[a])}};function gt(){let{selectableAdminBusinesses:e,fetching:t}=d(),{selectableFinancialEntities:n,fetching:r}=f(),{selectableFinancialAccounts:i,fetching:a}=Re(),{selectableTags:o,fetching:c}=s(),{selectableBusinessTrips:l,fetching:u}=ht();return{owners:e,ownersFetching:t,financialEntities:n,financialEntitiesFetching:r,financialAccounts:(0,V.useMemo)(()=>i.map(e=>({value:e.value,label:e.label,group:K[e.type]})),[i]),financialAccountsFetching:a,tags:o,tagsFetching:c,businessTrips:l,businessTripsFetching:u,fetching:t||r||a||c||u}}function _t({control:e,data:t}){let n=_({control:e,name:`byChargeTypes`}),r=_({control:e,name:`byBusinessTrips`}),i=_({control:e,name:`byOwners`}),a=t.owners.length>1||(i?.length??0)>0,o=(n??[]).includes(I.BusinessTrip)||(r?.length??0)>0;return(0,G.jsxs)(G.Fragment,{children:[a&&(0,G.jsx)(Q,{control:e,name:`byOwners`,label:`Owners`,options:t.owners,loading:t.ownersFetching,placeholder:`All my businesses`,searchPlaceholder:`Search owners...`}),(0,G.jsx)(Z,{control:e,include:`byBusinesses`,exclude:`excludedBusinesses`,label:`Financial Entities`,options:t.financialEntities,loading:t.financialEntitiesFetching,placeholder:`All counterparties`,searchPlaceholder:`Search counterparties...`}),(0,G.jsx)(Z,{control:e,include:`byFinancialAccounts`,exclude:`excludedFinancialAccounts`,label:`Financial Accounts`,options:t.financialAccounts,loading:t.financialAccountsFetching,placeholder:`All accounts`,searchPlaceholder:`Search accounts...`,groupOrder:$e}),(0,G.jsx)(Z,{control:e,include:`byTags`,exclude:`excludedTags`,label:`Tags`,options:t.tags,loading:t.tagsFetching,placeholder:`All tags`,searchPlaceholder:`Search tags or paths...`}),o&&(0,G.jsx)(Q,{control:e,name:`byBusinessTrips`,label:`Business Trips`,options:t.businessTrips,loading:t.businessTripsFetching,placeholder:`All trips`,searchPlaceholder:`Search trips...`})]})}function vt({control:e}){let t=ne();return(0,G.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,G.jsx)(k,{name:`sortBy.field`,control:e,render:({field:e})=>(0,G.jsxs)(b,{className:`h-min min-w-40 flex-1`,children:[(0,G.jsx)(w,{children:`Field to sort by`}),(0,G.jsxs)(ge,{value:e.value??L.Date,onValueChange:t=>e.onChange(t),children:[(0,G.jsx)(x,{children:(0,G.jsx)(se,{className:`w-full`,children:(0,G.jsx)(ie,{})})}),(0,G.jsx)(de,{container:t,children:Qe.map(e=>(0,G.jsx)(me,{value:e.value,children:e.label},e.value))})]}),(0,G.jsx)(M,{})]})}),(0,G.jsx)(k,{name:`sortBy.asc`,control:e,render:({field:e})=>(0,G.jsxs)(b,{className:`h-min`,children:[(0,G.jsx)(w,{children:`Direction`}),(0,G.jsx)(x,{children:(0,G.jsxs)(`div`,{className:`flex gap-1`,children:[(0,G.jsxs)(g,{type:`button`,size:`sm`,variant:e.value===!0?`default`:`outline`,"aria-pressed":e.value===!0,onClick:()=>e.onChange(!0),children:[(0,G.jsx)(c,{className:`size-3.5`}),`Asc`]}),(0,G.jsxs)(g,{type:`button`,size:`sm`,variant:e.value===!1?`default`:`outline`,"aria-pressed":e.value===!1,onClick:()=>e.onChange(!1),children:[(0,G.jsx)(o,{className:`size-3.5`}),`Desc`]})]})}),(0,G.jsx)(M,{})]})})]})}function yt(){let e=Ge(_());return e?(0,G.jsxs)(_e,{children:[e,` filter`,e===1?``:`s`,` active`]}):null}function bt({filter:e,setFilter:t,closeModal:n,withDefaultDateRange:r=!0}){let{userContext:i}=(0,V.useContext)(Ne),a=gt(),o=(0,V.useMemo)(()=>tt({adminBusinessId:i?.context.adminBusinessId,withDefaultDateRange:r}),[i?.context.adminBusinessId,r]),s=Ae({resolver:Me(ot),mode:`onChange`,defaultValues:st(e,o)}),{control:c,handleSubmit:u}=s,d=(0,V.useMemo)(()=>({owners:a.owners,businesses:a.financialEntities,financialAccounts:a.financialAccounts,tags:a.tags,businessTrips:a.businessTrips,chargeTypes:Ze,accountantStatus:Object.values(l)}),[a]),f=e=>{t(ct(e)),n()};return(0,G.jsx)(Oe,{...s,children:(0,G.jsxs)(`form`,{onSubmit:u(f),className:`flex min-h-0 flex-1 flex-col`,children:[(0,G.jsxs)(oe,{className:`shrink-0 space-y-2 border-b px-5 py-4 text-left`,children:[(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsx)(pe,{children:`Filter Charges`}),(0,G.jsx)(yt,{})]}),(0,G.jsx)(Ye,{sources:d,onClearAll:()=>s.reset(q())})]}),(0,G.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:[(0,G.jsx)(rt,{control:c}),(0,G.jsxs)(Ee,{type:`multiple`,defaultValue:[`dates`,`entities`,`classification`],children:[(0,G.jsx)(J,{value:`dates`,label:`Date Range`,selector:U,children:(0,G.jsx)(mt,{control:c})}),(0,G.jsx)(J,{value:`entities`,label:`Entities`,selector:W,children:(0,G.jsx)(_t,{control:c,data:a})}),(0,G.jsx)(J,{value:`classification`,label:`Classification`,selector:He,children:(0,G.jsx)(ut,{control:c})}),(0,G.jsx)(J,{value:`completeness`,label:`Completeness`,selector:Ue,children:(0,G.jsx)(pt,{control:c})}),(0,G.jsx)(J,{value:`sort`,label:`Sorting`,children:(0,G.jsx)(vt,{control:c})})]})]}),(0,G.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-2 border-t bg-secondary/30 px-5 py-3`,children:[(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(g,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>s.reset(o),children:[(0,G.jsx)(ze,{className:`size-3.5`}),`Reset`]}),(0,G.jsx)(g,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>s.reset(q()),children:`Clear all`})]}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(g,{type:`button`,variant:`outline`,size:`sm`,onClick:n,children:`Cancel`}),(0,G.jsx)(g,{type:`submit`,size:`sm`,disabled:a.fetching,children:`Apply`})]})]})]})})}function xt({filter:e={},setFilter:t,activePage:n,setPage:r,totalPages:i=1,initiallyOpened:a=!1,withDefaultDateRange:o=!0}){let[s,c]=(0,V.useState)(a),{get:l,set:u}=Le(),d=(0,V.useMemo)(()=>Ge(e),[e]);(0,V.useEffect)(()=>{let e=n>0?n.toFixed(0):null;e!==l(`page`)&&u(`page`,e)},[n,l,u]),(0,V.useEffect)(()=>{let t=Se(e);t!==l(`chargesFilters`)&&(u(`chargesFilters`,t),u(`page`),r(0))},[e,l,u,r]);let f=(0,V.useCallback)(n=>{(0,Ve.default)(n,e)||t(n)},[e,t]);return(0,G.jsxs)(`div`,{className:`flex flex-row gap-5 items-center`,children:[i>1&&(0,G.jsx)(te,{className:`flex-fit w-fit mx-0`,currentPageIndex:n,onChange:r,totalPages:i}),(0,G.jsxs)(ae,{open:s,onOpenChange:c,children:[(0,G.jsx)(ue,{asChild:!0,children:(0,G.jsxs)(g,{variant:`outline`,size:`icon`,className:`relative size-7.5`,children:[(0,G.jsx)(be,{className:`size-5`}),d>0&&(0,G.jsx)(v,{className:`absolute -end-1.5 -top-1.5 size-4 justify-center rounded-full p-0 text-xs tabular-nums`,children:d}),(0,G.jsx)(`span`,{className:`sr-only`,children:d>0?`Filters (${d} active)`:`Filters`})]})}),(0,G.jsx)(ce,{className:`flex max-h-[85dvh] flex-col gap-0 overflow-hidden p-0 sm:max-w-2xl`,children:(0,G.jsx)(bt,{filter:e,setFilter:f,closeModal:()=>c(!1),withDefaultDateRange:o})})]})]})}export{Xe as n,xt as t};