UNPKG

@accounter/client

Version:
1 lines 60.8 kB
import{s as e}from"./dist-ypP48_Ax.js";import{i as t,o as n}from"./utils-CbS-oR5I.js";import{r,t as i}from"./error-handling-CKe_iwSC.js";import{t as a}from"./chunk-62JRHF6Z-CBbOZODe.js";import{t as o}from"./createLucideIcon-BK8Z-P8J.js";import{$ as s,Ct as c,Er as l,Et as u,Jt as d,Ot as f,Qn as p,Qt as m,U as h,Ut as g,Wt as _,Zt as v,_r as y,an as b,ar as x,dn as ee,dt as te,en as S,et as ne,j as re,lt as C,nn as w,on as T,ot as E,st as ie,vr as D,yt as ae}from"./common-DtCH-1rN.js";import{r as oe,t as se}from"./similar-transactions-modal-C600zv0h.js";import{pt as O,s as k,ut as A}from"./select-DrAHsHyM.js";import{y as ce}from"./separator-C_NTzotM.js";import{t as le}from"./loader-circle-CZACSY-b.js";import{t as ue}from"./routes-4W-duEv9.js";import{t as j}from"./button-DUNsVBiu.js";import{i as M,n as N,r as P,t as de}from"./accordion-Bfa7-As4.js";import{Gc as F,Hc as I,Jc as L,Kc as R,Kl as z,Vc as B,Wc as V,Zc as H,el as U,nl as fe,ol as W,qc as G,sl as K}from"./table-BXolY871.js";import{At as pe,Bn as me,Bt as he,Cr as ge,Ct as _e,Dt as ve,Et as ye,Ft as be,Ga as xe,In as Se,Ja as Ce,Ka as we,Kt as Te,Lt as Ee,Mt as De,Ot as Oe,Pt as ke,Qa as Ae,Rr as je,Rt as Me,St as Ne,Tt as Pe,Ua as Fe,Wa as Ie,Z as Le,Za as Re,ao as ze,bt as Be,c as Ve,co as He,cs as q,d as Ue,jt as We,l as Ge,lo as Ke,ls as J,mr as qe,oo as Je,qa as Ye,qt as Xe,ro as Ze,s as Qe,so as $e,u as et,wt as tt,xt as nt,zn as rt}from"./graphql-HKLcNTdf.js";import{t as it}from"./Card-03FbGebu.js";import{t as at}from"./MultiSelect-BX6mil7t.js";import{V as ot}from"./index-U1vN7cBF.js";var st=o(`car`,[[`path`,{d:`M19 17h2c.6 0 1-.4 1-1v-3c0-.9-.7-1.7-1.5-1.9C18.7 10.6 16 10 16 10s-1.3-1.4-2.2-2.3c-.5-.4-1.1-.7-1.8-.7H5c-.6 0-1.1.4-1.4.9l-1.4 2.9A3.7 3.7 0 0 0 2 12v4c0 .6.4 1 1 1h2`,key:`5owen`}],[`circle`,{cx:`7`,cy:`17`,r:`2`,key:`u2ysq9`}],[`path`,{d:`M9 17h6`,key:`r8uit2`}],[`circle`,{cx:`17`,cy:`17`,r:`2`,key:`axvx0g`}]]),ct=o(`fuel`,[[`path`,{d:`M14 13h2a2 2 0 0 1 2 2v2a2 2 0 0 0 4 0v-6.998a2 2 0 0 0-.59-1.42L18 5`,key:`1wtuz0`}],[`path`,{d:`M14 21V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v16`,key:`e09ifn`}],[`path`,{d:`M2 21h13`,key:`1x0fut`}],[`path`,{d:`M3 9h11`,key:`1p7c0w`}]]),Y=e(n(),1),lt=`addBusinessTripAccommodationsExpense`,ut=()=>{let[{fetching:e},t]=q(Qe);return{fetching:e,addBusinessTripAccommodationsExpense:(0,Y.useCallback)(async e=>{let n=`Error adding business trip accommodations expense`,a=lt;r.loading(`Adding Business Trip Accommodations Expense`,{id:a});try{let o=await t(e),s=i(o,n,a);if(s)return r.success(`Success`,{id:a,description:`Business trip accommodations expense added`}),s.addBusinessTripAccommodationsExpense}catch(e){console.error(`${n}: ${e}`),r.error(`Error`,{id:a,description:n,duration:1e5,closeButton:!0})}},[t])}},X=t();function dt({formManager:e,attendeesStayPath:t,attendeesData:n,fetchingAttendees:r=!1,businessTripId:i}){let{control:a,trigger:o}=e,{controlledFields:s,append:c,remove:u}=C(e,t),[d,f]=(0,Y.useState)(r),[p,h]=(0,Y.useState)(n??[]);(0,Y.useEffect)(()=>{n&&h(n)},[n]),(0,Y.useEffect)(()=>{f(r)},[r]);let[{data:g,fetching:_},y]=J({query:Le,pause:!0,variables:{businessTripId:i??``}});return(0,Y.useEffect)(()=>{if(g?.businessTrip?.attendees.length){let e=g.businessTrip.attendees.map(e=>({value:e.id,label:e.name}))??[];h(e)}},[g?.businessTrip?.attendees]),(0,Y.useEffect)(()=>{f(_)},[_]),(0,Y.useEffect)(()=>{!n&&!g&&!r&&!_&&y({businessTripId:i})},[n,r,_,y,i,g]),!i&&!n?(0,X.jsx)(`div`,{children:`Cannot edit attendees stay, lacking some mandatory information!`}):(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`span`,{className:`mantine-InputWrapper-label mantine-Select-label`,children:`Employees Stay`}),(0,X.jsxs)(`div`,{className:`h-full flex flex-col overflow-hidden`,children:[s?.map((e,n)=>(0,X.jsxs)(`div`,{className:`flex items-end gap-2 text-gray-600 mb-2`,children:[(0,X.jsx)(`div`,{className:`w-full mt-1 relative rounded-md shadow-xs`,children:(0,X.jsx)(L,{name:`${t}.${n}.attendeeId`,control:a,rules:{required:`Required`},render:({field:e,fieldState:t})=>(0,X.jsx)(v,{...e,disabled:d,data:p,value:e.value??void 0,label:`Attendee`,placeholder:`Scroll to see all options`,maxDropdownHeight:160,searchable:!0,error:t.error?.message,withinPortal:!0,required:!0})})}),(0,X.jsx)(`div`,{className:`w-full mt-1 relative rounded-md shadow-xs`,children:(0,X.jsx)(L,{control:a,name:`${t}.${n}.nightsCount`,render:({field:e,fieldState:t})=>(0,X.jsx)(m,{className:`w-full`,...e,min:0,label:`Nights Count`,value:e.value??void 0,hideControls:!0,precision:0,error:t.error?.message,required:!0,onChange:t=>e.onChange(t&&typeof t==`number`?t:void 0)})})}),(0,X.jsx)(j,{variant:`ghost`,size:`icon`,className:`mb-2 size-7.5`,onClick:()=>{u(n),o(t)},children:(0,X.jsx)(ce,{className:`size-5`})})]},e.id)),(0,X.jsx)(j,{variant:`ghost`,size:`icon`,className:`size-7.5`,onClick:()=>{c({}),o(t)},children:(0,X.jsx)(l,{className:`size-5`})})]})]})}function Z({businessTripId:e,control:t,setFetching:n}){let[i,a]=(0,Y.useState)([]),[{data:o,fetching:s,error:c}]=J({query:Le,variables:{businessTripId:e}}),{userContext:l}=(0,Y.useContext)(fe);(0,Y.useEffect)(()=>{o?.businessTrip?.attendees.length&&a(o.businessTrip.attendees.map(e=>({value:e.id,label:e.name})).sort((e,t)=>e.label>t.label?1:-1))},[o,a]),(0,Y.useEffect)(()=>{n(s)},[n,s]),(0,Y.useEffect)(()=>{c&&r.error(`Error`,{description:`Oops, we have an error fetching attendees`})},[c]);let u=(0,Y.useMemo)(()=>l?.context.ledgerLock,[l]);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(V,{name:`date`,control:t,rules:{min:u?{value:u,message:`Date must be after ${u}`}:void 0,pattern:{value:x,message:`Date must be in format yyyy-mm-dd`}},render:({field:e,fieldState:t})=>(0,X.jsxs)(F,{children:[(0,X.jsx)(R,{htmlFor:`expense-date`,children:`Date`}),(0,X.jsx)(I,{children:(0,X.jsx)(E,{id:`expense-date`,"data-autofocus":!0,value:e.value??void 0,onChange:t=>{t!==e.value&&e.onChange(t)},"aria-invalid":!!t.error})}),(0,X.jsx)(G,{})]})}),(0,X.jsx)(V,{name:`valueDate`,control:t,rules:{pattern:{value:x,message:`Date must be in format yyyy-mm-dd`},min:u?{value:u,message:`Date must be after ${u}`}:void 0},render:({field:e,fieldState:t})=>(0,X.jsxs)(F,{children:[(0,X.jsx)(R,{htmlFor:`expense-value-date`,children:`Value Date`}),(0,X.jsx)(I,{children:(0,X.jsx)(E,{id:`expense-value-date`,value:e.value??void 0,onChange:t=>{t!==e.value&&e.onChange(t)},"aria-invalid":!!t.error})}),(0,X.jsx)(G,{})]})}),(0,X.jsx)(V,{name:`amount`,control:t,render:({field:e,fieldState:n})=>(0,X.jsx)(V,{name:`currency`,control:t,defaultValue:Se.Ils,render:({field:t,fieldState:r})=>(0,X.jsx)(ie,{...e,value:e.value??void 0,error:n.error?.message||r.error?.message,label:`Amount`,currencyCodeProps:{...t,label:`Currency`}})})}),(0,X.jsx)(V,{name:`employeeBusinessId`,control:t,render:({field:e,fieldState:t})=>(0,X.jsxs)(F,{children:[(0,X.jsx)(R,{children:`Attendee`}),(0,X.jsx)(I,{children:(0,X.jsx)(v,{...e,data:i,value:e.value,disabled:s,placeholder:`Scroll to see all options`,maxDropdownHeight:160,searchable:!0,error:t.error?.message,withinPortal:!0})}),(0,X.jsx)(G,{})]})})]})}function ft(e){let{businessTripId:t,onAdd:n}=e,[r,i]=(0,Y.useState)(!1);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(c,{content:`Add Accommodations Expense`,children:(0,X.jsx)(j,{variant:`outline`,size:`icon`,className:`size-7.5`,onClick:e=>{e.stopPropagation(),i(!0)},children:(0,X.jsx)(A,{className:`size-5`})})}),r&&(0,X.jsx)(pt,{businessTripId:t,opened:r,close:()=>i(!1),onAdd:n})]})}function pt({businessTripId:e,opened:t,close:n,onAdd:r}){let i=H({defaultValues:{businessTripId:e}}),{control:a,handleSubmit:o}=i,[s,c]=(0,Y.useState)(!1),{addBusinessTripAccommodationsExpense:l,fetching:u}=ut(),d=e=>{l({fields:e}).then(()=>{r?.(),n()})};return(0,X.jsxs)(S,{opened:t,onClose:n,centered:!0,lockScroll:!0,children:[(0,X.jsx)(S.Title,{children:`Add Accommodation Expense`}),(0,X.jsx)(S.Body,{children:(0,X.jsx)(B,{...i,children:(0,X.jsxs)(`form`,{onSubmit:o(d),className:`space-y-3`,children:[(0,X.jsx)(Z,{businessTripId:e,control:a,setFetching:c}),(0,X.jsx)(V,{control:a,name:`country`,render:({field:e})=>(0,X.jsxs)(F,{children:[(0,X.jsx)(R,{children:`Country`}),(0,X.jsx)(I,{children:(0,X.jsx)(k,{...e,value:e.value??void 0})}),(0,X.jsx)(G,{})]})}),(0,X.jsx)(V,{name:`nightsCount`,control:a,render:({field:e})=>(0,X.jsxs)(F,{children:[(0,X.jsx)(R,{children:`Nights Count`}),(0,X.jsx)(I,{children:(0,X.jsx)(ne,{...e,value:e.value??void 0,hideControls:!0,decimalScale:0,thousandSeparator:`,`})}),(0,X.jsx)(G,{})]})}),(0,X.jsx)(dt,{formManager:i,attendeesStayPath:`attendeesStay`,businessTripId:e}),(0,X.jsx)(`div`,{className:`flex justify-center mt-5 gap-3`,children:(0,X.jsx)(`button`,{type:`submit`,className:`text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg`,children:`Add`})})]})})}),(u||s)&&(0,X.jsx)(T,{blur:1,center:!0,children:(0,X.jsx)(K,{})})]})}var mt=`updateBusinessTripAccommodationsExpense`,ht=()=>{let[{fetching:e},t]=q(Ze);return{fetching:e,updateBusinessTripAccommodationsExpense:(0,Y.useCallback)(async e=>{let n=`Error updating business trip accommodations expense`,a=mt;r.loading(`Updating trip accommodations expense`,{id:a});try{let o=await t(e),s=i(o,n,a);if(s)return r.success(`Success`,{id:a,description:`Business trip accommodations expense was updated`}),s.updateBusinessTripAccommodationsExpense}catch(e){console.error(`${n}: ${e}`),r.error(`Error`,{id:a,description:n,duration:1e5,closeButton:!0})}},[t])}},gt=`categorizeIntoExistingBusinessTripExpense`,_t=()=>{let[{fetching:e},t]=q(Xe);return{fetching:e,categorizeIntoExistingBusinessTripExpense:(0,Y.useCallback)(async e=>{let n=`Error updating business trip expense category`,a=gt;r.loading(`Updating business trip expense category`,{id:a});try{let o=await t(e),s=i(o,n,a);if(s)return r.success(`Success`,{id:a,description:`Business trip expense category was updated`}),s.categorizeIntoExistingBusinessTripExpense}catch(e){console.error(`${n}: ${e}`),r.error(`Error`,{id:a,description:n,duration:1e5,closeButton:!0})}},[t])}};function Q(e){let{businessTripExpenseId:t,businessTripId:n,onChange:r}=e,[i,a]=(0,Y.useState)(!1);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(c,{content:`Attach Uncategorized Transaction`,children:(0,X.jsx)(j,{variant:`outline`,size:`icon`,className:`size-7.5`,onClick:e=>{e.stopPropagation(),a(!0)},children:(0,X.jsx)(A,{className:`size-5`})})}),i&&(0,X.jsx)(vt,{businessTripExpenseId:t,businessTripId:n,opened:i,close:()=>a(!1),onChange:r})]})}function vt({businessTripExpenseId:e,businessTripId:t,opened:n,close:i,onChange:a}){let{control:o,handleSubmit:s,setValue:c}=H({defaultValues:{businessTripExpenseId:e}}),[l,u]=(0,Y.useState)([]),[{data:d,fetching:f,error:p}]=J({query:Re,variables:{businessTripId:t}}),{categorizeIntoExistingBusinessTripExpense:h,fetching:g}=_t();return(0,Y.useEffect)(()=>{if(d?.businessTrip?.uncategorizedTransactions.length){let e=d.businessTrip.uncategorizedTransactions.filter(e=>e?.transaction);u(e.map(({transaction:e})=>({eventDate:e.eventDate,sourceDescription:e.sourceDescription,referenceKey:e.referenceKey,counterparty:e.counterparty?.name,amount:e.amount.formatted,rawAmount:e.amount.raw,value:e.id,label:`${e.eventDate} | ${e.counterparty?.name} | ${e.amount.formatted}`})).sort((e,t)=>e.eventDate.localeCompare(t.eventDate)))}},[d,u]),(0,Y.useEffect)(()=>{p&&r.error(`Error`,{description:`Oops, we have an error fetching transactions to categorize`})},[p]),(0,X.jsxs)(S,{opened:n,onClose:i,centered:!0,children:[(0,X.jsx)(S.Title,{children:`Set Transaction Category`}),(0,X.jsx)(S.Body,{children:(0,X.jsxs)(`form`,{onSubmit:s(e=>{h({fields:e}).then(()=>{a?.(),i()})}),className:`flex flex-col gap-3 mt-3`,children:[(0,X.jsx)(L,{name:`transactionId`,control:o,render:({field:e,fieldState:t})=>(0,X.jsx)(v,{...e,itemComponent:yt,data:l??[],disabled:f,label:`Transactions`,placeholder:`Scroll to see all options`,maxDropdownHeight:160,error:t.error?.message,withAsterisk:!0,withinPortal:!0,onChange:t=>{let n=l.find(e=>e.value===t);n?.rawAmount&&c(`amount`,n.rawAmount),e.onChange(t)}})}),(0,X.jsx)(L,{name:`amount`,control:o,render:({field:e,fieldState:t})=>(0,X.jsx)(m,{...e,value:e.value??void 0,hideControls:!0,precision:2,removeTrailingZeros:!0,error:t.error?.message,label:`Amount`})}),(0,X.jsx)(`div`,{className:`flex justify-center gap-3`,children:(0,X.jsx)(`button`,{type:`submit`,className:`text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg`,children:`Confirm`})})]})}),g&&(0,X.jsx)(T,{blur:1,center:!0,children:(0,X.jsx)(K,{})})]})}var yt=(0,Y.forwardRef)(({eventDate:e,sourceDescription:t,referenceKey:n,counterparty:r,amount:i,...a},o)=>(0,X.jsx)(`div`,{ref:o,...a,children:(0,X.jsxs)(b,{children:[(0,X.jsx)(b.Col,{span:4,children:e}),(0,X.jsx)(b.Col,{span:4,children:(0,X.jsx)(W,{size:`sm`,children:r})}),(0,X.jsx)(b.Col,{span:4,children:(0,X.jsx)(W,{size:`sm`,children:i})}),(0,X.jsx)(b.Col,{span:8,children:(0,X.jsx)(W,{size:`xs`,opacity:.65,children:t})}),(0,X.jsxs)(b.Col,{span:4,children:[`Reference: `,n]})]})})),bt=`deleteBusinessTripExpense`,xt=()=>{let[{fetching:e},t]=q(me);return{fetching:e,deleteBusinessTripExpense:(0,Y.useCallback)(async e=>{let n=`Error deleting business trip expense`,a=`${bt}-${e.businessTripExpenseId}`;r.loading(`Deleting trip expense`,{id:a});try{let o=await t(e),s=i(o,n,a);if(s)return r.success(`Success`,{id:a,description:`Business trip expense was deleted`}),s.deleteBusinessTripExpense}catch(e){console.error(`${n}: ${e}`),r.error(`Error`,{id:a,description:n,duration:1e5,closeButton:!0})}},[t])}};function $(e){let{fetching:t,deleteBusinessTripExpense:n}=xt(),r=(0,Y.useCallback)(()=>{n({businessTripExpenseId:e.businessTripExpenseId}).then(()=>{e.onDelete?.()})},[e,n]);return(0,X.jsx)(c,{content:`Remove Expense`,children:(0,X.jsx)(h,{onConfirm:r,title:`Are you sure you want to remove expense?`,children:(0,X.jsx)(j,{variant:`outline`,size:`icon`,className:`size-7.5 text-red-500`,disabled:t,children:(0,X.jsx)(y,{className:`size-5`})})})})}var St=({data:e,isEditMode:t=!1,control:n,businessTripId:i})=>{let o=U(Oe,e),[s,c]=(0,Y.useState)([]),[{data:l,fetching:u,error:d}]=J({query:Le,variables:{businessTripId:i}});(0,Y.useEffect)(()=>{l?.businessTrip?.attendees.length&&c(l.businessTrip.attendees.map(e=>({value:e.id,label:e.name})).sort((e,t)=>e.label>t.label?1:-1))},[l,c]),(0,Y.useEffect)(()=>{d&&r.error(`Error`,{description:`Oops, we have an error fetching attendees`})},[d]);let f=Array.from(new Set(o.charges?.map(e=>e.id)));return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`td`,{children:(0,X.jsx)(`div`,{className:`flex flex-col gap-2 justify-center`,children:t&&o.payedByEmployee?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(V,{name:`date`,control:n,defaultValue:o.date,rules:{pattern:{value:x,message:`Date must be in format yyyy-mm-dd`}},render:({field:e,fieldState:t})=>(0,X.jsxs)(F,{className:`h-min`,children:[(0,X.jsx)(R,{htmlFor:`business-trip-expense-date-${o.id}`,children:`Date`}),(0,X.jsx)(I,{children:(0,X.jsx)(E,{id:`business-trip-expense-date-${o.id}`,form:`form ${o.id}`,"data-autofocus":!0,value:e.value??void 0,onChange:t=>{t!==e.value&&e.onChange(t)},"aria-invalid":!!t.error})}),(0,X.jsx)(G,{})]})}),(0,X.jsx)(V,{name:`valueDate`,control:n,defaultValue:o.valueDate,rules:{pattern:{value:x,message:`Date must be in format yyyy-mm-dd`}},render:({field:e,fieldState:t})=>(0,X.jsxs)(F,{className:`h-min`,children:[(0,X.jsx)(R,{children:`Value Date`}),(0,X.jsx)(I,{children:(0,X.jsx)(E,{form:`form ${o.id}`,value:e.value??void 0,onChange:t=>{t!==e.value&&e.onChange(t)},"aria-invalid":!!t.error})}),(0,X.jsx)(G,{})]})})]}):(0,X.jsxs)(X.Fragment,{children:[o.date&&z(new Date(o.date),`dd/MM/yy`),(0,X.jsx)(W,{fz:`sm`,c:`dimmed`,children:o.valueDate&&z(new Date(o.valueDate),`dd/MM/yy`)})]})})}),(0,X.jsx)(`td`,{children:t&&o.payedByEmployee?(0,X.jsx)(V,{name:`amount`,control:n,defaultValue:o.amount?.raw??void 0,render:({field:e,fieldState:t})=>(0,X.jsx)(V,{name:`currency`,control:n,defaultValue:o.amount?.currency??Se.Ils,render:({field:n,fieldState:r})=>(0,X.jsx)(ie,{form:`form ${o.id}`,...e,value:e.value??void 0,error:t.error?.message||r.error?.message,label:`Amount`,currencyCodeProps:{...n,label:`Currency`,form:`form ${o.id}`}})})}):(0,X.jsx)(`div`,{children:o.amount?.formatted})}),(0,X.jsx)(`td`,{children:(0,X.jsx)(`div`,{className:`flex flex-col gap-2 justify-center`,children:t&&o.payedByEmployee?(0,X.jsx)(V,{name:`employeeBusinessId`,control:n,defaultValue:o.employee?.id,render:({field:e,fieldState:t})=>(0,X.jsx)(v,{form:`form ${o.id}`,...e,data:s,value:e.value,disabled:u,label:`Attendee`,placeholder:`Scroll to see all options`,maxDropdownHeight:160,searchable:!0,error:t.error?.message,withinPortal:!0})}):(0,X.jsx)(`div`,{className:`flex flex-row gap-2 items-center`,children:o.payedByEmployee&&(0,X.jsx)(W,{c:o.employee?.name?void 0:`red`,children:o.employee?.name??`Missing`})})})}),(0,X.jsx)(`td`,{children:(0,X.jsx)(`div`,{className:`flex flex-col gap-2`,children:f.map(e=>(0,X.jsx)(a,{to:ue.CHARGES.DETAIL(e),target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`inline-flex items-center font-semibold`,children:`To Charge`},e))})})]})},Ct=()=>(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`th`,{children:`Date`}),(0,X.jsx)(`th`,{children:`Amount`}),(0,X.jsx)(`th`,{children:`Payed By Attendee`}),(0,X.jsx)(`th`,{children:`Charges`})]}),wt=({data:e,businessTripId:t,onChange:n})=>{let r=U(Ne,e),[i,a]=(0,Y.useState)(!1),o=H({defaultValues:{id:r.id,businessTripId:t,attendeesStay:r.attendeesStay.map(e=>({attendeeId:e.id,nightsCount:e.nightsCount}))}}),{control:s,handleSubmit:l}=o,{updateBusinessTripAccommodationsExpense:u,fetching:d}=ht(),f=e=>{u({fields:e}).then(()=>{n?.(),a(!1)})};return(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(St,{data:r,isEditMode:i,control:s,businessTripId:t}),(0,X.jsx)(`td`,{children:(0,X.jsx)(B,{...o,children:(0,X.jsx)(`form`,{id:`form ${r.id}`,onSubmit:l(f),children:i?(0,X.jsx)(V,{name:`country`,control:s,defaultValue:r.country?.id??void 0,render:({field:e})=>(0,X.jsxs)(F,{children:[(0,X.jsx)(I,{children:(0,X.jsx)(k,{form:`form ${r.id}`,...e,value:e.value??void 0})}),(0,X.jsx)(G,{})]})}):(0,X.jsx)(W,{c:r.country?void 0:`red`,children:r.country?.name??`Missing`})})})}),(0,X.jsx)(`td`,{children:(0,X.jsx)(`div`,{className:`flex flex-col gap-2 justify-center`,children:i?(0,X.jsx)(B,{...o,children:(0,X.jsx)(V,{name:`nightsCount`,control:s,defaultValue:r.nightsCount,render:({field:e})=>(0,X.jsxs)(F,{children:[(0,X.jsx)(I,{children:(0,X.jsx)(ne,{...e,value:e.value??void 0,form:`form ${r.id}`,hideControls:!0,decimalScale:0,thousandSeparator:`,`})}),(0,X.jsx)(G,{})]})})}):(0,X.jsx)(W,{c:r.nightsCount?void 0:`red`,children:r.nightsCount??`Missing`})})}),(0,X.jsx)(`td`,{children:i?(0,X.jsx)(B,{...o,children:(0,X.jsx)(dt,{formManager:o,attendeesStayPath:`attendeesStay`,businessTripId:t})}):(0,X.jsx)(w,{listStyleType:`disc`,children:r.attendeesStay?.length?r.attendeesStay.map(e=>(0,X.jsxs)(w.Item,{children:[e.attendee.name,` (`,e.nightsCount,`)`]},e.id)):(0,X.jsx)(W,{c:`red`,fz:`sm`,children:`Missing`})})}),(0,X.jsx)(`td`,{children:n&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(c,{content:`Edit`,children:(0,X.jsx)(j,{disabled:d,variant:i?`default`:`outline`,size:`icon`,className:`size-7.5`,onClick:e=>{e.stopPropagation(),a(e=>!e)},children:(0,X.jsx)(D,{className:`size-5`})})}),i&&(0,X.jsx)(c,{content:`Confirm Changes`,children:(0,X.jsx)(j,{type:`submit`,form:`form ${r.id}`,variant:`outline`,size:`icon`,className:`size-7.5 text-green-500`,children:(0,X.jsx)(O,{className:`size-5`})})}),(0,X.jsx)(Q,{businessTripExpenseId:r.id,businessTripId:t,onChange:n}),(0,X.jsx)($,{businessTripExpenseId:r.id,onDelete:n})]})})]},r.id)},Tt=({businessTripId:e,expenses:t,onChange:n})=>{if(!t?.length)return n?(0,X.jsx)(ft,{businessTripId:e,onAdd:n}):(0,X.jsx)(X.Fragment,{});let r=t.map(e=>U(_e,e));return(0,X.jsx)(`div`,{className:`flex flex-col gap-2 mt-5`,children:(0,X.jsxs)(d,{highlightOnHover:!0,withBorder:!0,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(Ct,{}),(0,X.jsx)(`th`,{children:`Location`}),(0,X.jsx)(`th`,{children:`Nights`}),(0,X.jsx)(`th`,{children:`Attendees Stay`}),(0,X.jsx)(`th`,{})]})}),(0,X.jsxs)(`tbody`,{children:[r.sort((e,t)=>e.date&&t.date?e.date<t.date?1:-1:e.date?-1:+!!t.date).map(t=>(0,X.jsx)(wt,{data:t,businessTripId:e,onChange:n},t.id)),n&&(0,X.jsx)(`tr`,{children:(0,X.jsx)(`td`,{colSpan:6,children:(0,X.jsx)(ft,{businessTripId:e,onAdd:n})})})]})]})})},Et=({data:e,onChange:t})=>{let{accommodationExpenses:n,id:r}=U(nt,e);return(0,X.jsx)(Tt,{businessTripId:r,expenses:n,onChange:t})},Dt=`insertBusinessTripAttendee`,Ot=()=>{let[{fetching:e},t]=q(je);return{fetching:e,insertBusinessTripAttendee:(0,Y.useCallback)(async e=>{let n=`Error adding attendee to business trip`,a=Dt;r.loading(`Adding attendee`,{id:a});try{let o=await t(e),s=i(o,n,a);if(s)return r.success(`Success`,{id:a,description:`Attendee was added to the business trip`}),s.insertBusinessTripAttendee}catch(e){console.error(`${n}: ${e}`),r.error(`Error`,{id:a,description:n,duration:1e5,closeButton:!0})}},[t])}};function kt(e){let{businessTripId:t,onAdd:n}=e,[r,i]=(0,Y.useState)(!1);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(c,{content:`Add Attendee`,children:(0,X.jsx)(j,{variant:`outline`,size:`icon`,onClick:e=>{e.stopPropagation(),i(!0)},className:`size-7.5`,children:(0,X.jsx)(A,{className:`size-5`})})}),r&&(0,X.jsx)(At,{businessTripId:t,opened:r,close:()=>i(!1),onAdd:n})]})}function At({businessTripId:e,opened:t,close:n,onAdd:r}){let{selectableBusinesses:i,fetching:a}=te(),o=H({defaultValues:{businessTripId:e}}),{control:s,handleSubmit:c}=o,{insertBusinessTripAttendee:l,fetching:u}=Ot(),d=e=>{l({fields:e}).then(()=>{r?.(),n()})};return(0,X.jsxs)(S,{opened:t,onClose:n,centered:!0,children:[(0,X.jsx)(S.Title,{children:`Add Attendee`}),(0,X.jsx)(S.Body,{children:(0,X.jsx)(B,{...o,children:(0,X.jsxs)(`form`,{onSubmit:c(d),className:`space-y-4 pt-2`,children:[(0,X.jsx)(L,{name:`attendeeId`,control:s,render:({field:e,fieldState:t})=>(0,X.jsx)(v,{"data-autofocus":!0,...e,data:i,value:e.value,disabled:a,label:`Attendee`,placeholder:`Scroll to see all options`,maxDropdownHeight:160,searchable:!0,error:t.error?.message,withAsterisk:!0,withinPortal:!0})}),(0,X.jsx)(V,{name:`arrivalDate`,control:s,rules:{pattern:{value:x,message:`Date must be in format yyyy-mm-dd`}},render:({field:e,fieldState:t})=>(0,X.jsxs)(F,{className:`h-min`,children:[(0,X.jsx)(R,{htmlFor:`arrival-date`,children:`Arrival`}),(0,X.jsx)(I,{children:(0,X.jsx)(E,{id:`arrival-date`,value:e.value??void 0,onChange:t=>{t!==e.value&&e.onChange(t)},"aria-invalid":!!t.error})}),(0,X.jsx)(G,{})]})}),(0,X.jsx)(V,{name:`departureDate`,control:s,rules:{pattern:{value:x,message:`Date must be in format yyyy-mm-dd`}},render:({field:e,fieldState:t})=>(0,X.jsxs)(F,{className:`h-min`,children:[(0,X.jsx)(R,{htmlFor:`departure-date`,children:`Departure`}),(0,X.jsx)(I,{children:(0,X.jsx)(E,{id:`departure-date`,value:e.value??void 0,onChange:t=>{t!==e.value&&e.onChange(t)},"aria-invalid":!!t.error})}),(0,X.jsx)(G,{})]})}),(0,X.jsx)(`div`,{className:`flex justify-center mt-5 gap-3`,children:(0,X.jsx)(`button`,{type:`submit`,className:`text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg`,children:`Add`})})]})})}),(u||a)&&(0,X.jsx)(T,{blur:1,center:!0,children:(0,X.jsx)(K,{})})]})}var jt=`updateBusinessTripAttendee`,Mt=()=>{let[{fetching:e},t]=q(ze);return{fetching:e,updateBusinessTripAttendee:(0,Y.useCallback)(async e=>{let n=`Error updating business trip attendee`,a=jt;r.loading(`Updating trip attendee`,{id:a});try{let o=await t(e),s=i(o,n,a);if(s)return r.success(`Success`,{id:a,description:`Business trip attendee was updated`}),s.updateBusinessTripAttendee}catch(e){console.error(`${n}: ${e}`),r.error(`Error`,{id:a,description:n,duration:1e5,closeButton:!0})}},[t])}},Nt=`deleteBusinessTripAttendee`,Pt=()=>{let[{fetching:e},t]=q(rt);return{fetching:e,deleteBusinessTripAttendee:(0,Y.useCallback)(async e=>{let n=`Error removing business trip attendee`,a=Nt;r.loading(`Removing business trip attendee`,{id:a});try{let o=await t(e),s=i(o,n,a);if(s)return r.success(`Success`,{id:a,description:`Business trip attendee was removed`}),s.deleteBusinessTripAttendee}catch(e){console.error(`${n}: ${e}`),r.error(`Error`,{id:a,description:n,duration:1e5,closeButton:!0})}},[t])}};function Ft(e){let{fetching:t,deleteBusinessTripAttendee:n}=Pt(),r=(0,Y.useCallback)(()=>{n({fields:{businessTripId:e.businessTripId,attendeeId:e.attendeeId}}).then(()=>{e.onDelete?.()})},[e,n]);return(0,X.jsx)(c,{content:`Remove Attendee`,children:(0,X.jsx)(h,{onConfirm:r,title:`Are you sure you want to remove attendee?`,children:(0,X.jsx)(j,{variant:`outline`,size:`icon`,className:`size-7.5 text-red-500`,disabled:t,children:(0,X.jsx)(y,{className:`size-5`})})})})}var It=`addBusinessTripFlightsExpense`,Lt=()=>{let[{fetching:e},t]=q(Ge);return{fetching:e,addBusinessTripFlightsExpense:(0,Y.useCallback)(async e=>{let n=`Error adding business trip flight expense`,a=It;r.loading(`Adding business trip flight expense`,{id:a});try{let o=await t(e),s=i(o,n,a);if(s)return r.success(`Success`,{id:a,description:`Business trip flight expense added`}),s.addBusinessTripFlightsExpense}catch(e){console.error(`${n}: ${e}`),r.error(`Error`,{id:a,description:n,duration:1e5,closeButton:!0})}},[t])}};function Rt({formManager:e,flightPathPath:t,flightPathData:n}){let{control:r,trigger:i}=e,{controlledFields:a,append:o,remove:s}=C(e,t);return n?(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`span`,{className:`mantine-InputWrapper-label mantine-Select-label`,children:`Flight Path`}),(0,X.jsxs)(`div`,{className:`h-full flex flex-col overflow-hidden`,children:[a?.map((e,n)=>(0,X.jsxs)(`div`,{className:`flex items-end gap-2 text-gray-600 mb-2`,children:[(0,X.jsx)(`div`,{className:`w-full mt-1 relative rounded-md shadow-xs`,children:(0,X.jsx)(V,{name:`${t}.${n}`,control:r,rules:{required:`Required`},render:({field:e})=>(0,X.jsxs)(F,{children:[(0,X.jsx)(I,{children:(0,X.jsx)(k,{...e,value:e.value??void 0,placeholder:`Destination`})}),(0,X.jsx)(G,{})]})})}),(0,X.jsx)(j,{variant:`ghost`,size:`icon`,className:`mb-2 size-7.5`,onClick:()=>{s(n),i(t)},children:(0,X.jsx)(ce,{className:`size-5`})})]},e.id)),(0,X.jsx)(j,{variant:`ghost`,size:`icon`,className:`size-7.5`,onClick:()=>{o(``),i(t)},children:(0,X.jsx)(l,{className:`size-5`})})]})]}):(0,X.jsx)(`div`,{children:`Cannot edit flight path stay, lacking some mandatory information!`})}function zt(e){let{businessTripId:t,onAdd:n}=e,[r,i]=(0,Y.useState)(!1);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(c,{content:`Add Flight Expense`,children:(0,X.jsx)(j,{variant:`outline`,size:`icon`,className:`size-7.5`,onClick:e=>{e.stopPropagation(),i(!0)},children:(0,X.jsx)(A,{className:`size-5`})})}),r&&(0,X.jsx)(Vt,{businessTripId:t,opened:r,close:()=>i(!1),onAdd:n})]})}var Bt=Object.entries(ge).map(([e,t])=>({value:t,label:e}));function Vt({businessTripId:e,opened:t,close:n,onAdd:r}){let i=H({defaultValues:{businessTripId:e}}),{control:a,handleSubmit:o}=i,[s,c]=(0,Y.useState)(!1),[{data:l,fetching:u}]=J({query:Le,variables:{businessTripId:e}}),{addBusinessTripFlightsExpense:d,fetching:f}=Lt(),p=e=>{d({fields:e}).then(()=>{r?.(),n()})},m=l?.businessTrip?.attendees.map(e=>({value:e.id,label:e.name}))??[];return(0,X.jsxs)(S,{opened:t,onClose:n,centered:!0,lockScroll:!0,children:[(0,X.jsx)(S.Title,{children:`Add Flight Expense`}),(0,X.jsx)(S.Body,{children:(0,X.jsx)(B,{...i,children:(0,X.jsxs)(`form`,{onSubmit:o(p),children:[(0,X.jsx)(Z,{businessTripId:e,control:a,setFetching:c}),(0,X.jsx)(Rt,{formManager:i,flightPathPath:`path`}),(0,X.jsx)(L,{name:`flightClass`,control:a,render:({field:e,fieldState:t})=>(0,X.jsx)(v,{...e,data:Bt,value:e.value,label:`Flight Class`,placeholder:`Scroll to see all options`,maxDropdownHeight:160,searchable:!0,error:t.error?.message,withinPortal:!0})}),(0,X.jsx)(L,{name:`attendeeIds`,control:a,render:({field:e,fieldState:t})=>(0,X.jsx)(at,{...e,disabled:u,data:m,value:e.value??[],label:`Attendees`,placeholder:`Scroll to see all options`,maxDropdownHeight:160,searchable:!0,error:t.error?.message,withinPortal:!0})}),(0,X.jsx)(`div`,{className:`flex justify-center mt-5 gap-3`,children:(0,X.jsx)(`button`,{type:`submit`,className:`text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg`,children:`Add`})})]})})}),(f||s)&&(0,X.jsx)(T,{blur:1,center:!0,children:(0,X.jsx)(K,{})})]})}var Ht=`updateBusinessTripFlightsExpense`,Ut=()=>{let[{fetching:e},t]=q($e);return{fetching:e,updateBusinessTripFlightsExpense:(0,Y.useCallback)(async e=>{let n=`Error updating business trip flights expense`,a=Ht;r.loading(`Updating trip flights expense`,{id:a});try{let o=await t(e),s=i(o,n,a);if(s)return r.success(`Success`,{id:a,description:`Business trip flights expense was updated`}),s.updateBusinessTripFlightsExpense}catch(e){console.error(`${n}: ${e}`),r.error(`Error`,{id:a,description:n,duration:1e5,closeButton:!0})}},[t])}},Wt=Object.entries(ge).map(([e,t])=>({value:t,label:e})),Gt=({data:e,businessTripId:t,onChange:n,attendees:r})=>{let i=U(We,e),[a,o]=(0,Y.useState)(!1),s=H({defaultValues:{id:i.id,businessTripId:t,attendeeIds:i.attendees?.map(e=>e.id)??[],path:i.path??[]}}),{control:l,handleSubmit:u}=s,{updateBusinessTripFlightsExpense:d,fetching:f}=Ut(),p=e=>{d({fields:e}).then(()=>{n?.(),o(!1)})},m=r.map(e=>({value:e.id,label:e.name}));return(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(St,{data:i,isEditMode:a,control:l,businessTripId:t}),(0,X.jsx)(`td`,{children:(0,X.jsx)(B,{...s,children:(0,X.jsx)(`form`,{id:`form ${i.id}`,onSubmit:u(p),children:(0,X.jsxs)(`div`,{className:`flex flex-col gap-2 justify-center`,children:[a?(0,X.jsx)(Rt,{formManager:s,flightPathPath:`path`,flightPathData:i.path??void 0}):(0,X.jsx)(`div`,{className:`flex gap-2 items-center`,children:i.path?.length?i.path.map((e,t)=>(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(W,{fw:700,children:e},t),t<i.path.length-1&&(e===i.path[t+1]?` | `:` → `)]})):(0,X.jsx)(W,{fw:700,className:`flex gap-2 items-center`,c:`red`,children:`Missing`})}),a?(0,X.jsx)(L,{name:`flightClass`,control:l,defaultValue:i.class??void 0,render:({field:e,fieldState:t})=>(0,X.jsx)(v,{form:`form ${i.id}`,"data-autofocus":!0,...e,data:Wt,value:e.value,label:`Flight Class`,placeholder:`Scroll to see all options`,maxDropdownHeight:160,searchable:!0,error:t.error?.message,withinPortal:!0})}):(0,X.jsx)(W,{c:i.class?void 0:`red`,fz:`sm`,children:`Class: ${i.class??`Missing`}`})]})})})}),(0,X.jsx)(`td`,{children:a?(0,X.jsx)(L,{name:`attendeeIds`,control:l,defaultValue:i.attendees?.map(e=>e.id)??void 0,render:({field:e,fieldState:t})=>(0,X.jsx)(at,{...e,form:`form ${i.id}`,data:m,value:e.value??[],label:`Attendees`,placeholder:`Scroll to see all options`,maxDropdownHeight:160,searchable:!0,error:t.error?.message,withinPortal:!0})}):(0,X.jsx)(w,{listStyleType:`disc`,children:i.attendees?.length?i.attendees.map(e=>(0,X.jsx)(w.Item,{children:e.name},e.id)):(0,X.jsx)(W,{c:`red`,fz:`sm`,children:`Missing`})})}),(0,X.jsx)(`td`,{children:n&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(c,{content:`Edit`,children:(0,X.jsx)(j,{disabled:f,variant:a?`default`:`outline`,size:`icon`,className:`size-7.5`,onClick:e=>{e.stopPropagation(),o(e=>!e)},children:(0,X.jsx)(D,{className:`size-5`})})}),a&&(0,X.jsx)(c,{content:`Confirm Changes`,children:(0,X.jsx)(j,{type:`submit`,form:`form ${i.id}`,variant:`outline`,size:`icon`,className:`size-7.5 text-green-500`,children:(0,X.jsx)(O,{className:`size-5`})})}),(0,X.jsx)(Q,{businessTripExpenseId:i.id,businessTripId:t,onChange:n}),(0,X.jsx)($,{businessTripExpenseId:i.id,onDelete:n})]})})]},i.id)},Kt=({businessTripId:e,expenses:t,attendees:n,onChange:r})=>{if(!t?.length)return r?(0,X.jsx)(zt,{businessTripId:e,onAdd:r}):(0,X.jsx)(X.Fragment,{});let i=t.map(e=>U(De,e));return(0,X.jsx)(`div`,{className:`flex flex-col gap-2 mt-5`,children:(0,X.jsxs)(d,{highlightOnHover:!0,withBorder:!0,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(Ct,{}),(0,X.jsx)(`th`,{children:`Flight`}),(0,X.jsx)(`th`,{children:`Attendees`}),(0,X.jsx)(`th`,{})]})}),(0,X.jsxs)(`tbody`,{children:[i.sort((e,t)=>e.date&&t.date?e.date<t.date?1:-1:e.date?-1:+!!t.date).map(t=>(0,X.jsx)(Gt,{data:t,businessTripId:e,onChange:r,attendees:n},t.id)),r&&(0,X.jsx)(`tr`,{children:(0,X.jsx)(`td`,{colSpan:5,children:(0,X.jsx)(zt,{businessTripId:e,onAdd:r})})})]})]})})},qt=({data:e,businessTripId:t,onChange:n})=>{let r=U(tt,e),[i,a]=(0,Y.useState)(!1),[o,s]=(0,Y.useState)(!1),l=H({defaultValues:{businessTripId:t,attendeeId:r.id,arrivalDate:r.arrivalDate,departureDate:r.departureDate}}),{control:u,handleSubmit:d}=l,{updateBusinessTripAttendee:p,fetching:m}=Mt(),h=e=>{p({fields:e}).then(()=>{n?.(),a(!1)})};return(0,X.jsxs)(B,{...l,children:[(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{children:r.name}),(0,X.jsx)(`td`,{children:i?(0,X.jsx)(`form`,{id:`form ${r.id}`,onSubmit:d(h),children:(0,X.jsx)(V,{name:`arrivalDate`,control:u,defaultValue:r.arrivalDate,rules:{pattern:{value:x,message:`Date must be in format yyyy-mm-dd`}},render:({field:e,fieldState:t})=>(0,X.jsxs)(F,{className:`h-min`,children:[(0,X.jsx)(R,{className:`sr-only`,htmlFor:`arrival-date-${r.id}`,children:`Arrival`}),(0,X.jsx)(I,{children:(0,X.jsx)(E,{id:`arrival-date-${r.id}`,"data-autofocus":!0,value:e.value??void 0,onChange:t=>{t!==e.value&&e.onChange(t)},"aria-invalid":!!t.error})}),(0,X.jsx)(G,{})]})})}):r.arrivalDate}),(0,X.jsx)(`td`,{children:i?(0,X.jsx)(V,{name:`departureDate`,control:u,defaultValue:r.departureDate,rules:{pattern:{value:x,message:`Date must be in format yyyy-mm-dd`}},render:({field:e,fieldState:t})=>(0,X.jsxs)(F,{className:`h-min`,children:[(0,X.jsx)(R,{className:`sr-only`,htmlFor:`departure-date-${r.id}`,children:`Departure`}),(0,X.jsx)(I,{children:(0,X.jsx)(E,{id:`departure-date-${r.id}`,value:e.value??void 0,onChange:t=>{t!==e.value&&e.onChange(t)},"aria-invalid":!!t.error})}),(0,X.jsx)(G,{})]})}):r.departureDate}),(0,X.jsxs)(`td`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(c,{content:`Edit`,children:(0,X.jsx)(j,{disabled:m,variant:i?`default`:`outline`,size:`icon`,className:`size-7.5`,onClick:e=>{e.stopPropagation(),a(e=>!e)},children:(0,X.jsx)(D,{className:`size-5`})})}),i&&(0,X.jsx)(c,{content:`Confirm Changes`,children:(0,X.jsx)(j,{type:`submit`,form:`form ${r.id}`,variant:`outline`,size:`icon`,className:`size-7.5 text-green-500`,children:(0,X.jsx)(O,{className:`size-5`})})}),(0,X.jsx)(Ft,{businessTripId:t,attendeeId:r.id,onDelete:n}),(0,X.jsx)(f,{toggleExpansion:s,isExpanded:o})]})]},r.id),o&&(0,X.jsx)(`tr`,{children:(0,X.jsx)(`td`,{colSpan:4,children:(0,X.jsx)(it,{shadow:`sm`,withBorder:!0,children:(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[r.flights&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{children:`Flights:`}),(0,X.jsx)(Kt,{businessTripId:t,attendees:[],expenses:r.flights})]}),r.accommodations&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{children:`Accommodations:`}),(0,X.jsx)(Tt,{businessTripId:t,expenses:r.accommodations})]})]})})})},`${r.id}-expension`)]})},Jt=({data:e,onChange:t})=>{let{attendees:n,id:r}=U(Pe,e);return n?.length?(0,X.jsx)(`div`,{className:`flex flex-col gap-2 mt-5`,children:(0,X.jsxs)(d,{highlightOnHover:!0,withBorder:!0,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`th`,{children:`Name`}),(0,X.jsx)(`th`,{children:`Arrival Date`}),(0,X.jsx)(`th`,{children:`Departure Date`}),(0,X.jsx)(`th`,{})]})}),(0,X.jsxs)(`tbody`,{children:[n.sort((e,t)=>e.name.toLocaleLowerCase()>t.name.toLocaleLowerCase()?1:-1).map(e=>(0,X.jsx)(qt,{data:e,businessTripId:r,onChange:t},e.id)),(0,X.jsx)(`tr`,{children:(0,X.jsx)(`td`,{colSpan:4,children:(0,X.jsx)(kt,{businessTripId:r,onAdd:t})})})]})]})}):(0,X.jsx)(kt,{businessTripId:r,onAdd:t})},Yt=`addBusinessTripCarRentalExpense`,Xt=()=>{let[{fetching:e},t]=q(Ve);return{fetching:e,addBusinessTripCarRentalExpense:(0,Y.useCallback)(async e=>{let n=`Error adding business trip car rental expense`;r.loading(`Adding car rental expense...`,{id:Yt});try{let a=await t(e),o=i(a,n,Yt);if(o)return r.success(`Success`,{id:Yt,description:`Car rental expense added`}),o.addBusinessTripCarRentalExpense}catch(e){console.error(`${n}: ${e}`),r.error(`Error`,{id:Yt,description:n,duration:1e5,closeButton:!0})}},[t])}};function Zt(e){let{businessTripId:t,onAdd:n}=e,[r,i]=(0,Y.useState)(!1);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(c,{content:`Add Car Rental Expense`,children:(0,X.jsx)(j,{variant:`outline`,size:`icon`,onClick:e=>{e.stopPropagation(),i(!0)},className:`size-7.5`,children:(0,X.jsx)(A,{className:`size-5`})})}),r&&(0,X.jsx)(Qt,{businessTripId:t,opened:r,close:()=>i(!1),onAdd:n})]})}function Qt({businessTripId:e,opened:t,close:n,onAdd:r}){let i=H({defaultValues:{businessTripId:e}}),{control:a,handleSubmit:o}=i,[s,c]=(0,Y.useState)(!1),{addBusinessTripCarRentalExpense:l,fetching:u}=Xt(),d=e=>{l({fields:e}).then(()=>{r?.(),n()})};return(0,X.jsxs)(S,{opened:t,onClose:n,centered:!0,lockScroll:!0,children:[(0,X.jsx)(S.Title,{children:`Add Car Rental Expense`}),(0,X.jsx)(S.Body,{children:(0,X.jsx)(B,{...i,children:(0,X.jsxs)(`form`,{onSubmit:o(d),children:[(0,X.jsx)(Z,{businessTripId:e,control:a,setFetching:c}),(0,X.jsx)(L,{name:`days`,control:a,render:({field:e,fieldState:t})=>(0,X.jsx)(m,{...e,value:e.value??void 0,hideControls:!0,precision:2,removeTrailingZeros:!0,error:t.error?.message,label:`Rent Days`})}),(0,X.jsx)(V,{name:`isFuelExpense`,control:a,render:({field:{value:e,...t}})=>(0,X.jsxs)(F,{className:`flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm`,children:[(0,X.jsx)(`div`,{className:`space-y-0.5`,children:(0,X.jsx)(R,{children:`Is Fuel Expense`})}),(0,X.jsx)(I,{children:(0,X.jsx)(ae,{...t,checked:e===!0,onCheckedChange:t.onChange})}),(0,X.jsx)(G,{})]})}),(0,X.jsx)(`div`,{className:`flex justify-center mt-5 gap-3`,children:(0,X.jsx)(`button`,{type:`submit`,className:`text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg`,children:`Add`})})]})})}),(u||s)&&(0,X.jsx)(T,{blur:1,center:!0,children:(0,X.jsx)(K,{})})]})}var $t=`updateBusinessTripCarRentalExpense`,en=()=>{let[{fetching:e},t]=q(Je);return{fetching:e,updateBusinessTripCarRentalExpense:(0,Y.useCallback)(async e=>{let n=`Error updating business trip car rental expense`,a=$t;r.loading(`Updating trip car rental expense`,{id:a});try{let o=await t(e),s=i(o,n,a);if(s)return r.success(`Success`,{id:a,description:`Business trip car rental expense was updated`}),s.updateBusinessTripCarRentalExpense}catch(e){console.error(`${n}: ${e}`),r.error(`Error`,{id:a,description:n,duration:1e5,closeButton:!0})}},[t])}},tn=({data:e,businessTripId:t,onChange:n})=>{let r=U(ve,e),[i,a]=(0,Y.useState)(!1),o=H({defaultValues:{id:r.id,businessTripId:t}}),{control:s,handleSubmit:l}=o,{updateBusinessTripCarRentalExpense:u,fetching:d}=en(),f=e=>{u({fields:e}).then(()=>{n?.(),a(!1)})};return(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(St,{data:r,isEditMode:i,control:s,businessTripId:t}),(0,X.jsx)(`td`,{children:(0,X.jsx)(B,{...o,children:(0,X.jsx)(`form`,{id:`form ${r.id}`,onSubmit:l(f),children:(0,X.jsx)(`div`,{className:`flex flex-col gap-2 justify-center`,children:r.isFuelExpense!==!0&&(i?(0,X.jsx)(L,{name:`days`,control:s,defaultValue:r.days,render:({field:e,fieldState:t})=>(0,X.jsx)(m,{...e,value:e.value??void 0,form:`form ${r.id}`,hideControls:!0,precision:2,removeTrailingZeros:!0,error:t.error?.message,placeholder:`Rent Days`})}):(0,X.jsx)(W,{c:r.days?void 0:`red`,children:r.days??`Missing`}))})})})}),(0,X.jsx)(`td`,{children:i?(0,X.jsx)(B,{...o,children:(0,X.jsx)(V,{name:`isFuelExpense`,control:s,defaultValue:r.isFuelExpense,render:({field:e})=>(0,X.jsxs)(F,{className:`flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm`,children:[(0,X.jsx)(`div`,{className:`space-y-0.5`,children:(0,X.jsx)(R,{children:`Is Fuel Expense`})}),(0,X.jsx)(I,{children:(0,X.jsx)(ae,{form:`form ${r.id}`,checked:e.value===!0,onCheckedChange:e.onChange})})]})})}):r.isFuelExpense===!0?(0,X.jsx)(ct,{}):(0,X.jsx)(st,{})}),(0,X.jsxs)(`td`,{children:[(0,X.jsx)(c,{content:`Edit`,children:(0,X.jsx)(j,{disabled:d,variant:i?`default`:`outline`,size:`icon`,className:`size-7.5`,onClick:e=>{e.stopPropagation(),a(e=>!e)},children:(0,X.jsx)(D,{className:`size-5`})})}),i&&(0,X.jsx)(c,{content:`Confirm Changes`,children:(0,X.jsx)(j,{type:`submit`,form:`form ${r.id}`,variant:`outline`,size:`icon`,className:`size-7.5 text-green-500`,children:(0,X.jsx)(O,{className:`size-5`})})}),(0,X.jsx)(Q,{businessTripExpenseId:r.id,businessTripId:t,onChange:n}),(0,X.jsx)($,{businessTripExpenseId:r.id,onDelete:n})]})]},r.id)},nn=({data:e,onChange:t})=>{let{carRentalExpenses:n,id:r}=U(ye,e);return n?.length?(0,X.jsx)(`div`,{className:`flex flex-col gap-2 mt-5`,children:(0,X.jsxs)(d,{highlightOnHover:!0,withBorder:!0,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(Ct,{}),(0,X.jsx)(`th`,{children:`Days`}),(0,X.jsx)(`th`,{children:`Type`}),(0,X.jsx)(`th`,{})]})}),(0,X.jsxs)(`tbody`,{children:[n.sort((e,t)=>e.date&&t.date?e.date<t.date?1:-1:e.date?-1:+!!t.date).map(e=>(0,X.jsx)(tn,{data:e,businessTripId:r,onChange:t},e.id)),(0,X.jsx)(`tr`,{children:(0,X.jsx)(`td`,{colSpan:6,children:(0,X.jsx)(Zt,{businessTripId:r,onAdd:t})})})]})]})}):(0,X.jsx)(Zt,{businessTripId:r,onAdd:t})},rn=({data:e,onChange:t})=>{let{flightExpenses:n,id:r,attendees:i}=U(pe,e);return(0,X.jsx)(Kt,{businessTripId:r,attendees:i,expenses:n,onChange:t})},an=`addBusinessTripOtherExpense`,on=()=>{let[{fetching:e},t]=q(et);return{fetching:e,addBusinessTripOtherExpense:(0,Y.useCallback)(async e=>{let n=`Error adding business trip "other" expense`,a=an;r.loading(`Adding trip "other" expense`,{id:a});try{let o=await t(e),s=i(o,n,a);if(s)return r.success(`Success`,{id:a,description:`Business trip "other" expense was added`}),s.addBusinessTripOtherExpense}catch(e){console.error(`${n}: ${e}`),r.error(`Error`,{id:a,description:n,duration:1e5,closeButton:!0})}},[t])}};function sn(e){let{businessTripId:t,onAdd:n}=e,[r,i]=(0,Y.useState)(!1);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(c,{content:`Add Other Expense`,children:(0,X.jsx)(j,{variant:`outline`,size:`icon`,className:`size-7.5`,onClick:e=>{e.stopPropagation(),i(!0)},children:(0,X.jsx)(A,{className:`size-5`})})}),r&&(0,X.jsx)(cn,{businessTripId:t,opened:r,close:()=>i(!1),onAdd:n})]})}function cn({businessTripId:e,opened:t,close:n,onAdd:r}){let i=H({defaultValues:{businessTripId:e}}),{control:a,handleSubmit:o}=i,[s,c]=(0,Y.useState)(!1),{addBusinessTripOtherExpense:l,fetching:u}=on(),d=e=>{l({fields:e}).then(()=>{r?.(),n()})};return(0,X.jsxs)(S,{opened:t,onClose:n,centered:!0,lockScroll:!0,children:[(0,X.jsx)(S.Title,{children:`Add Other Expense`}),(0,X.jsx)(S.Body,{children:(0,X.jsx)(B,{...i,children:(0,X.jsxs)(`form`,{onSubmit:o(d),className:`space-y-3`,children:[(0,X.jsx)(Z,{businessTripId:e,control:a,setFetching:c}),(0,X.jsx)(V,{name:`description`,control:a,render:({field:e})=>(0,X.jsxs)(F,{children:[(0,X.jsx)(R,{children:`Description`}),(0,X.jsx)(I,{children:(0,X.jsx)(k,{...e,value:e.value??void 0})}),(0,X.jsx)(G,{})]})}),(0,X.jsx)(V,{control:i.control,name:`deductibleExpense`,render:({field:e})=>(0,X.jsxs)(F,{className:`flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm`,children:[(0,X.jsx)(`div`,{className:`space-y-0.5`,children:(0,X.jsx)(R,{children:`Deductible Expense`})}),(0,X.jsx)(I,{children:(0,X.jsx)(ae,{checked:e.value===!0,onCheckedChange:e.onChange})})]})}),(0,X.jsx)(`div`,{className:`flex justify-center mt-5 gap-3`,children:(0,X.jsx)(`button`,{type:`submit`,className:`text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg`,children:`Add`})})]})})}),(u||s)&&(0,X.jsx)(T,{blur:1,center:!0,children:(0,X.jsx)(K,{})})]})}var ln=`updateBusinessTripOtherExpense`,un=()=>{let[{fetching:e},t]=q(He);return{fetching:e,updateBusinessTripOtherExpense:(0,Y.useCallback)(async e=>{let n=`Error updating business trip "other" expense`,a=ln;r.loading(`Updating business trip "other" expense`,{id:a});try{let o=await t(e),s=i(o,n,a);if(s)return r.success(`Success`,{id:a,description:`Business trip "other" expense was updated`}),s.updateBusinessTripOtherExpense}catch(e){console.error(`${n}: ${e}`),r.error(`Error`,{id:a,description:n,duration:1e5,closeButton:!0})}},[t])}},dn=({data:e,businessTripId:t,onChange:n})=>{let r=U(be,e),[i,a]=(0,Y.useState)(!1),o=H({defaultValues:{id:r.id,businessTripId:t}}),{control:s,handleSubmit:l}=o,{updateBusinessTripOtherExpense:u,fetching:d}=un(),f=e=>{u({fields:e}).then(()=>{n?.(),a(!1)})};return(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(St,{data:r,isEditMode:i,control:s,businessTripId:t}),(0,X.jsx)(`td`,{children:(0,X.jsx)(B,{...o,children:(0,X.jsx)(`form`,{id:`form ${r.id}`,onSubmit:l(f),children:i?(0,X.jsx)(V,{name:`description`,control:s,defaultValue:r.description,render:({field:e})=>(0,X.jsxs)(F,{children:[(0,X.jsx)(I,{children:(0,X.jsx)(k,{form:`form ${r.id}`,...e,value:e.value??void 0})}),(0,X.jsx)(G,{})]})}):(0,X.jsx)(W,{c:r.description?void 0:`red`,children:r.description??`Missing`})})})}),(0,X.jsx)(`td`,{children:(0,X.jsx)(`div`,{className:`flex flex-col gap-2 justify-center`,children:i?(0,X.jsx)(B,{...o,children:(0,X.jsx)(V,{name:`deductibleExpense`,control:o.control,defaultValue:r.deductibleExpense,render:({field:e})=>(0,X.jsx)(F,{children:(0,X.jsx)(I,{children:(0,X.jsx)(ae,{form:`form ${r.id}`,checked:e.value===!0,onCheckedChange:e.onChange})})})})}):(0,X.jsx)(W,{c:r.deductibleExpense?void 0:`red`,children:r.deductibleExpense===!0?`Yes`:r.deductibleExpense===!1?`No`:`Missing`})})}),(0,X.jsxs)(`td`,{children:[(0,X.jsx)(c,{content:`Edit`,children:(0,X.jsx)(j,{disabled:d,variant:i?`default`:`outline`,size:`icon`,className:`size-7.5`,onClick:e=>{e.stopPropagation(),a(e=>!e)},children:(0,X.jsx)(D,{className:`size-5`})})}),i&&(0,X.jsx)(c,{content:`Confirm Changes`,children:(0,X.jsx)(j,{type:`submit`,form:`form ${r.id}`,variant:`outline`,size:`icon`,className:`size-7.5 text-green-500`,children:(0,X.jsx)(O,{className:`size-5`})})}),(0,X.jsx)(Q,{businessTripExpenseId:r.id,businessTripId:t,onChange:n}),(0,X.jsx)($,{businessTripExpenseId:r.id,onDelete:n})]})]},r.id)},fn=({data:e,onChange:t})=>{let{otherExpenses:n,id:r}=U(ke,e);return n?.length?(0,X.jsx)(`div`,{className:`flex flex-col gap-2 mt-5`,children:(0,X.jsxs)(d,{highlightOnHover:!0,withBorder:!0,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(Ct,{}),(0,X.jsx)(`th`,{children:`Description`}),(0,X.jsx)(`th`,{children:`Deductible Expense`}),(0,X.jsx)(`th`,{})]})}),(0,X.jsxs)(`tbody`,{children:[n.sort((e,t)=>e.date&&t.date?e.date<t.date?1:-1:e.date?-1:+!!t.date).map(e=>(0,X.jsx)(dn,{data:e,businessTripId:r,onChange:t},e.id)),(0,X.jsx)(`tr`,{children:(0,X.jsx)(`td`,{colSpan:6,children:(0,X.jsx)(sn,{businessTripId:r,onAdd:t})})})]})]})}):(0,X.jsx)(sn,{businessTripId:r,onAdd:t})},pn=`addBusinessTripTravelAndSubsistenceExpense`,mn=()=>{let[{fetching:e},t]=q(Ue);return{fetching:e,addBusinessTripTravelAndSubsistenceExpense:(0,Y.useCallback)(async e=>{let n=`Error adding business trip travel&subsistence expense`,a=pn;r.loading(`Adding trip travel&subsistence expense`,{id:a});try{let o=await t(e),s=i(o,n,a);if(s)return r.success(`Success`,{id:a,description:`Business trip travel&subsistence expense was added`}),s.addBusinessTripTravelAndSubsistenceExpense}catch(e){console.error(`${n}: ${e}`),r.error(`Error`,{id:a,description:n,duration:1e5,closeButton:!0})}},[t])}};function hn(e){let{businessTripId:t,onAdd:n}=e,[r,i]=(0,Y.useState)(!1);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(c,{content:`Add T&S Expense`,children:(0,X.jsx)(j,{variant:`outline`,size:`icon`,className:`size-7.5`,onClick:e=>{e.stopPropagation(),i(!0)},children:(0,X.jsx)(A,{className:`size-5`})})}),r&&(0,X.jsx)(gn,{businessTripId:t,opened:r,close:()=>i(!1),onAdd:n})]})}function gn({businessTripId:e,opened:t,close:n,onAdd:r}){let i=H({defaultValues:{businessTripId:e}}),{control:a,handleSubmit:o}=i,[s,c]=(0,Y.useState)(!1),{addBusinessTripTravelAndSubsistenceExpense:l,fetching:u}=mn(),d=e=>{l({fields:e}).then(()=>{r?.(),n()})};return(0,X.jsxs)(S,{opened:t,onClose:n,centered:!0,lockScroll:!0,children:[(0,X.jsx)(S.Title,{children:`Add Travel & Subsistence Expense`}),(0,X.jsx)(S.Body,{children:(0,X.jsx)(B,{...i,children:(0,X.jsxs)(`form`,{onSubmit:o(d),className:`space-y-3`,children:[(0,X.jsx)(Z,{businessTripId:e,control:a,setFetching:c}),(0,X.jsx)(V,{name:`expenseType`,control:a,render:({field:e})=>(0,X.jsxs)(F,{children:[(0,X.jsx)(R,{children:`Expense Type`}),(0,X.jsx)(I,{children:(0,X.jsx)(k,{...e,value:e.value??void 0})}),(0,X.jsx)(G,{})]})}),(0,X.jsx)(`div`,{className:`flex justify-center mt-5 gap-3`,children:(0,X.jsx)(`button`,{type:`submit`,className:`text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg`,children:`Add`})})]})})}),(u||s)&&(0,X.jsx)(T,{blur:1,center:!0,children:(0,X.jsx)(K,{})})]})}var _n=`updateBusinessTripTravelAndSubsistenceExpense`,vn=()=>{let[{fetching:e},t]=q(Ke);return{fetching:e,updateBusinessTripTravelAndSubsistenceExpense:(0,Y.useCallback)(async e=>{let n=`Error updating business trip travel&subsistence expense`,a=_n;r.loading(`Updating trip travel&subsistence expense`,{id:a});try{let o=await t(e),s=i(o,n,a);if(s)return r.success(`Success`,{id:a,description:`Business trip travel&subsistence expense was updated`}),s.updateBusinessTripTravelAndSubsistenceExpense}catch(e){console.error(`${n}: ${e}`),r.error(`Error`,{id:a,description:n,duration:1e5,closeButton:!0})}},[t])}},yn=({data:e,businessTripId:t,onChange:n})=>{let r=U(Me,e),[i,a]=(0,Y.useState)(!1),o=H({defaultValues:{id:r.id,businessTripId:t}}),{control:s,handleSubmit:l}=o,{updateBusinessTripTravelAndSubsistenceExpense:u,fetching:d}=vn(),f=e=>{u({fields:e}).then(()=>{n?.(),a(!1)})};return(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(St,{data:r,isEditMode:i,control:s,businessTripId:t}),(0,X.jsx)(`td`,{children:(0,X.jsx)(B,{...o,children:(0,X.jsx)(`form`,{id:`form ${r.id}`,onSubmit:l(f),children:i?(0,X.jsx)(V,{name:`expenseType`,control:s,defaultValue:r.expenseType,render:({field:e})=>(0,X.jsxs)(F,{children:[(0,X.jsx)(I,{children:(0,X.jsx)(k,{form:`form ${r.id}`,...e,value:e.value??void 0})}),(0,X.jsx)(G,{})]})}):(0,X.jsx)(W,{c:r.expenseType?void 0:`red`,children:r.expenseType??`Missing`})})})}),(0,X.jsxs)(`td`,{children:[(0,X.jsx)(c,{content:`Edit`,children:(0,X.jsx)(j,{disabled:d,variant:i?`default`:`outline`,size:`icon`,className:`size-7.5`,onClick:e=>{e.stopPropagation(),a(e=>!e)},children:(0,X.jsx)(D,{className:`size-5`})})}),i&&(0,X.jsx)(c,{content:`Confirm Changes`,children:(0,X.jsx)(j,{type:`submit`,form:`form ${r.id}`,variant:`outline`,size:`icon`,className:`size-7.5 text-green-500`,children:(0,X.jsx)(O,{className:`size-5`})})}),(0,X.jsx)(Q,{businessTripExpenseId:r.id,businessTripId:t,onChange:n}),(0,X.jsx)($,{businessTripExpenseId:r.id,onDelete:n})]})]},r.id)},bn=({data:e,onChange:t})=>{let{travelAndSubsistenceExpenses:n,id:r}=U(Ee,e);return n?.length?(0,X.jsx)(`div`,{className:`flex flex-col gap-2 mt-5`,children:(0,X.jsxs)(d,{highlightOnHover:!0,withBorder:!0,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(Ct,{}),(0,X.jsx)(`th`,{children:`Expense Type`}),(0,X.jsx)(`th`,{})]})}),(0,X.jsxs)(`tbody`,{children:[n.sort((e,t)=>e.date&&t.date?e.date<t.date?1:-1:e.date?-1:+!!t.date).map(e=>(0,X.jsx)(yn,{data:e,businessTripId:r,onChange:t},e.id)),(0,X.jsx)(`tr`,{children:(0,X.jsx)(`td`,{colSpan:6,children:(0,X.jsx)(hn,{businessTripId:r,onAdd:t})})})]})]})}):(0,X.jsx)(hn,{businessTripId:r,onAdd:t})},xn=({data:e})=>{let t=U(Ie,e),n=`effectiveDate`in t?t.effectiveDate:void 0;return(0,X.jsx)(`td`,{children:(0,X.jsxs)(`div`,{className:`flex flex-col justify-center`,children:[(0,X.jsx)(`div`,{children:n&&z(new Date(n),`dd/MM/yy`)}),t.sourceEffectiveDate&&(0,X.jsxs)(`div`,{className:`text-xs text-gray-500`,children:[`(Originally `,z(new Date(t.sourceEffectiveDate),`dd/MM/yy`),`)`]})]})})},Sn=({data:e})=>{let t=U(Ye,e),n=`eventDate`in t?t.eventDate:void 0;return(0,X.jsx)(`td`,{children:(0,X.jsx)(`div`,{className:`flex flex-col justify-center`,children:n&&z(new Date(n),`dd/MM/yy`)})})},Cn=({data:e})=>{let{account:t}=U(Fe,e),n=oe(t.type),r=t.name;return(0,X.jsx)(`td`,{children:(0,X.jsxs)(`div`,{className:`flex flex-col gap-2 items-center`,children:[(0,X.jsx)(`p`,{children:n}),(0,X.jsx)(`p`,{children:r})]})})},wn=({data:e})=>{let t=U(xe,e),n=`sourceDescription`in t?t.sourceDescription:`Missing`;return(0,X.jsx)(`td`,{children:(0,X.jsx)(`div`,{className:`flex flex-wrap`,children:(0,X.jsx)(`div`,{className:`flex flex-col justify-center`,children:n})})})},Tn=({data:e})=>{let t=U(Ce,e);return(0,X.jsx)(`td`,{children:(0,X.jsx)(`div`,{className:`flex flex-wrap`,children:(0,X.jsx)(`div`,{className:`flex flex-col justify-center`,children:t.referenceKey})})})};function En({data:e,onChange:t,enableEdit:n}){let{id:r,counterparty:i,missingInfoSuggestions:o,sourceDescription:l}=U(we,e),d=!!o?.business&&n,f=d?o?.business?.name:`Missing`,p=d?o?.business?.id:null,m=i?.name??f,[h,g]=(0,Y.useState)(!1),{updateTransaction:_,fetching:v}=u(),y=async e=>{await _({transactionId:r,fields:{counterpartyId:e}}),g(!0)},b=async e=>{await y(e),g(!0),t?.()},{selectableBusinesses:x,fetching:ee}=te(),[S,ne]=(0,Y.useState)(p??null),[C,w]=(0,Y.useState)(l);return(0,X.jsxs)(`td`,{children:[(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1 items-center justify-center`,children:i?.id?(0,X.jsx)(a,{to:ue.BUSINESSES.DETAIL(i.id),target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`inline-flex items-center font-semibold`,children:m}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(s,{options:x,value:S,onChange:ne,search:C,onSearchChange:w,placeholder:`Choose or create a business`,empty:C?(0,X.jsx)(re,{description:C,onAdd:b}):null}),(0,X.jsx)(c,{content:`Approve`,children:(0,X.jsx)(j,{variant:`outline`,size:`icon`,onClick:()=>S&&y(S),disabled:v||ee||!S,children:(0,X.jsx)(O,{className:`size-4`})})})]})}),(0,X.jsx)(se,{transactionId:r,counterpartyId:i?.id??S,open:h,onOpenChange:g,onClose:t})]})}var Dn=`categorizeBusinessTripExpense`,On=()=>{let[{fetching:e},t]=q(Te);return{fetching:e,categorizeBusinessTripExpense:(0,Y.useCallback)(async e=>{let n=`Error updating business trip expense category`,a=Dn;r.loading(`Updating trip expense category`,{id:a});try{let o=await t(e),s=i(o,n,a);if(s)return r.success(`Success`,{id:a,description:`Business trip expense category was updated`}),s.categorizeBusinessTripExpense}catch(e){console.error(`${n}: ${e}`),r.error(`Error`,{id:a,description:n,duration:1e5,closeButton:!0})}},[t])}};function kn(e){let{businessTripId:t,transactionId:n,onChange:r,defaultAmount:i}=e,[a,o]=(0,Y.useState)(!1);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(c,{content:`Categorize`,children:(0,X.jsx)(j,{variant:`outline`,size:`icon`,className:`size-7.5`,onClick:e=>{e.stopPropagation(),o(!0)},children:(0,X.jsx)(D,{className:`size-5`})})}),a&&(0,X.jsx)(jn,{businessTripId:t,transactionId:n,opened:a,close:()=>o(!1),onChange:r,defaultAmount:i})]})}var An=Object.entries(Be).map(([e,t])=>({value:t,label:e}));function jn({businessTripId:e,transactionId:t,defaultAmount:n,opened:r,close:i,onChange:a}){let{control:o,handleSubmit:s}=H({defaultValues:{businessTripId:e,transactionId:t}}),{categorizeBusinessTripExpense:c,fetching:l}=On();return(0,X.jsxs)(S,{opened:r,onClose:i,centered:!0,children:[(0,X.jsx)(S.Title,{children:`Set Expense Category`}),(0,X.jsx)(S.Body,{children:(0,X.jsxs)(`form`,{onSubmit:s(e=>{c({fields:e}).then(()=>{a?.(),i()})}),className:`flex flex-col gap-3 mt-3`,children:[(0,X.jsx)(L,{name:`category`,control:o,render:({field:e,fieldState:t})=>(0,X.jsx)(v,{"data-autofocus":!0,...e,data:An,value:e.value,label:`Category`,placeholder:`Scroll to see all options`,maxDropdownHeight:160,searchable:!0,error:t.error?.message,withinPortal:!0})}),(0,X.jsx)(L,{name:`amount`,control:o,defaultValue:n,render:({field:e,fieldState:t})=>(0,X.jsx)(m,{...e,value:e.value??void 0,hideControls:!0,precision:2,removeTrailingZeros:!0,error:t.error?.message,label:`Amount`})}),(0,X.jsx)(`div`,{className:`flex justify-center gap-3`,children:(0,X.jsx)(`button`,{type:`submit`,className:`text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg`,children:`Confirm`})})]})}),l&&(0,X.jsx)(T,{blur:1,center:!0,children:(0,X.jsx)(K,{})})]})}var Mn=({data:e,onChange:t})=>{let{uncategorizedTransactions:n,id:r}=U(he,e);return n?.length?(0,X.jsx)(`div`,{className:`flex flex-col gap-2 mt-5`,children:(0,X.jsxs)(d,{highlightOnHover:!0,withBorder:!0,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`th`,{children:`Event Date`}),(0,X.jsx)(`th`,{children:`Debit Date`}),(0,X.jsx)(`th`,{children:`Amount`}),(0,X.jsx)(`th`,{}),(0,X.jsx)(`th`,{children:`Account`}),(0,X.jsx)(`th`,{children:`Description`}),(0,X.jsx)(`th`,{children:`Reference#`}),(0,X.jsx)(`th`,{children:`Counterparty`}),(0,X.jsx)(`th`,{})]})}),(0,X.jsx)(`tbody`,{children:n.sort((e,t)=>e.transaction.eventDate.localeCompare(t.transaction.eventDate)).map(e=>(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(Sn,{data:e.transaction}),(0,X.jsx)(xn,{data:e.transaction}),(0,X.jsx)(Nn,{data:e}),(0,X.jsx)(`td`,{children:(0,X.jsx)(a,{to:ue.CHARGES.DETAIL(e.transaction.chargeId),target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`inline-flex items-center font-semibold`,children:`To Charge`})}),(0,X.jsx)(Cn,{data:e.transaction}),(0,X.jsx)(wn,{data:e.transaction}),(0,X.jsx)(Tn,{data:e.transaction}),(0,X.jsx)(En,{data:e.transaction}),(0,X.jsx)(`td`,{children:(0,X.jsx)(kn,{businessTripId:r,transactionId:e.transaction.id,onChange:t,defaultAmount:e.transaction.amount.raw})})]},e.transaction.id))})]})}):(0,X.jsx)(X.Fragment,{})},Nn=({data:e})=>{let{transaction:t,categorizedAmount:n,errors:r}=U(Ae,e),i=`amount`in t?t.amount:void 0,a=i?.raw!==n.raw&&n.raw!==0;return(0,X.jsx)(`td`,{children:(0,X.jsxs)(`div`,{className:`flex flex-col whitespace-nowrap`,style:{color:Number(i?.raw)>0?`green`:`red`},children:[(0,X.jsxs)(`div`,{className:`flex gap-1`,children:[i?.formatted,r.length>0&&(0,X.jsx)(Pn,{errors:r})]}),a&&(0,X.jsxs)(`div`,{className:`text-gray-500 ml-2`,children:[n.formatted,` categorized `]}),t.cryptoExchangeRate&&(0,X.jsxs)(`div`,{className:`text-gray-500 ml-2`,children:[`(Rate: ${t.cryptoExchangeRate.rate})`,(0,X.jsx)(`br`,{}),i?.raw?`${p(i.raw*t.cryptoExchangeRate.rate)}$`:null]})]})})},Pn=({errors:e})=>{let[t,n]=(0,Y.useState)(!1);return(0,X.jsxs)(ee,{width:200,position:`bottom`,shadow:`md`,opened:t,children:[(0,X.jsx)(ee.Target,{children:(0,X.jsx)(ot,{onMouseEnter:()=>n(!0),onMouseLeave:()=>n(!1)})}),(0,X.jsx)(ee.Dropdown,{sx:{pointerEvents:`none`},className:`whitespace-normal text-red-500`,children:e.map((e,t)=>(0,X.jsx)(W,{size:`sm`,children:e},t))})]})};function Fn({tripId:e,isExtended:t=!1}){let[n,r]=(0,Y.useState)(),[{data:i},a]=J({query:qe,variables:{businessTripId:e}}),o=a;return(0,Y.useEffect)(()=>{i?.businessTrip&&r(i.businessTrip)},[i?.businessTrip]),(0,X.jsx)(it,{shadow:`sm`,radius:`md`,withBorder:!0,children:n?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(_,{data:n,onChange:o}),(0,X.jsxs)(de,{className:`w-full`,type:`multiple`,children:[(0,X.jsxs)(P,{value:`attendees`,children:[(0,X.jsx)(M,{children:`Attendees`}),(0,X.jsx)(N,{children:(0,X.jsx)(Jt,{data:n,onChange:o})})]}),t&&(0,X.jsxs)(P,{value:`uncategorized-transactions`,children:[(0,X.jsx)(M,{disabled:!n.uncategorizedTransactions?.length,children:`Uncategorized Transactions`}),(0,X.jsx)(N,{children:(0,X.jsx)(Mn,{data:n,onChange:o})})]}),(0,X.jsxs)(P,{value:`flights`,children:[(0,X.jsx)(M,{children:`Flights`}),(0,X.jsx)(N,{children:(0,X.jsx)(rn,{data:n,onChange:o})})]}),(0,X.jsxs)(P,{value:`accommodations`,children:[(0,X.jsx)(M,{children:`Accommodations`}),(0,X.jsx)(N,{children:(0,X.jsx)(Et,{data:n,onChange:o})})]}),(0,X.jsxs)(P,{value:`travelAndSubsistence`,children:[(0,X.jsx)(M,{children:`Travel & Subsistence`}),(0,X.jsx)(N,{children:(0,X.jsx)(bn,{data:n,onChange:o})})]}),(0,X.jsxs)(P,{value:`other`,children:[(0,X.jsx)(M,{children:`Other`}),(0,X.jsx)(N,{children:(0,X.jsx)(fn,{data:n,onChange:o})})]}),(0,X.jsxs)(P,{value:`carRental`,children:[(0,X.jsx)(M,{children:`Car Rental`}),(0,X.jsx)(N,{children:(0,X.jsx)(nn,{data:n,onChange:o})})]}),(0,X.jsxs)(P,{value:`summary`,children:[(0,X.jsx)(M,{children:`Summary`}),(0,X.jsx)(N,{children:(0,X.jsx)(g,{data:n})})]})]})]}):(0,X.jsx)(le,{className:`h-10 w-10 animate-spin mr-2 self-center`})})}export{Fn as t};