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