@accounter/client
Version:
Accounter client application
1 lines • 111 kB
JavaScript
import{s as e}from"./dist-BBBZL-zT.js";import{a as t,i as n,o as r}from"./utils-C9b7NsUD.js";import{Ca as i,In as a,Kn as o,Li as s,Nn as c,Ri as l,Sa as u,Sn as d,So as f,_i as p,_n as m,_t as h,bn as g,ct as _,en as v,gi as y,gt as b,ht as x,li as S,lt as ee,mr as te,mt as C,ot as ne,pi as re,r as w,st as ie,t as ae,v as oe,xo as se,yn as ce,yr as le,za as ue}from"./error-handling-DIXN-FX1.js";import{S as de,a as fe,m as pe,r as T,s as me,t as he,y as ge}from"./routes-g2AjKuLo.js";import{a as _e,c as ve,d as ye,f as be,gt as E,i as xe,l as Se,n as Ce,o as we,p as Te,r as Ee,s as De,t as Oe,u as ke,ut as D}from"./select-D5MmcncR.js";import{o as Ae,t as je}from"./charges-table-Dy8Tb2Q4.js";import{$r as Me,B as Ne,Br as Pe,Bt as Fe,Cr as Ie,Er as Le,Fr as O,Ft as k,G as A,H as Re,I as ze,Ir as Be,It as j,J as Ve,Jr as He,K as Ue,L as We,Lt as M,M as Ge,Mt as Ke,N as qe,Nt as N,P as Je,Pt as Ye,Rr as Xe,Rt as P,Tr as Ze,U as F,Ur as Qe,Ut as $e,V as et,Vr as tt,Vt as nt,W as rt,Wr as it,Wt as at,Xr as ot,a as I,br as st,c as ct,dt as lt,ei as ut,h as dt,hr as ft,ht as pt,i as mt,ii as ht,j as gt,jt as L,li as _t,n as vt,o as yt,q as bt,qr as xt,rt as St,s as R,ut as Ct,xt as wt,y as Tt,yr as Et,z as Dt}from"./common-DiZ9CVmc.js";import{n as Ot,r as kt}from"./similar-transactions-modal-DSa8-pVR.js";import{t as At}from"./modify-contract-dialog-Rd9hSyfX.js";import{t as jt}from"./building-2-BkWnYwH_.js";import{t as Mt}from"./circle-check-B0UQNleV.js";import{h as z,o as Nt,t as B,x as V}from"./separator-CotXr7HB.js";import{t as Pt}from"./save-B3F1CNgl.js";import{t as H}from"./button-DATCl8sW.js";import{i as Ft,n as It,r as Lt,t as Rt}from"./accordion-D_iiPE8N.js";import{a as zt,c as Bt,i as Vt,l as Ht,n as Ut,o as Wt,r as Gt,s as Kt,t as qt}from"./alert-dialog-CNuzJAPc.js";import{a as U,i as Jt,n as W,o as G,r as K,t as q}from"./card-D1mbhL3p.js";import{b as Yt,g as Xt,h as J,it as Zt,v as Qt}from"./table-x-G-XYlj.js";import{t as $t}from"./subMonths-W4DpQejx.js";import{A as en,P as tn,k as nn,x as rn}from"./index-C_oxjCc2.js";import{t as an}from"./business-extended-info-BusLbaZY.js";import{t as on}from"./business-header-xJMYR17w.js";import{t as sn}from"./transactions-table-DH22NoJo.js";import{Z as cn}from"./wiggle-D8eDIAGt.js";import{A as ln,B as un,Bt as dn,C as fn,Dt as pn,E as mn,Et as hn,F as gn,G as _n,It as vn,J as yn,K as bn,Lt as xn,M as Sn,N as Cn,Nt as wn,O as Tn,Ot as En,Pt as Dn,Q as On,Rt as kn,S as An,St as jn,T as Mn,Tt as Nn,U as Pn,Vt as Fn,W as In,Z as Ln,_ as Rn,a as zn,at as Bn,b as Vn,bt as Hn,c as Un,ct as Wn,d as Gn,dt as Kn,f as qn,ft as Jn,g as Yn,h as Xn,ht as Zn,it as Qn,j as $n,jt as er,k as tr,l as nr,lt as rr,m as ir,n as ar,o as or,ot as sr,p as cr,pt as lr,q as ur,s as dr,st as fr,t as pr,u as mr,ut as hr,v as gr,vt as _r,w as vr,x as yr,xt as br,y as xr,z as Y,zt as Sr}from"./download-csv-Bhy_hGmt.js";import{t as Cr}from"./spinner-DxxI_ALH.js";import{n as wr,t as Tr}from"./use-issue-monthly-documents-CqTWv2s7.js";var Er=E(`chart-line`,[[`path`,{d:`M3 3v16a2 2 0 0 0 2 2h16`,key:`c24i48`}],[`path`,{d:`m19 9-5 5-4-4-3 3`,key:`2osh9i`}]]),Dr=E(`circle-slash`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`9`,x2:`15`,y1:`15`,y2:`9`,key:`1dfufj`}]]),Or=E(`dollar-sign`,[[`line`,{x1:`12`,x2:`12`,y1:`2`,y2:`22`,key:`7eqyqh`}],[`path`,{d:`M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6`,key:`1b0p4s`}]]),kr=E(`file-check`,[[`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:`m9 15 2 2 4-4`,key:`1grp1n`}]]),Ar=E(`fullscreen`,[[`path`,{d:`M3 7V5a2 2 0 0 1 2-2h2`,key:`aa7l1z`}],[`path`,{d:`M17 3h2a2 2 0 0 1 2 2v2`,key:`4qcy5o`}],[`path`,{d:`M21 17v2a2 2 0 0 1-2 2h-2`,key:`6vwrx8`}],[`path`,{d:`M7 21H5a2 2 0 0 1-2-2v-2`,key:`ioqczr`}],[`rect`,{width:`10`,height:`8`,x:`7`,y:`8`,rx:`1`,key:`vys8me`}]]),jr=E(`notebook`,[[`path`,{d:`M2 6h4`,key:`aawbzj`}],[`path`,{d:`M2 10h4`,key:`l0bgd4`}],[`path`,{d:`M2 14h4`,key:`1gsvsf`}],[`path`,{d:`M2 18h4`,key:`1bu2t1`}],[`rect`,{width:`16`,height:`20`,x:`4`,y:`2`,rx:`2`,key:`1nb95v`}],[`path`,{d:`M16 2v20`,key:`rotuqe`}]]),Mr=E(`plug`,[[`path`,{d:`M12 22v-5`,key:`1ega77`}],[`path`,{d:`M15 8V2`,key:`18g5xt`}],[`path`,{d:`M17 8a1 1 0 0 1 1 1v4a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1z`,key:`1xoxul`}],[`path`,{d:`M9 8V2`,key:`14iosj`}]]),X=e(r(),1),Nr=()=>{let[{data:e,fetching:t,error:n},r]=f({query:y});return{data:e?.providerCredentials,fetching:t,error:n,refetch:()=>r({requestPolicy:`network-only`})}},Pr=`delete-provider-credentials`,Fr=()=>{let[{fetching:e},t]=se(o);return{fetching:e,deleteCredentials:(0,X.useCallback)(async e=>{let n=`Failed to disconnect provider`;w.loading(`Disconnecting provider`,{id:Pr});try{let r=ae(await t(e),n,Pr,`deleteProviderCredentials`);if(r)return w.success(`Provider disconnected`,{id:Pr}),r.deleteProviderCredentials}catch(e){console.error(`${n}: ${e}`),w.error(`Error`,{id:Pr,description:n,duration:1e5,closeButton:!0})}},[t])}},Ir=`set-deel-credentials`,Lr=()=>{let[{fetching:e},t]=se(s);return{fetching:e,setCredentials:(0,X.useCallback)(async e=>{let n=`Failed to save Deel credentials`;w.loading(`Saving Deel credentials`,{id:Ir});try{let r=ae(await t(e),n,Ir,`setDeelCredentials`);if(r)return w.success(`Deel connected`,{id:Ir}),r.setDeelCredentials}catch(e){console.error(`${n}: ${e}`),w.error(`Error`,{id:Ir,description:n,duration:1e5,closeButton:!0})}},[t])}},Z=n(),Rr=F({apiToken:A().min(1,`Required`)});function zr({status:e,onSuccess:t}){let[n,r]=(0,X.useState)(!1),{fetching:i,setCredentials:a}=Lr(),{fetching:o,deleteCredentials:s}=Fr(),c=at({resolver:Je(Rr),defaultValues:{apiToken:``}});async function l(e){await a(e)&&(r(!1),c.reset(),t())}async function u(){await s({provider:p.Deel})&&t()}return(0,Z.jsxs)(q,{children:[(0,Z.jsxs)(U,{children:[(0,Z.jsx)(G,{children:`Deel`}),(0,Z.jsx)(K,{children:`Payment processing and payroll integration`})]}),(0,Z.jsx)(W,{children:e?(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(J,{className:`w-fit bg-green-600 text-white hover:bg-green-600`,children:`Connected`}),(0,Z.jsxs)(`p`,{className:`text-sm text-gray-500`,children:[`Since `,new Date(e.configuredAt).toLocaleDateString(`en-US`)]})]}):(0,Z.jsx)(`p`,{className:`text-sm text-gray-500`,children:`Not connected`})}),(0,Z.jsx)(Jt,{children:e?(0,Z.jsxs)(qt,{children:[(0,Z.jsx)(Ht,{asChild:!0,children:(0,Z.jsx)(H,{variant:`outline`,disabled:o,children:`Disconnect`})}),(0,Z.jsxs)(Vt,{children:[(0,Z.jsxs)(Kt,{children:[(0,Z.jsx)(Bt,{children:`Disconnect Deel?`}),(0,Z.jsx)(zt,{children:`Are you sure you want to disconnect Deel? You can reconnect at any time.`})]}),(0,Z.jsxs)(Wt,{children:[(0,Z.jsx)(Gt,{children:`Cancel`}),(0,Z.jsx)(Ut,{onClick:u,disabled:o,children:`Disconnect`})]})]})]}):(0,Z.jsxs)(De,{open:n,onOpenChange:e=>{r(e),e||c.reset()},children:[(0,Z.jsx)(Te,{asChild:!0,children:(0,Z.jsx)(H,{children:`Connect`})}),(0,Z.jsxs)(ve,{children:[(0,Z.jsxs)(ye,{children:[(0,Z.jsx)(be,{children:`Connect Deel`}),(0,Z.jsx)(Se,{children:`Enter your Deel API token to connect your account.`})]}),(0,Z.jsx)(Ke,{...c,children:(0,Z.jsxs)(`form`,{onSubmit:c.handleSubmit(l),className:`space-y-4`,children:[(0,Z.jsx)(k,{control:c.control,name:`apiToken`,render:({field:e})=>(0,Z.jsxs)(j,{children:[(0,Z.jsx)(M,{children:`API Token`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{type:`password`,...e})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(ke,{children:(0,Z.jsx)(H,{type:`submit`,disabled:i,children:i?`Saving…`:`Save`})})]})})]})]})})]})}var Br=`set-green-invoice-credentials`,Vr=()=>{let[{fetching:e},t]=se(l);return{fetching:e,setCredentials:(0,X.useCallback)(async e=>{let n=`Failed to save Green Invoice credentials`;w.loading(`Saving Green Invoice credentials`,{id:Br});try{let r=ae(await t(e),n,Br,`setGreenInvoiceCredentials`);if(r)return w.success(`Green Invoice connected`,{id:Br}),r.setGreenInvoiceCredentials}catch(e){console.error(`${n}: ${e}`),w.error(`Error`,{id:Br,description:n,duration:1e5,closeButton:!0})}},[t])}},Hr=F({id:A().min(1,`Required`),secret:A().min(1,`Required`)});function Ur({status:e,onSuccess:t}){let[n,r]=(0,X.useState)(!1),{fetching:i,setCredentials:a}=Vr(),{fetching:o,deleteCredentials:s}=Fr(),c=at({resolver:Je(Hr),defaultValues:{id:``,secret:``}});async function l(e){await a(e)&&(r(!1),c.reset(),t())}async function u(){await s({provider:p.GreenInvoice})&&t()}return(0,Z.jsxs)(q,{children:[(0,Z.jsxs)(U,{children:[(0,Z.jsx)(G,{children:`Green Invoice`}),(0,Z.jsx)(K,{children:`Automated invoice creation and document sync`})]}),(0,Z.jsx)(W,{children:e?(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(J,{className:`w-fit bg-green-600 text-white hover:bg-green-600`,children:`Connected`}),(0,Z.jsxs)(`p`,{className:`text-sm text-gray-500`,children:[`Since `,new Date(e.configuredAt).toLocaleDateString(`en-US`)]})]}):(0,Z.jsx)(`p`,{className:`text-sm text-gray-500`,children:`Not connected`})}),(0,Z.jsx)(Jt,{children:e?(0,Z.jsxs)(qt,{children:[(0,Z.jsx)(Ht,{asChild:!0,children:(0,Z.jsx)(H,{variant:`outline`,disabled:o,children:`Disconnect`})}),(0,Z.jsxs)(Vt,{children:[(0,Z.jsxs)(Kt,{children:[(0,Z.jsx)(Bt,{children:`Disconnect Green Invoice?`}),(0,Z.jsx)(zt,{children:`Are you sure you want to disconnect Green Invoice? You can reconnect at any time.`})]}),(0,Z.jsxs)(Wt,{children:[(0,Z.jsx)(Gt,{children:`Cancel`}),(0,Z.jsx)(Ut,{onClick:u,disabled:o,children:`Disconnect`})]})]})]}):(0,Z.jsxs)(De,{open:n,onOpenChange:e=>{r(e),e||c.reset()},children:[(0,Z.jsx)(Te,{asChild:!0,children:(0,Z.jsx)(H,{children:`Connect`})}),(0,Z.jsxs)(ve,{children:[(0,Z.jsxs)(ye,{children:[(0,Z.jsx)(be,{children:`Connect Green Invoice`}),(0,Z.jsx)(Se,{children:`Enter your Green Invoice API credentials to connect your account.`})]}),(0,Z.jsx)(Ke,{...c,children:(0,Z.jsxs)(`form`,{onSubmit:c.handleSubmit(l),className:`space-y-4`,children:[(0,Z.jsx)(k,{control:c.control,name:`id`,render:({field:e})=>(0,Z.jsxs)(j,{children:[(0,Z.jsx)(M,{children:`API ID`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{type:`text`,...e})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:c.control,name:`secret`,render:({field:e})=>(0,Z.jsxs)(j,{children:[(0,Z.jsx)(M,{children:`API Secret`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{type:`password`,...e})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(ke,{children:(0,Z.jsx)(H,{type:`submit`,disabled:i,children:i?`Saving…`:`Save`})})]})})]})]})})]})}function Wr(){let{data:e,fetching:t,refetch:n}=Nr();if(t)return(0,Z.jsx)(`div`,{className:`flex justify-center p-8`,children:(0,Z.jsx)(Cr,{className:`h-10 w-10`})});let r=e?.find(e=>e.provider===p.GreenInvoice),i=e?.find(e=>e.provider===p.Deel);return(0,Z.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,Z.jsx)(Ur,{status:r,onSuccess:n}),(0,Z.jsx)(zr,{status:i,onSuccess:n})]})}var Gr=`updateAdminBusiness`,Kr=()=>{let[{fetching:e},t]=se(u);return{fetching:e,updateAdminBusiness:(0,X.useCallback)(async e=>{let n=`Error updating admin business ID [${e.adminBusinessId}]`,r=`${Gr}-${e.adminBusinessId}`;w.loading(`Updating admin business`,{id:r});try{let i=ae(await t(e),n,r,`updateAdminBusiness`);if(i)return w.success(`Success`,{id:r,description:`Admin Business Updated`}),i.updateAdminBusiness}catch(e){console.error(`${n}: ${e}`),w.error(`Error`,{id:r,description:n,duration:1e5,closeButton:!0})}},[t])}},qr=F({year:Re().min(2e3).max(2100),id:A().min(1,{message:`ID is required`})}),Jr=F({registrationDate:A().min(1,{message:`Business Registration Start Date is required`}),withholdingTaxAnnualIds:We(qr),withholdingTaxCompanyId:A().min(1,{message:`Withholding Tax Company ID is required`}),socialSecurityEmployerIds:We(qr),socialSecurityDeductionsId:A().min(1,{message:`Social Security Deductions ID is required`}),taxAdvancesAnnualIds:We(qr),taxAdvancesRates:We(F({date:Ve(),rate:Re().min(0,{message:`Rate must be at least 0`}).max(100,{message:`Rate must be at most 100`})}))}),Yr={WITHHOLDING_TAX:`https://secapp.taxes.gov.il/NikPay/StartPage.aspx#/Home`,TAX_ADVANCES:`https://secapp.taxes.gov.il/gmftashmh/main/entrance`,SOCIAL_SECURITY:`https://b2b.btl.gov.il/BTL.ILG.Payments/ChovDochMaasikInfo.aspx`,VAT:`https://secapp.taxes.gov.il/emdvhmfrt/wLogOnMenu.aspx`},Xr=({href:e,children:t})=>(0,Z.jsxs)(`h3`,{className:`flex flex-row gap-2 text-sm font-semibold text-foreground md:col-span-2`,children:[(0,Z.jsx)(`a`,{href:e,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`inline-flex items-center font-semibold`,children:(0,Z.jsx)(ot,{size:12})}),(0,Z.jsx)(`span`,{children:t})]});function Zr(e){return!e||e.__typename!==`LtdFinancialEntity`||!e.adminInfo?{}:{registrationDate:e.adminInfo.registrationDate,withholdingTaxAnnualIds:e.adminInfo.withholdingTaxAnnualIds.sort((e,t)=>t.year-e.year),withholdingTaxCompanyId:e.adminInfo.withholdingTaxCompanyId??void 0,socialSecurityEmployerIds:e.adminInfo.socialSecurityEmployerIds.sort((e,t)=>t.year-e.year),socialSecurityDeductionsId:e.adminInfo.socialSecurityDeductionsId??void 0,taxAdvancesAnnualIds:e.adminInfo.taxAdvancesAnnualIds.sort((e,t)=>t.year-e.year),taxAdvancesRates:e.adminInfo.taxAdvancesRates?.map(e=>({date:e.date,rate:e.rate*100}))}}function Qr(e){return{registrationDate:e.registrationDate?st(new Date(e.registrationDate)):void 0,withholdingTaxAnnualIds:e.withholdingTaxAnnualIds,withholdingTaxCompanyId:e.withholdingTaxCompanyId,socialSecurityEmployerIds:e.socialSecurityEmployerIds,taxAdvancesRates:e.taxAdvancesRates?.map(e=>({date:e.date,rate:e.rate/100})),taxAdvancesAnnualIds:e.taxAdvancesAnnualIds}}function $r({data:e,refetchBusiness:t}){let n=Xt(ne,e),[r,i]=(0,X.useState)(Zr(n)),{updateAdminBusiness:a,fetching:o}=Kr(),s=at({resolver:Je(Jr),defaultValues:r}),c=async e=>{if(!n)return;let r=fe(e,s.formState.dirtyFields);if(!r)return;let i=Qr(r);await a({adminBusinessId:n.id,fields:i}),t?.()};(0,X.useEffect)(()=>{if(n){let e=Zr(n);i(e),s.reset(e)}},[n,s]);let{fields:l,append:u,remove:d}=$e({control:s.control,name:`taxAdvancesAnnualIds`}),{fields:f,append:p,remove:m}=$e({control:s.control,name:`withholdingTaxAnnualIds`}),{fields:h,append:g,remove:_}=$e({control:s.control,name:`socialSecurityEmployerIds`}),v={withholdingTaxAnnualIds:{append:p,remove:m},taxAdvancesAnnualIds:{append:u,remove:d},socialSecurityEmployerIds:{append:g,remove:_}},y=e=>{v[e].append({year:new Date().getFullYear(),id:``})},b=(e,t)=>{v[e].remove(t)},{fields:x,append:S,remove:ee}=$e({control:s.control,name:`taxAdvancesRates`}),te=()=>{S({date:Zt(new Date,`yyyy-MM-dd`),rate:0})},C=e=>{ee(e)};return(0,Z.jsxs)(q,{children:[(0,Z.jsxs)(U,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(en,{className:`h-5 w-5 text-primary`}),(0,Z.jsx)(G,{children:`Admin Business Configuration`})]}),(0,Z.jsx)(K,{children:`Tax and registration information for the business operating this application`})]}),(0,Z.jsx)(Ke,{...s,children:(0,Z.jsxs)(`form`,{onSubmit:s.handleSubmit(c),className:`space-y-6`,children:[(0,Z.jsx)(W,{children:(0,Z.jsxs)(`div`,{className:`grid gap-6 md:grid-cols-2`,children:[(0,Z.jsx)(Xr,{href:Yr.VAT,children:`VAT`}),(0,Z.jsx)(B,{className:`md:col-span-2`}),(0,Z.jsx)(Xr,{href:Yr.TAX_ADVANCES,children:`Tax Advances`}),(0,Z.jsx)(B,{className:`md:col-span-2`}),(0,Z.jsx)(Xr,{href:Yr.WITHHOLDING_TAX,children:`Withholding Tax`}),(0,Z.jsx)(k,{control:s.control,name:`withholdingTaxCompanyId`,render:({field:e,fieldState:t})=>(0,Z.jsxs)(j,{children:[(0,Z.jsx)(M,{children:`Company Tax ID`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{placeholder:`Enter company ID`,...e,className:T(t)})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(we,{children:`Annual IDs`}),(0,Z.jsx)(H,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>y(`withholdingTaxAnnualIds`),children:(0,Z.jsx)(V,{className:`size-4`})})]}),(0,Z.jsx)(`div`,{className:`space-y-3`,children:f.map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex gap-2 items-start`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 grid grid-cols-2 gap-2`,children:[(0,Z.jsx)(z,{placeholder:`Year`,type:`number`,...s.register(`withholdingTaxAnnualIds.${t}.year`,{valueAsNumber:!0})}),(0,Z.jsx)(z,{placeholder:`ID`,...s.register(`withholdingTaxAnnualIds.${t}.id`)})]}),(0,Z.jsx)(H,{type:`button`,variant:`ghost`,size:`icon`,onClick:()=>b(`withholdingTaxAnnualIds`,t),children:(0,Z.jsx)(D,{className:`size-4`})})]},e.id))})]}),(0,Z.jsx)(B,{className:`md:col-span-2`}),(0,Z.jsx)(Xr,{href:Yr.TAX_ADVANCES,children:`Tax Advances`}),(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(we,{children:`Annual IDs`}),(0,Z.jsx)(H,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>y(`taxAdvancesAnnualIds`),children:(0,Z.jsx)(V,{className:`size-4`})})]}),(0,Z.jsx)(`div`,{className:`space-y-3`,children:l.map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex gap-2 items-start`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 grid grid-cols-2 gap-2`,children:[(0,Z.jsx)(z,{placeholder:`Year`,type:`number`,...s.register(`taxAdvancesAnnualIds.${t}.year`,{valueAsNumber:!0})}),(0,Z.jsx)(z,{placeholder:`ID`,...s.register(`taxAdvancesAnnualIds.${t}.id`)})]}),(0,Z.jsx)(H,{type:`button`,variant:`ghost`,size:`icon`,onClick:()=>b(`taxAdvancesAnnualIds`,t),children:(0,Z.jsx)(D,{className:`size-4`})})]},e.id))})]}),(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(we,{children:`Rates (%)`}),(0,Z.jsx)(H,{type:`button`,variant:`outline`,size:`sm`,onClick:te,children:(0,Z.jsx)(V,{className:`size-4`})})]}),(0,Z.jsx)(`div`,{className:`space-y-3`,children:x.map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex gap-2 items-start`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 grid grid-cols-2 gap-2`,children:[(0,Z.jsx)(z,{placeholder:`Date`,type:`date`,...s.register(`taxAdvancesRates.${t}.date`)}),(0,Z.jsx)(z,{placeholder:`Rate`,...s.register(`taxAdvancesRates.${t}.rate`,{valueAsNumber:!0})})]}),(0,Z.jsx)(H,{type:`button`,variant:`ghost`,size:`icon`,onClick:()=>C(t),children:(0,Z.jsx)(D,{className:`size-4`})})]},e.id))})]}),(0,Z.jsx)(B,{className:`md:col-span-2`}),(0,Z.jsx)(Xr,{href:Yr.SOCIAL_SECURITY,children:`Social Security`}),(0,Z.jsx)(k,{control:s.control,name:`socialSecurityDeductionsId`,render:({field:e,fieldState:t})=>(0,Z.jsxs)(j,{children:[(0,Z.jsx)(M,{children:`Deductions ID`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{placeholder:`Enter deductions ID`,...e,className:T(t)})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(we,{children:`Annual Employer IDs`}),(0,Z.jsx)(H,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>y(`socialSecurityEmployerIds`),children:(0,Z.jsx)(V,{className:`size-4`})})]}),(0,Z.jsx)(`div`,{className:`space-y-3`,children:h.map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex gap-2 items-start`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 grid grid-cols-2 gap-2`,children:[(0,Z.jsx)(z,{placeholder:`Year`,type:`number`,...s.register(`socialSecurityEmployerIds.${t}.year`,{valueAsNumber:!0})}),(0,Z.jsx)(z,{placeholder:`ID`,...s.register(`socialSecurityEmployerIds.${t}.id`)})]}),(0,Z.jsx)(H,{type:`button`,variant:`ghost`,size:`icon`,onClick:()=>b(`socialSecurityEmployerIds`,t),children:(0,Z.jsx)(D,{className:`size-4`})})]},e.id))})]}),(0,Z.jsx)(B,{className:`md:col-span-2`}),(0,Z.jsx)(k,{control:s.control,name:`registrationDate`,render:({field:e,fieldState:t})=>(0,Z.jsxs)(j,{children:[(0,Z.jsx)(M,{children:`Business Registration Start Date`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{type:`date`,...e,className:T(t)})}),(0,Z.jsx)(P,{})]})})]})}),(0,Z.jsx)(Jt,{className:`flex justify-end border-t mt-4 pt-6`,children:(0,Z.jsxs)(H,{type:`submit`,disabled:o||Object.keys(s.formState.dirtyFields).length===0||!s.formState.isValid,children:[(0,Z.jsx)(Pt,{className:`h-4 w-4`}),`Save Changes`]})})]})})]})}function ei({account:e,handleOpenModal:t}){return(0,Z.jsxs)(q,{children:[(0,Z.jsx)(U,{children:(0,Z.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsx)(`div`,{className:`p-2 rounded-lg bg-primary/10 text-primary`,children:Ot(e.type)}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(G,{className:`text-lg`,children:[e.name,e.name===e.number?``:` (${e.number})`]}),(0,Z.jsxs)(K,{className:`flex items-center gap-2 mt-1`,children:[(0,Z.jsx)(J,{variant:`outline`,children:kt(e.type)}),!e.isBusiness&&(0,Z.jsx)(J,{variant:`secondary`,children:`Private`})]})]})]}),(0,Z.jsx)(`div`,{className:`flex gap-1`,children:(0,Z.jsx)(H,{variant:`ghost`,size:`sm`,onClick:()=>t(e),"aria-label":`Edit account ${e.name}`,children:(0,Z.jsx)(Pe,{className:`h-4 w-4`,"aria-hidden":`true`})})})]})}),(0,Z.jsxs)(W,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h4`,{className:`text-sm font-medium mb-2`,children:`Currencies & Tax Categories`}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:e.currencies?.map(e=>(0,Z.jsx)(me,{to:he.TAX_CATEGORIES,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),children:(0,Z.jsxs)(J,{variant:`secondary`,className:`text-xs`,children:[e.currency,` → `,e.taxCategory.name]})},e.currency))})]}),e.type===le.BankAccount&&(0,Z.jsxs)(`div`,{className:`border-t pt-4`,children:[(0,Z.jsx)(`h4`,{className:`text-sm font-medium mb-3`,children:`Bank Details`}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-3 text-sm`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`Bank Number:`}),(0,Z.jsx)(`p`,{className:`font-medium`,children:e.bankNumber})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`Branch Number:`}),(0,Z.jsx)(`p`,{className:`font-medium`,children:e.branchNumber})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`Extended Bank Number:`}),(0,Z.jsx)(`p`,{className:`font-medium`,children:e.extendedBankNumber})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`IBAN:`}),(0,Z.jsx)(`p`,{className:`font-medium`,children:e.iban})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`Swift Code:`}),(0,Z.jsx)(`p`,{className:`font-medium`,children:e.swiftCode})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`Party Preferred Indication:`}),(0,Z.jsx)(`p`,{className:`font-medium`,children:e.partyPreferredIndication})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`Party Account Involvement:`}),(0,Z.jsx)(`p`,{className:`font-medium`,children:e.partyAccountInvolvementCode})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`Account Deal Date:`}),(0,Z.jsx)(`p`,{className:`font-medium`,children:e.accountDealDate})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`Account Update Date:`}),(0,Z.jsx)(`p`,{className:`font-medium`,children:e.accountUpdateDate})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`Meteg Dora Net:`}),(0,Z.jsx)(`p`,{className:`font-medium`,children:e.metegDoarNet})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`Kod Harshaot Peilut:`}),(0,Z.jsx)(`p`,{className:`font-medium`,children:e.kodHarshaatPeilut})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`Closing Reason Code:`}),(0,Z.jsx)(`p`,{className:`font-medium`,children:e.accountClosingReasonCode})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`Agreement Opening Date:`}),(0,Z.jsx)(`p`,{className:`font-medium`,children:e.accountAgreementOpeningDate})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`Branch Type Code:`}),(0,Z.jsx)(`p`,{className:`font-medium`,children:e.branchTypeCode})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`Mymail Entitlement:`}),(0,Z.jsx)(`p`,{className:`font-medium`,children:e.mymailEntitlementSwitch})]}),(0,Z.jsxs)(`div`,{className:`col-span-2`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`Service Authorization:`}),(0,Z.jsx)(`p`,{className:`font-medium`,children:e.serviceAuthorizationDesc})]}),(0,Z.jsxs)(`div`,{className:`col-span-2`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`Product Label:`}),(0,Z.jsx)(`p`,{className:`font-medium`,children:e.productLabel})]})]})]})]})]})}var ti=`createFinancialAccount`,ni=()=>{let[{fetching:e},t]=se(c);return{creating:e,createFinancialAccount:(0,X.useCallback)(async e=>{let n=`Error creating new account "${e.input.name}"`,r=`${ti}-${e.input.name}`;w.loading(`Creating account`,{id:r});try{ae(await t(e),n,r)&&w.success(`Success`,{id:r,description:`Financial Account ${e.input.name} was successfully created`})}catch(e){console.error(`${n}: ${e}`),w.error(`Error`,{id:r,description:n,duration:1e5,closeButton:!0})}},[t])}},ri=`updateFinancialAccount`,ii=()=>{let[{fetching:e},t]=se(ue);return{updating:e,updateFinancialAccount:(0,X.useCallback)(async e=>{let n=`Error updating financial account ID [${e.financialAccountId}]`,r=`${ri}-${e.financialAccountId}`;w.loading(`Updating financial account`,{id:r});try{let i=ae(await t(e),n,r,`updateFinancialAccount`);if(i)return w.success(`Success`,{id:r,description:`Financial account updated`}),i.updateFinancialAccount}catch(e){console.error(`${n}: ${e}`),w.error(`Error`,{id:r,description:n,duration:1e5,closeButton:!0})}},[t])}},ai=F({currency:ze(Object.values(a),`Currency is required`),taxCategoryId:bt(`Tax category ID is required`)}),Q=rt(e=>{if(e===``||e==null)return;let t=typeof e==`string`?parseInt(e,10):e;return Number.isNaN(t)?void 0:t},Re().int().optional()),oi=F({name:A().min(1,`Name is required`),number:A().min(1,`Account number is required`),isBusiness:Dt().default(!1).optional(),type:ze(Object.values(le),`Account type is required`),currencies:We(ai),bankNumber:Q,branchNumber:Q,iban:rt(e=>e===``?void 0:e,A().optional()),swiftCode:rt(e=>e===``?void 0:e,A().optional()),extendedBankNumber:Q,partyPreferredIndication:Q,partyAccountInvolvementCode:Q,accountDealDate:Q,accountUpdateDate:Q,metegDoarNet:Q,kodHarshaatPeilut:Q,accountClosingReasonCode:Q,accountAgreementOpeningDate:Q,serviceAuthorizationDesc:A().optional(),branchTypeCode:Q,mymailEntitlementSwitch:Q,productLabel:A().optional()});function si(e){return{name:e.name,number:e.number,isBusiness:e.isBusiness,type:e.type,currencies:e.currencies?.map(e=>({currency:e.currency,taxCategoryId:e.taxCategory.id}))??[],bankNumber:e.bankNumber,branchNumber:e.branchNumber,iban:e.iban,swiftCode:e.swiftCode,extendedBankNumber:e.extendedBankNumber,partyPreferredIndication:e.partyPreferredIndication,partyAccountInvolvementCode:e.partyAccountInvolvementCode,accountDealDate:e.accountDealDate,accountUpdateDate:e.accountUpdateDate,metegDoarNet:e.metegDoarNet,kodHarshaatPeilut:e.kodHarshaatPeilut,accountClosingReasonCode:e.accountClosingReasonCode,accountAgreementOpeningDate:e.accountAgreementOpeningDate,serviceAuthorizationDesc:e.serviceAuthorizationDesc,branchTypeCode:e.branchTypeCode,mymailEntitlementSwitch:e.mymailEntitlementSwitch,productLabel:e.productLabel}}var ci=(0,X.forwardRef)(function({ownerId:e,onDone:t},n){let[r,i]=(0,X.useState)(!1),[o,s]=(0,X.useState)(null),{createFinancialAccount:c,creating:l}=ni(),{updateFinancialAccount:u,updating:d}=ii(),{selectableTaxCategories:f,fetching:p}=Fe(),m=at({resolver:Je(oi),defaultValues:{name:``,number:``,isBusiness:!1,type:le.BankAccount,currencies:[],bankNumber:void 0,branchNumber:void 0,iban:void 0,swiftCode:void 0,extendedBankNumber:void 0,partyPreferredIndication:void 0,partyAccountInvolvementCode:void 0,accountDealDate:void 0,accountUpdateDate:void 0,metegDoarNet:void 0,kodHarshaatPeilut:void 0,accountClosingReasonCode:void 0,accountAgreementOpeningDate:void 0,serviceAuthorizationDesc:void 0,branchTypeCode:void 0,mymailEntitlementSwitch:void 0,productLabel:void 0},mode:`onBlur`}),{control:h,handleSubmit:g,watch:_,reset:v}=m,y=e=>{e?(s(e),v(si(e))):(s(null),v()),i(!0)};(0,X.useImperativeHandle)(n,()=>({open:y}));let b=$e({control:h,name:`currencies`}),x=()=>{i(!1),s(null),v()},S=async n=>{console.log(`Submitting form with values:`,n);try{let r=n.isBusiness?re.Business:re.Private,i=n.type===le.BankAccount&&n.bankNumber!==void 0&&n.branchNumber!==void 0?{bankNumber:n.bankNumber,branchNumber:n.branchNumber,...n.iban!==void 0&&{iban:n.iban},...n.swiftCode!==void 0&&{swiftCode:n.swiftCode},...n.extendedBankNumber!==void 0&&{extendedBankNumber:n.extendedBankNumber},...n.partyPreferredIndication!==void 0&&{partyPreferredIndication:n.partyPreferredIndication},...n.partyAccountInvolvementCode!==void 0&&{partyAccountInvolvementCode:n.partyAccountInvolvementCode},...n.accountDealDate!==void 0&&{accountDealDate:n.accountDealDate},...n.accountUpdateDate!==void 0&&{accountUpdateDate:n.accountUpdateDate},...n.metegDoarNet!==void 0&&{metegDoarNet:n.metegDoarNet},...n.kodHarshaatPeilut!==void 0&&{kodHarshaatPeilut:n.kodHarshaatPeilut},...n.accountClosingReasonCode!==void 0&&{accountClosingReasonCode:n.accountClosingReasonCode},...n.accountAgreementOpeningDate!==void 0&&{accountAgreementOpeningDate:n.accountAgreementOpeningDate},...n.serviceAuthorizationDesc!==void 0&&{serviceAuthorizationDesc:n.serviceAuthorizationDesc},...n.branchTypeCode!==void 0&&{branchTypeCode:n.branchTypeCode},...n.mymailEntitlementSwitch!==void 0&&{mymailEntitlementSwitch:n.mymailEntitlementSwitch},...n.productLabel!==void 0&&{productLabel:n.productLabel}}:void 0;o?await u({financialAccountId:o.id,fields:{name:n.name,number:n.number,type:n.type,privateOrBusiness:r,bankAccountDetails:i,currencies:n.currencies}}):await c({input:{name:n.name,number:n.number,ownerId:e,type:n.type,privateOrBusiness:r,bankAccountDetails:i}}),x(),t?.()}catch{}},ee=()=>{b.append({currency:a.Usd,taxCategoryId:``})},te=e=>{b.remove(e)};return(0,Z.jsx)(De,{open:r,onOpenChange:i,children:(0,Z.jsxs)(ve,{className:`max-w-4xl max-h-[90vh] overflow-y-auto`,children:[(0,Z.jsxs)(ye,{children:[(0,Z.jsx)(be,{children:o?`Edit Account`:`New Account`}),(0,Z.jsx)(Se,{children:o?`Update account details and settings`:`Add a new financial account`})]}),(0,Z.jsx)(Ke,{...m,children:(0,Z.jsxs)(`form`,{onSubmit:g(S),className:`space-y-6`,children:[(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:`Basic Information`}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,Z.jsx)(k,{control:h,name:`name`,render:({field:e})=>(0,Z.jsxs)(j,{className:`space-y-2`,children:[(0,Z.jsx)(M,{children:`Name *`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{...e})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:h,name:`number`,render:({field:e})=>(0,Z.jsxs)(j,{className:`space-y-2`,children:[(0,Z.jsx)(M,{children:`Account Number *`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{...e})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:h,name:`type`,render:({field:e})=>(0,Z.jsxs)(j,{className:`space-y-2`,children:[(0,Z.jsx)(M,{children:`Account Type *`}),(0,Z.jsxs)(Oe,{value:e.value,onValueChange:e.onChange,children:[(0,Z.jsx)(xe,{id:`type`,children:(0,Z.jsx)(_e,{})}),(0,Z.jsx)(Ce,{children:Object.values(le).map(e=>(0,Z.jsx)(Ee,{value:e,children:kt(e)},e))})]}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:h,name:`isBusiness`,render:({field:e})=>(0,Z.jsxs)(j,{className:`flex items-center space-x-2`,children:[(0,Z.jsx)(N,{children:(0,Z.jsx)(L,{id:`isBusiness`,checked:e.value,onCheckedChange:e.onChange})}),(0,Z.jsx)(M,{children:`Business Account`})]})})]})]}),(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:`Currencies & Tax Categories`}),(0,Z.jsxs)(H,{type:`button`,variant:`outline`,size:`sm`,onClick:ee,"aria-label":`Add currency row`,children:[(0,Z.jsx)(V,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),`Add Currency`]})]}),(0,Z.jsx)(`div`,{className:`space-y-3`,children:b.fields.map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex gap-2 items-start`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 grid grid-cols-2 gap-2`,children:[(0,Z.jsx)(k,{control:h,name:`currencies.${t}.currency`,render:({field:e})=>(0,Z.jsxs)(j,{className:`space-y-2`,children:[(0,Z.jsxs)(Oe,{value:e.value,onValueChange:e.onChange,children:[(0,Z.jsx)(xe,{id:`currencies.${t}.currency`,children:(0,Z.jsx)(_e,{})}),(0,Z.jsx)(Ce,{children:Object.entries(a).map(([e,t])=>(0,Z.jsx)(Ee,{value:t,children:t},e))})]}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:m.control,name:`currencies.${t}.taxCategoryId`,render:({field:e})=>(0,Z.jsxs)(j,{children:[(0,Z.jsx)(N,{children:(0,Z.jsx)(pt,{data:f,disabled:p,value:e.value,onChange:e.onChange,placeholder:`Scroll to see all options`,formPart:!0})}),(0,Z.jsx)(P,{})]})})]}),(0,Z.jsx)(H,{type:`button`,variant:`ghost`,size:`icon`,onClick:()=>te(t),"aria-label":`Remove currency ${_(`currencies.${t}.currency`)||``}`,children:(0,Z.jsx)(D,{className:`h-4 w-4`,"aria-hidden":`true`})})]},e.id))})]}),_(`type`)===le.BankAccount&&(0,Z.jsxs)(`div`,{className:`space-y-4 border-t pt-4`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:`Bank-Specific Details`}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:[(0,Z.jsx)(k,{control:h,name:`bankNumber`,render:({field:e})=>(0,Z.jsxs)(j,{className:`space-y-2`,children:[(0,Z.jsx)(M,{children:`Bank Number`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{inputMode:`numeric`,value:e.value??``,onChange:e.onChange})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:h,name:`branchNumber`,render:({field:e})=>(0,Z.jsxs)(j,{className:`space-y-2`,children:[(0,Z.jsx)(M,{children:`Branch Number`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{inputMode:`numeric`,value:e.value??``,onChange:e.onChange})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:h,name:`iban`,render:({field:e})=>(0,Z.jsxs)(j,{className:`space-y-2`,children:[(0,Z.jsx)(M,{children:`IBAN`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{value:e.value??``,onChange:e.onChange})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:h,name:`swiftCode`,render:({field:e})=>(0,Z.jsxs)(j,{className:`space-y-2`,children:[(0,Z.jsx)(M,{children:`Swift Code`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{value:e.value??``,onChange:e.onChange})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:h,name:`extendedBankNumber`,render:({field:e})=>(0,Z.jsxs)(j,{className:`space-y-2`,children:[(0,Z.jsx)(M,{children:`Extended Bank Number`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{inputMode:`numeric`,value:e.value??``,onChange:e.onChange})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:h,name:`partyPreferredIndication`,render:({field:e})=>(0,Z.jsxs)(j,{className:`space-y-2`,children:[(0,Z.jsx)(M,{children:`Party Preferred Indication`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{inputMode:`numeric`,value:e.value??``,onChange:e.onChange})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:h,name:`partyAccountInvolvementCode`,render:({field:e})=>(0,Z.jsxs)(j,{className:`space-y-2`,children:[(0,Z.jsx)(M,{children:`Party Account Involvement Code`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{inputMode:`numeric`,value:e.value??``,onChange:e.onChange})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:h,name:`accountDealDate`,render:({field:e})=>(0,Z.jsxs)(j,{className:`space-y-2`,children:[(0,Z.jsx)(M,{children:`Account Deal Date`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{inputMode:`numeric`,placeholder:`YYYYMMDD`,value:e.value??``,onChange:e.onChange})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:h,name:`accountUpdateDate`,render:({field:e})=>(0,Z.jsxs)(j,{className:`space-y-2`,children:[(0,Z.jsx)(M,{children:`Account Update Date`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{inputMode:`numeric`,placeholder:`YYYYMMDD`,value:e.value??``,onChange:e.onChange})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:h,name:`metegDoarNet`,render:({field:e})=>(0,Z.jsxs)(j,{className:`space-y-2`,children:[(0,Z.jsx)(M,{children:`Meteg Dora Net`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{inputMode:`numeric`,value:e.value??``,onChange:e.onChange})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:h,name:`kodHarshaatPeilut`,render:({field:e})=>(0,Z.jsxs)(j,{className:`space-y-2`,children:[(0,Z.jsx)(M,{children:`Kod Harshaot Peilut`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{inputMode:`numeric`,value:e.value??``,onChange:e.onChange})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:h,name:`accountClosingReasonCode`,render:({field:e})=>(0,Z.jsxs)(j,{className:`space-y-2`,children:[(0,Z.jsx)(M,{children:`Account Closing Reason Code`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{inputMode:`numeric`,value:e.value??``,onChange:e.onChange})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:h,name:`accountAgreementOpeningDate`,render:({field:e})=>(0,Z.jsxs)(j,{className:`space-y-2`,children:[(0,Z.jsx)(M,{children:`Account Agreement Opening Date`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{inputMode:`numeric`,placeholder:`YYYYMMDD`,value:e.value??``,onChange:e.onChange})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:h,name:`branchTypeCode`,render:({field:e})=>(0,Z.jsxs)(j,{className:`space-y-2`,children:[(0,Z.jsx)(M,{children:`Branch Type Code`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{inputMode:`numeric`,value:e.value??``,onChange:e.onChange})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:h,name:`mymailEntitlementSwitch`,render:({field:e})=>(0,Z.jsxs)(j,{className:`space-y-2`,children:[(0,Z.jsx)(M,{children:`Mymail Entitlement Switch`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{inputMode:`numeric`,value:e.value??``,onChange:e.onChange})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:h,name:`serviceAuthorizationDesc`,render:({field:e})=>(0,Z.jsxs)(j,{className:`space-y-2 md:col-span-2`,children:[(0,Z.jsx)(M,{children:`Service Authorization Description`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{...e})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:h,name:`productLabel`,render:({field:e})=>(0,Z.jsxs)(j,{className:`space-y-2 md:col-span-2 lg:col-span-3`,children:[(0,Z.jsx)(M,{children:`Product Label`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{...e})}),(0,Z.jsx)(P,{})]})})]})]}),(0,Z.jsxs)(ke,{children:[(0,Z.jsx)(H,{type:`button`,variant:`outline`,onClick:x,children:`Cancel`}),(0,Z.jsx)(H,{type:`submit`,disabled:l||d,children:o?d?`Updating…`:`Update Account`:l?`Creating…`:`Create Account`})]})]})})]})})});function li(e){return{id:e.id,name:e.name,number:e.number,isBusiness:e.privateOrBusiness===re.Business,type:e.type,currencies:e.accountTaxCategories.map(e=>({currency:e.currency,taxCategory:{id:e.taxCategory.id,name:e.taxCategory.name}})),...e.__typename===`BankFinancialAccount`?{bankNumber:e.bankNumber,branchNumber:e.branchNumber,iban:e.iban??void 0,swiftCode:e.swiftCode??void 0,extendedBankNumber:e.extendedBankNumber??void 0,partyPreferredIndication:e.partyPreferredIndication??void 0,partyAccountInvolvementCode:e.partyAccountInvolvementCode??void 0,accountDealDate:e.accountDealDate??void 0,accountUpdateDate:e.accountUpdateDate??void 0,metegDoarNet:e.metegDoarNet??void 0,kodHarshaatPeilut:e.kodHarshaatPeilut??void 0,accountClosingReasonCode:e.accountClosingReasonCode??void 0,accountAgreementOpeningDate:e.accountAgreementOpeningDate??void 0,serviceAuthorizationDesc:e.serviceAuthorizationDesc??void 0,branchTypeCode:e.branchTypeCode??void 0,mymailEntitlementSwitch:e.mymailEntitlementSwitch??void 0,productLabel:e.productLabel??void 0}:{}}}function ui({adminId:e}){let[t,n]=(0,X.useState)([]),[{data:r,fetching:i},a]=f({query:oe,variables:{adminId:e}});(0,X.useEffect)(()=>{r?.financialAccountsByOwner&&n(r.financialAccountsByOwner?.map(li)??[])},[r]);let o=(0,X.useRef)(null),s=e=>{o.current?.open(e)};return(0,Z.jsxs)(`div`,{className:`space-y-6`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h2`,{className:`text-2xl font-semibold tracking-tight`,children:`Financial Accounts`}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Manage bank accounts, credit cards, and crypto wallets`})]}),(0,Z.jsxs)(H,{onClick:()=>s(),"aria-label":`Create new financial account`,children:[(0,Z.jsx)(V,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),`New Account`]})]}),i?(0,Z.jsx)(`p`,{children:`Loading...`}):(0,Z.jsxs)(`div`,{className:`grid gap-4`,children:[t.length===0&&(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No financial accounts added yet.`}),t.map(e=>(0,Z.jsx)(ei,{account:e,handleOpenModal:s},e.id))]}),(0,Z.jsx)(ci,{ownerId:e,ref:o,onDone:()=>a()})]})}function di({businessId:e}){return(0,Z.jsxs)(q,{children:[(0,Z.jsxs)(U,{className:`flex w-full justify-between items-center`,children:[(0,Z.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(G,{children:`Balance`}),(0,Z.jsx)(K,{children:`Business balance overview`})]})}),(0,Z.jsx)(me,{to:he.BUSINESSES.DETAIL_LEDGER(e),children:(0,Z.jsx)(H,{variant:`outline`,size:`icon`,children:(0,Z.jsx)(Ar,{})})})]}),(0,Z.jsx)(W,{children:(0,Z.jsx)(`div`,{className:`rounded-md border`,children:(0,Z.jsx)(an,{businessID:e,filter:{}})})})]})}function fi({businessId:e}){let{userContext:t}=(0,X.useContext)(Qt),[n,r]=(0,X.useState)(0),[i,a]=(0,X.useState)([]),o=(0,X.useCallback)(e=>{a(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),s=(0,X.useMemo)(()=>new Set(i),[i]),c=(0,X.useCallback)(()=>{a([])},[]),[{data:l,fetching:u},d]=f({query:ie,variables:{filters:{byOwners:t?.context.adminBusinessId?[t.context.adminBusinessId]:void 0,sortBy:{field:v.Date,asc:!1},byBusinesses:[e]},page:n,limit:10}}),p=l?.allCharges?.pageInfo.totalPages??1,m=(0,X.useMemo)(()=>l?.allCharges?.nodes??[],[l]);return u&&!m.length?(0,Z.jsx)(`div`,{children:`Loading charges...`}):(0,Z.jsxs)(q,{children:[(0,Z.jsxs)(U,{className:`flex w-full justify-between items-center`,children:[(0,Z.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(G,{children:`Charges`}),(0,Z.jsx)(K,{children:`Recurring and one-time charges for this business`})]})}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[p>1&&(0,Z.jsx)(vt,{className:`flex-fit w-fit mx-0`,currentPageIndex:n,onChange:r,totalPages:p}),(0,Z.jsx)(St,{selected:i.map(e=>({id:e,onChange:()=>{d({requestPolicy:`cache-and-network`})}})),resetMerge:c})]})]}),(0,Z.jsx)(W,{children:(0,Z.jsx)(`div`,{className:`rounded-md border`,children:(0,Z.jsx)(je,{data:m,isAllOpened:!1,toggleMergeCharge:o,mergeSelectedCharges:s})})})]})}function pi(){return pi=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},pi.apply(null,arguments)}var mi=e=>{var{cx:n,cy:r,r:i,className:a}=e,o=t(`recharts-dot`,a);return Dn(n)&&Dn(r)&&Dn(i)?X.createElement(`circle`,pi({},dn(e),En(e),{className:o,cx:n,cy:r,r:i})):null},hi=[`points`];function gi(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function _i(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?gi(Object(n),!0).forEach(function(t){vi(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):gi(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function vi(e,t,n){return(t=yi(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function yi(e){var t=bi(e,`string`);return typeof t==`symbol`?t:t+``}function bi(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function xi(){return xi=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},xi.apply(null,arguments)}function Si(e,t){if(e==null)return{};var n,r,i=Ci(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function Ci(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function wi(e){var{option:n,dotProps:r,className:i}=e;if((0,X.isValidElement)(n))return(0,X.cloneElement)(n,r);if(typeof n==`function`)return n(r);var a=t(i,typeof n==`boolean`?``:n.className),o=r??{},{points:s}=o,c=Si(o,hi);return X.createElement(mi,xi({},c,{className:a}))}function Ti(e,t){return e==null?!1:t?!0:e.length===1}function Ei(e){var{points:t,dot:n,className:r,dotClassName:i,dataKey:a,baseProps:o,needClip:s,clipPathId:c,zIndex:l=On.scatter}=e;if(!Ti(t,n))return null;var u=Tn(n),d=Sr(n),f=t.map((e,r)=>{var s=_i(_i(_i({r:3},o),d),{},{index:r,cx:e.x??void 0,cy:e.y??void 0,dataKey:a,value:e.value,payload:e.payload,points:t});return X.createElement(wi,{key:`dot-${r}`,option:n,dotProps:s,className:i})}),p={};return s&&c!=null&&(p.clipPath=`url(#clipPath-${u?``:`dots-`}${c})`),X.createElement(Cn,{zIndex:l},X.createElement(xn,xi({className:r},p),f))}function Di(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function Oi(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Di(Object(n),!0).forEach(function(t){ki(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Di(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function ki(e,t,n){return(t=Ai(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Ai(e){var t=ji(e,`string`);return typeof t==`symbol`?t:t+``}function ji(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var Mi=e=>{var{point:t,childIndex:n,mainColor:r,activeDot:i,dataKey:a,clipPath:o}=e;if(i===!1||t.x==null||t.y==null)return null;var s=Oi(Oi(Oi({},{index:n,dataKey:a,cx:t.x,cy:t.y,r:4,fill:r??`none`,strokeWidth:2,stroke:`#fff`,payload:t.payload,value:t.value}),Fn(i)),En(i)),c=(0,X.isValidElement)(i)?(0,X.cloneElement)(i,s):typeof i==`function`?i(s):X.createElement(mi,s);return X.createElement(xn,{className:`recharts-active-dot`,clipPath:o},c)};function Ni(e){var{points:t,mainColor:n,activeDot:r,itemDataKey:i,clipPath:a,zIndex:o=On.activeDot}=e,s=hn(gn),c=Yn();if(t==null||c==null)return null;var l=t.find(e=>c.includes(e.payload));return wn(l)?null:X.createElement(Cn,{zIndex:o},X.createElement(Mi,{point:l,childIndex:Number(s),mainColor:n,dataKey:i,activeDot:r,clipPath:a}))}var Pi=(e,t,n,r)=>un(e,`xAxis`,t,r),Fi=(e,t,n,r)=>In(e,`xAxis`,t,r),Ii=(e,t,n,r)=>un(e,`yAxis`,n,r),Li=(e,t,n,r)=>In(e,`yAxis`,n,r),Ri=cn([Wn,Pi,Ii,Fi,Li],(e,t,n,r,i)=>jn(e,`xAxis`)?Zn(t,r,!1):Zn(n,i,!1)),zi=(e,t,n,r,i)=>i;function Bi(e){return e.type===`line`}var Vi=cn([Wn,Pi,Ii,Fi,Li,cn([_n,zi],(e,t)=>e.filter(Bi).find(e=>e.id===t)),Ri,Qn],(e,t,n,r,i,a,o,s)=>{var{chartData:c,dataStartIndex:l,dataEndIndex:u}=s;if(!(a==null||t==null||n==null||r==null||i==null||r.length===0||i.length===0||o==null||e!==`horizontal`&&e!==`vertical`)){var{dataKey:d,data:f}=a,p=f!=null&&f.length>0?f:c?.slice(l,u+1);if(p!=null)return ma({layout:e,xAxis:t,yAxis:n,xAxisTicks:r,yAxisTicks:i,dataKey:d,bandSize:o,displayedData:p})}});function Hi(e){var t=Fn(e),n=3,r=2;if(t!=null){var{r:i,strokeWidth:a}=t,o=Number(i),s=Number(a);return(Number.isNaN(o)||o<0)&&(o=n),(Number.isNaN(s)||s<0)&&(s=r),{r:o,strokeWidth:s}}return{r:n,strokeWidth:r}}var Ui=[`id`],Wi=[`type`,`layout`,`connectNulls`,`needClip`,`shape`],Gi=[`activeDot`,`animateNewValues`,`animationBegin`,`animationDuration`,`animationEasing`,`connectNulls`,`dot`,`hide`,`isAnimationActive`,`label`,`legendType`,`xAxisId`,`yAxisId`,`id`];function Ki(){return Ki=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Ki.apply(null,arguments)}function qi(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function $(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?qi(Object(n),!0).forEach(function(t){Ji(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):qi(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Ji(e,t,n){return(t=Yi(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Yi(e){var t=Xi(e,`string`);return typeof t==`symbol`?t:t+``}function Xi(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Zi(e,t){if(e==null)return{};var n,r,i=Qi(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function Qi(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var $i=e=>{var{dataKey:t,name:n,stroke:r,legendType:i,hide:a}=e;return[{inactive:a,dataKey:t,type:i,color:r,value:Hn(n,t),payload:e}]},ea=X.memo(e=>{var{dataKey:t,data:n,stroke:r,strokeWidth:i,fill:a,name:o,hide:s,unit:c,tooltipType:l,id:u}=e,d={dataDefinedOnItem:n,getPosition:vn,settings:{stroke:r,strokeWidth:i,fill:a,dataKey:t,nameKey:void 0,name:Hn(o,t),hide:s,type:l,color:r,unit:c,graphicalItemId:u}};return X.createElement(Mn,{tooltipEntrySettings:d})}),ta=(e,t)=>`${t}px ${e}px`;function na(e,t){for(var n=e.length%2==0?e:[...e,0],r=[],i=0;i<t;++i)r.push(...n);return r}var ra=(e,t,n)=>{var r=n.reduce((e,t)=>e+t,0);if(!r)return ta(t,e);for(var i=Math.floor(e/r),a=e%r,o=[],s=0,c=0;s<n.length;c+=(l=n[s])??0,++s){var l,u=n[s];if(u!=null&&c+u>a){o=[...n.slice(0,s),a-c];break}}var d=o.length%2==0?[0,t]:[t];return[...na(n,i),...o,...d].map(e=>`${e}px`).join(`, `)};function ia(e){var{clipPathId:t,points:n,props:r}=e,{dot:i,dataKey:a,needClip:o}=r,{id:s}=r,c=dn(Zi(r,Ui));return X.createElement(Ei,{points:n,dot:i,className:`recharts-line-dots`,dotClassName:`recharts-line-dot`,dataKey:a,baseProps:c,needClip:o,clipPathId:t})}function aa(e){var{showLabels:t,children:n,points:r}=e,i=(0,X.useMemo)(()=>r?.map(e=>{var t={x:e.x??0,y:e.y??0,width:0,lowerWidth:0,upperWidth:0,height:0};return $($({},t),{},{value:e.value,payload:e.payload,viewBox:t,parentViewBox:void 0,fill:void 0})}),[r]);return X.createElement(tr,{value:t?i:void 0},n)}function oa(e){var{clipPathId:t,pathRef:n,points:r,strokeDasharray:i,props:a}=e,{type:o,layout:s,connectNulls:c,needClip:l,shape:u}=a,d=$($({},kn(Zi(a,Wi))),{},{fill:`none`,className:`recharts-line-curve`,clipPath:l?`url(#clipPath-${t})`:void 0,points:r,type:o,layout:s,connectNulls:c,strokeDasharray:i??a.strokeDasharray});return X.createElement(X.Fragment,null,r?.length>1&&X.createElement(mn,Ki({shapeType:`curve`,option:u},d,{pathRef:n})),X.createElement(ia,{points:r,clipPathId:t,props:a}))}function sa(e){try{return e&&e.getTotalLength&&e.getTotalLength()||0}catch{return 0}}function ca(e){var{clipPathId:t,props:n,pathRef:r,previousPointsRef:i,longestAnimatedLengthRef:a}=e,{points:o,strokeDasharray:s,isAnimationActive:c,animationBegin:l,animationDuration:u,animationEasing:d,animateNewValues:f,width:p,height:m,onAnimationEnd:h,onAnimationStart:g}=n,_=i.current,v=Bn(o,`recharts-line-`),y=(0,X.useRef)(v),[b,x]=(0,X.useState)(!1),S=!b,ee=(0,X.useCallback)(()=>{typeof h==`function`&&h(),x(!1)},[h]),te=(0,X.useCallback)(()=>{typeof g==`function`&&g(),x(!0)},[g]),C=sa(r.current),ne=(0,X.useRef)(0);y.current!==v&&(ne.current=a.current,y.current=v);var re=ne.current;return X.createElement(aa,{points:o,showLabels:S},n.children,X.createElement(sr,{animationId:v,begin:l,duration:u,isActive:c,easing:d,onAnimationEnd:ee,onAnimationStart:te,key:v},e=>{var l=er(re,C+re,e),u=Math.min(l,C),d=c?s?ra(u,C,`${s}`.split(/[,\s]+/gim).map(e=>parseFloat(e))):ta(C,u):s==null?void 0:String(s);if(e>0&&C>0&&(i.current=o,a.current=Math.max(a.current,u)),_){var h=_.length/o.length,g=e===1?o:o.map((t,n)=>{var r=Math.floor(n*h);if(_[r]){var i=_[r];return $($({},t),{},{x:er(i.x,t.x,e),y:er(i.y,t.y,e)})}return f?$($({},t),{},{x:er(p*2,t.x,e),y:er(m/2,t.y,e)}):$($({},t),{},{x:t.x,y:t.y})});return i.current=g,X.createElement(oa,{props:n,points:g,clipPathId:t,pathRef:r,strokeDasharray:d})}return X.createElement(oa,{props:n,points:o,clipPathId:t,pathRef:r,strokeDasharray:d})}),X.createElement(ln,{label:n.label}))}function la(e){var{clipPathId:t,props:n}=e,r=(0,X.useRef)(null),i=(0,X.useRef)(0),a=(0,X.useRef)(null);return X.createElement(ca,{props:n,clipPathId:t,previousPointsRef:r,longestAnimatedLengthRef:i,pathRef:a})}var ua=(e,t)=>({x:e.x??void 0,y:e.y??void 0,value:e.value,errorVal:br(e.payload,t)}),da=class extends X.Component{render(){var{hide:e,dot:n,points:r,className:i,xAxisId:a,yAxisId:o,top:s,left:c,width:l,height:u,id:d,needClip:f,zIndex:p}=this.props;if(e)return null;var m=t(`recharts-line`,i),h=d,{r:g,strokeWidth:_}=Hi(n),v=Tn(n),y=g*2+_,b=f?`url(#clipPath-${v?``:`dots-`}${h})`:void 0;return X.createElement(Cn,{zIndex:p},X.createElement(xn,{className:m},f&&X.createElement(`defs`,null,X.createElement(mr,{clipPathId:h,xAxisId:a,yAxisId:o}),!v&&X.createElement(`clipPath`,{id:`clipPath-dots-${h}`},X.createElement(`rect`,{x:c-y/2,y:s-y/2,width:l+y,height:u+y}))),X.createElement(qn,{xAxisId:a,yAxisId:o,data:r,dataPointFormatter:ua,errorBarOffset:0},X.createElement(la,{props:this.props,clipPathId:h}))),X.createElement(Ni,{activeDot:this.props.activeDot,points:r,mainColor:this.props.stroke,itemDataKey:this.props.dataKey,clipPath:b}))}},fa={activeDot:!0,animateNewValues:!0,animationBegin:0,animationDuration:1500,animationEasing:`ease`,connectNulls:!1,dot:!0,fill:`#fff`,hide:!1,isAnimationActive:`auto`,label:!1,legendType:`line`,stroke:`#3182bd`,strokeWidth:1,xAxisId:0,yAxisId:0,zIndex:On.line,type:`linear`};function pa(e){var t=pn(e,fa),{activeDot:n,animateNewValues:r,animationBegin:i,animationDuration:a,animationEasing:o,connectNulls:s,dot:c,hide:l,isAnimationActive:u,label:d,legendType:f,xAxisId:p,yAxisId:m,id:h}=t,g=Zi(t,Gi),{needClip:_}=Gn(p,m),v=Rn(),y=hr(),b=Jn(),x=hn(e=>Vi(e,p,m,b,h));if(y!==`horizontal`&&y!==`vertical`||x==null||v==null)return null;var{height:S,width:ee,x:te,y:C}=v;return X.createElement(da,Ki({},g,{id:h,connectNulls:s,dot:c,activeDot:n,animateNewValues:r,animationBegin:i,animationDuration:a,animationEasing:o,isAnimationActive:u,hide:l,label:d,legendType:f,xAxisId:p,yAxisId:m,points:x,layout:y,height:S,width:ee,left:te,top:C,needClip:_}))}function ma(e){var{layout:t,xAxis:n,yAxis:r,xAxisTicks:i,yAxisTicks:a,dataKey:o,bandSize:s,displayedData:c}=e;return c.map((e,c)=>{var l=br(e,o);if(t===`horizontal`)return{x:_r({axis:n,ticks:i,bandSize:s,entry:e,index:c}),y:(wn(l)?null:r.scale.map(l))??null,value:l,payload:e};var u=wn(l)?null:n.scale.map(l),d=_r({axis:r,ticks:a,bandSize:s,entry:e,index:c});return u==null||d==null?null:{x:u,y:d,value:l,payload:e}}).filter(Boolean)}function ha(e){var t=pn(e,fa),n=Jn();return X.createElement(fn,{id:t.id,type:`line`},e=>X.createElement(X.Fragment,null,X.createElement(vr,{legendPayload:$i(t)}),X.createElement(ea,{dataKey:t.dataKey,data:t.data,stroke:t.stroke,strokeWidth:t.strokeWidth,fill:t.fill,name:t.name,hide:t.hide,unit:t.unit,tooltipType:t.tooltipType,id:e}),X.createElement(An,{type:`line`,id:e,data:t.data,xAxisId:t.xAxisId,yAxisId:t.yAxisId,zAxisId:0,dataKey:t.dataKey,hide:t.hide,isPanorama:n}),X.createElement(pa,Ki({},t,{id:e}))))}var ga=X.memo(ha,fr);ga.displayName=`Line`;var _a=[`type`],va=[`dangerouslySetInnerHTML`,`ticks`,`scale`],ya=[`id`,`scale`];function ba(){return ba=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},ba.apply(null,arguments)}function xa(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function Sa(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?xa(Object(n),!0).forEach(function(t){Ca(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):xa(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Ca(e,t,n){return(t=wa(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function wa(e){var t=Ta(e,`string`);return typeof t==`symbol`?t:t+``}function Ta(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ea(e,t){if(e==null)return{};var n,r,i=Da(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function Da(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function Oa(e){var t=Nn(),n=(0,X.useRef)(null),r=rr(),{type:i}=e,a=Ea(e,_a),o=Ln(r,`yAxis`,i),s=(0,X.useMemo)(()=>{if(o!=null)return Sa(Sa({},a),{},{type:o})},[o,a]);return(0,X.useLayoutEffect)(()=>{s!=null&&(n.current===null?t(gr(s)):n.current!==s&&t(Vn({prev:n.current,next:s})),n.current=s)},[s,t]),(0,X.useLayoutEffect)(()=>()=>{n.current&&=(t(xr(n.current)),null)},[t]),null}function ka(e){var{yAxisId:n,className:r,width:i,label:a}=e,o=(0,X.useRef)(null),s=(0,X.useRef)(null),c=hn(lr),l=Jn(),u=Nn(),d=`yAxis`,f=hn(e=>yn(e,n)),p=hn(e=>bn(e,n)),m=hn(e=>Pn(e,d,n,l)),h=hn(e=>ur(e,n));if((0,X.useLayoutEffect)(()=>{if(!(i!==`auto`||!f||$n(a)||(0,X.isValidElement)(a)||h==null)){var e=o.current;if(e){var t=e.getCalculatedWidth();Math.round(f.width)!==Math.round(t)&&u(yr({id:n,width:t}))}}},[m,f,u,a,n,i,h]),f==null||p==null||h==null)return null;var{dangerouslySetInnerHTML:g,ticks:_,scale:v}=e,y=Ea(e,va),{id:b,scale:x}=h,S=Ea(h,ya);return X.createElement(ir,ba({},y,S,{ref:o,labelRef:s,x:p.x,y:p.y,tickTextProps:i===`auto`?{width:void 0}:{width:i},width:f.width,height:f.height,className:t(`recharts-${d} ${d}`,r),viewBox:c,ticks:m,axisType:d,axisId:n}))}var Aa={allowDataOverflow:Y.allowDataOverflow,allowDecimals:Y.allowDecimals,allowDuplicatedCategory:Y.allowDuplicatedCategory,angle:Y.angle,axisLine:Xn.axisLine,hide:!1,includeHidden:Y.includeHidden,interval:Y.interval,label:!1,minTickGap:Y.minTickGap,mirror:Y.mirror,orientation:Y.orientation,padding:Y.padding,reversed:Y.reversed,scale:Y.scale,tick:Y.tick,tickCount:Y.tickCount,tickLine:Xn.tickLine,tickSize:Xn.tickSize,type:Y.type,niceTicks:Y.niceTicks,width:Y.width,yAxisId:0},ja=X.memo(e=>{var t=pn(e,Aa);return X.createElement(X.Fragment,null,X.createElement(Oa,{interval:t.interval,id:t.yAxisId,scale:t.scale,type:t.type,domain:t.domain,allowDataOverflow:t.allowDataOverflow,dataKey:t.dataKey,allowDuplicatedCategory:t.allowDuplicatedCategory,allowDecimals:t.allowDecimals,tickCount:t.tickCount,padding:t.padding,includeHidden:t.includeHidden,reversed:t.reversed,ticks:t.ticks,width:t.width,orientation:t.orientation,mirror:t.mirror,hide:t.hide,unit:t.unit,name:t.name,angle:t.angle,minTickGap:t.minTickGap,tick:t.tick,tickFormatter:t.tickFormatter,niceTicks:t.niceTicks}),X.createElement(ka,t))},nr);ja.displayName=`YAxis`;var Ma=[`axis`],Na=(0,X.forwardRef)((e,t)=>X.createElement(dr,{chartName:`LineChart`,defaultTooltipEventType:`axis`,validateTooltipEventTypes:Ma,tooltipPayloadSearcher:Sn,categoricalChartProps:e,ref:t})),Pa=[{month:`Jan`,revenue:12500,expenses:8200},{month:`Feb`,revenue:15800,expenses:9100},{month:`Mar`,revenue:18200,expenses:10500},{month:`Apr`,revenue:16900,expenses:9800},{month:`May`,revenue:21300,expenses:11200},{month:`Jun`,revenue:24500,expenses:12800},{month:`Jul`,revenue:22800,expenses:11900},{month:`Aug`,revenue:26100,expenses:13500},{month:`Sep`,revenue:28900,expenses:14200},{month:`Oct`,revenue:31200,expenses:15100}];function Fa(){let e=Pa.reduce((e,t)=>e+t.revenue,0),t=e/Pa.length;return(0,Z.jsxs)(q,{children:[(0,Z.jsxs)(U,{children:[(0,Z.jsx)(G,{children:`Revenue Analytics`}),(0,Z.jsx)(K,{children:`Revenue and expenses over time`})]}),(0,Z.jsxs)(W,{children:[(0,Z.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-3 mb-6`,children:[(0,Z.jsxs)(`div`,{className:`rounded-lg border p-4 space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,Z.jsx)(Or,{className:`h-4 w-4`}),`Total Revenue`]}),(0,Z.jsxs)(`p`,{className:`text-2xl font-bold`,children:[`$`,e.toLocaleString()]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 text-sm text-green-600`,children:[(0,Z.jsx)(nn,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{children:`+24.5% from last period`})]})]}),(0,Z.jsxs)(`div`,{className:`rounded-lg border p-4 space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,Z.jsx)(Or,{className:`h-4 w-4`}),`Average Monthly`]}),(0,Z.jsxs)(`p`,{className:`text-2xl font-bold`,children:[`$`,t.toLocaleString(void 0,{maximumFractionDigits:0})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 text-sm text-green-600`,children:[(0,Z.jsx)(nn,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{children:`+18.2% growth rate`})]})]}),(0,Z.jsxs)(`div`,{className:`rounded-lg border p-4 space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,Z.jsx)(Or,{className:`h-4 w-4`}),`Current Month`]}),(0,Z.jsxs)(`p`,{className:`text-2xl font-bold`,children:[`$`,Pa[Pa.length-1].revenue.toLocaleString()]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 text-sm text-green-600`,children:[(0,Z.jsx)(nn,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{children:`+8.0% from last month`})]})]})]}),(0,Z.jsx)(ar,{config:{revenue:{label:`Revenue`,color:`hsl(var(--chart-1))`},expenses:{label:`Expenses`,color:`hsl(var(--chart-2))`}},className:`h-[400px]`,children:(0,Z.jsx)(Kn,{width:`100%`,height:`100%`,children:(0,Z.jsxs)(Na,{data:Pa,margin:{top:5,right:10,left:10,bottom:5},children:[(0,Z.jsx)(cr,{strokeDasharray:`3 3`,className:`stroke-muted`}),(0,Z.jsx)(Un,{dataKey:`month`,className:`text-xs`,tick:{fill:`hsl(var(--muted-foreground))`}}),(0,Z.jsx)(ja,{className:`text-xs`,tick:{fill:`hsl(var(--muted-foreground))`}}),(0,Z.jsx)(zn,{content:(0,Z.jsx)(or,{})}),(0,Z.jsx)(ga,{type:`monotone`,dataKey:`revenue`,stroke:`var(--color-revenue)`,strokeWidth:2,dot:{fill:`var(--color-revenue)`,r:4}}),(0,Z.jsx)(ga,{type:`monotone`,dataKey:`expenses`,stroke:`var(--color-expenses)`,strokeWidth:2,dot:{fill:`var(--color-expenses)`,r:4}})]})})})]})]})}var Ia=({contractId:e})=>{let[t,n]=(0,X.useState)(!1),[r,i]=(0,X.useState)(void 0),{issueDocuments:a}=Tr(),[{data:o,fetching:s},c]=f({query:d,variables:{issueMonth:Zt($t(new Date,1),`yyyy-MM-dd`),contractId:e},pause:!t});(0,X.useEffect)(()=>{t&&c()},[t,c]),(0,X.useEffect)(()=>{o?.periodicalDocumentDraftsByContracts?.length?i(dt(Xt(S,o.periodicalDocumentDraftsByContracts[0]))):o&&i(void 0)},[o,i]);let l=(0,X.useCallback)(async e=>{await a({generateDocumentsInfo:[e]}),n(!1)},[a]);return(0,Z.jsxs)(De,{open:t,onOpenChange:n,children:[(0,Z.jsx)(Te,{asChild:!0,children:(0,Z.jsx)(H,{className:`size-7.5`,variant:`ghost`,children:(0,Z.jsx)(Qe,{className:`size-5`})})}),(0,Z.jsxs)(ve,{className:`w-[90vw] sm:max-w-[95%] max-h-[90vh] overflow-y-auto`,children:[(0,Z.jsxs)(ye,{children:[(0,Z.jsx)(be,{children:`Issue Document for Contract`}),(0,Z.jsx)(Se,{children:`Issue periodically documents based on contract`})]}),s?(0,Z.jsx)(Yt,{}):r?(0,Z.jsx)(wr,{draft:r,onApprove:l}):(0,Z.jsx)(`div`,{className:`text-center p-4 text-muted-foreground`,children:`No document draft available to issue for this contract and period.`})]})]})};function La(e){return{id:e.id,pos:e.purchaseOrders??void 0,startDate:e.startDate,endDate:e.endDate,paymentAmount:e.amount.raw,paymentCurrency:e.amount.currency,productType:e.product??void 0,billingCycle:e.billingCycle,msCloudLink:e.msCloud?.toString(),isActive:e.isActive,subscriptionPlan:e.plan??void 0,defaultRemark:e.remarks??void 0,defaultDocumentType:e.documentType??void 0,operationsLimit:e.operationsLimit}}function Ra({clientId:e}){let[{data:t,fetching:n},r]=f({query:m,variables:{clientId:e}}),i=(0,X.useMemo)(()=>[...t?.contractsByClient??[]].sort((e,t)=>new Date(t.startDate).getTime()-new Date(e.startDate).getTime()),[t?.contractsByClient]);return n?(0,Z.jsx)(`div`,{children:`Loading contracts...`}):(0,Z.jsxs)(q,{children:[(0,Z.jsx)(U,{children:(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(G,{children:`Contracts`}),(0,Z.jsx)(K,{children:`Current and past contracts sorted by start date`})]}),(0,Z.jsx)(At,{clientId:e,onDone:r})]})}),(0,Z.jsx)(W,{className:`space-y-4`,children:i.map(t=>(0,Z.jsx)(za,{clientId:e,contract:t,refetch:r},t.id))})]})}function za({clientId:e,contract:t,refetch:n}){let r=!!t.isActive;return(0,Z.jsxs)(`div`,{className:`rounded-lg border p-4 space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`h4`,{className:`font-semibold`,children:t.product}),(0,Z.jsx)(J,{variant:r?`default`:`secondary`,children:t.isActive?`Active`:`Inactive`})]}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground font-mono`,children:t.id})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(At,{clientId:e,contract:La(t),onDone:n}),(0,Z.jsx)(At,{clientId:e,contract:La(t),onDone:n,duplicate:!0}),(0,Z.jsx)(Ia,{contractId:t.id})]})]}),(0,Z.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2 lg:grid-cols-3`,children:[(0,Z.jsxs)(`div`,{className:`space-y-0`,children:[(0,Z.jsxs)(`p`,{className:`text-sm text-muted-foreground flex items-center gap-1`,children:[(0,Z.jsx)(_t,{className:`h-3 w-3`}),`Contract Period`]}),(0,Z.jsxs)(`p`,{className:`text-sm font-medium`,children:[new Date(t.startDate).toLocaleDateString(),` →`,` `,new Date(t.endDate).toLocaleDateString()]})]}),(0,Z.jsxs)(`div`,{className:`space-y-0`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`PO Numbers`}),(0,Z.jsx)(`p`,{className:`text-sm font-medium font-mono`,children:t.purchaseOrders.toReversed()[0]??``}),t.purchaseOrders.length>1&&(0,Z.jsx)(`div`,{className:`space-x-1`,children:t.purchaseOrders.toReversed().slice(1).map(e=>(0,Z.jsx)(`span`,{className:`text-xs font-thin font-mono`,children:e},e))})]}),(0,Z.jsxs)(`div`,{className:`space-y-0`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Payment`}),(0,Z.jsx)(`p`,{className:`text-sm font-medium`,children:Ie(t.amount.raw,t.amount.currency)})]}),(0,Z.jsxs)(`div`,{className:`space-y-0`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Billing Cycle`}),(0,Z.jsx)(`p`,{className:`text-sm font-medium`,children:Ze(t.billingCycle)})]}),(0,Z.jsxs)(`div`,{className:`space-y-0`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Subscription Plan`}),(0,Z.jsx)(`p`,{className:`text-sm font-medium`,children:t.plan?Le(t.plan):`N/A`})]}),(0,Z.jsxs)(`div`,{className:`space-y-0`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Operations Limit`}),(0,Z.jsx)(`p`,{className:`text-sm font-medium`,children:t.operationsLimit.toLocaleString()})]}),(0,Z.jsxs)(`div`,{className:`space-y-0`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Document Type`}),(0,Z.jsx)(`p`,{className:`text-sm font-medium`,children:Et(t.documentType)})]})]}),t.remarks&&(0,Z.jsxs)(`div`,{className:`space-y-0`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Remark`}),(0,Z.jsx)(`p`,{className:`text-sm`,children:t.remarks})]}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:t.msCloud&&(0,Z.jsx)(H,{variant:`outline`,size:`sm`,asChild:!0,children:(0,Z.jsxs)(`a`,{href:t.msCloud.toString(),target:`_blank`,rel:`noopener noreferrer`,children:[(0,Z.jsx)(ot,{className:`h-4 w-4 mr-2`}),`MS Cloud`,(0,Z.jsx)(ht,{className:`h-3 w-3 ml-1`})]})})})]},t.id)}var Ba=[{id:`linearId`,name:`Linear`,description:`Issue tracking and project management`,url:`https://linear.app/the-guild/customer/[ID]`,color:`indigo-500`},{id:`slackChannelKey`,name:`Slack`,description:`Team communication and notifications`,keyType:`Channel Key`,url:`https://guild-oss.slack.com/archives/[ID]`},{id:`notionId`,name:`Notion`,description:`Documentation and knowledge management`,url:`https://www.notion.so/theguildoss/[ID]`},{id:`workflowyUrl`,name:`Workflowy`,keyType:`URL`,description:`Task management and note taking`,url:`[ID]`}];function Va({data:e}){let[t,n]=(0,X.useState)([]),r=(0,X.useMemo)(()=>Xt(ce,e),[e]),i=r?.clientInfo?.integrations,{updateClient:a}=qe(),[{data:o,fetching:s},c]=f({query:g,variables:{clientId:r?.id??``},pause:!i?.greenInvoiceInfo||!r?.id||!t.includes(`green-invoice`)}),l=o?.greenInvoiceClient,u=i?.hiveId,d=(0,X.useCallback)((e,t)=>{if(!r?.id)return;let n={};n[t]=e,a({businessId:r?.id,fields:{integrations:n}})},[r?.id,a]);return(0,X.useEffect)(()=>{i?.greenInvoiceInfo?.greenInvoiceId&&r?.id&&t.includes(`green-invoice`)&&c()},[i?.greenInvoiceInfo?.greenInvoiceId,r?.id,c,t]),(0,Z.jsxs)(q,{children:[(0,Z.jsx)(U,{children:(0,Z.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(G,{children:`Integrations`}),(0,Z.jsx)(K,{children:`Connected external services and providers`})]})})}),(0,Z.jsx)(W,{className:`space-y-6`,children:(0,Z.jsxs)(Rt,{type:`multiple`,value:t,onValueChange:n,className:`space-y-4`,children:[(0,Z.jsxs)(Lt,{value:`green-invoice`,className:`rounded-lg border-2 border-green-600/20 bg-green-600/5`,children:[(0,Z.jsx)(`div`,{className:`px-4 py-3 bg-green-600/10 rounded-t-lg`,children:(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 flex-1`,children:[(0,Z.jsx)(`div`,{className:`h-10 w-10 rounded-lg bg-green-600 flex items-center justify-center text-white font-bold`,children:`GI`}),(0,Z.jsxs)(`div`,{className:`flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`h3`,{className:`font-semibold text-lg`,children:`Green Invoice`}),(0,Z.jsx)(Mt,{className:`h-5 w-5 text-green-600`})]}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Israeli invoicing system integration`})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(Ha,{id:r?.clientInfo?.integrations.greenInvoiceInfo?.greenInvoiceId??void 0,provider:`Green Invoice`,updateClient:async e=>d(e,`greenInvoiceId`)}),r?.clientInfo?.integrations.greenInvoiceInfo?.greenInvoiceId&&(0,Z.jsx)(Ft,{className:`p-2`})]})]})}),(0,Z.jsx)(It,{children:s?(0,Z.jsxs)(`div`,{className:`p-6 space-y-6`,children:[(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsx)(O,{className:`h-4 w-40`}),(0,Z.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(O,{className:`h-3 w-24`}),(0,Z.jsx)(O,{className:`h-4 w-full`})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(O,{className:`h-3 w-24`}),(0,Z.jsx)(O,{className:`h-4 w-full`})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(O,{className:`h-3 w-24`}),(0,Z.jsx)(O,{className:`h-4 w-full`})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(O,{className:`h-3 w-24`}),(0,Z.jsx)(O,{className:`h-4 w-full`})]})]})]}),(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsx)(O,{className:`h-4 w-40`}),(0,Z.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(O,{className:`h-3 w-32`}),(0,Z.jsx)(O,{className:`h-6 w-full`})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(O,{className:`h-3 w-24`}),(0,Z.jsx)(O,{className:`h-4 w-full`})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(O,{className:`h-3 w-24`}),(0,Z.jsx)(O,{className:`h-4 w-full`})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(O,{className:`h-3 w-24`}),(0,Z.jsx)(O,{className:`h-4 w-full`})]})]})]}),(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsx)(O,{className:`h-4 w-40`}),(0,Z.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-3`,children:[(0,Z.jsxs)(`div`,{className:`space-y-2 md:col-span-2`,children:[(0,Z.jsx)(O,{className:`h-3 w-24`}),(0,Z.jsx)(O,{className:`h-4 w-full`})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(O,{className:`h-3 w-24`}),(0,Z.jsx)(O,{className:`h-4 w-full`})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(O,{className:`h-3 w-24`}),(0,Z.jsx)(O,{className:`h-4 w-full`})]})]})]})]}):l&&(0,Z.jsxs)(`div`,{className:`p-6 space-y-6`,children:[(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsx)(`h4`,{className:`font-semibold text-sm text-muted-foreground uppercase tracking-wide`,children:`Business Information`}),(0,Z.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium text-muted-foreground`,children:`Integration ID`}),(0,Z.jsx)(`p`,{className:`text-sm font-mono`,children:r?.clientInfo?.integrations.greenInvoiceInfo?.greenInvoiceId})]}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium text-muted-foreground`,children:`Business Name`}),(0,Z.jsx)(`p`,{className:`text-sm`,children:l.name})]}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium text-muted-foreground`,children:`Country`}),(0,Z.jsx)(`p`,{className:`text-sm`,children:l.country?.name})]}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium text-muted-foreground`,children:`Tax ID`}),(0,Z.jsx)(`p`,{className:`text-sm font-mono`,children:l.taxId})]})]})]}),(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsx)(`h4`,{className:`font-semibold text-sm text-muted-foreground uppercase tracking-wide`,children:`Contact Information`}),(0,Z.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`span`,{className:`text-sm font-medium text-muted-foreground flex items-center gap-2`,children:[(0,Z.jsx)(He,{className:`h-3.5 w-3.5`}),`Email Addresses`]}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:l.emails?.map((e,t)=>(0,Z.jsx)(`span`,{className:`text-sm px-2 py-1 bg-muted rounded`,children:e},t))})]}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`span`,{className:`text-sm font-medium text-muted-foreground flex items-center gap-2`,children:[(0,Z.jsx)(it,{className:`h-3.5 w-3.5`}),`Phone`]}),(0,Z.jsx)(`p`,{className:`text-sm font-mono`,children:l.phone})]}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium text-muted-foreground`,children:`Mobile`}),(0,Z.jsx)(`p`,{className:`text-sm font-mono`,children:l.mobile})]}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium text-muted-foreground`,children:`Fax`}),(0,Z.jsx)(`p`,{className:`text-sm font-mono`,children:l.fax})]})]})]}),(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`h4`,{className:`font-semibold text-sm text-muted-foreground uppercase tracking-wide flex items-center gap-2`,children:[(0,Z.jsx)(xt,{className:`h-3.5 w-3.5`}),`Address`]}),(0,Z.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-3`,children:[(0,Z.jsxs)(`div`,{className:`space-y-1 md:col-span-2`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium text-muted-foreground`,children:`Street Address`}),(0,Z.jsx)(`p`,{className:`text-sm`,children:l.address})]}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium text-muted-foreground`,children:`City`}),(0,Z.jsx)(`p`,{className:`text-sm`,children:l.city})]}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium text-muted-foreground`,children:`Zip Code`}),(0,Z.jsx)(`p`,{className:`text-sm font-mono`,children:l.zip})]})]})]})]})})]}),(0,Z.jsxs)(Lt,{value:`hiveId`,className:`rounded-lg border-2 border-green-900/20 bg-green-900/5`,children:[(0,Z.jsx)(`div`,{className:`px-4 py-3 bg-green-900/10 rounded-t-lg`,children:(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 flex-1`,children:[u?(0,Z.jsx)(me,{to:`https://the-guild.dev/graphql/hive`,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`inline-flex items-center font-semibold`,children:(0,Z.jsx)(`div`,{className:`h-10 w-10 rounded-lg bg-green-900 flex items-center justify-center text-white font-bold`,children:(0,Z.jsx)(`img`,{src:`/icons/logos/hive.svg`,alt:`Hive logo`,className:`size-8 object-cover`})})}):(0,Z.jsx)(`div`,{className:`h-10 w-10 rounded-lg bg-green-900 flex items-center justify-center text-white font-bold`,children:(0,Z.jsx)(Xe,{})}),(0,Z.jsxs)(`div`,{className:`flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`h3`,{className:`font-semibold text-lg`,children:`Hive`}),u?(0,Z.jsx)(Mt,{className:`h-5 w-5 text-green-600`}):(0,Z.jsx)(Dr,{className:`h-5 w-5 text-red-600`})]}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Schema registry, analytics, metrics and gateway for GraphQL federation and other GraphQL APIs`})]})]}),(0,Z.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,Z.jsx)(Ha,{id:i?.hiveId??void 0,provider:`Hive`,updateClient:async e=>d(e,`hiveId`)})}),u&&(0,Z.jsx)(Ft,{className:`p-2`})]})}),(0,Z.jsx)(It,{children:u&&(0,Z.jsxs)(`div`,{className:`flex flex-col gap-4 px-4 pb-4 pt-2 border-t`,children:[(0,Z.jsx)(`div`,{className:`text-sm`,children:(0,Z.jsxs)(me,{to:`https://the-guild.dev/graphql/hive`,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`inline-flex items-center font-semibold gap-2`,children:[(0,Z.jsx)(`img`,{src:`/icons/logos/hive.svg`,alt:`Hive logo`,className:`size-8 object-cover`}),`Hive`]})}),(0,Z.jsx)(`div`,{className:`text-sm`,children:(0,Z.jsxs)(me,{to:`https://graphcdn.retool.com/apps/f6c244bc-b7ce-11ef-a86c-0b05f221c5b4/Hive/Hive%20Admin/explore_organization?id=${i.hiveId}`,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`inline-flex items-center font-semibold gap-2`,children:[(0,Z.jsx)(`img`,{src:`/icons/logos/retool.svg`,alt:`Retool logo`,className:`size-8 object-cover`}),`Retool`]})})]})})]},`hiveId`),Ba.map(e=>(0,Z.jsx)(Lt,{value:e.id,className:`rounded-lg border-2 border-gray-500/20 bg-gray-500/5`,children:(0,Z.jsx)(`div`,{className:`px-4 py-3 bg-gray-500/10 rounded-t-lg`,children:(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 flex-1`,children:[i?.[e.id]?(0,Z.jsx)(me,{to:e.url.replace(`[ID]`,i?.[e.id]??``),target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`inline-flex items-center font-semibold`,children:(0,Z.jsx)(`div`,{className:`h-10 w-10 rounded-lg bg-gray-500 flex items-center justify-center text-white font-bold`,children:(0,Z.jsx)(ot,{})})}):(0,Z.jsx)(`div`,{className:`h-10 w-10 rounded-lg bg-gray-500 flex items-center justify-center text-white font-bold`,children:(0,Z.jsx)(Xe,{})}),(0,Z.jsxs)(`div`,{className:`flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`h3`,{className:`font-semibold text-lg`,children:e.name}),i?.[e.id]==null?(0,Z.jsx)(Dr,{className:`h-5 w-5 text-red-600`}):(0,Z.jsx)(Mt,{className:`h-5 w-5 text-green-600`})]}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.description})]})]}),(0,Z.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,Z.jsx)(Ha,{id:r?.clientInfo?.integrations[e.id]??void 0,provider:e.name,keyType:e.keyType,updateClient:async t=>d(t,e.id)})})]})})},e.id))]})})]})}function Ha({id:e,provider:t,keyType:n,updateClient:r}){let[i,a]=(0,X.useState)(!1),[o,s]=(0,X.useState)(e),c=(0,X.useCallback)(async()=>{await r(o),a(!1)},[o,r]);return(0,Z.jsxs)(De,{open:i,onOpenChange:a,children:[(0,Z.jsx)(Te,{asChild:!0,children:(0,Z.jsx)(H,{variant:`outline`,size:`sm`,onClick:e=>e.stopPropagation(),children:(0,Z.jsx)(tt,{className:`h-4 w-4`})})}),(0,Z.jsxs)(ve,{onClick:e=>e.stopPropagation(),children:[(0,Z.jsxs)(ye,{children:[(0,Z.jsxs)(be,{children:[`Configure `,t]}),(0,Z.jsxs)(Se,{children:[`Update your `,t,` integration settings`]})]}),(0,Z.jsx)(`div`,{className:`space-y-4 py-4`,children:(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsxs)(we,{htmlFor:`id`,children:[t,` `,n??`ID`]}),(0,Z.jsx)(z,{id:`id`,value:o,onChange:e=>s(e.target.value),placeholder:`Enter ${t} ${n??`ID`}`})]})}),(0,Z.jsxs)(ke,{children:[(0,Z.jsx)(H,{variant:`outline`,onClick:()=>a(!1),children:`Cancel`}),(0,Z.jsx)(H,{onClick:c,disabled:!o,children:`Save Changes`})]})]})]})}var Ua=`updateBusiness`,Wa=()=>{let[{fetching:e},t]=se(i);return{fetching:e,updateBusiness:(0,X.useCallback)(async e=>{let n=`Error updating business ID [${e.businessId}]`,r=`${Ua}-${e.businessId}`;w.loading(`Updating business`,{id:r});try{let i=ae(await t(e),n,r,`updateBusiness`);if(i)return w.success(`Success`,{id:r,description:`Business updated`}),i.updateBusiness}catch(e){console.error(`${n}: ${e}`),w.error(`Error`,{id:r,description:n,duration:1e5,closeButton:!0})}},[t])}},Ga=Object.values(te);function Ka(e){return!e||e.__typename!==`LtdFinancialEntity`?{}:{isClient:!!e.clientInfo?.id,isActive:e.isActive,isReceiptEnough:e.isReceiptEnough??void 0,isDocumentsOptional:e.isDocumentsOptional??void 0,isVatOptional:e.optionalVAT??void 0,isExemptDealer:e.exemptDealer??void 0,sortCode:e.sortCode?.key?.toString()??void 0,taxCategory:e.taxCategory?.id??void 0,pcn874RecordType:e?.pcn874RecordType??void 0,irsCode:e?.irsCode??void 0,description:e.suggestions?.description??void 0,tags:e.suggestions?.tags?.map(e=>e.id)??[],phrases:e.suggestions?.phrases??[],emails:e.suggestions?.emails??[],internalLinks:e.suggestions?.emailListener?.internalEmailLinks??[],attachmentTypes:e.suggestions?.emailListener?.attachments??[],useMessageBody:e.suggestions?.emailListener?.emailBody??void 0}}function qa(e){let t=e.internalLinks||e.useMessageBody||e.attachmentTypes?{internalEmailLinks:e.internalLinks,emailBody:e.useMessageBody,attachments:e.attachmentTypes}:void 0,n=e.description||e.tags||e.phrases||e.emails||t?{description:e.description,tags:e.tags?.map(e=>({id:e})),phrases:e.phrases,emails:e.emails,emailListener:t}:void 0;return{optionalVAT:e.isVatOptional,exemptDealer:e.isExemptDealer,sortCode:e.sortCode?parseInt(e.sortCode):void 0,taxCategory:e.taxCategory,pcn874RecordType:e.pcn874RecordType,irsCode:e.irsCode,isActive:e.isActive,isReceiptEnough:e.isReceiptEnough,isDocumentsOptional:e.isDocumentsOptional,suggestions:n}}function Ja({data:e,refetchBusiness:t}){let n=Xt(_,e),[r,i]=(0,X.useState)(Ka(n)),{userContext:a}=(0,X.useContext)(Qt),{updateBusiness:o,fetching:s}=Wa(),[c,l]=(0,X.useState)(!1),[u,d]=(0,X.useState)(void 0),f=at({defaultValues:r}),p=async e=>{if(!n||!a?.context.adminBusinessId)return;let r=f.formState.dirtyFields,i=r.irsCode===!0&&e.irsCode===null,s=fe(i?{...e,irsCode:void 0}:e,r),c=i?{...s,irsCode:null}:s;if(!c)return;let u=qa(c);await o({businessId:n.id,ownerId:a.context.adminBusinessId,fields:u}),c.tags?.length||c.description?(d({tagIds:c.tags?.map(e=>({id:e})),description:c.description}),l(!0)):t?.()};if((0,X.useEffect)(()=>{if(n){let e=Ka(n);i(e),f.reset(e)}},[n,f]),!n)return(0,Z.jsx)(`div`,{});let m=f.watch(`isClient`);return(0,Z.jsxs)(q,{children:[(0,Z.jsx)(U,{children:(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(G,{children:`Configurations`}),(0,Z.jsx)(K,{children:`Business status, tax settings, automation rules, and integration preferences`})]}),!m&&(0,Z.jsx)(Ge,{businessId:n.id,onDone:t})]})}),(0,Z.jsx)(Ke,{...f,children:(0,Z.jsxs)(`form`,{onSubmit:f.handleSubmit(p),children:[(0,Z.jsxs)(W,{className:`space-y-6`,children:[(0,Z.jsx)(Ya,{form:f}),(0,Z.jsx)(B,{}),(0,Z.jsx)(Xa,{form:f}),(0,Z.jsx)(B,{}),(0,Z.jsx)(Za,{form:f}),(0,Z.jsx)(B,{}),(0,Z.jsx)(Qa,{form:f})]}),(0,Z.jsx)(Jt,{className:`flex justify-end border-t pt-6`,children:(0,Z.jsxs)(H,{type:`submit`,disabled:s||Object.keys(f.formState.dirtyFields).length===0,children:[(0,Z.jsx)(Pt,{className:`h-4 w-4 mr-2`}),`Save Changes`]})})]})}),(0,Z.jsx)(ct,{businessId:n.id,tagIds:u?.tagIds,description:u?.description,open:c,onOpenChange:l,onClose:t})]})}function Ya({form:e}){return(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Business Status & Behavior`}),(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsx)(k,{control:e.control,name:`isClient`,render:({field:e,fieldState:t})=>(0,Z.jsxs)(j,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Z.jsx)(M,{children:`Is Client`}),(0,Z.jsx)(Ye,{children:`Mark this business as a client`})]}),(0,Z.jsx)(N,{children:(0,Z.jsx)(L,{disabled:!0,checked:e.value,onCheckedChange:e.onChange,className:T(t)})})]})}),(0,Z.jsx)(k,{control:e.control,name:`isActive`,render:({field:e,fieldState:t})=>(0,Z.jsxs)(j,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Z.jsx)(M,{children:`Is Active`}),(0,Z.jsx)(Ye,{children:`Business is currently active`})]}),(0,Z.jsx)(N,{children:(0,Z.jsx)(L,{checked:e.value,onCheckedChange:e.onChange,className:T(t)})})]})}),(0,Z.jsx)(k,{control:e.control,name:`isReceiptEnough`,render:({field:e,fieldState:t})=>(0,Z.jsxs)(j,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Z.jsx)(M,{children:`Is Receipt Enough`}),(0,Z.jsx)(Ye,{children:`Generate ledger for receipt documents if no invoice available`})]}),(0,Z.jsx)(N,{children:(0,Z.jsx)(L,{checked:e.value,onCheckedChange:e.onChange,className:T(t)})})]})}),(0,Z.jsx)(k,{control:e.control,name:`isDocumentsOptional`,render:({field:e,fieldState:t})=>(0,Z.jsxs)(j,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Z.jsx)(M,{children:`No Docs Required`}),(0,Z.jsx)(Ye,{children:`Skip document validation for common charges`})]}),(0,Z.jsx)(N,{children:(0,Z.jsx)(L,{checked:e.value,onCheckedChange:e.onChange,className:T(t)})})]})}),(0,Z.jsx)(k,{control:e.control,name:`isVatOptional`,render:({field:e,fieldState:t})=>(0,Z.jsxs)(j,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Z.jsx)(M,{children:`Is VAT Optional`}),(0,Z.jsx)(Ye,{children:`Mute missing VAT indicator`})]}),(0,Z.jsx)(N,{children:(0,Z.jsx)(L,{checked:e.value,onCheckedChange:e.onChange,className:T(t)})})]})}),(0,Z.jsx)(k,{control:e.control,name:`isExemptDealer`,render:({field:e,fieldState:t})=>(0,Z.jsxs)(j,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Z.jsx)(M,{children:`Is Exempt Dealer`}),(0,Z.jsx)(Ye,{children:`Business is exempt from VAT requirements`})]}),(0,Z.jsx)(N,{children:(0,Z.jsx)(L,{checked:e.value,onCheckedChange:e.onChange,className:T(t)})})]})})]})]})}function Xa({form:e}){let{selectableTaxCategories:t,fetching:n}=Fe(),{selectableSortCodes:r,fetching:i,sortCodes:a}=gt(),{selectableTags:o,fetching:s}=nt(),c=(0,X.useCallback)(t=>{if(t){let n=a.find(e=>Number(e.key)===Number(t));n&&(n.defaultIrsCode?e.setValue(`irsCode`,n.defaultIrsCode,{shouldDirty:!0}):e.setValue(`irsCode`,null,{shouldDirty:!0}))}},[e,a]);return(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Default Settings`}),(0,Z.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,Z.jsx)(k,{control:e.control,name:`sortCode`,render:({field:e,fieldState:t})=>(0,Z.jsxs)(j,{children:[(0,Z.jsx)(M,{children:`Sort Code`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(pt,{onChange:t=>{c(t),e.onChange(t)},data:r,value:e.value,disabled:i,placeholder:`Scroll to see all options`,formPart:!0,triggerProps:{className:T(t)}})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:e.control,name:`taxCategory`,render:({field:e,fieldState:r})=>(0,Z.jsxs)(j,{children:[(0,Z.jsx)(M,{children:`Tax Category`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(pt,{data:t,disabled:n,value:e.value,onChange:e.onChange,placeholder:`Scroll to see all options`,formPart:!0,triggerProps:{className:T(r)}})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:e.control,name:`pcn874RecordType`,render:({field:e,fieldState:t})=>(0,Z.jsxs)(j,{children:[(0,Z.jsx)(M,{children:`PCN874 Record Type`}),(0,Z.jsxs)(Oe,{onValueChange:e.onChange,value:e.value,children:[(0,Z.jsx)(N,{children:(0,Z.jsx)(xe,{className:T(t),children:(0,Z.jsx)(_e,{})})}),(0,Z.jsx)(Ce,{children:Object.entries(ft).map(([e,t])=>(0,Z.jsx)(Ee,{value:e,children:`${t} (${e})`},e))})]}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:e.control,name:`irsCode`,render:({field:e,fieldState:t})=>(0,Z.jsxs)(j,{children:[(0,Z.jsx)(M,{children:`IRS Code`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(Ct,{value:e.value??void 0,onValueChange:t=>e.onChange(t??null),hideControls:!0,decimalScale:0,className:T(t)})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:e.control,name:`description`,render:({field:e,fieldState:t})=>(0,Z.jsxs)(j,{children:[(0,Z.jsx)(M,{children:`Charge Description`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{placeholder:`Enter default charge description`,...e,className:T(t)})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:e.control,name:`tags`,render:({field:e,fieldState:t})=>(0,Z.jsxs)(j,{children:[(0,Z.jsx)(M,{children:`Tags`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(lt,{options:Object.values(o),onValueChange:e.onChange,defaultValue:e.value,value:e.value,placeholder:`Select Default Tags`,variant:`default`,disabled:s,className:T(t)})}),(0,Z.jsx)(P,{})]})})]})]})}function Za({form:e}){let[t,n]=(0,X.useState)(``),[r,i]=(0,X.useState)(``),a=()=>{if(t.trim()){let r=e.getValues(`phrases`);e.setValue(`phrases`,[...r,t.trim()],{shouldDirty:!0}),n(``)}},o=()=>{if(r.trim()){let t=e.getValues(`emails`);e.setValue(`emails`,[...t,r.trim()],{shouldDirty:!0}),i(``)}},s=t=>{let n=e.getValues(`phrases`);e.setValue(`phrases`,n.filter((e,n)=>n!==t),{shouldDirty:!0})},c=t=>{let n=e.getValues(`emails`);e.setValue(`emails`,n.filter((e,n)=>n!==t),{shouldDirty:!0})};return(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Auto-matching Configuration`}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Configure patterns for automatic matching of bank transactions and documents`}),(0,Z.jsx)(k,{control:e.control,name:`phrases`,render:({field:e,fieldState:r})=>(0,Z.jsxs)(j,{children:[(0,Z.jsx)(M,{children:`Phrases`}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(z,{placeholder:`Add phrase...`,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),a())},className:T(r)}),(0,Z.jsx)(H,{type:`button`,size:`sm`,onClick:a,children:(0,Z.jsx)(V,{className:`h-4 w-4`})})]}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:e.value?.map((e,t)=>(0,Z.jsxs)(J,{variant:`secondary`,className:`gap-1`,children:[e,(0,Z.jsx)(H,{variant:`ghost`,size:`icon`,className:`p-0 size-3`,onClick:()=>s(t),children:(0,Z.jsx)(D,{className:`size-3 cursor-pointer`,onClick:()=>s(t)})})]},t))}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:e.control,name:`emails`,render:({field:e,fieldState:t})=>(0,Z.jsxs)(j,{children:[(0,Z.jsx)(M,{children:`Email Addresses`}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(z,{type:`email`,placeholder:`Add email...`,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),o())},className:T(t)}),(0,Z.jsx)(H,{type:`button`,size:`sm`,onClick:o,children:(0,Z.jsx)(V,{className:`h-4 w-4`})})]}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:e.value?.map((e,t)=>(0,Z.jsxs)(J,{variant:`secondary`,className:`gap-1`,children:[e,(0,Z.jsx)(H,{variant:`ghost`,size:`icon`,className:`p-0 size-3`,onClick:()=>c(t),children:(0,Z.jsx)(D,{className:`size-3 cursor-pointer`})})]},t))}),(0,Z.jsx)(P,{})]})})]})}function Qa({form:e}){let[t,n]=(0,X.useState)(``),r=()=>{if(t.trim()){let r=e.getValues(`internalLinks`);e.setValue(`internalLinks`,[...r,t.trim()],{shouldDirty:!0}),n(``)}},i=t=>{let n=e.getValues(`attachmentTypes`);e.setValue(`attachmentTypes`,n?.includes(t)?n.filter(e=>e!==t):[...n,t],{shouldDirty:!0})},a=t=>{let n=e.getValues(`internalLinks`);e.setValue(`internalLinks`,n.filter((e,n)=>n!==t),{shouldDirty:!0})};return(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Gmail Feature Configuration`}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Configure Gmail integration settings for document processing`}),(0,Z.jsx)(k,{control:e.control,name:`attachmentTypes`,render:({field:e,fieldState:t})=>(0,Z.jsxs)(j,{children:[(0,Z.jsx)(M,{children:`Attachment Types`}),(0,Z.jsx)(`div`,{className:T(t)+` rounded-md flex flex-wrap gap-2`,children:Ga.map(t=>(0,Z.jsx)(J,{variant:e.value?.includes(t)?`default`:`outline`,className:`cursor-pointer`,onClick:()=>i(t),children:t},t))}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:e.control,name:`internalLinks`,render:({field:e,fieldState:i})=>(0,Z.jsxs)(j,{children:[(0,Z.jsx)(M,{children:`Internal Links`}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(z,{type:`url`,placeholder:`Add internal link...`,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),r())}}),(0,Z.jsx)(H,{type:`button`,size:`sm`,onClick:r,children:(0,Z.jsx)(V,{className:`h-4 w-4`})})]}),(0,Z.jsx)(`div`,{className:T(i)+` flex flex-wrap gap-2 rounded-md`,children:e.value?.map((e,t)=>(0,Z.jsxs)(J,{variant:`secondary`,className:`gap-1 max-w-xs truncate`,children:[e,(0,Z.jsx)(H,{variant:`ghost`,size:`icon`,className:`p-0 size-3`,onClick:()=>a(t),children:(0,Z.jsx)(D,{className:`size-3 cursor-pointer flex-shrink-0`})})]},t))}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:e.control,name:`useMessageBody`,render:({field:e,fieldState:t})=>(0,Z.jsxs)(j,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Z.jsx)(M,{children:`Should Use Message Body`}),(0,Z.jsx)(Ye,{children:`Extract information from email message body`})]}),(0,Z.jsx)(N,{children:(0,Z.jsx)(L,{checked:e.value,onCheckedChange:e.onChange,className:T(t)})})]})})]})}var $a=F({businessName:A().min(1,`Business name is required`),locality:A().min(1,`Locality is required`),localName:A().optional(),govId:A().optional(),address:A().optional(),city:A().optional(),zipCode:A().optional(),localAddress:A().optional(),phone:A().optional(),website:Ue(`Invalid URL`).optional().or(et(``)),generalContacts:We(Ne()).optional(),billingEmails:We(Ne()).optional()});function eo(e){return!e||e.__typename!==`LtdFinancialEntity`?{}:{businessName:e.name,locality:e.country?.code,localName:e.hebrewName??void 0,govId:e.governmentId??void 0,address:e.address??void 0,city:e.city??void 0,zipCode:e.zipCode??void 0,phone:e.phoneNumber??void 0,website:e.website??void 0,generalContacts:e.email?.split(`,`).map(e=>e.trim()),billingEmails:e.clientInfo?.emails}}function to(e){return{name:e.businessName,country:e.locality,hebrewName:e.localName,governmentId:e.govId,address:e.address,city:e.city,zipCode:e.zipCode,phoneNumber:e.phone,website:e.website,email:e.generalContacts?.join(`, `)}}function no({data:e,refetchBusiness:t}){let n=Xt(ee,e),[r,i]=(0,X.useState)(eo(n)),{userContext:a}=(0,X.useContext)(Qt),{updateBusiness:o,fetching:s}=Wa(),{updateClient:c,fetching:l}=qe(),u=at({resolver:Je($a),defaultValues:r}),{countries:d,fetching:f}=wt(),[p,m]=(0,X.useState)(``),[h,g]=(0,X.useState)(``),_=u.watch(`locality`),v=u.watch(`address`),y=u.watch(`city`),b=u.watch(`zipCode`),x=u.watch(`localAddress`);(0,X.useEffect)(()=>{v!==r.address&&u.setValue(`address`,v,{shouldDirty:!0})},[v,r.address,u]),(0,X.useEffect)(()=>{y!==r.city&&u.setValue(`city`,y,{shouldDirty:!0})},[y,r.city,u]),(0,X.useEffect)(()=>{b!==r.zipCode&&u.setValue(`zipCode`,b,{shouldDirty:!0})},[b,r.zipCode,u]),(0,X.useEffect)(()=>{x!==r.localAddress&&u.setValue(`localAddress`,x,{shouldDirty:!0})},[x,r.localAddress,u]);let S=n&&`clientInfo`in n&&!!n.clientInfo,te=_===a?.context.locality,C=e=>{p.trim()&&(u.setValue(`generalContacts`,[...e,p.trim()],{shouldDirty:!0}),m(``))},ne=(e,t)=>{u.setValue(`generalContacts`,e.filter((e,n)=>n!==t),{shouldDirty:!0})},re=e=>{h.trim()&&(u.setValue(`billingEmails`,[...e,h.trim()],{shouldDirty:!0}),g(``))},w=(e,t)=>{u.setValue(`billingEmails`,e.filter((e,n)=>n!==t),{shouldDirty:!0})},ie=async e=>{if(!n||!a?.context.adminBusinessId)return;let r=fe(e,u.formState.dirtyFields);if(!r)return;let i=to(r),s=[];Object.values(i).some(e=>e!=null)&&s.push(o({businessId:n.id,ownerId:a.context.adminBusinessId,fields:i})),S&&r.billingEmails&&s.push(c({businessId:n.id,fields:{emails:r.billingEmails}})),await Promise.all(s),t?.()};return(0,X.useEffect)(()=>{if(n){let e=eo(n);i(e),u.reset(e)}},[n,u]),(0,Z.jsxs)(q,{children:[(0,Z.jsxs)(U,{children:[(0,Z.jsx)(G,{children:`Contact Information`}),(0,Z.jsx)(K,{children:`Business contact details and address information`})]}),(0,Z.jsx)(Ke,{...u,children:(0,Z.jsxs)(`form`,{onSubmit:u.handleSubmit(ie),children:[(0,Z.jsx)(W,{children:(0,Z.jsxs)(`div`,{className:`grid gap-6 md:grid-cols-2`,children:[(0,Z.jsx)(k,{control:u.control,name:`businessName`,render:({field:e,fieldState:t})=>(0,Z.jsxs)(j,{children:[(0,Z.jsx)(M,{children:`Business Name`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{...e,className:T(t)})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:u.control,name:`locality`,render:({field:e,fieldState:t})=>(0,Z.jsxs)(j,{children:[(0,Z.jsx)(M,{children:`Locality / Country`}),(0,Z.jsx)(pt,{onChange:e.onChange,data:d.map(e=>({value:e.code,label:e.name})),value:e.value,disabled:f,placeholder:`Scroll to see all options`,formPart:!0,triggerProps:{className:T(t)}}),(0,Z.jsx)(P,{})]})}),te&&(0,Z.jsx)(k,{control:u.control,name:`localName`,render:({field:e,fieldState:t})=>(0,Z.jsxs)(j,{children:[(0,Z.jsx)(M,{children:`Local Name`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{...e,placeholder:`Business name in local language`,className:T(t)})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:u.control,name:`govId`,render:({field:e,fieldState:t})=>(0,Z.jsxs)(j,{children:[(0,Z.jsx)(M,{children:`Government ID`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{...e,placeholder:`Enter Government ID`,className:T(t)})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:u.control,name:`address`,render:({field:e,fieldState:t})=>(0,Z.jsxs)(j,{className:`md:col-span-2`,children:[(0,Z.jsxs)(M,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(xt,{className:`h-4 w-4`}),`Address`]}),(0,Z.jsx)(N,{children:(0,Z.jsx)(Nt,{...e,rows:3,placeholder:`Enter business address`,className:T(t)})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:u.control,name:`city`,render:({field:e,fieldState:t})=>(0,Z.jsxs)(j,{children:[(0,Z.jsx)(M,{children:`City`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{...e,placeholder:`Enter City`,className:T(t)})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:u.control,name:`zipCode`,render:({field:e,fieldState:t})=>(0,Z.jsxs)(j,{children:[(0,Z.jsx)(M,{children:`Zip Code`}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{...e,placeholder:`Enter Zip Code`,className:T(t)})}),(0,Z.jsx)(P,{})]})}),te&&(0,Z.jsx)(k,{control:u.control,name:`localAddress`,render:({field:e,fieldState:t})=>(0,Z.jsxs)(j,{className:`md:col-span-2`,children:[(0,Z.jsxs)(M,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(xt,{className:`h-4 w-4`}),`Local Address`]}),(0,Z.jsx)(N,{children:(0,Z.jsx)(Nt,{...e,rows:3,placeholder:`Enter address in local language`,className:T(t)})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:u.control,name:`phone`,render:({field:e,fieldState:t})=>(0,Z.jsxs)(j,{children:[(0,Z.jsxs)(M,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(it,{className:`h-4 w-4`}),`Phone`]}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{...e,type:`tel`,placeholder:`+1 (555) 123-4567`,className:T(t)})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:u.control,name:`website`,render:({field:e,fieldState:t})=>(0,Z.jsxs)(j,{children:[(0,Z.jsxs)(M,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(Me,{className:`h-4 w-4`}),`Website`]}),(0,Z.jsx)(N,{children:(0,Z.jsx)(z,{...e,type:`url`,placeholder:`https://example.com`,className:T(t)})}),(0,Z.jsx)(P,{})]})}),(0,Z.jsx)(k,{control:u.control,name:`generalContacts`,render:({field:e,fieldState:t})=>(0,Z.jsxs)(j,{className:`md:col-span-2`,children:[(0,Z.jsxs)(M,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(He,{className:`h-4 w-4`}),`General Contacts`]}),(0,Z.jsx)(N,{children:(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`div`,{className:T(t)+` flex flex-wrap gap-2 mb-2 rounded-md`,children:e.value?.map((t,n)=>(0,Z.jsxs)(J,{variant:`secondary`,className:`gap-1 pr-1`,children:[t,(0,Z.jsx)(`button`,{type:`button`,onClick:()=>ne(e.value??[],n),className:`ml-1 hover:bg-muted rounded-sm p-0.5`,children:(0,Z.jsx)(D,{className:`h-3 w-3`})})]},n))}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(z,{value:p,onChange:e=>m(e.target.value),onKeyDown:t=>{t.key===`Enter`&&(t.preventDefault(),C(e.value??[]))},placeholder:`Add contact email`,type:`email`}),(0,Z.jsx)(H,{type:`button`,variant:`outline`,size:`icon`,disabled:!p.trim(),onClick:()=>C(e.value??[]),children:(0,Z.jsx)(V,{className:`h-4 w-4`})})]})]})}),(0,Z.jsx)(P,{})]})}),S&&(0,Z.jsx)(k,{control:u.control,name:`billingEmails`,render:({field:e,fieldState:t})=>(0,Z.jsxs)(j,{className:`md:col-span-2`,children:[(0,Z.jsxs)(M,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(He,{className:`h-4 w-4`}),`Billing Emails`]}),(0,Z.jsx)(N,{children:(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`div`,{className:T(t)+` flex flex-wrap gap-2 mb-2 rounded-md`,children:e.value?.map((t,n)=>(0,Z.jsxs)(J,{variant:`secondary`,className:`gap-1 pr-1`,children:[t,(0,Z.jsx)(`button`,{type:`button`,onClick:()=>w(e.value??[],n),className:`ml-1 hover:bg-muted rounded-sm p-0.5`,children:(0,Z.jsx)(D,{className:`h-3 w-3`})})]},n))}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(z,{value:h,onChange:e=>g(e.target.value),onKeyDown:t=>{t.key===`Enter`&&(t.preventDefault(),re(e.value??[]))},placeholder:`Add billing email`,type:`email`}),(0,Z.jsx)(H,{type:`button`,variant:`outline`,size:`icon`,disabled:!h.trim(),onClick:()=>re(e.value??[]),children:(0,Z.jsx)(V,{className:`h-4 w-4`})})]})]})}),(0,Z.jsx)(P,{})]})})]})}),(0,Z.jsx)(Jt,{className:`flex justify-end border-t mt-4 pt-6`,children:(0,Z.jsxs)(H,{type:`submit`,disabled:s||l||Object.keys(u.formState.dirtyFields).length===0,children:[(0,Z.jsx)(Pt,{className:`h-4 w-4 mr-2`}),`Save Changes`]})})]})})]})}function ro({businessId:e}){return(0,Z.jsxs)(q,{children:[(0,Z.jsx)(U,{children:(0,Z.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(G,{children:`Documents`}),(0,Z.jsx)(K,{children:`Invoices, proformas, receipts, and other accounting documents`})]})})}),(0,Z.jsx)(W,{children:(0,Z.jsx)(Tt,{businessId:e,linkedDocumentIds:[],limit:1e3})})]})}function io({businessId:e}){let[{data:t,fetching:n}]=f({query:C,variables:{businessId:e}});return n?(0,Z.jsx)(`div`,{children:`Loading ledger records...`}):(0,Z.jsxs)(q,{children:[(0,Z.jsx)(U,{className:`flex w-full justify-between items-center`,children:(0,Z.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(G,{children:`Ledger Records`}),(0,Z.jsx)(K,{children:`Complete ledger history for this business`})]})})}),(0,Z.jsx)(W,{children:(0,Z.jsx)(`div`,{className:`rounded-md border`,children:(0,Z.jsx)(Ae,{ledgerRecordsData:t?.ledgerRecordsByFinancialEntity??[]})})})]})}function ao({businessId:e}){let[{data:t,fetching:n}]=f({query:h,variables:{businessId:e}});return n?(0,Z.jsx)(`div`,{children:`Loading transactions...`}):(0,Z.jsxs)(q,{children:[(0,Z.jsxs)(U,{className:`flex w-full justify-between items-center`,children:[(0,Z.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(G,{children:`Transactions`}),(0,Z.jsx)(K,{children:`Complete transaction history for this business`})]})}),(0,Z.jsx)(pr,{rawTransactions:t?.transactionsByFinancialEntity??[]})]}),(0,Z.jsx)(W,{children:(0,Z.jsx)(`div`,{className:`rounded-md border`,children:(0,Z.jsx)(sn,{transactionsProps:t?.transactionsByFinancialEntity??[]})})})]})}function oo({data:e,refetchBusiness:t}){let n=Xt(x,e),[r,i]=de(),{setFiltersContext:a}=(0,X.useContext)(rn);(0,X.useEffect)(()=>{a(null)},[a]);let o=r.get(`tab`)||`contact`,s=e=>{i({tab:e})};if(!n)return(0,Z.jsx)(`div`,{children:`Business not found`});let c=`clientInfo`in n&&!!n.clientInfo,l=`adminInfo`in n&&!!n.adminInfo;return(0,Z.jsxs)(`div`,{className:`min-h-screen bg-background`,children:[(0,Z.jsx)(on,{data:n}),(0,Z.jsx)(`main`,{className:`container mx-auto px-4 py-6 md:px-6 lg:px-8 max-w-7xl`,children:(0,Z.jsxs)(mt,{value:o,onValueChange:s,className:`w-full`,children:[(0,Z.jsxs)(yt,{className:`grid w-full lg:grid-cols-8 sm:grid-cols-4 grid-cols-8 mb-6 h-auto gap-1 bg-muted/50 p-1`,children:[(0,Z.jsxs)(R,{value:`contact`,className:`flex items-center gap-2 data-[state=active]:bg-background`,children:[(0,Z.jsx)(jt,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{className:`hidden sm:inline`,children:`Contact`})]}),(0,Z.jsxs)(R,{value:`config`,className:`flex items-center gap-2 data-[state=active]:bg-background`,children:[(0,Z.jsx)(tt,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{className:`hidden sm:inline`,children:`Config`})]}),(0,Z.jsxs)(R,{value:`charges`,className:`flex items-center gap-2 data-[state=active]:bg-background`,children:[(0,Z.jsx)(Or,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{className:`hidden sm:inline`,children:`Charges`})]}),(0,Z.jsxs)(R,{value:`transactions`,className:`flex items-center gap-2 data-[state=active]:bg-background`,children:[(0,Z.jsx)(tn,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{className:`hidden sm:inline`,children:`Transactions`})]}),(0,Z.jsxs)(R,{value:`documents`,className:`flex items-center gap-2 data-[state=active]:bg-background`,children:[(0,Z.jsx)(ut,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{className:`hidden sm:inline`,children:`Documents`})]}),(0,Z.jsxs)(R,{value:`ledger`,className:`flex items-center gap-2 data-[state=active]:bg-background`,children:[(0,Z.jsx)(jr,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{className:`hidden sm:inline`,children:`Ledger`})]}),(0,Z.jsxs)(R,{value:`balance`,className:`flex items-center gap-2 data-[state=active]:bg-background`,children:[(0,Z.jsx)(Er,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{className:`hidden sm:inline`,children:`Balance`})]}),c&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(R,{value:`contracts`,className:`flex items-center gap-2 data-[state=active]:bg-background`,children:[(0,Z.jsx)(kr,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{className:`hidden sm:inline`,children:`Contracts`})]}),(0,Z.jsxs)(R,{value:`integrations`,className:`flex items-center gap-2 data-[state=active]:bg-background`,children:[(0,Z.jsx)(Mr,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{className:`hidden sm:inline`,children:`Integrations`})]})]}),l&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(R,{value:`accounts`,className:`flex items-center gap-2 data-[state=active]:bg-background`,children:[(0,Z.jsx)(Be,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{className:`hidden sm:inline`,children:`Accounts`})]}),(0,Z.jsxs)(R,{value:`admin`,className:`flex items-center gap-2 data-[state=active]:bg-background`,children:[(0,Z.jsx)(en,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{className:`hidden sm:inline`,children:`Admin`})]}),(0,Z.jsxs)(R,{value:`admin-config`,className:`flex items-center gap-2 data-[state=active]:bg-background`,children:[(0,Z.jsx)(en,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{className:`hidden sm:inline`,children:`Admin Config`})]})]})]}),(0,Z.jsx)(I,{value:`contact`,className:`mt-0`,children:(0,Z.jsx)(no,{data:n,refetchBusiness:t})}),(0,Z.jsx)(I,{value:`config`,className:`mt-0`,children:(0,Z.jsx)(Ja,{data:n,refetchBusiness:t})}),(0,Z.jsx)(I,{value:`charges`,className:`mt-0`,children:(0,Z.jsx)(fi,{businessId:n.id})}),(0,Z.jsx)(I,{value:`transactions`,className:`mt-0`,children:(0,Z.jsx)(ao,{businessId:n.id})}),(0,Z.jsx)(I,{value:`documents`,className:`mt-0`,children:(0,Z.jsx)(ro,{businessId:n.id})}),(0,Z.jsx)(I,{value:`ledger`,className:`mt-0`,children:(0,Z.jsx)(io,{businessId:n.id})}),(0,Z.jsx)(I,{value:`balance`,className:`mt-0`,children:(0,Z.jsx)(di,{businessId:n.id})}),c&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(I,{value:`contracts`,className:`mt-0`,children:(0,Z.jsx)(Ra,{clientId:n.id})}),(0,Z.jsx)(I,{value:`integrations`,className:`mt-0`,children:(0,Z.jsx)(Va,{data:n})}),(0,Z.jsx)(I,{value:`charts`,className:`mt-0`,children:(0,Z.jsx)(Fa,{})})]}),l&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(I,{value:`accounts`,className:`mt-0`,children:(0,Z.jsx)(ui,{adminId:n.id})}),(0,Z.jsx)(I,{value:`admin`,className:`mt-0`,children:(0,Z.jsx)($r,{data:n})}),(0,Z.jsx)(I,{value:`admin-config`,className:`mt-0`,children:(0,Z.jsx)(Wr,{})})]})]})})]})}var so=()=>{let{businessId:e}=ge(),t;try{t=pe()}catch{}let[{data:n,fetching:r},i]=f({query:b,pause:!e||!!t,variables:{businessId:e??``}}),a=t||n;return!t&&r&&!a?.business?(0,Z.jsx)(Yt,{}):!e||!a?.business?(0,Z.jsx)(`div`,{children:`Business not found`}):(0,Z.jsx)(oo,{data:a.business,refetchBusiness:async()=>i()})};export{so as BusinessScreen};