@mercoa/react 0.0.10-rc7 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.es.js +5 -5
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +4 -4
- package/dist/index.umd.js.map +1 -1
- package/dist/style.css +1 -4
- package/dist/tailwind.css +1 -1
- package/package.json +3 -3
package/dist/index.umd.js
CHANGED
|
@@ -142,7 +142,7 @@ attempted value: ${ar}
|
|
|
142
142
|
mercoa-cursor-pointer mercoa-bg-white mercoa-px-6 mercoa-py-5 mercoa-shadow-sm hover:mercoa-border-indigo-600 hover:mercoa-text-gray-800`,children:"Individual"}),jsx("button",{type:"button",onClick:()=>cr("accountType","business"),className:`mercoa-flex-grow mercoa-rounded-lg mercoa-border mercoa-border-gray-300 mercoa-text-center mercoa-text-gray-600
|
|
143
143
|
${fr==="business"?"mercoa-border-indigo-600 mercoa-text-gray-800":""}
|
|
144
144
|
${fr==="individual"?"mercoa-text-gray-300":""}
|
|
145
|
-
mercoa-cursor-pointer mercoa-bg-white mercoa-px-6 mercoa-py-5 mercoa-shadow-sm hover:mercoa-border-indigo-600 hover:mercoa-text-gray-800`,children:"Business"})]}),fr==="business"&&jsxs(Fragment,{children:[jsxs("div",{className:"mercoa-mt-1",children:[jsx("label",{htmlFor:"email",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Business Type"}),jsxs("select",{...ir("businessType"),className:"mercoa-mt-1 mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border mercoa-border-gray-300 mercoa-bg-white mercoa-py-2 mercoa-px-3 mercoa-shadow-sm focus:mercoa-border-indigo-500 focus:mercoa-outline-none focus:mercoa-ring-indigo-500 sm:mercoa-text-sm",children:[jsx("option",{value:"",disabled:!0,children:"Select an option"}),jsx("option",{value:"soleProprietorship",children:"Sole proprietorship"}),jsx("option",{value:"llc",children:"LLC"}),jsx("option",{value:"trust",children:"Trust"}),jsx("option",{value:"publicCorporation",children:"Public Corporation"}),jsx("option",{value:"privateCorporation",children:"Private Corporation"}),jsx("option",{value:"partnership",children:"Partnership"}),jsx("option",{value:"unincorporatedAssociation",children:"Unincorporated association"}),jsx("option",{value:"unincorporatedNonProfit",children:"Unincorporated Non-Profit "}),jsx("option",{value:"incorporatedNonProfit",children:"Incorporated Non-Profit "})]})]}),jsxs("div",{className:"mercoa-mt-1",children:[jsx("label",{htmlFor:"email",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Business Website"}),jsx("input",{type:"text",...ir("website"),className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 focus:mercoa-border-indigo-500 focus:mercoa-ring-indigo-500 sm:mercoa-text-sm",placeholder:"https://www.example.com"}),((Tr=ur==null?void 0:ur.website)==null?void 0:Tr.message)&&jsx("p",{className:"mercoa-text-sm mercoa-text-red-500",children:(Pr=ur==null?void 0:ur.website)==null?void 0:Pr.message})]}),jsxs("div",{className:"mercoa-mt-1",children:[jsx("label",{htmlFor:"email",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Business Description"}),jsx("input",{type:"text",...ir("description"),className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 focus:mercoa-border-indigo-500 focus:mercoa-ring-indigo-500 sm:mercoa-text-sm",placeholder:""})]})]}),fr==="individual"&&jsxs("div",{className:"mercoa-mt-1",children:[jsx("label",{htmlFor:"email",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Full Name"}),jsxs("div",{className:"mercoa-grid mercoa-grid-cols-7 mercoa-gap-1",children:[jsx("input",{type:"text",...ir("firstName"),required:!0,className:"mercoa-col-span-2 mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 focus:mercoa-border-indigo-500 focus:mercoa-ring-indigo-500 sm:mercoa-text-sm",placeholder:"First Name"}),jsx("input",{type:"text",...ir("middleName"),className:"mercoa-col-span-2 mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 focus:mercoa-border-indigo-500 focus:mercoa-ring-indigo-500 sm:mercoa-text-sm",placeholder:"Middle Name"}),jsx("input",{type:"text",...ir("lastName"),required:!0,className:"mercoa-col-span-2 mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 focus:mercoa-border-indigo-500 focus:mercoa-ring-indigo-500 sm:mercoa-text-sm",placeholder:"Last Name"}),jsxs("select",{...ir("suffix"),className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border mercoa-border-gray-300 mercoa-bg-white mercoa-py-2 mercoa-px-3 mercoa-shadow-sm focus:mercoa-border-indigo-500 focus:mercoa-outline-none focus:mercoa-ring-indigo-500 sm:mercoa-text-sm",children:[jsx("option",{value:""}),jsx("option",{value:"Sr.",children:"Sr."}),jsx("option",{value:"Jr.",children:"Jr."}),jsx("option",{value:"II",children:"II"}),jsx("option",{value:"III",children:"III"}),jsx("option",{value:"IV",children:"IV"}),jsx("option",{value:"V",children:"V"})]})]})]}),fr&&jsx(MercoaButton,{isEmphasized:!0,type:"submit",className:"mercoa-mt-2 mercoa-w-full",children:"Save"})]})}function Counterparties({type:ee,admin:te}){var _r,xr,jr;const ce=useMercoaSession(),[re,nr]=React$1.useState(void 0),[or,ar]=React$1.useState(!1),[ir,sr]=React$1.useState([]),[cr,lr]=React$1.useState(1),[ur,fr]=React$1.useState(!0),[hr,pr]=React$1.useState(20),[dr,mr]=React$1.useState(0),[yr,Mr]=React$1.useState(),[Sr,Er]=React$1.useState(void 0);React$1.useEffect(()=>{!ce.client||!ce.entityId||(ee==="payor"?ce.client.entity.counterparty.findPayors(ce.entityId,{limit:hr,startingAfter:ir[ir.length-1],...yr&&{name:yr},paymentMethods:!0}).then(wr=>{nr(wr.data),fr(wr.hasMore),mr(wr.count)}):ce.client.entity.counterparty.findPayees(ce.entityId,{limit:hr,startingAfter:ir[ir.length-1],...yr&&{name:yr},paymentMethods:!0}).then(wr=>{console.log(wr),nr(wr.data),fr(wr.hasMore),mr(wr.count)}))},[ce.client,ce.entityId,ce.refreshId,ee,ir]);function br({entity:wr,index:Ir,type:Br,setSelected:Ar,selectedId:Ur,admin:Lr}){const Zr=useMercoaSession();return Ur===wr.id?jsx("tr",{className:`hover:mercoa-bg-gray-100 ${Ir%2===0?void 0:"mercoa-bg-gray-50"}`,children:jsx("td",{className:"mercoa-p-10 mercoa-bg-gray-200",colSpan:Lr?4:3,children:jsx("div",{className:"mercoa-rounded-lg mercoa-bg-gray-50 mercoa-shadow mercoa-ring-1 mercoa-ring-gray-900/5",children:jsx(CounterpartyDetails,{counterparty:wr,admin:Lr,type:Br})})})},wr.email):jsxs("tr",{className:`hover:mercoa-bg-gray-100 mercoa-cursor-pointer ${Ir%2===0?void 0:"mercoa-bg-gray-50"}`,onClick:()=>{Ar(wr)},children:[jsx("td",{className:"mercoa-whitespace-nowrap mercoa-py-4 mercoa-pl-4 mercoa-pr-3 mercoa-text-sm mercoa-font-medium mercoa-text-gray-900 sm:mercoa-pl-6",children:wr.name}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-4 mercoa-text-sm mercoa-text-gray-900",children:wr.email}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-4 mercoa-text-sm mercoa-text-gray-900",children:capitalize(wr.accountType)}),Lr&&jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-4 mercoa-text-sm mercoa-text-gray-900",children:jsx(MercoaButton,{isEmphasized:!1,color:"red",size:"sm",onClick:async()=>{var nn,rn;Zr.entityId&&(Br==="payor"?await((nn=Zr.client)==null?void 0:nn.entity.counterparty.hidePayors(Zr.entityId,{payors:[wr.id]})):await((rn=Zr.client)==null?void 0:rn.entity.counterparty.hidePayees(Zr.entityId,{payees:[wr.id]})),Zr.refresh())},children:"Hide"})})]},wr.email)}return jsxs("div",{className:"mercoa mercoa-overflow-hidden mercoa-shadow mercoa-ring-1 mercoa-ring-black mercoa-ring-opacity-5 md:mercoa-rounded-lg mercoa-p-5",children:[jsxs("div",{className:"mercoa-flex mercoa-mb-5 mercoa-space-x-5 mercoa-items-center",children:[jsx("h2",{className:"mercoa-text-base mercoa-font-semibold mercoa-leading-7 mercoa-text-gray-900",children:ee==="payor"?"Customers":"Vendors"}),jsx(DebouncedSearch,{placeholder:`Search ${ee==="payor"?"Customers":"Vendors"}`,onSettle:wr=>{Mr(wr),lr(1),sr([])}}),(te||!((jr=(xr=(_r=ce.iframeOptions)==null?void 0:_r.options)==null?void 0:xr.vendors)!=null&&jr.disableCreation))&&jsxs(MercoaButton,{isEmphasized:!0,type:"button",className:"mercoa-ml-2 mercoa-inline-flex mercoa-text-sm",onClick:()=>{ar(!0)},children:[jsx(PlusIcon$1,{className:"-mercoa-ml-1 mercoa-inline-flex mercoa-h-5 mercoa-w-5 md:mercoa-mr-2"})," ",jsxs("span",{className:"mercoa-hidden md:mercoa-inline-block",children:["Add ",ee==="payee"?"Vendor":"Customer"]})]})]}),jsxs("table",{className:"mercoa-min-w-full mercoa-divide-y mercoa-divide-gray-300",children:[jsx("thead",{className:"mercoa-bg-gray-50",children:jsxs("tr",{children:[jsx("th",{scope:"col",className:"mercoa-py-3.5 mercoa-pl-4 mercoa-pr-3 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 sm:mercoa-pl-6",children:"Name"}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900",children:"Email"}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900",children:"Type"}),te&&jsx("th",{children:jsx("span",{className:"mercoa-sr-only",children:"Hide"})})]})}),jsxs("tbody",{className:"mercoa-bg-white",children:[!re&&jsx("tr",{children:jsx("td",{colSpan:5,className:"mercoa-p-9 mercoa-text-center",children:jsx(LoadingSpinnerIcon,{})})}),re&&re.map((wr,Ir)=>jsx(br,{entity:wr,index:Ir,type:ee,setSelected:Er,selectedId:Sr==null?void 0:Sr.id,admin:te},wr.id))]})]}),re&&jsx(TableNavigation,{data:re,page:cr,setPage:lr,hasMore:ur,startingAfter:ir,setStartingAfter:sr,count:dr,resultsPerPage:hr,setResultsPerPage:pr}),jsx(AddCounterpartyModal,{type:ee,show:or,setShow:ar})]})}function AddCounterpartyModal({type:ee,show:te,setShow:ce}){const re=useMercoaSession();return jsx(tt$1.Root,{show:te,as:React$1.Fragment,children:jsxs(_t$1,{as:"div",className:"mercoa-relative mercoa-z-10",onClose:()=>{re.refresh(),ce(!1)},children:[jsx(tt$1.Child,{as:React$1.Fragment,enter:"mercoa-ease-out mercoa-duration-300",enterFrom:"mercoa-opacity-0",enterTo:"mercoa-opacity-100",leave:"mercoa-ease-in mercoa-duration-200",leaveFrom:"mercoa-opacity-100",leaveTo:"mercoa-opacity-0",children:jsx("div",{className:"mercoa-fixed mercoa-inset-0 mercoa-bg-gray-500 mercoa-bg-mercoa-opacity-75 mercoa-transition-opacity"})}),jsx("div",{className:"mercoa-fixed mercoa-inset-0 mercoa-z-10 mercoa-overflow-y-auto",children:jsx("div",{className:"mercoa-flex mercoa-min-h-full mercoa-items-end mercoa-justify-center mercoa-p-4 mercoa-text-center sm:mercoa-items-center sm:mercoa-p-0",children:jsx(tt$1.Child,{as:React$1.Fragment,enter:"mercoa-ease-out mercoa-duration-300",enterFrom:"mercoa-opacity-0 mercoa-translate-y-4 sm:mercoa-translate-y-0 sm:mercoa-scale-95",enterTo:"mercoa-opacity-100 mercoa-translate-y-0 sm:mercoa-scale-100",leave:"mercoa-ease-in mercoa-duration-200",leaveFrom:"mercoa-opacity-100 mercoa-translate-y-0 sm:mercoa-scale-100",leaveTo:"mercoa-opacity-0 mercoa-translate-y-4 sm:mercoa-translate-y-0 sm:mercoa-scale-95",children:jsx(_t$1.Panel,{className:"mercoa-relative mercoa-transform mercoa-rounded-lg mercoa-bg-white mercoa-text-left mercoa-shadow-xl mercoa-transition-all",children:jsx("div",{className:"mercoa-w-[600px]",children:jsx(CounterpartyAddOrEdit,{type:ee,onComplete:()=>{ce(!1),re.refresh()}})})})})})})]})})}function CounterpartyDetails({counterparty:ee,admin:te,type:ce}){var lr,ur,fr,hr,pr,dr,mr,yr,Mr,Sr,Er,br,_r,xr,jr,wr,Ir,Br,Ar,Ur,Lr,Zr,nn,rn,tn,Nr,Fr,Yr,Dr,vr,Or,Tr,Pr,gr;const re=useMercoaSession(),nr=((fr=(ur=(lr=ee.profile)==null?void 0:lr.business)==null?void 0:ur.phone)==null?void 0:fr.number)??((dr=(pr=(hr=ee.profile)==null?void 0:hr.individual)==null?void 0:pr.phone)==null?void 0:dr.number),ar=`+${((Mr=(yr=(mr=ee.profile)==null?void 0:mr.business)==null?void 0:yr.phone)==null?void 0:Mr.countryCode)??((br=(Er=(Sr=ee.profile)==null?void 0:Sr.individual)==null?void 0:Er.phone)==null?void 0:br.countryCode)??"1"} ${nr}`,ir=((xr=(_r=ee.profile)==null?void 0:_r.business)==null?void 0:xr.address)??((wr=(jr=ee.profile)==null?void 0:jr.individual)==null?void 0:wr.address),sr=`${(ir==null?void 0:ir.addressLine1)??""} ${(ir==null?void 0:ir.addressLine2)??""}, ${(ir==null?void 0:ir.city)??""}, ${(ir==null?void 0:ir.stateOrProvince)??""} ${(ir==null?void 0:ir.postalCode)??""}`;function cr({method:$r}){let Rr=jsx(Fragment,{});return $r.type===javascript.Mercoa.PaymentMethodType.BankAccount?Rr=jsx(BankAccountComponent,{account:$r}):$r.type===javascript.Mercoa.PaymentMethodType.Card?Rr=jsx(CreditCardComponent,{account:$r}):$r.type===javascript.Mercoa.PaymentMethodType.Custom?Rr=jsx(CustomPaymentMethodComponent,{account:$r}):$r.type===javascript.Mercoa.PaymentMethodType.Check&&(Rr=jsx(CheckComponent,{account:$r})),jsxs("div",{children:[te&&jsxs(Fragment,{children:[jsx("p",{className:"mercoa-text-xs mercoa-font-bold mercoa-whitespace-nowrap",children:$r.type}),jsx("p",{className:"mercoa-text-xs mercoa-whitespace-nowrap",children:$r.id})]}),Rr]},$r.id)}return jsxs("div",{className:"mercoa-py-6 ",children:[jsxs("div",{className:"mercoa-flex mercoa-flex-auto mercoa-px-6 mercoa-items-center",children:[jsx("dt",{className:"mercoa-sr-only",children:"Vendor Name"}),jsxs("div",{children:[jsxs("dd",{className:"mercoa-text-xl mercoa-font-semibold mercoa-leading-6 mercoa-text-gray-900 mercoa-inline",children:[((Ir=ee.profile)==null?void 0:Ir.business)&&((Br=ee==null?void 0:ee.profile.business)==null?void 0:Br.legalBusinessName),((Ar=ee.profile)==null?void 0:Ar.individual)&&`${constructFullName((Zr=(Lr=(Ur=ee.profile)==null?void 0:Ur.individual)==null?void 0:Lr.name)==null?void 0:Zr.firstName,(tn=(rn=(nn=ee.profile)==null?void 0:nn.individual)==null?void 0:rn.name)==null?void 0:tn.lastName,(Yr=(Fr=(Nr=ee.profile)==null?void 0:Nr.individual)==null?void 0:Fr.name)==null?void 0:Yr.middleName,(Or=(vr=(Dr=ee.profile)==null?void 0:Dr.individual)==null?void 0:vr.name)==null?void 0:Or.suffix)}`]}),!te&&jsx("div",{className:"mercoa-text-sm mercoa-leading-6 mercoa-text-gray-400 mercoa-select-all",children:ee.id})]}),jsx("div",{className:"mercoa-flex-grow"}),jsx(MercoaButton,{isEmphasized:!1,size:"sm",className:"mercoa-ml-5",onClick:async()=>{var Rr,kr;if(!re.entityId)return;let $r;ce==="payor"?$r=await((Rr=re.client)==null?void 0:Rr.entity.getOnboardingLink(ee.id,{expiresIn:"30d",type:javascript.Mercoa.EntityOnboardingLinkType.Payor})):$r=await((kr=re.client)==null?void 0:kr.entity.getOnboardingLink(ee.id,{expiresIn:"30d",type:javascript.Mercoa.EntityOnboardingLinkType.Payee})),$r?navigator.clipboard.writeText($r).then(function(){Q$1.info("Link Copied")},function(Cr){Q$1.error("There was an issue generating the onboarding link. Please refresh and try again.")}):(Q$1.error("There was an issue generating the onboarding link. Please refresh and try again."),re.refresh()),re.refresh()},children:"Onboarding Link"})]}),jsxs("div",{className:"mercoa-flex mercoa-w-full mercoa-flex-none mercoa-gap-x-2 mercoa-px-6 mercoa-border-t mercoa-border-gray-900/5 mercoa-mt-3 mercoa-pt-2",children:[jsxs("dt",{className:"mercoa-flex-none",children:[jsx("span",{className:"mercoa-sr-only",children:"Email"}),jsx(EnvelopeIcon$1,{className:"mercoa-h-6 mercoa-w-5 mercoa-text-gray-400","aria-hidden":"true"})]}),jsx("dd",{className:"mercoa-text-sm mercoa-leading-6 mercoa-text-gray-500 mercoa-select-all",children:ee.email})]}),nr&&jsxs("div",{className:"mercoa-flex mercoa-w-full mercoa-flex-none mercoa-gap-x-2 mercoa-px-6 mercoa-mt-1",children:[jsxs("dt",{className:"mercoa-flex-none",children:[jsx("span",{className:"mercoa-sr-only",children:"Email"}),jsx(DevicePhoneMobileIcon$1,{className:"mercoa-h-6 mercoa-w-5 mercoa-text-gray-400","aria-hidden":"true"})]}),jsx("dd",{className:"mercoa-text-sm mercoa-leading-6 mercoa-text-gray-500 mercoa-select-all",children:jsx("a",{className:"mercoa-text-sm mercoa-font-medium mercoa-leading-3 mercoa-text-blue-400",href:`tel:${ar}`,children:ar})})]}),(ir==null?void 0:ir.addressLine1)&&jsxs("div",{className:"mercoa-flex mercoa-w-full mercoa-flex-none mercoa-gap-x-2 mercoa-px-6 mercoa-mt-1",children:[jsxs("dt",{className:"mercoa-flex-none",children:[jsx("span",{className:"mercoa-sr-only",children:"Address"}),jsx(MapPinIcon$1,{className:"mercoa-h-6 mercoa-w-5 mercoa-text-gray-400","aria-hidden":"true"})]}),jsx("dd",{className:"mercoa-text-sm mercoa-leading-6 mercoa-text-gray-500 mercoa-select-all",children:sr})]}),jsx("div",{className:"mercoa-flex mercoa-flex-auto mercoa-pl-6 mercoa-pt-6 mercoa-items-center",children:jsx("dd",{className:"mercoa-text-lg mercoa-font-semibold mercoa-leading-6 mercoa-text-gray-800 mercoa-inline",children:"Payment Methods"})}),jsx("div",{className:"mercoa-flex mercoa-flex-auto mercoa-pl-6 mercoa-mt-2 mercoa-pt-2 mercoa-items-center mercoa-border-t mercoa-border-gray-900/5 ",children:jsx("dd",{className:"mercoa-text-base mercoa-font-semibold mercoa-leading-6 mercoa-text-gray-800 mercoa-inline",children:"ACH"})}),jsx("div",{className:"mercoa-grid mercoa-grid-cols-3 mercoa-gap-2 mercoa-ml-4 mercoa-p-2",children:(Tr=ee.paymentMethods.filter($r=>$r.type===javascript.Mercoa.PaymentMethodType.BankAccount))==null?void 0:Tr.map($r=>jsx(cr,{method:$r},$r.id))}),jsx("div",{className:"mercoa-flex mercoa-flex-auto mercoa-pl-6 mercoa-mt-2 mercoa-pt-2 mercoa-items-center mercoa-border-t mercoa-border-gray-900/5 ",children:jsx("dd",{className:"mercoa-text-base mercoa-font-semibold mercoa-leading-6 mercoa-text-gray-800 mercoa-inline",children:"Check"})}),jsx("div",{className:"mercoa-grid mercoa-grid-cols-3 mercoa-gap-2 mercoa-ml-4 mercoa-p-2",children:(Pr=ee.paymentMethods.filter($r=>$r.type===javascript.Mercoa.PaymentMethodType.Check))==null?void 0:Pr.map($r=>jsx(cr,{method:$r},$r.id))}),jsx("div",{className:"mercoa-flex mercoa-flex-auto mercoa-pl-6 mercoa-mt-2 mercoa-pt-2 mercoa-items-center mercoa-border-t mercoa-border-gray-900/5 "}),jsx("div",{className:"mercoa-grid mercoa-grid-cols-3 mercoa-gap-2 mercoa-ml-4 mercoa-p-2",children:(gr=ee.paymentMethods.filter($r=>$r.type===javascript.Mercoa.PaymentMethodType.Custom))==null?void 0:gr.map($r=>jsx(cr,{method:$r},$r.id))})]})}var accounting$1={exports:{}};/*!
|
|
145
|
+
mercoa-cursor-pointer mercoa-bg-white mercoa-px-6 mercoa-py-5 mercoa-shadow-sm hover:mercoa-border-indigo-600 hover:mercoa-text-gray-800`,children:"Business"})]}),fr==="business"&&jsxs(Fragment,{children:[jsxs("div",{className:"mercoa-mt-1",children:[jsx("label",{htmlFor:"email",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Business Type"}),jsxs("select",{...ir("businessType"),className:"mercoa-mt-1 mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border mercoa-border-gray-300 mercoa-bg-white mercoa-py-2 mercoa-px-3 mercoa-shadow-sm focus:mercoa-border-indigo-500 focus:mercoa-outline-none focus:mercoa-ring-indigo-500 sm:mercoa-text-sm",children:[jsx("option",{value:"",disabled:!0,children:"Select an option"}),jsx("option",{value:"soleProprietorship",children:"Sole proprietorship"}),jsx("option",{value:"llc",children:"LLC"}),jsx("option",{value:"trust",children:"Trust"}),jsx("option",{value:"publicCorporation",children:"Public Corporation"}),jsx("option",{value:"privateCorporation",children:"Private Corporation"}),jsx("option",{value:"partnership",children:"Partnership"}),jsx("option",{value:"unincorporatedAssociation",children:"Unincorporated association"}),jsx("option",{value:"unincorporatedNonProfit",children:"Unincorporated Non-Profit "}),jsx("option",{value:"incorporatedNonProfit",children:"Incorporated Non-Profit "})]})]}),jsxs("div",{className:"mercoa-mt-1",children:[jsx("label",{htmlFor:"email",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Business Website"}),jsx("input",{type:"text",...ir("website"),className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 focus:mercoa-border-indigo-500 focus:mercoa-ring-indigo-500 sm:mercoa-text-sm",placeholder:"https://www.example.com"}),((Tr=ur==null?void 0:ur.website)==null?void 0:Tr.message)&&jsx("p",{className:"mercoa-text-sm mercoa-text-red-500",children:(Pr=ur==null?void 0:ur.website)==null?void 0:Pr.message})]}),jsxs("div",{className:"mercoa-mt-1",children:[jsx("label",{htmlFor:"email",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Business Description"}),jsx("input",{type:"text",...ir("description"),className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 focus:mercoa-border-indigo-500 focus:mercoa-ring-indigo-500 sm:mercoa-text-sm",placeholder:""})]})]}),fr==="individual"&&jsxs("div",{className:"mercoa-mt-1",children:[jsx("label",{htmlFor:"email",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Full Name"}),jsxs("div",{className:"mercoa-grid mercoa-grid-cols-7 mercoa-gap-1",children:[jsx("input",{type:"text",...ir("firstName"),required:!0,className:"mercoa-col-span-2 mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 focus:mercoa-border-indigo-500 focus:mercoa-ring-indigo-500 sm:mercoa-text-sm",placeholder:"First Name"}),jsx("input",{type:"text",...ir("middleName"),className:"mercoa-col-span-2 mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 focus:mercoa-border-indigo-500 focus:mercoa-ring-indigo-500 sm:mercoa-text-sm",placeholder:"Middle Name"}),jsx("input",{type:"text",...ir("lastName"),required:!0,className:"mercoa-col-span-2 mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 focus:mercoa-border-indigo-500 focus:mercoa-ring-indigo-500 sm:mercoa-text-sm",placeholder:"Last Name"}),jsxs("select",{...ir("suffix"),className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border mercoa-border-gray-300 mercoa-bg-white mercoa-py-2 mercoa-px-3 mercoa-shadow-sm focus:mercoa-border-indigo-500 focus:mercoa-outline-none focus:mercoa-ring-indigo-500 sm:mercoa-text-sm",children:[jsx("option",{value:""}),jsx("option",{value:"Sr.",children:"Sr."}),jsx("option",{value:"Jr.",children:"Jr."}),jsx("option",{value:"II",children:"II"}),jsx("option",{value:"III",children:"III"}),jsx("option",{value:"IV",children:"IV"}),jsx("option",{value:"V",children:"V"})]})]})]}),fr&&jsx(MercoaButton,{isEmphasized:!0,type:"submit",className:"mercoa-mt-2 mercoa-w-full",children:"Save"})]})}function Counterparties({type:ee,admin:te}){var _r,xr,jr;const ce=useMercoaSession(),[re,nr]=React$1.useState(void 0),[or,ar]=React$1.useState(!1),[ir,sr]=React$1.useState([]),[cr,lr]=React$1.useState(1),[ur,fr]=React$1.useState(!0),[hr,pr]=React$1.useState(20),[dr,mr]=React$1.useState(0),[yr,Mr]=React$1.useState(),[Sr,Er]=React$1.useState(void 0);React$1.useEffect(()=>{!ce.client||!ce.entityId||(ee==="payor"?ce.client.entity.counterparty.findPayors(ce.entityId,{limit:hr,startingAfter:ir[ir.length-1],...yr&&{name:yr},paymentMethods:!0}).then(wr=>{nr(wr.data),fr(wr.hasMore),mr(wr.count)}):ce.client.entity.counterparty.findPayees(ce.entityId,{limit:hr,startingAfter:ir[ir.length-1],...yr&&{name:yr},paymentMethods:!0}).then(wr=>{console.log(wr),nr(wr.data),fr(wr.hasMore),mr(wr.count)}))},[ce.client,ce.entityId,ce.refreshId,ee,ir]);function br({entity:wr,index:Ir,type:Br,setSelected:Ar,selectedId:Ur,admin:Lr}){const Zr=useMercoaSession();return Ur===wr.id?jsx("tr",{className:`hover:mercoa-bg-gray-100 ${Ir%2===0?void 0:"mercoa-bg-gray-50"}`,children:jsx("td",{className:"mercoa-p-10 mercoa-bg-gray-200",colSpan:Lr?4:3,children:jsx("div",{className:"mercoa-rounded-lg mercoa-bg-gray-50 mercoa-shadow mercoa-ring-1 mercoa-ring-gray-900/5",children:jsx(CounterpartyDetails,{counterparty:wr,admin:Lr,type:Br})})})},wr.email):jsxs("tr",{className:`hover:mercoa-bg-gray-100 mercoa-cursor-pointer ${Ir%2===0?void 0:"mercoa-bg-gray-50"}`,onClick:()=>{Ar(wr)},children:[jsx("td",{className:"mercoa-whitespace-nowrap mercoa-py-4 mercoa-pl-4 mercoa-pr-3 mercoa-text-sm mercoa-font-medium mercoa-text-gray-900 sm:mercoa-pl-6",children:wr.name}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-4 mercoa-text-sm mercoa-text-gray-900",children:wr.email}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-4 mercoa-text-sm mercoa-text-gray-900",children:capitalize(wr.accountType)}),Lr&&jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-4 mercoa-text-sm mercoa-text-gray-900",children:jsx(MercoaButton,{isEmphasized:!1,color:"red",size:"sm",onClick:async()=>{var nn,rn;Zr.entityId&&(Br==="payor"?await((nn=Zr.client)==null?void 0:nn.entity.counterparty.hidePayors(Zr.entityId,{payors:[wr.id]})):await((rn=Zr.client)==null?void 0:rn.entity.counterparty.hidePayees(Zr.entityId,{payees:[wr.id]})),Zr.refresh())},children:"Hide"})})]},wr.email)}return jsxs("div",{className:"mercoa-overflow-hidden mercoa-shadow mercoa-ring-1 mercoa-ring-black mercoa-ring-opacity-5 md:mercoa-rounded-lg mercoa-p-5",children:[jsxs("div",{className:"mercoa-flex mercoa-mb-5 mercoa-space-x-5 mercoa-items-center",children:[jsx("h2",{className:"mercoa-text-base mercoa-font-semibold mercoa-leading-7 mercoa-text-gray-900",children:ee==="payor"?"Customers":"Vendors"}),jsx(DebouncedSearch,{placeholder:`Search ${ee==="payor"?"Customers":"Vendors"}`,onSettle:wr=>{Mr(wr),lr(1),sr([])}}),(te||!((jr=(xr=(_r=ce.iframeOptions)==null?void 0:_r.options)==null?void 0:xr.vendors)!=null&&jr.disableCreation))&&jsxs(MercoaButton,{isEmphasized:!0,type:"button",className:"mercoa-ml-2 mercoa-inline-flex mercoa-text-sm",onClick:()=>{ar(!0)},children:[jsx(PlusIcon$1,{className:"-mercoa-ml-1 mercoa-inline-flex mercoa-h-5 mercoa-w-5 md:mercoa-mr-2"})," ",jsxs("span",{className:"mercoa-hidden md:mercoa-inline-block",children:["Add ",ee==="payee"?"Vendor":"Customer"]})]})]}),jsxs("table",{className:"mercoa-min-w-full mercoa-divide-y mercoa-divide-gray-300",children:[jsx("thead",{className:"mercoa-bg-gray-50",children:jsxs("tr",{children:[jsx("th",{scope:"col",className:"mercoa-py-3.5 mercoa-pl-4 mercoa-pr-3 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 sm:mercoa-pl-6",children:"Name"}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900",children:"Email"}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900",children:"Type"}),te&&jsx("th",{children:jsx("span",{className:"mercoa-sr-only",children:"Hide"})})]})}),jsxs("tbody",{className:"mercoa-bg-white",children:[!re&&jsx("tr",{children:jsx("td",{colSpan:5,className:"mercoa-p-9 mercoa-text-center",children:jsx(LoadingSpinnerIcon,{})})}),re&&re.map((wr,Ir)=>jsx(br,{entity:wr,index:Ir,type:ee,setSelected:Er,selectedId:Sr==null?void 0:Sr.id,admin:te},wr.id))]})]}),re&&jsx(TableNavigation,{data:re,page:cr,setPage:lr,hasMore:ur,startingAfter:ir,setStartingAfter:sr,count:dr,resultsPerPage:hr,setResultsPerPage:pr}),jsx(AddCounterpartyModal,{type:ee,show:or,setShow:ar})]})}function AddCounterpartyModal({type:ee,show:te,setShow:ce}){const re=useMercoaSession();return jsx(tt$1.Root,{show:te,as:React$1.Fragment,children:jsxs(_t$1,{as:"div",className:"mercoa-relative mercoa-z-10",onClose:()=>{re.refresh(),ce(!1)},children:[jsx(tt$1.Child,{as:React$1.Fragment,enter:"mercoa-ease-out mercoa-duration-300",enterFrom:"mercoa-opacity-0",enterTo:"mercoa-opacity-100",leave:"mercoa-ease-in mercoa-duration-200",leaveFrom:"mercoa-opacity-100",leaveTo:"mercoa-opacity-0",children:jsx("div",{className:"mercoa-fixed mercoa-inset-0 mercoa-bg-gray-500 mercoa-bg-mercoa-opacity-75 mercoa-transition-opacity"})}),jsx("div",{className:"mercoa-fixed mercoa-inset-0 mercoa-z-10 mercoa-overflow-y-auto",children:jsx("div",{className:"mercoa-flex mercoa-min-h-full mercoa-items-end mercoa-justify-center mercoa-p-4 mercoa-text-center sm:mercoa-items-center sm:mercoa-p-0",children:jsx(tt$1.Child,{as:React$1.Fragment,enter:"mercoa-ease-out mercoa-duration-300",enterFrom:"mercoa-opacity-0 mercoa-translate-y-4 sm:mercoa-translate-y-0 sm:mercoa-scale-95",enterTo:"mercoa-opacity-100 mercoa-translate-y-0 sm:mercoa-scale-100",leave:"mercoa-ease-in mercoa-duration-200",leaveFrom:"mercoa-opacity-100 mercoa-translate-y-0 sm:mercoa-scale-100",leaveTo:"mercoa-opacity-0 mercoa-translate-y-4 sm:mercoa-translate-y-0 sm:mercoa-scale-95",children:jsx(_t$1.Panel,{className:"mercoa-relative mercoa-transform mercoa-rounded-lg mercoa-bg-white mercoa-text-left mercoa-shadow-xl mercoa-transition-all",children:jsx("div",{className:"mercoa-w-[600px]",children:jsx(CounterpartyAddOrEdit,{type:ee,onComplete:()=>{ce(!1),re.refresh()}})})})})})})]})})}function CounterpartyDetails({counterparty:ee,admin:te,type:ce}){var lr,ur,fr,hr,pr,dr,mr,yr,Mr,Sr,Er,br,_r,xr,jr,wr,Ir,Br,Ar,Ur,Lr,Zr,nn,rn,tn,Nr,Fr,Yr,Dr,vr,Or,Tr,Pr,gr;const re=useMercoaSession(),nr=((fr=(ur=(lr=ee.profile)==null?void 0:lr.business)==null?void 0:ur.phone)==null?void 0:fr.number)??((dr=(pr=(hr=ee.profile)==null?void 0:hr.individual)==null?void 0:pr.phone)==null?void 0:dr.number),ar=`+${((Mr=(yr=(mr=ee.profile)==null?void 0:mr.business)==null?void 0:yr.phone)==null?void 0:Mr.countryCode)??((br=(Er=(Sr=ee.profile)==null?void 0:Sr.individual)==null?void 0:Er.phone)==null?void 0:br.countryCode)??"1"} ${nr}`,ir=((xr=(_r=ee.profile)==null?void 0:_r.business)==null?void 0:xr.address)??((wr=(jr=ee.profile)==null?void 0:jr.individual)==null?void 0:wr.address),sr=`${(ir==null?void 0:ir.addressLine1)??""} ${(ir==null?void 0:ir.addressLine2)??""}, ${(ir==null?void 0:ir.city)??""}, ${(ir==null?void 0:ir.stateOrProvince)??""} ${(ir==null?void 0:ir.postalCode)??""}`;function cr({method:$r}){let Rr=jsx(Fragment,{});return $r.type===javascript.Mercoa.PaymentMethodType.BankAccount?Rr=jsx(BankAccountComponent,{account:$r}):$r.type===javascript.Mercoa.PaymentMethodType.Card?Rr=jsx(CreditCardComponent,{account:$r}):$r.type===javascript.Mercoa.PaymentMethodType.Custom?Rr=jsx(CustomPaymentMethodComponent,{account:$r}):$r.type===javascript.Mercoa.PaymentMethodType.Check&&(Rr=jsx(CheckComponent,{account:$r})),jsxs("div",{children:[te&&jsxs(Fragment,{children:[jsx("p",{className:"mercoa-text-xs mercoa-font-bold mercoa-whitespace-nowrap",children:$r.type}),jsx("p",{className:"mercoa-text-xs mercoa-whitespace-nowrap",children:$r.id})]}),Rr]},$r.id)}return jsxs("div",{className:"mercoa-py-6 ",children:[jsxs("div",{className:"mercoa-flex mercoa-flex-auto mercoa-px-6 mercoa-items-center",children:[jsx("dt",{className:"mercoa-sr-only",children:"Vendor Name"}),jsxs("div",{children:[jsxs("dd",{className:"mercoa-text-xl mercoa-font-semibold mercoa-leading-6 mercoa-text-gray-900 mercoa-inline",children:[((Ir=ee.profile)==null?void 0:Ir.business)&&((Br=ee==null?void 0:ee.profile.business)==null?void 0:Br.legalBusinessName),((Ar=ee.profile)==null?void 0:Ar.individual)&&`${constructFullName((Zr=(Lr=(Ur=ee.profile)==null?void 0:Ur.individual)==null?void 0:Lr.name)==null?void 0:Zr.firstName,(tn=(rn=(nn=ee.profile)==null?void 0:nn.individual)==null?void 0:rn.name)==null?void 0:tn.lastName,(Yr=(Fr=(Nr=ee.profile)==null?void 0:Nr.individual)==null?void 0:Fr.name)==null?void 0:Yr.middleName,(Or=(vr=(Dr=ee.profile)==null?void 0:Dr.individual)==null?void 0:vr.name)==null?void 0:Or.suffix)}`]}),!te&&jsx("div",{className:"mercoa-text-sm mercoa-leading-6 mercoa-text-gray-400 mercoa-select-all",children:ee.id})]}),jsx("div",{className:"mercoa-flex-grow"}),jsx(MercoaButton,{isEmphasized:!1,size:"sm",className:"mercoa-ml-5",onClick:async()=>{var Rr,kr;if(!re.entityId)return;let $r;ce==="payor"?$r=await((Rr=re.client)==null?void 0:Rr.entity.getOnboardingLink(ee.id,{expiresIn:"30d",type:javascript.Mercoa.EntityOnboardingLinkType.Payor})):$r=await((kr=re.client)==null?void 0:kr.entity.getOnboardingLink(ee.id,{expiresIn:"30d",type:javascript.Mercoa.EntityOnboardingLinkType.Payee})),$r?navigator.clipboard.writeText($r).then(function(){Q$1.info("Link Copied")},function(Cr){Q$1.error("There was an issue generating the onboarding link. Please refresh and try again.")}):(Q$1.error("There was an issue generating the onboarding link. Please refresh and try again."),re.refresh()),re.refresh()},children:"Onboarding Link"})]}),jsxs("div",{className:"mercoa-flex mercoa-w-full mercoa-flex-none mercoa-gap-x-2 mercoa-px-6 mercoa-border-t mercoa-border-gray-900/5 mercoa-mt-3 mercoa-pt-2",children:[jsxs("dt",{className:"mercoa-flex-none",children:[jsx("span",{className:"mercoa-sr-only",children:"Email"}),jsx(EnvelopeIcon$1,{className:"mercoa-h-6 mercoa-w-5 mercoa-text-gray-400","aria-hidden":"true"})]}),jsx("dd",{className:"mercoa-text-sm mercoa-leading-6 mercoa-text-gray-500 mercoa-select-all",children:ee.email})]}),nr&&jsxs("div",{className:"mercoa-flex mercoa-w-full mercoa-flex-none mercoa-gap-x-2 mercoa-px-6 mercoa-mt-1",children:[jsxs("dt",{className:"mercoa-flex-none",children:[jsx("span",{className:"mercoa-sr-only",children:"Email"}),jsx(DevicePhoneMobileIcon$1,{className:"mercoa-h-6 mercoa-w-5 mercoa-text-gray-400","aria-hidden":"true"})]}),jsx("dd",{className:"mercoa-text-sm mercoa-leading-6 mercoa-text-gray-500 mercoa-select-all",children:jsx("a",{className:"mercoa-text-sm mercoa-font-medium mercoa-leading-3 mercoa-text-blue-400",href:`tel:${ar}`,children:ar})})]}),(ir==null?void 0:ir.addressLine1)&&jsxs("div",{className:"mercoa-flex mercoa-w-full mercoa-flex-none mercoa-gap-x-2 mercoa-px-6 mercoa-mt-1",children:[jsxs("dt",{className:"mercoa-flex-none",children:[jsx("span",{className:"mercoa-sr-only",children:"Address"}),jsx(MapPinIcon$1,{className:"mercoa-h-6 mercoa-w-5 mercoa-text-gray-400","aria-hidden":"true"})]}),jsx("dd",{className:"mercoa-text-sm mercoa-leading-6 mercoa-text-gray-500 mercoa-select-all",children:sr})]}),jsx("div",{className:"mercoa-flex mercoa-flex-auto mercoa-pl-6 mercoa-pt-6 mercoa-items-center",children:jsx("dd",{className:"mercoa-text-lg mercoa-font-semibold mercoa-leading-6 mercoa-text-gray-800 mercoa-inline",children:"Payment Methods"})}),jsx("div",{className:"mercoa-flex mercoa-flex-auto mercoa-pl-6 mercoa-mt-2 mercoa-pt-2 mercoa-items-center mercoa-border-t mercoa-border-gray-900/5 ",children:jsx("dd",{className:"mercoa-text-base mercoa-font-semibold mercoa-leading-6 mercoa-text-gray-800 mercoa-inline",children:"ACH"})}),jsx("div",{className:"mercoa-grid mercoa-grid-cols-3 mercoa-gap-2 mercoa-ml-4 mercoa-p-2",children:(Tr=ee.paymentMethods.filter($r=>$r.type===javascript.Mercoa.PaymentMethodType.BankAccount))==null?void 0:Tr.map($r=>jsx(cr,{method:$r},$r.id))}),jsx("div",{className:"mercoa-flex mercoa-flex-auto mercoa-pl-6 mercoa-mt-2 mercoa-pt-2 mercoa-items-center mercoa-border-t mercoa-border-gray-900/5 ",children:jsx("dd",{className:"mercoa-text-base mercoa-font-semibold mercoa-leading-6 mercoa-text-gray-800 mercoa-inline",children:"Check"})}),jsx("div",{className:"mercoa-grid mercoa-grid-cols-3 mercoa-gap-2 mercoa-ml-4 mercoa-p-2",children:(Pr=ee.paymentMethods.filter($r=>$r.type===javascript.Mercoa.PaymentMethodType.Check))==null?void 0:Pr.map($r=>jsx(cr,{method:$r},$r.id))}),jsx("div",{className:"mercoa-flex mercoa-flex-auto mercoa-pl-6 mercoa-mt-2 mercoa-pt-2 mercoa-items-center mercoa-border-t mercoa-border-gray-900/5 "}),jsx("div",{className:"mercoa-grid mercoa-grid-cols-3 mercoa-gap-2 mercoa-ml-4 mercoa-p-2",children:(gr=ee.paymentMethods.filter($r=>$r.type===javascript.Mercoa.PaymentMethodType.Custom))==null?void 0:gr.map($r=>jsx(cr,{method:$r},$r.id))})]})}var accounting$1={exports:{}};/*!
|
|
146
146
|
* accounting.js v0.4.1
|
|
147
147
|
* Copyright 2014 Open Exchange Rates
|
|
148
148
|
*
|
|
@@ -165,7 +165,7 @@ License: MIT
|
|
|
165
165
|
`:"\r"}(Rr,qr)),Br=!1,jr.delimiter)xr(jr.delimiter)&&(jr.delimiter=jr.delimiter(Rr),Dr.meta.delimiter=jr.delimiter);else{var on=function(yn,jn,wn,Dn,Rn){var fn,Sn,gn,vn;Rn=Rn||[","," ","|",";",sr.RECORD_SEP,sr.UNIT_SEP];for(var Gr=0;Gr<Rn.length;Gr++){var Qr=Rn[Gr],cn=0,Xr=0,zr=0;gn=void 0;for(var Vr=new yr({comments:Dn,delimiter:Qr,newline:jn,preview:10}).parse(yn),un=0;un<Vr.data.length;un++)if(wn&&Or(Vr.data[un]))zr++;else{var Kr=Vr.data[un].length;Xr+=Kr,gn!==void 0?0<Kr&&(cn+=Math.abs(Kr-gn),gn=Kr):gn=Kr}0<Vr.data.length&&(Xr/=Vr.data.length-zr),(Sn===void 0||cn<=Sn)&&(vn===void 0||vn<Xr)&&1.99<Xr&&(Sn=cn,fn=Qr,vn=Xr)}return{successful:!!(jr.delimiter=fn),bestDelimiter:fn}}(Rr,jr.newline,jr.skipEmptyLines,jr.comments,jr.delimitersToGuess);on.successful?jr.delimiter=on.bestDelimiter:(Br=!0,jr.delimiter=sr.DefaultDelimiter),Dr.meta.delimiter=jr.delimiter}var sn=br(jr);return jr.preview&&jr.header&&sn.preview++,wr=Rr,Ir=new yr(sn),Dr=Ir.parse(wr,kr,Cr),Tr(),Nr?{meta:{paused:!0}}:Dr||{meta:{paused:!1}}},this.paused=function(){return Nr},this.pause=function(){Nr=!0,Ir.abort(),wr=xr(jr.chunk)?"":wr.substring(Ir.getCharIndex())},this.resume=function(){nn.streamer._halted?(Nr=!1,nn.streamer.parseChunk(wr,!0)):setTimeout(nn.resume,3)},this.aborted=function(){return Fr},this.abort=function(){Fr=!0,Ir.abort(),Dr.meta.aborted=!0,xr(jr.complete)&&jr.complete(Dr),wr=""}}function mr(jr){return jr.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function yr(jr){var wr,Ir=(jr=jr||{}).delimiter,Br=jr.newline,Ar=jr.comments,Ur=jr.step,Lr=jr.preview,Zr=jr.fastMode,nn=wr=jr.quoteChar===void 0||jr.quoteChar===null?'"':jr.quoteChar;if(jr.escapeChar!==void 0&&(nn=jr.escapeChar),(typeof Ir!="string"||-1<sr.BAD_DELIMITERS.indexOf(Ir))&&(Ir=","),Ar===Ir)throw new Error("Comment character same as delimiter");Ar===!0?Ar="#":(typeof Ar!="string"||-1<sr.BAD_DELIMITERS.indexOf(Ar))&&(Ar=!1),Br!==`
|
|
166
166
|
`&&Br!=="\r"&&Br!==`\r
|
|
167
167
|
`&&(Br=`
|
|
168
|
-
`);var rn=0,tn=!1;this.parse=function(Nr,Fr,Yr){if(typeof Nr!="string")throw new Error("Input must be a string");var Dr=Nr.length,vr=Ir.length,Or=Br.length,Tr=Ar.length,Pr=xr(Ur),gr=[],$r=[],Rr=[],kr=rn=0;if(!Nr)return hn();if(jr.header&&!Fr){var Cr=Nr.split(Br)[0].split(Ir),qr=[],on={},sn=!1;for(var yn in Cr){var jn=Cr[yn];xr(jr.transformHeader)&&(jn=jr.transformHeader(jn,yn));var wn=jn,Dn=on[jn]||0;for(0<Dn&&(sn=!0,wn=jn+"_"+Dn),on[jn]=Dn+1;qr.includes(wn);)wn=wn+"_"+Dn;qr.push(wn)}if(sn){var Rn=Nr.split(Br);Rn[0]=qr.join(Ir),Nr=Rn.join(Br)}}if(Zr||Zr!==!1&&Nr.indexOf(wr)===-1){for(var fn=Nr.split(Br),Sn=0;Sn<fn.length;Sn++){if(Rr=fn[Sn],rn+=Rr.length,Sn!==fn.length-1)rn+=Br.length;else if(Yr)return hn();if(!Ar||Rr.substring(0,Tr)!==Ar){if(Pr){if(gr=[],zr(Rr.split(Ir)),_n(),tn)return hn()}else zr(Rr.split(Ir));if(Lr&&Lr<=Sn)return gr=gr.slice(0,Lr),hn(!0)}}return hn()}for(var gn=Nr.indexOf(Ir,rn),vn=Nr.indexOf(Br,rn),Gr=new RegExp(mr(nn)+mr(wr),"g"),Qr=Nr.indexOf(wr,rn);;)if(Nr[rn]!==wr)if(Ar&&Rr.length===0&&Nr.substring(rn,rn+Tr)===Ar){if(vn===-1)return hn();rn=vn+Or,vn=Nr.indexOf(Br,rn),gn=Nr.indexOf(Ir,rn)}else if(gn!==-1&&(gn<vn||vn===-1))Rr.push(Nr.substring(rn,gn)),rn=gn+vr,gn=Nr.indexOf(Ir,rn);else{if(vn===-1)break;if(Rr.push(Nr.substring(rn,vn)),Kr(vn+Or),Pr&&(_n(),tn))return hn();if(Lr&&gr.length>=Lr)return hn(!0)}else for(Qr=rn,rn++;;){if((Qr=Nr.indexOf(wr,Qr+1))===-1)return Yr||$r.push({type:"Quotes",code:"MissingQuotes",message:"Quoted field unterminated",row:gr.length,index:rn}),un();if(Qr===Dr-1)return un(Nr.substring(rn,Qr).replace(Gr,wr));if(wr!==nn||Nr[Qr+1]!==nn){if(wr===nn||Qr===0||Nr[Qr-1]!==nn){gn!==-1&&gn<Qr+1&&(gn=Nr.indexOf(Ir,Qr+1)),vn!==-1&&vn<Qr+1&&(vn=Nr.indexOf(Br,Qr+1));var cn=Vr(vn===-1?gn:Math.min(gn,vn));if(Nr.substr(Qr+1+cn,vr)===Ir){Rr.push(Nr.substring(rn,Qr).replace(Gr,wr)),Nr[rn=Qr+1+cn+vr]!==wr&&(Qr=Nr.indexOf(wr,rn)),gn=Nr.indexOf(Ir,rn),vn=Nr.indexOf(Br,rn);break}var Xr=Vr(vn);if(Nr.substring(Qr+1+Xr,Qr+1+Xr+Or)===Br){if(Rr.push(Nr.substring(rn,Qr).replace(Gr,wr)),Kr(Qr+1+Xr+Or),gn=Nr.indexOf(Ir,rn),Qr=Nr.indexOf(wr,rn),Pr&&(_n(),tn))return hn();if(Lr&&gr.length>=Lr)return hn(!0);break}$r.push({type:"Quotes",code:"InvalidQuotes",message:"Trailing quote on quoted field is malformed",row:gr.length,index:rn}),Qr++}}else Qr++}return un();function zr(zn){gr.push(zn),kr=rn}function Vr(zn){var dn=0;if(zn!==-1){var mn=Nr.substring(Qr+1,zn);mn&&mn.trim()===""&&(dn=mn.length)}return dn}function un(zn){return Yr||(zn===void 0&&(zn=Nr.substring(rn)),Rr.push(zn),rn=Dr,zr(Rr),Pr&&_n()),hn()}function Kr(zn){rn=zn,zr(Rr),Rr=[],vn=Nr.indexOf(Br,rn)}function hn(zn){return{data:gr,errors:$r,meta:{delimiter:Ir,linebreak:Br,aborted:tn,truncated:!!zn,cursor:kr+(Fr||0)}}}function _n(){Ur(hn()),gr=[],$r=[]}},this.abort=function(){tn=!0},this.getCharIndex=function(){return rn}}function Mr(jr){var wr=jr.data,Ir=ar[wr.workerId],Br=!1;if(wr.error)Ir.userError(wr.error,wr.file);else if(wr.results&&wr.results.data){var Ar={abort:function(){Br=!0,Sr(wr.workerId,{data:[],errors:[],meta:{aborted:!0}})},pause:Er,resume:Er};if(xr(Ir.userStep)){for(var Ur=0;Ur<wr.results.data.length&&(Ir.userStep({data:wr.results.data[Ur],errors:wr.results.errors,meta:wr.results.meta},Ar),!Br);Ur++);delete wr.results}else xr(Ir.userChunk)&&(Ir.userChunk(wr.results,Ar,wr.file),delete wr.results)}wr.finished&&!Br&&Sr(wr.workerId,wr.results)}function Sr(jr,wr){var Ir=ar[jr];xr(Ir.userComplete)&&Ir.userComplete(wr),Ir.terminate(),delete ar[jr]}function Er(){throw new Error("Not implemented.")}function br(jr){if(typeof jr!="object"||jr===null)return jr;var wr=Array.isArray(jr)?[]:{};for(var Ir in jr)wr[Ir]=br(jr[Ir]);return wr}function _r(jr,wr){return function(){jr.apply(wr,arguments)}}function xr(jr){return typeof jr=="function"}return or&&(re.onmessage=function(jr){var wr=jr.data;if(sr.WORKER_ID===void 0&&wr&&(sr.WORKER_ID=wr.workerId),typeof wr.input=="string")re.postMessage({workerId:sr.WORKER_ID,results:sr.parse(wr.input,wr.config),finished:!0});else if(re.File&&wr.input instanceof File||wr.input instanceof Object){var Ir=sr.parse(wr.input,wr.config);Ir&&re.postMessage({workerId:sr.WORKER_ID,results:Ir,finished:!0})}}),(ur.prototype=Object.create(lr.prototype)).constructor=ur,(fr.prototype=Object.create(lr.prototype)).constructor=fr,(hr.prototype=Object.create(hr.prototype)).constructor=hr,(pr.prototype=Object.create(lr.prototype)).constructor=pr,sr})})(papaparse_min);var papaparse_minExports=papaparse_min.exports;const Papa=getDefaultExportFromCjs(papaparse_minExports);pdfjs$1.GlobalWorkerOptions.workerSrc=`//unpkg.com/pdfjs-dist@${pdfjs$1.version}/build/pdf.worker.min.js`;function ApprovalsTable({search:ee,onClick:te}){var nn,rn;const ce=useMercoaSession(),re=javascript.Mercoa.InvoiceStatus.New,[nr,or]=React$1.useState(),[ar,ir]=React$1.useState(javascript.Mercoa.InvoiceOrderByField.CreatedAt),[sr,cr]=React$1.useState(javascript.Mercoa.OrderDirection.Asc),[lr,ur]=React$1.useState(!0),[fr,hr]=React$1.useState(0),[pr,dr]=React$1.useState(!1),[mr,yr]=React$1.useState([]),[Mr,Sr]=React$1.useState(20),[Er,br]=React$1.useState(1),_r=React$1.useRef(null),[xr,jr]=React$1.useState(!1),[wr,Ir]=React$1.useState(!1),[Br,Ar]=React$1.useState([]);React$1.useLayoutEffect(()=>{const tn=Br.length>0&&Br.length<(nr?nr.length:0);jr(Br.length===(nr?nr.length:0)),Ir(tn),_r.current&&(_r.current.indeterminate=tn)},[Br,nr]);function Ur(){nr&&(Ar(xr||wr?[]:nr),jr(!xr&&!wr),Ir(!1))}async function Lr(){var Nr;if(!ce.token||!((Nr=ce.entity)!=null&&Nr.id)||!ce.user)return;let tn=!1;await Promise.all(Br.map(async Fr=>{var Yr,Dr;try{await((Dr=ce.client)==null?void 0:Dr.invoice.approval.approve(Fr.id,{userId:(Yr=ce.user)==null?void 0:Yr.id})),tn=!0}catch(vr){console.error("Error approving invoice: ",vr),console.log("Errored invoice: ",{invoice:Fr})}})),tn&&Q$1.success("Approved"),ce.refresh()}async function Zr(){var Nr;if(!ce.token||!((Nr=ce.entity)!=null&&Nr.id)||!ce.user)return;let tn=!1;await Promise.all(Br.map(Fr=>{var Yr,Dr;try{(Dr=ce.client)==null||Dr.invoice.approval.reject(Fr.id,{userId:(Yr=ce.user)==null?void 0:Yr.id}),tn=!0}catch(vr){console.error("Error rejecting invoice: ",vr),console.log("Errored invoice: ",{invoice:Fr})}})),tn&&Q$1.success("Rejected"),ce.refresh()}return React$1.useEffect(()=>{var tn,Nr,Fr,Yr;!ce.token||!((tn=ce.entity)!=null&&tn.id)||!((Nr=ce.user)!=null&&Nr.id)||(Yr=ce.client)==null||Yr.entity.invoice.find(ce.entity.id,{status:re,search:ee,orderBy:ar,orderDirection:sr,approverId:(Fr=ce.user)==null?void 0:Fr.id,limit:Mr,startingAfter:mr[mr.length-1],excludeReceivables:!0}).then(Dr=>{if(Dr){const vr=Dr.data.filter(Or=>{var Tr;return(Tr=Or.approvers)==null?void 0:Tr.some(Pr=>{var gr;return Pr.assignedUserId===((gr=ce.user)==null?void 0:gr.id)&&Pr.action===javascript.Mercoa.ApproverAction.None})});ur(Dr.hasMore),hr(Dr.count),or(vr),dr(vr.length>0)}})},[ce.token,ce.entity,ce.refreshId,(nn=ce.user)==null?void 0:nn.id,ee,ar,sr,mr,Mr]),(rn=ce.user)!=null&&rn.id?nr?jsx(Fragment,{children:pr&&jsx(Fragment,{children:ce.entity&&nr?jsxs(Fragment,{children:[jsxs("div",{className:"mercoa-mt-7 ",children:[jsx("div",{className:"sm:mercoa-flex sm:mercoa-items-center",children:jsxs("div",{className:"sm:mercoa-flex-auto",children:[jsx("h1",{className:"mercoa-text-base mercoa-font-semibold mercoa-leading-6 mercoa-text-gray-900",children:"Assigned to Me"}),jsx("p",{className:"mercoa-mt-2 mercoa-text-sm mercoa-text-gray-700",children:"A list of all invoices that require your review"})]})}),jsx("div",{className:"mercoa-flow-root",children:jsx("div",{className:"-mercoa-mx-4 -mercoa-my-2 mercoa-overflow-x-auto sm:-mercoa-mx-6 lg:-mercoa-mx-8",children:jsx("div",{className:"mercoa-inline-block mercoa-min-w-full mercoa-py-2 mercoa-align-middle sm:mercoa-px-6 lg:mercoa-px-8",children:jsxs("div",{className:"mercoa-relative",children:[Br.length>0&&jsxs("div",{className:"mercoa-absolute mercoa-left-14 mercoa-top-0 mercoa-flex mercoa-h-12 mercoa-items-center mercoa-space-x-3 mercoa-bg-white sm:mercoa-left-12",children:[jsx("button",{type:"button",className:"mercoa-inline-flex mercoa-items-center mercoa-rounded mercoa-bg-white mercoa-px-2 mercoa-py-1 mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 mercoa-shadow-sm mercoa-ring-1 mercoa-ring-inset mercoa-ring-gray-300 hover:mercoa-bg-gray-50 disabled:mercoa-cursor-not-allowed disabled:mercoa-opacity-30 disabled:hover:mercoa-bg-white",onClick:Lr,children:"Approve"}),jsx("button",{type:"button",className:"mercoa-inline-flex mercoa-items-center mercoa-rounded mercoa-bg-white mercoa-px-2 mercoa-py-1 mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 mercoa-shadow-sm mercoa-ring-1 mercoa-ring-inset mercoa-ring-gray-300 hover:mercoa-bg-gray-50 disabled:mercoa-cursor-not-allowed disabled:mercoa-opacity-30 disabled:hover:mercoa-bg-white",onClick:Zr,children:"Reject"})]}),jsxs("table",{className:"mercoa-min-w-full table-mercoa-fixed mercoa-divide-y mercoa-divide-gray-300 mercoa-mt-5",children:[jsx("thead",{children:jsxs("tr",{children:[jsx("th",{scope:"col",className:"mercoa-relative mercoa-px-7 sm:mercoa-w-12 sm:mercoa-px-6",children:jsx("input",{type:"checkbox",className:"mercoa-absolute mercoa-left-4 mercoa-top-1/2 -mercoa-mt-2 mercoa-h-4 mercoa-w-4 mercoa-rounded mercoa-border-gray-300 mercoa-text-mercoa-primary-text focus:mercoa-ring-mercoa-primary",ref:_r,checked:xr,onChange:Ur})}),jsx("th",{scope:"col",className:"mercoa-min-w-[12rem] mercoa-py-3.5 mercoa-pl-4 mercoa-pr-3 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 sm:mercoa-pl-3",children:jsx(TableOrderHeader,{title:"Vendor",setOrder:tn=>{ir(javascript.Mercoa.InvoiceOrderByField.VendorName),cr(tn)},isSelected:ar===javascript.Mercoa.InvoiceOrderByField.VendorName,orderDirection:sr})}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 mercoa-hidden sm:mercoa-table-cell",children:jsx(TableOrderHeader,{title:"Invoice Number",setOrder:tn=>{ir(javascript.Mercoa.InvoiceOrderByField.InvoiceNumber),cr(tn)},isSelected:ar===javascript.Mercoa.InvoiceOrderByField.InvoiceNumber,orderDirection:sr})}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900",children:jsx(TableOrderHeader,{title:"Due Date",setOrder:tn=>{ir(javascript.Mercoa.InvoiceOrderByField.DueDate),cr(tn)},isSelected:ar===javascript.Mercoa.InvoiceOrderByField.DueDate,orderDirection:sr})}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900",children:jsx(TableOrderHeader,{title:"Amount",setOrder:tn=>{ir(javascript.Mercoa.InvoiceOrderByField.Amount),cr(tn)},isSelected:ar===javascript.Mercoa.InvoiceOrderByField.Amount,orderDirection:sr})}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 mercoa-pl-6 mercoa-hidden lg:mercoa-table-cell",children:"Status"})]})}),jsx("tbody",{className:"mercoa-divide-y mercoa-divide-gray-200 mercoa-bg-white",children:nr.map(tn=>{var Nr;return jsxs("tr",{className:classNames$1("mercoa-cursor-pointer hover:mercoa-bg-gray-100",Br.includes(tn)?"mercoa-bg-gray-50":void 0),children:[jsxs("td",{className:"mercoa-relative mercoa-px-7 sm:mercoa-w-12 sm:mercoa-px-6",children:[Br.includes(tn)&&jsx("div",{className:"mercoa-absolute mercoa-inset-y-0 mercoa-left-0 mercoa-w-0.5 mercoa-bg-mercoa-primary"}),jsx("input",{type:"checkbox",className:"mercoa-absolute mercoa-left-4 mercoa-top-1/2 -mercoa-mt-2 mercoa-h-4 mercoa-w-4 mercoa-rounded mercoa-border-gray-300 mercoa-text-mercoa-primary-text focus:mercoa-ring-mercoa-primary",value:tn.id,checked:Br.includes(tn),onChange:Fr=>Ar(Fr.target.checked?[...Br,tn]:Br.filter(Yr=>Yr!==tn))})]}),jsx("td",{className:classNames$1("mercoa-whitespace-nowrap mercoa-py-3 mercoa-pl-4 mercoa-pr-3 mercoa-text-sm mercoa-font-medium mercoa-text-gray-900 sm:mercoa-pl-3",Br.includes(tn)?"mercoa-text-mercoa-primary-text":"mercoa-text-gray-900"),onClick:()=>{te&&te(tn)},children:(Nr=tn.vendor)==null?void 0:Nr.name}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-3 mercoa-text-sm mercoa-text-gray-900 mercoa-hidden sm:mercoa-table-cell",onClick:()=>{te&&te(tn)},children:tn.invoiceNumber}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-3 mercoa-text-sm mercoa-text-gray-900",onClick:()=>{te&&te(tn)},children:dayjs$1(tn.dueDate).format("MMM DD, YYYY")}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-3 mercoa-text-sm mercoa-text-gray-900",onClick:()=>{te&&te(tn)},children:accounting.formatMoney(tn.amount??"",currencyCodeToSymbol(tn.currency))}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-3 mercoa-text-sm mercoa-hidden lg:mercoa-table-cell",onClick:()=>{te&&te(tn)},children:jsx(InvoiceStatusPill,{invoice:tn})})]},tn.id)})})]}),jsx(TableNavigation,{data:nr,page:Er,setPage:br,hasMore:lr,startingAfter:mr,setStartingAfter:yr,count:fr,resultsPerPage:Mr,setResultsPerPage:Sr})]})})})})]}),jsx("div",{className:"mercoa-mt-10 sm:mercoa-flex sm:mercoa-items-center",children:jsxs("div",{className:"sm:mercoa-flex-auto",children:[jsx("h1",{className:"mercoa-text-base mercoa-font-semibold mercoa-leading-6 mercoa-text-gray-900",children:"All invoices"}),jsx("p",{className:"mercoa-mt-2 mercoa-text-sm mercoa-text-gray-700",children:"A list of all invoices that require review from an assigned approver"})]})})]}):jsx(LoadingSpinner,{})})}):jsx(Skeleton,{rows:10}):jsx(Fragment,{})}function SchedulePaymentModal({show:ee,closeModal:te,setDate:ce}){return jsxs(_t$1,{as:"div",open:ee,onClose:te,className:"mercoa-relative mercoa-z-10",children:[jsx("div",{className:"mercoa-fixed mercoa-inset-0 mercoa-bg-black/30","aria-hidden":"true"}),jsx("div",{className:"mercoa-fixed mercoa-inset-0 mercoa-overflow-y-auto",children:jsx("div",{className:"mercoa-flex mercoa-min-h-full mercoa-items-end mercoa-justify-center mercoa-p-4 mercoa-text-center sm:mercoa-items-center sm:mercoa-p-0",children:jsx(DatePickerPanel,{closeModal:te,setDate:ce})})})]})}function DatePickerPanel({closeModal:ee,setDate:te}){const[ce,re]=React$1.useState();return jsxs(_t$1.Panel,{className:"mercoa-relative mercoa-transform mercoa-rounded-lg mercoa-bg-white mercoa-px-4 mercoa-pb-4 mercoa-pt-5 mercoa-text-left mercoa-shadow-xl mercoa-transition-all sm:mercoa-my-8 sm:mercoa-w-full sm:mercoa-max-w-sm sm:mercoa-p-6",children:[jsx("div",{children:jsxs("div",{className:"mercoa-mt-3 mercoa-text-center sm:mercoa-mt-5",children:[jsx(_t$1.Title,{as:"h3",className:"mercoa-text-base mercoa-font-semibold mercoa-leading-6 mercoa-text-gray-900",children:"When should these payments be scheduled?"}),jsx("div",{className:"mercoa-mt-2",children:jsx(er,{className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 focus:mercoa-border-indigo-500 focus:mercoa-ring-indigo-500 sm:mercoa-text-sm",placeholderText:"Select deduction date",onChange:nr=>re(nr),selected:ce,minDate:dayjs$1().add(1,"day").toDate(),filterDate:isWeekday})})]})}),jsx("div",{className:"mercoa-mt-5 sm:mercoa-mt-6",children:jsx(MercoaButton,{type:"button",className:"mercoa-inline-flex mercoa-w-full mercoa-justify-center ",isEmphasized:!0,onClick:()=>{ee(),console.log(ce),te(ce)},disabled:!ce,children:"Schedule Payments"})})]})}function InvoiceInboxTable({status:ee,search:te,onClick:ce}){const re=useMercoaSession(),[nr,or]=React$1.useState(),[ar,ir]=React$1.useState(javascript.Mercoa.InvoiceOrderByField.CreatedAt),[sr,cr]=React$1.useState(javascript.Mercoa.OrderDirection.Asc),[lr,ur]=React$1.useState(!0),[fr,hr]=React$1.useState(0),[pr,dr]=React$1.useState(!1),[mr,yr]=React$1.useState([]),[Mr,Sr]=React$1.useState(20),[Er,br]=React$1.useState(1),_r=React$1.useRef(null),[xr,jr]=React$1.useState(!1),[wr,Ir]=React$1.useState(!1),[Br,Ar]=React$1.useState([]),[Ur,Lr]=React$1.useState(!1);React$1.useLayoutEffect(()=>{const Fr=Br.length>0&&Br.length<(nr?nr.length:0);jr(Br.length===(nr?nr.length:0)),Ir(Fr),_r.current&&(_r.current.indeterminate=Fr)},[Br,nr]);function Zr(){nr&&(Ar(xr||wr?[]:nr),jr(!xr&&!wr),Ir(!1))}const nn=()=>{Lr(!0)},rn=()=>{Lr(!1)};async function tn(Fr){var vr;if(!re.token||!((vr=re.entity)!=null&&vr.id))return;function Yr(Or){var $r,Rr,kr,Cr,qr;if(!Or.vendor)return!1;const Tr=Or.vendor;let Pr=!!Or.amount&&!!Or.dueDate&&!!Or.currency&&!!Or.vendorId&&!!Or.paymentSourceId&&!!Tr.name;return(kr=(Rr=($r=re.iframeOptions)==null?void 0:$r.options)==null?void 0:Rr.vendors)!=null&&kr.disableCreation||(Pr=Pr&&!!Tr.email&&!!(Tr.accountType===javascript.Mercoa.AccountType.Individual||Tr.accountType===javascript.Mercoa.AccountType.Business&&((Cr=Tr.profile.business)!=null&&Cr.website||(qr=Tr.profile.business)!=null&&qr.description))),Pr&&Or.status===javascript.Mercoa.InvoiceStatus.Approved&&!!Or.paymentDestinationId}let Dr=!1;await Promise.all(Br.map(async Or=>{var Tr;try{if(Yr(Or)){const Pr={status:javascript.Mercoa.InvoiceStatus.Scheduled,deductionDate:Fr};await((Tr=re.client)==null?void 0:Tr.invoice.update(Or.id,Pr)),Dr=!0}else console.error("Invoice does not have all the information needed to schedule payment"),console.log("Invalid invoice:",{invoice:Or})}catch(Pr){console.error("Error updating invoice: ",Pr),console.log("Errored invoice: ",{invoice:Or})}})),Dr?Q$1.success("Payment Scheduled"):Q$1.error("Error scheduling payment"),re.refresh()}async function Nr(){var vr;if(!re.token||!((vr=re.entity)!=null&&vr.id))return;let Fr="",Yr=[];Dr();async function Dr(){var Tr,Pr;if(!re.token||!((Tr=re.entity)!=null&&Tr.id))return;const Or=await((Pr=re.client)==null?void 0:Pr.entity.invoice.find(re.entity.id,{status:ee,limit:100,startingAfter:Fr,excludeReceivables:!0}));if(Or)if(Or.data.length>0)Fr=Or.data[Or.data.length-1].id,Yr=[...Yr,...Or.data],await Dr();else{const gr=Papa.unparse(Yr.map(Cr=>{var qr,on,sn,yn,jn,wn;return{"Invoice ID":Cr.id,"Invoice Number":Cr.invoiceNumber,Status:Cr.status,Amount:Cr.amount,Currency:Cr.currency,Note:Cr.noteToSelf,"Payer ID":(qr=Cr.payer)==null?void 0:qr.id,"Payer Email":(on=Cr.payer)==null?void 0:on.email,"Payer Name":(sn=Cr.payer)==null?void 0:sn.name,"Vendor ID":(yn=Cr.vendor)==null?void 0:yn.id,"Vendor Email":(jn=Cr.vendor)==null?void 0:jn.email,"Vendor Name":(wn=Cr.vendor)==null?void 0:wn.name,Metadata:JSON.stringify(Cr.metadata),"Due Date":dayjs$1(Cr.dueDate),"Deduction Date":dayjs$1(Cr.deductionDate),"Processed At":dayjs$1(Cr.processedAt),"Created At":dayjs$1(Cr.createdAt),"Updated At":dayjs$1(Cr.updatedAt)}})),$r=new Blob([gr],{type:"text/csv"}),Rr=window.URL.createObjectURL($r),kr=document.createElement("a");kr.setAttribute("mercoa-hidden",""),kr.setAttribute("href",Rr),kr.setAttribute("download",`mercoa-invoice-export-${dayjs$1().format("YYYY-MM-DD")}.csv`),document.body.appendChild(kr),kr.click(),document.body.removeChild(kr)}}}return React$1.useEffect(()=>{var Fr,Yr;!re.token||!((Fr=re.entity)!=null&&Fr.id)||(Ar([]),dr(!1),(Yr=re.client)==null||Yr.entity.invoice.find(re.entity.id,{status:ee,search:te,orderBy:ar,orderDirection:sr,limit:Mr,startingAfter:mr[mr.length-1],excludeReceivables:!0}).then(Dr=>{Dr&&(ur(Dr.hasMore),hr(Dr.count),or(Dr.data),dr(!0))}))},[re.token,re.entity,re.refreshId,ee,te,ar,sr,mr,Mr]),React$1.useEffect(()=>{dr(!1),yr([]),br(1),hr(0)},[ee]),pr?jsx(Fragment,{children:re.entity&&nr?jsxs(Fragment,{children:[jsx("div",{className:"mercoa-min-h-[600px]",children:jsxs("div",{className:"mercoa-relative",children:[ee.some(Fr=>Fr===javascript.Mercoa.InvoiceStatus.Approved)&&Br.length>0&&jsx("div",{className:"mercoa-absolute mercoa-left-14 mercoa-top-0 mercoa-flex mercoa-h-12 mercoa-items-center mercoa-space-x-3 mercoa-bg-white sm:mercoa-left-12",children:jsx("button",{type:"button",className:"mercoa-inline-flex mercoa-items-center mercoa-rounded mercoa-bg-white mercoa-px-2 mercoa-py-1 mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 mercoa-shadow-sm mercoa-ring-1 mercoa-ring-inset mercoa-ring-gray-300 hover:mercoa-bg-gray-50 disabled:mercoa-cursor-not-allowed disabled:mercoa-opacity-30 disabled:hover:mercoa-bg-white",onClick:nn,children:"Schedule Payment"})}),jsxs("table",{className:"mercoa-min-w-full table-mercoa-fixed mercoa-divide-y mercoa-divide-gray-300 mercoa-mt-5",children:[jsx("thead",{children:jsxs("tr",{children:[ee.some(Fr=>Fr===javascript.Mercoa.InvoiceStatus.Approved)&&jsx("th",{scope:"col",className:"mercoa-relative mercoa-px-7 sm:mercoa-w-12 sm:mercoa-px-6",children:jsx("input",{type:"checkbox",className:"mercoa-absolute mercoa-left-4 mercoa-top-1/2 -mercoa-mt-2 mercoa-h-4 mercoa-w-4 mercoa-rounded mercoa-border-gray-300 mercoa-text-mercoa-primary-text focus:mercoa-ring-mercoa-primary",ref:_r,checked:xr,onChange:Zr})}),jsx("th",{scope:"col",className:"mercoa-min-w-[12rem] mercoa-py-3.5 mercoa-pl-4 mercoa-pr-3 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 sm:mercoa-pl-3",children:jsx(TableOrderHeader,{title:"Vendor",setOrder:Fr=>{ir(javascript.Mercoa.InvoiceOrderByField.VendorName),cr(Fr)},isSelected:ar===javascript.Mercoa.InvoiceOrderByField.VendorName,orderDirection:sr})}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 mercoa-hidden sm:mercoa-table-cell",children:jsx(TableOrderHeader,{title:"Invoice Number",setOrder:Fr=>{ir(javascript.Mercoa.InvoiceOrderByField.InvoiceNumber),cr(Fr)},isSelected:ar===javascript.Mercoa.InvoiceOrderByField.InvoiceNumber,orderDirection:sr})}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900",children:jsx(TableOrderHeader,{title:"Due Date",setOrder:Fr=>{ir(javascript.Mercoa.InvoiceOrderByField.DueDate),cr(Fr)},isSelected:ar===javascript.Mercoa.InvoiceOrderByField.DueDate,orderDirection:sr})}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900",children:jsx(TableOrderHeader,{title:"Amount",setOrder:Fr=>{ir(javascript.Mercoa.InvoiceOrderByField.Amount),cr(Fr)},isSelected:ar===javascript.Mercoa.InvoiceOrderByField.Amount,orderDirection:sr})}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 mercoa-pl-6 mercoa-hidden lg:mercoa-table-cell",children:"Status"}),ee.some(Fr=>Fr===javascript.Mercoa.InvoiceStatus.Scheduled||Fr===javascript.Mercoa.InvoiceStatus.Pending||Fr===javascript.Mercoa.InvoiceStatus.Paid)&&jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 group mercoa-inline-flex mercoa-items-center",children:"Deduction Date"})]})}),jsx("tbody",{className:"mercoa-divide-y mercoa-divide-gray-200 mercoa-bg-white",children:nr.map(Fr=>{var Yr;return jsxs("tr",{className:classNames$1("mercoa-cursor-pointer hover:mercoa-bg-gray-100",Br.includes(Fr)?"mercoa-bg-gray-50":void 0),children:[ee.some(Dr=>Dr===javascript.Mercoa.InvoiceStatus.Approved)&&jsxs("td",{className:"mercoa-relative mercoa-px-7 sm:mercoa-w-12 sm:mercoa-px-6",children:[Br.includes(Fr)&&jsx("div",{className:"mercoa-absolute mercoa-inset-y-0 mercoa-left-0 mercoa-w-0.5 mercoa-bg-mercoa-primary"}),jsx("input",{type:"checkbox",className:"mercoa-absolute mercoa-left-4 mercoa-top-1/2 -mercoa-mt-2 mercoa-h-4 mercoa-w-4 mercoa-rounded mercoa-border-gray-300 mercoa-text-mercoa-primary-text focus:mercoa-ring-mercoa-primary",value:Fr.id,checked:Br.includes(Fr),onChange:Dr=>Ar(Dr.target.checked?[...Br,Fr]:Br.filter(vr=>vr!==Fr))})]}),jsx("td",{className:classNames$1("mercoa-whitespace-nowrap mercoa-py-3 mercoa-pl-4 mercoa-pr-3 mercoa-text-sm mercoa-font-medium mercoa-text-gray-900 sm:mercoa-pl-3",Br.includes(Fr)?"mercoa-text-mercoa-primary-text":"mercoa-text-gray-900"),onClick:()=>{ce&&ce(Fr)},children:(Yr=Fr.vendor)==null?void 0:Yr.name}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-3 mercoa-text-sm mercoa-text-gray-900 mercoa-hidden sm:mercoa-table-cell",onClick:()=>{ce&&ce(Fr)},children:Fr.invoiceNumber}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-3 mercoa-text-sm mercoa-text-gray-900",onClick:()=>{ce&&ce(Fr)},children:dayjs$1(Fr.dueDate).format("MMM DD, YYYY")}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-3 mercoa-text-sm mercoa-text-gray-900",onClick:()=>{ce&&ce(Fr)},children:accounting.formatMoney(Fr.amount??"",currencyCodeToSymbol(Fr.currency))}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-3 mercoa-text-sm mercoa-hidden lg:mercoa-table-cell",onClick:()=>{ce&&ce(Fr)},children:jsx(InvoiceStatusPill,{invoice:Fr})}),ee.some(Dr=>Dr===javascript.Mercoa.InvoiceStatus.Scheduled||Dr===javascript.Mercoa.InvoiceStatus.Pending||Dr===javascript.Mercoa.InvoiceStatus.Paid)&&Fr.deductionDate&&jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-3 mercoa-text-sm mercoa-hidden lg:mercoa-table-cell",onClick:()=>{ce&&ce(Fr)},children:dayjs$1(Fr.deductionDate).format("MMM DD, YYYY")})]},Fr.id)})})]})]})}),jsx(TableNavigation,{data:nr,page:Er,setPage:br,hasMore:lr,startingAfter:mr,setStartingAfter:yr,count:fr,resultsPerPage:Mr,setResultsPerPage:Sr,downloadAll:Nr}),jsx(SchedulePaymentModal,{show:Ur,closeModal:rn,setDate:tn})]}):jsx(LoadingSpinner,{})}):jsx("div",{className:"mercoa-mt-7",children:jsx(Skeleton,{rows:10})})}function InvoiceStatusPill({invoice:ee}){let te="mercoa-bg-gray-100",ce="mercoa-text-black",re="",nr="";return ee.failureType===javascript.Mercoa.InvoiceFailureType.InsufficientFunds&&(nr=" - Insufficient Funds"),ee.status===javascript.Mercoa.InvoiceStatus.Draft?!ee.vendor||!ee.amount||!ee.dueDate?(te="mercoa-bg-yellow-100",ce="mercoa-text-black",re="Draft Incomplete"):(te="mercoa-bg-green-100",ce="mercoa-text-green-800",re="Draft Ready"):ee.status===javascript.Mercoa.InvoiceStatus.New?!ee.paymentSourceId||!ee.vendor||!ee.amount||!ee.dueDate?(te="mercoa-bg-yellow-100",ce="mercoa-text-gray-800",re="Incomplete"):(te="mercoa-bg-green-100",ce="mercoa-text-green-800",re="Ready for Review"):ee.status===javascript.Mercoa.InvoiceStatus.Approved?!ee.paymentSourceId||!ee.paymentDestinationId||!ee.vendor||!ee.amount||!ee.dueDate?(te="mercoa-bg-yellow-100",ce="mercoa-text-black",re="Incomplete"):(te="mercoa-bg-green-100",ce="mercoa-text-green-800",re="Ready for Payment"):ee.status===javascript.Mercoa.InvoiceStatus.Scheduled?!ee.paymentSourceId||!ee.paymentDestinationId||!ee.vendor||!ee.amount||!ee.dueDate?(te="mercoa-bg-yellow-100",ce="mercoa-text-black",re="Incomplete"):(te="mercoa-bg-green-100",ce="mercoa-text-green-800",re="Payment Scheduled"):ee.status===javascript.Mercoa.InvoiceStatus.Pending?(te="mercoa-bg-yellow-100",ce="mercoa-text-black",re="Payment Processing"):ee.status===javascript.Mercoa.InvoiceStatus.Paid?(te="mercoa-bg-green-100",ce="mercoa-text-green-800",re="Paid"):ee.status===javascript.Mercoa.InvoiceStatus.Canceled?(te="mercoa-bg-red-100",ce="mercoa-text-red-800",re="Canceled"):ee.status===javascript.Mercoa.InvoiceStatus.Archived?(te="mercoa-bg-gray-100",ce="mercoa-text-black",re="Archived"):ee.status===javascript.Mercoa.InvoiceStatus.Refused?(te="mercoa-bg-red-100",ce="mercoa-text-red-800",re="Refused"):ee.status===javascript.Mercoa.InvoiceStatus.Failed&&(te="mercoa-bg-red-100",ce="mercoa-text-red-800",re="Failed "+nr),re?jsx("p",{className:`mercoa-inline-flex mercoa-items-center mercoa-whitespace-nowrap mercoa-rounded-full mercoa-px-3 mercoa-py-0.5 mercoa-text-xs mercoa-font-medium ${te} ${ce} md:mercoa-ml-2`,children:re}):jsx(Fragment,{})}function InvoiceInbox({statuses:ee,selectedStatus:te,onSelectInvoice:ce,onTabChange:re,children:nr}){const or=useMercoaSession(),[ar,ir]=React$1.useState(te??javascript.Mercoa.InvoiceStatus.Draft),[sr,cr]=React$1.useState(""),[lr,ur]=React$1.useState(),[fr,hr]=React$1.useState(ee??[javascript.Mercoa.InvoiceStatus.Draft,javascript.Mercoa.InvoiceStatus.New,javascript.Mercoa.InvoiceStatus.Approved,javascript.Mercoa.InvoiceStatus.Scheduled,javascript.Mercoa.InvoiceStatus.Pending,javascript.Mercoa.InvoiceStatus.Paid,javascript.Mercoa.InvoiceStatus.Canceled,javascript.Mercoa.InvoiceStatus.Failed]);React$1.useEffect(()=>{var Sr,Er;!or.token||!((Sr=or.entity)!=null&&Sr.id)||(Er=or.client)==null||Er.entity.approvalPolicy.getAll(or.entity.id).then(br=>ur(br)).catch(()=>ur(void 0))},[or.token,or.entity,or.refreshId]),React$1.useEffect(()=>{re&&re(ar)},[ar]),React$1.useEffect(()=>{Array.isArray(lr)&&(console.log(lr),ee?hr(ee):(!lr||(lr==null?void 0:lr.length)<1)&&hr(fr.filter(Sr=>Sr!==javascript.Mercoa.InvoiceStatus.New)))},[ee,lr]);const pr={DRAFT:"Inbox",NEW:"Ready for Review",APPROVED:lr!=null&&lr.length?"Approved":"Ready for Payment",SCHEDULED:"Payment Scheduled",PENDING:"Payment Processing",FAILED:"Payment Failed",PAID:"Paid",CANCELED:"Canceled",REFUSED:"Refused",ARCHIVED:"Archived"},[dr,mr]=React$1.useState();function yr(Sr){return Sr==null?void 0:Sr.reduce((Er,br)=>(Er+=br.totalCount,Er),0)}function Mr(Sr,Er){return!Sr||Sr.length<1?accounting.formatMoney(0,currencyCodeToSymbol("USD")):Sr.length<2?accounting.formatMoney(Sr[0][Er]??0??"",currencyCodeToSymbol(Sr[0].currency)):jsx("div",{children:Sr.map(br=>jsxs("p",{children:[jsx("span",{children:accounting.formatMoney(br[Er]??0??"",currencyCodeToSymbol(br.currency))}),jsxs("span",{className:"mercoa-text-gray-500 mercoa-text-xs",children:[" ",br.currency]})]},br.currency))})}return React$1.useEffect(()=>{var Er;if(!or.token||!((Er=or.entity)!=null&&Er.id))return;async function Sr(){const br=(await Promise.all((fr??[]).map(async xr=>{var wr,Ir;if(!or.token||!((wr=or.entity)!=null&&wr.id))return;const jr=await((Ir=or.client)==null?void 0:Ir.entity.invoice.metrics(or.entity.id,{search:sr,status:xr,excludeReceivables:!0}));return[xr,jr]}))).filter(xr=>xr),_r=Object.fromEntries(br);mr(_r)}Sr()},[sr,ee,or.client,or.entity,or.refreshId]),Object.keys(dr??{}).length<1?jsx(LoadingSpinner,{}):jsxs("div",{className:"mercoa-mt-8",children:[jsxs("div",{className:"mercoa-grid mercoa-items-center mercoa-grid-cols-3",children:[jsx("div",{className:"mercoa-hidden md:mercoa-block md:mercoa-col-span-2"}),jsx("div",{className:"mercoa-mt-2 mercoa-flex mercoa-w-full mercoa-rounded-md mercoa-shadow-sm mercoa-mr-2 mercoa-col-span-3 md:mercoa-col-span-1",children:jsx(DebouncedSearch,{placeholder:"Search Vendors",onSettle:cr})})]}),jsxs("div",{className:"md:mercoa-hidden mercoa-mt-2",children:[jsx("label",{htmlFor:"tabs",className:"mercoa-sr-only",children:"Select a tab"}),jsx("select",{id:"tabs",name:"tabs",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-py-1 mercoa-pl-3 mercoa-pr-10 mercoa-text-base focus:mercoa-border-mercoa-primary focus:mercoa-outline-none focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm",defaultValue:ar,onChange:Sr=>{ir(Sr.target.value)},children:fr.map(Sr=>jsx("option",{value:Sr,children:pr[Sr]},Sr))})]}),jsx("div",{className:"mercoa-hidden md:mercoa-block sm:mercoa-border-b sm:mercoa-border-gray-200",children:jsx("nav",{className:"-mercoa-mb-px mercoa-block sm:mercoa-flex sm:mercoa-space-x-6 mercoa-overflow-auto","aria-label":"Tabs",children:fr.map(Sr=>jsxs("a",{onClick:()=>{ir(Sr)},href:"#",className:`${Sr==ar?"mercoa-text-mercoa-primary sm:mercoa-border-mercoa-primary":"mercoa-border-transparent mercoa-text-gray-500 hover:mercoa-border-gray-300 hover:mercoa-text-gray-700"} mercoa-mr-2 mercoa-whitespace-nowrap mercoa-py-4 mercoa-px-1 mercoa-text-sm mercoa-font-medium sm:mercoa-mr-0 sm:mercoa-border-b-2`,"aria-current":pr[Sr]==ar?"page":void 0,children:[pr[Sr]," ",jsxs("span",{className:`${Sr==ar?"mercoa-bg-mercoa-primary mercoa-text-mercoa-primary-text-invert":"mercoa-bg-gray-100 mercoa-text-gray-800"} mercoa-inline-flex mercoa-items-center mercoa-rounded-full mercoa-px-2.5 mercoa-py-0.5 mercoa-text-xs mercoa-font-medium`,children:[" ",yr((dr==null?void 0:dr[Sr])??[])]})]},Sr))})}),jsxs("div",{className:"mercoa-grid mercoa-grid-cols-3 mercoa-space-x-3 mercoa-mt-2",children:[jsx(StatCard,{size:"sm",title:`Total ${pr[ar]} Invoices`,value:yr((dr==null?void 0:dr[ar])??[])}),jsx(StatCard,{size:"sm",title:`Total ${pr[ar]} Amount`,value:Mr((dr==null?void 0:dr[ar])??[],"totalAmount")}),jsx(StatCard,{size:"sm",title:`Average ${pr[ar]} Amount`,value:Mr((dr==null?void 0:dr[ar])??[],"averageAmount")})]}),ar===javascript.Mercoa.InvoiceStatus.New&&jsx(ApprovalsTable,{search:sr,onClick:ce}),jsx(InvoiceInboxTable,{status:[ar],search:sr,onClick:ce})]})}var relativeTime$1={exports:{}};(function(ee,te){(function(ce,re){ee.exports=re()})(commonjsGlobal$1,function(){return function(ce,re,nr){ce=ce||{};var or=re.prototype,ar={future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"};function ir(cr,lr,ur,fr){return or.fromToBase(cr,lr,ur,fr)}nr.en.relativeTime=ar,or.fromToBase=function(cr,lr,ur,fr,hr){for(var pr,dr,mr,yr=ur.$locale().relativeTime||ar,Mr=ce.thresholds||[{l:"s",r:44,d:"second"},{l:"m",r:89},{l:"mm",r:44,d:"minute"},{l:"h",r:89},{l:"hh",r:21,d:"hour"},{l:"d",r:35},{l:"dd",r:25,d:"day"},{l:"M",r:45},{l:"MM",r:10,d:"month"},{l:"y",r:17},{l:"yy",d:"year"}],Sr=Mr.length,Er=0;Er<Sr;Er+=1){var br=Mr[Er];br.d&&(pr=fr?nr(cr).diff(ur,br.d,!0):ur.diff(cr,br.d,!0));var _r=(ce.rounding||Math.round)(Math.abs(pr));if(mr=pr>0,_r<=br.r||!br.r){_r<=1&&Er>0&&(br=Mr[Er-1]);var xr=yr[br.l];hr&&(_r=hr(""+_r)),dr=typeof xr=="string"?xr.replace("%d",_r):xr(_r,lr,br.l,mr);break}}if(lr)return dr;var jr=mr?yr.future:yr.past;return typeof jr=="function"?jr(dr):jr.replace("%s",dr)},or.to=function(cr,lr){return ir(cr,lr,this,!0)},or.from=function(cr,lr){return ir(cr,lr,this)};var sr=function(cr){return cr.$u?nr.utc():nr()};or.toNow=function(cr){return this.to(sr(this),cr)},or.fromNow=function(cr){return this.from(sr(this),cr)}}})})(relativeTime$1);var relativeTimeExports=relativeTime$1.exports;const relativeTime=getDefaultExportFromCjs(relativeTimeExports),URL$1="https://js.moov.io/v1",URL_REGEX=/^https:\/\/js\.moov\.io\/v1\/?(\?.*)?$/,EXISTING_SCRIPT_MESSAGE="loadMoov.setLoadParameters was called but an existing Moov.js script already exists in the document; existing script parameters will be used",findScript=()=>{const ee=document.querySelectorAll(`script[src^="${URL$1}"]`);for(let te=0;te<ee.length;te++){const ce=ee[te];if(URL_REGEX.test(ce.src))return ce}return null},injectScript=()=>{const ee=document.createElement("script");ee.src=URL$1;const te=document.head||document.body;if(!te)throw new Error("Expected document.body not to be null. Moov.js requires a <body> element.");return te.appendChild(ee),ee};let moovPromise$1=null;const loadScript=()=>(moovPromise$1!==null||(moovPromise$1=new Promise((ee,te)=>{if(typeof window>"u"){ee(null);return}if(window.Moov&&console.warn(EXISTING_SCRIPT_MESSAGE),window.Moov){ee(window.Moov);return}try{let ce=findScript();ce?console.warn(EXISTING_SCRIPT_MESSAGE):ce||(ce=injectScript()),ce.addEventListener("load",()=>{window.Moov?ee(window.Moov):te(new Error("Moov.js not available"))}),ce.addEventListener("error",()=>{te(new Error("Failed to load Moov.js"))})}catch(ce){te(ce);return}})),moovPromise$1),initMoov=(ee,te)=>ee===null?null:ee.apply(void 0,te),moovPromise=Promise.resolve().then(()=>loadScript());let loadCalled=!1;moovPromise.catch(ee=>{loadCalled||console.warn(ee)});function loadMoov(...ee){if(!window)throw new Error("@moovio/moov-js is intended for browser use only. For a server-side solution, try @moovio/node.");return loadCalled=!0,moovPromise.then(te=>initMoov(te,ee))}class InvalidTokenError extends Error{}InvalidTokenError.prototype.name="InvalidTokenError";function b64DecodeUnicode(ee){return decodeURIComponent(atob(ee).replace(/(.)/g,(te,ce)=>{let re=ce.charCodeAt(0).toString(16).toUpperCase();return re.length<2&&(re="0"+re),"%"+re}))}function base64UrlDecode(ee){let te=ee.replace(/-/g,"+").replace(/_/g,"/");switch(te.length%4){case 0:break;case 2:te+="==";break;case 3:te+="=";break;default:throw new Error("base64 string is not of the correct length")}try{return b64DecodeUnicode(te)}catch{return atob(te)}}function jwtDecode(ee,te){if(typeof ee!="string")throw new InvalidTokenError("Invalid token specified: must be a string");te||(te={});const ce=te.header===!0?0:1,re=ee.split(".")[ce];if(typeof re!="string")throw new InvalidTokenError(`Invalid token specified: missing part #${ce+1}`);let nr;try{nr=base64UrlDecode(re)}catch(or){throw new InvalidTokenError(`Invalid token specified: invalid base64 for part #${ce+1} (${or.message})`)}try{return JSON.parse(nr)}catch(or){throw new InvalidTokenError(`Invalid token specified: invalid json for part #${ce+1} (${or.message})`)}}const sessionContext=React$1.createContext({token:"",entityId:"",entity:void 0,user:void 0,users:[],selectedInvoice:void 0,setSelectedInvoice:()=>{},client:void 0,refresh:()=>{},refreshId:0,organization:void 0,moov:void 0,moovToken:void 0,moovAccountId:void 0,iframeOptions:void 0,setIframeOptions:()=>{},getNewToken:ee=>{},googleMapsApiKey:void 0});function MercoaSession({children:ee,entityId:te,entityUserId:ce,token:re,endpoint:nr,isAdmin:or,googleMapsApiKey:ar}){return jsx(sessionContext.Provider,{value:useProvideSession({token:re,entityId:te,entityUserId:ce,endpoint:nr,isAdmin:or,googleMapsApiKey:ar}),children:ee||jsx(EntityPortal,{token:re})})}const useMercoaSession=()=>React$1.useContext(sessionContext);function useProvideSession({token:ee,entityId:te,entityUserId:ce,endpoint:re,isAdmin:nr,googleMapsApiKey:or}){var Zr;const[ar,ir]=React$1.useState(),[sr,cr]=React$1.useState(),[lr,ur]=React$1.useState([]),[fr,hr]=React$1.useState(),[pr,dr]=React$1.useState(),[mr,yr]=React$1.useState(0),[Mr,Sr]=React$1.useState(),[Er,br]=React$1.useState(),[_r,xr]=React$1.useState(),[jr,wr]=React$1.useState(ee),[Ir,Br]=React$1.useState(),Ar=React$1.useMemo(()=>new javascript.MercoaClient({environment:re??"https://api.mercoa.com",token:jr}),[jr]);async function Ur(){if(!ee)return;let nn=te;if(!nn)try{const{entityId:rn}=jwtDecode(String(ee));nn=rn}catch(rn){console.error(rn)}if(nn!=="undefined"&&(Ar.organization.get({paymentMethods:!0,emailProvider:!0,colorScheme:!0,payeeOnboardingOptions:!0,payorOnboardingOptions:!0,metadataSchema:!0}).then(rn=>{dr(rn)}),nn!=="all"&&nn)){Ar.entity.get(nn).then(tn=>{ir(tn),yr(Math.random())});let rn=ce;if(!rn)try{const{userId:tn}=jwtDecode(String(ee));rn=tn}catch(tn){console.error(tn)}rn&&Ar.entity.user.get(nn,rn).then(tn=>{cr(tn)}),Ar.entity.user.getAll(nn).then(tn=>{ur(tn)}),!Mr&&!nr&&Ar.entity.getToken(nn,{}).then(async tn=>{wr(tn);const{moov:Nr}=jwtDecode(String(tn));if(br(Nr.accountId),xr(Nr.token),!(!Nr||!Nr.token||Nr.token==="sandbox"))try{const Fr=await loadMoov(Nr.token);Fr&&Sr(Fr)}catch(Fr){console.error(Fr)}})}}async function Lr(nn){const rn=Ir||{options:{expiresIn:nn??"12hr"}};if(rn.options||(rn.options={}),rn.options.expiresIn=nn??"12hr",!(ar!=null&&ar.id))return;let tn="";sr!=null&&sr.id?tn=await Ar.entity.user.getToken(ar.id,sr.id,{...rn.options}):tn=await Ar.entity.getToken(ar.id,{...rn.options}),wr(tn)}return React$1.useEffect(()=>{if(!(pr!=null&&pr.colorScheme))return;const nn=(vr,Or)=>{vr=vr.replace(/^#/,""),vr.length===3&&(vr=vr[0]+vr[0]+vr[1]+vr[1]+vr[2]+vr[2]);let[Tr,Pr,gr]=vr.match(/.{2}/g);[Tr,Pr,gr]=[parseInt(Tr,16)+Or,parseInt(Pr,16)+Or,parseInt(gr,16)+Or],Tr=Math.max(Math.min(255,Tr),0).toString(16),Pr=Math.max(Math.min(255,Pr),0).toString(16),gr=Math.max(Math.min(255,gr),0).toString(16);const $r=(Tr.length<2?"0":"")+Tr,Rr=(Pr.length<2?"0":"")+Pr,kr=(gr.length<2?"0":"")+gr;return`#${$r}${Rr}${kr}`},rn=pr.colorScheme.logoBackgroundColor||"transparent",tn=pr.colorScheme.primaryColor||"#4f46e5",Nr=nn(tn,40),Fr=nn(tn,-40);let Yr=tn,Dr="#ffffff";tn==="#f8fafc"&&(Yr="#111827",Dr="#111827"),document.documentElement.style.setProperty("--mercoa-logo-background",rn),document.documentElement.style.setProperty("--mercoa-primary",tn),document.documentElement.style.setProperty("--mercoa-primary-light",Nr),document.documentElement.style.setProperty("--mercoa-primary-dark",Fr),document.documentElement.style.setProperty("--mercoa-primary-text",Yr),document.documentElement.style.setProperty("--mercoa-primary-text-invert",Dr)},[(Zr=pr==null?void 0:pr.colorScheme)==null?void 0:Zr.primaryColor]),React$1.useEffect(()=>{Ur()},[ee,te]),{refresh:Ur,refreshId:mr,token:ee,entityId:te??(ar==null?void 0:ar.id),entity:ar,user:sr,users:lr,selectedInvoice:fr,setSelectedInvoice:hr,client:Ar,organization:pr,moov:Mr,moovAccountId:Er,moovToken:_r,iframeOptions:Ir,setIframeOptions:Br,getNewToken:Lr,googleMapsApiKey:or}}dayjs$1.extend(relativeTime);function InvoiceComments({invoice:ee}){var fr;const te=useMercoaSession(),[ce,re]=React$1.useState((ee==null?void 0:ee.comments)??[]),{register:nr,handleSubmit:or,setValue:ar}=useForm({defaultValues:{type:"comment",text:""}});function ir({type:hr,text:pr}){var dr,mr,yr;if(!((dr=te.user)!=null&&dr.id)){Q$1.error("Please login as a user to comment");return}!te.token||!(ee!=null&&ee.id)||pr&&hr==="comment"&&((yr=te.client)==null||yr.invoice.comment.create(ee.id,{text:pr,userId:(mr=te.user)==null?void 0:mr.id}).then(Mr=>{Mr&&(console.log(Mr),re([...ce,Mr]),ar("text",""))}))}function sr(hr){let pr=jsx("div",{className:"mercoa-h-1.5 mercoa-w-1.5 mercoa-rounded-full mercoa-bg-gray-100 mercoa-ring-1 mercoa-ring-gray-300"});return hr.action==="APPROVE"?pr=jsx(CheckCircleIcon$1,{className:"mercoa-h-6 mercoa-w-6 mercoa-text-green-600","aria-hidden":"true"}):hr.action==="REJECT"&&(pr=jsx(XCircleIcon$1,{className:"mercoa-h-6 mercoa-w-6 mercoa-text-red-600","aria-hidden":"true"})),pr}const cr={APPROVE:"approved",REJECT:"rejected",NONE:"created"},lr=ce.filter(hr=>hr.text||hr.associatedApprovalAction),ur={id:(ee==null?void 0:ee.id)??"",createdAt:(ee==null?void 0:ee.createdAt)??"",user:(ee==null?void 0:ee.creatorUser)??{id:"",name:"Email"},text:"",associatedApprovalAction:{action:javascript.Mercoa.ApproverAction.None,userId:((fr=ee==null?void 0:ee.creatorUser)==null?void 0:fr.id)??""}};return jsxs(Fragment,{children:[jsx("ul",{role:"list",className:"mercoa-space-y-6 mercoa-ml-1",children:[ur,...lr].map((hr,pr)=>{var dr,mr;return jsxs("li",{className:"mercoa-relative mercoa-flex mercoa-gap-x-4",children:[jsx("div",{className:`${pr===lr.length?"mercoa-h-6":"-mercoa-bottom-6"} mercoa-absolute mercoa-left-0 mercoa-top-0 mercoa-flex mercoa-w-6 mercoa-justify-center`,children:jsx("div",{className:"mercoa-w-px mercoa-bg-gray-200"})}),hr.text&&jsxs(Fragment,{children:[jsx(UserIcon$1,{className:"mercoa-h-8 mercoa-w-8 mercoa-text-gray-300 mercoa-mt-3 mercoa-text-gray-300 mercoa-bg-gray-100 mercoa-rounded-full mercoa-p-1 -mercoa-ml-1"}),jsxs("div",{className:"mercoa-flex-auto mercoa-rounded-md mercoa-p-3 mercoa-ring-1 mercoa-ring-inset mercoa-ring-gray-200",children:[jsxs("div",{className:"mercoa-flex mercoa-justify-between mercoa-gap-x-4",children:[jsxs("div",{className:"mercoa-py-0.5 mercoa-text-xs mercoa-leading-5 mercoa-text-gray-500",children:[jsx("span",{className:"mercoa-font-medium mercoa-text-gray-900",children:(dr=hr.user)==null?void 0:dr.name})," commented"]}),jsx("time",{dateTime:dayjs$1(hr.createdAt).toISOString(),className:"mercoa-flex-none mercoa-py-0.5 mercoa-text-xs mercoa-leading-5 mercoa-text-gray-500",children:dayjs$1(hr.createdAt).fromNow()})]}),jsx("p",{className:"mercoa-text-sm mercoa-leading-6 mercoa-text-gray-500",children:hr.text})]})]}),hr.associatedApprovalAction&&jsxs(Fragment,{children:[jsx("div",{className:"mercoa-relative mercoa-flex mercoa-h-6 mercoa-w-6 mercoa-flex-none mercoa-items-center mercoa-justify-center mercoa-bg-white",children:sr(hr.associatedApprovalAction)}),jsxs("p",{className:"mercoa-flex-auto mercoa-py-0.5 mercoa-text-xs mercoa-leading-5 mercoa-text-gray-500",children:[jsx("span",{className:"mercoa-font-medium mercoa-text-gray-900",children:(mr=hr.user)==null?void 0:mr.name})," ",cr[hr.associatedApprovalAction.action]," the invoice."]}),jsx("time",{dateTime:dayjs$1(hr.createdAt).toISOString(),className:"mercoa-flex-none mercoa-py-0.5 mercoa-text-xs mercoa-leading-5 mercoa-text-gray-500",children:dayjs$1(hr.createdAt).fromNow()})]})]},hr.id)})}),jsx("div",{className:"mercoa-mt-6 mercoa-flex mercoa-gap-x-3",children:jsxs("form",{onSubmit:or(ir),className:"mercoa-relative mercoa-flex-auto",children:[jsxs("div",{className:"mercoa-overflow-hidden mercoa-rounded-lg mercoa-pb-12 mercoa-shadow-sm mercoa-ring-1 mercoa-ring-inset mercoa-ring-gray-300 focus-within:mercoa-ring-2 focus-within:mercoa-ring-indigo-600",children:[jsx("label",{htmlFor:"comment",className:"mercoa-sr-only",children:"Add your comment"}),jsx("textarea",{rows:2,...nr("text"),className:"mercoa-block mercoa-w-full mercoa-resize-none mercoa-border-0 mercoa-bg-transparent mercoa-py-1.5 mercoa-text-gray-900 placeholder:mercoa-text-gray-400 focus:mercoa-ring-0 sm:mercoa-text-sm sm:mercoa-leading-6",placeholder:"Add your comment..."})]}),jsxs("div",{className:"mercoa-absolute mercoa-inset-x-0 mercoa-bottom-0 mercoa-flex mercoa-justify-between mercoa-py-2 mercoa-pl-3 mercoa-pr-2",children:[jsx("div",{}),jsx("button",{type:"submit",className:"mercoa-rounded-md mercoa-bg-white mercoa-px-2.5 mercoa-py-1.5 mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 mercoa-shadow-sm mercoa-ring-1 mercoa-ring-inset mercoa-ring-gray-300 hover:mercoa-bg-gray-50",children:"Comment"})]})]})})]})}const dJSON=require("dirty-json");dayjs$1.extend(minMax);function classNames(...ee){return ee.filter(Boolean).join(" ")}function InvoiceDetails({invoiceId:ee,invoice:te,onRedirect:ce,addPaymentMethodRedirect:re,children:nr}){var Br;const or=useMercoaSession(),[ar,ir]=React$1.useState(),[sr,cr]=React$1.useState(),[lr,ur]=React$1.useState(),[fr,hr]=React$1.useState(!1),[pr,dr]=React$1.useState(te),[mr,yr]=React$1.useState(),[Mr,Sr]=React$1.useState(typeof window<"u"?window.innerHeight-70:0),[Er,br]=React$1.useState(!1);async function _r(Ar){var Lr,Zr;if(!or.token||!((Lr=or.entity)!=null&&Lr.id))return;const Ur=await((Zr=or.client)==null?void 0:Zr.invoice.get(Ar));Ur&&dr(Ur)}async function xr(Ar){var Lr,Zr;if(!or.token||!((Lr=or.entity)!=null&&Lr.id))return;const Ur=await((Zr=or.client)==null?void 0:Zr.ocr.getAsyncOcr(Ar));Ur&&Ur.status===javascript.Mercoa.OcrJobStatus.Success?(cr(Ur.data),hr(!1)):Ur&&Ur.status===javascript.Mercoa.OcrJobStatus.Failed?(Q$1.error("OCR failed"),hr(!1)):setTimeout(()=>xr(Ar),5e3)}async function jr(Ar,Ur){var Lr;ir({fileReaderObj:Ar,mimeType:Ur.type}),ur(Ar),hr(!0);try{const Zr=await((Lr=or.client)==null?void 0:Lr.ocr.runAsyncOcr({entityId:or.entityId,image:Ar,mimeType:Ur.type}));Zr?xr(Zr==null?void 0:Zr.jobId):(Q$1.error("OCR failed"),hr(!1))}catch(Zr){console.log(Zr),Q$1.error("OCR failed"),hr(!1)}}React$1.useEffect(()=>{var Ar;!or.token||!((Ar=or.entity)!=null&&Ar.id)||!te&&ee&&_r(ee)},[te,ee,or.token,(Br=or.entity)==null?void 0:Br.id]);function wr(){Sr(window.innerHeight-70)}React$1.useEffect(()=>(wr(),window.addEventListener("resize",wr,!1),()=>{window.removeEventListener("resize",wr)}),[]),React$1.useEffect(()=>{var Ar;pr&&pr.hasDocuments&&((Ar=or.client)==null||Ar.invoice.document.getAll(pr.id).then(Ur=>{var Lr,Zr;Ur&&Ur.length>0&&(yr(Ur),ir({fileReaderObj:(Lr=Ur==null?void 0:Ur[0])==null?void 0:Lr.uri,mimeType:(Zr=Ur==null?void 0:Ur[0])==null?void 0:Zr.mimeType}))}))},[pr]);const Ir=jsx("div",{className:"mercoa-min-w-[300px] mercoa-mr-5",children:ar?jsxs(Fragment,{children:[jsxs("div",{className:`mercoa-text-center ${fr?"mercoa-block mercoa-mb-5":"mercoa-hidden"}`,children:[jsx("span",{className:"mercoa-text-gray-800 mercoa-w-full",children:" Extracting Invoice Details "}),jsx(ProgressBar,{})]}),jsx(InvoiceDocuments,{documents:new Array(ar),height:Mr})]}):jsx(InvoiceDocumentsUpload,{onFileUpload:jr})});return nr?jsx(Fragment,{children:nr({invoice:pr,documents:mr})}):!pr&&ee?jsx(LoadingSpinner,{}):jsxs(X$2,{className:"mercoa",children:[jsx(_$2,{minSize:0,children:Ir}),jsx(ne,{size:5,className:"mercoa-bg-gray-200 mercoa-cursor-ew-resize mercoa-invisible min-[450px]:mercoa-visible",children:jsx("div",{className:"mercoa-w-3 mercoa-h-10 mercoa-bg-gray-500 mercoa-absolute mercoa-top-1/2 mercoa-left-1/2 mercoa-transform -mercoa-translate-x-1/2 -mercoa-translate-y-1/2"})}),jsxs(_$2,{className:"mercoa-pl-5 mercoa-relative",minSize:400,children:[jsx("div",{className:"mercoa-flex mercoa-w-full mercoa-flex-row-reverse visible min-[450px]:mercoa-invisible mercoa-absolute mercoa-top-2",children:jsxs(MercoaButton,{isEmphasized:!0,size:"sm",type:"button",onClick:()=>{br(!Er)},className:"mercoa-mr-7 mercoa-z-20",children:["View ",Er?"Form":"Invoice"]})}),Er?jsx("div",{className:"mercoa-mt-20",children:Ir}):jsx(EditInvoiceForm,{invoice:pr,ocrResponse:sr,uploadedImage:lr,setUploadedImage:ur,onRedirect:ce,refreshInvoice:_r,addPaymentMethodRedirect:re,height:Mr})]})]})}function InvoiceDocumentsUpload({onFileUpload:ee}){const te=ce=>new Promise((re,nr)=>{const or=new FileReader;or.onload=()=>re(String(or.result)),or.onerror=nr,or.readAsDataURL(ce)});return jsx(Dropzone$1,{onDropAccepted:ce=>{te(ce[0]).then(re=>{ee(re,ce[0])})},onDropRejected:()=>{Q$1.error("Invalid file type")},minSize:0,maxSize:1e7,accept:{"application/pdf":[".pdf"],"image/png":[".png"],"image/gif":[".gif"],"image/tiff":[".tif",".tiff"],"image/jpeg":[".jpeg",".jpg"],"image/bmp":[".bmp"],"image/webp":[".webp"]},children:({getRootProps:ce,getInputProps:re,isDragActive:nr})=>jsx("div",{className:`mercoa-mt-2 mercoa-flex mercoa-justify-center mercoa-rounded-lg mercoa-border mercoa-border-dashed mercoa-border-gray-900/25 ${nr?"mercoa-border-mercoa-primary":"mercoa-border-gray-300"} mercoa-px-6 mercoa-py-10`,...ce(),children:jsxs("div",{className:"mercoa-text-center",children:[jsx(PhotoIcon$1,{className:"mercoa-mx-auto mercoa-h-12 mercoa-w-12 mercoa-text-gray-300","aria-hidden":"true"}),jsxs("div",{className:"mercoa-mt-4 mercoa-flex mercoa-text-sm mercoa-text-gray-600",children:[jsxs("label",{htmlFor:"file-upload",className:"mercoa-relative mercoa-cursor-pointer mercoa-rounded-md mercoa-bg-white mercoa-font-semibold mercoa-text-mercoa-primary focus-within:mercoa-outline-none focus-within:mercoa-ring-2 focus-within:mercoa-ring-mercoa-primary focus-within:mercoa-ring-offset-2 hover:mercoa-text-indigo-500",children:[jsx("span",{children:"Upload an invoice"}),jsx("input",{...re(),id:"file-upload",name:"file-upload",type:"file",className:"mercoa-sr-only"})]}),jsx("p",{className:"mercoa-pl-1",children:"or drag and drop"})]}),jsx("p",{className:"mercoa-text-xs mercoa-leading-5 mercoa-text-gray-600",children:"PNG, JPG, PDF up to 10MB"})]})})})}function InvoiceDocuments({documents:ee,height:te}){const[ce,re]=React$1.useState(),[nr,or]=React$1.useState(1),[ar,ir]=useDebounce(0,20),sr=React$1.useRef(null);React$1.useLayoutEffect(()=>{sr.current!==null&&ir(sr.current.getBoundingClientRect().width)},[sr]),useResizeObserver(sr,ur=>{ar&&Math.abs(ar-ur.contentRect.width)<20||ir(ur.contentRect.width)});const cr=jsx("div",{className:"mercoa-flex mercoa-justify-center",children:jsxs("nav",{className:"mercoa-isolate mercoa-inline-flex -mercoa-space-x-px mercoa-rounded-md mercoa-shadow-sm","aria-label":"Pagination",children:[jsxs("button",{type:"button",onClick:()=>or(Math.max(nr-1,1)),className:"mercoa-relative mercoa-inline-flex mercoa-items-center mercoa-rounded-l-md mercoa-px-2 mercoa-py-2 mercoa-text-gray-400 mercoa-ring-1 mercoa-ring-inset mercoa-ring-gray-300 hover:mercoa-bg-gray-50 focus:mercoa-z-20 focus:mercoa-outline-offset-0",children:[jsx("span",{className:"mercoa-sr-only",children:"Previous"}),jsx(ChevronLeftIcon$1,{className:"mercoa-h-5 mercoa-w-5","aria-hidden":"true"})]}),Array.from(new Array(ce),(ur,fr)=>jsx("button",{type:"button",onClick:()=>or(fr+1),"aria-current":nr!=fr+1?"false":"page",className:nr!=fr+1?"mercoa-relative mercoa-inline-flex mercoa-items-center mercoa-px-4 mercoa-py-2 mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 mercoa-ring-1 mercoa-ring-inset mercoa-ring-gray-300 hover:mercoa-bg-gray-50 focus:mercoa-z-20 focus:mercoa-outline-offset-0":"mercoa-relative mercoa-z-10 mercoa-inline-flex mercoa-items-center mercoa-bg-mercoa-primary mercoa-px-4 mercoa-py-2 mercoa-text-sm mercoa-font-semibold mercoa-text-white focus:mercoa-z-20 focus-visible:outline focus-visible:mercoa-outline-2 focus-visible:mercoa-outline-offset-2 focus-visible:mercoa-outline-mercoa-primary",children:fr+1},fr)),jsxs("button",{type:"button",onClick:()=>or(Math.min(nr+1,ce??1)),className:"mercoa-relative mercoa-inline-flex mercoa-items-center mercoa-rounded-r-md mercoa-px-2 mercoa-py-2 mercoa-text-gray-400 mercoa-ring-1 mercoa-ring-inset mercoa-ring-gray-300 hover:mercoa-bg-gray-50 focus:mercoa-z-20 focus:mercoa-outline-offset-0",children:[jsx("span",{className:"mercoa-sr-only",children:"Next"}),jsx(ChevronRightIcon$1,{className:"mercoa-h-5 mercoa-w-5","aria-hidden":"true"})]})]})}),lr=jsx("div",{children:ee&&ee.length>0&&jsx("div",{ref:sr,children:ee.map((ur,fr)=>jsxs("div",{children:[jsx("div",{className:"mercoa-rounded-md mercoa-border mercoa-shadow-lg",style:{width:`${ar}px`},children:ur.mimeType==="application/pdf"?jsx(Document$1,{loading:jsx("div",{className:"mercoa-mt-2 mercoa-flex mercoa-w-full mercoa-items-center mercoa-justify-center",style:{height:"700px"},children:jsx(LoadingSpinnerIcon,{})}),file:ur.fileReaderObj,onLoadSuccess:({numPages:hr})=>re(hr),children:jsx(Page$1,{pageNumber:nr,className:"mercoa-m-0 mercoa-w-full mercoa-p-0 mercoa-mt-2",renderTextLayer:!1,renderAnnotationLayer:!1,width:ar-5})},ur.fileReaderObj):jsx("img",{src:ur.fileReaderObj,onLoad:()=>re(1),className:"mercoa-mt-2"},ur.fileReaderObj)}),jsx("a",{href:ur.fileReaderObj,target:"_blank",rel:"noreferrer",className:"mercoa-mt-2",download:!0,children:jsxs(MercoaButton,{type:"button",isEmphasized:!1,className:"mercoa-mt-2",children:[jsxs("span",{className:"mercoa-hidden xl:mercoa-inline",children:[jsx(ArrowDownTrayIcon$1,{className:"-mercoa-ml-1 mercoa-mr-2 mercoa-inline-flex mercoa-h-5 mercoa-w-5"})," ","Download Invoice"]}),jsx("span",{className:"mercoa-inline xl:mercoa-hidden",children:"Download"})]})})]},fr))})});return jsxs("div",{className:"mercoa-overflow-auto",style:{height:`${te}px`},children:[cr,lr]})}function EditInvoiceForm({invoice:ee,ocrResponse:te,uploadedImage:ce,setUploadedImage:re,onRedirect:nr,refreshInvoice:or,addPaymentMethodRedirect:ar,height:ir}){var gn,vn,Gr,Qr,cn,Xr,zr,Vr,un,Kr,hn,_n,zn,dn,mn,Wr,Pn,Un,Hr,Fn,pn,an,On,xn,kn,qn,Wn,Ln,Qn,Yn,$n,en,bn,Mn,Cn,ln,En,In,Gn;const sr=useMercoaSession(),[cr,lr]=React$1.useState([]),[ur,fr]=React$1.useState([]),[hr,pr]=React$1.useState([]),[dr,mr]=React$1.useState([]),[yr,Mr]=React$1.useState(ee==null?void 0:ee.vendor),[Sr,Er]=React$1.useState(),[br,_r]=React$1.useState([]),[xr,jr]=React$1.useState(!1),wr=An=>{const[Vn,Kn]=React$1.useState(0);return React$1.useLayoutEffect(()=>{Kn(An.current.getBoundingClientRect().width)},[An]),useResizeObserver(An,Hn=>Kn(Hn.contentRect.width)),Vn},Ir=React$1.useRef(null),Br=wr(Ir);let Ar="mercoa-grid-cols-1";Br&&Br>300&&(Ar="mercoa-grid-cols-2"),Br&&Br>500&&(Ar="mercoa-grid-cols-3"),Br&&Br>700&&(Ar="mercoa-grid-cols-4"),Br&&Br>900&&(Ar="mercoa-grid-cols-5"),Br&&Br>1100&&(Ar="mercoa-grid-cols-6");const Ur=create$3({amount:create$5().positive().required().typeError("Please enter a valid number"),invoiceNumber:create$6(),description:create$6(),dueDate:create$4().required("Please select a due date").typeError("Please select a due date"),deductionDate:create$4().typeError("Please select a deduction date"),invoiceDate:create$4().required("Please select an invoice date").typeError("Please select an invoice date"),approvers:create$8(),lineItems:create$2().of(create$3({id:create$6(),description:create$6().required(),amount:create$5().required().typeError("Please enter a valid number"),quantity:create$5().required().typeError("Please enter a valid number"),unitPrice:create$5().required().typeError("Please enter a valid number"),metadata:create$8().nullable(),glAccountId:create$6()})),currency:create$6().required(),vendorId:create$6(),vendorName:create$6(),paymentDestinationId:create$6(),paymentMethodDestinationType:create$6(),paymentSourceId:create$6(),paymentMethodSourceType:create$6(),saveAsDraft:create$7(),metadata:create$8().nullable()}).required(),{register:Lr,handleSubmit:Zr,setValue:nn,setError:rn,clearErrors:tn,watch:Nr,control:Fr,formState:{errors:Yr}}=useForm({resolver:o(Ur),defaultValues:{invoiceNumber:ee==null?void 0:ee.invoiceNumber,amount:ee==null?void 0:ee.amount,currency:(ee==null?void 0:ee.currency)??"USD",vendorId:(gn=ee==null?void 0:ee.vendor)==null?void 0:gn.id,vendorName:(vn=ee==null?void 0:ee.vendor)==null?void 0:vn.name,invoiceDate:ee!=null&&ee.invoiceDate?dayjs$1(ee==null?void 0:ee.invoiceDate).toDate():void 0,dueDate:ee!=null&&ee.dueDate?dayjs$1(ee==null?void 0:ee.dueDate).toDate():void 0,deductionDate:ee!=null&&ee.deductionDate?dayjs$1(ee==null?void 0:ee.deductionDate).toDate():void 0,lineItems:(ee==null?void 0:ee.lineItems)??[],paymentDestinationId:(Gr=ee==null?void 0:ee.paymentDestination)==null?void 0:Gr.id,paymentMethodDestinationType:"",paymentSourceId:(Qr=ee==null?void 0:ee.paymentSource)==null?void 0:Qr.id,paymentMethodSourceType:"",description:(ee==null?void 0:ee.noteToSelf)??"",saveAsDraft:!1,metadata:JSON.stringify((ee==null?void 0:ee.metadata)??{}),approvers:ee!=null&&ee.approvers?ee.approvers.map(An=>({approvalSlotId:An.approvalSlotId,assignedUserId:An.assignedUserId})):[]}}),Dr=Nr("amount"),vr=Nr("dueDate"),Or=Nr("currency"),Tr=Nr("vendorId"),Pr=Nr("vendorName"),gr=Nr("paymentDestinationId"),$r=Nr("paymentSourceId"),Rr=Nr("approvers"),kr=Nr("metadata"),{fields:Cr,append:qr,remove:on}=useFieldArray({control:Fr,name:"lineItems"});Nr((An,{name:Vn,type:Kn})=>{if(Kn!="change"||!(Vn!=null&&Vn.startsWith("lineItems"))||Vn.endsWith("amount")||Vn.endsWith("description")||Vn.endsWith("name"))return;let Xn=An.lineItems.reduce((Jn,Zn,so)=>(Zn.amount=Math.floor((Zn.quantity??1)*(Zn.unitPrice??1)*100)/100,nn(`lineItems.${so}.amount`,Zn.amount),Jn+Zn.amount),0);Xn=Math.floor(Xn*100)/100,nn("amount",Xn)}),React$1.useEffect(()=>{Er(ee==null?void 0:ee.approvers.map(An=>({assignedUserId:An.assignedUserId??"",approvalSlotId:An.approvalSlotId})))},[ee]),React$1.useEffect(()=>{var An,Vn,Kn,Hn;!sr.token||!((An=sr.entity)!=null&&An.id)||!sr.client||((Kn=sr.client)==null||Kn.entity.paymentMethod.getAll((Vn=sr.entity)==null?void 0:Vn.id).then(Xn=>{Xn&&lr(Xn)}),(Hn=sr.client)==null||Hn.customPaymentMethodSchema.getAll().then(Xn=>{var Jn,Zn;if(Xn){fr(Xn);let so=[];((Zn=(Jn=sr.organization)==null?void 0:Jn.paymentMethods)==null?void 0:Zn.payerPayments.some(fo=>fo.active&&(fo.type==="bankAccount"||fo.type==="card")))&&so.push("USD"),Xn.forEach(fo=>{fo.supportedCurrencies&&(so=[...new Set([...so,...fo.supportedCurrencies])])}),mr(so)}}))},[sr.client,(cn=sr.entity)==null?void 0:cn.id,sr.token]),React$1.useEffect(()=>{var An,Vn;!sr.token||!((An=sr.entity)!=null&&An.id)||(Vn=sr.client)==null||Vn.entity.metadata.getAll(sr.entity.id).then(Kn=>{Kn&&_r(Kn)})},[(Xr=sr.entity)==null?void 0:Xr.id,sr.refreshId,sr.token]),React$1.useEffect(()=>{dr.length>0&&nn("currency",(ee==null?void 0:ee.currency)??dr[0])},[dr]),React$1.useEffect(()=>{var An;!sr.token||!Tr||(An=sr.client)==null||An.entity.paymentMethod.getAll(Tr).then(Vn=>{Vn&&pr(Vn)})},[sr.client,Tr,sr.token]),React$1.useEffect(()=>{var An,Vn,Kn,Hn,Xn,Jn;te&&(te.invoice.amount&&nn("amount",te.invoice.amount),nn("invoiceNumber",te.invoice.invoiceNumber),te.invoice.invoiceDate&&nn("invoiceDate",te.invoice.invoiceDate),te.invoice.dueDate&&nn("dueDate",te.invoice.dueDate),nn("deductionDate",te.invoice.deductionDate),te.invoice.currency&&nn("currency",te.invoice.currency),te.invoice.metadata&&nn("metadata",JSON.stringify(te.invoice.metadata)),te.invoice.lineItems&&!((Kn=(Vn=(An=sr.iframeOptions)==null?void 0:An.options)==null?void 0:Vn.invoice)!=null&&Kn.disableLineItems)&&nn("lineItems",te.invoice.lineItems.map(Zn=>({description:Zn.description??"",amount:Zn.amount??0,quantity:Zn.quantity??0,unitPrice:Zn.unitPrice??0,name:Zn.name??"",metadata:Zn.metadata??{},glAccountId:Zn.glAccountId??"",id:Zn.id??"",createdAt:Zn.createdAt??new Date,updatedAt:Zn.updatedAt??new Date}))),yr||(te.vendor.id==="new"&&((Jn=(Xn=(Hn=sr.iframeOptions)==null?void 0:Hn.options)==null?void 0:Xn.vendors)!=null&&Jn.disableCreation)?console.log("new vendor creation disabled"):te.vendor.id&&(console.log("setting selected vendor",te.vendor),Mr(te.vendor))))},[te,yr]);let sn=!1;ee!=null&&ee.approvers?sn=!!(Rr!=null&&Rr.every(An=>!!An)):sn=!!(ee!=null&&ee.approvers.every(An=>An.assignedUserId));let yn=!!Dr&&!!vr&&!!Or&&!!Tr&&Tr!=="new"&&!!$r&&!!Pr;(un=(Vr=(zr=sr.iframeOptions)==null?void 0:zr.options)==null?void 0:Vr.vendors)!=null&&un.disableCreation||(yn=yn&&!!(yr!=null&&yr.email)&&!!(yr.accountType==="individual"||yr.accountType==="business"&&((Kr=yr.profile.business)!=null&&Kr.website||(hn=yr.profile.business)!=null&&hn.description)));const jn=(ee==null?void 0:ee.status)===javascript.Mercoa.InvoiceStatus.Approved&&yn&&(!gr||gr==="new"),wn=yn&&(ee==null?void 0:ee.status)===javascript.Mercoa.InvoiceStatus.Approved&&gr;let Dn=javascript.Mercoa.InvoiceStatus.Draft;wn?Dn=javascript.Mercoa.InvoiceStatus.Scheduled:jn||(ee==null?void 0:ee.status)===javascript.Mercoa.InvoiceStatus.New?Dn=javascript.Mercoa.InvoiceStatus.Approved:yn&&sn&&(Dn=javascript.Mercoa.InvoiceStatus.New);const Rn=async An=>{var Kn,Hn,Xn,Jn,Zn,so,po,fo,ho,yo;if(!sr.token||!((Kn=sr.entity)!=null&&Kn.id))return;const Vn={status:An.saveAsDraft?javascript.Mercoa.InvoiceStatus.Draft:Dn,amount:Number(An.amount),currency:An.currency,invoiceDate:An.invoiceDate,deductionDate:An.deductionDate,dueDate:An.dueDate,invoiceNumber:An.invoiceNumber,noteToSelf:An.description,payerId:(Hn=sr.entity)==null?void 0:Hn.id,paymentSourceId:An.paymentSourceId,approvers:An.approvers.filter(mo=>mo.assignedUserId),...An.vendorId!=="new"&&{vendorId:An.vendorId},paymentDestinationId:An.paymentDestinationId,lineItems:An.lineItems.map(mo=>({...mo.id&&{id:mo.id},description:mo.description,amount:Number(mo.amount),quantity:Number(mo.quantity),unitPrice:Number(mo.unitPrice),metadata:mo.metadata,currency:An.currency??"USD",glAccountId:mo.glAccountId})),metadata:JSON.parse(An.metadata),uploadedImage:ce,creatorEntityId:(Xn=sr.entity)==null?void 0:Xn.id};if(console.log({data:An,invoiceData:Vn}),An.paymentMethodDestinationType&&(!An.paymentDestinationId||An.paymentDestinationId==="new")){const mo=An.paymentMethodDestinationType,go=An.paymentMethodDestinationType.startsWith("cpms_")?"custom":An.paymentMethodDestinationType;let Eo;if(go==="bankAccount")Eo={type:go,accountNumber:An.accountNumber,routingNumber:An.routingNumber,accountType:An.accountType,bankName:An.bankName};else if(go==="check")Eo={type:go,...An};else if(go==="custom"){const wo={};Object.entries(An).forEach(([Ci,Di])=>{Ci.startsWith("~cpm~~")&&Di.forEach(Jo=>{wo[Jo.name]=`${wo[Jo.name]??Jo.value}`})}),Eo={type:go,foreignId:Math.random().toString(36).substring(7),schemaId:mo,data:wo}}if(Eo){const wo=await((Jn=sr.client)==null?void 0:Jn.entity.paymentMethod.create(An.vendorId,Eo));wo&&(Vn.paymentDestinationId=wo.id)}}if(Vn.status!==javascript.Mercoa.InvoiceStatus.Draft&&((Zn=Vn.approvers)==null?void 0:Zn.length)!==(ee==null?void 0:ee.approvers.length)){Q$1.error("Please assign all approvers for this invoice."),jr(!1);return}console.log("invoiceData before API call: ",{invoiceData:Vn}),ee?(fo=sr.client)==null||fo.invoice.update(ee.id,{...Vn,creatorUserId:((so=ee.creatorUser)==null?void 0:so.id)??((po=sr.user)==null?void 0:po.id)}).then(mo=>{mo&&(console.log("invoice/update API response: ",mo),re(void 0),Q$1.success("Invoice updated"),or(mo.id),jr(!1))}).catch(mo=>{console.log(mo.statusCode),console.log(mo.body),Q$1.error(`There was an error updating the invoice.
|
|
168
|
+
`);var rn=0,tn=!1;this.parse=function(Nr,Fr,Yr){if(typeof Nr!="string")throw new Error("Input must be a string");var Dr=Nr.length,vr=Ir.length,Or=Br.length,Tr=Ar.length,Pr=xr(Ur),gr=[],$r=[],Rr=[],kr=rn=0;if(!Nr)return hn();if(jr.header&&!Fr){var Cr=Nr.split(Br)[0].split(Ir),qr=[],on={},sn=!1;for(var yn in Cr){var jn=Cr[yn];xr(jr.transformHeader)&&(jn=jr.transformHeader(jn,yn));var wn=jn,Dn=on[jn]||0;for(0<Dn&&(sn=!0,wn=jn+"_"+Dn),on[jn]=Dn+1;qr.includes(wn);)wn=wn+"_"+Dn;qr.push(wn)}if(sn){var Rn=Nr.split(Br);Rn[0]=qr.join(Ir),Nr=Rn.join(Br)}}if(Zr||Zr!==!1&&Nr.indexOf(wr)===-1){for(var fn=Nr.split(Br),Sn=0;Sn<fn.length;Sn++){if(Rr=fn[Sn],rn+=Rr.length,Sn!==fn.length-1)rn+=Br.length;else if(Yr)return hn();if(!Ar||Rr.substring(0,Tr)!==Ar){if(Pr){if(gr=[],zr(Rr.split(Ir)),_n(),tn)return hn()}else zr(Rr.split(Ir));if(Lr&&Lr<=Sn)return gr=gr.slice(0,Lr),hn(!0)}}return hn()}for(var gn=Nr.indexOf(Ir,rn),vn=Nr.indexOf(Br,rn),Gr=new RegExp(mr(nn)+mr(wr),"g"),Qr=Nr.indexOf(wr,rn);;)if(Nr[rn]!==wr)if(Ar&&Rr.length===0&&Nr.substring(rn,rn+Tr)===Ar){if(vn===-1)return hn();rn=vn+Or,vn=Nr.indexOf(Br,rn),gn=Nr.indexOf(Ir,rn)}else if(gn!==-1&&(gn<vn||vn===-1))Rr.push(Nr.substring(rn,gn)),rn=gn+vr,gn=Nr.indexOf(Ir,rn);else{if(vn===-1)break;if(Rr.push(Nr.substring(rn,vn)),Kr(vn+Or),Pr&&(_n(),tn))return hn();if(Lr&&gr.length>=Lr)return hn(!0)}else for(Qr=rn,rn++;;){if((Qr=Nr.indexOf(wr,Qr+1))===-1)return Yr||$r.push({type:"Quotes",code:"MissingQuotes",message:"Quoted field unterminated",row:gr.length,index:rn}),un();if(Qr===Dr-1)return un(Nr.substring(rn,Qr).replace(Gr,wr));if(wr!==nn||Nr[Qr+1]!==nn){if(wr===nn||Qr===0||Nr[Qr-1]!==nn){gn!==-1&&gn<Qr+1&&(gn=Nr.indexOf(Ir,Qr+1)),vn!==-1&&vn<Qr+1&&(vn=Nr.indexOf(Br,Qr+1));var cn=Vr(vn===-1?gn:Math.min(gn,vn));if(Nr.substr(Qr+1+cn,vr)===Ir){Rr.push(Nr.substring(rn,Qr).replace(Gr,wr)),Nr[rn=Qr+1+cn+vr]!==wr&&(Qr=Nr.indexOf(wr,rn)),gn=Nr.indexOf(Ir,rn),vn=Nr.indexOf(Br,rn);break}var Xr=Vr(vn);if(Nr.substring(Qr+1+Xr,Qr+1+Xr+Or)===Br){if(Rr.push(Nr.substring(rn,Qr).replace(Gr,wr)),Kr(Qr+1+Xr+Or),gn=Nr.indexOf(Ir,rn),Qr=Nr.indexOf(wr,rn),Pr&&(_n(),tn))return hn();if(Lr&&gr.length>=Lr)return hn(!0);break}$r.push({type:"Quotes",code:"InvalidQuotes",message:"Trailing quote on quoted field is malformed",row:gr.length,index:rn}),Qr++}}else Qr++}return un();function zr(zn){gr.push(zn),kr=rn}function Vr(zn){var dn=0;if(zn!==-1){var mn=Nr.substring(Qr+1,zn);mn&&mn.trim()===""&&(dn=mn.length)}return dn}function un(zn){return Yr||(zn===void 0&&(zn=Nr.substring(rn)),Rr.push(zn),rn=Dr,zr(Rr),Pr&&_n()),hn()}function Kr(zn){rn=zn,zr(Rr),Rr=[],vn=Nr.indexOf(Br,rn)}function hn(zn){return{data:gr,errors:$r,meta:{delimiter:Ir,linebreak:Br,aborted:tn,truncated:!!zn,cursor:kr+(Fr||0)}}}function _n(){Ur(hn()),gr=[],$r=[]}},this.abort=function(){tn=!0},this.getCharIndex=function(){return rn}}function Mr(jr){var wr=jr.data,Ir=ar[wr.workerId],Br=!1;if(wr.error)Ir.userError(wr.error,wr.file);else if(wr.results&&wr.results.data){var Ar={abort:function(){Br=!0,Sr(wr.workerId,{data:[],errors:[],meta:{aborted:!0}})},pause:Er,resume:Er};if(xr(Ir.userStep)){for(var Ur=0;Ur<wr.results.data.length&&(Ir.userStep({data:wr.results.data[Ur],errors:wr.results.errors,meta:wr.results.meta},Ar),!Br);Ur++);delete wr.results}else xr(Ir.userChunk)&&(Ir.userChunk(wr.results,Ar,wr.file),delete wr.results)}wr.finished&&!Br&&Sr(wr.workerId,wr.results)}function Sr(jr,wr){var Ir=ar[jr];xr(Ir.userComplete)&&Ir.userComplete(wr),Ir.terminate(),delete ar[jr]}function Er(){throw new Error("Not implemented.")}function br(jr){if(typeof jr!="object"||jr===null)return jr;var wr=Array.isArray(jr)?[]:{};for(var Ir in jr)wr[Ir]=br(jr[Ir]);return wr}function _r(jr,wr){return function(){jr.apply(wr,arguments)}}function xr(jr){return typeof jr=="function"}return or&&(re.onmessage=function(jr){var wr=jr.data;if(sr.WORKER_ID===void 0&&wr&&(sr.WORKER_ID=wr.workerId),typeof wr.input=="string")re.postMessage({workerId:sr.WORKER_ID,results:sr.parse(wr.input,wr.config),finished:!0});else if(re.File&&wr.input instanceof File||wr.input instanceof Object){var Ir=sr.parse(wr.input,wr.config);Ir&&re.postMessage({workerId:sr.WORKER_ID,results:Ir,finished:!0})}}),(ur.prototype=Object.create(lr.prototype)).constructor=ur,(fr.prototype=Object.create(lr.prototype)).constructor=fr,(hr.prototype=Object.create(hr.prototype)).constructor=hr,(pr.prototype=Object.create(lr.prototype)).constructor=pr,sr})})(papaparse_min);var papaparse_minExports=papaparse_min.exports;const Papa=getDefaultExportFromCjs(papaparse_minExports);pdfjs$1.GlobalWorkerOptions.workerSrc=`//unpkg.com/pdfjs-dist@${pdfjs$1.version}/build/pdf.worker.min.js`;function ApprovalsTable({search:ee,onClick:te}){var nn,rn;const ce=useMercoaSession(),re=javascript.Mercoa.InvoiceStatus.New,[nr,or]=React$1.useState(),[ar,ir]=React$1.useState(javascript.Mercoa.InvoiceOrderByField.CreatedAt),[sr,cr]=React$1.useState(javascript.Mercoa.OrderDirection.Asc),[lr,ur]=React$1.useState(!0),[fr,hr]=React$1.useState(0),[pr,dr]=React$1.useState(!1),[mr,yr]=React$1.useState([]),[Mr,Sr]=React$1.useState(20),[Er,br]=React$1.useState(1),_r=React$1.useRef(null),[xr,jr]=React$1.useState(!1),[wr,Ir]=React$1.useState(!1),[Br,Ar]=React$1.useState([]);React$1.useLayoutEffect(()=>{const tn=Br.length>0&&Br.length<(nr?nr.length:0);jr(Br.length===(nr?nr.length:0)),Ir(tn),_r.current&&(_r.current.indeterminate=tn)},[Br,nr]);function Ur(){nr&&(Ar(xr||wr?[]:nr),jr(!xr&&!wr),Ir(!1))}async function Lr(){var Nr;if(!ce.token||!((Nr=ce.entity)!=null&&Nr.id)||!ce.user)return;let tn=!1;await Promise.all(Br.map(async Fr=>{var Yr,Dr;try{await((Dr=ce.client)==null?void 0:Dr.invoice.approval.approve(Fr.id,{userId:(Yr=ce.user)==null?void 0:Yr.id})),tn=!0}catch(vr){console.error("Error approving invoice: ",vr),console.log("Errored invoice: ",{invoice:Fr})}})),tn&&Q$1.success("Approved"),ce.refresh()}async function Zr(){var Nr;if(!ce.token||!((Nr=ce.entity)!=null&&Nr.id)||!ce.user)return;let tn=!1;await Promise.all(Br.map(Fr=>{var Yr,Dr;try{(Dr=ce.client)==null||Dr.invoice.approval.reject(Fr.id,{userId:(Yr=ce.user)==null?void 0:Yr.id}),tn=!0}catch(vr){console.error("Error rejecting invoice: ",vr),console.log("Errored invoice: ",{invoice:Fr})}})),tn&&Q$1.success("Rejected"),ce.refresh()}return React$1.useEffect(()=>{var tn,Nr,Fr,Yr;!ce.token||!((tn=ce.entity)!=null&&tn.id)||!((Nr=ce.user)!=null&&Nr.id)||(Yr=ce.client)==null||Yr.entity.invoice.find(ce.entity.id,{status:re,search:ee,orderBy:ar,orderDirection:sr,approverId:(Fr=ce.user)==null?void 0:Fr.id,limit:Mr,startingAfter:mr[mr.length-1],excludeReceivables:!0}).then(Dr=>{if(Dr){const vr=Dr.data.filter(Or=>{var Tr;return(Tr=Or.approvers)==null?void 0:Tr.some(Pr=>{var gr;return Pr.assignedUserId===((gr=ce.user)==null?void 0:gr.id)&&Pr.action===javascript.Mercoa.ApproverAction.None})});ur(Dr.hasMore),hr(Dr.count),or(vr),dr(vr.length>0)}})},[ce.token,ce.entity,ce.refreshId,(nn=ce.user)==null?void 0:nn.id,ee,ar,sr,mr,Mr]),(rn=ce.user)!=null&&rn.id?nr?jsx(Fragment,{children:pr&&jsx(Fragment,{children:ce.entity&&nr?jsxs(Fragment,{children:[jsxs("div",{className:"mercoa-mt-7 ",children:[jsx("div",{className:"sm:mercoa-flex sm:mercoa-items-center",children:jsxs("div",{className:"sm:mercoa-flex-auto",children:[jsx("h1",{className:"mercoa-text-base mercoa-font-semibold mercoa-leading-6 mercoa-text-gray-900",children:"Assigned to Me"}),jsx("p",{className:"mercoa-mt-2 mercoa-text-sm mercoa-text-gray-700",children:"A list of all invoices that require your review"})]})}),jsx("div",{className:"mercoa-flow-root",children:jsx("div",{className:"-mercoa-mx-4 -mercoa-my-2 mercoa-overflow-x-auto sm:-mercoa-mx-6 lg:-mercoa-mx-8",children:jsx("div",{className:"mercoa-inline-block mercoa-min-w-full mercoa-py-2 mercoa-align-middle sm:mercoa-px-6 lg:mercoa-px-8",children:jsxs("div",{className:"mercoa-relative",children:[Br.length>0&&jsxs("div",{className:"mercoa-absolute mercoa-left-14 mercoa-top-0 mercoa-flex mercoa-h-12 mercoa-items-center mercoa-space-x-3 mercoa-bg-white sm:mercoa-left-12",children:[jsx("button",{type:"button",className:"mercoa-inline-flex mercoa-items-center mercoa-rounded mercoa-bg-white mercoa-px-2 mercoa-py-1 mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 mercoa-shadow-sm mercoa-ring-1 mercoa-ring-inset mercoa-ring-gray-300 hover:mercoa-bg-gray-50 disabled:mercoa-cursor-not-allowed disabled:mercoa-opacity-30 disabled:hover:mercoa-bg-white",onClick:Lr,children:"Approve"}),jsx("button",{type:"button",className:"mercoa-inline-flex mercoa-items-center mercoa-rounded mercoa-bg-white mercoa-px-2 mercoa-py-1 mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 mercoa-shadow-sm mercoa-ring-1 mercoa-ring-inset mercoa-ring-gray-300 hover:mercoa-bg-gray-50 disabled:mercoa-cursor-not-allowed disabled:mercoa-opacity-30 disabled:hover:mercoa-bg-white",onClick:Zr,children:"Reject"})]}),jsxs("table",{className:"mercoa-min-w-full table-mercoa-fixed mercoa-divide-y mercoa-divide-gray-300 mercoa-mt-5",children:[jsx("thead",{children:jsxs("tr",{children:[jsx("th",{scope:"col",className:"mercoa-relative mercoa-px-7 sm:mercoa-w-12 sm:mercoa-px-6",children:jsx("input",{type:"checkbox",className:"mercoa-absolute mercoa-left-4 mercoa-top-1/2 -mercoa-mt-2 mercoa-h-4 mercoa-w-4 mercoa-rounded mercoa-border-gray-300 mercoa-text-mercoa-primary-text focus:mercoa-ring-mercoa-primary",ref:_r,checked:xr,onChange:Ur})}),jsx("th",{scope:"col",className:"mercoa-min-w-[12rem] mercoa-py-3.5 mercoa-pl-4 mercoa-pr-3 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 sm:mercoa-pl-3",children:jsx(TableOrderHeader,{title:"Vendor",setOrder:tn=>{ir(javascript.Mercoa.InvoiceOrderByField.VendorName),cr(tn)},isSelected:ar===javascript.Mercoa.InvoiceOrderByField.VendorName,orderDirection:sr})}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 mercoa-hidden sm:mercoa-table-cell",children:jsx(TableOrderHeader,{title:"Invoice Number",setOrder:tn=>{ir(javascript.Mercoa.InvoiceOrderByField.InvoiceNumber),cr(tn)},isSelected:ar===javascript.Mercoa.InvoiceOrderByField.InvoiceNumber,orderDirection:sr})}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900",children:jsx(TableOrderHeader,{title:"Due Date",setOrder:tn=>{ir(javascript.Mercoa.InvoiceOrderByField.DueDate),cr(tn)},isSelected:ar===javascript.Mercoa.InvoiceOrderByField.DueDate,orderDirection:sr})}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900",children:jsx(TableOrderHeader,{title:"Amount",setOrder:tn=>{ir(javascript.Mercoa.InvoiceOrderByField.Amount),cr(tn)},isSelected:ar===javascript.Mercoa.InvoiceOrderByField.Amount,orderDirection:sr})}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 mercoa-pl-6 mercoa-hidden lg:mercoa-table-cell",children:"Status"})]})}),jsx("tbody",{className:"mercoa-divide-y mercoa-divide-gray-200 mercoa-bg-white",children:nr.map(tn=>{var Nr;return jsxs("tr",{className:classNames$1("mercoa-cursor-pointer hover:mercoa-bg-gray-100",Br.includes(tn)?"mercoa-bg-gray-50":void 0),children:[jsxs("td",{className:"mercoa-relative mercoa-px-7 sm:mercoa-w-12 sm:mercoa-px-6",children:[Br.includes(tn)&&jsx("div",{className:"mercoa-absolute mercoa-inset-y-0 mercoa-left-0 mercoa-w-0.5 mercoa-bg-mercoa-primary"}),jsx("input",{type:"checkbox",className:"mercoa-absolute mercoa-left-4 mercoa-top-1/2 -mercoa-mt-2 mercoa-h-4 mercoa-w-4 mercoa-rounded mercoa-border-gray-300 mercoa-text-mercoa-primary-text focus:mercoa-ring-mercoa-primary",value:tn.id,checked:Br.includes(tn),onChange:Fr=>Ar(Fr.target.checked?[...Br,tn]:Br.filter(Yr=>Yr!==tn))})]}),jsx("td",{className:classNames$1("mercoa-whitespace-nowrap mercoa-py-3 mercoa-pl-4 mercoa-pr-3 mercoa-text-sm mercoa-font-medium mercoa-text-gray-900 sm:mercoa-pl-3",Br.includes(tn)?"mercoa-text-mercoa-primary-text":"mercoa-text-gray-900"),onClick:()=>{te&&te(tn)},children:(Nr=tn.vendor)==null?void 0:Nr.name}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-3 mercoa-text-sm mercoa-text-gray-900 mercoa-hidden sm:mercoa-table-cell",onClick:()=>{te&&te(tn)},children:tn.invoiceNumber}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-3 mercoa-text-sm mercoa-text-gray-900",onClick:()=>{te&&te(tn)},children:dayjs$1(tn.dueDate).format("MMM DD, YYYY")}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-3 mercoa-text-sm mercoa-text-gray-900",onClick:()=>{te&&te(tn)},children:accounting.formatMoney(tn.amount??"",currencyCodeToSymbol(tn.currency))}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-3 mercoa-text-sm mercoa-hidden lg:mercoa-table-cell",onClick:()=>{te&&te(tn)},children:jsx(InvoiceStatusPill,{invoice:tn})})]},tn.id)})})]}),jsx(TableNavigation,{data:nr,page:Er,setPage:br,hasMore:lr,startingAfter:mr,setStartingAfter:yr,count:fr,resultsPerPage:Mr,setResultsPerPage:Sr})]})})})})]}),jsx("div",{className:"mercoa-mt-10 sm:mercoa-flex sm:mercoa-items-center",children:jsxs("div",{className:"sm:mercoa-flex-auto",children:[jsx("h1",{className:"mercoa-text-base mercoa-font-semibold mercoa-leading-6 mercoa-text-gray-900",children:"All invoices"}),jsx("p",{className:"mercoa-mt-2 mercoa-text-sm mercoa-text-gray-700",children:"A list of all invoices that require review from an assigned approver"})]})})]}):jsx(LoadingSpinner,{})})}):jsx(Skeleton,{rows:10}):jsx(Fragment,{})}function SchedulePaymentModal({show:ee,closeModal:te,setDate:ce}){return jsxs(_t$1,{as:"div",open:ee,onClose:te,className:"mercoa-relative mercoa-z-10",children:[jsx("div",{className:"mercoa-fixed mercoa-inset-0 mercoa-bg-black/30","aria-hidden":"true"}),jsx("div",{className:"mercoa-fixed mercoa-inset-0 mercoa-overflow-y-auto",children:jsx("div",{className:"mercoa-flex mercoa-min-h-full mercoa-items-end mercoa-justify-center mercoa-p-4 mercoa-text-center sm:mercoa-items-center sm:mercoa-p-0",children:jsx(DatePickerPanel,{closeModal:te,setDate:ce})})})]})}function DatePickerPanel({closeModal:ee,setDate:te}){const[ce,re]=React$1.useState();return jsxs(_t$1.Panel,{className:"mercoa-relative mercoa-transform mercoa-rounded-lg mercoa-bg-white mercoa-px-4 mercoa-pb-4 mercoa-pt-5 mercoa-text-left mercoa-shadow-xl mercoa-transition-all sm:mercoa-my-8 sm:mercoa-w-full sm:mercoa-max-w-sm sm:mercoa-p-6",children:[jsx("div",{children:jsxs("div",{className:"mercoa-mt-3 mercoa-text-center sm:mercoa-mt-5",children:[jsx(_t$1.Title,{as:"h3",className:"mercoa-text-base mercoa-font-semibold mercoa-leading-6 mercoa-text-gray-900",children:"When should these payments be scheduled?"}),jsx("div",{className:"mercoa-mt-2",children:jsx(er,{className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 focus:mercoa-border-indigo-500 focus:mercoa-ring-indigo-500 sm:mercoa-text-sm",placeholderText:"Select deduction date",onChange:nr=>re(nr),selected:ce,minDate:dayjs$1().add(1,"day").toDate(),filterDate:isWeekday})})]})}),jsx("div",{className:"mercoa-mt-5 sm:mercoa-mt-6",children:jsx(MercoaButton,{type:"button",className:"mercoa-inline-flex mercoa-w-full mercoa-justify-center ",isEmphasized:!0,onClick:()=>{ee(),console.log(ce),te(ce)},disabled:!ce,children:"Schedule Payments"})})]})}function InvoiceInboxTable({status:ee,search:te,onClick:ce}){const re=useMercoaSession(),[nr,or]=React$1.useState(),[ar,ir]=React$1.useState(javascript.Mercoa.InvoiceOrderByField.CreatedAt),[sr,cr]=React$1.useState(javascript.Mercoa.OrderDirection.Asc),[lr,ur]=React$1.useState(!0),[fr,hr]=React$1.useState(0),[pr,dr]=React$1.useState(!1),[mr,yr]=React$1.useState([]),[Mr,Sr]=React$1.useState(20),[Er,br]=React$1.useState(1),_r=React$1.useRef(null),[xr,jr]=React$1.useState(!1),[wr,Ir]=React$1.useState(!1),[Br,Ar]=React$1.useState([]),[Ur,Lr]=React$1.useState(!1);React$1.useLayoutEffect(()=>{const Fr=Br.length>0&&Br.length<(nr?nr.length:0);jr(Br.length===(nr?nr.length:0)),Ir(Fr),_r.current&&(_r.current.indeterminate=Fr)},[Br,nr]);function Zr(){nr&&(Ar(xr||wr?[]:nr),jr(!xr&&!wr),Ir(!1))}const nn=()=>{Lr(!0)},rn=()=>{Lr(!1)};async function tn(Fr){var vr;if(!re.token||!((vr=re.entity)!=null&&vr.id))return;function Yr(Or){var $r,Rr,kr,Cr,qr;if(!Or.vendor)return!1;const Tr=Or.vendor;let Pr=!!Or.amount&&!!Or.dueDate&&!!Or.currency&&!!Or.vendorId&&!!Or.paymentSourceId&&!!Tr.name;return(kr=(Rr=($r=re.iframeOptions)==null?void 0:$r.options)==null?void 0:Rr.vendors)!=null&&kr.disableCreation||(Pr=Pr&&!!Tr.email&&!!(Tr.accountType===javascript.Mercoa.AccountType.Individual||Tr.accountType===javascript.Mercoa.AccountType.Business&&((Cr=Tr.profile.business)!=null&&Cr.website||(qr=Tr.profile.business)!=null&&qr.description))),Pr&&Or.status===javascript.Mercoa.InvoiceStatus.Approved&&!!Or.paymentDestinationId}let Dr=!1;await Promise.all(Br.map(async Or=>{var Tr;try{if(Yr(Or)){const Pr={status:javascript.Mercoa.InvoiceStatus.Scheduled,deductionDate:Fr};await((Tr=re.client)==null?void 0:Tr.invoice.update(Or.id,Pr)),Dr=!0}else console.error("Invoice does not have all the information needed to schedule payment"),console.log("Invalid invoice:",{invoice:Or})}catch(Pr){console.error("Error updating invoice: ",Pr),console.log("Errored invoice: ",{invoice:Or})}})),Dr?Q$1.success("Payment Scheduled"):Q$1.error("Error scheduling payment"),re.refresh()}async function Nr(){var vr;if(!re.token||!((vr=re.entity)!=null&&vr.id))return;let Fr="",Yr=[];Dr();async function Dr(){var Tr,Pr;if(!re.token||!((Tr=re.entity)!=null&&Tr.id))return;const Or=await((Pr=re.client)==null?void 0:Pr.entity.invoice.find(re.entity.id,{status:ee,limit:100,startingAfter:Fr,excludeReceivables:!0}));if(Or)if(Or.data.length>0)Fr=Or.data[Or.data.length-1].id,Yr=[...Yr,...Or.data],await Dr();else{const gr=Papa.unparse(Yr.map(Cr=>{var qr,on,sn,yn,jn,wn;return{"Invoice ID":Cr.id,"Invoice Number":Cr.invoiceNumber,Status:Cr.status,Amount:Cr.amount,Currency:Cr.currency,Note:Cr.noteToSelf,"Payer ID":(qr=Cr.payer)==null?void 0:qr.id,"Payer Email":(on=Cr.payer)==null?void 0:on.email,"Payer Name":(sn=Cr.payer)==null?void 0:sn.name,"Vendor ID":(yn=Cr.vendor)==null?void 0:yn.id,"Vendor Email":(jn=Cr.vendor)==null?void 0:jn.email,"Vendor Name":(wn=Cr.vendor)==null?void 0:wn.name,Metadata:JSON.stringify(Cr.metadata),"Due Date":dayjs$1(Cr.dueDate),"Deduction Date":dayjs$1(Cr.deductionDate),"Processed At":dayjs$1(Cr.processedAt),"Created At":dayjs$1(Cr.createdAt),"Updated At":dayjs$1(Cr.updatedAt)}})),$r=new Blob([gr],{type:"text/csv"}),Rr=window.URL.createObjectURL($r),kr=document.createElement("a");kr.setAttribute("mercoa-hidden",""),kr.setAttribute("href",Rr),kr.setAttribute("download",`mercoa-invoice-export-${dayjs$1().format("YYYY-MM-DD")}.csv`),document.body.appendChild(kr),kr.click(),document.body.removeChild(kr)}}}return React$1.useEffect(()=>{var Fr,Yr;!re.token||!((Fr=re.entity)!=null&&Fr.id)||(Ar([]),dr(!1),(Yr=re.client)==null||Yr.entity.invoice.find(re.entity.id,{status:ee,search:te,orderBy:ar,orderDirection:sr,limit:Mr,startingAfter:mr[mr.length-1],excludeReceivables:!0}).then(Dr=>{Dr&&(ur(Dr.hasMore),hr(Dr.count),or(Dr.data),dr(!0))}))},[re.token,re.entity,re.refreshId,ee,te,ar,sr,mr,Mr]),React$1.useEffect(()=>{dr(!1),yr([]),br(1),hr(0)},[ee]),pr?jsx(Fragment,{children:re.entity&&nr?jsxs(Fragment,{children:[jsx("div",{className:"mercoa-min-h-[600px]",children:jsxs("div",{className:"mercoa-relative",children:[ee.some(Fr=>Fr===javascript.Mercoa.InvoiceStatus.Approved)&&Br.length>0&&jsx("div",{className:"mercoa-absolute mercoa-left-14 mercoa-top-0 mercoa-flex mercoa-h-12 mercoa-items-center mercoa-space-x-3 mercoa-bg-white sm:mercoa-left-12",children:jsx("button",{type:"button",className:"mercoa-inline-flex mercoa-items-center mercoa-rounded mercoa-bg-white mercoa-px-2 mercoa-py-1 mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 mercoa-shadow-sm mercoa-ring-1 mercoa-ring-inset mercoa-ring-gray-300 hover:mercoa-bg-gray-50 disabled:mercoa-cursor-not-allowed disabled:mercoa-opacity-30 disabled:hover:mercoa-bg-white",onClick:nn,children:"Schedule Payment"})}),jsxs("table",{className:"mercoa-min-w-full table-mercoa-fixed mercoa-divide-y mercoa-divide-gray-300 mercoa-mt-5",children:[jsx("thead",{children:jsxs("tr",{children:[ee.some(Fr=>Fr===javascript.Mercoa.InvoiceStatus.Approved)&&jsx("th",{scope:"col",className:"mercoa-relative mercoa-px-7 sm:mercoa-w-12 sm:mercoa-px-6",children:jsx("input",{type:"checkbox",className:"mercoa-absolute mercoa-left-4 mercoa-top-1/2 -mercoa-mt-2 mercoa-h-4 mercoa-w-4 mercoa-rounded mercoa-border-gray-300 mercoa-text-mercoa-primary-text focus:mercoa-ring-mercoa-primary",ref:_r,checked:xr,onChange:Zr})}),jsx("th",{scope:"col",className:"mercoa-min-w-[12rem] mercoa-py-3.5 mercoa-pl-4 mercoa-pr-3 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 sm:mercoa-pl-3",children:jsx(TableOrderHeader,{title:"Vendor",setOrder:Fr=>{ir(javascript.Mercoa.InvoiceOrderByField.VendorName),cr(Fr)},isSelected:ar===javascript.Mercoa.InvoiceOrderByField.VendorName,orderDirection:sr})}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 mercoa-hidden sm:mercoa-table-cell",children:jsx(TableOrderHeader,{title:"Invoice Number",setOrder:Fr=>{ir(javascript.Mercoa.InvoiceOrderByField.InvoiceNumber),cr(Fr)},isSelected:ar===javascript.Mercoa.InvoiceOrderByField.InvoiceNumber,orderDirection:sr})}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900",children:jsx(TableOrderHeader,{title:"Due Date",setOrder:Fr=>{ir(javascript.Mercoa.InvoiceOrderByField.DueDate),cr(Fr)},isSelected:ar===javascript.Mercoa.InvoiceOrderByField.DueDate,orderDirection:sr})}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900",children:jsx(TableOrderHeader,{title:"Amount",setOrder:Fr=>{ir(javascript.Mercoa.InvoiceOrderByField.Amount),cr(Fr)},isSelected:ar===javascript.Mercoa.InvoiceOrderByField.Amount,orderDirection:sr})}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 mercoa-pl-6 mercoa-hidden lg:mercoa-table-cell",children:"Status"}),ee.some(Fr=>Fr===javascript.Mercoa.InvoiceStatus.Scheduled||Fr===javascript.Mercoa.InvoiceStatus.Pending||Fr===javascript.Mercoa.InvoiceStatus.Paid)&&jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 group mercoa-inline-flex mercoa-items-center",children:"Deduction Date"})]})}),jsx("tbody",{className:"mercoa-divide-y mercoa-divide-gray-200 mercoa-bg-white",children:nr.map(Fr=>{var Yr;return jsxs("tr",{className:classNames$1("mercoa-cursor-pointer hover:mercoa-bg-gray-100",Br.includes(Fr)?"mercoa-bg-gray-50":void 0),children:[ee.some(Dr=>Dr===javascript.Mercoa.InvoiceStatus.Approved)&&jsxs("td",{className:"mercoa-relative mercoa-px-7 sm:mercoa-w-12 sm:mercoa-px-6",children:[Br.includes(Fr)&&jsx("div",{className:"mercoa-absolute mercoa-inset-y-0 mercoa-left-0 mercoa-w-0.5 mercoa-bg-mercoa-primary"}),jsx("input",{type:"checkbox",className:"mercoa-absolute mercoa-left-4 mercoa-top-1/2 -mercoa-mt-2 mercoa-h-4 mercoa-w-4 mercoa-rounded mercoa-border-gray-300 mercoa-text-mercoa-primary-text focus:mercoa-ring-mercoa-primary",value:Fr.id,checked:Br.includes(Fr),onChange:Dr=>Ar(Dr.target.checked?[...Br,Fr]:Br.filter(vr=>vr!==Fr))})]}),jsx("td",{className:classNames$1("mercoa-whitespace-nowrap mercoa-py-3 mercoa-pl-4 mercoa-pr-3 mercoa-text-sm mercoa-font-medium mercoa-text-gray-900 sm:mercoa-pl-3",Br.includes(Fr)?"mercoa-text-mercoa-primary-text":"mercoa-text-gray-900"),onClick:()=>{ce&&ce(Fr)},children:(Yr=Fr.vendor)==null?void 0:Yr.name}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-3 mercoa-text-sm mercoa-text-gray-900 mercoa-hidden sm:mercoa-table-cell",onClick:()=>{ce&&ce(Fr)},children:Fr.invoiceNumber}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-3 mercoa-text-sm mercoa-text-gray-900",onClick:()=>{ce&&ce(Fr)},children:dayjs$1(Fr.dueDate).format("MMM DD, YYYY")}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-3 mercoa-text-sm mercoa-text-gray-900",onClick:()=>{ce&&ce(Fr)},children:accounting.formatMoney(Fr.amount??"",currencyCodeToSymbol(Fr.currency))}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-3 mercoa-text-sm mercoa-hidden lg:mercoa-table-cell",onClick:()=>{ce&&ce(Fr)},children:jsx(InvoiceStatusPill,{invoice:Fr})}),ee.some(Dr=>Dr===javascript.Mercoa.InvoiceStatus.Scheduled||Dr===javascript.Mercoa.InvoiceStatus.Pending||Dr===javascript.Mercoa.InvoiceStatus.Paid)&&Fr.deductionDate&&jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-3 mercoa-text-sm mercoa-hidden lg:mercoa-table-cell",onClick:()=>{ce&&ce(Fr)},children:dayjs$1(Fr.deductionDate).format("MMM DD, YYYY")})]},Fr.id)})})]})]})}),jsx(TableNavigation,{data:nr,page:Er,setPage:br,hasMore:lr,startingAfter:mr,setStartingAfter:yr,count:fr,resultsPerPage:Mr,setResultsPerPage:Sr,downloadAll:Nr}),jsx(SchedulePaymentModal,{show:Ur,closeModal:rn,setDate:tn})]}):jsx(LoadingSpinner,{})}):jsx("div",{className:"mercoa-mt-7",children:jsx(Skeleton,{rows:10})})}function InvoiceStatusPill({invoice:ee}){let te="mercoa-bg-gray-100",ce="mercoa-text-black",re="",nr="";return ee.failureType===javascript.Mercoa.InvoiceFailureType.InsufficientFunds&&(nr=" - Insufficient Funds"),ee.status===javascript.Mercoa.InvoiceStatus.Draft?!ee.vendor||!ee.amount||!ee.dueDate?(te="mercoa-bg-yellow-100",ce="mercoa-text-black",re="Draft Incomplete"):(te="mercoa-bg-green-100",ce="mercoa-text-green-800",re="Draft Ready"):ee.status===javascript.Mercoa.InvoiceStatus.New?!ee.paymentSourceId||!ee.vendor||!ee.amount||!ee.dueDate?(te="mercoa-bg-yellow-100",ce="mercoa-text-gray-800",re="Incomplete"):(te="mercoa-bg-green-100",ce="mercoa-text-green-800",re="Ready for Review"):ee.status===javascript.Mercoa.InvoiceStatus.Approved?!ee.paymentSourceId||!ee.paymentDestinationId||!ee.vendor||!ee.amount||!ee.dueDate?(te="mercoa-bg-yellow-100",ce="mercoa-text-black",re="Incomplete"):(te="mercoa-bg-green-100",ce="mercoa-text-green-800",re="Ready for Payment"):ee.status===javascript.Mercoa.InvoiceStatus.Scheduled?!ee.paymentSourceId||!ee.paymentDestinationId||!ee.vendor||!ee.amount||!ee.dueDate?(te="mercoa-bg-yellow-100",ce="mercoa-text-black",re="Incomplete"):(te="mercoa-bg-green-100",ce="mercoa-text-green-800",re="Payment Scheduled"):ee.status===javascript.Mercoa.InvoiceStatus.Pending?(te="mercoa-bg-yellow-100",ce="mercoa-text-black",re="Payment Processing"):ee.status===javascript.Mercoa.InvoiceStatus.Paid?(te="mercoa-bg-green-100",ce="mercoa-text-green-800",re="Paid"):ee.status===javascript.Mercoa.InvoiceStatus.Canceled?(te="mercoa-bg-red-100",ce="mercoa-text-red-800",re="Canceled"):ee.status===javascript.Mercoa.InvoiceStatus.Archived?(te="mercoa-bg-gray-100",ce="mercoa-text-black",re="Archived"):ee.status===javascript.Mercoa.InvoiceStatus.Refused?(te="mercoa-bg-red-100",ce="mercoa-text-red-800",re="Refused"):ee.status===javascript.Mercoa.InvoiceStatus.Failed&&(te="mercoa-bg-red-100",ce="mercoa-text-red-800",re="Failed "+nr),re?jsx("p",{className:`mercoa-inline-flex mercoa-items-center mercoa-whitespace-nowrap mercoa-rounded-full mercoa-px-3 mercoa-py-0.5 mercoa-text-xs mercoa-font-medium ${te} ${ce} md:mercoa-ml-2`,children:re}):jsx(Fragment,{})}function InvoiceInbox({statuses:ee,selectedStatus:te,onSelectInvoice:ce,onTabChange:re,children:nr}){const or=useMercoaSession(),[ar,ir]=React$1.useState(te??javascript.Mercoa.InvoiceStatus.Draft),[sr,cr]=React$1.useState(""),[lr,ur]=React$1.useState(),[fr,hr]=React$1.useState(ee??[javascript.Mercoa.InvoiceStatus.Draft,javascript.Mercoa.InvoiceStatus.New,javascript.Mercoa.InvoiceStatus.Approved,javascript.Mercoa.InvoiceStatus.Scheduled,javascript.Mercoa.InvoiceStatus.Pending,javascript.Mercoa.InvoiceStatus.Paid,javascript.Mercoa.InvoiceStatus.Canceled,javascript.Mercoa.InvoiceStatus.Failed]);React$1.useEffect(()=>{var Sr,Er;!or.token||!((Sr=or.entity)!=null&&Sr.id)||(Er=or.client)==null||Er.entity.approvalPolicy.getAll(or.entity.id).then(br=>ur(br)).catch(()=>ur(void 0))},[or.token,or.entity,or.refreshId]),React$1.useEffect(()=>{re&&re(ar)},[ar]),React$1.useEffect(()=>{Array.isArray(lr)&&(console.log(lr),ee?hr(ee):(!lr||(lr==null?void 0:lr.length)<1)&&hr(fr.filter(Sr=>Sr!==javascript.Mercoa.InvoiceStatus.New)))},[ee,lr]);const pr={DRAFT:"Inbox",NEW:"Ready for Review",APPROVED:lr!=null&&lr.length?"Approved":"Ready for Payment",SCHEDULED:"Payment Scheduled",PENDING:"Payment Processing",FAILED:"Payment Failed",PAID:"Paid",CANCELED:"Canceled",REFUSED:"Refused",ARCHIVED:"Archived"},[dr,mr]=React$1.useState();function yr(Sr){return Sr==null?void 0:Sr.reduce((Er,br)=>(Er+=br.totalCount,Er),0)}function Mr(Sr,Er){return!Sr||Sr.length<1?accounting.formatMoney(0,currencyCodeToSymbol("USD")):Sr.length<2?accounting.formatMoney(Sr[0][Er]??0??"",currencyCodeToSymbol(Sr[0].currency)):jsx("div",{children:Sr.map(br=>jsxs("p",{children:[jsx("span",{children:accounting.formatMoney(br[Er]??0??"",currencyCodeToSymbol(br.currency))}),jsxs("span",{className:"mercoa-text-gray-500 mercoa-text-xs",children:[" ",br.currency]})]},br.currency))})}return React$1.useEffect(()=>{var Er;if(!or.token||!((Er=or.entity)!=null&&Er.id))return;async function Sr(){const br=(await Promise.all((fr??[]).map(async xr=>{var wr,Ir;if(!or.token||!((wr=or.entity)!=null&&wr.id))return;const jr=await((Ir=or.client)==null?void 0:Ir.entity.invoice.metrics(or.entity.id,{search:sr,status:xr,excludeReceivables:!0}));return[xr,jr]}))).filter(xr=>xr),_r=Object.fromEntries(br);mr(_r)}Sr()},[sr,ee,or.client,or.entity,or.refreshId]),Object.keys(dr??{}).length<1?jsx(LoadingSpinner,{}):jsxs("div",{className:"mercoa-mt-8",children:[jsxs("div",{className:"mercoa-grid mercoa-items-center mercoa-grid-cols-3",children:[jsx("div",{className:"mercoa-hidden md:mercoa-block md:mercoa-col-span-2"}),jsx("div",{className:"mercoa-mt-2 mercoa-flex mercoa-w-full mercoa-rounded-md mercoa-shadow-sm mercoa-mr-2 mercoa-col-span-3 md:mercoa-col-span-1",children:jsx(DebouncedSearch,{placeholder:"Search Vendors",onSettle:cr})})]}),jsxs("div",{className:"md:mercoa-hidden mercoa-mt-2",children:[jsx("label",{htmlFor:"tabs",className:"mercoa-sr-only",children:"Select a tab"}),jsx("select",{id:"tabs",name:"tabs",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-py-1 mercoa-pl-3 mercoa-pr-10 mercoa-text-base focus:mercoa-border-mercoa-primary focus:mercoa-outline-none focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm",defaultValue:ar,onChange:Sr=>{ir(Sr.target.value)},children:fr.map(Sr=>jsx("option",{value:Sr,children:pr[Sr]},Sr))})]}),jsx("div",{className:"mercoa-hidden md:mercoa-block sm:mercoa-border-b sm:mercoa-border-gray-200",children:jsx("nav",{className:"-mercoa-mb-px mercoa-block sm:mercoa-flex sm:mercoa-space-x-6 mercoa-overflow-auto","aria-label":"Tabs",children:fr.map(Sr=>jsxs("a",{onClick:()=>{ir(Sr)},href:"#",className:`${Sr==ar?"mercoa-text-mercoa-primary sm:mercoa-border-mercoa-primary":"mercoa-border-transparent mercoa-text-gray-500 hover:mercoa-border-gray-300 hover:mercoa-text-gray-700"} mercoa-mr-2 mercoa-whitespace-nowrap mercoa-py-4 mercoa-px-1 mercoa-text-sm mercoa-font-medium sm:mercoa-mr-0 sm:mercoa-border-b-2`,"aria-current":pr[Sr]==ar?"page":void 0,children:[pr[Sr]," ",jsxs("span",{className:`${Sr==ar?"mercoa-bg-mercoa-primary mercoa-text-mercoa-primary-text-invert":"mercoa-bg-gray-100 mercoa-text-gray-800"} mercoa-inline-flex mercoa-items-center mercoa-rounded-full mercoa-px-2.5 mercoa-py-0.5 mercoa-text-xs mercoa-font-medium`,children:[" ",yr((dr==null?void 0:dr[Sr])??[])]})]},Sr))})}),jsxs("div",{className:"mercoa-grid mercoa-grid-cols-3 mercoa-space-x-3 mercoa-mt-2",children:[jsx(StatCard,{size:"sm",title:`Total ${pr[ar]} Invoices`,value:yr((dr==null?void 0:dr[ar])??[])}),jsx(StatCard,{size:"sm",title:`Total ${pr[ar]} Amount`,value:Mr((dr==null?void 0:dr[ar])??[],"totalAmount")}),jsx(StatCard,{size:"sm",title:`Average ${pr[ar]} Amount`,value:Mr((dr==null?void 0:dr[ar])??[],"averageAmount")})]}),ar===javascript.Mercoa.InvoiceStatus.New&&jsx(ApprovalsTable,{search:sr,onClick:ce}),jsx(InvoiceInboxTable,{status:[ar],search:sr,onClick:ce})]})}var relativeTime$1={exports:{}};(function(ee,te){(function(ce,re){ee.exports=re()})(commonjsGlobal$1,function(){return function(ce,re,nr){ce=ce||{};var or=re.prototype,ar={future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"};function ir(cr,lr,ur,fr){return or.fromToBase(cr,lr,ur,fr)}nr.en.relativeTime=ar,or.fromToBase=function(cr,lr,ur,fr,hr){for(var pr,dr,mr,yr=ur.$locale().relativeTime||ar,Mr=ce.thresholds||[{l:"s",r:44,d:"second"},{l:"m",r:89},{l:"mm",r:44,d:"minute"},{l:"h",r:89},{l:"hh",r:21,d:"hour"},{l:"d",r:35},{l:"dd",r:25,d:"day"},{l:"M",r:45},{l:"MM",r:10,d:"month"},{l:"y",r:17},{l:"yy",d:"year"}],Sr=Mr.length,Er=0;Er<Sr;Er+=1){var br=Mr[Er];br.d&&(pr=fr?nr(cr).diff(ur,br.d,!0):ur.diff(cr,br.d,!0));var _r=(ce.rounding||Math.round)(Math.abs(pr));if(mr=pr>0,_r<=br.r||!br.r){_r<=1&&Er>0&&(br=Mr[Er-1]);var xr=yr[br.l];hr&&(_r=hr(""+_r)),dr=typeof xr=="string"?xr.replace("%d",_r):xr(_r,lr,br.l,mr);break}}if(lr)return dr;var jr=mr?yr.future:yr.past;return typeof jr=="function"?jr(dr):jr.replace("%s",dr)},or.to=function(cr,lr){return ir(cr,lr,this,!0)},or.from=function(cr,lr){return ir(cr,lr,this)};var sr=function(cr){return cr.$u?nr.utc():nr()};or.toNow=function(cr){return this.to(sr(this),cr)},or.fromNow=function(cr){return this.from(sr(this),cr)}}})})(relativeTime$1);var relativeTimeExports=relativeTime$1.exports;const relativeTime=getDefaultExportFromCjs(relativeTimeExports),URL$1="https://js.moov.io/v1",URL_REGEX=/^https:\/\/js\.moov\.io\/v1\/?(\?.*)?$/,EXISTING_SCRIPT_MESSAGE="loadMoov.setLoadParameters was called but an existing Moov.js script already exists in the document; existing script parameters will be used",findScript=()=>{const ee=document.querySelectorAll(`script[src^="${URL$1}"]`);for(let te=0;te<ee.length;te++){const ce=ee[te];if(URL_REGEX.test(ce.src))return ce}return null},injectScript=()=>{const ee=document.createElement("script");ee.src=URL$1;const te=document.head||document.body;if(!te)throw new Error("Expected document.body not to be null. Moov.js requires a <body> element.");return te.appendChild(ee),ee};let moovPromise$1=null;const loadScript=()=>(moovPromise$1!==null||(moovPromise$1=new Promise((ee,te)=>{if(typeof window>"u"){ee(null);return}if(window.Moov&&console.warn(EXISTING_SCRIPT_MESSAGE),window.Moov){ee(window.Moov);return}try{let ce=findScript();ce?console.warn(EXISTING_SCRIPT_MESSAGE):ce||(ce=injectScript()),ce.addEventListener("load",()=>{window.Moov?ee(window.Moov):te(new Error("Moov.js not available"))}),ce.addEventListener("error",()=>{te(new Error("Failed to load Moov.js"))})}catch(ce){te(ce);return}})),moovPromise$1),initMoov=(ee,te)=>ee===null?null:ee.apply(void 0,te),moovPromise=Promise.resolve().then(()=>loadScript());let loadCalled=!1;moovPromise.catch(ee=>{loadCalled||console.warn(ee)});function loadMoov(...ee){if(!window)throw new Error("@moovio/moov-js is intended for browser use only. For a server-side solution, try @moovio/node.");return loadCalled=!0,moovPromise.then(te=>initMoov(te,ee))}class InvalidTokenError extends Error{}InvalidTokenError.prototype.name="InvalidTokenError";function b64DecodeUnicode(ee){return decodeURIComponent(atob(ee).replace(/(.)/g,(te,ce)=>{let re=ce.charCodeAt(0).toString(16).toUpperCase();return re.length<2&&(re="0"+re),"%"+re}))}function base64UrlDecode(ee){let te=ee.replace(/-/g,"+").replace(/_/g,"/");switch(te.length%4){case 0:break;case 2:te+="==";break;case 3:te+="=";break;default:throw new Error("base64 string is not of the correct length")}try{return b64DecodeUnicode(te)}catch{return atob(te)}}function jwtDecode(ee,te){if(typeof ee!="string")throw new InvalidTokenError("Invalid token specified: must be a string");te||(te={});const ce=te.header===!0?0:1,re=ee.split(".")[ce];if(typeof re!="string")throw new InvalidTokenError(`Invalid token specified: missing part #${ce+1}`);let nr;try{nr=base64UrlDecode(re)}catch(or){throw new InvalidTokenError(`Invalid token specified: invalid base64 for part #${ce+1} (${or.message})`)}try{return JSON.parse(nr)}catch(or){throw new InvalidTokenError(`Invalid token specified: invalid json for part #${ce+1} (${or.message})`)}}const sessionContext=React$1.createContext({token:"",entityId:"",entity:void 0,user:void 0,users:[],selectedInvoice:void 0,setSelectedInvoice:()=>{},client:void 0,refresh:()=>{},refreshId:0,organization:void 0,moov:void 0,moovToken:void 0,moovAccountId:void 0,iframeOptions:void 0,setIframeOptions:()=>{},getNewToken:ee=>{},googleMapsApiKey:void 0});function MercoaSession({children:ee,entityId:te,entityUserId:ce,token:re,endpoint:nr,isAdmin:or,googleMapsApiKey:ar}){return jsx(sessionContext.Provider,{value:useProvideSession({token:re,entityId:te,entityUserId:ce,endpoint:nr,isAdmin:or,googleMapsApiKey:ar}),children:ee||jsx(EntityPortal,{token:re})})}const useMercoaSession=()=>React$1.useContext(sessionContext);function useProvideSession({token:ee,entityId:te,entityUserId:ce,endpoint:re,isAdmin:nr,googleMapsApiKey:or}){var Zr;const[ar,ir]=React$1.useState(),[sr,cr]=React$1.useState(),[lr,ur]=React$1.useState([]),[fr,hr]=React$1.useState(),[pr,dr]=React$1.useState(),[mr,yr]=React$1.useState(0),[Mr,Sr]=React$1.useState(),[Er,br]=React$1.useState(),[_r,xr]=React$1.useState(),[jr,wr]=React$1.useState(ee),[Ir,Br]=React$1.useState(),Ar=React$1.useMemo(()=>new javascript.MercoaClient({environment:re??"https://api.mercoa.com",token:jr}),[jr]);async function Ur(){if(!ee)return;let nn=te;if(!nn)try{const{entityId:rn}=jwtDecode(String(ee));nn=rn}catch(rn){console.error(rn)}if(nn!=="undefined"&&(Ar.organization.get({paymentMethods:!0,emailProvider:!0,colorScheme:!0,payeeOnboardingOptions:!0,payorOnboardingOptions:!0,metadataSchema:!0}).then(rn=>{dr(rn)}),nn!=="all"&&nn)){Ar.entity.get(nn).then(tn=>{ir(tn),yr(Math.random())});let rn=ce;if(!rn)try{const{userId:tn}=jwtDecode(String(ee));rn=tn}catch(tn){console.error(tn)}rn&&Ar.entity.user.get(nn,rn).then(tn=>{cr(tn)}),Ar.entity.user.getAll(nn).then(tn=>{ur(tn)}),!Mr&&!nr&&Ar.entity.getToken(nn,{}).then(async tn=>{wr(tn);const{moov:Nr}=jwtDecode(String(tn));if(br(Nr.accountId),xr(Nr.token),!(!Nr||!Nr.token||Nr.token==="sandbox"))try{const Fr=await loadMoov(Nr.token);Fr&&Sr(Fr)}catch(Fr){console.error(Fr)}})}}async function Lr(nn){const rn=Ir||{options:{expiresIn:nn??"12hr"}};if(rn.options||(rn.options={}),rn.options.expiresIn=nn??"12hr",!(ar!=null&&ar.id))return;let tn="";sr!=null&&sr.id?tn=await Ar.entity.user.getToken(ar.id,sr.id,{...rn.options}):tn=await Ar.entity.getToken(ar.id,{...rn.options}),wr(tn)}return React$1.useEffect(()=>{if(!(pr!=null&&pr.colorScheme))return;const nn=(vr,Or)=>{vr=vr.replace(/^#/,""),vr.length===3&&(vr=vr[0]+vr[0]+vr[1]+vr[1]+vr[2]+vr[2]);let[Tr,Pr,gr]=vr.match(/.{2}/g);[Tr,Pr,gr]=[parseInt(Tr,16)+Or,parseInt(Pr,16)+Or,parseInt(gr,16)+Or],Tr=Math.max(Math.min(255,Tr),0).toString(16),Pr=Math.max(Math.min(255,Pr),0).toString(16),gr=Math.max(Math.min(255,gr),0).toString(16);const $r=(Tr.length<2?"0":"")+Tr,Rr=(Pr.length<2?"0":"")+Pr,kr=(gr.length<2?"0":"")+gr;return`#${$r}${Rr}${kr}`},rn=pr.colorScheme.logoBackgroundColor||"transparent",tn=pr.colorScheme.primaryColor||"#4f46e5",Nr=nn(tn,40),Fr=nn(tn,-40);let Yr=tn,Dr="#ffffff";tn==="#f8fafc"&&(Yr="#111827",Dr="#111827"),document.documentElement.style.setProperty("--mercoa-logo-background",rn),document.documentElement.style.setProperty("--mercoa-primary",tn),document.documentElement.style.setProperty("--mercoa-primary-light",Nr),document.documentElement.style.setProperty("--mercoa-primary-dark",Fr),document.documentElement.style.setProperty("--mercoa-primary-text",Yr),document.documentElement.style.setProperty("--mercoa-primary-text-invert",Dr)},[(Zr=pr==null?void 0:pr.colorScheme)==null?void 0:Zr.primaryColor]),React$1.useEffect(()=>{Ur()},[ee,te]),{refresh:Ur,refreshId:mr,token:ee,entityId:te??(ar==null?void 0:ar.id),entity:ar,user:sr,users:lr,selectedInvoice:fr,setSelectedInvoice:hr,client:Ar,organization:pr,moov:Mr,moovAccountId:Er,moovToken:_r,iframeOptions:Ir,setIframeOptions:Br,getNewToken:Lr,googleMapsApiKey:or}}dayjs$1.extend(relativeTime);function InvoiceComments({invoice:ee}){var fr;const te=useMercoaSession(),[ce,re]=React$1.useState((ee==null?void 0:ee.comments)??[]),{register:nr,handleSubmit:or,setValue:ar}=useForm({defaultValues:{type:"comment",text:""}});function ir({type:hr,text:pr}){var dr,mr,yr;if(!((dr=te.user)!=null&&dr.id)){Q$1.error("Please login as a user to comment");return}!te.token||!(ee!=null&&ee.id)||pr&&hr==="comment"&&((yr=te.client)==null||yr.invoice.comment.create(ee.id,{text:pr,userId:(mr=te.user)==null?void 0:mr.id}).then(Mr=>{Mr&&(console.log(Mr),re([...ce,Mr]),ar("text",""))}))}function sr(hr){let pr=jsx("div",{className:"mercoa-h-1.5 mercoa-w-1.5 mercoa-rounded-full mercoa-bg-gray-100 mercoa-ring-1 mercoa-ring-gray-300"});return hr.action==="APPROVE"?pr=jsx(CheckCircleIcon$1,{className:"mercoa-h-6 mercoa-w-6 mercoa-text-green-600","aria-hidden":"true"}):hr.action==="REJECT"&&(pr=jsx(XCircleIcon$1,{className:"mercoa-h-6 mercoa-w-6 mercoa-text-red-600","aria-hidden":"true"})),pr}const cr={APPROVE:"approved",REJECT:"rejected",NONE:"created"},lr=ce.filter(hr=>hr.text||hr.associatedApprovalAction),ur={id:(ee==null?void 0:ee.id)??"",createdAt:(ee==null?void 0:ee.createdAt)??"",user:(ee==null?void 0:ee.creatorUser)??{id:"",name:"Email"},text:"",associatedApprovalAction:{action:javascript.Mercoa.ApproverAction.None,userId:((fr=ee==null?void 0:ee.creatorUser)==null?void 0:fr.id)??""}};return jsxs(Fragment,{children:[jsx("ul",{role:"list",className:"mercoa-space-y-6 mercoa-ml-1",children:[ur,...lr].map((hr,pr)=>{var dr,mr;return jsxs("li",{className:"mercoa-relative mercoa-flex mercoa-gap-x-4",children:[jsx("div",{className:`${pr===lr.length?"mercoa-h-6":"-mercoa-bottom-6"} mercoa-absolute mercoa-left-0 mercoa-top-0 mercoa-flex mercoa-w-6 mercoa-justify-center`,children:jsx("div",{className:"mercoa-w-px mercoa-bg-gray-200"})}),hr.text&&jsxs(Fragment,{children:[jsx(UserIcon$1,{className:"mercoa-h-8 mercoa-w-8 mercoa-text-gray-300 mercoa-mt-3 mercoa-text-gray-300 mercoa-bg-gray-100 mercoa-rounded-full mercoa-p-1 -mercoa-ml-1"}),jsxs("div",{className:"mercoa-flex-auto mercoa-rounded-md mercoa-p-3 mercoa-ring-1 mercoa-ring-inset mercoa-ring-gray-200",children:[jsxs("div",{className:"mercoa-flex mercoa-justify-between mercoa-gap-x-4",children:[jsxs("div",{className:"mercoa-py-0.5 mercoa-text-xs mercoa-leading-5 mercoa-text-gray-500",children:[jsx("span",{className:"mercoa-font-medium mercoa-text-gray-900",children:(dr=hr.user)==null?void 0:dr.name})," commented"]}),jsx("time",{dateTime:dayjs$1(hr.createdAt).toISOString(),className:"mercoa-flex-none mercoa-py-0.5 mercoa-text-xs mercoa-leading-5 mercoa-text-gray-500",children:dayjs$1(hr.createdAt).fromNow()})]}),jsx("p",{className:"mercoa-text-sm mercoa-leading-6 mercoa-text-gray-500",children:hr.text})]})]}),hr.associatedApprovalAction&&jsxs(Fragment,{children:[jsx("div",{className:"mercoa-relative mercoa-flex mercoa-h-6 mercoa-w-6 mercoa-flex-none mercoa-items-center mercoa-justify-center mercoa-bg-white",children:sr(hr.associatedApprovalAction)}),jsxs("p",{className:"mercoa-flex-auto mercoa-py-0.5 mercoa-text-xs mercoa-leading-5 mercoa-text-gray-500",children:[jsx("span",{className:"mercoa-font-medium mercoa-text-gray-900",children:(mr=hr.user)==null?void 0:mr.name})," ",cr[hr.associatedApprovalAction.action]," the invoice."]}),jsx("time",{dateTime:dayjs$1(hr.createdAt).toISOString(),className:"mercoa-flex-none mercoa-py-0.5 mercoa-text-xs mercoa-leading-5 mercoa-text-gray-500",children:dayjs$1(hr.createdAt).fromNow()})]})]},hr.id)})}),jsx("div",{className:"mercoa-mt-6 mercoa-flex mercoa-gap-x-3",children:jsxs("form",{onSubmit:or(ir),className:"mercoa-relative mercoa-flex-auto",children:[jsxs("div",{className:"mercoa-overflow-hidden mercoa-rounded-lg mercoa-pb-12 mercoa-shadow-sm mercoa-ring-1 mercoa-ring-inset mercoa-ring-gray-300 focus-within:mercoa-ring-2 focus-within:mercoa-ring-indigo-600",children:[jsx("label",{htmlFor:"comment",className:"mercoa-sr-only",children:"Add your comment"}),jsx("textarea",{rows:2,...nr("text"),className:"mercoa-block mercoa-w-full mercoa-resize-none mercoa-border-0 mercoa-bg-transparent mercoa-py-1.5 mercoa-text-gray-900 placeholder:mercoa-text-gray-400 focus:mercoa-ring-0 sm:mercoa-text-sm sm:mercoa-leading-6",placeholder:"Add your comment..."})]}),jsxs("div",{className:"mercoa-absolute mercoa-inset-x-0 mercoa-bottom-0 mercoa-flex mercoa-justify-between mercoa-py-2 mercoa-pl-3 mercoa-pr-2",children:[jsx("div",{}),jsx("button",{type:"submit",className:"mercoa-rounded-md mercoa-bg-white mercoa-px-2.5 mercoa-py-1.5 mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 mercoa-shadow-sm mercoa-ring-1 mercoa-ring-inset mercoa-ring-gray-300 hover:mercoa-bg-gray-50",children:"Comment"})]})]})})]})}const dJSON=require("dirty-json");dayjs$1.extend(minMax);function classNames(...ee){return ee.filter(Boolean).join(" ")}function InvoiceDetails({invoiceId:ee,invoice:te,onRedirect:ce,addPaymentMethodRedirect:re,children:nr}){var Br;const or=useMercoaSession(),[ar,ir]=React$1.useState(),[sr,cr]=React$1.useState(),[lr,ur]=React$1.useState(),[fr,hr]=React$1.useState(!1),[pr,dr]=React$1.useState(te),[mr,yr]=React$1.useState(),[Mr,Sr]=React$1.useState(typeof window<"u"?window.innerHeight-70:0),[Er,br]=React$1.useState(!1);async function _r(Ar){var Lr,Zr;if(!or.token||!((Lr=or.entity)!=null&&Lr.id))return;const Ur=await((Zr=or.client)==null?void 0:Zr.invoice.get(Ar));Ur&&dr(Ur)}async function xr(Ar){var Lr,Zr;if(!or.token||!((Lr=or.entity)!=null&&Lr.id))return;const Ur=await((Zr=or.client)==null?void 0:Zr.ocr.getAsyncOcr(Ar));Ur&&Ur.status===javascript.Mercoa.OcrJobStatus.Success?(cr(Ur.data),hr(!1)):Ur&&Ur.status===javascript.Mercoa.OcrJobStatus.Failed?(Q$1.error("OCR failed"),hr(!1)):setTimeout(()=>xr(Ar),5e3)}async function jr(Ar,Ur){var Lr;ir({fileReaderObj:Ar,mimeType:Ur.type}),ur(Ar),hr(!0);try{const Zr=await((Lr=or.client)==null?void 0:Lr.ocr.runAsyncOcr({entityId:or.entityId,image:Ar,mimeType:Ur.type}));Zr?xr(Zr==null?void 0:Zr.jobId):(Q$1.error("OCR failed"),hr(!1))}catch(Zr){console.log(Zr),Q$1.error("OCR failed"),hr(!1)}}React$1.useEffect(()=>{var Ar;!or.token||!((Ar=or.entity)!=null&&Ar.id)||!te&&ee&&_r(ee)},[te,ee,or.token,(Br=or.entity)==null?void 0:Br.id]);function wr(){Sr(window.innerHeight-70)}React$1.useEffect(()=>(wr(),window.addEventListener("resize",wr,!1),()=>{window.removeEventListener("resize",wr)}),[]),React$1.useEffect(()=>{var Ar;pr&&pr.hasDocuments&&((Ar=or.client)==null||Ar.invoice.document.getAll(pr.id).then(Ur=>{var Lr,Zr;Ur&&Ur.length>0&&(yr(Ur),ir({fileReaderObj:(Lr=Ur==null?void 0:Ur[0])==null?void 0:Lr.uri,mimeType:(Zr=Ur==null?void 0:Ur[0])==null?void 0:Zr.mimeType}))}))},[pr]);const Ir=jsx("div",{className:"mercoa-min-w-[300px] mercoa-mr-5",children:ar?jsxs(Fragment,{children:[jsxs("div",{className:`mercoa-text-center ${fr?"mercoa-block mercoa-mb-5":"mercoa-hidden"}`,children:[jsx("span",{className:"mercoa-text-gray-800 mercoa-w-full",children:" Extracting Invoice Details "}),jsx(ProgressBar,{})]}),jsx(InvoiceDocuments,{documents:new Array(ar),height:Mr})]}):jsx(InvoiceDocumentsUpload,{onFileUpload:jr})});return nr?jsx(Fragment,{children:nr({invoice:pr,documents:mr})}):!pr&&ee?jsx(LoadingSpinner,{}):jsxs(X$2,{children:[jsx(_$2,{minSize:0,children:Ir}),jsx(ne,{size:5,className:"mercoa-bg-gray-200 mercoa-cursor-ew-resize mercoa-invisible min-[450px]:mercoa-visible",children:jsx("div",{className:"mercoa-w-3 mercoa-h-10 mercoa-bg-gray-500 mercoa-absolute mercoa-top-1/2 mercoa-left-1/2 mercoa-transform -mercoa-translate-x-1/2 -mercoa-translate-y-1/2"})}),jsxs(_$2,{className:"mercoa-pl-5 mercoa-relative",minSize:400,children:[jsx("div",{className:"mercoa-flex mercoa-w-full mercoa-flex-row-reverse visible min-[450px]:mercoa-invisible mercoa-absolute mercoa-top-2",children:jsxs(MercoaButton,{isEmphasized:!0,size:"sm",type:"button",onClick:()=>{br(!Er)},className:"mercoa-mr-7 mercoa-z-20",children:["View ",Er?"Form":"Invoice"]})}),Er?jsx("div",{className:"mercoa-mt-20",children:Ir}):jsx(EditInvoiceForm,{invoice:pr,ocrResponse:sr,uploadedImage:lr,setUploadedImage:ur,onRedirect:ce,refreshInvoice:_r,addPaymentMethodRedirect:re,height:Mr})]})]})}function InvoiceDocumentsUpload({onFileUpload:ee}){const te=ce=>new Promise((re,nr)=>{const or=new FileReader;or.onload=()=>re(String(or.result)),or.onerror=nr,or.readAsDataURL(ce)});return jsx(Dropzone$1,{onDropAccepted:ce=>{te(ce[0]).then(re=>{ee(re,ce[0])})},onDropRejected:()=>{Q$1.error("Invalid file type")},minSize:0,maxSize:1e7,accept:{"application/pdf":[".pdf"],"image/png":[".png"],"image/gif":[".gif"],"image/tiff":[".tif",".tiff"],"image/jpeg":[".jpeg",".jpg"],"image/bmp":[".bmp"],"image/webp":[".webp"]},children:({getRootProps:ce,getInputProps:re,isDragActive:nr})=>jsx("div",{className:`mercoa-mt-2 mercoa-flex mercoa-justify-center mercoa-rounded-lg mercoa-border mercoa-border-dashed mercoa-border-gray-900/25 ${nr?"mercoa-border-mercoa-primary":"mercoa-border-gray-300"} mercoa-px-6 mercoa-py-10`,...ce(),children:jsxs("div",{className:"mercoa-text-center",children:[jsx(PhotoIcon$1,{className:"mercoa-mx-auto mercoa-h-12 mercoa-w-12 mercoa-text-gray-300","aria-hidden":"true"}),jsxs("div",{className:"mercoa-mt-4 mercoa-flex mercoa-text-sm mercoa-text-gray-600",children:[jsxs("label",{htmlFor:"file-upload",className:"mercoa-relative mercoa-cursor-pointer mercoa-rounded-md mercoa-bg-white mercoa-font-semibold mercoa-text-mercoa-primary focus-within:mercoa-outline-none focus-within:mercoa-ring-2 focus-within:mercoa-ring-mercoa-primary focus-within:mercoa-ring-offset-2 hover:mercoa-text-indigo-500",children:[jsx("span",{children:"Upload an invoice"}),jsx("input",{...re(),id:"file-upload",name:"file-upload",type:"file",className:"mercoa-sr-only"})]}),jsx("p",{className:"mercoa-pl-1",children:"or drag and drop"})]}),jsx("p",{className:"mercoa-text-xs mercoa-leading-5 mercoa-text-gray-600",children:"PNG, JPG, PDF up to 10MB"})]})})})}function InvoiceDocuments({documents:ee,height:te}){const[ce,re]=React$1.useState(),[nr,or]=React$1.useState(1),[ar,ir]=useDebounce(0,20),sr=React$1.useRef(null);React$1.useLayoutEffect(()=>{sr.current!==null&&ir(sr.current.getBoundingClientRect().width)},[sr]),useResizeObserver(sr,ur=>{ar&&Math.abs(ar-ur.contentRect.width)<20||ir(ur.contentRect.width)});const cr=jsx("div",{className:"mercoa-flex mercoa-justify-center",children:jsxs("nav",{className:"mercoa-isolate mercoa-inline-flex -mercoa-space-x-px mercoa-rounded-md mercoa-shadow-sm","aria-label":"Pagination",children:[jsxs("button",{type:"button",onClick:()=>or(Math.max(nr-1,1)),className:"mercoa-relative mercoa-inline-flex mercoa-items-center mercoa-rounded-l-md mercoa-px-2 mercoa-py-2 mercoa-text-gray-400 mercoa-ring-1 mercoa-ring-inset mercoa-ring-gray-300 hover:mercoa-bg-gray-50 focus:mercoa-z-20 focus:mercoa-outline-offset-0",children:[jsx("span",{className:"mercoa-sr-only",children:"Previous"}),jsx(ChevronLeftIcon$1,{className:"mercoa-h-5 mercoa-w-5","aria-hidden":"true"})]}),Array.from(new Array(ce),(ur,fr)=>jsx("button",{type:"button",onClick:()=>or(fr+1),"aria-current":nr!=fr+1?"false":"page",className:nr!=fr+1?"mercoa-relative mercoa-inline-flex mercoa-items-center mercoa-px-4 mercoa-py-2 mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 mercoa-ring-1 mercoa-ring-inset mercoa-ring-gray-300 hover:mercoa-bg-gray-50 focus:mercoa-z-20 focus:mercoa-outline-offset-0":"mercoa-relative mercoa-z-10 mercoa-inline-flex mercoa-items-center mercoa-bg-mercoa-primary mercoa-px-4 mercoa-py-2 mercoa-text-sm mercoa-font-semibold mercoa-text-white focus:mercoa-z-20 focus-visible:outline focus-visible:mercoa-outline-2 focus-visible:mercoa-outline-offset-2 focus-visible:mercoa-outline-mercoa-primary",children:fr+1},fr)),jsxs("button",{type:"button",onClick:()=>or(Math.min(nr+1,ce??1)),className:"mercoa-relative mercoa-inline-flex mercoa-items-center mercoa-rounded-r-md mercoa-px-2 mercoa-py-2 mercoa-text-gray-400 mercoa-ring-1 mercoa-ring-inset mercoa-ring-gray-300 hover:mercoa-bg-gray-50 focus:mercoa-z-20 focus:mercoa-outline-offset-0",children:[jsx("span",{className:"mercoa-sr-only",children:"Next"}),jsx(ChevronRightIcon$1,{className:"mercoa-h-5 mercoa-w-5","aria-hidden":"true"})]})]})}),lr=jsx("div",{children:ee&&ee.length>0&&jsx("div",{ref:sr,children:ee.map((ur,fr)=>jsxs("div",{children:[jsx("div",{className:"mercoa-rounded-md mercoa-border mercoa-shadow-lg",style:{width:`${ar}px`},children:ur.mimeType==="application/pdf"?jsx(Document$1,{loading:jsx("div",{className:"mercoa-mt-2 mercoa-flex mercoa-w-full mercoa-items-center mercoa-justify-center",style:{height:"700px"},children:jsx(LoadingSpinnerIcon,{})}),file:ur.fileReaderObj,onLoadSuccess:({numPages:hr})=>re(hr),children:jsx(Page$1,{pageNumber:nr,className:"mercoa-m-0 mercoa-w-full mercoa-p-0 mercoa-mt-2",renderTextLayer:!1,renderAnnotationLayer:!1,width:ar-5})},ur.fileReaderObj):jsx("img",{src:ur.fileReaderObj,onLoad:()=>re(1),className:"mercoa-mt-2"},ur.fileReaderObj)}),jsx("a",{href:ur.fileReaderObj,target:"_blank",rel:"noreferrer",className:"mercoa-mt-2",download:!0,children:jsxs(MercoaButton,{type:"button",isEmphasized:!1,className:"mercoa-mt-2",children:[jsxs("span",{className:"mercoa-hidden xl:mercoa-inline",children:[jsx(ArrowDownTrayIcon$1,{className:"-mercoa-ml-1 mercoa-mr-2 mercoa-inline-flex mercoa-h-5 mercoa-w-5"})," ","Download Invoice"]}),jsx("span",{className:"mercoa-inline xl:mercoa-hidden",children:"Download"})]})})]},fr))})});return jsxs("div",{className:"mercoa-overflow-auto",style:{height:`${te}px`},children:[cr,lr]})}function EditInvoiceForm({invoice:ee,ocrResponse:te,uploadedImage:ce,setUploadedImage:re,onRedirect:nr,refreshInvoice:or,addPaymentMethodRedirect:ar,height:ir}){var gn,vn,Gr,Qr,cn,Xr,zr,Vr,un,Kr,hn,_n,zn,dn,mn,Wr,Pn,Un,Hr,Fn,pn,an,On,xn,kn,qn,Wn,Ln,Qn,Yn,$n,en,bn,Mn,Cn,ln,En,In,Gn;const sr=useMercoaSession(),[cr,lr]=React$1.useState([]),[ur,fr]=React$1.useState([]),[hr,pr]=React$1.useState([]),[dr,mr]=React$1.useState([]),[yr,Mr]=React$1.useState(ee==null?void 0:ee.vendor),[Sr,Er]=React$1.useState(),[br,_r]=React$1.useState([]),[xr,jr]=React$1.useState(!1),wr=An=>{const[Vn,Kn]=React$1.useState(0);return React$1.useLayoutEffect(()=>{Kn(An.current.getBoundingClientRect().width)},[An]),useResizeObserver(An,Hn=>Kn(Hn.contentRect.width)),Vn},Ir=React$1.useRef(null),Br=wr(Ir);let Ar="mercoa-grid-cols-1";Br&&Br>300&&(Ar="mercoa-grid-cols-2"),Br&&Br>500&&(Ar="mercoa-grid-cols-3"),Br&&Br>700&&(Ar="mercoa-grid-cols-4"),Br&&Br>900&&(Ar="mercoa-grid-cols-5"),Br&&Br>1100&&(Ar="mercoa-grid-cols-6");const Ur=create$3({amount:create$5().positive().required().typeError("Please enter a valid number"),invoiceNumber:create$6(),description:create$6(),dueDate:create$4().required("Please select a due date").typeError("Please select a due date"),deductionDate:create$4().typeError("Please select a deduction date"),invoiceDate:create$4().required("Please select an invoice date").typeError("Please select an invoice date"),approvers:create$8(),lineItems:create$2().of(create$3({id:create$6(),description:create$6().required(),amount:create$5().required().typeError("Please enter a valid number"),quantity:create$5().required().typeError("Please enter a valid number"),unitPrice:create$5().required().typeError("Please enter a valid number"),metadata:create$8().nullable(),glAccountId:create$6()})),currency:create$6().required(),vendorId:create$6(),vendorName:create$6(),paymentDestinationId:create$6(),paymentMethodDestinationType:create$6(),paymentSourceId:create$6(),paymentMethodSourceType:create$6(),saveAsDraft:create$7(),metadata:create$8().nullable()}).required(),{register:Lr,handleSubmit:Zr,setValue:nn,setError:rn,clearErrors:tn,watch:Nr,control:Fr,formState:{errors:Yr}}=useForm({resolver:o(Ur),defaultValues:{invoiceNumber:ee==null?void 0:ee.invoiceNumber,amount:ee==null?void 0:ee.amount,currency:(ee==null?void 0:ee.currency)??"USD",vendorId:(gn=ee==null?void 0:ee.vendor)==null?void 0:gn.id,vendorName:(vn=ee==null?void 0:ee.vendor)==null?void 0:vn.name,invoiceDate:ee!=null&&ee.invoiceDate?dayjs$1(ee==null?void 0:ee.invoiceDate).toDate():void 0,dueDate:ee!=null&&ee.dueDate?dayjs$1(ee==null?void 0:ee.dueDate).toDate():void 0,deductionDate:ee!=null&&ee.deductionDate?dayjs$1(ee==null?void 0:ee.deductionDate).toDate():void 0,lineItems:(ee==null?void 0:ee.lineItems)??[],paymentDestinationId:(Gr=ee==null?void 0:ee.paymentDestination)==null?void 0:Gr.id,paymentMethodDestinationType:"",paymentSourceId:(Qr=ee==null?void 0:ee.paymentSource)==null?void 0:Qr.id,paymentMethodSourceType:"",description:(ee==null?void 0:ee.noteToSelf)??"",saveAsDraft:!1,metadata:JSON.stringify((ee==null?void 0:ee.metadata)??{}),approvers:ee!=null&&ee.approvers?ee.approvers.map(An=>({approvalSlotId:An.approvalSlotId,assignedUserId:An.assignedUserId})):[]}}),Dr=Nr("amount"),vr=Nr("dueDate"),Or=Nr("currency"),Tr=Nr("vendorId"),Pr=Nr("vendorName"),gr=Nr("paymentDestinationId"),$r=Nr("paymentSourceId"),Rr=Nr("approvers"),kr=Nr("metadata"),{fields:Cr,append:qr,remove:on}=useFieldArray({control:Fr,name:"lineItems"});Nr((An,{name:Vn,type:Kn})=>{if(Kn!="change"||!(Vn!=null&&Vn.startsWith("lineItems"))||Vn.endsWith("amount")||Vn.endsWith("description")||Vn.endsWith("name"))return;let Xn=An.lineItems.reduce((Jn,Zn,so)=>(Zn.amount=Math.floor((Zn.quantity??1)*(Zn.unitPrice??1)*100)/100,nn(`lineItems.${so}.amount`,Zn.amount),Jn+Zn.amount),0);Xn=Math.floor(Xn*100)/100,nn("amount",Xn)}),React$1.useEffect(()=>{Er(ee==null?void 0:ee.approvers.map(An=>({assignedUserId:An.assignedUserId??"",approvalSlotId:An.approvalSlotId})))},[ee]),React$1.useEffect(()=>{var An,Vn,Kn,Hn;!sr.token||!((An=sr.entity)!=null&&An.id)||!sr.client||((Kn=sr.client)==null||Kn.entity.paymentMethod.getAll((Vn=sr.entity)==null?void 0:Vn.id).then(Xn=>{Xn&&lr(Xn)}),(Hn=sr.client)==null||Hn.customPaymentMethodSchema.getAll().then(Xn=>{var Jn,Zn;if(Xn){fr(Xn);let so=[];((Zn=(Jn=sr.organization)==null?void 0:Jn.paymentMethods)==null?void 0:Zn.payerPayments.some(fo=>fo.active&&(fo.type==="bankAccount"||fo.type==="card")))&&so.push("USD"),Xn.forEach(fo=>{fo.supportedCurrencies&&(so=[...new Set([...so,...fo.supportedCurrencies])])}),mr(so)}}))},[sr.client,(cn=sr.entity)==null?void 0:cn.id,sr.token]),React$1.useEffect(()=>{var An,Vn;!sr.token||!((An=sr.entity)!=null&&An.id)||(Vn=sr.client)==null||Vn.entity.metadata.getAll(sr.entity.id).then(Kn=>{Kn&&_r(Kn)})},[(Xr=sr.entity)==null?void 0:Xr.id,sr.refreshId,sr.token]),React$1.useEffect(()=>{dr.length>0&&nn("currency",(ee==null?void 0:ee.currency)??dr[0])},[dr]),React$1.useEffect(()=>{var An;!sr.token||!Tr||(An=sr.client)==null||An.entity.paymentMethod.getAll(Tr).then(Vn=>{Vn&&pr(Vn)})},[sr.client,Tr,sr.token]),React$1.useEffect(()=>{var An,Vn,Kn,Hn,Xn,Jn;te&&(te.invoice.amount&&nn("amount",te.invoice.amount),nn("invoiceNumber",te.invoice.invoiceNumber),te.invoice.invoiceDate&&nn("invoiceDate",te.invoice.invoiceDate),te.invoice.dueDate&&nn("dueDate",te.invoice.dueDate),nn("deductionDate",te.invoice.deductionDate),te.invoice.currency&&nn("currency",te.invoice.currency),te.invoice.metadata&&nn("metadata",JSON.stringify(te.invoice.metadata)),te.invoice.lineItems&&!((Kn=(Vn=(An=sr.iframeOptions)==null?void 0:An.options)==null?void 0:Vn.invoice)!=null&&Kn.disableLineItems)&&nn("lineItems",te.invoice.lineItems.map(Zn=>({description:Zn.description??"",amount:Zn.amount??0,quantity:Zn.quantity??0,unitPrice:Zn.unitPrice??0,name:Zn.name??"",metadata:Zn.metadata??{},glAccountId:Zn.glAccountId??"",id:Zn.id??"",createdAt:Zn.createdAt??new Date,updatedAt:Zn.updatedAt??new Date}))),yr||(te.vendor.id==="new"&&((Jn=(Xn=(Hn=sr.iframeOptions)==null?void 0:Hn.options)==null?void 0:Xn.vendors)!=null&&Jn.disableCreation)?console.log("new vendor creation disabled"):te.vendor.id&&(console.log("setting selected vendor",te.vendor),Mr(te.vendor))))},[te,yr]);let sn=!1;ee!=null&&ee.approvers?sn=!!(Rr!=null&&Rr.every(An=>!!An)):sn=!!(ee!=null&&ee.approvers.every(An=>An.assignedUserId));let yn=!!Dr&&!!vr&&!!Or&&!!Tr&&Tr!=="new"&&!!$r&&!!Pr;(un=(Vr=(zr=sr.iframeOptions)==null?void 0:zr.options)==null?void 0:Vr.vendors)!=null&&un.disableCreation||(yn=yn&&!!(yr!=null&&yr.email)&&!!(yr.accountType==="individual"||yr.accountType==="business"&&((Kr=yr.profile.business)!=null&&Kr.website||(hn=yr.profile.business)!=null&&hn.description)));const jn=(ee==null?void 0:ee.status)===javascript.Mercoa.InvoiceStatus.Approved&&yn&&(!gr||gr==="new"),wn=yn&&(ee==null?void 0:ee.status)===javascript.Mercoa.InvoiceStatus.Approved&&gr;let Dn=javascript.Mercoa.InvoiceStatus.Draft;wn?Dn=javascript.Mercoa.InvoiceStatus.Scheduled:jn||(ee==null?void 0:ee.status)===javascript.Mercoa.InvoiceStatus.New?Dn=javascript.Mercoa.InvoiceStatus.Approved:yn&&sn&&(Dn=javascript.Mercoa.InvoiceStatus.New);const Rn=async An=>{var Kn,Hn,Xn,Jn,Zn,so,po,fo,ho,yo;if(!sr.token||!((Kn=sr.entity)!=null&&Kn.id))return;const Vn={status:An.saveAsDraft?javascript.Mercoa.InvoiceStatus.Draft:Dn,amount:Number(An.amount),currency:An.currency,invoiceDate:An.invoiceDate,deductionDate:An.deductionDate,dueDate:An.dueDate,invoiceNumber:An.invoiceNumber,noteToSelf:An.description,payerId:(Hn=sr.entity)==null?void 0:Hn.id,paymentSourceId:An.paymentSourceId,approvers:An.approvers.filter(mo=>mo.assignedUserId),...An.vendorId!=="new"&&{vendorId:An.vendorId},paymentDestinationId:An.paymentDestinationId,lineItems:An.lineItems.map(mo=>({...mo.id&&{id:mo.id},description:mo.description,amount:Number(mo.amount),quantity:Number(mo.quantity),unitPrice:Number(mo.unitPrice),metadata:mo.metadata,currency:An.currency??"USD",glAccountId:mo.glAccountId})),metadata:JSON.parse(An.metadata),uploadedImage:ce,creatorEntityId:(Xn=sr.entity)==null?void 0:Xn.id};if(console.log({data:An,invoiceData:Vn}),An.paymentMethodDestinationType&&(!An.paymentDestinationId||An.paymentDestinationId==="new")){const mo=An.paymentMethodDestinationType,go=An.paymentMethodDestinationType.startsWith("cpms_")?"custom":An.paymentMethodDestinationType;let Eo;if(go==="bankAccount")Eo={type:go,accountNumber:An.accountNumber,routingNumber:An.routingNumber,accountType:An.accountType,bankName:An.bankName};else if(go==="check")Eo={type:go,...An};else if(go==="custom"){const wo={};Object.entries(An).forEach(([Ci,Di])=>{Ci.startsWith("~cpm~~")&&Di.forEach(Jo=>{wo[Jo.name]=`${wo[Jo.name]??Jo.value}`})}),Eo={type:go,foreignId:Math.random().toString(36).substring(7),schemaId:mo,data:wo}}if(Eo){const wo=await((Jn=sr.client)==null?void 0:Jn.entity.paymentMethod.create(An.vendorId,Eo));wo&&(Vn.paymentDestinationId=wo.id)}}if(Vn.status!==javascript.Mercoa.InvoiceStatus.Draft&&((Zn=Vn.approvers)==null?void 0:Zn.length)!==(ee==null?void 0:ee.approvers.length)){Q$1.error("Please assign all approvers for this invoice."),jr(!1);return}console.log("invoiceData before API call: ",{invoiceData:Vn}),ee?(fo=sr.client)==null||fo.invoice.update(ee.id,{...Vn,creatorUserId:((so=ee.creatorUser)==null?void 0:so.id)??((po=sr.user)==null?void 0:po.id)}).then(mo=>{mo&&(console.log("invoice/update API response: ",mo),re(void 0),Q$1.success("Invoice updated"),or(mo.id),jr(!1))}).catch(mo=>{console.log(mo.statusCode),console.log(mo.body),Q$1.error(`There was an error updating the invoice.
|
|
169
169
|
Error: ${mo.body}`),jr(!1)}):(yo=sr.client)==null||yo.invoice.create({...Vn,creatorUserId:(ho=sr.user)==null?void 0:ho.id}).then(mo=>{mo&&(console.log("invoice/create API response: ",mo),Q$1.success("Invoice created"),re(void 0),or(mo.id),nr(mo),jr(!1))}).catch(mo=>{console.log(mo.statusCode),console.log(mo.body),Q$1.error(`There was an error creating the invoice.
|
|
170
170
|
Error: ${mo.body}`),Q$1.error("There was an error creating the invoice. Make sure the invoice number is unique for this vendor and try again."),jr(!1)})},fn=(An,Vn,Kn)=>{const Hn=Sr==null?void 0:Sr.map((Xn,Jn)=>Jn===An?Vn:Xn);Er(Hn),Kn(Hn)};async function Sn(){var Vn;if(!(ee!=null&&ee.id))return;const An=await((Vn=sr.client)==null?void 0:Vn.invoice.getVendorLink(ee.id));An?navigator.clipboard.writeText(An).then(function(){Q$1.info("Link Copied")},function(Kn){Q$1.error("There was an issue generating the vendor link. Please refresh and try again.")}):Q$1.error("There was an issue generating the vendor link. Please refresh and try again.")}return jsxs("div",{style:{height:`${ir}px`},className:"mercoa-overflow-auto mercoa-pr-2 mercoa-pb-10",ref:Ir,children:[jsxs("h2",{className:"mercoa-text-base mercoa-font-semibold mercoa-leading-7 mercoa-text-gray-900",children:["Edit Invoice ",ee&&jsx(InvoiceStatusPill,{invoice:ee})]}),jsx("p",{className:"mercoa-mb-3 mercoa-text-xs mercoa-leading-6 mercoa-text-gray-400 mercoa-select-all",children:ee==null?void 0:ee.id}),jsx("div",{className:"mercoa-border-b mercoa-border-gray-900/10 mercoa-mb-4"}),jsxs("div",{className:"sm:mercoa-col-span-3",children:[jsx("label",{htmlFor:"vendor-name",className:"mercoa-block mercoa-text-lg mercoa-font-medium mercoa-leading-6 mercoa-text-gray-700",children:"Vendor"}),jsx("div",{className:"mercoa-mt-2 mercoa-flex mercoa-items-center mercoa-justify-left",children:jsx(CounterpartySearch,{type:"payee",onSelect:An=>{console.log({vendor:An}),Mr(An),nn("vendorId",(An==null?void 0:An.id)??void 0,{shouldTouch:!0,shouldDirty:!0}),nn("vendorName",(An==null?void 0:An.name)??void 0,{shouldTouch:!0,shouldDirty:!0})},counterparty:yr})})]}),jsx("div",{className:"mercoa-border-b mercoa-border-gray-900/10 mercoa-pb-6"}),jsxs("form",{onSubmit:Zr(Rn),className:`${Tr==="new"&&!((dn=(zn=(_n=sr.iframeOptions)==null?void 0:_n.options)==null?void 0:zn.vendors)!=null&&dn.disableCreation)?"mercoa-opacity-25 mercoa-pointer-events-none":""}
|
|
171
171
|
${Ar}
|
|
@@ -268,8 +268,8 @@ License: MIT
|
|
|
268
268
|
mercoa-text-sm mercoa-font-medium`,style:{top:-1*(ce??40)},children:te}),ee]})}function Skeleton({rows:ee,height:te}){return ee||(ee=1),te||(te=24),jsx("div",{className:"mercoa-flex mercoa-flex-col mercoa-space-y-2 mercoa-animate-pulse",children:[...Array(ee)].map(ce=>jsx("div",{className:"mercoa-w-full mercoa-rounded-md mercoa-bg-gray-200",style:{height:te+"px"}},ce))})}function DefaultPaymentMethodIndicator({paymentMethod:ee}){const te=useMercoaSession();return jsx(Fragment,{children:ee!=null&&ee.isDefaultSource?jsx("span",{className:"mercoa-inline-flex mercoa-items-center mercoa-rounded-full mercoa-bg-green-100 mercoa-px-2.5 mercoa-py-0.5 mercoa-text-xs mercoa-font-medium mercoa-text-green-800 mercoa-mr-2",children:"Default Payment Method"}):jsx(MercoaButton,{isEmphasized:!1,onClick:async ce=>{var re,nr,or;ce.preventDefault(),ce.stopPropagation(),te.token&&((re=te.entity)!=null&&re.id)&&(ee!=null&&ee.id)&&(await((or=te.client)==null?void 0:or.entity.paymentMethod.update((nr=te.entity)==null?void 0:nr.id,ee==null?void 0:ee.id,{type:"bankAccount",defaultSource:!0})),te.refresh())},size:"sm",className:"mercoa-mr-2",children:"Make Default"})})}function Switch({register:ee,name:te,label:ce,disabled:re}){return jsxs("label",{className:"mercoa-relative mercoa-inline-flex mercoa-cursor-pointer mercoa-items-center mercoa-mt-2",children:[jsx("input",{...ee(te),type:"checkbox",value:"",className:"mercoa-peer mercoa-sr-only",disabled:re}),jsx("div",{className:`mercoa-peer mercoa-h-6 mercoa-w-11 mercoa-rounded-full mercoa-bg-gray-300 after:mercoa-absolute after:mercoa-top-0.5 after:mercoa-left-[2px]
|
|
269
269
|
after:mercoa-h-5 after:mercoa-w-5 after:mercoa-rounded-full
|
|
270
270
|
after:border after:mercoa-border-gray-300 after:mercoa-bg-white after:mercoa-transition-all after:mercoa-content-[''] peer-checked:mercoa-bg-blue-600 peer-checked:after:mercoa-translate-x-full
|
|
271
|
-
peer-checked:after:mercoa-border-white peer-focus:mercoa-ring-4 peer-focus:mercoa-ring-blue-300 peer-disabled:mercoa-bg-red-100 peer-disabled:after:mercoa-bg-red-50`}),jsx("span",{className:"mercoa-ml-3 mercoa-flex mercoa-items-center mercoa-text-sm mercoa-font-medium mercoa-text-gray-900",children:ce})]})}function DebouncedSearch({onSettle:ee,placeholder:te}){const[ce,re]=React$1.useState(""),nr=React$1.useRef(debounce$1(ee,200)).current;return React$1.useEffect(()=>{nr(ce)},[ce]),jsx("input",{onChange:or=>re(or.target.value),type:"text",placeholder:te,className:"mercoa-block mercoa-w-48 mercoa-flex-1 mercoa-rounded-md mercoa-border-0 mercoa-py-1.5 mercoa-text-gray-900 mercoa-ring-1 mercoa-ring-inset mercoa-ring-gray-300 sm:mercoa-text-sm sm:mercoa-leading-6"})}function StatCard({title:ee,value:te,icon:ce,size:re}){const nr=re==="sm"?"mercoa-px-3 mercoa-py-2":"mercoa-px-4 mercoa-py-5 sm:mercoa-p-6",or=re==="sm"?"mercoa-text-xs":"mercoa-text-sm",ar=re==="sm"?"mercoa-text-md":"mercoa-text-3xl";return jsxs("div",{className:`mercoa-overflow-hidden mercoa-rounded-lg mercoa-bg-white ${nr} mercoa-shadow`,children:[jsx("dt",{className:`mercoa-truncate ${or} mercoa-font-medium mercoa-text-gray-500`,children:ee}),jsx("dd",{className:`mercoa-mt-1 ${ar} mercoa-font-semibold mercoa-tracking-tight mercoa-text-gray-900`,children:te})]},ee)}function MercoaCombobox({onChange:ee,options:te,value:ce,label:re,disabledText:nr,displayIndex:or,secondaryDisplayIndex:ar,multiple:ir,className:sr,labelClassName:cr,inputClassName:lr,freeText:ur}){const[fr,hr]=React$1.useState(""),[pr,dr]=React$1.useState(ce);React$1.useEffect(()=>{dr(ce)},[ce]),React$1.useEffect(()=>{ur&&fr!==""&&dr(fr)},[fr,ur]);const mr=fr===""?te:[...te.filter(br=>{const _r=or?br.value[or]:br.value;return _r==null?void 0:_r.toLowerCase().includes(fr.toLowerCase())}),...ur?[{value:fr,disabled:!1}]:[]],yr=mr.slice(0,100);function Mr(br){var _r;return ir&&Array.isArray(br)?(br==null?void 0:br.length)>0?(_r=br.map(xr=>(or?xr==null?void 0:xr[or]:xr)??""))==null?void 0:_r.join(", "):"":(or?br==null?void 0:br[or]:br)??""}function Sr(br){return Array.isArray(br)?br.join(", "):br}const Er=jsxs(Fragment,{children:[re&&jsx(qo.Label,{className:cr??"mercoa-block mercoa-text-sm mercoa-font-medium mercoa-leading-6 mercoa-text-gray-900",children:re}),jsxs("div",{className:`mercoa-relative ${re?"mercoa-mt-2":""}`,children:[jsx(qo.Button,{className:"mercoa-relative mercoa-w-full",children:({open:br})=>jsxs(Fragment,{children:[jsx(qo.Input,{autoComplete:"off",className:"mercoa-w-full mercoa-rounded-md mercoa-border-0 mercoa-bg-white mercoa-py-1.5 mercoa-pl-3 mercoa-pr-12 mercoa-text-gray-900 mercoa-shadow-sm mercoa-ring-1 mercoa-ring-inset mercoa-ring-gray-300 focus:mercoa-ring-2 focus:mercoa-ring-inset focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm sm:mercoa-leading-6 "+lr,onChange:_r=>hr(_r.target.value),displayValue:Mr,onClick:_r=>{br&&_r.stopPropagation()}}),jsx("div",{className:"mercoa-absolute mercoa-inset-y-0 mercoa-right-0 mercoa-flex mercoa-items-center mercoa-rounded-r-md mercoa-px-2 focus:mercoa-outline-none",children:jsx(ChevronUpDownIcon$1,{className:"mercoa-h-5 mercoa-w-5 mercoa-text-gray-400","aria-hidden":"true"})})]})}),yr.length>0&&jsxs(qo.Options,{className:"mercoa-absolute mercoa-z-10 mercoa-mt-1 mercoa-max-h-60 mercoa-w-full mercoa-overflow-auto mercoa-rounded-md mercoa-bg-white mercoa-py-1 mercoa-text-base mercoa-shadow-lg mercoa-ring-1 mercoa-ring-black mercoa-ring-opacity-5 focus:mercoa-outline-none sm:mercoa-text-sm ",children:[yr.map(({value:br,disabled:_r})=>jsx(qo.Option,{value:br,disabled:_r,className:({active:xr})=>classNames$1("mercoa-relative mercoa-cursor-default mercoa-select-none mercoa-py-2 mercoa-pl-3 mercoa-pr-9",xr?"mercoa-bg-mercoa-primary mercoa-text-mercoa-primary-text-invert":"mercoa-text-gray-900",_r?"mercoa-bg-gray-200 mercoa-text-gray-600":""),children:({active:xr,selected:jr,disabled:wr})=>{let Ir="";return wr?Ir=nr??"Disabled":ar&&(Array.isArray(ar)?(console.log(ar),Ir=ar.map(Br=>Sr(br[Br])).join(" - ")):Ir=Sr(br[ar])),jsxs(Fragment,{children:[jsxs("div",{className:"mercoa-flex",children:[jsx("span",{className:classNames$1("mercoa-truncate",jr&&"mercoa-font-semibold"),children:Sr(or?br[or]:br)}),ar&&jsx("span",{className:classNames$1("mercoa-ml-2 mercoa-truncate",xr?"mercoa-text-mercoa-primary-text-invert":"mercoa-text-gray-500",wr?"mercoa-text-gray-600":""),children:Ir})]}),jr&&jsx("span",{className:classNames$1("mercoa-absolute mercoa-inset-y-0 mercoa-right-0 mercoa-flex mercoa-items-center mercoa-pr-4",xr?"mercoa-text-mercoa-primary-text-invert":"mercoa-text-mercoa-primary"),children:jsx(CheckIcon$1,{className:"mercoa-h-5 mercoa-w-5","aria-hidden":"true"})})]})}},(br==null?void 0:br.id)??(or?br[or]:br))),yr.length!=mr.length&&jsx(qo.Option,{className:"mercoa-relative mercoa-cursor-default mercoa-select-none mercoa-py-2 mercoa-pl-3 mercoa-pr-9 mercoa-bg-gray-200 mercoa-text-gray-600",disabled:!0,value:"",children:jsx("div",{className:"mercoa-flex mercoa-justify-center mercoa-py-2",children:jsx("span",{className:"mercoa-text-gray-500",children:"Showing first 100 results. Please type to search all results."})})})]})]})]});return ir?jsx(qo,{as:"div",value:pr,onChange:br=>{dr(br),ee(br)},multiple:!0,className:sr,children:Er}):jsx(qo,{as:"div",value:pr,onChange:br=>{dr(br),ee(br)},className:sr,children:Er})}function TokenVerification({token:ee,children:te}){const ce=typeof window<"u"?window.location.search:"",re=new URLSearchParams(ce),nr=Object.fromEntries(re.entries()),or=ee??nr.t??nr.token??"";if(!or)return jsx(LoadingSpinner,{});const ar=jwtDecode(String(or));return ar.exp*1e3<Date.now()?jsx("main",{className:"mercoa-grid mercoa-min-h-full place-mercoa-items-center mercoa-bg-white mercoa-px-6 mercoa-py-24 sm:mercoa-py-32 lg:mercoa-px-8",children:jsxs("div",{className:"mercoa-text-center",children:[jsx("h1",{className:"mercoa-mt-4 mercoa-text-3xl mercoa-font-bold mercoa-tracking-tight mercoa-text-gray-900 sm:mercoa-text-5xl",children:"Link expired"}),jsx("p",{className:"mercoa-mt-6 mercoa-text-base mercoa-leading-7 mercoa-text-gray-600",children:"This link was set to expire after a certain amount of time. Please contact the person who shared this link with you."})]})}):jsx(MercoaSession,{googleMapsApiKey:dist.process.env.NEXT_PUBLIC_GOOGLE_MAPS,endpoint:getEndpoint(),token:or,children:te(ar,or)})}function LoadingSpinner({absolute:ee}){return jsx("div",{style:{position:ee?"absolute":"fixed",margin:"auto",top:0,left:0,bottom:0,right:0,height:"1px",width:"1px"},children:jsx(LoadingSpinnerIcon,{})})}function LoadingSpinnerIcon(){return jsxs("div",{role:"status",children:[jsxs("svg",{className:"mercoa-mr-2 mercoa-inline mercoa-h-8 mercoa-w-8 mercoa-animate-spin mercoa-fill-mercoa-primary mercoa-text-gray-200 dark:mercoa-text-gray-300",viewBox:"0 0 100 101",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z",fill:"currentColor"}),jsx("path",{d:"M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z",fill:"currentFill"})]}),jsx("span",{className:"mercoa-sr-only",children:"Loading..."})]})}const useDebounce=(ee=null,te=1e3)=>{const[ce,re]=React$1.useState(ee),nr=ar=>{or(ar)},or=React$1.useCallback(debounce$1(ar=>{re(ar)},te),[]);return[ce,nr]},nestedBg=["mercoa-bg-white","mercoa-bg-gray-50","mercoa-bg-indigo-50","mercoa-bg-green-50","mercoa-bg-yellow-50","mercoa-bg-blue-50"];function ArrowDownLeftIcon({className:ee}){return jsx("svg",{className:ee,viewBox:"0 0 256 256",xmlns:"http://www.w3.org/2000/svg",fill:"#999999",children:jsx("path",{d:"m210.828 178.829-48 48a4 4 0 0 1-5.656-5.658L198.342 180H64a4 4 0 0 1-4-4V32a4 4 0 0 1 8 0v140h130.343l-41.171-41.171a4 4 0 0 1 5.656-5.658l48 48a4.028 4.028 0 0 1 .499.61c.065.099.11.205.166.307a3.971 3.971 0 0 1 .201.382 3.92 3.92 0 0 1 .126.406c.034.114.078.223.1.34a4.01 4.01 0 0 1 0 1.567c-.022.118-.066.227-.1.34a3.902 3.902 0 0 1-.126.407 3.945 3.945 0 0 1-.2.382c-.057.102-.102.208-.167.306a4.028 4.028 0 0 1-.499.61Z"})})}function ApprovalPolicies(){var _r,xr,jr,wr;const ee=useMercoaSession(),[te,ce]=React$1.useState([]),[re,nr]=React$1.useState([]),[or,ar]=React$1.useState([]),[ir,sr]=React$1.useState([]),[cr,lr]=React$1.useState([]),{register:ur,handleSubmit:fr,watch:hr,setValue:pr,control:dr,reset:mr}=useForm({defaultValues:{policies:te}}),{append:yr,remove:Mr,fields:Sr}=useFieldArray({control:dr,name:"policies"}),Er=hr("policies");React$1.useEffect(()=>{var Ir;!ee.token||!((Ir=ee.entity)!=null&&Ir.id)||mr({policies:te})},[te]),React$1.useEffect(()=>{var Ir,Br;!ee.token||!((Ir=ee.entity)!=null&&Ir.id)||(Br=ee.client)==null||Br.entity.approvalPolicy.getAll(ee.entity.id).then(Ar=>{Ar&&ce(Ar)})},[(_r=ee.entity)==null?void 0:_r.id,ee.refreshId,ee.token]),React$1.useEffect(()=>{var Ir,Br;!ee.token||!((Ir=ee.entity)!=null&&Ir.id)||(Br=ee.client)==null||Br.entity.user.getAll(ee.entity.id).then(Ar=>{Ar&&(nr(Ar),ar([...new Set(Ar.map(Ur=>Ur.roles).flat())]))})},[(xr=ee.entity)==null?void 0:xr.id,ee.refreshId,ee.token]),React$1.useEffect(()=>{var Ir,Br;!ee.token||!((Ir=ee.entity)!=null&&Ir.id)||(Br=ee.client)==null||Br.entity.counterparty.findPayees(ee.entity.id,{limit:100}).then(Ar=>{Ar&&sr(Ar.data)})},[(jr=ee.entity)==null?void 0:jr.id,ee.refreshId,ee.token]),React$1.useEffect(()=>{var Ir,Br;!ee.token||!((Ir=ee.entity)!=null&&Ir.id)||(Br=ee.client)==null||Br.entity.metadata.getAll(ee.entity.id).then(Ar=>{Ar&&lr(Ar)})},[(wr=ee.entity)==null?void 0:wr.id,ee.refreshId,ee.token]);async function br(Ir){const Br=[];await Promise.all(te.map(async Ur=>{var Lr,Zr;if((Lr=ee.entity)!=null&&Lr.id&&!Ir.policies.find(nn=>nn.id==Ur.id))try{await((Zr=ee.client)==null?void 0:Zr.entity.approvalPolicy.delete(ee.entity.id,Ur.id)),Br.push({id:Ur.id,success:!0})}catch(nn){console.log(nn),Br.push({id:Ur.id,success:!1})}}));const Ar={root:"root"};Ir.policies.forEach(Ur=>{Ar[Ur.id]=Ur.id.indexOf("~")?"":Ur.id}),await Promise.all(Ir.policies.map(async(Ur,Lr)=>{var tn,Nr,Fr;if(!((tn=ee.entity)!=null&&tn.id))return;const Zr=Ur.trigger.map(Yr=>Yr.type=="amount"?{type:Yr.type,amount:Number(Yr.amount),currency:Yr.currency}:Yr.type=="vendor"?{type:Yr.type,vendorIds:Yr.vendorIds}:Yr.type=="metadata"?{type:Yr.type,key:Yr.key,value:Yr.value}:Yr);let nn=Ar[Ur.upstreamPolicyId];for(;!nn;)await new Promise(Yr=>setTimeout(Yr,100)),nn=Ar[Ur.upstreamPolicyId];const rn={upstreamPolicyId:nn,trigger:Zr,rule:{type:Ur.rule.type,numApprovers:Number(Ur.rule.numApprovers),identifierList:{type:Ur.rule.identifierList.type,value:Ur.rule.identifierList.value}}};if(Ur.rule.identifierList.type==="userList"&&rn.rule.numApprovers>rn.rule.identifierList.value.length){Q$1(`Error With Rule ${Lr+1}: Number of approvers cannot be more than number of users`,{type:"error"});return}try{let Yr;Ur!=null&&Ur.id&&(Ur==null?void 0:Ur.id.indexOf("~"))<0?Yr=await((Nr=ee.client)==null?void 0:Nr.entity.approvalPolicy.update(ee.entity.id,Ur.id,rn)):Yr=await((Fr=ee.client)==null?void 0:Fr.entity.approvalPolicy.create(ee.entity.id,rn)),Ar[Ur.id]=(Yr==null?void 0:Yr.id)??"",Br.push({id:Ur.id,success:!0})}catch(Yr){console.log(Yr),Br.push({id:Ur.id,success:!1})}})),Br.every(Ur=>Ur.success)?(Q$1("Approval Policies Saved",{type:"success"}),ee.refresh()):Q$1("Error Saving Some Approval Policies",{type:"error"})}return jsxs("form",{onSubmit:fr(br),className:"mercoa",children:[jsx(Level,{level:0,fields:Er,remove:Mr,append:yr,control:dr,watch:hr,register:ur,setValue:pr,users:re,roles:or,counterparties:ir,metadata:cr,formPolicies:Er,upstreamPolicyId:"root"}),jsx(MercoaButton,{isEmphasized:!0,size:"md",className:"mercoa-mt-5",children:"Save Rules"})]})}function Level({level:ee,upstreamPolicyId:te,fields:ce,remove:re,append:nr,control:or,watch:ar,register:ir,setValue:sr,users:cr,roles:lr,counterparties:ur,metadata:fr,formPolicies:hr}){const pr=ce.filter(dr=>dr.upstreamPolicyId===te);return jsxs("ul",{role:"list",className:`mercoa-space-y-6 mercoa-max-w-[800px] ${nestedBg[ee]}`,children:[jsxs("li",{className:`mercoa-relative mercoa-flex mercoa-gap-x-4 ${te==="root"?"":"mercoa-mt-1"}`,children:[jsx("div",{className:"-mercoa-bottom-6 mercoa-absolute mercoa-left-0 mercoa-top-0 mercoa-flex mercoa-w-6 mercoa-justify-center",children:jsx("div",{className:"mercoa-w-px mercoa-bg-gray-200"})}),te==="root"&&jsx("div",{className:`mercoa-relative mercoa-flex mercoa-h-6 mercoa-w-6 mercoa-flex-none mercoa-items-center mercoa-justify-center ${nestedBg[ee]}`,children:jsx(RocketLaunchIcon$1,{className:"mercoa-h-5 mercoa-w-5 mercoa-text-gray-300","aria-hidden":"true"})}),jsx("p",{className:"mercoa-flex-auto mercoa-py-0.5 mercoa-text-xs mercoa-leading-5 mercoa-text-gray-500",children:jsx("span",{className:"mercoa-font-medium mercoa-text-gray-900",children:te==="root"?"When an invoice is sent for approval:":""})})]}),pr.map((dr,mr)=>dr.trigger.length===0?jsx(Fragment,{}):jsxs("li",{className:"mercoa-relative mercoa-flex mercoa-gap-x-4",children:[jsx("div",{className:"-mercoa-bottom-6 mercoa-absolute mercoa-left-0 mercoa-top-0 mercoa-flex mercoa-w-6 mercoa-justify-center",children:jsx("div",{className:"mercoa-w-px mercoa-bg-gray-200"})}),jsx("div",{className:`mercoa-relative mercoa-flex mercoa-h-6 mercoa-w-6 mercoa-flex-none mercoa-items-center mercoa-justify-center ${nestedBg[ee]}`,children:jsx(SparklesIcon$1,{className:"mercoa-h-5 mercoa-w-5 mercoa-text-gray-300","aria-hidden":"true"})}),jsx("p",{className:"mercoa-flex-auto mercoa-py-0.5 mercoa-text-xs mercoa-leading-5 mercoa-text-gray-500",children:jsxs("div",{className:`font-medium mercoa-text-gray-900 mercoa-p-2 mercoa-pb-5 mercoa-rounded-md ${nestedBg[ee+1]}`,children:[jsxs("div",{className:"mercoa-grid mercoa-grid-cols-4 mercoa-gap-2 mercoa-p-3 mercoa-border mercoa-border-gray-200 mercoa-rounded-md mercoa-relative mercoa-bg-white",children:[jsxs("button",{className:"mercoa-absolute mercoa-top-2 mercoa-right-2 mercoa-text-gray-400 hover:mercoa-text-gray-500",type:"button",onClick:()=>re(ce.findIndex(yr=>yr.id==dr.id)),children:[jsx("span",{className:"mercoa-sr-only",children:"Remove"}),jsx(XMarkIcon$1,{className:"mercoa-h-5 mercoa-w-5"})]}),jsx(Trigger,{control:or,watch:ar,register:ir,setValue:sr,counterparties:ur,index:ce.findIndex(yr=>yr.id==dr.id),metadata:fr})]}),jsx(Rule,{watch:ar,register:ir,setValue:sr,users:cr,roles:lr,index:ce.findIndex(yr=>yr.id==dr.id),remove:()=>re(ce.findIndex(yr=>yr.id==dr.id))}),jsx("div",{className:"mercoa-ml-10",children:jsx(Level,{level:ee+1,fields:hr,remove:re,append:nr,control:or,watch:ar,register:ir,setValue:sr,users:cr,roles:lr,counterparties:ur,metadata:fr,formPolicies:hr,upstreamPolicyId:dr.id})})]})})]},mr)),jsxs("li",{className:"mercoa-relative mercoa-flex mercoa-gap-x-4",children:[te==="root"&&jsx("div",{className:"-mercoa-bottom-6 mercoa-absolute mercoa-left-0 mercoa-top-0 mercoa-flex mercoa-w-6 mercoa-justify-center",children:jsx("div",{className:"mercoa-w-px mercoa-bg-gray-200"})}),jsx("div",{className:`mercoa-relative mercoa-flex mercoa-h-6 mercoa-w-6 mercoa-flex-none mercoa-items-center mercoa-justify-center ${nestedBg[ee]}`,children:jsx("div",{className:"mercoa-h-1.5 mercoa-w-1.5 mercoa-rounded-full mercoa-bg-gray-100 mercoa-ring-1 mercoa-ring-gray-300"})}),jsx("p",{className:"mercoa-flex-auto mercoa-py-0.5 mercoa-text-xs mercoa-leading-5 mercoa-text-gray-500",children:jsx(AddRule,{id:te+"~"+pr.length,upstreamPolicyId:te,append:nr,trigger:[{type:"amount",amount:100,currency:javascript.Mercoa.CurrencyCode.Usd}]})})]}),te==="root"&&jsxs(Fragment,{children:[jsxs("li",{className:"mercoa-relative mercoa-gap-x-4",children:[jsxs("div",{className:"mercoa-flex",children:[jsx("div",{className:"-mercoa-bottom-6 mercoa-absolute mercoa-left-0 mercoa-top-0 mercoa-flex mercoa-w-6 mercoa-justify-center",children:jsx("div",{className:"mercoa-w-px mercoa-bg-gray-200"})}),jsx("div",{className:"mercoa-relative mercoa-flex mercoa-h-6 mercoa-w-6 mercoa-flex-none mercoa-items-center mercoa-justify-center mercoa-bg-white",children:jsx(ExclamationTriangleIcon$1,{className:"mercoa-h-5 mercoa-w-5 mercoa-text-gray-300","aria-hidden":"true"})}),jsx("p",{className:"mercoa-flex-auto mercoa-py-0.5 mercoa-text-xs mercoa-leading-5 mercoa-text-gray-500 mercoa-ml-4",children:jsxs("span",{className:"mercoa-font-medium mercoa-text-gray-900 ",children:["Always apply the following rule:",jsx("div",{className:"mercoa-mt-1",children:hr.filter(dr=>dr.trigger.length===0).length===0&&jsx(AddRule,{upstreamPolicyId:"root",append:nr,trigger:[],id:"fallback"})})]})})]}),ce.map((dr,mr)=>dr.trigger.length>0?jsx(Fragment,{}):jsx("div",{className:"mercoa-ml-10",children:jsx(Rule,{watch:ar,register:ir,setValue:sr,users:cr,roles:lr,index:ce.findIndex(yr=>yr.id==dr.id),noTrigger:!0,remove:()=>re(ce.findIndex(yr=>yr.id==dr.id))},ce.findIndex(yr=>yr.id==dr.id))},mr))]}),jsxs("li",{className:"mercoa-relative mercoa-flex mercoa-gap-x-4",children:[jsx("div",{className:"mercoa-h-6 mercoa-absolute mercoa-left-0 mercoa-top-0 mercoa-flex mercoa-w-6 mercoa-justify-center",children:jsx("div",{className:"mercoa-w-px mercoa-bg-gray-200"})}),jsx("div",{className:`mercoa-relative mercoa-flex mercoa-h-6 mercoa-w-6 mercoa-flex-none mercoa-items-center mercoa-justify-center ${nestedBg[ee]}`,children:jsx(CheckCircleIcon$1,{className:"mercoa-h-5 mercoa-w-5 mercoa-text-green-400","aria-hidden":"true"})}),jsx("p",{className:"mercoa-flex-auto mercoa-py-0.5 mercoa-text-xs mercoa-leading-5 mercoa-text-gray-500",children:jsx("span",{className:"mercoa-font-medium mercoa-text-gray-900",children:" Approve Invoice"})})]})]})]})}function Trigger({control:ee,watch:te,register:ce,setValue:re,counterparties:nr,index:or,metadata:ar}){const ir=useMercoaSession(),{append:sr,remove:cr,fields:lr}=useFieldArray({control:ee,name:`policies.${or}.trigger`}),ur=te(`policies.${or}.trigger`);return jsxs(Fragment,{children:[jsx("div",{className:"mercoa-col-span-4 mercoa-font-medium mercoa-text-gray-700 mercoa-mb-1",children:"If these conditions are true:"}),lr.map((fr,hr)=>{var dr,mr,yr,Mr,Sr,Er;const pr=ur.slice(0,hr).map(br=>br.type);return jsxs("div",{className:"mercoa-p-3 mercoa-bg-gray-50 mercoa-rounded-md mercoa-col-span-4 mercoa-flex mercoa-items-center",children:[jsx("span",{className:"mercoa-text-sm mercoa-font-medium mercoa-leading-6 mercoa-text-gray-900 mercoa-mr-2",children:hr>0?"And":"If"}),jsx(MercoaCombobox,{options:[...pr.every(br=>br!="amount")?[{displayName:"Amount",key:"~mercoa~amount"}]:[],...pr.every(br=>br!="vendor")?[{displayName:"Vendor",key:"~mercoa~vendor"}]:[],...((dr=ir.organization)==null?void 0:dr.metadataSchema)??[]].map(br=>({disabled:!1,value:br})),onChange:br=>{br.key=="~mercoa~amount"?re(`policies.${or}.trigger.${hr}.type`,"amount",{shouldDirty:!0}):br.key=="~mercoa~vendor"?re(`policies.${or}.trigger.${hr}.type`,"vendor",{shouldDirty:!0}):(re(`policies.${or}.trigger.${hr}.type`,"metadata",{shouldDirty:!0}),re(`policies.${or}.trigger.${hr}.key`,br.key,{shouldDirty:!0}),re(`policies.${or}.trigger.${hr}.value`,"",{shouldDirty:!0}))},value:()=>{var br,_r,xr,jr;return((br=ur[hr])==null?void 0:br.type)==="amount"?{displayName:"Amount",key:"~mercoa~amount"}:((_r=ur[hr])==null?void 0:_r.type)==="vendor"?{displayName:"Vendor",key:"~mercoa~vendor"}:(jr=(xr=ir.organization)==null?void 0:xr.metadataSchema)==null?void 0:jr.find(wr=>{var Ir;return wr.key==((Ir=ur[hr])==null?void 0:Ir.key)})},displayIndex:"displayName"}),((mr=ur[hr])==null?void 0:mr.type)=="amount"&&jsxs(Fragment,{children:[jsx("span",{className:"mercoa-text-sm mercoa-font-medium mercoa-leading-6 mercoa-text-gray-900 mercoa-ml-2 mercoa-mr-2",children:"more than or equal to"}),jsxs("div",{className:"mercoa-relative mercoa-rounded-md mercoa-shadow-sm mercoa-inline-block",children:[jsx("div",{className:"mercoa-pointer-events-none mercoa-absolute mercoa-inset-y-0 mercoa-left-0 mercoa-flex mercoa-items-center mercoa-pl-3",children:jsx("span",{className:"mercoa-text-gray-500 sm:mercoa-text-sm",children:currencyCodeToSymbol(ur[hr].currency)})}),jsx("input",{type:"text",...ce(`policies.${or}.trigger.${hr}.amount`),className:`mercoa-block mercoa-rounded-md mercoa-border-0 mercoa-py-1.5 mercoa-pr-[4.4rem] mercoa-text-gray-900 mercoa-ring-1 mercoa-ring-inset mercoa-ring-gray-300 placeholder:mercoa-text-gray-400 focus:mercoa-ring-2 focus:mercoa-ring-inset focus:mercoa-ring-primary sm:mercoa-text-sm sm:mercoa-leading-6
|
|
271
|
+
peer-checked:after:mercoa-border-white peer-focus:mercoa-ring-4 peer-focus:mercoa-ring-blue-300 peer-disabled:mercoa-bg-red-100 peer-disabled:after:mercoa-bg-red-50`}),jsx("span",{className:"mercoa-ml-3 mercoa-flex mercoa-items-center mercoa-text-sm mercoa-font-medium mercoa-text-gray-900",children:ce})]})}function DebouncedSearch({onSettle:ee,placeholder:te}){const[ce,re]=React$1.useState(""),nr=React$1.useRef(debounce$1(ee,200)).current;return React$1.useEffect(()=>{nr(ce)},[ce]),jsx("input",{onChange:or=>re(or.target.value),type:"text",placeholder:te,className:"mercoa-block mercoa-w-48 mercoa-flex-1 mercoa-rounded-md mercoa-border-0 mercoa-py-1.5 mercoa-text-gray-900 mercoa-ring-1 mercoa-ring-inset mercoa-ring-gray-300 sm:mercoa-text-sm sm:mercoa-leading-6"})}function StatCard({title:ee,value:te,icon:ce,size:re}){const nr=re==="sm"?"mercoa-px-3 mercoa-py-2":"mercoa-px-4 mercoa-py-5 sm:mercoa-p-6",or=re==="sm"?"mercoa-text-xs":"mercoa-text-sm",ar=re==="sm"?"mercoa-text-md":"mercoa-text-3xl";return jsxs("div",{className:`mercoa-overflow-hidden mercoa-rounded-lg mercoa-bg-white ${nr} mercoa-shadow`,children:[jsx("dt",{className:`mercoa-truncate ${or} mercoa-font-medium mercoa-text-gray-500`,children:ee}),jsx("dd",{className:`mercoa-mt-1 ${ar} mercoa-font-semibold mercoa-tracking-tight mercoa-text-gray-900`,children:te})]},ee)}function MercoaCombobox({onChange:ee,options:te,value:ce,label:re,disabledText:nr,displayIndex:or,secondaryDisplayIndex:ar,multiple:ir,className:sr,labelClassName:cr,inputClassName:lr,freeText:ur}){const[fr,hr]=React$1.useState(""),[pr,dr]=React$1.useState(ce);React$1.useEffect(()=>{dr(ce)},[ce]),React$1.useEffect(()=>{ur&&fr!==""&&dr(fr)},[fr,ur]);const mr=fr===""?te:[...te.filter(br=>{const _r=or?br.value[or]:br.value;return _r==null?void 0:_r.toLowerCase().includes(fr.toLowerCase())}),...ur?[{value:fr,disabled:!1}]:[]],yr=mr.slice(0,100);function Mr(br){var _r;return ir&&Array.isArray(br)?(br==null?void 0:br.length)>0?(_r=br.map(xr=>(or?xr==null?void 0:xr[or]:xr)??""))==null?void 0:_r.join(", "):"":(or?br==null?void 0:br[or]:br)??""}function Sr(br){return Array.isArray(br)?br.join(", "):br}const Er=jsxs(Fragment,{children:[re&&jsx(qo.Label,{className:cr??"mercoa-block mercoa-text-sm mercoa-font-medium mercoa-leading-6 mercoa-text-gray-900",children:re}),jsxs("div",{className:`mercoa-relative ${re?"mercoa-mt-2":""}`,children:[jsx(qo.Button,{className:"mercoa-relative mercoa-w-full",children:({open:br})=>jsxs(Fragment,{children:[jsx(qo.Input,{autoComplete:"off",className:"mercoa-w-full mercoa-rounded-md mercoa-border-0 mercoa-bg-white mercoa-py-1.5 mercoa-pl-3 mercoa-pr-12 mercoa-text-gray-900 mercoa-shadow-sm mercoa-ring-1 mercoa-ring-inset mercoa-ring-gray-300 focus:mercoa-ring-2 focus:mercoa-ring-inset focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm sm:mercoa-leading-6 "+lr,onChange:_r=>hr(_r.target.value),displayValue:Mr,onClick:_r=>{br&&_r.stopPropagation()}}),jsx("div",{className:"mercoa-absolute mercoa-inset-y-0 mercoa-right-0 mercoa-flex mercoa-items-center mercoa-rounded-r-md mercoa-px-2 focus:mercoa-outline-none",children:jsx(ChevronUpDownIcon$1,{className:"mercoa-h-5 mercoa-w-5 mercoa-text-gray-400","aria-hidden":"true"})})]})}),yr.length>0&&jsxs(qo.Options,{className:"mercoa-absolute mercoa-z-10 mercoa-mt-1 mercoa-max-h-60 mercoa-w-full mercoa-overflow-auto mercoa-rounded-md mercoa-bg-white mercoa-py-1 mercoa-text-base mercoa-shadow-lg mercoa-ring-1 mercoa-ring-black mercoa-ring-opacity-5 focus:mercoa-outline-none sm:mercoa-text-sm ",children:[yr.map(({value:br,disabled:_r})=>jsx(qo.Option,{value:br,disabled:_r,className:({active:xr})=>classNames$1("mercoa-relative mercoa-cursor-default mercoa-select-none mercoa-py-2 mercoa-pl-3 mercoa-pr-9",xr?"mercoa-bg-mercoa-primary mercoa-text-mercoa-primary-text-invert":"mercoa-text-gray-900",_r?"mercoa-bg-gray-200 mercoa-text-gray-600":""),children:({active:xr,selected:jr,disabled:wr})=>{let Ir="";return wr?Ir=nr??"Disabled":ar&&(Array.isArray(ar)?(console.log(ar),Ir=ar.map(Br=>Sr(br[Br])).join(" - ")):Ir=Sr(br[ar])),jsxs(Fragment,{children:[jsxs("div",{className:"mercoa-flex",children:[jsx("span",{className:classNames$1("mercoa-truncate",jr&&"mercoa-font-semibold"),children:Sr(or?br[or]:br)}),ar&&jsx("span",{className:classNames$1("mercoa-ml-2 mercoa-truncate",xr?"mercoa-text-mercoa-primary-text-invert":"mercoa-text-gray-500",wr?"mercoa-text-gray-600":""),children:Ir})]}),jr&&jsx("span",{className:classNames$1("mercoa-absolute mercoa-inset-y-0 mercoa-right-0 mercoa-flex mercoa-items-center mercoa-pr-4",xr?"mercoa-text-mercoa-primary-text-invert":"mercoa-text-mercoa-primary"),children:jsx(CheckIcon$1,{className:"mercoa-h-5 mercoa-w-5","aria-hidden":"true"})})]})}},(br==null?void 0:br.id)??(or?br[or]:br))),yr.length!=mr.length&&jsx(qo.Option,{className:"mercoa-relative mercoa-cursor-default mercoa-select-none mercoa-py-2 mercoa-pl-3 mercoa-pr-9 mercoa-bg-gray-200 mercoa-text-gray-600",disabled:!0,value:"",children:jsx("div",{className:"mercoa-flex mercoa-justify-center mercoa-py-2",children:jsx("span",{className:"mercoa-text-gray-500",children:"Showing first 100 results. Please type to search all results."})})})]})]})]});return ir?jsx(qo,{as:"div",value:pr,onChange:br=>{dr(br),ee(br)},multiple:!0,className:sr,children:Er}):jsx(qo,{as:"div",value:pr,onChange:br=>{dr(br),ee(br)},className:sr,children:Er})}function TokenVerification({token:ee,children:te}){const ce=typeof window<"u"?window.location.search:"",re=new URLSearchParams(ce),nr=Object.fromEntries(re.entries()),or=ee??nr.t??nr.token??"";if(!or)return jsx(LoadingSpinner,{});const ar=jwtDecode(String(or));return ar.exp*1e3<Date.now()?jsx("main",{className:"mercoa-grid mercoa-min-h-full place-mercoa-items-center mercoa-bg-white mercoa-px-6 mercoa-py-24 sm:mercoa-py-32 lg:mercoa-px-8",children:jsxs("div",{className:"mercoa-text-center",children:[jsx("h1",{className:"mercoa-mt-4 mercoa-text-3xl mercoa-font-bold mercoa-tracking-tight mercoa-text-gray-900 sm:mercoa-text-5xl",children:"Link expired"}),jsx("p",{className:"mercoa-mt-6 mercoa-text-base mercoa-leading-7 mercoa-text-gray-600",children:"This link was set to expire after a certain amount of time. Please contact the person who shared this link with you."})]})}):jsx(MercoaSession,{googleMapsApiKey:dist.process.env.NEXT_PUBLIC_GOOGLE_MAPS,endpoint:getEndpoint(),token:or,children:te(ar,or)})}function LoadingSpinner({absolute:ee}){return jsx("div",{style:{position:ee?"absolute":"fixed",margin:"auto",top:0,left:0,bottom:0,right:0,height:"1px",width:"1px"},children:jsx(LoadingSpinnerIcon,{})})}function LoadingSpinnerIcon(){return jsxs("div",{role:"status",children:[jsxs("svg",{className:"mercoa-mr-2 mercoa-inline mercoa-h-8 mercoa-w-8 mercoa-animate-spin mercoa-fill-mercoa-primary mercoa-text-gray-200 dark:mercoa-text-gray-300",viewBox:"0 0 100 101",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z",fill:"currentColor"}),jsx("path",{d:"M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z",fill:"currentFill"})]}),jsx("span",{className:"mercoa-sr-only",children:"Loading..."})]})}const useDebounce=(ee=null,te=1e3)=>{const[ce,re]=React$1.useState(ee),nr=ar=>{or(ar)},or=React$1.useCallback(debounce$1(ar=>{re(ar)},te),[]);return[ce,nr]},nestedBg=["mercoa-bg-white","mercoa-bg-gray-50","mercoa-bg-indigo-50","mercoa-bg-green-50","mercoa-bg-yellow-50","mercoa-bg-blue-50"];function ArrowDownLeftIcon({className:ee}){return jsx("svg",{className:ee,viewBox:"0 0 256 256",xmlns:"http://www.w3.org/2000/svg",fill:"#999999",children:jsx("path",{d:"m210.828 178.829-48 48a4 4 0 0 1-5.656-5.658L198.342 180H64a4 4 0 0 1-4-4V32a4 4 0 0 1 8 0v140h130.343l-41.171-41.171a4 4 0 0 1 5.656-5.658l48 48a4.028 4.028 0 0 1 .499.61c.065.099.11.205.166.307a3.971 3.971 0 0 1 .201.382 3.92 3.92 0 0 1 .126.406c.034.114.078.223.1.34a4.01 4.01 0 0 1 0 1.567c-.022.118-.066.227-.1.34a3.902 3.902 0 0 1-.126.407 3.945 3.945 0 0 1-.2.382c-.057.102-.102.208-.167.306a4.028 4.028 0 0 1-.499.61Z"})})}function ApprovalPolicies(){var _r,xr,jr,wr;const ee=useMercoaSession(),[te,ce]=React$1.useState([]),[re,nr]=React$1.useState([]),[or,ar]=React$1.useState([]),[ir,sr]=React$1.useState([]),[cr,lr]=React$1.useState([]),{register:ur,handleSubmit:fr,watch:hr,setValue:pr,control:dr,reset:mr}=useForm({defaultValues:{policies:te}}),{append:yr,remove:Mr,fields:Sr}=useFieldArray({control:dr,name:"policies"}),Er=hr("policies");React$1.useEffect(()=>{var Ir;!ee.token||!((Ir=ee.entity)!=null&&Ir.id)||mr({policies:te})},[te]),React$1.useEffect(()=>{var Ir,Br;!ee.token||!((Ir=ee.entity)!=null&&Ir.id)||(Br=ee.client)==null||Br.entity.approvalPolicy.getAll(ee.entity.id).then(Ar=>{Ar&&ce(Ar)})},[(_r=ee.entity)==null?void 0:_r.id,ee.refreshId,ee.token]),React$1.useEffect(()=>{var Ir,Br;!ee.token||!((Ir=ee.entity)!=null&&Ir.id)||(Br=ee.client)==null||Br.entity.user.getAll(ee.entity.id).then(Ar=>{Ar&&(nr(Ar),ar([...new Set(Ar.map(Ur=>Ur.roles).flat())]))})},[(xr=ee.entity)==null?void 0:xr.id,ee.refreshId,ee.token]),React$1.useEffect(()=>{var Ir,Br;!ee.token||!((Ir=ee.entity)!=null&&Ir.id)||(Br=ee.client)==null||Br.entity.counterparty.findPayees(ee.entity.id,{limit:100}).then(Ar=>{Ar&&sr(Ar.data)})},[(jr=ee.entity)==null?void 0:jr.id,ee.refreshId,ee.token]),React$1.useEffect(()=>{var Ir,Br;!ee.token||!((Ir=ee.entity)!=null&&Ir.id)||(Br=ee.client)==null||Br.entity.metadata.getAll(ee.entity.id).then(Ar=>{Ar&&lr(Ar)})},[(wr=ee.entity)==null?void 0:wr.id,ee.refreshId,ee.token]);async function br(Ir){const Br=[];await Promise.all(te.map(async Ur=>{var Lr,Zr;if((Lr=ee.entity)!=null&&Lr.id&&!Ir.policies.find(nn=>nn.id==Ur.id))try{await((Zr=ee.client)==null?void 0:Zr.entity.approvalPolicy.delete(ee.entity.id,Ur.id)),Br.push({id:Ur.id,success:!0})}catch(nn){console.log(nn),Br.push({id:Ur.id,success:!1})}}));const Ar={root:"root"};Ir.policies.forEach(Ur=>{Ar[Ur.id]=Ur.id.indexOf("~")?"":Ur.id}),await Promise.all(Ir.policies.map(async(Ur,Lr)=>{var tn,Nr,Fr;if(!((tn=ee.entity)!=null&&tn.id))return;const Zr=Ur.trigger.map(Yr=>Yr.type=="amount"?{type:Yr.type,amount:Number(Yr.amount),currency:Yr.currency}:Yr.type=="vendor"?{type:Yr.type,vendorIds:Yr.vendorIds}:Yr.type=="metadata"?{type:Yr.type,key:Yr.key,value:Yr.value}:Yr);let nn=Ar[Ur.upstreamPolicyId];for(;!nn;)await new Promise(Yr=>setTimeout(Yr,100)),nn=Ar[Ur.upstreamPolicyId];const rn={upstreamPolicyId:nn,trigger:Zr,rule:{type:Ur.rule.type,numApprovers:Number(Ur.rule.numApprovers),identifierList:{type:Ur.rule.identifierList.type,value:Ur.rule.identifierList.value}}};if(Ur.rule.identifierList.type==="userList"&&rn.rule.numApprovers>rn.rule.identifierList.value.length){Q$1(`Error With Rule ${Lr+1}: Number of approvers cannot be more than number of users`,{type:"error"});return}try{let Yr;Ur!=null&&Ur.id&&(Ur==null?void 0:Ur.id.indexOf("~"))<0?Yr=await((Nr=ee.client)==null?void 0:Nr.entity.approvalPolicy.update(ee.entity.id,Ur.id,rn)):Yr=await((Fr=ee.client)==null?void 0:Fr.entity.approvalPolicy.create(ee.entity.id,rn)),Ar[Ur.id]=(Yr==null?void 0:Yr.id)??"",Br.push({id:Ur.id,success:!0})}catch(Yr){console.log(Yr),Br.push({id:Ur.id,success:!1})}})),Br.every(Ur=>Ur.success)?(Q$1("Approval Policies Saved",{type:"success"}),ee.refresh()):Q$1("Error Saving Some Approval Policies",{type:"error"})}return jsxs("form",{onSubmit:fr(br),children:[jsx(Level,{level:0,fields:Er,remove:Mr,append:yr,control:dr,watch:hr,register:ur,setValue:pr,users:re,roles:or,counterparties:ir,metadata:cr,formPolicies:Er,upstreamPolicyId:"root"}),jsx(MercoaButton,{isEmphasized:!0,size:"md",className:"mercoa-mt-5",children:"Save Rules"})]})}function Level({level:ee,upstreamPolicyId:te,fields:ce,remove:re,append:nr,control:or,watch:ar,register:ir,setValue:sr,users:cr,roles:lr,counterparties:ur,metadata:fr,formPolicies:hr}){const pr=ce.filter(dr=>dr.upstreamPolicyId===te);return jsxs("ul",{role:"list",className:`mercoa-space-y-6 mercoa-max-w-[800px] ${nestedBg[ee]}`,children:[jsxs("li",{className:`mercoa-relative mercoa-flex mercoa-gap-x-4 ${te==="root"?"":"mercoa-mt-1"}`,children:[jsx("div",{className:"-mercoa-bottom-6 mercoa-absolute mercoa-left-0 mercoa-top-0 mercoa-flex mercoa-w-6 mercoa-justify-center",children:jsx("div",{className:"mercoa-w-px mercoa-bg-gray-200"})}),te==="root"&&jsx("div",{className:`mercoa-relative mercoa-flex mercoa-h-6 mercoa-w-6 mercoa-flex-none mercoa-items-center mercoa-justify-center ${nestedBg[ee]}`,children:jsx(RocketLaunchIcon$1,{className:"mercoa-h-5 mercoa-w-5 mercoa-text-gray-300","aria-hidden":"true"})}),jsx("p",{className:"mercoa-flex-auto mercoa-py-0.5 mercoa-text-xs mercoa-leading-5 mercoa-text-gray-500",children:jsx("span",{className:"mercoa-font-medium mercoa-text-gray-900",children:te==="root"?"When an invoice is sent for approval:":""})})]}),pr.map((dr,mr)=>dr.trigger.length===0?jsx(Fragment,{}):jsxs("li",{className:"mercoa-relative mercoa-flex mercoa-gap-x-4",children:[jsx("div",{className:"-mercoa-bottom-6 mercoa-absolute mercoa-left-0 mercoa-top-0 mercoa-flex mercoa-w-6 mercoa-justify-center",children:jsx("div",{className:"mercoa-w-px mercoa-bg-gray-200"})}),jsx("div",{className:`mercoa-relative mercoa-flex mercoa-h-6 mercoa-w-6 mercoa-flex-none mercoa-items-center mercoa-justify-center ${nestedBg[ee]}`,children:jsx(SparklesIcon$1,{className:"mercoa-h-5 mercoa-w-5 mercoa-text-gray-300","aria-hidden":"true"})}),jsx("p",{className:"mercoa-flex-auto mercoa-py-0.5 mercoa-text-xs mercoa-leading-5 mercoa-text-gray-500",children:jsxs("div",{className:`font-medium mercoa-text-gray-900 mercoa-p-2 mercoa-pb-5 mercoa-rounded-md ${nestedBg[ee+1]}`,children:[jsxs("div",{className:"mercoa-grid mercoa-grid-cols-4 mercoa-gap-2 mercoa-p-3 mercoa-border mercoa-border-gray-200 mercoa-rounded-md mercoa-relative mercoa-bg-white",children:[jsxs("button",{className:"mercoa-absolute mercoa-top-2 mercoa-right-2 mercoa-text-gray-400 hover:mercoa-text-gray-500",type:"button",onClick:()=>re(ce.findIndex(yr=>yr.id==dr.id)),children:[jsx("span",{className:"mercoa-sr-only",children:"Remove"}),jsx(XMarkIcon$1,{className:"mercoa-h-5 mercoa-w-5"})]}),jsx(Trigger,{control:or,watch:ar,register:ir,setValue:sr,counterparties:ur,index:ce.findIndex(yr=>yr.id==dr.id),metadata:fr})]}),jsx(Rule,{watch:ar,register:ir,setValue:sr,users:cr,roles:lr,index:ce.findIndex(yr=>yr.id==dr.id),remove:()=>re(ce.findIndex(yr=>yr.id==dr.id))}),jsx("div",{className:"mercoa-ml-10",children:jsx(Level,{level:ee+1,fields:hr,remove:re,append:nr,control:or,watch:ar,register:ir,setValue:sr,users:cr,roles:lr,counterparties:ur,metadata:fr,formPolicies:hr,upstreamPolicyId:dr.id})})]})})]},mr)),jsxs("li",{className:"mercoa-relative mercoa-flex mercoa-gap-x-4",children:[te==="root"&&jsx("div",{className:"-mercoa-bottom-6 mercoa-absolute mercoa-left-0 mercoa-top-0 mercoa-flex mercoa-w-6 mercoa-justify-center",children:jsx("div",{className:"mercoa-w-px mercoa-bg-gray-200"})}),jsx("div",{className:`mercoa-relative mercoa-flex mercoa-h-6 mercoa-w-6 mercoa-flex-none mercoa-items-center mercoa-justify-center ${nestedBg[ee]}`,children:jsx("div",{className:"mercoa-h-1.5 mercoa-w-1.5 mercoa-rounded-full mercoa-bg-gray-100 mercoa-ring-1 mercoa-ring-gray-300"})}),jsx("p",{className:"mercoa-flex-auto mercoa-py-0.5 mercoa-text-xs mercoa-leading-5 mercoa-text-gray-500",children:jsx(AddRule,{id:te+"~"+pr.length,upstreamPolicyId:te,append:nr,trigger:[{type:"amount",amount:100,currency:javascript.Mercoa.CurrencyCode.Usd}]})})]}),te==="root"&&jsxs(Fragment,{children:[jsxs("li",{className:"mercoa-relative mercoa-gap-x-4",children:[jsxs("div",{className:"mercoa-flex",children:[jsx("div",{className:"-mercoa-bottom-6 mercoa-absolute mercoa-left-0 mercoa-top-0 mercoa-flex mercoa-w-6 mercoa-justify-center",children:jsx("div",{className:"mercoa-w-px mercoa-bg-gray-200"})}),jsx("div",{className:"mercoa-relative mercoa-flex mercoa-h-6 mercoa-w-6 mercoa-flex-none mercoa-items-center mercoa-justify-center mercoa-bg-white",children:jsx(ExclamationTriangleIcon$1,{className:"mercoa-h-5 mercoa-w-5 mercoa-text-gray-300","aria-hidden":"true"})}),jsx("p",{className:"mercoa-flex-auto mercoa-py-0.5 mercoa-text-xs mercoa-leading-5 mercoa-text-gray-500 mercoa-ml-4",children:jsxs("span",{className:"mercoa-font-medium mercoa-text-gray-900 ",children:["Always apply the following rule:",jsx("div",{className:"mercoa-mt-1",children:hr.filter(dr=>dr.trigger.length===0).length===0&&jsx(AddRule,{upstreamPolicyId:"root",append:nr,trigger:[],id:"fallback"})})]})})]}),ce.map((dr,mr)=>dr.trigger.length>0?jsx(Fragment,{}):jsx("div",{className:"mercoa-ml-10",children:jsx(Rule,{watch:ar,register:ir,setValue:sr,users:cr,roles:lr,index:ce.findIndex(yr=>yr.id==dr.id),noTrigger:!0,remove:()=>re(ce.findIndex(yr=>yr.id==dr.id))},ce.findIndex(yr=>yr.id==dr.id))},mr))]}),jsxs("li",{className:"mercoa-relative mercoa-flex mercoa-gap-x-4",children:[jsx("div",{className:"mercoa-h-6 mercoa-absolute mercoa-left-0 mercoa-top-0 mercoa-flex mercoa-w-6 mercoa-justify-center",children:jsx("div",{className:"mercoa-w-px mercoa-bg-gray-200"})}),jsx("div",{className:`mercoa-relative mercoa-flex mercoa-h-6 mercoa-w-6 mercoa-flex-none mercoa-items-center mercoa-justify-center ${nestedBg[ee]}`,children:jsx(CheckCircleIcon$1,{className:"mercoa-h-5 mercoa-w-5 mercoa-text-green-400","aria-hidden":"true"})}),jsx("p",{className:"mercoa-flex-auto mercoa-py-0.5 mercoa-text-xs mercoa-leading-5 mercoa-text-gray-500",children:jsx("span",{className:"mercoa-font-medium mercoa-text-gray-900",children:" Approve Invoice"})})]})]})]})}function Trigger({control:ee,watch:te,register:ce,setValue:re,counterparties:nr,index:or,metadata:ar}){const ir=useMercoaSession(),{append:sr,remove:cr,fields:lr}=useFieldArray({control:ee,name:`policies.${or}.trigger`}),ur=te(`policies.${or}.trigger`);return jsxs(Fragment,{children:[jsx("div",{className:"mercoa-col-span-4 mercoa-font-medium mercoa-text-gray-700 mercoa-mb-1",children:"If these conditions are true:"}),lr.map((fr,hr)=>{var dr,mr,yr,Mr,Sr,Er;const pr=ur.slice(0,hr).map(br=>br.type);return jsxs("div",{className:"mercoa-p-3 mercoa-bg-gray-50 mercoa-rounded-md mercoa-col-span-4 mercoa-flex mercoa-items-center",children:[jsx("span",{className:"mercoa-text-sm mercoa-font-medium mercoa-leading-6 mercoa-text-gray-900 mercoa-mr-2",children:hr>0?"And":"If"}),jsx(MercoaCombobox,{options:[...pr.every(br=>br!="amount")?[{displayName:"Amount",key:"~mercoa~amount"}]:[],...pr.every(br=>br!="vendor")?[{displayName:"Vendor",key:"~mercoa~vendor"}]:[],...((dr=ir.organization)==null?void 0:dr.metadataSchema)??[]].map(br=>({disabled:!1,value:br})),onChange:br=>{br.key=="~mercoa~amount"?re(`policies.${or}.trigger.${hr}.type`,"amount",{shouldDirty:!0}):br.key=="~mercoa~vendor"?re(`policies.${or}.trigger.${hr}.type`,"vendor",{shouldDirty:!0}):(re(`policies.${or}.trigger.${hr}.type`,"metadata",{shouldDirty:!0}),re(`policies.${or}.trigger.${hr}.key`,br.key,{shouldDirty:!0}),re(`policies.${or}.trigger.${hr}.value`,"",{shouldDirty:!0}))},value:()=>{var br,_r,xr,jr;return((br=ur[hr])==null?void 0:br.type)==="amount"?{displayName:"Amount",key:"~mercoa~amount"}:((_r=ur[hr])==null?void 0:_r.type)==="vendor"?{displayName:"Vendor",key:"~mercoa~vendor"}:(jr=(xr=ir.organization)==null?void 0:xr.metadataSchema)==null?void 0:jr.find(wr=>{var Ir;return wr.key==((Ir=ur[hr])==null?void 0:Ir.key)})},displayIndex:"displayName"}),((mr=ur[hr])==null?void 0:mr.type)=="amount"&&jsxs(Fragment,{children:[jsx("span",{className:"mercoa-text-sm mercoa-font-medium mercoa-leading-6 mercoa-text-gray-900 mercoa-ml-2 mercoa-mr-2",children:"more than or equal to"}),jsxs("div",{className:"mercoa-relative mercoa-rounded-md mercoa-shadow-sm mercoa-inline-block",children:[jsx("div",{className:"mercoa-pointer-events-none mercoa-absolute mercoa-inset-y-0 mercoa-left-0 mercoa-flex mercoa-items-center mercoa-pl-3",children:jsx("span",{className:"mercoa-text-gray-500 sm:mercoa-text-sm",children:currencyCodeToSymbol(ur[hr].currency)})}),jsx("input",{type:"text",...ce(`policies.${or}.trigger.${hr}.amount`),className:`mercoa-block mercoa-rounded-md mercoa-border-0 mercoa-py-1.5 mercoa-pr-[4.4rem] mercoa-text-gray-900 mercoa-ring-1 mercoa-ring-inset mercoa-ring-gray-300 placeholder:mercoa-text-gray-400 focus:mercoa-ring-2 focus:mercoa-ring-inset focus:mercoa-ring-primary sm:mercoa-text-sm sm:mercoa-leading-6
|
|
272
272
|
${currencyCodeToSymbol(ur[hr].currency).length>1?"mercoa-pl-12":"mercoa-pl-6"}`,placeholder:"0.00"}),jsxs("div",{className:"mercoa-absolute mercoa-inset-y-0 mercoa-right-0 mercoa-flex mercoa-items-center",children:[jsx("label",{htmlFor:"currency",className:"mercoa-sr-only",children:"Currency"}),jsx("select",{...ce(`policies.${or}.trigger.${hr}.currency`),className:"mercoa-h-full mercoa-rounded-md mercoa-border-0 mercoa-bg-transparent mercoa-py-0 mercoa-pl-2 mercoa-pr-7 mercoa-text-gray-500 focus:mercoa-ring-2 focus:mercoa-ring-inset focus:mercoa-ring-primary sm:mercoa-text-sm",children:Object.values(javascript.Mercoa.CurrencyCode).map((br,_r)=>jsx("option",{value:br,children:br},_r))})]})]})]}),((yr=ur[hr])==null?void 0:yr.type)=="vendor"&&jsxs(Fragment,{children:[jsx("span",{className:"mercoa-text-sm mercoa-font-medium mercoa-leading-6 mercoa-text-gray-900 mercoa-ml-2 mercoa-mr-2 mercoa-w-[100px]",children:"is one of"}),jsx(MercoaCombobox,{className:"mercoa-w-full",options:nr==null?void 0:nr.map(br=>({disabled:!1,value:br})),onChange:br=>{br.length!=0&&re(`policies.${or}.trigger.${hr}.vendorIds`,br.filter(_r=>_r).map(_r=>_r.id),{shouldDirty:!0})},value:nr.filter(br=>{var _r,xr;return(xr=(_r=ur[hr])==null?void 0:_r.vendorIds)==null?void 0:xr.includes(br.id)}),displayIndex:"name",multiple:!0})]}),((Mr=ur[hr])==null?void 0:Mr.type)=="metadata"&&jsxs(Fragment,{children:[jsx("span",{className:"mercoa-text-sm mercoa-font-medium mercoa-leading-6 mercoa-text-gray-900 mercoa-ml-2 mercoa-mr-2",children:"is"}),jsx(MetadataSelection,{lineItem:!0,setValue:br=>{re(`policies.${or}.trigger.${hr}.value`,br,{shouldDirty:!0})},hasDocument:!0,skipValidation:!0,value:te(`policies.${or}.trigger.${hr}.value`),entityMetadata:ar.find(br=>br.key===te(`policies.${or}.trigger.${hr}.key`)),schema:((Er=(Sr=ir.organization)==null?void 0:Sr.metadataSchema)==null?void 0:Er.find(br=>br.key===te(`policies.${or}.trigger.${hr}.key`)))??{key:"",displayName:"",type:"STRING"}})]}),hr!==0&&jsxs("button",{type:"button",onClick:()=>cr(hr),className:"mercoa-ml-2 mercoa-text-gray-400 hover:mercoa-text-gray-500",children:[jsx("span",{className:"mercoa-sr-only",children:"Remove"}),jsx(XMarkIcon$1,{className:"mercoa-h-5 mercoa-w-5"})]})]},hr)}),jsx("div",{className:"mercoa-col-span-4",children:jsxs(MercoaButton,{isEmphasized:!1,size:"sm",type:"button",className:"mercoa-flex",onClick:()=>{console.log({triggerWatch:ur}),ur.every(fr=>fr.type!="amount")?sr({type:"amount",amount:100,currency:javascript.Mercoa.CurrencyCode.Usd}):ur.every(fr=>fr.type!="vendor")?sr({type:"vendor",vendorIds:[]}):sr({})},children:[jsx(PlusIcon$1,{className:"mercoa-h-4 mercoa-w-4 mercoa-mr-1"})," Add Condition"]})})]})}function Rule({watch:ee,register:te,setValue:ce,users:re,roles:nr,index:or,remove:ar,noTrigger:ir}){var ur;const[sr,cr]=React$1.useState(!0),lr=ee(`policies.${or}.rule.identifierList.type`);return React$1.useEffect(()=>{sr||(ce(`policies.${or}.rule.type`,"approver"),ce(`policies.${or}.rule.identifierList.value`,[])),cr(!1)},[lr]),jsxs("div",{className:"mercoa-grid mercoa-grid-cols-1 mercoa-gap-2 mercoa-p-3 mercoa-border mercoa-border-gray-200 mercoa-rounded-md mercoa-relative mercoa-mt-5 mercoa-ml-10 mercoa-bg-white",children:[jsx(ArrowDownLeftIcon,{className:"mercoa-w-7 mercoa-h-7 mercoa-absolute -mercoa-top-2 -mercoa-left-10"}),ir?jsxs("button",{className:"mercoa-absolute mercoa-top-2 mercoa-right-2 mercoa-text-gray-400 hover:mercoa-text-gray-500",type:"button",onClick:ar,children:[jsx("span",{className:"mercoa-sr-only",children:"Remove"}),jsx(XMarkIcon$1,{className:"mercoa-h-5 mercoa-w-5"})]}):jsx("div",{className:"mercoa-font-medium mercoa-text-gray-700",children:"Then:"}),jsxs("div",{className:"mercoa-flex mercoa-items-center",children:[jsx("span",{className:"mercoa-text-sm mercoa-font-medium mercoa-leading-6 mercoa-text-gray-900 mercoa-mr-2",children:"Require"}),jsx("input",{...te(`policies.${or}.rule.numApprovers`,{required:!0}),min:"1",type:"number",className:"mercoa-block mercoa-rounded-md mercoa-border-0 mercoa-py-1.5 mercoa-text-gray-900 mercoa-ring-1 mercoa-ring-inset mercoa-ring-gray-300 placeholder:mercoa-text-gray-400 focus:mercoa-ring-2 focus:mercoa-ring-inset focus:mercoa-ring-primary sm:mercoa-text-sm sm:mercoa-leading-6 mercoa-w-[50px]"}),jsx("span",{className:"mercoa-text-sm mercoa-font-medium mercoa-leading-6 mercoa-text-gray-900 mercoa-ml-2 mercoa-mr-2",children:"approvals from the following"}),jsxs("select",{...te(`policies.${or}.rule.identifierList.type`,{required:!0}),className:"mercoa-block mercoa-rounded-md mercoa-border-0 mercoa-py-1.5 mercoa-pr-[4.4rem] mercoa-text-gray-900 mercoa-ring-1 mercoa-ring-inset mercoa-ring-gray-300 placeholder:mercoa-text-gray-400 focus:mercoa-ring-2 focus:mercoa-ring-inset focus:mercoa-ring-primary sm:mercoa-text-sm sm:mercoa-leading-6",children:[jsx("option",{value:"rolesList",children:"roles"}),jsx("option",{value:"userList",children:"users"})]})]}),jsx("div",{className:"mercoa-mt-1",children:lr==="rolesList"?jsx(MercoaCombobox,{options:nr.map(fr=>({disabled:!1,value:fr})),onChange:fr=>{fr.length!=0&&ce(`policies.${or}.rule.identifierList.value`,fr.filter(hr=>hr),{shouldDirty:!0})},value:ee(`policies.${or}.rule.identifierList.value`),multiple:!0}):jsx(MercoaCombobox,{options:re.map(fr=>({disabled:!1,value:fr})),onChange:fr=>{fr.length!=0&&ce(`policies.${or}.rule.identifierList.value`,fr.filter(hr=>hr).map(hr=>hr.id),{shouldDirty:!0})},value:(ur=ee(`policies.${or}.rule.identifierList.value`))==null?void 0:ur.map(fr=>re.find(hr=>hr.id==fr.trim())),displayIndex:"name",secondaryDisplayIndex:"id",multiple:!0})})]})}function AddRule({id:ee,upstreamPolicyId:te,append:ce,trigger:re}){return jsxs(MercoaButton,{isEmphasized:!0,size:"sm",type:"button",className:"mercoa-flex",onClick:()=>{ce({id:ee,upstreamPolicyId:te,trigger:re,rule:{type:"approver",numApprovers:1,identifierList:{type:"rolesList",value:[""]}}})},children:[jsx(PlusIcon$1,{className:"mercoa-h-4 mercoa-w-4 mercoa-mr-1"})," Add Rule"]})}function ownKeys$1(ee,te){var ce=Object.keys(ee);if(Object.getOwnPropertySymbols){var re=Object.getOwnPropertySymbols(ee);te&&(re=re.filter(function(nr){return Object.getOwnPropertyDescriptor(ee,nr).enumerable})),ce.push.apply(ce,re)}return ce}function _objectSpread2(ee){for(var te=1;te<arguments.length;te++){var ce=arguments[te]!=null?arguments[te]:{};te%2?ownKeys$1(Object(ce),!0).forEach(function(re){_defineProperty$1(ee,re,ce[re])}):Object.getOwnPropertyDescriptors?Object.defineProperties(ee,Object.getOwnPropertyDescriptors(ce)):ownKeys$1(Object(ce)).forEach(function(re){Object.defineProperty(ee,re,Object.getOwnPropertyDescriptor(ce,re))})}return ee}function _defineProperty$1(ee,te,ce){return te in ee?Object.defineProperty(ee,te,{value:ce,enumerable:!0,configurable:!0,writable:!0}):ee[te]=ce,ee}function _slicedToArray(ee,te){return _arrayWithHoles(ee)||_iterableToArrayLimit(ee,te)||_unsupportedIterableToArray(ee,te)||_nonIterableRest()}function _arrayWithHoles(ee){if(Array.isArray(ee))return ee}function _iterableToArrayLimit(ee,te){var ce=ee==null?null:typeof Symbol<"u"&&ee[Symbol.iterator]||ee["@@iterator"];if(ce!=null){var re=[],nr=!0,or=!1,ar,ir;try{for(ce=ce.call(ee);!(nr=(ar=ce.next()).done)&&(re.push(ar.value),!(te&&re.length===te));nr=!0);}catch(sr){or=!0,ir=sr}finally{try{!nr&&ce.return!=null&&ce.return()}finally{if(or)throw ir}}return re}}function _unsupportedIterableToArray(ee,te){if(ee){if(typeof ee=="string")return _arrayLikeToArray(ee,te);var ce=Object.prototype.toString.call(ee).slice(8,-1);if(ce==="Object"&&ee.constructor&&(ce=ee.constructor.name),ce==="Map"||ce==="Set")return Array.from(ee);if(ce==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(ce))return _arrayLikeToArray(ee,te)}}function _arrayLikeToArray(ee,te){(te==null||te>ee.length)&&(te=ee.length);for(var ce=0,re=new Array(te);ce<te;ce++)re[ce]=ee[ce];return re}function _nonIterableRest(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
273
273
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var commonjsGlobal=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof dist.global<"u"?dist.global:typeof self<"u"?self:{};function unwrapExports(ee){return ee&&ee.__esModule&&Object.prototype.hasOwnProperty.call(ee,"default")?ee.default:ee}function createCommonjsModule(ee,te){return te={exports:{}},ee(te,te.exports),te.exports}var useScript_1=createCommonjsModule(function(ee,te){var ce=commonjsGlobal&&commonjsGlobal.__rest||function(ar,ir){var sr={};for(var cr in ar)Object.prototype.hasOwnProperty.call(ar,cr)&&ir.indexOf(cr)<0&&(sr[cr]=ar[cr]);if(ar!=null&&typeof Object.getOwnPropertySymbols=="function")for(var lr=0,cr=Object.getOwnPropertySymbols(ar);lr<cr.length;lr++)ir.indexOf(cr[lr])<0&&Object.prototype.propertyIsEnumerable.call(ar,cr[lr])&&(sr[cr[lr]]=ar[cr[lr]]);return sr};Object.defineProperty(te,"__esModule",{value:!0}),te.scripts=void 0,te.scripts={};var re=function(ar){var ir=document.querySelector('script[src="'+ar+'"]');if(ir)return te.scripts[ar]={loading:!1,error:null,scriptEl:ir}};function nr(ar){var ir=ar.src,sr=ar.checkForExisting,cr=sr===void 0?!1:sr,lr=ce(ar,["src","checkForExisting"]),ur=ir?te.scripts[ir]:void 0;!ur&&cr&&ir&&or&&(ur=re(ir));var fr=(0,React$1.useState)(ur?ur.loading:!!ir),hr=fr[0],pr=fr[1],dr=(0,React$1.useState)(ur?ur.error:null),mr=dr[0],yr=dr[1];return(0,React$1.useEffect)(function(){if(!(!or||!ir||!hr||mr)){ur=te.scripts[ir],!ur&&cr&&(ur=re(ir));var Mr;ur?Mr=ur.scriptEl:(Mr=document.createElement("script"),Mr.src=ir,Object.keys(lr).forEach(function(br){Mr[br]===void 0?Mr.setAttribute(br,lr[br]):Mr[br]=lr[br]}),ur=te.scripts[ir]={loading:!0,error:null,scriptEl:Mr});var Sr=function(){ur&&(ur.loading=!1),pr(!1)},Er=function(br){ur&&(ur.error=br),yr(br)};return Mr.addEventListener("load",Sr),Mr.addEventListener("error",Er),document.body.appendChild(Mr),function(){Mr.removeEventListener("load",Sr),Mr.removeEventListener("error",Er)}}},[ir]),[hr,mr]}te.default=nr;var or=typeof window<"u"&&typeof window.document<"u"});unwrapExports(useScript_1),useScript_1.scripts;var lib$1=createCommonjsModule(function(ee,te){var ce=commonjsGlobal&&commonjsGlobal.__importDefault||function(re){return re&&re.__esModule?re:{default:re}};Object.defineProperty(te,"__esModule",{value:!0}),te.scripts=te.default=void 0,Object.defineProperty(te,"default",{enumerable:!0,get:function(){return ce(useScript_1).default}}),Object.defineProperty(te,"scripts",{enumerable:!0,get:function(){return useScript_1.scripts}})}),useScript=unwrapExports(lib$1);lib$1.scripts;var renameKeyInObject=function ee(te,ce,re){var nr={};return delete Object.assign(nr,te,_defineProperty$1({},re,te[ce]))[ce],nr},createPlaidHandler=function ee(te,ce){var re={plaid:null,open:!1,onExitCallback:null};if(typeof window>"u"||!window.Plaid)throw new Error("Plaid not loaded");re.plaid=ce(_objectSpread2(_objectSpread2({},te),{},{onExit:function(sr,cr){re.open=!1,te.onExit&&te.onExit(sr,cr),re.onExitCallback&&re.onExitCallback()}}));var nr=function(){re.plaid&&(re.open=!0,re.onExitCallback=null,re.plaid.open())},or=function(sr,cr){if(!re.open||!re.plaid){cr&&cr();return}re.onExitCallback=cr,re.plaid.exit(sr),sr&&sr.force&&(re.open=!1)},ar=function(){re.plaid&&(re.plaid.destroy(),re.plaid=null)};return{open:nr,exit:or,destroy:ar}},createPlaid=function ee(te,ce){var re=renameKeyInObject(te,"publicKey","key");return createPlaidHandler(re,ce)},PLAID_LINK_STABLE_URL="https://cdn.plaid.com/link/v2/stable/link-initialize.js",noop=function ee(){},usePlaidLink=function ee(te){var ce=useScript({src:PLAID_LINK_STABLE_URL,checkForExisting:!0}),re=_slicedToArray(ce,2),nr=re[0],or=re[1],ar=React$1.useState(null),ir=_slicedToArray(ar,2),sr=ir[0],cr=ir[1],lr=React$1.useState(!1),ur=_slicedToArray(lr,2),fr=ur[0],hr=ur[1],pr=(te.product||[]).slice().sort().join(",");React$1.useEffect(function(){if(!nr&&!(!te.token&&!te.publicKey&&!te.receivedRedirectUri)){if(or||!window.Plaid){console.error("Error loading Plaid",or);return}sr!=null&&sr.exit({force:!0},function(){return sr.destroy()});var yr=createPlaid(_objectSpread2(_objectSpread2({},te),{},{onLoad:function(){hr(!0),te.onLoad&&te.onLoad()}}),window.Plaid.create);return cr(yr),function(){return yr.exit({force:!0},function(){return yr.destroy()})}}},[nr,or,te.publicKey,te.token,pr]);var dr=sr!=null&&(!nr||fr),mr=function(){te.token||console.warn("react-plaid-link: You cannot call open() without a valid token supplied to usePlaidLink. This is a no-op.")};return{error:or,ready:dr,exit:sr?sr.exit:noop,open:sr?sr.open:mr}},PlaidLinkStableEvent;(function(ee){ee.OPEN="OPEN",ee.EXIT="EXIT",ee.HANDOFF="HANDOFF",ee.SELECT_INSTITUTION="SELECT_INSTITUTION",ee.ERROR="ERROR",ee.BANK_INCOME_INSIGHTS_COMPLETED="BANK_INCOME_INSIGHTS_COMPLETED",ee.IDENTITY_VERIFICATION_PASS_SESSION="IDENTITY_VERIFICATION_PASS_SESSION",ee.IDENTITY_VERIFICATION_FAIL_SESSION="IDENTITY_VERIFICATION_FAIL_SESSION"})(PlaidLinkStableEvent||(PlaidLinkStableEvent={}));const validBankAccount=require("us-bank-account-validator");function BankAccounts({children:ee,onSelect:te,showAdd:ce,showEdit:re,verifiedOnly:nr}){var ur;const[or,ar]=React$1.useState(),[ir,sr]=React$1.useState(!1),cr=useMercoaSession();React$1.useEffect(()=>{var fr,hr,pr;cr.token&&((fr=cr.entity)!=null&&fr.id)&&((pr=cr.client)==null||pr.entity.paymentMethod.getAll((hr=cr.entity)==null?void 0:hr.id,{type:"bankAccount"}).then(dr=>{ar(dr.map(mr=>mr).filter(mr=>nr&&mr.status!="VERIFIED"?null:mr))}))},[(ur=cr.entity)==null?void 0:ur.id,cr.token,ir,cr.refreshId]);const lr=fr=>{sr(!1),te&&fr&&te(fr)};return ee?ee({bankAccounts:or}):jsxs(Fragment,{children:[!or&&jsx("div",{className:"mercoa-p-9 mercoa-text-center",children:jsx(LoadingSpinnerIcon,{})}),or&&or.map(fr=>jsx("div",{className:"mercoa-mt-2",children:jsx(BankAccountComponent,{account:fr,onSelect:te,showEdit:re})},fr.id)),or&&ce&&jsxs("div",{className:"mercoa-mt-2",children:[jsx(AddDialog,{show:ir,onClose:lr,component:jsx(AddBankViaPlaidOrManual,{onSubmit:fr=>{lr(fr)}})}),jsx(BankAccountComponent,{onSelect:()=>sr(!0)})]}),or&&or.length==0&&nr&&jsx("div",{className:"mercoa-mt-2 mercoa-text-left mercoa-text-gray-700",children:"No verified bank accounts found. Please add and verify at least one bank account."})]})}function AddBankViaPlaidOrManual({title:ee,actions:te,onSubmit:ce}){const re=useMercoaSession(),[nr,or]=React$1.useState(!1),[ar,ir]=React$1.useState(null),sr=async()=>{var fr;if(!re.entityId)return;const ur=await((fr=re.client)==null?void 0:fr.entity.plaidLinkToken(re.entityId));ur?ir(ur):or(!0)},{open:cr,ready:lr}=usePlaidLink({token:ar,onSuccess:async(ur,fr)=>{let hr;await Promise.all(fr.accounts.map(async pr=>{var mr,yr;let dr=javascript.Mercoa.BankType.Checking;pr.subtype=="savings"&&(dr=javascript.Mercoa.BankType.Savings),re.entityId&&(hr=await((yr=re.client)==null?void 0:yr.entity.paymentMethod.create(re.entityId,{type:"bankAccount",plaid:{publicToken:ur,accountId:pr.id},accountNumber:pr.mask,routingNumber:"",accountType:dr,bankName:((mr=fr==null?void 0:fr.institution)==null?void 0:mr.name)??""})))})),hr&&ce(hr)},onExit:(ur,fr)=>{console.log("onPlaidExit",{err:ur,metadata:fr}),ur&&Q$1.error("There was an error adding your bank account automatically. Please try again or add manually."),or(!0)}});return React$1.useEffect(()=>{sr()},[re.entityId]),React$1.useEffect(()=>{ar&&lr&&cr()},[ar,lr,cr]),nr?jsx(AddBankAccount,{title:ee,actions:te,onSubmit:ce}):!ar||!lr?jsx("div",{className:"mercoa-p-9 mercoa-text-center",children:jsx(LoadingSpinnerIcon,{})}):jsx("div",{className:"mercoa-p-10 mercoa-text-center"})}function AddBankAccount({onSubmit:ee,title:te,actions:ce,formOnlySubmit:re,bankAccount:nr}){const or=useMercoaSession();addMethod(create$6,"accountNumber",function(dr){return this.test({name:"accountNumber",exclusive:!0,message:dr||"Invalid Account Number",test:mr=>mr&&validBankAccount.accountNumber(mr).isPotentiallyValid})}),addMethod(create$6,"routingNumber",function(dr){return this.test({name:"routingNumber",exclusive:!0,message:dr||"Invalid Routing Number",test:mr=>mr&&validBankAccount.routingNumber(mr).isPotentiallyValid})});const ar=create$3({bankName:create$6().required(),routingNumber:create$6().required(),accountNumber:create$6().accountNumber().required()}).required(),{register:ir,setValue:sr,setError:cr,clearErrors:lr,handleSubmit:ur,watch:fr,formState:{errors:hr}}=useForm({defaultValues:nr,resolver:o(ar)});async function pr(dr){var mr,yr,Mr;if((mr=or.entity)!=null&&mr.id){const Sr=await((Mr=or.client)==null?void 0:Mr.entity.paymentMethod.create((yr=or.entity)==null?void 0:yr.id,{...dr,type:"bankAccount"}));if(!ee)return;Sr?ee(Sr):ee()}}return jsxs("form",{className:"mercoa-space-y-3 mercoa-text-left",onSubmit:ur(re||pr),children:[te||jsx("h3",{className:"mercoa-text-center mercoa-text-lg mercoa-font-medium mercoa-leading-6 mercoa-text-gray-900",children:"Manually Add Bank Account"}),jsx(AddBankAccountForm,{register:ir,errors:hr,watch:fr,setValue:sr,setError:cr,clearErrors:lr}),ce||jsxs("div",{className:"mercoa-flex mercoa-justify-between",children:[jsx(MercoaButton,{isEmphasized:!1,onClick:()=>{ee&&ee()},type:"button",children:"Back"}),jsx(MercoaButton,{isEmphasized:!0,children:"Add Bank Account"})]})]})}function AddBankAccountForm({register:ee,errors:te,watch:ce,setValue:re,setError:nr,clearErrors:or}){var cr,lr,ur;const ar=useMercoaSession(),ir=ce("routingNumber"),sr=ce("bankName");return React$1.useEffect(()=>{var fr;re("bankName","",{shouldDirty:!0,shouldTouch:!0}),ir&&(ir.length===9?(fr=ar.client)==null||fr.bankLookup.find({routingNumber:ir}).then(hr=>{hr.bankName?(re("bankName",hr.bankName),or("routingNumber")):nr("routingNumber",{message:"invalid"})}):ir&&nr("routingNumber",{message:"invalid"}))},[ir]),jsxs(Fragment,{children:[jsxs("div",{children:[jsx("label",{htmlFor:"routingNumber",className:"mercoa-block mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Routing Number"}),jsxs("div",{className:"mercoa-mt-1",children:[jsx("input",{...ee("routingNumber"),className:"mercoa-block mercoa-w-full mercoa-appearance-none mercoa-rounded-md mercoa-border mercoa-border-gray-300 mercoa-px-3 mercoa-py-2 mercoa-placeholder-gray-400 mercoa-shadow-sm focus:mercoa-border-indigo-500 focus:mercoa-outline-none focus:mercoa-ring-indigo-500 sm:mercoa-text-sm"}),((cr=te==null?void 0:te.routingNumber)==null?void 0:cr.message)&&jsx("p",{className:"mercoa-text-sm mercoa-text-red-500",children:"Please enter a valid routing number"})]})]}),jsxs("div",{children:[jsx("label",{htmlFor:"accountNumber",className:"mercoa-block mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Account Number"}),jsxs("div",{className:"mercoa-mt-1",children:[jsx("input",{...ee("accountNumber"),className:"mercoa-block mercoa-w-full mercoa-appearance-none mercoa-rounded-md mercoa-border mercoa-border-gray-300 mercoa-px-3 mercoa-py-2 mercoa-placeholder-gray-400 mercoa-shadow-sm focus:mercoa-border-indigo-500 focus:mercoa-outline-none focus:mercoa-ring-indigo-500 sm:mercoa-text-sm"}),((lr=te==null?void 0:te.accountNumber)==null?void 0:lr.message)&&jsx("p",{className:"mercoa-text-sm mercoa-text-red-500",children:"Please enter a valid account number"})]})]}),jsxs("div",{children:[jsx("label",{htmlFor:"accountType",className:"mercoa-block mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Account Type"}),jsx("div",{className:"mercoa-mt-1",children:jsxs("select",{...ee("accountType"),className:"mercoa-mt-1 mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border mercoa-border-gray-300 mercoa-bg-white mercoa-py-2 mercoa-px-3 mercoa-shadow-sm focus:mercoa-border-indigo-500 focus:mercoa-outline-none focus:mercoa-ring-indigo-500 sm:mercoa-text-sm",children:[jsx("option",{value:"CHECKING",children:"Checking"}),jsx("option",{value:"SAVINGS",children:"Savings"}),jsx("option",{value:"UNKNOWN",children:"Other"})]})})]}),sr&&jsxs("div",{children:[jsx("label",{htmlFor:"bankName",className:"mercoa-block mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Bank Name"}),jsxs("div",{className:"mercoa-mt-1",children:[jsx("input",{readOnly:!0,disabled:!0,...ee("bankName"),className:"mercoa-block mercoa-w-full mercoa-appearance-none mercoa-rounded-md mercoa-border mercoa-border-gray-300 mercoa-px-3 mercoa-py-2 mercoa-placeholder-gray-400 mercoa-shadow-sm focus:mercoa-border-indigo-500 focus:mercoa-outline-none focus:mercoa-ring-indigo-500 sm:mercoa-text-sm"}),((ur=te==null?void 0:te.bankName)==null?void 0:ur.message)&&jsx("p",{className:"mercoa-text-sm mercoa-text-red-500",children:"Please enter the bank name"})]})]})]})}function EditBankAccount({paymentMethodId:ee,onSubmit:te}){const ce=useMercoaSession(),{register:re,handleSubmit:nr}=useForm();function or(ar){var ir,sr,cr;(ir=ce.entity)!=null&&ir.id&&((cr=ce.client)==null||cr.entity.paymentMethod.update((sr=ce.entity)==null?void 0:sr.id,ee,{...ar,type:javascript.Mercoa.PaymentMethodType.BankAccount}).then(()=>{Q$1.success("Bank account updated"),te&&te(ar),ce.refresh()}))}return jsxs("form",{onSubmit:nr(or),children:[jsxs("div",{children:[jsx("label",{htmlFor:"accountName",className:"mercoa-block mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Account Name"}),jsx("div",{className:"mercoa-mt-1",children:jsx("input",{...re("accountName"),className:"mercoa-block mercoa-w-full mercoa-appearance-none mercoa-rounded-md mercoa-border mercoa-border-gray-300 mercoa-px-3 mercoa-py-2 mercoa-placeholder-gray-400 mercoa-shadow-sm focus:mercoa-border-indigo-500 focus:mercoa-outline-none focus:mercoa-ring-indigo-500 sm:mercoa-text-sm"})})]}),jsxs("div",{className:"mercoa-flex mercoa-justify-between mercoa-mt-2",children:[jsx(MercoaButton,{isEmphasized:!1,onClick:()=>{te&&te()},type:"button",children:"Back"}),jsx(MercoaButton,{isEmphasized:!0,children:"Update"})]})]})}function AddDialog({show:ee,onClose:te,component:ce}){return jsx(tt$1.Root,{show:ee,as:React$1.Fragment,children:jsxs(_t$1,{as:"div",className:"mercoa-relative mercoa-z-10",onClose:()=>te(),children:[jsx(tt$1.Child,{as:React$1.Fragment,enter:"mercoa-ease-out mercoa-duration-300",enterFrom:"mercoa-opacity-0",enterTo:"mercoa-opacity-100",leave:"mercoa-ease-in mercoa-duration-200",leaveFrom:"mercoa-opacity-100",leaveTo:"mercoa-opacity-0",children:jsx("div",{className:"mercoa-fixed mercoa-inset-0 mercoa-bg-gray-500 mercoa-bg-mercoa-opacity-75 mercoa-transition-opacity"})}),jsx("div",{className:"mercoa-fixed mercoa-inset-0 mercoa-z-10 mercoa-overflow-y-auto",children:jsx("div",{className:"mercoa-flex mercoa-min-h-full mercoa-items-end mercoa-justify-center mercoa-p-4 mercoa-text-center sm:mercoa-items-center sm:mercoa-p-0",children:jsx(tt$1.Child,{as:React$1.Fragment,enter:"mercoa-ease-out mercoa-duration-300",enterFrom:"mercoa-opacity-0 mercoa-translate-y-4 sm:mercoa-translate-y-0 sm:mercoa-scale-95",enterTo:"mercoa-opacity-100 mercoa-translate-y-0 sm:mercoa-scale-100",leave:"mercoa-ease-in mercoa-duration-200",leaveFrom:"mercoa-opacity-100 mercoa-translate-y-0 sm:mercoa-scale-100",leaveTo:"mercoa-opacity-0 mercoa-translate-y-4 sm:mercoa-translate-y-0 sm:mercoa-scale-95",children:jsx(_t$1.Panel,{className:"mercoa-relative mercoa-transform mercoa-rounded-lg mercoa-bg-white mercoa-px-4 mercoa-pt-5 mercoa-pb-4 mercoa-text-left mercoa-shadow-xl mercoa-transition-all sm:mercoa-my-8 sm:mercoa-w-full sm:mercoa-max-w-md sm:mercoa-p-6",children:ce})})})})]})})}function BankAccountComponent({children:ee,account:te,onSelect:ce,showEdit:re,selected:nr}){var fr,hr;const or=useMercoaSession(),[ar,ir]=React$1.useState(!1),[sr,cr]=React$1.useState(!1),{register:lr,handleSubmit:ur}=useForm();return te?jsxs("div",{onClick:()=>{ce&&ce(te)},className:`mercoa-relative mercoa-flex mercoa-items-center mercoa-space-x-3 mercoa-rounded-lg mercoa-border ${nr?"mercoa-border-gray-600":"mercoa-border-gray-300"} mercoa-bg-white mercoa-px-6 mercoa-py-5 mercoa-shadow-sm focus-within:mercoa-ring-2 focus-within:mercoa-ring-indigo-500 focus-within:mercoa-ring-offset-2 ${ce?"mercoa-cursor-pointer hover:mercoa-border-gray-400":""}`,children:[jsx("div",{className:`mercoa-flex-shrink-0 mercoa-rounded-full mercoa-p-1 ${nr?"mercoa-text-mercoa-primary-text-invert mercoa-bg-mercoa-primary-light":"mercoa-bg-gray-200 mercoa-text-gray-600"}`,children:jsx(BuildingLibraryIcon$1,{className:"mercoa-h-5 mercoa-w-5"})}),jsxs("div",{className:"mercoa-flex mercoa-min-w-0 mercoa-flex-1 mercoa-justify-between",children:[jsxs("div",{className:"mercoa-group mercoa-flex",children:[jsxs("div",{children:[!re&&jsx("span",{className:"mercoa-absolute mercoa-inset-0","aria-hidden":"true"}),jsx(AddDialog,{component:jsx(EditBankAccount,{paymentMethodId:te.id,onSubmit:()=>cr(!1)}),onClose:()=>cr(!1),show:sr}),te!=null&&te.accountName?jsxs(Fragment,{children:[jsx("p",{className:`mercoa-text-sm mercoa-font-medium mercoa-text-gray-900 ${nr?"mercoa-underline":""}`,children:te.accountName}),jsxs("p",{className:`mercoa-text-xs mercoa-font-medium mercoa-text-gray-800 ${nr?"mercoa-underline":""}`,children:[te==null?void 0:te.bankName,` ••••${String(te==null?void 0:te.accountNumber).slice(-4)}`]})]}):jsxs(Fragment,{children:[jsx("p",{className:`mercoa-text-sm mercoa-font-medium mercoa-text-gray-900 ${nr?"mercoa-underline":""}`,children:`${capitalize(te==null?void 0:te.accountType)} ••••${String(te==null?void 0:te.accountNumber).slice(-4)}`}),jsx("p",{className:`mercoa-text-xs mercoa-font-medium mercoa-text-gray-800 ${nr?"mercoa-underline":""}`,children:te==null?void 0:te.bankName})]})]}),re&&jsx(MercoaButton,{size:"sm",isEmphasized:!1,className:"mercoa-hidden group-hover:mercoa-block mercoa-ml-2",onClick:()=>cr(!0),children:jsx(PencilIcon$1,{className:"mercoa-h-5 mercoa-w-5"})})]}),re&&((te==null?void 0:te.status)===javascript.Mercoa.BankStatus.New||(te==null?void 0:te.status)===javascript.Mercoa.BankStatus.Pending)&&jsxs("button",{className:"mercoa-relative mercoa-inline-flex mercoa-items-center mercoa-rounded-md mercoa-bg-green-600 mercoa-px-4 mercoa-py-2 mercoa-text-sm mercoa-font-medium mercoa-text-white mercoa-shadow-sm hover:mercoa-bg-green-700",onClick:()=>ir(!0),children:[(te==null?void 0:te.status)===javascript.Mercoa.BankStatus.New&&"Start Verification",(te==null?void 0:te.status)===javascript.Mercoa.BankStatus.Pending&&"Complete Verification"]})]}),re&&jsxs("div",{className:"mercoa-flex mercoa-cursor-pointer ",children:[jsx(DefaultPaymentMethodIndicator,{paymentMethod:te}),(te==null?void 0:te.status)===javascript.Mercoa.BankStatus.New&&jsx(Tooltip,{title:"Can only receive funds",children:jsx("span",{className:"mercoa-inline-flex mercoa-items-center mercoa-rounded-full mercoa-bg-indigo-100 mercoa-px-2.5 mercoa-py-0.5 mercoa-text-xs mercoa-font-medium mercoa-text-indigo-800",children:"New"})}),(te==null?void 0:te.status)===javascript.Mercoa.BankStatus.Verified&&jsx(Tooltip,{title:"Can send and receive funds",children:jsx("span",{className:"mercoa-inline-flex mercoa-items-center mercoa-rounded-full mercoa-bg-green-100 mercoa-px-2.5 mercoa-py-0.5 mercoa-text-xs mercoa-font-medium mercoa-text-green-800",children:"Verified"})}),(te==null?void 0:te.status)===javascript.Mercoa.BankStatus.Pending&&jsx(Tooltip,{title:"Can only receive funds",children:jsx("span",{className:"mercoa-inline-flex mercoa-items-center mercoa-rounded-full mercoa-bg-yellow-100 mercoa-px-2.5 mercoa-py-0.5 mercoa-text-xs mercoa-font-medium mercoa-text-yellow-800",children:"Pending"})}),((te==null?void 0:te.status)===javascript.Mercoa.BankStatus.VerificationFailed||(te==null?void 0:te.status)===javascript.Mercoa.BankStatus.Errored)&&jsx(Tooltip,{title:"Can only receive funds",children:jsx("span",{className:"mercoa-inline-flex mercoa-items-center mercoa-rounded-full mercoa-bg-red-100 mercoa-px-2.5 mercoa-py-0.5 mercoa-text-xs mercoa-font-medium mercoa-text-red-800",children:"VERIFICATION FAILED"})}),jsx(tt$1.Root,{show:!!ar,as:React$1.Fragment,children:jsxs(_t$1,{as:"div",className:"mercoa-relative mercoa-z-10",onClose:()=>ir(!1),children:[jsx(tt$1.Child,{as:React$1.Fragment,enter:"mercoa-ease-out mercoa-duration-300",enterFrom:"mercoa-opacity-0",enterTo:"mercoa-opacity-100",leave:"mercoa-ease-in mercoa-duration-200",leaveFrom:"mercoa-opacity-100",leaveTo:"mercoa-opacity-0",children:jsx("div",{className:"mercoa-fixed mercoa-inset-0 mercoa-bg-gray-500 mercoa-bg-mercoa-opacity-75 mercoa-transition-opacity"})}),jsx("div",{className:"mercoa-fixed mercoa-inset-0 mercoa-z-10 mercoa-overflow-y-auto",children:jsx("div",{className:"mercoa-flex mercoa-min-h-full mercoa-items-end mercoa-justify-center mercoa-p-4 mercoa-text-center sm:mercoa-items-center sm:mercoa-p-0",children:jsx(tt$1.Child,{as:React$1.Fragment,enter:"mercoa-ease-out mercoa-duration-300",enterFrom:"mercoa-opacity-0 mercoa-translate-y-4 sm:mercoa-translate-y-0 sm:mercoa-scale-95",enterTo:"mercoa-opacity-100 mercoa-translate-y-0 sm:mercoa-scale-100",leave:"mercoa-ease-in mercoa-duration-200",leaveFrom:"mercoa-opacity-100 mercoa-translate-y-0 sm:mercoa-scale-100",leaveTo:"mercoa-opacity-0 mercoa-translate-y-4 sm:mercoa-translate-y-0 sm:mercoa-scale-95",children:jsxs(_t$1.Panel,{className:"mercoa-relative mercoa-transform mercoa-rounded-lg mercoa-bg-white mercoa-px-4 mercoa-pt-5 mercoa-pb-4 mercoa-text-left mercoa-shadow-xl mercoa-transition-all sm:mercoa-my-8 sm:mercoa-w-full sm:mercoa-max-w-lg sm:mercoa-p-6",children:[jsx(_t$1.Title,{as:"h3",className:"mercoa-text-lg mercoa-font-medium mercoa-leading-6 mercoa-text-gray-900",children:"Verify Account"}),(te==null?void 0:te.status)===javascript.Mercoa.BankStatus.New&&jsxs(Fragment,{children:[jsx("p",{className:"mercoa-mt-5 mercoa-text-sm",children:"Mercoa will send two small deposits to verify this account. These deposits may take up to 1-2 days to appear."}),jsx("p",{className:"mercoa-mt-3 mercoa-text-sm",children:"Once transactions have been sent, you'll have 14 days to verify their values."}),((fr=or.organization)==null?void 0:fr.sandbox)&&jsxs("p",{className:"mercoa-mt-3 mercoa-rounded-md mercoa-bg-orange-200 mercoa-p-1 mercoa-text-sm",children:[jsx("b",{children:"Test Mode:"})," actual deposits will not be sent. Use 0 and 0 as the values to instantly verify the account in the next step."]}),jsx("button",{onClick:async()=>{var pr,dr,mr;(pr=or.entity)!=null&&pr.id&&(te!=null&&te.id)&&(await((mr=or.client)==null?void 0:mr.entity.paymentMethod.initiateMicroDeposits((dr=or.entity)==null?void 0:dr.id,te==null?void 0:te.id)),ir(!1),or.refresh())},className:"mercoa-mt-5 mercoa-inline-flex mercoa-w-full mercoa-justify-center mercoa-rounded-md mercoa-border mercoa-border-transparent mercoa-bg-indigo-600 mercoa-px-4 mercoa-py-2 mercoa-text-base mercoa-font-medium mercoa-text-white mercoa-shadow-sm hover:mercoa-bg-indigo-700 focus:mercoa-outline-none focus:mercoa-ring-2 focus:mercoa-ring-indigo-500 focus:mercoa-ring-offset-2 disabled:mercoa-bg-indigo-300 sm:mercoa-text-sm",children:"Send deposits"})]}),(te==null?void 0:te.status)===javascript.Mercoa.BankStatus.Pending&&jsxs("form",{onSubmit:ur(async pr=>{var dr,mr,yr;(dr=or.entity)!=null&&dr.id&&(te!=null&&te.id)&&(await((yr=or.client)==null?void 0:yr.entity.paymentMethod.completeMicroDeposits((mr=or.entity)==null?void 0:mr.id,te==null?void 0:te.id,{amounts:[Number(pr.md1),Number(pr.md2)]})),ir(!1),or.refresh())}),children:[jsx("p",{className:"mercoa-mt-5 mercoa-text-sm",children:"Micro-deposits may take up to 2 days to appear on your statement. Once you have both values please enter the amounts to verify this account."}),((hr=or.organization)==null?void 0:hr.sandbox)&&jsxs("p",{className:"mercoa-mt-3 mercoa-rounded-md mercoa-bg-orange-200 mercoa-p-1 mercoa-text-sm",children:[jsx("b",{children:"Test Mode:"})," use 0 and 0 to instantly verify this account."]}),jsxs("div",{className:"mercoa-mt-2",children:[jsx("label",{htmlFor:"md1",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Amount"}),jsx("div",{className:"mercoa-mt-1",children:jsx("input",{...lr("md1"),type:"number",placeholder:"0.00",step:.01,min:0,max:.99,className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-indigo-500 focus:mercoa-ring-indigo-500 sm:mercoa-text-sm"})})]}),jsxs("div",{className:"mercoa-mt-2",children:[jsx("label",{htmlFor:"md2",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Amount"}),jsx("div",{className:"mercoa-mt-1",children:jsx("input",{...lr("md2"),type:"number",placeholder:"0.00",step:.01,min:0,max:.99,className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-indigo-500 focus:mercoa-ring-indigo-500 sm:mercoa-text-sm"})})]}),jsx("button",{className:"mercoa-mt-5 mercoa-inline-flex mercoa-w-full mercoa-justify-center mercoa-rounded-md mercoa-border mercoa-border-transparent mercoa-bg-indigo-600 mercoa-px-4 mercoa-py-2 mercoa-text-base mercoa-font-medium mercoa-text-white mercoa-shadow-sm hover:mercoa-bg-indigo-700 focus:mercoa-outline-none focus:mercoa-ring-2 focus:mercoa-ring-indigo-500 focus:mercoa-ring-offset-2 disabled:mercoa-bg-indigo-300 sm:mercoa-text-sm",children:"Verify Account"})]})]})})})})]})})]})]},`${te==null?void 0:te.routingNumber} ${te==null?void 0:te.accountNumber}`):jsxs("div",{onClick:()=>{ce&&ce(te)},className:`mercoa-relative mercoa-flex mercoa-items-center mercoa-space-x-3 mercoa-rounded-lg mercoa-border mercoa-border-gray-300 mercoa-bg-white mercoa-px-6 mercoa-py-5 mercoa-shadow-sm focus-within:mercoa-ring-2 focus-within:mercoa-ring-indigo-500 focus-within:mercoa-ring-offset-2 hover:mercoa-border-gray-400 ${ce?"mercoa-cursor-pointer ":""}`,children:[jsx("div",{className:`mercoa-flex-shrink-0 mercoa-rounded-full mercoa-p-1 ${nr?"mercoa-text-mercoa-primary-text-invert mercoa-bg-mercoa-primary-light":"mercoa-bg-gray-200 mercoa-text-gray-600"}`,children:jsx(PlusIcon$1,{className:"mercoa-h-5 mercoa-w-5"})}),jsxs("div",{className:"mercoa-min-w-0 mercoa-flex-1",children:[jsx("span",{className:"mercoa-absolute mercoa-inset-0","aria-hidden":"true"}),jsx("p",{className:"mercoa-text-sm mercoa-font-medium mercoa-text-gray-900",children:"Add new bank account"}),jsx("p",{className:"mercoa-truncate mercoa-text-sm mercoa-text-gray-500"})]})]})}function AddCheck({onSubmit:ee,title:te,actions:ce,formOnlySubmit:re,check:nr}){const or=useMercoaSession(),ar=create$3({payToTheOrderOf:create$6().required(),addressLine1:create$6().required(),city:create$6().required(),stateOrProvince:create$6().required(),postalCode:create$6().required()}).required(),{register:ir,handleSubmit:sr}=useForm({defaultValues:nr,resolver:o(ar)});async function cr(lr){var ur,fr,hr;if((ur=or.entity)!=null&&ur.id){lr.country="US";const pr=await((hr=or.client)==null?void 0:hr.entity.paymentMethod.create((fr=or.entity)==null?void 0:fr.id,{...lr,type:"check"}));if(!ee)return;pr?ee(pr):ee()}}return jsxs("form",{className:"mercoa-space-y-3 mercoa-text-left",onSubmit:sr(re||cr),children:[te||jsx("h3",{className:"mercoa-text-center mercoa-text-lg mercoa-font-medium mercoa-leading-6 mercoa-text-gray-900",children:"Add Check Address"}),jsx(AddCheckForm,{register:ir}),ce||jsx("button",{className:"mercoa-relative mercoa-inline-flex mercoa-items-center mercoa-rounded-md mercoa-border mercoa-border-transparent mercoa-bg-indigo-600 mercoa-px-4 mercoa-py-2 mercoa-text-sm mercoa-font-medium mercoa-text-white mercoa-shadow-sm hover:mercoa-bg-indigo-700 focus:mercoa-outline-none focus:mercoa-ring-2 focus:mercoa-ring-indigo-500 focus:mercoa-ring-offset-2",children:"Add Check Address"})]})}function AddCheckForm({register:ee}){return jsxs("div",{className:"mercoa-mt-2",children:[jsx("div",{className:"mercoa-mt-1",children:jsx("input",{...ee("payToTheOrderOf"),type:"text",placeholder:"Pay To The Order Of",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-indigo-500 focus:mercoa-ring-indigo-500 sm:mercoa-text-sm"})}),jsx("div",{className:"mercoa-mt-1",children:jsx("input",{...ee("addressLine1"),type:"text",placeholder:"Address Line 1",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-indigo-500 focus:mercoa-ring-indigo-500 sm:mercoa-text-sm"})}),jsx("div",{className:"mercoa-mt-1",children:jsx("input",{...ee("addressLine2"),type:"text",placeholder:"Address Line 2",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-indigo-500 focus:mercoa-ring-indigo-500 sm:mercoa-text-sm"})}),jsx("div",{className:"mercoa-mt-1",children:jsx("input",{...ee("city"),type:"text",placeholder:"City",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-indigo-500 focus:mercoa-ring-indigo-500 sm:mercoa-text-sm"})}),jsx("div",{className:"mercoa-mt-1",children:jsx("input",{...ee("stateOrProvince"),type:"text",placeholder:"State Or Province",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-indigo-500 focus:mercoa-ring-indigo-500 sm:mercoa-text-sm"})}),jsx("div",{className:"mercoa-mt-1",children:jsx("input",{...ee("postalCode"),type:"text",placeholder:"Postal Code",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-indigo-500 focus:mercoa-ring-indigo-500 sm:mercoa-text-sm"})})]})}function CheckComponent({account:ee,onSelect:te,showEdit:ce,selected:re}){const nr=useMercoaSession();async function or(){var ar,ir,sr;nr.token&&((ar=nr.entity)!=null&&ar.id)&&(ee!=null&&ee.id)&&(await((sr=nr.client)==null?void 0:sr.entity.paymentMethod.delete((ir=nr.entity)==null?void 0:ir.id,ee==null?void 0:ee.id)),nr.refresh())}return ee?jsxs("div",{onClick:()=>{te&&te(ee)},className:`mercoa-relative mercoa-flex mercoa-items-center mercoa-space-x-3 mercoa-rounded-lg mercoa-border ${re?"mercoa-border-gray-600":"mercoa-border-gray-300"} mercoa-bg-white mercoa-px-6 mercoa-py-5 mercoa-shadow-sm focus-within:mercoa-ring-2 focus-within:mercoa-ring-indigo-500 focus-within:mercoa-ring-offset-2 ${te?"mercoa-cursor-pointer hover:mercoa-border-gray-400":""}`,children:[jsx("div",{className:`mercoa-flex-shrink-0 mercoa-rounded-full mercoa-p-1 ${re?"mercoa-text-mercoa-primary-text-invert mercoa-bg-mercoa-primary-light":"mercoa-bg-gray-200 mercoa-text-gray-600"}`,children:jsx(EnvelopeIcon$1,{className:"mercoa-h-5 mercoa-w-5"})}),jsxs("div",{className:"mercoa-min-w-0 mercoa-flex-1",children:[!ce&&jsx("span",{className:"mercoa-absolute mercoa-inset-0","aria-hidden":"true"}),jsx("p",{className:`mercoa-text-sm mercoa-font-medium mercoa-text-gray-900 ${re?"mercoa-underline":""}`,children:`${ee==null?void 0:ee.payToTheOrderOf}`}),jsx("p",{className:`mercoa-text-sm mercoa-font-medium mercoa-text-gray-900 ${re?"mercoa-underline":""}`,children:`${ee==null?void 0:ee.addressLine1}, ${ee==null?void 0:ee.addressLine2}`}),jsx("p",{className:`mercoa-text-sm mercoa-font-medium mercoa-text-gray-900 ${re?"mercoa-underline":""}`,children:`${ee==null?void 0:ee.city} ${ee==null?void 0:ee.stateOrProvince}, ${ee==null?void 0:ee.postalCode}`})]}),ce&&jsxs("div",{className:"mercoa-flex-shrink-0",children:[jsx(DefaultPaymentMethodIndicator,{paymentMethod:ee}),jsxs("button",{className:"mercoa-ml-1 mercoa-cursor-pointer hover:mercoa-text-red-300",onClick:()=>or(),children:[" ",jsx(TrashIcon$1,{className:"mercoa-h-5 mercoa-w-5"})]})]})]},`${ee==null?void 0:ee.addressLine1} ${ee==null?void 0:ee.addressLine1}`):jsxs("div",{onClick:()=>{te&&te()},className:`mercoa-relative mercoa-flex mercoa-items-center mercoa-space-x-3 mercoa-rounded-lg mercoa-border mercoa-border-gray-300 mercoa-bg-white mercoa-px-6 mercoa-py-5 mercoa-shadow-sm focus-within:mercoa-ring-2 focus-within:mercoa-ring-indigo-500 focus-within:mercoa-ring-offset-2 hover:mercoa-border-gray-400 ${te?"mercoa-cursor-pointer ":""}`,children:[jsx("div",{className:`mercoa-flex-shrink-0 mercoa-rounded-full mercoa-p-1 ${re?"mercoa-text-mercoa-primary-text-invert mercoa-bg-mercoa-primary-light":"mercoa-bg-gray-200 mercoa-text-gray-600"}`,children:jsx(PlusIcon$1,{className:"mercoa-h-5 mercoa-w-5"})}),jsxs("div",{className:"mercoa-min-w-0 mercoa-flex-1",children:[jsx("span",{className:"mercoa-absolute mercoa-inset-0","aria-hidden":"true"}),jsx("p",{className:"mercoa-text-sm mercoa-font-medium mercoa-text-gray-900",children:"Add new address"}),jsx("p",{className:"mercoa-truncate mercoa-text-sm mercoa-text-gray-500"})]})]})}var lib={},ReactGoogleAutocomplete$1={},usePlacesWidget$1={},utils={};Object.defineProperty(utils,"__esModule",{value:!0}),utils.loadGoogleMapScript=utils.isBrowser=void 0;var isBrowser=typeof window<"u"&&window.document;utils.isBrowser=isBrowser;var loadGoogleMapScript=function ee(te,ce){if(!isBrowser||typeof google<"u"&&google.maps&&google.maps.api)return Promise.resolve();var re=document.querySelectorAll('script[src*="'.concat(te,'"]'));if(re&&re.length)return new Promise(function(ar){if(typeof google<"u")return ar();re[0].addEventListener("load",function(){return ar()})});var nr=new URL(ce);nr.searchParams.set("callback","__REACT_GOOGLE_AUTOCOMPLETE_CALLBACK__");var or=document.createElement("script");return or.src=nr.toString(),new Promise(function(ar){window.__REACT_GOOGLE_AUTOCOMPLETE_CALLBACK__=ar,document.body.appendChild(or)})};utils.loadGoogleMapScript=loadGoogleMapScript;var constants={};Object.defineProperty(constants,"__esModule",{value:!0}),constants.GOOGLE_MAP_SCRIPT_BASE_URL=void 0;var GOOGLE_MAP_SCRIPT_BASE_URL="https://maps.googleapis.com/maps/api/js";constants.GOOGLE_MAP_SCRIPT_BASE_URL=GOOGLE_MAP_SCRIPT_BASE_URL;function _typeof$1(ee){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?_typeof$1=function(ce){return typeof ce}:_typeof$1=function(ce){return ce&&typeof Symbol=="function"&&ce.constructor===Symbol&&ce!==Symbol.prototype?"symbol":typeof ce},_typeof$1(ee)}Object.defineProperty(usePlacesWidget$1,"__esModule",{value:!0}),usePlacesWidget$1.default=usePlacesWidget;var _react$1=_interopRequireWildcard$1(React$1),_utils=utils,_constants=constants;function _getRequireWildcardCache$1(ee){if(typeof WeakMap!="function")return null;var te=new WeakMap,ce=new WeakMap;return(_getRequireWildcardCache$1=function(nr){return nr?ce:te})(ee)}function _interopRequireWildcard$1(ee,te){if(!te&&ee&&ee.__esModule)return ee;if(ee===null||_typeof$1(ee)!=="object"&&typeof ee!="function")return{default:ee};var ce=_getRequireWildcardCache$1(te);if(ce&&ce.has(ee))return ce.get(ee);var re={},nr=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var or in ee)if(or!=="default"&&Object.prototype.hasOwnProperty.call(ee,or)){var ar=nr?Object.getOwnPropertyDescriptor(ee,or):null;ar&&(ar.get||ar.set)?Object.defineProperty(re,or,ar):re[or]=ee[or]}return re.default=ee,ce&&ce.set(ee,re),re}function ownKeys(ee,te){var ce=Object.keys(ee);if(Object.getOwnPropertySymbols){var re=Object.getOwnPropertySymbols(ee);te&&(re=re.filter(function(nr){return Object.getOwnPropertyDescriptor(ee,nr).enumerable})),ce.push.apply(ce,re)}return ce}function _objectSpread(ee){for(var te=1;te<arguments.length;te++){var ce=arguments[te]!=null?arguments[te]:{};te%2?ownKeys(Object(ce),!0).forEach(function(re){_defineProperty(ee,re,ce[re])}):Object.getOwnPropertyDescriptors?Object.defineProperties(ee,Object.getOwnPropertyDescriptors(ce)):ownKeys(Object(ce)).forEach(function(re){Object.defineProperty(ee,re,Object.getOwnPropertyDescriptor(ce,re))})}return ee}function _defineProperty(ee,te,ce){return te in ee?Object.defineProperty(ee,te,{value:ce,enumerable:!0,configurable:!0,writable:!0}):ee[te]=ce,ee}function _objectWithoutProperties$1(ee,te){if(ee==null)return{};var ce=_objectWithoutPropertiesLoose$1(ee,te),re,nr;if(Object.getOwnPropertySymbols){var or=Object.getOwnPropertySymbols(ee);for(nr=0;nr<or.length;nr++)re=or[nr],!(te.indexOf(re)>=0)&&Object.prototype.propertyIsEnumerable.call(ee,re)&&(ce[re]=ee[re])}return ce}function _objectWithoutPropertiesLoose$1(ee,te){if(ee==null)return{};var ce={},re=Object.keys(ee),nr,or;for(or=0;or<re.length;or++)nr=re[or],!(te.indexOf(nr)>=0)&&(ce[nr]=ee[nr]);return ce}function usePlacesWidget(ee){var te=ee.ref,ce=ee.onPlaceSelected,re=ee.apiKey,nr=ee.libraries,or=nr===void 0?"places":nr,ar=ee.inputAutocompleteValue,ir=ar===void 0?"new-password":ar,sr=ee.options;sr=sr===void 0?{}:sr;var cr=sr.types,lr=cr===void 0?["(cities)"]:cr,ur=sr.componentRestrictions,fr=sr.fields,hr=fr===void 0?["address_components","geometry.location","place_id","formatted_address"]:fr,pr=sr.bounds,dr=_objectWithoutProperties$1(sr,["types","componentRestrictions","fields","bounds"]),mr=ee.googleMapsScriptBaseUrl,yr=mr===void 0?_constants.GOOGLE_MAP_SCRIPT_BASE_URL:mr,Mr=ee.language,Sr=(0,_react$1.useRef)(null),Er=(0,_react$1.useRef)(null),br=(0,_react$1.useRef)(null),_r=(0,_react$1.useRef)(null),xr=Mr?"&language=".concat(Mr):"",jr="".concat(yr,"?libraries=").concat(or,"&key=").concat(re).concat(xr),wr=(0,_react$1.useCallback)(function(){return(0,_utils.loadGoogleMapScript)(yr,jr)},[yr,jr]);return(0,_react$1.useEffect)(function(){var Ir=_objectSpread(_objectSpread({},dr),{},{fields:hr,types:lr,bounds:pr});if(ur&&(Ir.componentRestrictions=ur),!(br.current||!Sr.current||!_utils.isBrowser)){te&&!te.current&&(te.current=Sr.current);var Br=function(){var Ur;if(typeof google>"u")return console.error("Google has not been found. Make sure your provide apiKey prop.");if(!((Ur=google.maps)!==null&&Ur!==void 0&&Ur.places))return console.error("Google maps places API must be loaded.");if(!Sr.current instanceof HTMLInputElement)return console.error("Input ref must be HTMLInputElement.");br.current=new google.maps.places.Autocomplete(Sr.current,Ir),br.current&&(Er.current=br.current.addListener("place_changed",function(){ce&&br&&br.current&&ce(br.current.getPlace(),Sr.current,br.current)}))};return re?wr().then(function(){return Br()}):Br(),function(){return Er.current?Er.current.remove():void 0}}},[]),(0,_react$1.useEffect)(function(){var Ir;!(_react$1.default!==null&&_react$1.default!==void 0&&(Ir=_react$1.default.version)!==null&&Ir!==void 0&&Ir.startsWith("18"))&&_utils.isBrowser&&window.MutationObserver&&Sr.current&&Sr.current instanceof HTMLInputElement&&(_r.current=new MutationObserver(function(){_r.current.disconnect(),Sr.current&&(Sr.current.autocomplete=ir)}),_r.current.observe(Sr.current,{attributes:!0,attributeFilter:["autocomplete"]}))},[ir]),(0,_react$1.useEffect)(function(){br.current&&br.current.setFields(hr)},[hr]),(0,_react$1.useEffect)(function(){br.current&&br.current.setBounds(pr)},[pr]),(0,_react$1.useEffect)(function(){br.current&&br.current.setComponentRestrictions(ur)},[ur]),(0,_react$1.useEffect)(function(){br.current&&br.current.setOptions(dr)},[dr]),{ref:Sr,autocompleteRef:br}}function _typeof(ee){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?_typeof=function(ce){return typeof ce}:_typeof=function(ce){return ce&&typeof Symbol=="function"&&ce.constructor===Symbol&&ce!==Symbol.prototype?"symbol":typeof ce},_typeof(ee)}Object.defineProperty(ReactGoogleAutocomplete$1,"__esModule",{value:!0}),ReactGoogleAutocomplete$1.default=void 0;var _react=_interopRequireWildcard(React$1),_propTypes=_interopRequireDefault(propTypesExports),_usePlacesWidget2=_interopRequireDefault(usePlacesWidget$1);function _interopRequireDefault(ee){return ee&&ee.__esModule?ee:{default:ee}}function _getRequireWildcardCache(ee){if(typeof WeakMap!="function")return null;var te=new WeakMap,ce=new WeakMap;return(_getRequireWildcardCache=function(nr){return nr?ce:te})(ee)}function _interopRequireWildcard(ee,te){if(!te&&ee&&ee.__esModule)return ee;if(ee===null||_typeof(ee)!=="object"&&typeof ee!="function")return{default:ee};var ce=_getRequireWildcardCache(te);if(ce&&ce.has(ee))return ce.get(ee);var re={},nr=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var or in ee)if(or!=="default"&&Object.prototype.hasOwnProperty.call(ee,or)){var ar=nr?Object.getOwnPropertyDescriptor(ee,or):null;ar&&(ar.get||ar.set)?Object.defineProperty(re,or,ar):re[or]=ee[or]}return re.default=ee,ce&&ce.set(ee,re),re}function _extends(){return _extends=Object.assign||function(ee){for(var te=1;te<arguments.length;te++){var ce=arguments[te];for(var re in ce)Object.prototype.hasOwnProperty.call(ce,re)&&(ee[re]=ce[re])}return ee},_extends.apply(this,arguments)}function _objectWithoutProperties(ee,te){if(ee==null)return{};var ce=_objectWithoutPropertiesLoose(ee,te),re,nr;if(Object.getOwnPropertySymbols){var or=Object.getOwnPropertySymbols(ee);for(nr=0;nr<or.length;nr++)re=or[nr],!(te.indexOf(re)>=0)&&Object.prototype.propertyIsEnumerable.call(ee,re)&&(ce[re]=ee[re])}return ce}function _objectWithoutPropertiesLoose(ee,te){if(ee==null)return{};var ce={},re=Object.keys(ee),nr,or;for(or=0;or<re.length;or++)nr=re[or],!(te.indexOf(nr)>=0)&&(ce[nr]=ee[nr]);return ce}function ReactGoogleAutocomplete(ee){var te=ee.onPlaceSelected,ce=ee.apiKey,re=ee.libraries,nr=ee.inputAutocompleteValue,or=ee.options,ar=ee.googleMapsScriptBaseUrl,ir=ee.refProp,sr=ee.language,cr=_objectWithoutProperties(ee,["onPlaceSelected","apiKey","libraries","inputAutocompleteValue","options","googleMapsScriptBaseUrl","refProp","language"]),lr=(0,_usePlacesWidget2.default)({ref:ir,googleMapsScriptBaseUrl:ar,onPlaceSelected:te,apiKey:ce,libraries:re,inputAutocompleteValue:nr,options:or,language:sr}),ur=lr.ref;return _react.default.createElement("input",_extends({ref:ur},cr))}ReactGoogleAutocomplete.propTypes={apiKey:_propTypes.default.string,libraries:_propTypes.default.arrayOf(_propTypes.default.string),ref:_propTypes.default.oneOfType([_propTypes.default.func,_propTypes.default.shape({current:_propTypes.default.any})]),googleMapsScriptBaseUrl:_propTypes.default.string,onPlaceSelected:_propTypes.default.func,inputAutocompleteValue:_propTypes.default.string,options:_propTypes.default.shape({componentRestrictions:_propTypes.default.object,bounds:_propTypes.default.object,location:_propTypes.default.object,offset:_propTypes.default.number,origin:_propTypes.default.object,radius:_propTypes.default.number,sessionToken:_propTypes.default.object,types:_propTypes.default.arrayOf(_propTypes.default.string)}),language:_propTypes.default.string};var _default=(0,_react.forwardRef)(function(ee,te){return _react.default.createElement(ReactGoogleAutocomplete,_extends({},ee,{refProp:te}))});ReactGoogleAutocomplete$1.default=_default,function(ee){Object.defineProperty(ee,"__esModule",{value:!0}),Object.defineProperty(ee,"default",{enumerable:!0,get:function(){return te.default}}),Object.defineProperty(ee,"usePlacesWidget",{enumerable:!0,get:function(){return ce.default}});var te=re(ReactGoogleAutocomplete$1),ce=re(usePlacesWidget$1);function re(nr){return nr&&nr.__esModule?nr:{default:nr}}}(lib);var reactGoogleAutocomplete=lib,reactInputMask={exports:{}},reactInputMask_production_min,hasRequiredReactInputMask_production_min;function requireReactInputMask_production_min(){if(hasRequiredReactInputMask_production_min)return reactInputMask_production_min;hasRequiredReactInputMask_production_min=1;function ee(Nr){return Nr&&typeof Nr=="object"&&"default"in Nr?Nr.default:Nr}var te=ee(React$1),ce=require$$2;function re(Nr,Fr){for(var Yr=Object.getOwnPropertyNames(Fr),Dr=0;Dr<Yr.length;Dr++){var vr=Yr[Dr],Or=Object.getOwnPropertyDescriptor(Fr,vr);Or&&Or.configurable&&Nr[vr]===void 0&&Object.defineProperty(Nr,vr,Or)}return Nr}function nr(){return(nr=Object.assign||function(Nr){for(var Fr=1;Fr<arguments.length;Fr++){var Yr=arguments[Fr];for(var Dr in Yr)Object.prototype.hasOwnProperty.call(Yr,Dr)&&(Nr[Dr]=Yr[Dr])}return Nr}).apply(this,arguments)}function or(Nr,Fr){Nr.prototype=Object.create(Fr.prototype),re(Nr.prototype.constructor=Nr,Fr)}function ar(Nr,Fr){if(Nr==null)return{};var Yr,Dr,vr={},Or=Object.keys(Nr);for(Dr=0;Dr<Or.length;Dr++)Yr=Or[Dr],0<=Fr.indexOf(Yr)||(vr[Yr]=Nr[Yr]);return vr}function ir(Nr){if(Nr===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return Nr}var sr=function(Nr,Fr,Yr,Dr,vr,Or,Tr,Pr){if(!Nr){var gr;if(Fr===void 0)gr=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var $r=[Yr,Dr,vr,Or,Tr,Pr],Rr=0;(gr=new Error(Fr.replace(/%s/g,function(){return $r[Rr++]}))).name="Invariant Violation"}throw gr.framesToPop=1,gr}},cr=sr;function lr(Nr,Fr,Yr){if("selectionStart"in Nr&&"selectionEnd"in Nr)Nr.selectionStart=Fr,Nr.selectionEnd=Yr;else{var Dr=Nr.createTextRange();Dr.collapse(!0),Dr.moveStart("character",Fr),Dr.moveEnd("character",Yr-Fr),Dr.select()}}function ur(Nr){var Fr=0,Yr=0;if("selectionStart"in Nr&&"selectionEnd"in Nr)Fr=Nr.selectionStart,Yr=Nr.selectionEnd;else{var Dr=document.selection.createRange();Dr.parentElement()===Nr&&(Fr=-Dr.moveStart("character",-Nr.value.length),Yr=-Dr.moveEnd("character",-Nr.value.length))}return{start:Fr,end:Yr,length:Yr-Fr}}var fr={9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},hr="_";function pr(Nr,Fr,Yr){var Dr="",vr="",Or=null,Tr=[];if(Fr===void 0&&(Fr=hr),Yr==null&&(Yr=fr),!Nr||typeof Nr!="string")return{maskChar:Fr,formatChars:Yr,mask:null,prefix:null,lastEditablePosition:null,permanents:[]};var Pr=!1;return Nr.split("").forEach(function(gr){Pr=!Pr&&gr==="\\"||(Pr||!Yr[gr]?(Tr.push(Dr.length),Dr.length===Tr.length-1&&(vr+=gr)):Or=Dr.length+1,Dr+=gr,!1)}),{maskChar:Fr,formatChars:Yr,prefix:vr,mask:Dr,lastEditablePosition:Or,permanents:Tr}}function dr(Nr,Fr){return Nr.permanents.indexOf(Fr)!==-1}function mr(Nr,Fr,Yr){var Dr=Nr.mask,vr=Nr.formatChars;if(!Yr)return!1;if(dr(Nr,Fr))return Dr[Fr]===Yr;var Or=vr[Dr[Fr]];return new RegExp(Or).test(Yr)}function yr(Nr,Fr){return Fr.split("").every(function(Yr,Dr){return dr(Nr,Dr)||!mr(Nr,Dr,Yr)})}function Mr(Nr,Fr){var Yr=Nr.maskChar,Dr=Nr.prefix;if(!Yr){for(;Fr.length>Dr.length&&dr(Nr,Fr.length-1);)Fr=Fr.slice(0,Fr.length-1);return Fr.length}for(var vr=Dr.length,Or=Fr.length;Or>=Dr.length;Or--){var Tr=Fr[Or];if(!dr(Nr,Or)&&mr(Nr,Or,Tr)){vr=Or+1;break}}return vr}function Sr(Nr,Fr){return Mr(Nr,Fr)===Nr.mask.length}function Er(Nr,Fr){var Yr=Nr.maskChar,Dr=Nr.mask,vr=Nr.prefix;if(!Yr){for((Fr=_r(Nr,"",Fr,0)).length<vr.length&&(Fr=vr);Fr.length<Dr.length&&dr(Nr,Fr.length);)Fr+=Dr[Fr.length];return Fr}if(Fr)return _r(Nr,Er(Nr,""),Fr,0);for(var Or=0;Or<Dr.length;Or++)dr(Nr,Or)?Fr+=Dr[Or]:Fr+=Yr;return Fr}function br(Nr,Fr,Yr,Dr){var vr=Yr+Dr,Or=Nr.maskChar,Tr=Nr.mask,Pr=Nr.prefix,gr=Fr.split("");if(Or)return gr.map(function(Rr,kr){return kr<Yr||vr<=kr?Rr:dr(Nr,kr)?Tr[kr]:Or}).join("");for(var $r=vr;$r<gr.length;$r++)dr(Nr,$r)&&(gr[$r]="");return Yr=Math.max(Pr.length,Yr),gr.splice(Yr,vr-Yr),Fr=gr.join(""),Er(Nr,Fr)}function _r(Nr,Fr,Yr,Dr){var vr=Nr.mask,Or=Nr.maskChar,Tr=Nr.prefix,Pr=Yr.split(""),gr=Sr(Nr,Fr);return!Or&&Dr>Fr.length&&(Fr+=vr.slice(Fr.length,Dr)),Pr.every(function($r){for(;qr=$r,dr(Nr,Cr=Dr)&&qr!==vr[Cr];){if(Dr>=Fr.length&&(Fr+=vr[Dr]),Rr=$r,kr=Dr,Or&&dr(Nr,kr)&&Rr===Or)return!0;if(++Dr>=vr.length)return!1}var Rr,kr,Cr,qr;return!mr(Nr,Dr,$r)&&$r!==Or||(Dr<Fr.length?Fr=Or||gr||Dr<Tr.length?Fr.slice(0,Dr)+$r+Fr.slice(Dr+1):(Fr=Fr.slice(0,Dr)+$r+Fr.slice(Dr),Er(Nr,Fr)):Or||(Fr+=$r),++Dr<vr.length)}),Fr}function xr(Nr,Fr,Yr,Dr){var vr=Nr.mask,Or=Nr.maskChar,Tr=Yr.split(""),Pr=Dr;return Tr.every(function(gr){for(;Rr=gr,dr(Nr,$r=Dr)&&Rr!==vr[$r];)if(++Dr>=vr.length)return!1;var $r,Rr;return(mr(Nr,Dr,gr)||gr===Or)&&Dr++,Dr<vr.length}),Dr-Pr}function jr(Nr,Fr){for(var Yr=Fr;0<=Yr;--Yr)if(!dr(Nr,Yr))return Yr;return null}function wr(Nr,Fr){for(var Yr=Nr.mask,Dr=Fr;Dr<Yr.length;++Dr)if(!dr(Nr,Dr))return Dr;return null}function Ir(Nr){return Nr||Nr===0?Nr+"":""}function Br(Nr,Fr,Yr,Dr,vr){var Or=Nr.mask,Tr=Nr.prefix,Pr=Nr.lastEditablePosition,gr=Fr,$r="",Rr=0,kr=0,Cr=Math.min(vr.start,Yr.start);return Yr.end>vr.start?kr=(Rr=xr(Nr,Dr,$r=gr.slice(vr.start,Yr.end),Cr))?vr.length:0:gr.length<Dr.length&&(kr=Dr.length-gr.length),gr=Dr,kr&&(kr===1&&!vr.length&&(Cr=vr.start===Yr.start?wr(Nr,Yr.start):jr(Nr,Yr.start)),gr=br(Nr,gr,Cr,kr)),gr=_r(Nr,gr,$r,Cr),(Cr+=Rr)>=Or.length?Cr=Or.length:Cr<Tr.length&&!Rr?Cr=Tr.length:Cr>=Tr.length&&Cr<Pr&&Rr&&(Cr=wr(Nr,Cr)),$r||($r=null),{value:gr=Er(Nr,gr),enteredString:$r,selection:{start:Cr,end:Cr}}}function Ar(){var Nr=new RegExp("windows","i"),Fr=new RegExp("phone","i"),Yr=navigator.userAgent;return Nr.test(Yr)&&Fr.test(Yr)}function Ur(Nr){return typeof Nr=="function"}function Lr(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame}function Zr(){return window.cancelAnimationFrame||window.webkitCancelRequestAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame}function nn(Nr){return(Zr()?Lr():function(){return setTimeout(Nr,1e3/60)})(Nr)}function rn(Nr){(Zr()||clearTimeout)(Nr)}var tn=function(Nr){function Fr(Dr){var vr=Nr.call(this,Dr)||this;vr.focused=!1,vr.mounted=!1,vr.previousSelection=null,vr.selectionDeferId=null,vr.saveSelectionLoopDeferId=null,vr.saveSelectionLoop=function(){vr.previousSelection=vr.getSelection(),vr.saveSelectionLoopDeferId=nn(vr.saveSelectionLoop)},vr.runSaveSelectionLoop=function(){vr.saveSelectionLoopDeferId===null&&vr.saveSelectionLoop()},vr.stopSaveSelectionLoop=function(){vr.saveSelectionLoopDeferId!==null&&(rn(vr.saveSelectionLoopDeferId),vr.saveSelectionLoopDeferId=null,vr.previousSelection=null)},vr.getInputDOMNode=function(){if(!vr.mounted)return null;var on=ce.findDOMNode(ir(ir(vr))),sn=typeof window<"u"&&on instanceof window.Element;if(on&&!sn)return null;if(on.nodeName!=="INPUT"&&(on=on.querySelector("input")),!on)throw new Error("react-input-mask: inputComponent doesn't contain input node");return on},vr.getInputValue=function(){var on=vr.getInputDOMNode();return on?on.value:null},vr.setInputValue=function(on){var sn=vr.getInputDOMNode();sn&&(vr.value=on,sn.value=on)},vr.setCursorToEnd=function(){var on=Mr(vr.maskOptions,vr.value),sn=wr(vr.maskOptions,on);sn!==null&&vr.setCursorPosition(sn)},vr.setSelection=function(on,sn,yn){yn===void 0&&(yn={});var jn=vr.getInputDOMNode(),wn=vr.isFocused();jn&&wn&&(yn.deferred||lr(jn,on,sn),vr.selectionDeferId!==null&&rn(vr.selectionDeferId),vr.selectionDeferId=nn(function(){vr.selectionDeferId=null,lr(jn,on,sn)}),vr.previousSelection={start:on,end:sn,length:Math.abs(sn-on)})},vr.getSelection=function(){return ur(vr.getInputDOMNode())},vr.getCursorPosition=function(){return vr.getSelection().start},vr.setCursorPosition=function(on){vr.setSelection(on,on)},vr.isFocused=function(){return vr.focused},vr.getBeforeMaskedValueChangeConfig=function(){var on=vr.maskOptions,sn=on.mask,yn=on.maskChar,jn=on.permanents,wn=on.formatChars;return{mask:sn,maskChar:yn,permanents:jn,alwaysShowMask:!!vr.props.alwaysShowMask,formatChars:wn}},vr.isInputAutofilled=function(on,sn,yn,jn){var wn=vr.getInputDOMNode();try{if(wn.matches(":-webkit-autofill"))return!0}catch{}return!vr.focused||jn.end<yn.length&&sn.end===on.length},vr.onChange=function(on){var sn=ir(ir(vr)).beforePasteState,yn=ir(ir(vr)).previousSelection,jn=vr.props.beforeMaskedValueChange,wn=vr.getInputValue(),Dn=vr.value,Rn=vr.getSelection();vr.isInputAutofilled(wn,Rn,Dn,yn)&&(Dn=Er(vr.maskOptions,""),yn={start:0,end:0,length:0}),sn&&(yn=sn.selection,Dn=sn.value,Rn={start:yn.start+wn.length,end:yn.start+wn.length,length:0},wn=Dn.slice(0,yn.start)+wn+Dn.slice(yn.end),vr.beforePasteState=null);var fn=Br(vr.maskOptions,wn,Rn,Dn,yn),Sn=fn.enteredString,gn=fn.selection,vn=fn.value;if(Ur(jn)){var Gr=jn({value:vn,selection:gn},{value:Dn,selection:yn},Sn,vr.getBeforeMaskedValueChangeConfig());vn=Gr.value,gn=Gr.selection}vr.setInputValue(vn),Ur(vr.props.onChange)&&vr.props.onChange(on),vr.isWindowsPhoneBrowser?vr.setSelection(gn.start,gn.end,{deferred:!0}):vr.setSelection(gn.start,gn.end)},vr.onFocus=function(on){var sn=vr.props.beforeMaskedValueChange,yn=vr.maskOptions,jn=yn.mask,wn=yn.prefix;if(vr.focused=!0,vr.mounted=!0,jn){if(vr.value)Mr(vr.maskOptions,vr.value)<vr.maskOptions.mask.length&&vr.setCursorToEnd();else{var Dn=Er(vr.maskOptions,wn),Rn=Er(vr.maskOptions,Dn),fn=Mr(vr.maskOptions,Rn),Sn=wr(vr.maskOptions,fn),gn={start:Sn,end:Sn};if(Ur(sn)){var vn=sn({value:Rn,selection:gn},{value:vr.value,selection:null},null,vr.getBeforeMaskedValueChangeConfig());Rn=vn.value,gn=vn.selection}var Gr=Rn!==vr.getInputValue();Gr&&vr.setInputValue(Rn),Gr&&Ur(vr.props.onChange)&&vr.props.onChange(on),vr.setSelection(gn.start,gn.end)}vr.runSaveSelectionLoop()}Ur(vr.props.onFocus)&&vr.props.onFocus(on)},vr.onBlur=function(on){var sn=vr.props.beforeMaskedValueChange,yn=vr.maskOptions.mask;if(vr.stopSaveSelectionLoop(),vr.focused=!1,yn&&!vr.props.alwaysShowMask&&yr(vr.maskOptions,vr.value)){var jn="";Ur(sn)&&(jn=sn({value:jn,selection:null},{value:vr.value,selection:vr.previousSelection},null,vr.getBeforeMaskedValueChangeConfig()).value);var wn=jn!==vr.getInputValue();wn&&vr.setInputValue(jn),wn&&Ur(vr.props.onChange)&&vr.props.onChange(on)}Ur(vr.props.onBlur)&&vr.props.onBlur(on)},vr.onMouseDown=function(on){if(!vr.focused&&document.addEventListener){vr.mouseDownX=on.clientX,vr.mouseDownY=on.clientY,vr.mouseDownTime=new Date().getTime();var sn=function yn(jn){if(document.removeEventListener("mouseup",yn),vr.focused){var wn=Math.abs(jn.clientX-vr.mouseDownX),Dn=Math.abs(jn.clientY-vr.mouseDownY),Rn=Math.max(wn,Dn),fn=new Date().getTime()-vr.mouseDownTime;(Rn<=10&&fn<=200||Rn<=5&&fn<=300)&&vr.setCursorToEnd()}};document.addEventListener("mouseup",sn)}Ur(vr.props.onMouseDown)&&vr.props.onMouseDown(on)},vr.onPaste=function(on){Ur(vr.props.onPaste)&&vr.props.onPaste(on),on.defaultPrevented||(vr.beforePasteState={value:vr.getInputValue(),selection:vr.getSelection()},vr.setInputValue(""))},vr.handleRef=function(on){vr.props.children==null&&Ur(vr.props.inputRef)&&vr.props.inputRef(on)};var Or=Dr.mask,Tr=Dr.maskChar,Pr=Dr.formatChars,gr=Dr.alwaysShowMask,$r=Dr.beforeMaskedValueChange,Rr=Dr.defaultValue,kr=Dr.value;vr.maskOptions=pr(Or,Tr,Pr),Rr==null&&(Rr=""),kr==null&&(kr=Rr);var Cr=Ir(kr);if(vr.maskOptions.mask&&(gr||Cr)&&(Cr=Er(vr.maskOptions,Cr),Ur($r))){var qr=Dr.value;Dr.value==null&&(qr=Rr),Cr=$r({value:Cr,selection:null},{value:qr=Ir(qr),selection:null},null,vr.getBeforeMaskedValueChangeConfig()).value}return vr.value=Cr,vr}or(Fr,Nr);var Yr=Fr.prototype;return Yr.componentDidMount=function(){this.mounted=!0,this.getInputDOMNode()&&(this.isWindowsPhoneBrowser=Ar(),this.maskOptions.mask&&this.getInputValue()!==this.value&&this.setInputValue(this.value))},Yr.componentDidUpdate=function(){var Dr=this.previousSelection,vr=this.props,Or=vr.beforeMaskedValueChange,Tr=vr.alwaysShowMask,Pr=vr.mask,gr=vr.maskChar,$r=vr.formatChars,Rr=this.maskOptions,kr=Tr||this.isFocused(),Cr=this.props.value!=null,qr=Cr?Ir(this.props.value):this.value,on=Dr?Dr.start:null;if(this.maskOptions=pr(Pr,gr,$r),this.maskOptions.mask){!Rr.mask&&this.isFocused()&&this.runSaveSelectionLoop();var sn=this.maskOptions.mask&&this.maskOptions.mask!==Rr.mask;if(Rr.mask||Cr||(qr=this.getInputValue()),(sn||this.maskOptions.mask&&(qr||kr))&&(qr=Er(this.maskOptions,qr)),sn){var yn=Mr(this.maskOptions,qr);(on===null||yn<on)&&(on=Sr(this.maskOptions,qr)?yn:wr(this.maskOptions,yn))}!this.maskOptions.mask||!yr(this.maskOptions,qr)||kr||Cr&&this.props.value||(qr="");var jn={start:on,end:on};if(Ur(Or)){var wn=Or({value:qr,selection:jn},{value:this.value,selection:this.previousSelection},null,this.getBeforeMaskedValueChangeConfig());qr=wn.value,jn=wn.selection}this.value=qr;var Dn=this.getInputValue()!==this.value;Dn?(this.setInputValue(this.value),this.forceUpdate()):sn&&this.forceUpdate();var Rn=!1;jn.start!=null&&jn.end!=null&&(Rn=!Dr||Dr.start!==jn.start||Dr.end!==jn.end),(Rn||Dn)&&this.setSelection(jn.start,jn.end)}else Rr.mask&&(this.stopSaveSelectionLoop(),this.forceUpdate())},Yr.componentWillUnmount=function(){this.mounted=!1,this.selectionDeferId!==null&&rn(this.selectionDeferId),this.stopSaveSelectionLoop()},Yr.render=function(){var Dr,vr=this.props,Or=(vr.mask,vr.alwaysShowMask,vr.maskChar,vr.formatChars,vr.inputRef,vr.beforeMaskedValueChange,vr.children),Tr=ar(vr,["mask","alwaysShowMask","maskChar","formatChars","inputRef","beforeMaskedValueChange","children"]);if(Or){Ur(Or)||cr(!1);var Pr=["onChange","onPaste","onMouseDown","onFocus","onBlur","value","disabled","readOnly"],gr=nr({},Tr);Pr.forEach(function(Rr){return delete gr[Rr]}),Dr=Or(gr),Pr.filter(function(Rr){return Dr.props[Rr]!=null&&Dr.props[Rr]!==Tr[Rr]}).length&&cr(!1)}else Dr=te.createElement("input",nr({ref:this.handleRef},Tr));var $r={onFocus:this.onFocus,onBlur:this.onBlur};return this.maskOptions.mask&&(Tr.disabled||Tr.readOnly||($r.onChange=this.onChange,$r.onPaste=this.onPaste,$r.onMouseDown=this.onMouseDown),Tr.value!=null&&($r.value=this.value)),Dr=te.cloneElement(Dr,$r)},Fr}(te.Component);return reactInputMask_production_min=tn,reactInputMask_production_min}var browser,hasRequiredBrowser;function requireBrowser(){if(hasRequiredBrowser)return browser;hasRequiredBrowser=1;var ee=function(te,ce,re,nr,or,ar,ir,sr){if(dist.process.env.NODE_ENV!=="production"&&ce===void 0)throw new Error("invariant requires an error message argument");if(!te){var cr;if(ce===void 0)cr=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var lr=[re,nr,or,ar,ir,sr],ur=0;cr=new Error(ce.replace(/%s/g,function(){return lr[ur++]})),cr.name="Invariant Violation"}throw cr.framesToPop=1,cr}};return browser=ee,browser}var reactInputMask_development,hasRequiredReactInputMask_development;function requireReactInputMask_development(){if(hasRequiredReactInputMask_development)return reactInputMask_development;hasRequiredReactInputMask_development=1;function ee(Nr){return Nr&&typeof Nr=="object"&&"default"in Nr?Nr.default:Nr}var te=ee(React$1),ce=require$$2,re=ee(requireBrowser()),nr=ee(requireWarning());function or(Nr,Fr){for(var Yr=Object.getOwnPropertyNames(Fr),Dr=0;Dr<Yr.length;Dr++){var vr=Yr[Dr],Or=Object.getOwnPropertyDescriptor(Fr,vr);Or&&Or.configurable&&Nr[vr]===void 0&&Object.defineProperty(Nr,vr,Or)}return Nr}function ar(){return ar=Object.assign||function(Nr){for(var Fr=1;Fr<arguments.length;Fr++){var Yr=arguments[Fr];for(var Dr in Yr)Object.prototype.hasOwnProperty.call(Yr,Dr)&&(Nr[Dr]=Yr[Dr])}return Nr},ar.apply(this,arguments)}function ir(Nr,Fr){Nr.prototype=Object.create(Fr.prototype),Nr.prototype.constructor=Nr,or(Nr,Fr)}function sr(Nr,Fr){if(Nr==null)return{};var Yr={},Dr=Object.keys(Nr),vr,Or;for(Or=0;Or<Dr.length;Or++)vr=Dr[Or],!(Fr.indexOf(vr)>=0)&&(Yr[vr]=Nr[vr]);return Yr}function cr(Nr){if(Nr===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return Nr}function lr(Nr,Fr,Yr){if("selectionStart"in Nr&&"selectionEnd"in Nr)Nr.selectionStart=Fr,Nr.selectionEnd=Yr;else{var Dr=Nr.createTextRange();Dr.collapse(!0),Dr.moveStart("character",Fr),Dr.moveEnd("character",Yr-Fr),Dr.select()}}function ur(Nr){var Fr=0,Yr=0;if("selectionStart"in Nr&&"selectionEnd"in Nr)Fr=Nr.selectionStart,Yr=Nr.selectionEnd;else{var Dr=document.selection.createRange();Dr.parentElement()===Nr&&(Fr=-Dr.moveStart("character",-Nr.value.length),Yr=-Dr.moveEnd("character",-Nr.value.length))}return{start:Fr,end:Yr,length:Yr-Fr}}var fr={9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},hr="_";function pr(Nr,Fr,Yr){var Dr="",vr="",Or=null,Tr=[];if(Fr===void 0&&(Fr=hr),Yr==null&&(Yr=fr),!Nr||typeof Nr!="string")return{maskChar:Fr,formatChars:Yr,mask:null,prefix:null,lastEditablePosition:null,permanents:[]};var Pr=!1;return Nr.split("").forEach(function(gr){!Pr&&gr==="\\"?Pr=!0:(Pr||!Yr[gr]?(Tr.push(Dr.length),Dr.length===Tr.length-1&&(vr+=gr)):Or=Dr.length+1,Dr+=gr,Pr=!1)}),{maskChar:Fr,formatChars:Yr,prefix:vr,mask:Dr,lastEditablePosition:Or,permanents:Tr}}function dr(Nr,Fr){return Nr.permanents.indexOf(Fr)!==-1}function mr(Nr,Fr,Yr){var Dr=Nr.mask,vr=Nr.formatChars;if(!Yr)return!1;if(dr(Nr,Fr))return Dr[Fr]===Yr;var Or=Dr[Fr],Tr=vr[Or];return new RegExp(Tr).test(Yr)}function yr(Nr,Fr){return Fr.split("").every(function(Yr,Dr){return dr(Nr,Dr)||!mr(Nr,Dr,Yr)})}function Mr(Nr,Fr){var Yr=Nr.maskChar,Dr=Nr.prefix;if(!Yr){for(;Fr.length>Dr.length&&dr(Nr,Fr.length-1);)Fr=Fr.slice(0,Fr.length-1);return Fr.length}for(var vr=Dr.length,Or=Fr.length;Or>=Dr.length;Or--){var Tr=Fr[Or],Pr=!dr(Nr,Or)&&mr(Nr,Or,Tr);if(Pr){vr=Or+1;break}}return vr}function Sr(Nr,Fr){return Mr(Nr,Fr)===Nr.mask.length}function Er(Nr,Fr){var Yr=Nr.maskChar,Dr=Nr.mask,vr=Nr.prefix;if(!Yr){for(Fr=_r(Nr,"",Fr,0),Fr.length<vr.length&&(Fr=vr);Fr.length<Dr.length&&dr(Nr,Fr.length);)Fr+=Dr[Fr.length];return Fr}if(Fr){var Or=Er(Nr,"");return _r(Nr,Or,Fr,0)}for(var Tr=0;Tr<Dr.length;Tr++)dr(Nr,Tr)?Fr+=Dr[Tr]:Fr+=Yr;return Fr}function br(Nr,Fr,Yr,Dr){var vr=Yr+Dr,Or=Nr.maskChar,Tr=Nr.mask,Pr=Nr.prefix,gr=Fr.split("");if(!Or){for(var $r=vr;$r<gr.length;$r++)dr(Nr,$r)&&(gr[$r]="");return Yr=Math.max(Pr.length,Yr),gr.splice(Yr,vr-Yr),Fr=gr.join(""),Er(Nr,Fr)}return gr.map(function(Rr,kr){return kr<Yr||kr>=vr?Rr:dr(Nr,kr)?Tr[kr]:Or}).join("")}function _r(Nr,Fr,Yr,Dr){var vr=Nr.mask,Or=Nr.maskChar,Tr=Nr.prefix,Pr=Yr.split(""),gr=Sr(Nr,Fr),$r=function(Cr,qr){return!dr(Nr,Cr)||qr===vr[Cr]},Rr=function(Cr,qr){return!Or||!dr(Nr,qr)||Cr!==Or};return!Or&&Dr>Fr.length&&(Fr+=vr.slice(Fr.length,Dr)),Pr.every(function(kr){for(;!$r(Dr,kr);){if(Dr>=Fr.length&&(Fr+=vr[Dr]),!Rr(kr,Dr))return!0;if(Dr++,Dr>=vr.length)return!1}var Cr=mr(Nr,Dr,kr)||kr===Or;return Cr?(Dr<Fr.length?Or||gr||Dr<Tr.length?Fr=Fr.slice(0,Dr)+kr+Fr.slice(Dr+1):(Fr=Fr.slice(0,Dr)+kr+Fr.slice(Dr),Fr=Er(Nr,Fr)):Or||(Fr+=kr),Dr++,Dr<vr.length):!0}),Fr}function xr(Nr,Fr,Yr,Dr){var vr=Nr.mask,Or=Nr.maskChar,Tr=Yr.split(""),Pr=Dr,gr=function(Rr,kr){return!dr(Nr,Rr)||kr===vr[Rr]};return Tr.every(function($r){for(;!gr(Dr,$r);)if(Dr++,Dr>=vr.length)return!1;var Rr=mr(Nr,Dr,$r)||$r===Or;return Rr&&Dr++,Dr<vr.length}),Dr-Pr}function jr(Nr,Fr){for(var Yr=Fr;Yr>=0;--Yr)if(!dr(Nr,Yr))return Yr;return null}function wr(Nr,Fr){for(var Yr=Nr.mask,Dr=Fr;Dr<Yr.length;++Dr)if(!dr(Nr,Dr))return Dr;return null}function Ir(Nr){return!Nr&&Nr!==0?"":Nr+""}function Br(Nr,Fr,Yr,Dr,vr){var Or=Nr.mask,Tr=Nr.prefix,Pr=Nr.lastEditablePosition,gr=Fr,$r="",Rr=0,kr=0,Cr=Math.min(vr.start,Yr.start);if(Yr.end>vr.start?($r=gr.slice(vr.start,Yr.end),Rr=xr(Nr,Dr,$r,Cr),Rr?kr=vr.length:kr=0):gr.length<Dr.length&&(kr=Dr.length-gr.length),gr=Dr,kr){if(kr===1&&!vr.length){var qr=vr.start===Yr.start;Cr=qr?wr(Nr,Yr.start):jr(Nr,Yr.start)}gr=br(Nr,gr,Cr,kr)}return gr=_r(Nr,gr,$r,Cr),Cr=Cr+Rr,Cr>=Or.length?Cr=Or.length:Cr<Tr.length&&!Rr?Cr=Tr.length:Cr>=Tr.length&&Cr<Pr&&Rr&&(Cr=wr(Nr,Cr)),gr=Er(Nr,gr),$r||($r=null),{value:gr,enteredString:$r,selection:{start:Cr,end:Cr}}}function Ar(){var Nr=new RegExp("windows","i"),Fr=new RegExp("phone","i"),Yr=navigator.userAgent;return Nr.test(Yr)&&Fr.test(Yr)}function Ur(Nr){return typeof Nr=="function"}function Lr(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame}function Zr(){return window.cancelAnimationFrame||window.webkitCancelRequestAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame}function nn(Nr){var Fr=!!Zr(),Yr;return Fr?Yr=Lr():Yr=function(){return setTimeout(Nr,1e3/60)},Yr(Nr)}function rn(Nr){var Fr=Zr()||clearTimeout;Fr(Nr)}var tn=function(Nr){ir(Fr,Nr);function Fr(Dr){var vr;vr=Nr.call(this,Dr)||this,vr.focused=!1,vr.mounted=!1,vr.previousSelection=null,vr.selectionDeferId=null,vr.saveSelectionLoopDeferId=null,vr.saveSelectionLoop=function(){vr.previousSelection=vr.getSelection(),vr.saveSelectionLoopDeferId=nn(vr.saveSelectionLoop)},vr.runSaveSelectionLoop=function(){vr.saveSelectionLoopDeferId===null&&vr.saveSelectionLoop()},vr.stopSaveSelectionLoop=function(){vr.saveSelectionLoopDeferId!==null&&(rn(vr.saveSelectionLoopDeferId),vr.saveSelectionLoopDeferId=null,vr.previousSelection=null)},vr.getInputDOMNode=function(){if(!vr.mounted)return null;var sn=ce.findDOMNode(cr(cr(vr))),yn=typeof window<"u"&&sn instanceof window.Element;if(sn&&!yn)return null;if(sn.nodeName!=="INPUT"&&(sn=sn.querySelector("input")),!sn)throw new Error("react-input-mask: inputComponent doesn't contain input node");return sn},vr.getInputValue=function(){var sn=vr.getInputDOMNode();return sn?sn.value:null},vr.setInputValue=function(sn){var yn=vr.getInputDOMNode();yn&&(vr.value=sn,yn.value=sn)},vr.setCursorToEnd=function(){var sn=Mr(vr.maskOptions,vr.value),yn=wr(vr.maskOptions,sn);yn!==null&&vr.setCursorPosition(yn)},vr.setSelection=function(sn,yn,jn){jn===void 0&&(jn={});var wn=vr.getInputDOMNode(),Dn=vr.isFocused();if(!(!wn||!Dn)){var Rn=jn,fn=Rn.deferred;fn||lr(wn,sn,yn),vr.selectionDeferId!==null&&rn(vr.selectionDeferId),vr.selectionDeferId=nn(function(){vr.selectionDeferId=null,lr(wn,sn,yn)}),vr.previousSelection={start:sn,end:yn,length:Math.abs(yn-sn)}}},vr.getSelection=function(){var sn=vr.getInputDOMNode();return ur(sn)},vr.getCursorPosition=function(){return vr.getSelection().start},vr.setCursorPosition=function(sn){vr.setSelection(sn,sn)},vr.isFocused=function(){return vr.focused},vr.getBeforeMaskedValueChangeConfig=function(){var sn=vr.maskOptions,yn=sn.mask,jn=sn.maskChar,wn=sn.permanents,Dn=sn.formatChars,Rn=vr.props.alwaysShowMask;return{mask:yn,maskChar:jn,permanents:wn,alwaysShowMask:!!Rn,formatChars:Dn}},vr.isInputAutofilled=function(sn,yn,jn,wn){var Dn=vr.getInputDOMNode();try{if(Dn.matches(":-webkit-autofill"))return!0}catch{}return vr.focused?wn.end<jn.length&&yn.end===sn.length:!0},vr.onChange=function(sn){var yn=cr(cr(vr)),jn=yn.beforePasteState,wn=cr(cr(vr)),Dn=wn.previousSelection,Rn=vr.props.beforeMaskedValueChange,fn=vr.getInputValue(),Sn=vr.value,gn=vr.getSelection();vr.isInputAutofilled(fn,gn,Sn,Dn)&&(Sn=Er(vr.maskOptions,""),Dn={start:0,end:0,length:0}),jn&&(Dn=jn.selection,Sn=jn.value,gn={start:Dn.start+fn.length,end:Dn.start+fn.length,length:0},fn=Sn.slice(0,Dn.start)+fn+Sn.slice(Dn.end),vr.beforePasteState=null);var vn=Br(vr.maskOptions,fn,gn,Sn,Dn),Gr=vn.enteredString,Qr=vn.selection,cn=vn.value;if(Ur(Rn)){var Xr=Rn({value:cn,selection:Qr},{value:Sn,selection:Dn},Gr,vr.getBeforeMaskedValueChangeConfig());cn=Xr.value,Qr=Xr.selection}vr.setInputValue(cn),Ur(vr.props.onChange)&&vr.props.onChange(sn),vr.isWindowsPhoneBrowser?vr.setSelection(Qr.start,Qr.end,{deferred:!0}):vr.setSelection(Qr.start,Qr.end)},vr.onFocus=function(sn){var yn=vr.props.beforeMaskedValueChange,jn=vr.maskOptions,wn=jn.mask,Dn=jn.prefix;if(vr.focused=!0,vr.mounted=!0,wn){if(vr.value)Mr(vr.maskOptions,vr.value)<vr.maskOptions.mask.length&&vr.setCursorToEnd();else{var Rn=Er(vr.maskOptions,Dn),fn=Er(vr.maskOptions,Rn),Sn=Mr(vr.maskOptions,fn),gn=wr(vr.maskOptions,Sn),vn={start:gn,end:gn};if(Ur(yn)){var Gr=yn({value:fn,selection:vn},{value:vr.value,selection:null},null,vr.getBeforeMaskedValueChangeConfig());fn=Gr.value,vn=Gr.selection}var Qr=fn!==vr.getInputValue();Qr&&vr.setInputValue(fn),Qr&&Ur(vr.props.onChange)&&vr.props.onChange(sn),vr.setSelection(vn.start,vn.end)}vr.runSaveSelectionLoop()}Ur(vr.props.onFocus)&&vr.props.onFocus(sn)},vr.onBlur=function(sn){var yn=vr.props.beforeMaskedValueChange,jn=vr.maskOptions.mask;if(vr.stopSaveSelectionLoop(),vr.focused=!1,jn&&!vr.props.alwaysShowMask&&yr(vr.maskOptions,vr.value)){var wn="";if(Ur(yn)){var Dn=yn({value:wn,selection:null},{value:vr.value,selection:vr.previousSelection},null,vr.getBeforeMaskedValueChangeConfig());wn=Dn.value}var Rn=wn!==vr.getInputValue();Rn&&vr.setInputValue(wn),Rn&&Ur(vr.props.onChange)&&vr.props.onChange(sn)}Ur(vr.props.onBlur)&&vr.props.onBlur(sn)},vr.onMouseDown=function(sn){if(!vr.focused&&document.addEventListener){vr.mouseDownX=sn.clientX,vr.mouseDownY=sn.clientY,vr.mouseDownTime=new Date().getTime();var yn=function jn(wn){if(document.removeEventListener("mouseup",jn),!!vr.focused){var Dn=Math.abs(wn.clientX-vr.mouseDownX),Rn=Math.abs(wn.clientY-vr.mouseDownY),fn=Math.max(Dn,Rn),Sn=new Date().getTime()-vr.mouseDownTime;(fn<=10&&Sn<=200||fn<=5&&Sn<=300)&&vr.setCursorToEnd()}};document.addEventListener("mouseup",yn)}Ur(vr.props.onMouseDown)&&vr.props.onMouseDown(sn)},vr.onPaste=function(sn){Ur(vr.props.onPaste)&&vr.props.onPaste(sn),sn.defaultPrevented||(vr.beforePasteState={value:vr.getInputValue(),selection:vr.getSelection()},vr.setInputValue(""))},vr.handleRef=function(sn){vr.props.children==null&&Ur(vr.props.inputRef)&&vr.props.inputRef(sn)};var Or=Dr.mask,Tr=Dr.maskChar,Pr=Dr.formatChars,gr=Dr.alwaysShowMask,$r=Dr.beforeMaskedValueChange,Rr=Dr.defaultValue,kr=Dr.value;vr.maskOptions=pr(Or,Tr,Pr),Rr==null&&(Rr=""),kr==null&&(kr=Rr);var Cr=Ir(kr);if(vr.maskOptions.mask&&(gr||Cr)&&(Cr=Er(vr.maskOptions,Cr),Ur($r))){var qr=Dr.value;Dr.value==null&&(qr=Rr),qr=Ir(qr);var on=$r({value:Cr,selection:null},{value:qr,selection:null},null,vr.getBeforeMaskedValueChangeConfig());Cr=on.value}return vr.value=Cr,vr}var Yr=Fr.prototype;return Yr.componentDidMount=function(){this.mounted=!0,this.getInputDOMNode()&&(this.isWindowsPhoneBrowser=Ar(),this.maskOptions.mask&&this.getInputValue()!==this.value&&this.setInputValue(this.value))},Yr.componentDidUpdate=function(){var vr=this.previousSelection,Or=this.props,Tr=Or.beforeMaskedValueChange,Pr=Or.alwaysShowMask,gr=Or.mask,$r=Or.maskChar,Rr=Or.formatChars,kr=this.maskOptions,Cr=Pr||this.isFocused(),qr=this.props.value!=null,on=qr?Ir(this.props.value):this.value,sn=vr?vr.start:null;if(this.maskOptions=pr(gr,$r,Rr),this.maskOptions.mask)!kr.mask&&this.isFocused()&&this.runSaveSelectionLoop();else{kr.mask&&(this.stopSaveSelectionLoop(),this.forceUpdate());return}var yn=this.maskOptions.mask&&this.maskOptions.mask!==kr.mask;if(!kr.mask&&!qr&&(on=this.getInputValue()),(yn||this.maskOptions.mask&&(on||Cr))&&(on=Er(this.maskOptions,on)),yn){var jn=Mr(this.maskOptions,on);(sn===null||jn<sn)&&(Sr(this.maskOptions,on)?sn=jn:sn=wr(this.maskOptions,jn))}this.maskOptions.mask&&yr(this.maskOptions,on)&&!Cr&&(!qr||!this.props.value)&&(on="");var wn={start:sn,end:sn};if(Ur(Tr)){var Dn=Tr({value:on,selection:wn},{value:this.value,selection:this.previousSelection},null,this.getBeforeMaskedValueChangeConfig());on=Dn.value,wn=Dn.selection}this.value=on;var Rn=this.getInputValue()!==this.value;Rn?(this.setInputValue(this.value),this.forceUpdate()):yn&&this.forceUpdate();var fn=!1;wn.start!=null&&wn.end!=null&&(fn=!vr||vr.start!==wn.start||vr.end!==wn.end),(fn||Rn)&&this.setSelection(wn.start,wn.end)},Yr.componentWillUnmount=function(){this.mounted=!1,this.selectionDeferId!==null&&rn(this.selectionDeferId),this.stopSaveSelectionLoop()},Yr.render=function(){var vr=this.props,Or=vr.mask;vr.alwaysShowMask;var Tr=vr.maskChar,Pr=vr.formatChars,gr=vr.inputRef;vr.beforeMaskedValueChange;var $r=vr.children,Rr=sr(vr,["mask","alwaysShowMask","maskChar","formatChars","inputRef","beforeMaskedValueChange","children"]),kr;if(dist.process.env.NODE_ENV!=="production"&&nr(!Rr.maxLength||!pr(Or,Tr,Pr).mask,"react-input-mask: maxLength property shouldn't be passed to the masked input. It breaks masking and unnecessary because length is limited by the mask length."),$r){Ur($r)||(dist.process.env.NODE_ENV!=="production"?re(!1,"react-input-mask: children must be a function"):re(!1));var Cr=["onChange","onPaste","onMouseDown","onFocus","onBlur","value","disabled","readOnly"],qr=ar({},Rr);Cr.forEach(function(yn){return delete qr[yn]}),kr=$r(qr);var on=Cr.filter(function(yn){return kr.props[yn]!=null&&kr.props[yn]!==Rr[yn]});on.length&&(dist.process.env.NODE_ENV!=="production"?re(!1,"react-input-mask: the following props should be passed to the react-input-mask's component and should not be altered in children's function: "+on.join(", ")):re(!1)),dist.process.env.NODE_ENV!=="production"&&nr(!gr,"react-input-mask: inputRef is ignored when children is passed, attach ref to the children instead")}else kr=te.createElement("input",ar({ref:this.handleRef},Rr));var sn={onFocus:this.onFocus,onBlur:this.onBlur};return this.maskOptions.mask&&(!Rr.disabled&&!Rr.readOnly&&(sn.onChange=this.onChange,sn.onPaste=this.onPaste,sn.onMouseDown=this.onMouseDown),Rr.value!=null&&(sn.value=this.value)),kr=te.cloneElement(kr,sn),kr},Fr}(te.Component);return reactInputMask_development=tn,reactInputMask_development}dist.process.env.NODE_ENV==="production"?reactInputMask.exports=requireReactInputMask_production_min():reactInputMask.exports=requireReactInputMask_development();var reactInputMaskExports=reactInputMask.exports;const InputMask=getDefaultExportFromCjs(reactInputMaskExports);function CustomPaymentMethod({children:ee,onSelect:te,showEdit:ce,schema:re}){var cr;const[nr,or]=React$1.useState(),[ar,ir]=React$1.useState(!1),sr=useMercoaSession();return React$1.useEffect(()=>{var lr,ur,fr;sr.token&&((lr=sr.entity)!=null&&lr.id)&&((fr=sr.client)==null||fr.entity.paymentMethod.getAll((ur=sr.entity)==null?void 0:ur.id,{type:"custom"}).then(hr=>{or(hr.map(pr=>pr))}))},[(cr=sr.entity)==null?void 0:cr.id,sr.token,ar,sr.refreshId]),ee?ee({paymentMethods:nr}):jsxs(Fragment,{children:[!nr&&jsx("div",{className:"mercoa-p-9 mercoa-text-center",children:jsx(LoadingSpinnerIcon,{})}),nr&&(nr==null?void 0:nr.map(lr=>jsx("div",{className:"mercoa-mt-2",children:jsx(CustomPaymentMethodComponent,{account:lr,onSelect:te,schema:re,showEdit:ce})},lr.id)))]})}function CustomPaymentMethodComponent({children:ee,account:te,onSelect:ce,selected:re,showEdit:nr,schema:or}){if(te){const{accountName:ar,accountNumber:ir}=findCustomPaymentMethodAccountNameAndNumber(te);return jsxs("div",{onClick:()=>{ce&&ce(te)},className:`mercoa-relative mercoa-flex mercoa-items-center mercoa-space-x-3 mercoa-rounded-lg mercoa-border ${re?"mercoa-border-gray-600":"mercoa-border-gray-300"} mercoa-bg-white mercoa-px-6 mercoa-py-5 mercoa-shadow-sm focus-within:mercoa-ring-2 focus-within:mercoa-ring-indigo-500 focus-within:mercoa-ring-offset-2 ${ce?"mercoa-cursor-pointer hover:mercoa-border-gray-400":""}`,children:[jsx("div",{className:`mercoa-flex-shrink-0 mercoa-rounded-full mercoa-p-1 ${re?"mercoa-text-mercoa-primary-text-invert mercoa-bg-mercoa-primary-light":"mercoa-bg-gray-200 mercoa-text-gray-600"}`,children:jsx(BuildingLibraryIcon$1,{className:"mercoa-h-5 mercoa-w-5"})}),jsx("div",{className:"mercoa-flex mercoa-min-w-0 mercoa-flex-1 mercoa-justify-between",children:jsxs("div",{children:[!nr&&jsx("span",{className:"mercoa-absolute mercoa-inset-0","aria-hidden":"true"}),jsx("p",{className:`mercoa-text-sm mercoa-font-medium mercoa-text-gray-900 ${re?"mercoa-underline":""}`,children:`${capitalize(ar)} ${ir?`••••${String(ir).slice(-4)}`:""}`})]})}),nr&&jsx("div",{className:"mercoa-flex mercoa-cursor-pointer ",children:jsx(DefaultPaymentMethodIndicator,{paymentMethod:te})})]},te==null?void 0:te.id)}else return or?jsxs("div",{onClick:()=>{ce&&ce()},className:`mercoa-relative mercoa-flex mercoa-items-center mercoa-space-x-3 mercoa-rounded-lg mercoa-border ${re?"mercoa-border-gray-600":"mercoa-border-gray-300"} mercoa-bg-white mercoa-px-6 mercoa-py-5 mercoa-shadow-sm focus-within:mercoa-ring-2 focus-within:mercoa-ring-indigo-500 focus-within:mercoa-ring-offset-2 ${ce?"mercoa-cursor-pointer hover:mercoa-border-gray-400":""}`,children:[jsx("div",{className:`mercoa-flex-shrink-0 mercoa-rounded-full mercoa-p-1 ${re?"mercoa-text-mercoa-primary-text-invert mercoa-bg-mercoa-primary-light":"mercoa-bg-gray-200 mercoa-text-gray-600"}`,children:jsx(BuildingLibraryIcon$1,{className:"mercoa-h-5 mercoa-w-5"})}),jsx("div",{className:"mercoa-flex mercoa-min-w-0 mercoa-flex-1 mercoa-justify-between",children:jsxs("div",{children:[jsx("span",{className:"mercoa-absolute mercoa-inset-0","aria-hidden":"true"}),jsxs("p",{className:`mercoa-text-sm mercoa-font-medium mercoa-text-gray-900 ${re?"mercoa-underline":""}`,children:["Add new ",or.name]})]})})]}):jsx(Fragment,{})}function AddCustomPaymentMethod({onSubmit:ee,title:te,actions:ce,formOnlySubmit:re,custom:nr,schema:or}){const ar=useMercoaSession(),{register:ir,handleSubmit:sr,control:cr}=useForm();async function lr(ur){var hr,pr,dr;const fr={};if(Object.entries(ur).forEach(([mr,yr])=>{mr.startsWith("~cpm~~")&&yr.forEach(Mr=>{fr[Mr.name]=`${fr[Mr.name]??Mr.value}`})}),(hr=ar.entity)!=null&&hr.id){const mr=await((dr=ar.client)==null?void 0:dr.entity.paymentMethod.create((pr=ar.entity)==null?void 0:pr.id,{type:"custom",schemaId:or==null?void 0:or.id,data:fr,foreignId:Math.random().toString(36).substring(7)}));if(!ee)return;mr?ee(mr):ee()}}return jsxs("form",{className:"mercoa-space-y-3 mercoa-text-left",onSubmit:sr(re||lr),children:[te||jsx("h3",{className:"mercoa-text-center mercoa-text-lg mercoa-font-medium mercoa-leading-6 mercoa-text-gray-900",children:or.name}),jsx(AddCustomPaymentMethodForm,{register:ir,schema:or,control:cr}),ce||jsx("button",{className:"mercoa-relative mercoa-inline-flex mercoa-items-center mercoa-rounded-md mercoa-border mercoa-border-transparent mercoa-bg-indigo-600 mercoa-px-4 mercoa-py-2 mercoa-text-sm mercoa-font-medium mercoa-text-white mercoa-shadow-sm hover:mercoa-bg-indigo-700 focus:mercoa-outline-none focus:mercoa-ring-2 focus:mercoa-ring-indigo-500 focus:mercoa-ring-offset-2",children:"Add"})]})}function AddCustomPaymentMethodForm({register:ee,control:te,schema:ce}){const[re,nr]=React$1.useState(),{append:or,fields:ar}=useFieldArray({control:te,name:"~cpm~~"});return React$1.useEffect(()=>{re||ce&&nr(Object.values((ce==null?void 0:ce.fields)??{}))},[ce,re]),React$1.useEffect(()=>{re&&re.forEach(ir=>{or(ir,{focusIndex:0})})},[re]),jsx("div",{className:"mercoa-mt-2",children:ar==null?void 0:ar.map((ir,sr)=>{var cr,lr,ur,fr,hr,pr,dr,mr,yr,Mr,Sr,Er,br,_r,xr,jr,wr,Ir,Br,Ar,Ur;return jsxs("div",{className:"mercoa-mt-1",children:[jsx("label",{htmlFor:`~cpm~~.${sr}.value`,className:"mercoa-block mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:((cr=re==null?void 0:re[sr])==null?void 0:cr.displayName)||((lr=re==null?void 0:re[sr])==null?void 0:lr.name)}),((ur=re==null?void 0:re[sr])==null?void 0:ur.type)===javascript.Mercoa.CustomPaymentMethodSchemaFieldType.Text&&jsx("input",{...ee(`~cpm~~.${sr}.value`),type:"text",required:!((fr=re==null?void 0:re[sr])!=null&&fr.optional),placeholder:`${((hr=re==null?void 0:re[sr])==null?void 0:hr.displayName)||((pr=re==null?void 0:re[sr])==null?void 0:pr.name)}`,className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm"}),((dr=re==null?void 0:re[sr])==null?void 0:dr.type)===javascript.Mercoa.CustomPaymentMethodSchemaFieldType.Url&&jsx("input",{...ee(`~cpm~~.${sr}.value`,{pattern:{value:/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/,message:"Invalid URL"}}),type:"text",required:!((mr=re==null?void 0:re[sr])!=null&&mr.optional),placeholder:"https://example.com",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm"}),((yr=re==null?void 0:re[sr])==null?void 0:yr.type)===javascript.Mercoa.CustomPaymentMethodSchemaFieldType.Email&&jsx(Fragment,{children:jsx("input",{...ee(`~cpm~~.${sr}.value`,{pattern:{value:/(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/,message:"Invalid email"}}),type:"text",required:!((Mr=re==null?void 0:re[sr])!=null&&Mr.optional),placeholder:"name@example.com",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm"})}),((Sr=re==null?void 0:re[sr])==null?void 0:Sr.type)===javascript.Mercoa.CustomPaymentMethodSchemaFieldType.Number&&jsx("input",{...ee(`~cpm~~.${sr}.value`),type:"number",required:!((Er=re==null?void 0:re[sr])!=null&&Er.optional),placeholder:`${((br=re==null?void 0:re[sr])==null?void 0:br.displayName)||((_r=re==null?void 0:re[sr])==null?void 0:_r.name)}`,className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm"}),((xr=re==null?void 0:re[sr])==null?void 0:xr.type)===javascript.Mercoa.CustomPaymentMethodSchemaFieldType.Select&&jsx("select",{...ee(`~cpm~~.${sr}.value`),required:!((jr=re==null?void 0:re[sr])!=null&&jr.optional),className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm",children:(Ir=(wr=re==null?void 0:re[sr])==null?void 0:wr.options)==null?void 0:Ir.map((Lr,Zr)=>jsx("option",{value:Lr,children:Lr},Zr))}),((Br=re==null?void 0:re[sr])==null?void 0:Br.type)===javascript.Mercoa.CustomPaymentMethodSchemaFieldType.Date&&jsx(Controller,{control:te,name:`~cpm~~.${sr}.value`,render:({field:Lr})=>{var Zr;return jsx(er,{className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm",onChange:nn=>Lr.onChange(nn),selected:Lr.value,required:!((Zr=re==null?void 0:re[sr])!=null&&Zr.optional),placeholderText:"Select a date"})}}),((Ar=re==null?void 0:re[sr])==null?void 0:Ar.type)===javascript.Mercoa.CustomPaymentMethodSchemaFieldType.Phone&&jsx(Controller,{control:te,name:`~cpm~~.${sr}.value`,render:({field:Lr})=>{var Zr;return jsx(InputMask,{mask:"(999) 999-9999",value:Lr.value,onChange:Lr.onChange,required:!((Zr=re==null?void 0:re[sr])!=null&&Zr.optional),children:nn=>jsx("input",{...nn,type:"text",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm",placeholder:"(777) 777-7777"})})}}),((Ur=re==null?void 0:re[sr])==null?void 0:Ur.type)===javascript.Mercoa.CustomPaymentMethodSchemaFieldType.Address&&jsx(Controller,{control:te,name:`~cpm~~.${sr}.value`,render:({field:Lr})=>{var Zr;return jsx(CustomAddressBlock,{setValue:Lr.onChange,trigger:Lr.onBlur,required:!((Zr=re==null?void 0:re[sr])!=null&&Zr.optional)})}})]},ir.id)})})}function CustomAddressBlock({setValue:ee,trigger:te,required:ce}){const re=useMercoaSession(),{ref:nr}=reactGoogleAutocomplete.usePlacesWidget({apiKey:re.googleMapsApiKey,onPlaceSelected:async or=>{var ur,fr,hr,pr,dr;const ar=(ur=or.address_components.find(mr=>mr.types.includes("street_number")))==null?void 0:ur.long_name,ir=(fr=or.address_components.find(mr=>mr.types.includes("route")))==null?void 0:fr.long_name,sr=(hr=or.address_components.find(mr=>mr.types.includes("locality")))==null?void 0:hr.long_name,cr=(pr=or.address_components.find(mr=>mr.types.includes("administrative_area_level_1")))==null?void 0:pr.short_name,lr=(dr=or.address_components.find(mr=>mr.types.includes("postal_code")))==null?void 0:dr.long_name;ee(`${ar} ${ir}, ${sr}, ${cr} ${lr}}`),te()},options:{fields:["address_components"],types:["address"]}});return jsx("input",{ref:nr,type:"text",placeholder:"Enter a location",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-indigo-500 focus:mercoa-ring-indigo-500 sm:mercoa-text-sm",required:ce})}function findCustomPaymentMethodAccountNameAndNumber(ee){var re,nr,or,ar;let te=ee==null?void 0:ee.accountName;te||(nr=(re=ee.schema)==null?void 0:re.fields)==null||nr.forEach(ir=>{ir.useAsAccountName&&(te=ee==null?void 0:ee.data[ir.name])}),te||(te=capitalize(Object.values((ee==null?void 0:ee.data)??["Account"])[0]));let ce=ee==null?void 0:ee.accountNumber;return ce||(ar=(or=ee.schema)==null?void 0:or.fields)==null||ar.forEach(ir=>{ir.useAsAccountNumber&&(ce=ee==null?void 0:ee.data[ir.name])}),{accountName:te,accountNumber:ce}}function EntityDetails({children:ee}){const te=useMercoaSession();if(ee)return ee({entity:te.entity,organization:te.organization})}function EntityStatus({entity:ee}){const te=useMercoaSession();return ee=ee||te.entity,ee?jsxs(Fragment,{children:[ee.status==="unverified"&&jsx(Tooltip,{title:"Can only receive funds",children:jsx("span",{className:"mercoa-inline-flex mercoa-items-center mercoa-rounded-full mercoa-bg-indigo-100 mercoa-px-2.5 mercoa-py-0.5 mercoa-text-xs mercoa-font-medium mercoa-text-indigo-800",children:"Unverified"})}),ee.status==="verified"&&jsx(Tooltip,{title:"Can send and receive funds",children:jsx("span",{className:"mercoa-inline-flex mercoa-items-center mercoa-rounded-full mercoa-bg-green-100 mercoa-px-2.5 mercoa-py-0.5 mercoa-text-xs mercoa-font-medium mercoa-text-green-800",children:"Verified"})}),ee.status==="pending"||ee.status==="review"&&jsx(Tooltip,{title:"Can only receive funds",children:jsx("span",{className:"mercoa-inline-flex mercoa-items-center mercoa-rounded-full mercoa-bg-yellow-100 mercoa-px-2.5 mercoa-py-0.5 mercoa-text-xs mercoa-font-medium mercoa-text-yellow-800",children:"Pending"})}),ee.status==="resubmit"||ee.status==="failed"&&jsx(Tooltip,{title:"Can only receive funds",children:jsx("span",{className:"mercoa-inline-flex mercoa-items-center mercoa-rounded-full mercoa-bg-red-100 mercoa-px-2.5 mercoa-py-0.5 mercoa-text-xs mercoa-font-medium mercoa-text-red-800",children:"VERIFICATION FAILED"})})]}):jsx(Fragment,{})}const postalCodeRegex=/(^\d{5}$)|(^\d{5}-\d{4}$)/,usaStates=[{name:"Alabama",abbreviation:"AL"},{name:"Alaska",abbreviation:"AK"},{name:"American Samoa",abbreviation:"AS"},{name:"Arizona",abbreviation:"AZ"},{name:"Arkansas",abbreviation:"AR"},{name:"California",abbreviation:"CA"},{name:"Colorado",abbreviation:"CO"},{name:"Connecticut",abbreviation:"CT"},{name:"Delaware",abbreviation:"DE"},{name:"District Of Columbia",abbreviation:"DC"},{name:"Federated States Of Micronesia",abbreviation:"FM"},{name:"Florida",abbreviation:"FL"},{name:"Georgia",abbreviation:"GA"},{name:"Guam",abbreviation:"GU"},{name:"Hawaii",abbreviation:"HI"},{name:"Idaho",abbreviation:"ID"},{name:"Illinois",abbreviation:"IL"},{name:"Indiana",abbreviation:"IN"},{name:"Iowa",abbreviation:"IA"},{name:"Kansas",abbreviation:"KS"},{name:"Kentucky",abbreviation:"KY"},{name:"Louisiana",abbreviation:"LA"},{name:"Maine",abbreviation:"ME"},{name:"Marshall Islands",abbreviation:"MH"},{name:"Maryland",abbreviation:"MD"},{name:"Massachusetts",abbreviation:"MA"},{name:"Michigan",abbreviation:"MI"},{name:"Minnesota",abbreviation:"MN"},{name:"Mississippi",abbreviation:"MS"},{name:"Missouri",abbreviation:"MO"},{name:"Montana",abbreviation:"MT"},{name:"Nebraska",abbreviation:"NE"},{name:"Nevada",abbreviation:"NV"},{name:"New Hampshire",abbreviation:"NH"},{name:"New Jersey",abbreviation:"NJ"},{name:"New Mexico",abbreviation:"NM"},{name:"New York",abbreviation:"NY"},{name:"North Carolina",abbreviation:"NC"},{name:"North Dakota",abbreviation:"ND"},{name:"Northern Mariana Islands",abbreviation:"MP"},{name:"Ohio",abbreviation:"OH"},{name:"Oklahoma",abbreviation:"OK"},{name:"Oregon",abbreviation:"OR"},{name:"Palau",abbreviation:"PW"},{name:"Pennsylvania",abbreviation:"PA"},{name:"Puerto Rico",abbreviation:"PR"},{name:"Rhode Island",abbreviation:"RI"},{name:"South Carolina",abbreviation:"SC"},{name:"South Dakota",abbreviation:"SD"},{name:"Tennessee",abbreviation:"TN"},{name:"Texas",abbreviation:"TX"},{name:"Utah",abbreviation:"UT"},{name:"Vermont",abbreviation:"VT"},{name:"Virgin Islands",abbreviation:"VI"},{name:"Virginia",abbreviation:"VA"},{name:"Washington",abbreviation:"WA"},{name:"West Virginia",abbreviation:"WV"},{name:"Wisconsin",abbreviation:"WI"},{name:"Wyoming",abbreviation:"WY"}],addressBlockSchema={addressLine1:create$6().required("Address is required").test("addressLine1","PO Boxes are not supported",ee=>!(ee!=null&&ee.trim().startsWith("PO")||ee!=null&&ee.trim().startsWith("P.O."))).test("addressLine1","Address is required",ee=>!(ee!=null&&ee.trim().startsWith("undefined"))),addressLine2:create$6(),city:create$6().required("City is required"),stateOrProvince:create$6().length(2).required(),postalCode:create$6().matches(postalCodeRegex,"Invalid Postal Code").required()};function AddressBlock({register:ee,errors:te,watch:ce,setValue:re,trigger:nr,readOnly:or,required:ar,label:ir,placeholder:sr}){var pr,dr,mr,yr,Mr,Sr,Er,br,_r,xr;const cr=useMercoaSession(),{ref:lr}=reactGoogleAutocomplete.usePlacesWidget({apiKey:cr.googleMapsApiKey,onPlaceSelected:async jr=>{var Lr,Zr,nn,rn,tn;const wr=(Lr=jr.address_components.find(Nr=>Nr.types.includes("street_number")))==null?void 0:Lr.long_name,Ir=(Zr=jr.address_components.find(Nr=>Nr.types.includes("route")))==null?void 0:Zr.long_name,Br=(nn=jr.address_components.find(Nr=>Nr.types.includes("locality")))==null?void 0:nn.long_name,Ar=(rn=jr.address_components.find(Nr=>Nr.types.includes("administrative_area_level_1")))==null?void 0:rn.short_name,Ur=(tn=jr.address_components.find(Nr=>Nr.types.includes("postal_code")))==null?void 0:tn.long_name;hr(!0),re("addressLine1",wr+" "+Ir,{shouldDirty:!0}),re("city",Br??"",{shouldDirty:!0}),re("stateOrProvince",Ar??"",{shouldDirty:!0}),re("postalCode",Ur??"",{shouldDirty:!0}),re("country","US",{shouldDirty:!0}),nr()},options:{fields:["address_components"],types:["address"]}});React$1.useEffect(()=>{re("country","US",{shouldDirty:!0})},[]);const ur=ce("stateOrProvince"),[fr,hr]=React$1.useState(!!or||ur);return jsx("div",{className:"mercoa-mt-2",children:fr?jsxs("div",{className:"mercoa-grid mercoa-grid-cols-2 mercoa-gap-4 mercoa-mb-5",children:[jsxs("div",{className:"mercoa-mt-1 mercoa-col-span-2",children:[jsx("label",{htmlFor:"addressLine1",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:ir??"Address"}),jsx("input",{...ee("addressLine1"),readOnly:or,required:ar,type:"text",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm"}),((pr=te.addressLine1)==null?void 0:pr.message)&&jsx("p",{className:"mercoa-text-sm mercoa-text-red-500",children:(dr=te.addressLine1)==null?void 0:dr.message})]}),jsxs("div",{className:"mercoa-mt-1",children:[jsx("label",{htmlFor:"addressLine1",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Apartment, suite, etc."}),jsx("input",{...ee("addressLine2"),readOnly:or,type:"text",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm"}),((mr=te.addressLine2)==null?void 0:mr.message)&&jsx("p",{className:"mercoa-text-sm mercoa-text-red-500",children:(yr=te.addressLine2)==null?void 0:yr.message})]}),jsxs("div",{className:"mercoa-mt-1",children:[jsx("label",{htmlFor:"addressLine1",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"City"}),jsx("input",{...ee("city"),readOnly:or,required:ar,type:"text",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm"}),((Mr=te.city)==null?void 0:Mr.message)&&jsx("p",{className:"mercoa-text-sm mercoa-text-red-500",children:(Sr=te.city)==null?void 0:Sr.message})]}),jsxs("div",{className:"mercoa-mt-1",children:[jsx(MercoaCombobox,{options:usaStates.map(({name:jr,abbreviation:wr})=>({disabled:!1,value:wr})),label:"State",value:ur,onChange:jr=>{re("stateOrProvince",jr,{shouldDirty:!0})},inputClassName:"mercoa-py-2.5",labelClassName:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700 -mb-2"}),((Er=te.stateOrProvince)==null?void 0:Er.message)&&jsx("p",{className:"mercoa-text-sm mercoa-text-red-500",children:(br=te.stateOrProvince)==null?void 0:br.message})]}),jsxs("div",{className:"mercoa-mt-1",children:[jsx("label",{htmlFor:"addressLine1",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Postal Code"}),jsx("input",{...ee("postalCode"),readOnly:or,required:ar,type:"text",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm"}),((_r=te.postalCode)==null?void 0:_r.message)&&jsx("p",{className:"mercoa-text-sm mercoa-text-red-500",children:(xr=te.postalCode)==null?void 0:xr.message})]})]}):jsxs(Fragment,{children:[jsx("label",{htmlFor:"addressLine1",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:ir??"Address"}),jsx("div",{className:"mercoa-mt-1",children:jsx("input",{ref:lr,onBlur:()=>{hr(!0)},type:"text",placeholder:sr??"Enter a location",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm",required:ar})})]})})}const nameBlockSchema={firstName:create$6().required("First name is required"),middleName:create$6(),lastName:create$6().required("Last name is required"),suffix:create$6()};function NameBlock({register:ee,errors:te,readOnly:ce,required:re}){var nr,or,ar,ir;return jsxs("div",{className:"mercoa-mt-2 mercoa-grid mercoa-grid-cols-2 mercoa-gap-3",children:[jsxs("div",{children:[jsx("label",{htmlFor:"firstName",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"First Name"}),jsx("div",{className:"mercoa-mt-1",children:jsx("input",{...ee("firstName"),readOnly:ce,required:re,type:"text",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm"})}),((nr=te.firstName)==null?void 0:nr.message)&&jsx("p",{className:"mercoa-text-sm mercoa-text-red-500",children:(or=te.firstName)==null?void 0:or.message.toString()})]}),jsxs("div",{children:[jsxs("label",{htmlFor:"middleName",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:["Middle Name ",jsx("span",{className:"mercoa-text-gray-400",children:"(optional)"})]}),jsx("div",{className:"mercoa-mt-1",children:jsx("input",{...ee("middleName"),readOnly:ce,type:"text",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm"})})]}),jsxs("div",{children:[jsx("label",{htmlFor:"lastName",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Last Name"}),jsx("div",{className:"mercoa-mt-1",children:jsx("input",{...ee("lastName"),readOnly:ce,type:"text",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm"})}),((ar=te.lastName)==null?void 0:ar.message)&&jsx("p",{className:"mercoa-text-sm mercoa-text-red-500",children:(ir=te.lastName)==null?void 0:ir.message.toString()})]}),jsxs("div",{children:[jsx("label",{htmlFor:"suffix",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Suffix"}),jsx("div",{className:"mercoa-mt-1",children:jsxs("select",{...ee("suffix"),readOnly:ce,className:"mercoa-mt-1 mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border mercoa-border-gray-300 mercoa-bg-white mercoa-py-2 mercoa-px-3 mercoa-shadow-sm focus:mercoa-border-mercoa-primary focus:mercoa-outline-none focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm",children:[jsx("option",{value:"",children:"None"}),jsx("option",{value:"Sr.",children:"Sr."}),jsx("option",{value:"Jr.",children:"Jr."}),jsx("option",{value:"II",children:"II"}),jsx("option",{value:"III",children:"III"}),jsx("option",{value:"IV",children:"IV"}),jsx("option",{value:"V",children:"V"})]})})]})]})}const dateOfBirthSchema={dob:create$4().typeError("Date of birth is required").required("Date of birth is required").test("dob","Must be at least 18 years old",ee=>!dayjs$1(ee).isAfter(dayjs$1().subtract(18,"years")))};function DateOfBirthBlock({control:ee,errors:te,readOnly:ce,required:re}){var nr,or;return jsxs("div",{children:[jsx("label",{htmlFor:"dob",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Date of birth"}),jsx("div",{className:"mercoa-mt-1",children:jsx(Controller,{control:ee,name:"dob",render:({field:ar})=>jsx(er,{className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm",onChange:ir=>ar.onChange(ir),selected:ar.value,required:re,readOnly:ce})})}),((nr=te.dob)==null?void 0:nr.message)&&jsx("p",{className:"mercoa-text-sm mercoa-text-red-500",children:(or=te.dob)==null?void 0:or.message.toString()})]})}const SSNSchema={taxID:create$6().matches(/^\d{3}-\d{2}-\d{4}$/,"Invalid SSN").required("SSN is required")};function SSNBlock({control:ee,errors:te,readOnly:ce,required:re}){var nr,or;return jsxs("div",{children:[jsx("label",{htmlFor:"taxID",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"SSN"}),jsx("div",{className:"mercoa-mt-1",children:jsx(Controller,{control:ee,name:"taxID",render:({field:ar})=>ar.value==="****"?jsx("input",{type:"text",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm",placeholder:"123-45-6789",value:ar.value,onChange:ar.onChange,readOnly:ce}):jsx(InputMask,{mask:"999-99-9999",value:ar.value,onChange:ar.onChange,readOnly:ce,required:re,children:ir=>jsx("input",{...ir,type:"text",placeholder:"123-45-6789",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm"})})})}),((nr=te.taxID)==null?void 0:nr.message)&&jsx("p",{className:"mercoa-text-sm mercoa-text-red-500",children:(or=te.taxID)==null?void 0:or.message.toString()})]})}const emailSchema={email:create$6().email("Email is not valid").required("Email is required")};function EmailBlock({register:ee,errors:te,readOnly:ce,required:re}){var nr,or;return jsxs("div",{className:"mercoa-mt-2",children:[jsx("label",{htmlFor:"email",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Email"}),jsx("div",{className:"mercoa-mt-1",children:jsx("input",{type:"email",...ee("email"),readOnly:ce,required:re,className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm"})}),((nr=te.email)==null?void 0:nr.message)&&jsx("p",{className:"mercoa-text-sm mercoa-text-red-500",children:(or=te.email)==null?void 0:or.message.toString()})]})}const phoneSchema={phoneNumber:create$6().matches(/^\(\d{3}\) \d{3}-\d{4}$/,"Invalid phone number").required("Phone number is required")};function PhoneBlock({control:ee,errors:te,readOnly:ce,required:re}){var nr,or;return jsxs("div",{className:"mercoa-mt-2",children:[jsx("label",{htmlFor:"phoneNumber",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Phone"}),jsx("div",{className:"mercoa-mt-1",children:jsx(Controller,{control:ee,name:"phoneNumber",render:({field:ar})=>jsx(InputMask,{mask:"(999) 999-9999",value:ar.value,onChange:ar.onChange,readOnly:ce,required:re,children:ir=>jsx("input",{...ir,type:"text",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm",placeholder:"(777) 777-7777"})})})}),((nr=te.phoneNumber)==null?void 0:nr.message)&&jsx("p",{className:"mercoa-text-sm mercoa-text-red-500",children:(or=te.phoneNumber)==null?void 0:or.message.toString()})]})}const accountTypeSchema={accountType:create$6().required()};function AccountTypeRadioBlock({register:ee,errors:te}){return jsxs("div",{className:"mercoa-mt-3",children:[jsx("label",{htmlFor:"accountType",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Account Type"}),jsxs("div",{className:"mercoa-flex mercoa-items-center",children:[jsx("input",{...ee("accountType"),value:javascript.Mercoa.AccountType.Individual,type:"radio",className:"mercoa-h-4 mercoa-w-4 mercoa-border-gray-300 mercoa-text-mercoa-primary-text focus:mercoa-ring-mercoa-primary"}),jsx("label",{htmlFor:"accountType",className:"mercoa-ml-3 mercoa-block mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Individual"})]}),jsxs("div",{className:"mercoa-flex mercoa-items-center",children:[jsx("input",{...ee("accountType"),value:javascript.Mercoa.AccountType.Business,type:"radio",className:"mercoa-h-4 mercoa-w-4 mercoa-border-gray-300 mercoa-text-mercoa-primary-text focus:mercoa-ring-mercoa-primary"}),jsx("label",{htmlFor:"accountType",className:"mercoa-ml-3 mercoa-block mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Business"})]})]})}function AccountTypeSelectBlock({register:ee,errors:te}){return jsxs("div",{className:"mercoa-mt-3",children:[jsx("label",{htmlFor:"accountType",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Account Type"}),jsxs("select",{...ee("accountType"),className:"mercoa-mt-1 mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border mercoa-border-gray-300 mercoa-bg-white mercoa-py-2 mercoa-px-3 mercoa-shadow-sm focus:mercoa-border-mercoa-primary focus:mercoa-outline-none focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm",children:[jsx("option",{value:javascript.Mercoa.AccountType.Individual,children:"Individual"}),jsx("option",{value:javascript.Mercoa.AccountType.Business,children:"Business"})]})]})}function BusinessTypeBlock({register:ee,errors:te,readOnly:ce,required:re}){return jsxs("div",{className:"mercoa-mt-3",children:[jsx("label",{htmlFor:"businessType",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Business Type"}),jsxs("select",{...ee("businessType"),readOnly:ce,required:re,className:"mercoa-mt-1 mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border mercoa-border-gray-300 mercoa-bg-white mercoa-py-2 mercoa-px-3 mercoa-shadow-sm focus:mercoa-border-mercoa-primary focus:mercoa-outline-none focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm",children:[jsx("option",{value:"",disabled:!0,children:"Select an option"}),jsx("option",{value:"soleProprietorship",children:"Sole proprietorship"}),jsx("option",{value:"llc",children:"LLC"}),jsx("option",{value:"trust",children:"Trust"}),jsx("option",{value:"publicCorporation",children:"Public Corporation"}),jsx("option",{value:"privateCorporation",children:"Private Corporation"}),jsx("option",{value:"partnership",children:"Partnership"}),jsx("option",{value:"unincorporatedAssociation",children:"Unincorporated association"}),jsx("option",{value:"unincorporatedNonProfit",children:"Unincorporated Non-Profit "}),jsx("option",{value:"incorporatedNonProfit",children:"Incorporated Non-Profit "})]})]})}const legalBusinessNameSchema={legalBusinessName:create$6().required("Business name is required")};function LegalBusinessNameBlock({register:ee,errors:te,readOnly:ce,required:re}){var nr,or;return jsxs("div",{className:"mercoa-mt-2",children:[jsx("label",{htmlFor:"legalBusinessName",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Business Name"}),jsx("div",{className:"mercoa-mt-1",children:jsx("input",{...ee("legalBusinessName"),readOnly:ce,required:re,type:"text",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm"})}),((nr=te.legalBusinessName)==null?void 0:nr.message)&&jsx("p",{className:"mercoa-text-sm mercoa-text-red-500",children:(or=te.legalBusinessName)==null?void 0:or.message.toString()})]})}const doingBusinessAsSchema={doingBusinessAs:create$6()};function DoingBusinessAsBlock({register:ee,errors:te,readOnly:ce}){var re,nr;return jsxs("div",{className:"mercoa-mt-2",children:[jsxs("label",{htmlFor:"doingBusinessAs",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:["Doing business as ",jsx("span",{className:"mercoa-text-gray-400",children:"(optional)"})]}),jsx("div",{className:"mercoa-mt-1",children:jsx("input",{...ee("doingBusinessAs"),readOnly:ce,type:"text",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm"})}),((re=te.doingBusinessAs)==null?void 0:re.message)&&jsx("p",{className:"mercoa-text-sm mercoa-text-red-500",children:(nr=te.doingBusinessAs)==null?void 0:nr.message.toString()})]})}const einSchema={taxID:create$6().matches(/^(0[1-9]|[1-9]\d)-\d{7}|[*]{2}-[*]{7}$/,"Invalid EIN").required("EIN is required")};function EINBlock({control:ee,errors:te,readOnly:ce,required:re}){var nr,or;return jsxs("div",{className:"mercoa-mt-2",children:[jsx("label",{htmlFor:"taxID",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"EIN"}),jsx("div",{className:"mercoa-mt-1",children:jsx(Controller,{control:ee,name:"taxID",render:({field:ar})=>ar.value==="**-*******"?jsx("input",{type:"text",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm",placeholder:"12-3456789",value:ar.value,onChange:ar.onChange,readOnly:ce}):jsx(InputMask,{mask:"99-9999999",value:ar.value,onChange:ar.onChange,readOnly:ce,required:re,children:ir=>jsx("input",{...ir,type:"text",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm",placeholder:"12-3456789"})})})}),((nr=te.taxID)==null?void 0:nr.message)&&jsx("p",{className:"mercoa-text-sm mercoa-text-red-500",children:(or=te.taxID)==null?void 0:or.message.toString()})]})}const websiteSchema={website:create$6().url("Website must start with http:// or https:// and be a valid URL").required("Website is required")};function WebsiteBlock({register:ee,errors:te,readOnly:ce,required:re}){var nr,or;return jsxs("div",{className:"mercoa-mt-2",children:[jsx("label",{htmlFor:"website",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Website"}),jsx("div",{className:"mercoa-mt-1",children:jsx("input",{...ee("website"),type:"text",readOnly:ce,required:re,className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm"})}),((nr=te.website)==null?void 0:nr.message)&&jsx("p",{className:"mercoa-text-sm mercoa-text-red-500",children:(or=te.website)==null?void 0:or.message.toString()})]})}const descriptionSchema={website:create$6().required("Description is required")};function DescriptionBlock({register:ee,errors:te,readOnly:ce,required:re}){var nr,or;return jsxs("div",{className:"mercoa-mt-2",children:[jsx("label",{htmlFor:"description",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Business Description"}),jsx("div",{className:"mercoa-mt-1",children:jsx("input",{...ee("description"),type:"text",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm",readOnly:ce,required:re})}),((nr=te.description)==null?void 0:nr.message)&&jsx("p",{className:"mercoa-text-sm mercoa-text-red-500",children:(or=te.description)==null?void 0:or.message.toString()})]})}const formationDateSchema={formationDate:create$4().required("Formation date is required")};function FormationDateBlock({control:ee,errors:te,readOnly:ce,required:re}){return jsxs("div",{children:[jsx("label",{htmlFor:"formationDate",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Business Formation Date"}),jsx("div",{className:"mercoa-mt-1 mercoa-text-left",children:jsx(Controller,{control:ee,name:"formationDate",render:({field:nr})=>jsx(er,{className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm",onChange:or=>nr.onChange(or),selected:nr.value,required:re,readOnly:ce})})})]})}async function createOrUpdateEntity({entityId:ee,onClose:te,data:ce,isPayee:re,isPayor:nr,mercoaClient:or}){const ar={};ce.accountType==="individual"?ar.individual={email:ce.email,...ce.phoneNumber&&{phone:{number:ce.phoneNumber,countryCode:"1"}},...ce.taxID&&ce.taxID!="****"&&{governmentId:{ssn:ce.taxID}},name:{firstName:ce.firstName??"",lastName:ce.lastName??"",middleName:ce.middleName??"",suffix:ce.suffix??""},...ce.dob&&{birthDate:{day:dayjs$1(ce.dob).format("D"),month:dayjs$1(ce.dob).format("M"),year:dayjs$1(ce.dob).format("YYYY")}},...ce.addressLine1&&ce.city&&ce.stateOrProvince&&ce.postalCode&&{address:{addressLine1:ce.addressLine1,addressLine2:ce.addressLine2,postalCode:ce.postalCode,stateOrProvince:ce.stateOrProvince,city:ce.city,country:"US"}}}:ar.business={email:ce.email,...ce.phoneNumber&&{phone:{number:ce.phoneNumber,countryCode:"1"}},businessType:ce.businessType??"llc",legalBusinessName:ce.legalBusinessName,doingBusinessAs:ce.doingBusinessAs,website:ce.website,description:ce.description,formationDate:ce.formationDate?dayjs$1(ce.formationDate).toDate():void 0,...ce.taxID&&ce.taxID!="**-*******"&&{taxId:{ein:{number:ce.taxID}}},...ce.addressLine1&&ce.city&&ce.stateOrProvince&&ce.postalCode&&{address:{addressLine1:ce.addressLine1,addressLine2:ce.addressLine2,postalCode:ce.postalCode,stateOrProvince:ce.stateOrProvince,city:ce.city,country:"US"}}};const ir={isCustomer:!0,accountType:ce.accountType,profile:ar,isPayee:re,isPayor:nr};let sr;try{ee?sr=await(or==null?void 0:or.entity.update(ee,ir)):sr=await(or==null?void 0:or.entity.create(ir)),te&&te(ir)}catch(cr){Q$1.error(`There was an error saving your data.
|
|
274
|
-
Error: ${cr.body}`),console.error(cr)}return sr}function EntityOnboardingButton({className:ee,buttonText:te,title:ce,onClose:re,isPayee:nr,isPayor:or}){const[ar,ir]=React$1.useState(!1),sr=useMercoaSession();function cr(dr){ir(dr),!dr&&re&&re()}const{register:lr,handleSubmit:ur,watch:fr,formState:hr}=useForm({defaultValues:{accountType:javascript.Mercoa.AccountType.Business,legalBusinessName:"",email:"",firstName:"",lastName:""},resolver:async(dr,mr,yr)=>dr.accountType===javascript.Mercoa.AccountType.Business?await o(create$3({...accountTypeSchema,...legalBusinessNameSchema,...emailSchema}))(dr,mr,yr):await o(create$3({...accountTypeSchema,...nameBlockSchema,...emailSchema}))(dr,mr,yr)}),pr=fr("accountType");return jsxs(Fragment,{children:[jsx("button",{onClick:()=>{cr(!0)},className:ee||"mercoa-inline-flex mercoa-items-center mercoa-justify-center mercoa-rounded-md mercoa-border mercoa-border-transparent mercoa-bg-mercoa-primary mercoa-px-4 mercoa-py-2 mercoa-text-sm mercoa-font-medium mercoa-text-white mercoa-shadow-sm hover:mercoa-bg-mercoa-primary-dark focus:mercoa-outline-none focus:mercoa-ring-2 focus:mercoa-ring-mercoa-primary focus:mercoa-ring-offset-2 sm:mercoa-w-auto",children:te||"Get Started"}),jsx(tt$1.Root,{show:ar,as:React$1.Fragment,children:jsxs(_t$1,{as:"div",className:"mercoa-relative mercoa-z-10",onClose:cr,children:[jsx(tt$1.Child,{as:React$1.Fragment,enter:"mercoa-ease-out mercoa-duration-300",enterFrom:"mercoa-opacity-0",enterTo:"mercoa-opacity-100",leave:"mercoa-ease-in mercoa-duration-200",leaveFrom:"mercoa-opacity-100",leaveTo:"mercoa-opacity-0",children:jsx("div",{className:"mercoa-fixed mercoa-inset-0 mercoa-bg-gray-500 mercoa-bg-mercoa-opacity-75 mercoa-transition-opacity"})}),jsx("div",{className:"mercoa-fixed mercoa-inset-0 mercoa-z-10 mercoa-overflow-y-auto",children:jsx("div",{className:"mercoa-flex mercoa-min-h-full mercoa-items-end mercoa-justify-center mercoa-p-4 mercoa-text-center sm:mercoa-items-center sm:mercoa-p-0",children:jsx(tt$1.Child,{as:React$1.Fragment,enter:"mercoa-ease-out mercoa-duration-300",enterFrom:"mercoa-opacity-0 mercoa-translate-y-4 sm:mercoa-translate-y-0 sm:mercoa-scale-95",enterTo:"mercoa-opacity-100 mercoa-translate-y-0 sm:mercoa-scale-100",leave:"mercoa-ease-in mercoa-duration-200",leaveFrom:"mercoa-opacity-100 mercoa-translate-y-0 sm:mercoa-scale-100",leaveTo:"mercoa-opacity-0 mercoa-translate-y-4 sm:mercoa-translate-y-0 sm:mercoa-scale-95",children:jsx(_t$1.Panel,{className:"mercoa-relative mercoa-transform mercoa-rounded-lg mercoa-bg-white mercoa-px-4 mercoa-pt-5 mercoa-pb-4 mercoa-text-left mercoa-shadow-xl mercoa-transition-all sm:mercoa-my-8 sm:mercoa-w-full sm:mercoa-max-w-sm sm:mercoa-p-6",children:jsxs("form",{onSubmit:ur(async dr=>{if(!sr.client)return;const mr=await createOrUpdateEntity({data:dr,onClose:cr,isPayee:nr,isPayor:or,mercoaClient:sr.client});if(mr&&confirm("Do you want to onboard the entity?")){const Mr=await sr.client.entity.getOnboardingLink(mr.id,{type:nr?"PAYEE":"PAYOR"});window.location.href=Mr}}),children:[jsxs("div",{children:[jsx(AccountTypeSelectBlock,{register:lr,errors:hr.errors}),pr===javascript.Mercoa.AccountType.Business?jsx(LegalBusinessNameBlock,{register:lr,errors:hr.errors}):jsx(NameBlock,{register:lr,errors:hr.errors}),jsx(EmailBlock,{register:lr,errors:hr.errors})]}),jsx("div",{className:"mercoa-mt-4",children:jsx("button",{type:"submit",className:"mercoa-w-full mercoa-inline-flex mercoa-justify-center mercoa-rounded-md mercoa-border mercoa-border-transparent mercoa-bg-mercoa-primary mercoa-px-4 mercoa-py-2 mercoa-text-sm mercoa-font-medium mercoa-text-white mercoa-shadow-sm hover:mercoa-bg-mercoa-primary-dark focus:mercoa-outline-none focus:mercoa-ring-2 focus:mercoa-ring-mercoa-primary focus:mercoa-ring-offset-2 sm:mercoa-w-auto",children:"Continue"})})]})})})})})]})})]})}function RepresentativeOnboardingForm({entityId:ee,title:te,onClose:ce}){var pr,dr,mr,yr;const re=useMercoaSession(),nr=create$3({email:create$6().email("Email is not valid").required("Email is required"),...phoneSchema,...addressBlockSchema,...nameBlockSchema,...dateOfBirthSchema,...SSNSchema,jobTitle:create$6().required("Job title is required"),ownershipPercentage:create$5().typeError("Ownership percentage is required").min(0,"Ownership percentage must be greater than 0").max(100,"Ownership percentage must be less than 100").required("Ownership percentage is required"),isController:create$7().required()}).required(),{control:or,register:ar,handleSubmit:ir,setValue:sr,trigger:cr,watch:lr,formState:{errors:ur,isValid:fr}}=useForm({mode:"onChange",resolver:o(nr)});async function hr(Mr){var Er;const Sr={email:Mr.email,phone:{number:Mr.phoneNumber,countryCode:"1"},name:{firstName:Mr.firstName,lastName:Mr.lastName,middleName:Mr.middleName,suffix:Mr.suffix},birthDate:{day:dayjs$1(Mr.dob).format("D"),month:dayjs$1(Mr.dob).format("M"),year:dayjs$1(Mr.dob).format("YYYY")},address:{addressLine1:Mr.addressLine1,addressLine2:Mr.addressLine2,postalCode:Mr.postalCode,stateOrProvince:Mr.stateOrProvince,city:Mr.city,country:"US"},governmentId:{ssn:Mr.taxID},responsibilities:{isController:Mr.isController,isOwner:Mr.ownershipPercentage>=25,ownershipPercentage:Number(Mr.ownershipPercentage),jobTitle:Mr.jobTitle}};try{await((Er=re.client)==null?void 0:Er.entity.representative.create(ee,Sr)),await re.refresh(),ce&&ce(Mr)}catch(br){console.error(br),Q$1.error("There was an issue creating this representative. Please check your information and try again.")}}return jsxs("form",{onSubmit:ir(hr),children:[jsx("div",{children:jsxs("div",{className:"mercoa-mt-1",children:[jsxs("div",{className:"mercoa-flex",children:[jsx("div",{className:"mercoa-flex-1"}),jsxs(_t$1.Title,{as:"h3",className:"mercoa-text-lg mercoa-font-medium mercoa-leading-6 mercoa-text-gray-900",children:[jsx("button",{}),te||"Create Account"]}),jsx("div",{className:"mercoa-flex-1"}),jsx(XMarkIcon$1,{className:"mercoa-h-5 mercoa-w-5 mercoa-cursor-pointer mercoa-rounded-md mercoa-p-0.5 hover:mercoa-bg-gray-100",type:"button",onClick:()=>{ce&&ce()}})]}),jsx(NameBlock,{register:ar,errors:ur}),jsxs("div",{className:"mercoa-grid mercoa-grid-cols-2 mercoa-gap-3",children:[jsx(EmailBlock,{register:ar,errors:ur}),jsx(PhoneBlock,{control:or,errors:ur}),jsx(DateOfBirthBlock,{control:or,errors:ur}),jsx(SSNBlock,{control:or,errors:ur}),jsxs("div",{className:"mercoa-mt-2",children:[jsx("label",{htmlFor:"jobTitle",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Job Title"}),jsx("div",{className:"mercoa-mt-1",children:jsx("input",{...ar("jobTitle"),type:"text",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm"})}),((pr=ur.jobTitle)==null?void 0:pr.message)&&jsx("p",{className:"mercoa-text-sm mercoa-text-red-500",children:(dr=ur.jobTitle)==null?void 0:dr.message.toString()})]}),jsxs("div",{className:"mercoa-mt-2",children:[jsx("label",{htmlFor:"ownershipPercentage",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Percent Ownership"}),jsx("div",{className:"mercoa-mt-1",children:jsx("input",{...ar("ownershipPercentage"),type:"number",min:0,max:100,placeholder:"0-100",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm"})}),((mr=ur.ownershipPercentage)==null?void 0:mr.message)&&jsx("p",{className:"mercoa-text-sm mercoa-text-red-500",children:(yr=ur.ownershipPercentage)==null?void 0:yr.message.toString()})]})]}),jsx(AddressBlock,{register:ar,errors:ur,setValue:sr,trigger:cr,watch:lr,label:"Residential Address"}),jsxs("div",{className:"mercoa-relative mercoa-mt-2 mercoa-flex mercoa-items-start mercoa-items-center",children:[jsx("div",{className:"mercoa-flex mercoa-h-5 mercoa-items-center",children:jsx("input",{...ar("isController"),type:"checkbox",className:"mercoa-h-4 mercoa-w-4 mercoa-rounded mercoa-border-gray-300 mercoa-text-mercoa-primary-text focus:mercoa-ring-mercoa-primary"})}),jsx("div",{className:"mercoa-ml-3 mercoa-text-sm",children:jsx(Tooltip,{title:"Every business requires a controller. Examples include the CEO, COO, Treasurer, President, Vice President, or Managing Partner.",children:jsxs("label",{htmlFor:"isController",className:"mercoa-font-medium mercoa-text-gray-700",children:["This person is a company controller"," ",jsx(InformationCircleIcon$1,{className:"mercoa-inline mercoa-h-5 mercoa-w-5"})]})})})]})]})}),jsx("div",{className:"mercoa-mt-5 sm:mercoa-mt-6",children:jsx("button",{disabled:!fr,className:"mercoa-inline-flex mercoa-w-full mercoa-justify-center mercoa-rounded-md mercoa-border mercoa-border-transparent mercoa-bg-mercoa-primary mercoa-px-4 mercoa-py-2 mercoa-text-base mercoa-font-medium mercoa-text-white mercoa-shadow-sm hover:mercoa-bg-mercoa-primary-dark focus:mercoa-outline-none focus:mercoa-ring-2 focus:mercoa-ring-mercoa-primary focus:mercoa-ring-offset-2 disabled:mercoa-bg-mercoa-primary-light sm:mercoa-text-sm",children:"Add Representative"})})]})}function Representatives({children:ee,onSelect:te,showAdd:ce,showEdit:re}){var lr;const[nr,or]=React$1.useState(),[ar,ir]=React$1.useState(!1),sr=useMercoaSession();React$1.useEffect(()=>{var ur,fr;sr.token&&((ur=sr.entity)!=null&&ur.id)&&((fr=sr.client)==null||fr.entity.representative.getAll(sr.entity.id).then(hr=>{or(hr)}))},[sr.entity,sr.token,ar,sr.refreshId]);const cr=()=>{ir(!1)};return ee?ee({representatives:nr}):jsxs(Fragment,{children:[nr&&nr.map(ur=>jsx("div",{className:"mercoa-mt-2",children:jsx(RepresentativeComponent,{representative:ur,onSelect:te,showEdit:re})},ur.id)),ce&&jsxs("div",{className:"mercoa-mt-2",children:[jsx(AddDialog,{show:ar,onClose:cr,component:jsx(RepresentativeOnboardingForm,{title:"Create Representative",onClose:cr,entityId:((lr=sr.entity)==null?void 0:lr.id)??""})}),jsx(RepresentativeComponent,{onSelect:()=>ir(!0)})]})]})}function RepresentativeComponent({children:ee,representative:te,onSelect:ce,showEdit:re,selected:nr}){var ir,sr,cr;const or=useMercoaSession();async function ar(){var lr,ur,fr;if(or.token){if(!((lr=or.entity)!=null&&lr.id)){Q$1.error("Entity not found");return}(fr=(ur=or.client)==null?void 0:ur.entity.representative)==null||fr.delete(or.entity.id,(te==null?void 0:te.id)??""),or.refresh()}}return te?jsxs("div",{onClick:()=>{ce&&ce(te)},className:`mercoa-relative mercoa-flex mercoa-items-center mercoa-space-x-3 mercoa-rounded-lg mercoa-border ${nr?"mercoa-border-mercoa-primary":"mercoa-border-gray-300"} mercoa-bg-white mercoa-px-6 mercoa-py-5 mercoa-shadow-sm focus-within:mercoa-ring-2 focus-within:mercoa-ring-mercoa-primary focus-within:mercoa-ring-offset-2 ${ce?"mercoa-cursor-pointer hover:mercoa-border-gray-400":""}`,children:[jsx("div",{className:`mercoa-flex-shrink-0 mercoa-rounded-full mercoa-p-1 ${nr?"mercoa-text-mercoa-primary-text-invert mercoa-bg-mercoa-primary-light":"mercoa-bg-gray-200 mercoa-text-gray-600"}`,children:jsx(UserIcon$1,{className:"mercoa-h-5 mercoa-w-5"})}),jsxs("div",{className:"mercoa-min-w-0 mercoa-flex-1",children:[!re&&jsx("span",{className:"mercoa-absolute mercoa-inset-0","aria-hidden":"true"}),jsxs("p",{className:`mercoa-text-sm mercoa-font-medium mercoa-text-gray-900 ${nr?"mercoa-underline":""}`,children:[te.name.firstName," ",te.name.lastName," - ",(ir=te.responsibilities)==null?void 0:ir.jobTitle]}),jsxs("p",{className:`mercoa-text-xs mercoa-font-medium mercoa-text-gray-900 ${nr?"mercoa-underline":""}`,children:["Ownership: ",(sr=te.responsibilities)==null?void 0:sr.ownershipPercentage,"%"]}),((cr=te.responsibilities)==null?void 0:cr.isController)&&jsx("p",{className:`mercoa-text-xs mercoa-font-medium mercoa-text-gray-900 ${nr?"mercoa-underline":""}`,children:"Controller"})]}),re&&jsx("div",{className:"mercoa-flex-shrink-0",children:jsxs("button",{className:"mercoa-ml-1 mercoa-cursor-pointer hover:mercoa-text-red-300",onClick:()=>ar(),children:[" ",jsx(TrashIcon$1,{className:"mercoa-h-5 mercoa-w-5"})]})})]},te==null?void 0:te.id):jsxs("div",{onClick:()=>{ce&&ce(te)},className:`mercoa-relative mercoa-flex mercoa-items-center mercoa-space-x-3 mercoa-rounded-lg mercoa-border mercoa-border-gray-300 mercoa-bg-white mercoa-px-6 mercoa-py-5 mercoa-shadow-sm focus-within:mercoa-ring-2 focus-within:mercoa-ring-mercoa-primary focus-within:mercoa-ring-offset-2 hover:mercoa-border-gray-400 ${ce?"mercoa-cursor-pointer ":""}`,children:[jsx("div",{className:`mercoa-flex-shrink-0 mercoa-rounded-full mercoa-p-1 ${nr?"mercoa-text-mercoa-primary-text-invert mercoa-bg-mercoa-primary-light":"mercoa-bg-gray-200 mercoa-text-gray-600"}`,children:jsx(PlusIcon$1,{className:"mercoa-h-5 mercoa-w-5"})}),jsxs("div",{className:"mercoa-min-w-0 mercoa-flex-1",children:[jsx("span",{className:"mercoa-absolute mercoa-inset-0","aria-hidden":"true"}),jsx("p",{className:"mercoa-text-sm mercoa-font-medium mercoa-text-gray-900",children:"Add new representative"}),jsx("p",{className:"mercoa-truncate mercoa-text-sm mercoa-text-gray-500"})]})]})}function VerifyOwnersButton({entity:ee}){var or,ar;const te=useMercoaSession(),[ce,re]=React$1.useState();React$1.useEffect(()=>{var ir,sr;te.token&&((ir=te.entity)!=null&&ir.id)&&((sr=te.client)==null||sr.entity.representative.getAll(te.entity.id).then(cr=>{re(cr)}))},[te.entity,te.token,te.refreshId]);const nr=ce==null?void 0:ce.some(ir=>ir.responsibilities.isController);return!ee||(ar=(or=ee.profile)==null?void 0:or.business)!=null&&ar.ownersProvided?jsx(Fragment,{}):jsx(MercoaButton,{onClick:async()=>{var ir;ee.accountType==="business"?(await((ir=te.client)==null?void 0:ir.entity.initiateKyb(ee.id)),Q$1.success("Verification Started")):ee.accountType==="individual"&&Q$1.error("not implemented yet!"),te.refresh()},disabled:!nr,tooltip:nr?void 0:"Please add at least one representative who is a controller",isEmphasized:!0,className:"mercoa-mt-2",children:"Verify Account"})}function AcceptToSButton({className:ee,buttonText:te,title:ce,onClose:re,entity:nr}){const[or,ar]=React$1.useState(!1);function ir(sr){ar(sr),!sr&&re&&re()}return jsxs(Fragment,{children:[jsx(MercoaButton,{onClick:()=>{ir(!0)},isEmphasized:!0,size:"md",children:te||"Terms of Service"}),jsx(tt$1.Root,{show:or,as:React$1.Fragment,children:jsxs(_t$1,{as:"div",className:"mercoa-relative mercoa-z-10",onClose:ir,children:[jsx(tt$1.Child,{as:React$1.Fragment,enter:"mercoa-ease-out mercoa-duration-300",enterFrom:"mercoa-opacity-0",enterTo:"mercoa-opacity-100",leave:"mercoa-ease-in mercoa-duration-200",leaveFrom:"mercoa-opacity-100",leaveTo:"mercoa-opacity-0",children:jsx("div",{className:"mercoa-fixed mercoa-inset-0 mercoa-bg-gray-500 mercoa-bg-mercoa-opacity-75 mercoa-transition-opacity"})}),jsx("div",{className:"mercoa-fixed mercoa-inset-0 mercoa-z-10 mercoa-overflow-y-auto",children:jsx("div",{className:"mercoa-flex mercoa-min-h-full mercoa-items-end mercoa-justify-center mercoa-p-4 mercoa-text-center sm:mercoa-items-center sm:mercoa-p-0",children:jsx(tt$1.Child,{as:React$1.Fragment,enter:"mercoa-ease-out mercoa-duration-300",enterFrom:"mercoa-opacity-0 mercoa-translate-y-4 sm:mercoa-translate-y-0 sm:mercoa-scale-95",enterTo:"mercoa-opacity-100 mercoa-translate-y-0 sm:mercoa-scale-100",leave:"mercoa-ease-in mercoa-duration-200",leaveFrom:"mercoa-opacity-100 mercoa-translate-y-0 sm:mercoa-scale-100",leaveTo:"mercoa-opacity-0 mercoa-translate-y-4 sm:mercoa-translate-y-0 sm:mercoa-scale-95",children:jsxs(_t$1.Panel,{className:"mercoa-relative mercoa-transform mercoa-rounded-lg mercoa-bg-white mercoa-px-4 mercoa-pt-5 mercoa-pb-4 mercoa-text-left mercoa-shadow-xl mercoa-transition-all sm:mercoa-my-8 sm:mercoa-w-full sm:mercoa-max-w-md sm:mercoa-p-6",children:[jsx(_t$1.Title,{className:"mercoa-mb-3 mercoa-w-full mercoa-text-center mercoa-text-xl mercoa-text-gray-800 mercoa-underline",children:ce||"Terms of Service"}),jsx(AcceptTosForm,{entity:nr,onComplete:ir})]})})})})]})})]})}function AcceptTosForm({entity:ee,onComplete:te}){var ir;const ce=useMercoaSession(),{register:re,watch:nr,handleSubmit:or}=useForm(),ar=nr();return jsxs("form",{onSubmit:or(async()=>{var sr;if(!ee.id){Q$1.error("Entity not found");return}await((sr=ce.client)==null?void 0:sr.entity.acceptTermsOfService(ee.id)),te&&te(!1),ce.refresh()}),children:[jsxs("div",{className:"mercoa-mb-10 mercoa-text-sm",children:[jsx("b",{children:capitalize((ir=ce.organization)==null?void 0:ir.name)})," has partnered with"," ",jsx("a",{href:"https://mercoa.com",target:"_blank",rel:"noreferrer",className:"mercoa-text-blue-500 mercoa-underline",children:"Mercoa"})," ","to provide financial services.",jsx("br",{}),jsx("br",{}),"By clicking the button below, you agree to the"," ",jsx("a",{href:"https://mercoa.com/legal/platform-agreement/",target:"_blank",rel:"noreferrer",className:"mercoa-text-blue-500 mercoa-underline",children:"Mercoa Platform Agreement"})," ","and"," ",jsx("a",{href:"https://mercoa.com/legal/privacy-policy/",target:"_blank",rel:"noreferrer",className:"mercoa-text-blue-500 mercoa-underline",children:"Privacy Policy"}),"."]}),jsxs("div",{className:"mercoa-relative mercoa-mt-2 mercoa-flex mercoa-items-start mercoa-items-center",children:[jsx("div",{className:"mercoa-flex mercoa-h-5 mercoa-items-center",children:jsx("input",{...re("mercoa"),type:"checkbox",className:"mercoa-h-4 mercoa-w-4 mercoa-rounded mercoa-border-gray-300 mercoa-text-mercoa-primary-text focus:mercoa-ring-mercoa-primary"})}),jsx("div",{className:"mercoa-ml-3 mercoa-text-sm",children:jsxs("label",{htmlFor:"isController",className:"mercoa-font-medium mercoa-text-gray-700",children:["I have read and accept the"," ",jsxs("a",{href:"https://mercoa.com/legal/platform-agreement/",target:"_blank",rel:"noreferrer",className:"mercoa-text-blue-500 mercoa-underline",children:[" ","Mercoa terms of service"]})]})})]}),jsx(MercoaButton,{isEmphasized:!0,disabled:!ar.mercoa,className:"mercoa-mt-5",size:"md",children:"Confirm"})]})}function EntityOnboarding({entity:ee,organization:te,type:ce,setEntityData:re}){var hr,pr,dr,mr,yr,Mr,Sr,Er,br,_r,xr,jr,wr,Ir,Br,Ar,Ur,Lr,Zr,nn,rn,tn,Nr,Fr,Yr,Dr,vr,Or,Tr,Pr,gr,$r,Rr,kr,Cr,qr,on,sn;const{register:nr,handleSubmit:or,setValue:ar,trigger:ir,control:sr,watch:cr,formState:{errors:lr}}=useForm({defaultValues:{accountType:ee.accountType,email:ee.email,firstName:((hr=ee.profile.individual)==null?void 0:hr.name.firstName)??"",middleName:(pr=ee.profile.individual)==null?void 0:pr.name.middleName,lastName:((dr=ee.profile.individual)==null?void 0:dr.name.lastName)??"",suffix:(mr=ee.profile.individual)==null?void 0:mr.name.suffix,phoneNumber:formatPhoneNumber(((Mr=(yr=ee.profile.individual)==null?void 0:yr.phone)==null?void 0:Mr.number)??((Er=(Sr=ee.profile.business)==null?void 0:Sr.phone)==null?void 0:Er.number)),addressLine1:((_r=(br=ee.profile.individual)==null?void 0:br.address)==null?void 0:_r.addressLine1)??((jr=(xr=ee.profile.business)==null?void 0:xr.address)==null?void 0:jr.addressLine1),addressLine2:((Ir=(wr=ee.profile.individual)==null?void 0:wr.address)==null?void 0:Ir.addressLine2)??((Ar=(Br=ee.profile.business)==null?void 0:Br.address)==null?void 0:Ar.addressLine2),city:((Lr=(Ur=ee.profile.individual)==null?void 0:Ur.address)==null?void 0:Lr.city)??((nn=(Zr=ee.profile.business)==null?void 0:Zr.address)==null?void 0:nn.city),stateOrProvince:((tn=(rn=ee.profile.individual)==null?void 0:rn.address)==null?void 0:tn.stateOrProvince)??((Fr=(Nr=ee.profile.business)==null?void 0:Nr.address)==null?void 0:Fr.stateOrProvince),postalCode:((Dr=(Yr=ee.profile.individual)==null?void 0:Yr.address)==null?void 0:Dr.postalCode)??((Or=(vr=ee.profile.business)==null?void 0:vr.address)==null?void 0:Or.postalCode),country:((Pr=(Tr=ee.profile.individual)==null?void 0:Tr.address)==null?void 0:Pr.country)??(($r=(gr=ee.profile.business)==null?void 0:gr.address)==null?void 0:$r.country)??"US",taxID:(Rr=ee.profile.individual)!=null&&Rr.governmentIdProvided?"****":(kr=ee.profile.business)!=null&&kr.taxIdProvided?"**-*******":"",dob:new Date,legalBusinessName:((Cr=ee.profile.business)==null?void 0:Cr.legalBusinessName)??"",doingBusinessAs:(qr=ee.profile.business)==null?void 0:qr.doingBusinessAs,description:(on=ee.profile.business)==null?void 0:on.description,website:(sn=ee.profile.business)==null?void 0:sn.website,formationDate:new Date},resolver:async(yn,jn,wn)=>yn.accountType===javascript.Mercoa.AccountType.Individual?o(create$3({...(fr==null?void 0:fr.individual.name.required)&&nameBlockSchema,...(fr==null?void 0:fr.individual.email.required)&&emailSchema,...(fr==null?void 0:fr.individual.phone.required)&&phoneSchema,...(fr==null?void 0:fr.individual.dateOfBirth.required)&&dateOfBirthSchema,...(fr==null?void 0:fr.individual.address.required)&&addressBlockSchema,...(fr==null?void 0:fr.individual.ssn.required)&&SSNSchema}).required())(yn,jn,wn):o(create$3({...(fr==null?void 0:fr.business.name.required)&&legalBusinessNameSchema,...(fr==null?void 0:fr.business.email.required)&&emailSchema,...(fr==null?void 0:fr.business.phone.required)&&phoneSchema,...(fr==null?void 0:fr.business.website.required)&&websiteSchema,...(fr==null?void 0:fr.business.address.required)&&addressBlockSchema,...(fr==null?void 0:fr.business.ein.required)&&einSchema,...(fr==null?void 0:fr.business.formationDate.required)&&formationDateSchema,...(fr==null?void 0:fr.business.description.required)&&descriptionSchema}).required())(yn,jn,wn)}),ur=cr("accountType"),fr=ce==="payee"?te.payeeOnboardingOptions:te.payorOnboardingOptions;return jsxs("form",{onSubmit:or(async yn=>{re(yn)}),children:[jsxs("div",{className:"sm:mercoa-grid sm:mercoa-grid-cols-2 mercoa-gap-4",children:[(fr==null?void 0:fr.enableBusiness)&&(fr==null?void 0:fr.enableIndividual)&&jsx("div",{className:"mercoa-col-span-2",children:jsx(AccountTypeSelectBlock,{register:nr,errors:lr})}),ur==="individual"&&jsxs(Fragment,{children:[(fr==null?void 0:fr.individual.email.show)&&jsx("div",{className:"mercoa-col-span-2",children:jsx(EmailBlock,{register:nr,errors:lr,readOnly:!fr.individual.email.edit,required:fr.individual.email.required})}),(fr==null?void 0:fr.individual.name.show)&&jsx("div",{className:"mercoa-col-span-2",children:jsx(NameBlock,{register:nr,errors:lr,readOnly:!fr.individual.name.edit,required:fr.individual.name.required})}),(fr==null?void 0:fr.individual.phone.show)&&jsx(PhoneBlock,{control:sr,errors:lr,readOnly:!fr.individual.phone.edit,required:fr.individual.phone.required}),(fr==null?void 0:fr.individual.dateOfBirth.show)&&jsx(DateOfBirthBlock,{control:sr,errors:lr,readOnly:!fr.individual.dateOfBirth.edit,required:fr.individual.dateOfBirth.required}),(fr==null?void 0:fr.individual.address.show)&&jsx("div",{className:"mercoa-col-span-2",children:jsx(AddressBlock,{register:nr,errors:lr,setValue:ar,trigger:ir,watch:cr,readOnly:!fr.individual.address.edit,required:fr.individual.address.required})}),(fr==null?void 0:fr.individual.ssn.show)&&jsx(SSNBlock,{control:sr,errors:lr,readOnly:!fr.individual.ssn.edit,required:fr.individual.ssn.required})]}),ur==="business"&&jsxs(Fragment,{children:[(fr==null?void 0:fr.business.name.show)&&jsx(LegalBusinessNameBlock,{register:nr,errors:lr,readOnly:!fr.business.name.edit,required:fr.business.name.required}),(fr==null?void 0:fr.business.email.show)&&jsx(EmailBlock,{register:nr,errors:lr,readOnly:!fr.business.email.edit,required:fr.business.email.required}),(fr==null?void 0:fr.business.phone.show)&&jsx(PhoneBlock,{control:sr,errors:lr,readOnly:!fr.business.phone.edit,required:fr.business.phone.required}),(fr==null?void 0:fr.business.website.show)&&jsx(WebsiteBlock,{register:nr,errors:lr,readOnly:!fr.business.website.edit,required:fr.business.website.required}),(fr==null?void 0:fr.business.address.show)&&jsx("div",{className:"mercoa-col-span-2",children:jsx(AddressBlock,{label:"Business Address",register:nr,errors:lr,setValue:ar,trigger:ir,watch:cr,readOnly:!fr.business.address.edit,required:fr.business.address.required})}),(fr==null?void 0:fr.business.type.show)&&jsx(BusinessTypeBlock,{register:nr,errors:lr,readOnly:!fr.business.type.edit,required:fr.business.type.required}),(fr==null?void 0:fr.business.ein.show)&&jsx(EINBlock,{control:sr,errors:lr,readOnly:!fr.business.ein.edit,required:fr.business.ein.required}),(fr==null?void 0:fr.business.formationDate.show)&&jsx(FormationDateBlock,{control:sr,errors:lr,readOnly:!fr.business.formationDate.edit,required:fr.business.formationDate.required}),(fr==null?void 0:fr.business.description.show)&&jsx("div",{className:"mercoa-col-span-2",children:jsx(DescriptionBlock,{register:nr,errors:lr,readOnly:!fr.business.description.edit,required:fr.business.description.required})})]})]}),jsxs("div",{className:"mercoa-mt-8 mercoa-flex",children:[jsx("div",{className:"mercoa-flex-1"}),jsx(MercoaButton,{isEmphasized:!0,children:"Next"})]})]})}function EntityCreation({organization:ee,type:te,setEntityData:ce}){const re=te==="payee"?ee.payeeOnboardingOptions:ee.payorOnboardingOptions,{register:nr,handleSubmit:or,watch:ar,formState:{errors:ir}}=useForm({defaultValues:{accountType:re!=null&&re.enableBusiness?javascript.Mercoa.AccountType.Business:javascript.Mercoa.AccountType.Individual,email:"",legalBusinessName:"",firstName:"",middleName:"",lastName:"",suffix:""}}),sr=ar("accountType");return jsxs("form",{onSubmit:or(async cr=>{ce(cr)}),children:[jsxs("div",{className:"mercoa-gap-4",children:[(re==null?void 0:re.enableBusiness)&&(re==null?void 0:re.enableIndividual)&&jsx("div",{className:"mercoa-col-span-2",children:jsx(AccountTypeSelectBlock,{register:nr,errors:ir})}),sr==="individual"&&jsxs(Fragment,{children:[(re==null?void 0:re.individual.email.show)&&jsx(EmailBlock,{register:nr,errors:ir,readOnly:!re.individual.email.edit,required:re.individual.email.required}),(re==null?void 0:re.individual.name.show)&&jsx(NameBlock,{register:nr,errors:ir,readOnly:!re.individual.name.edit,required:re.individual.name.required})]}),sr==="business"&&jsxs(Fragment,{children:[(re==null?void 0:re.business.name.show)&&jsx(LegalBusinessNameBlock,{register:nr,errors:ir,readOnly:!re.business.name.edit,required:re.business.name.required}),(re==null?void 0:re.business.email.show)&&jsx(EmailBlock,{register:nr,errors:ir,readOnly:!re.business.email.edit,required:re.business.email.required})]})]}),jsxs("div",{className:"mercoa-mt-8 mercoa-flex",children:[jsx("div",{className:"mercoa-flex-1"}),jsx(MercoaButton,{isEmphasized:!0,children:"Next"})]})]})}function entityDetailsForMercoaPaymentsCompleted(ee){if(!ee.profile)return!1;if(ee.accountType==="business"){if(!ee.profile.business||!ee.profile.business.address||!ee.profile.business.legalBusinessName||!ee.profile.business.taxIdProvided||!ee.profile.business.businessType||!(ee.profile.business.description||ee.profile.business.website))return!1}else if(ee.accountType==="individual"&&(!ee.profile.individual||!ee.profile.individual.address||!ee.profile.individual.name||!ee.profile.individual.phone||!ee.profile.individual.birthDateProvided||!ee.profile.individual.governmentIdProvided))return!1;return!0}function formatPhoneNumber(ee){var te=(""+ee).replace(/\D/g,""),ce=te.match(/^(\d{3})(\d{3})(\d{4})$/);return ce?"("+ce[1]+") "+ce[2]+"-"+ce[3]:ee}function EntityPortal({token:ee}){var dr,mr,yr,Mr,Sr,Er,br,_r,xr,jr,wr,Ir,Br,Ar,Ur,Lr,Zr,nn,rn,tn,Nr,Fr,Yr,Dr,vr,Or,Tr,Pr,gr;const te=useMercoaSession(),ce=typeof window<"u"?window.location.search:"",re=new URLSearchParams(ce),nr=Object.fromEntries(re.entries()),{invoiceId:or}=nr,[ar,ir]=React$1.useState("inbox"),[sr,cr]=React$1.useState(),lr=te.entity,ur=te.user,fr=te.organization;let hr;try{const{options:$r}=jwtDecode(ee);hr=$r}catch($r){console.error($r)}async function pr($r){await te.getNewToken(),ir($r)}if(React$1.useEffect(()=>{te.setIframeOptions({options:hr})},[ee]),React$1.useEffect(()=>{var $r;or&&(($r=te.client)==null||$r.invoice.get(or).then(Rr=>{cr(Rr),pr("invoice")}))},[or]),!lr||!te.organization)return jsx(LoadingSpinner,{});if(lr&&((yr=(mr=(dr=te.iframeOptions)==null?void 0:dr.options)==null?void 0:mr.entity)!=null&&yr.enableMercoaPayments)&&lr.status!=javascript.Mercoa.EntityStatus.Verified){let $r=jsx(Fragment,{});return lr!=null&&lr.acceptedTos?entityDetailsForMercoaPaymentsCompleted(lr)?!((Sr=(Mr=lr==null?void 0:lr.profile)==null?void 0:Mr.business)!=null&&Sr.ownersProvided)&&lr.accountType==="business"?$r=jsxs(Fragment,{children:[jsxs("p",{className:"mercoa-mb-5",children:[" ","Before you can pay bills, you must add business representatives and verify your account."]}),jsx("div",{className:"mercoa-mt-8",children:jsx(Representatives,{showEdit:!0,showAdd:!0})}),!((br=(Er=te.entity)==null?void 0:Er.profile.business)!=null&&br.ownersProvided)&&jsxs("div",{className:"mercoa-mt-8 mercoa-text-left",children:[jsx("h2",{className:"mercoa-font-gray-800 mercoa-text-lg",children:"KYC Verification"}),jsx("p",{className:"mercoa-font-gray-700 mercoa-mt-2 mercoa-text-sm",children:'Banking regulations require that we perform a "Know Your Customer" (KYC) process to verify account identity before enabling the ability to pay bills or send invoices.'}),jsx("p",{className:"mercoa-font-gray-700 mercoa-mt-2 mercoa-text-sm",children:"Individuals with significant ownership in the business (over 25%) must be added as representatives."}),jsx("p",{className:"mercoa-font-gray-700 mercoa-mt-2 mercoa-text-sm",children:"At least one controller must be added as a representative. Examples include the CEO, COO, Treasurer, President, Vice President, or Managing Partner."}),jsx("p",{className:"mercoa-font-gray-700 mercoa-mt-2 mercoa-text-sm",children:'Once all representatives have been added, click "Verify Account" to start this process.'}),jsx(VerifyOwnersButton,{entity:lr})]})]}):$r=jsx("div",{className:"mercoa-mt-10 mercoa-text-center mercoa-text-gray-800",children:jsx("p",{className:"mercoa-mb-5",children:" We are currently verifying your account. Please come back shortly."})}):$r=jsxs(Fragment,{children:[jsxs("div",{className:"mercoa-text-gray-800",children:[jsxs("p",{className:"mercoa-text-lg mercoa-font-normal",children:["To pay bills and invoices with ",te.organization.name,", you'll need to provide us with a few pieces of information."]}),jsxs("div",{className:"mercoa-p-4 mercoa-text-sm mercoa-rounded-md mercoa-bg-gray-100 mercoa-my-4 mercoa-grid mercoa-gap-3",children:[jsxs("p",{className:"mercoa-flex mercoa-items-center",children:[jsx(LockClosedIcon$1,{className:"mercoa-w-5 mercoa-h-5 mercoa-mr-5"})," Your information is used for verification purposes and isn't used for third-party marketing. We take your privacy seriously."]}),jsxs("p",{className:"mercoa-flex mercoa-items-center",children:[jsx(ClockIcon$1,{className:"mercoa-w-4 mercoa-h-4 mercoa-mr-5"})," This process should take approximately 5 minutes to complete."]})]})]}),jsx(EntityOnboarding,{entity:lr,organization:te.organization,type:"payor",setEntityData:async Rr=>{lr&&Rr&&te.client&&(await createOrUpdateEntity({data:Rr,entityId:lr.id,mercoaClient:te.client,isPayee:!1,isPayor:!0}),te.refresh())}})]}):$r=jsxs(Fragment,{children:[jsx("p",{className:"mercoa-font-gray-700 mercoa-my-2 mercoa-text-sm",children:"Before you can get started, please read and accept the terms of service"}),jsx(AcceptToSButton,{title:"Terms of Service",buttonText:"View Terms of Service",entity:lr})]}),jsxs("div",{className:"mercoa mercoa-container mercoa-mx-auto mercoa-mt-5 mercoa-text-center",children:[jsx("h2",{className:"mercoa-font-gray-800 mercoa-text-lg",children:"Welcome to your Accounts Payable Dashboard"}),$r]})}return jsxs("div",{className:"mercoa mercoa-container mercoa-mx-auto mercoa-px-4 sm:mercoa-px-6 lg:mercoa-px-8",children:[jsxs("div",{className:"mercoa-flex mercoa-items-center",children:[jsx("div",{className:"mercoa-flex-auto mercoa-text-sm mercoa-text-gray-700 mercoa-my-4 sm:mercoa-mt-0",children:ar==="inbox"?jsx(Fragment,{children:((_r=fr==null?void 0:fr.emailProvider)==null?void 0:_r.inboxDomain)&&jsxs(Fragment,{children:["Forward invoices to: ",jsx("br",{}),jsxs("b",{children:[lr==null?void 0:lr.emailTo,"@",(xr=fr==null?void 0:fr.emailProvider)==null?void 0:xr.inboxDomain]})]})}):jsxs(MercoaButton,{onClick:()=>pr("inbox"),type:"button",isEmphasized:!1,className:"mercoa-ml-2 mercoa-inline-flex mercoa-text-sm",children:[jsx(ArrowLeftIcon$1,{className:"-mercoa-ml-1 mercoa-inline-flex mercoa-h-5 mercoa-w-5 md:mercoa-mr-2"})," ",jsx("span",{className:"mercoa-hidden md:mercoa-inline-block",children:"Back"})]})}),jsxs("div",{className:"mercoa-my-4 mercoa-flex-none sm:mercoa-mt-0 sm:mercoa-ml-16",children:[ur&&((jr=hr==null?void 0:hr.pages)==null?void 0:jr.notifications)&&ar!=="notifications"&&ar!=="invoice"&&jsxs(MercoaButton,{onClick:()=>pr("notifications"),type:"button",isEmphasized:!1,className:"mercoa-ml-2 mercoa-inline-flex mercoa-text-sm",children:[jsx(EnvelopeIcon$1,{className:"-mercoa-ml-1 mercoa-inline-flex mercoa-h-5 mercoa-w-5 md:mercoa-mr-2"})," ",jsx("span",{className:"mercoa-hidden md:mercoa-inline-block",children:"Notifications"})]}),((wr=hr==null?void 0:hr.pages)==null?void 0:wr.representatives)&&ar!=="representatives"&&ar!=="invoice"&&jsxs(MercoaButton,{onClick:()=>pr("representatives"),type:"button",isEmphasized:!1,className:"mercoa-ml-2 mercoa-inline-flex mercoa-text-sm",children:[jsx(UsersIcon$1,{className:"-mercoa-ml-1 mercoa-inline-flex mercoa-h-5 mercoa-w-5 md:mercoa-mr-2"})," ",jsx("span",{className:"mercoa-hidden md:mercoa-inline-block",children:"Representatives"})]}),((Ir=hr==null?void 0:hr.pages)==null?void 0:Ir.counterparties)&&ar!=="counterparties"&&ar!=="invoice"&&jsxs(MercoaButton,{onClick:()=>pr("counterparties"),type:"button",isEmphasized:!1,className:"mercoa-ml-2 mercoa-inline-flex mercoa-text-sm",children:[jsx(BriefcaseIcon$1,{className:"-mercoa-ml-1 mercoa-inline-flex mercoa-h-5 mercoa-w-5 md:mercoa-mr-2"})," ",jsx("span",{className:"mercoa-hidden md:mercoa-inline-block",children:"Vendors"})]}),((Br=hr==null?void 0:hr.pages)==null?void 0:Br.approvals)&&ar!=="approvals"&&ar!=="invoice"&&jsxs(MercoaButton,{onClick:()=>pr("approvals"),type:"button",isEmphasized:!1,className:"mercoa-ml-2 mercoa-inline-flex mercoa-text-sm",children:[jsx(LockOpenIcon$1,{className:"-mercoa-ml-1 mercoa-inline-flex mercoa-h-5 mercoa-w-5 md:mercoa-mr-2"})," ",jsx("span",{className:"mercoa-hidden md:mercoa-inline-block",children:"Approval Rules"})]}),((Lr=(Ur=(Ar=te.iframeOptions)==null?void 0:Ar.options)==null?void 0:Ur.entity)==null?void 0:Lr.enableMercoaPayments)&&((Zr=hr==null?void 0:hr.pages)==null?void 0:Zr.paymentMethods)&&ar!=="payments"&&ar!=="invoice"&&jsxs(MercoaButton,{onClick:()=>pr("payments"),type:"button",isEmphasized:!1,className:"mercoa-ml-2 mercoa-inline-flex mercoa-text-sm",children:[jsx(BuildingLibraryIcon$1,{className:"-mercoa-ml-1 mercoa-inline-flex mercoa-h-5 mercoa-w-5 md:mercoa-mr-2"})," ",jsx("span",{className:"mercoa-hidden md:mercoa-inline-block",children:"Payment Methods"})]}),ar!=="invoice"&&ar!=="counterparties"&&jsxs(MercoaButton,{isEmphasized:!0,type:"button",className:"mercoa-ml-2 mercoa-inline-flex mercoa-text-sm",onClick:()=>{pr("invoice"),cr(void 0)},children:[jsx(PlusIcon$1,{className:"-mercoa-ml-1 mercoa-inline-flex mercoa-h-5 mercoa-w-5 md:mercoa-mr-2"})," ",jsx("span",{className:"mercoa-hidden md:mercoa-inline-block",children:"New Invoice"})]})]})]}),ar==="inbox"&&jsx(InvoiceInbox,{statuses:(nn=hr==null?void 0:hr.invoice)==null?void 0:nn.status,onSelectInvoice:$r=>{cr($r),pr("invoice")}}),ar==="payments"&&jsxs("div",{children:[((Nr=(tn=(rn=te.organization)==null?void 0:rn.paymentMethods)==null?void 0:tn.payerPayments)==null?void 0:Nr.find($r=>$r.type===javascript.Mercoa.PaymentMethodType.BankAccount&&$r.active))&&jsxs(Fragment,{children:[jsx("h3",{className:"mercoa-mt-8",children:"Bank Accounts"}),jsx(BankAccounts,{showEdit:!0,showAdd:!0})]}),((Dr=(Yr=(Fr=te.organization)==null?void 0:Fr.paymentMethods)==null?void 0:Yr.payerPayments)==null?void 0:Dr.find($r=>$r.type===javascript.Mercoa.PaymentMethodType.Card&&$r.active))&&jsxs(Fragment,{children:[jsx("h3",{className:"mercoa-mt-8",children:"Cards"}),jsx(CreditCards,{showEdit:!0,showAdd:!0})]}),((Tr=(Or=(vr=te.organization)==null?void 0:vr.paymentMethods)==null?void 0:Or.payerPayments)==null?void 0:Tr.find($r=>$r.type===javascript.Mercoa.PaymentMethodType.Custom&&$r.active))&&jsxs(Fragment,{children:[jsx("h3",{className:"mercoa-mt-8"}),jsx(CustomPaymentMethod,{showEdit:!0})]})]}),ur&&ar==="notifications"&&jsxs("div",{children:[jsx("h3",{className:"mercoa-mt-8",children:"Notifications"}),jsx(EntityUserNotificationTable,{entityId:lr.id,userId:ur.id})]}),ar==="approvals"&&jsxs("div",{children:[jsx("h3",{className:"mercoa-my-8",children:"Approval Rules"}),jsx(ApprovalPolicies,{})]}),ar==="counterparties"&&jsx(Counterparties,{type:"payee"}),ar==="representatives"&&jsxs("div",{children:[jsx("p",{className:"mercoa-font-gray-700 mercoa-mt-2 mercoa-text-sm",children:"Regulatory guidelines require that all individuals with significant ownership in the business (over 25%) must be added as representatives."}),jsx("p",{className:"mercoa-font-gray-700 mercoa-mt-1 mercoa-text-sm",children:"Every business also requires a controller. Examples include the CEO, COO, Treasurer, President, Vice President, or Managing Partner."}),jsx(Representatives,{showEdit:!0,showAdd:!0}),lr&&lr.accountType==="business"&&!((gr=(Pr=lr.profile)==null?void 0:Pr.business)!=null&&gr.ownersProvided)&&jsxs("div",{className:"mercoa-mt-8",children:[jsx("h2",{className:"mercoa-font-gray-800 mercoa-text-lg",children:"KYC Verification"}),jsx("p",{className:"mercoa-font-gray-700 mercoa-mt-2 mercoa-text-sm",children:'Banking regulations require that we perform a "Know Your Customer" (KYC) process to verify account identity before enabling the ability to pay bills or send invoices.'}),jsx("p",{className:"mercoa-font-gray-700 mercoa-mt-2 mercoa-text-sm",children:'Once all representatives have been added, click "Verify Account" to start this process.'}),jsx(VerifyOwnersButton,{entity:lr})]})]}),ar==="invoice"&&jsx(InvoiceDetails,{invoice:sr,addPaymentMethodRedirect:()=>pr("payments"),onRedirect:$r=>{if(!$r){pr("inbox");return}}})]})}const notificationTypeToText={[javascript.Mercoa.NotificationType.InvoiceEmailed]:"Invoice Email Received",[javascript.Mercoa.NotificationType.InvoiceCreated]:"Invoice Created",[javascript.Mercoa.NotificationType.InvoicePaid]:"Invoice Paid",[javascript.Mercoa.NotificationType.InvoiceScheduled]:"Invoice Scheduled",[javascript.Mercoa.NotificationType.InvoiceApprovalNeeded]:"Invoice Approval Needed",[javascript.Mercoa.NotificationType.InvoiceApproved]:"Invoice Approved",[javascript.Mercoa.NotificationType.InvoiceCanceled]:"Invoice Canceled",[javascript.Mercoa.NotificationType.InvoiceRejected]:"Invoice Rejected",[javascript.Mercoa.NotificationType.InvoicePending]:"Invoice Payment Initiated",[javascript.Mercoa.NotificationType.InvoiceFailed]:"Invoice Payment Failed"};function EntityUserNotificationTable({entityId:ee,userId:te,onClick:ce}){const re=useMercoaSession(),[nr,or]=React$1.useState(),[ar,ir]=React$1.useState(),[sr,cr]=React$1.useState([]),[lr,ur]=React$1.useState(20),[fr,hr]=React$1.useState(1),[pr,dr]=React$1.useState(!0),[mr,yr]=React$1.useState(0),{handleSubmit:Mr}=useForm({defaultValues:{}});return React$1.useEffect(()=>{var Sr;(Sr=re.client)==null||Sr.entity.user.notifications.find(ee,te,{limit:lr,startingAfter:sr[sr.length-1]}).then(Er=>{Er&&(dr(Er.hasMore),yr(Er.count),or(Er.data))})},[re.client,sr,lr]),React$1.useEffect(()=>{var Sr;(Sr=re.client)==null||Sr.entity.invoice.find(ee,{invoiceId:(nr==null?void 0:nr.filter(Er=>Er.invoiceId).map(Er=>`${Er.invoiceId}`))??[],limit:lr}).then(Er=>{Er&&ir(Er.data)})},[re.client,ee,nr]),jsxs("div",{children:[jsxs("div",{className:"mercoa-flex mercoa-flex-col",children:[jsxs("form",{className:"mercoa-grid mercoa-items-center mercoa-grid-cols-3 mercoa-mb-3",onSubmit:Mr(Sr=>{console.log(Sr)}),children:[jsx("div",{className:"mercoa-hidden md:mercoa-block md:mercoa-col-span-2"}),jsx("div",{className:"mercoa-mt-2 mercoa-flex mercoa-w-full mercoa-rounded-md mercoa-shadow-sm mercoa-mr-2 mercoa-col-span-3 md:mercoa-col-span-1"})]}),jsx("div",{className:"-mercoa-my-2 -mercoa-mx-4 mercoa-overflow-x-auto sm:-mercoa-mx-6 lg:-mercoa-mx-8",children:jsx("div",{className:"mercoa-inline-block mercoa-min-w-full mercoa-py-2 mercoa-align-middle md:mercoa-px-6 lg:mercoa-px-8",children:jsx("div",{className:"mercoa-overflow-hidden mercoa-shadow mercoa-ring-1 mercoa-ring-black mercoa-ring-opacity-5 md:mercoa-rounded-lg",children:jsxs("table",{className:"mercoa-min-w-full mercoa-divide-y mercoa-divide-gray-300",children:[jsx("thead",{className:"mercoa-bg-gray-50",children:jsxs("tr",{children:[jsx("th",{scope:"col",className:"mercoa-py-3.5 mercoa-pl-4 mercoa-pr-3 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 sm:mercoa-pl-6",children:"Action"}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900",children:"Date"}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900",children:"Vendor"}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900",children:"Amount"}),jsx("th",{scope:"col",className:"mercoa-py-3.5 mercoa-pl-4 mercoa-pr-3 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 sm:mercoa-pl-6",children:"Invoice ID"}),jsx("th",{})]})}),jsxs("tbody",{className:"mercoa-bg-white",children:[!nr&&jsx("tr",{children:jsx("td",{colSpan:5,className:"mercoa-p-9 mercoa-text-center",children:jsx(LoadingSpinnerIcon,{})})}),nr&&nr.map((Sr,Er)=>{var br,_r,xr,jr;return jsxs("tr",{onClick:()=>ce==null?void 0:ce({entityId:ee,userId:te,invoiceId:Sr.invoiceId}),className:`hover:mercoa-bg-gray-100 ${Er%2===0?void 0:"mercoa-bg-gray-50"}`,children:[jsx("td",{className:"mercoa-whitespace-nowrap mercoa-py-4 mercoa-pl-4 mercoa-pr-3 mercoa-text-sm mercoa-font-medium mercoa-text-gray-900 sm:mercoa-pl-6",children:notificationTypeToText[Sr.type]}),jsxs("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-4 mercoa-text-sm mercoa-text-gray-900",children:[" ",dayjs$1(Sr.createdAt).format("MM/DD/YY")]}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-4 mercoa-text-sm mercoa-text-gray-900",children:((_r=(br=ar==null?void 0:ar.find(wr=>Sr.invoiceId===wr.id))==null?void 0:br.vendor)==null?void 0:_r.name)??""}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-4 mercoa-text-sm mercoa-text-gray-900",children:accounting.formatMoney(((xr=ar==null?void 0:ar.find(wr=>Sr.invoiceId===wr.id))==null?void 0:xr.amount)??"",currencyCodeToSymbol((jr=ar==null?void 0:ar.find(wr=>Sr.invoiceId===wr.id))==null?void 0:jr.currency))}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-4 mercoa-text-sm mercoa-text-gray-900",children:Sr.invoiceId})]},Sr.id)})]})]})})})})]}),nr&&jsx(TableNavigation,{data:nr,page:fr,setPage:hr,hasMore:pr,startingAfter:sr,setStartingAfter:cr,count:mr,resultsPerPage:lr,setResultsPerPage:ur})]})}function EntityUsersTable({openNotificationPreferences:ee}){var ur;const[te,ce]=React$1.useState(),[re,nr]=React$1.useState({}),[or,ar]=React$1.useState([]),[ir,sr]=React$1.useState(),cr=useMercoaSession();React$1.useEffect(()=>{var fr,hr;!cr.token||!((fr=cr.entity)!=null&&fr.id)||(hr=cr.client)==null||hr.entity.user.getAll(cr.entity.id).then(pr=>{if(pr){ce(pr);const dr=new Set;pr.forEach(mr=>{mr.roles.forEach(yr=>{dr.add(yr)})}),ar(Array.from(dr))}})},[(ur=cr.entity)==null?void 0:ur.id,cr.refreshId,cr.token]);function lr({user:fr}){const{register:hr,handleSubmit:pr,setValue:dr,watch:mr}=useForm({defaultValues:{id:fr==null?void 0:fr.id,roles:fr==null?void 0:fr.roles.join(", "),email:fr==null?void 0:fr.email,name:fr==null?void 0:fr.name,foreignId:fr==null?void 0:fr.foreignId}});return jsxs("form",{onSubmit:pr(async yr=>{var Sr,Er,br,_r,xr;if(!((Sr=cr.entity)!=null&&Sr.id))return;const Mr={roles:[...new Set((br=(Er=yr==null?void 0:yr.roles)==null?void 0:Er.trim())==null?void 0:br.split(",").filter(jr=>jr).map(jr=>jr.trim()))],email:yr.email,name:yr.name,foreignId:yr.foreignId};fr!=null&&fr.id&&(fr==null?void 0:fr.id)!="new"?await((_r=cr.client)==null?void 0:_r.entity.user.update(cr.entity.id,fr.id,Mr)):await((xr=cr.client)==null?void 0:xr.entity.user.create(cr.entity.id,Mr)),sr(void 0),Q$1("User Saved!",{type:"success"}),cr.refresh()}),children:[jsxs("div",{className:"mercoa-mt-2 mercoa-w-96",children:[jsx("label",{htmlFor:"email",className:"mercoa-block mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Email"}),jsx("div",{className:"mercoa-mt-1",children:jsx("input",{...hr("email",{required:!0}),type:"text",placeholder:"person@yourcustomer.com",className:"mercoa-w-full mercoa-border mercoa-border-gray-300 mercoa-rounded-md mercoa-shadow-sm focus:mercoa-ring-indigo-500 focus:mercoa-border-indigo-500 sm:mercoa-text-sm"})})]}),jsxs("div",{className:"mercoa-mt-2",children:[jsx("label",{htmlFor:"name",className:"mercoa-block mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Name"}),jsx("div",{className:"mercoa-mt-1",children:jsx("input",{...hr("name",{required:!0}),type:"text",placeholder:"Your User's Full Name",className:"mercoa-w-full mercoa-border mercoa-border-gray-300 mercoa-rounded-md mercoa-shadow-sm focus:mercoa-ring-indigo-500 focus:mercoa-border-indigo-500 sm:mercoa-text-sm"})})]}),jsxs("div",{className:"mercoa-mt-2",children:[jsx("label",{htmlFor:"roles",className:"mercoa-block mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Roles"}),jsxs("div",{className:"mercoa-mt-1 mercoa-flex mercoa-items-center mercoa-gap-x-1",children:[jsx("div",{className:"mercoa-flex-grow",children:jsx(MercoaCombobox,{options:or.map(yr=>({disabled:!1,value:yr})),onChange:yr=>{yr.length!=0&&dr("roles",yr.filter(Mr=>Mr).join(","),{shouldDirty:!0})},value:mr("roles").split(","),multiple:!0})}),jsxs("button",{className:"mercoa-mt-1",onClick:()=>{const yr=prompt("Create a new role");yr&&ar([...or,yr])},children:[" ",jsxs(Tooltip,{title:"Create a new role",children:[jsx(PlusCircleIcon$1,{className:"mercoa-h-6 mercoa-w-6 mercoa-text-gray-400"})," "]})]})]})]}),jsxs("div",{className:"mercoa-mt-2",children:[jsx("label",{htmlFor:"foreignId",className:"mercoa-block mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Foreign ID"}),jsx("div",{className:"mercoa-mt-1",children:jsx("input",{...hr("foreignId",{required:!0}),type:"text",placeholder:"The ID of the user in your system",className:"mercoa-w-full mercoa-border mercoa-border-gray-300 mercoa-rounded-md mercoa-shadow-sm focus:mercoa-ring-indigo-500 focus:mercoa-border-indigo-500 sm:mercoa-text-sm"})})]}),jsx(MercoaButton,{isEmphasized:!0,color:"green",className:"mercoa-mt-5 mercoa-w-full",children:"Save"})]})}return jsxs(Fragment,{children:[jsx("div",{className:"mercoa-rounded-md mercoa-bg-gray-100 mercoa-p-8",children:jsxs("ul",{role:"list",className:"mercoa-divide-y mercoa-divide-gray-100 mercoa-overflow-hidden mercoa-bg-white mercoa-shadow-sm mercoa-ring-1 mercoa-ring-gray-900/5 sm:mercoa-rounded-xl",children:[te==null?void 0:te.map((fr,hr)=>{var pr,dr,mr,yr,Mr,Sr,Er;return jsx("li",{onClick:()=>sr(fr),className:"mercoa-relative mercoa-flex mercoa-gap-x-6 mercoa-px-4 mercoa-py-5 hover:mercoa-bg-gray-50 sm:mercoa-px-6 mercoa-cursor-pointer ",children:jsxs("div",{className:"mercoa-flex mercoa-gap-x-4 mercoa-w-full",children:[jsx("div",{className:"mercoa-flex mercoa-justify-left",children:jsx("span",{className:"mercoa-inline-flex mercoa-h-16 mercoa-w-16 mercoa-items-center mercoa-justify-center mercoa-rounded-full mercoa-bg-gray-500",children:jsxs("span",{className:"mercoa-mt-0.5 mercoa-text-xl mercoa-font-medium mercoa-leading-none mercoa-text-white",children:[((pr=fr.name)==null?void 0:pr.charAt(0))??"N/A",((yr=(mr=(dr=fr.name)==null?void 0:dr.split(" "))==null?void 0:mr[1])==null?void 0:yr.charAt(0))??""]})})}),jsxs("div",{children:[jsx("p",{className:"mercoa-text-sm mercoa-font-semibold mercoa-leading-6 mercoa-text-gray-900",children:jsx("a",{children:fr.name})}),jsx("p",{className:"mercoa-mt-1 mercoa-flex mercoa-text-xs mercoa-leading-5 mercoa-text-gray-600",children:fr.email}),jsx("p",{className:"mercoa-mt-1 mercoa-flex mercoa-text-xs mercoa-leading-5 mercoa-text-gray-500",children:fr.id})]}),jsx("div",{className:"mercoa-flex mercoa-items-center mercoa-gap-x-2 grow",children:(Mr=fr==null?void 0:fr.roles)==null?void 0:Mr.map(br=>jsx("span",{className:"mercoa-inline-flex mercoa-items-center mercoa-px-2.5 mercoa-py-0.5 mercoa-rounded-full mercoa-text-xs mercoa-font-medium mercoa-bg-green-100 mercoa-text-green-800",children:br},br))}),jsx("div",{className:"mercoa-flex mercoa-items-center mercoa-rounded-md mercoa-p-2 hover:mercoa-bg-gray-200",onClick:br=>{var _r;br.preventDefault(),br.stopPropagation(),ee&&((_r=cr.entity)!=null&&_r.id)&&fr.id&&ee({entityId:cr.entity.id,userId:fr.id})},children:re[fr.id]&&jsxs("div",{className:"mercoa-flex mercoa-flex-col mercoa-items-center mercoa-gap-y-2",children:[(Sr=re[fr.id])!=null&&Sr.every(br=>br.disabled)?jsx("span",{className:"mercoa-inline-flex mercoa-items-center mercoa-px-2.5 mercoa-py-0.5 mercoa-rounded-full mercoa-text-xs mercoa-font-medium mercoa-bg-red-100 mercoa-text-red-800",children:"Notifications Disabled"}):jsx("span",{className:"mercoa-inline-flex mercoa-items-center mercoa-px-2.5 mercoa-py-0.5 mercoa-rounded-full mercoa-text-xs mercoa-font-medium mercoa-bg-green-100 mercoa-text-green-800",children:"Notifications Enabled"}),((Er=re[fr.id])==null?void 0:Er.every(br=>br.digest))&&jsx("span",{className:"mercoa-inline-flex mercoa-items-center mercoa-px-2.5 mercoa-py-0.5 mercoa-rounded-full mercoa-text-xs mercoa-font-medium mercoa-bg-blue-100 mercoa-text-blue-800",children:"Daily Digest Enabled"})]})}),jsxs("div",{className:"mercoa-flex mercoa-gap-3",children:[jsx("button",{onMouseOver:br=>{var _r,xr,jr;!((_r=cr.entity)!=null&&_r.id)||!fr.id||(jr=cr.client)==null||jr.entity.user.notificationPolicy.getAll((xr=cr.entity)==null?void 0:xr.id,fr.id).then(wr=>{wr&&nr(Ir=>({...Ir,[fr.id]:wr}))})},onClick:br=>{var _r;br.preventDefault(),br.stopPropagation(),ee&&((_r=cr.entity)!=null&&_r.id)&&fr.id&&ee({entityId:cr.entity.id,userId:fr.id})},children:jsx(EnvelopeIcon$1,{className:"mercoa-p-2 mercoa-rounded-xl mercoa-h-10 mercoa-w-10 mercoa-text-gray-400 hover:mercoa-text-gray-500 hover:mercoa-bg-gray-200"})}),jsx("button",{onClick:async br=>{var _r,xr;if(br.preventDefault(),br.stopPropagation(),confirm("Are you sure you want to delete this user?")){if(!((_r=cr.entity)!=null&&_r.id))return;if(fr!=null&&fr.id&&(fr==null?void 0:fr.id)!="new")try{await((xr=cr.client)==null?void 0:xr.entity.user.delete(cr.entity.id,fr.id))}catch(jr){Q$1.error(jr.body);return}cr.refresh()}},children:jsx(TrashIcon$1,{className:"mercoa-p-2 mercoa-rounded-xl mercoa-h-10 mercoa-w-10 mercoa-text-gray-400 hover:mercoa-text-gray-500 hover:mercoa-bg-gray-200"})})]})]})},(fr==null?void 0:fr.id)??hr)}),jsxs("li",{className:"mercoa-relative mercoa-flex mercoa-gap-x-6 mercoa-px-4 mercoa-py-5 hover:mercoa-bg-gray-50 sm:mercoa-px-6 mercoa-cursor-pointer mercoa-items-center mercoa-justify-center mercoa-align-center",onClick:()=>{sr({id:"",roles:[""],email:"",name:"",foreignId:"",createdAt:new Date,updatedAt:new Date})},children:[jsx(PlusCircleIcon$1,{className:"mercoa-h-6 mercoa-w-6 mercoa-text-gray-400"}),jsx("div",{className:"mercoa-text-sm mercoa-font-semibold mercoa-leading-6 mercoa-text-gray-900",children:"Add User"})]})]})}),jsx(tt$1.Root,{show:!!ir,as:React$1.Fragment,children:jsxs(_t$1,{as:"div",className:"mercoa-relative mercoa-z-10",onClose:()=>sr(void 0),children:[jsx(tt$1.Child,{as:React$1.Fragment,enter:"mercoa-ease-out mercoa-duration-300",enterFrom:"mercoa-opacity-0",enterTo:"mercoa-opacity-100",leave:"mercoa-ease-in mercoa-duration-200",leaveFrom:"mercoa-opacity-100",leaveTo:"mercoa-opacity-0",children:jsx("div",{className:"mercoa-fixed mercoa-inset-0 mercoa-bg-gray-500 mercoa-bg-mercoa-opacity-75 mercoa-transition-opacity"})}),jsx("div",{className:"mercoa-fixed mercoa-inset-0 mercoa-z-10 mercoa-overflow-y-auto",children:jsx("div",{className:"mercoa-flex mercoa-min-h-full mercoa-items-end mercoa-justify-center mercoa-p-4 mercoa-text-center sm:mercoa-items-center sm:mercoa-p-0",children:jsx(tt$1.Child,{as:React$1.Fragment,enter:"mercoa-ease-out mercoa-duration-300",enterFrom:"mercoa-opacity-0 mercoa-translate-y-4 sm:mercoa-translate-y-0 sm:mercoa-scale-95",enterTo:"mercoa-opacity-100 mercoa-translate-y-0 sm:mercoa-scale-100",leave:"mercoa-ease-in mercoa-duration-200",leaveFrom:"mercoa-opacity-100 mercoa-translate-y-0 sm:mercoa-scale-100",leaveTo:"mercoa-opacity-0 mercoa-translate-y-4 sm:mercoa-translate-y-0 sm:mercoa-scale-95",children:jsx(_t$1.Panel,{className:"mercoa-relative mercoa-transform mercoa-rounded-lg mercoa-bg-white mercoa-px-4 mercoa-pt-5 mercoa-pb-4 mercoa-text-left mercoa-shadow-xl mercoa-transition-all sm:mercoa-my-8 sm:mercoa-max-w-lg sm:mercoa-p-6",children:ir&&jsx(lr,{user:ir})})})})})]})})]})}pdfjs$1.GlobalWorkerOptions.workerSrc=`//unpkg.com/pdfjs-dist@${pdfjs$1.version}/build/pdf.worker.min.js`,dayjs$1.extend(utc);function ReceivablesTable({search:ee,onClick:te}){const ce=useMercoaSession(),[re,nr]=React$1.useState(),[or,ar]=React$1.useState(javascript.Mercoa.InvoiceOrderByField.CreatedAt),[ir,sr]=React$1.useState(javascript.Mercoa.OrderDirection.Asc),[cr,lr]=React$1.useState(!0),[ur,fr]=React$1.useState(0),[hr,pr]=React$1.useState(!1),[dr,mr]=React$1.useState([]),[yr,Mr]=React$1.useState(20),[Sr,Er]=React$1.useState(1);return React$1.useEffect(()=>{var br,_r;!ce.token||!((br=ce.entity)!=null&&br.id)||(_r=ce.client)==null||_r.entity.invoice.find(ce.entity.id,{search:ee,orderBy:or,orderDirection:ir,limit:yr,startingAfter:dr[dr.length-1],excludePayables:!0}).then(xr=>{xr&&(lr(xr.hasMore),fr(xr.count),nr(xr.data),pr(!0))})},[ce.token,ce.entity,ce.refreshId,ee,or,ir,dr,yr]),hr?jsx(Fragment,{children:ce.entity&&re?jsxs(Fragment,{children:[jsx("div",{className:"mercoa-min-h-[600px]",children:jsxs("table",{className:"mercoa-min-w-full mercoa-divide-y mercoa-divide-gray-300 mercoa-mt-5",children:[jsx("thead",{children:jsxs("tr",{children:[jsx("th",{scope:"col",className:"mercoa-py-3.5 mercoa-pl-4 mercoa-pr-3 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 sm:mercoa-pl-3",children:jsx(TableOrderHeader,{title:"Payer",setOrder:br=>{ar(javascript.Mercoa.InvoiceOrderByField.PayerName),sr(br)},isSelected:or===javascript.Mercoa.InvoiceOrderByField.PayerName,orderDirection:ir})}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 mercoa-hidden sm:mercoa-table-cell",children:jsx(TableOrderHeader,{title:"Invoice Number",setOrder:br=>{ar(javascript.Mercoa.InvoiceOrderByField.InvoiceNumber),sr(br)},isSelected:or===javascript.Mercoa.InvoiceOrderByField.InvoiceNumber,orderDirection:ir})}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900",children:jsx(TableOrderHeader,{title:"Due Date",setOrder:br=>{ar(javascript.Mercoa.InvoiceOrderByField.DueDate),sr(br)},isSelected:or===javascript.Mercoa.InvoiceOrderByField.DueDate,orderDirection:ir})}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900",children:jsx(TableOrderHeader,{title:"Amount",setOrder:br=>{ar(javascript.Mercoa.InvoiceOrderByField.Amount),sr(br)},isSelected:or===javascript.Mercoa.InvoiceOrderByField.Amount,orderDirection:ir})}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 mercoa-pl-6 mercoa-hidden lg:mercoa-table-cell",children:"Status"})]})}),jsx("tbody",{className:"mercoa-divide-y mercoa-divide-gray-200 mercoa-bg-white",children:re.map(br=>{var _r;return jsxs("tr",{className:"mercoa-cursor-pointer hover:mercoa-bg-gray-100",onClick:()=>{te&&te(br)},children:[jsx("td",{className:"mercoa-whitespace-nowrap mercoa-py-3 mercoa-pl-4 mercoa-pr-3 mercoa-text-sm mercoa-font-medium mercoa-text-gray-900 sm:mercoa-pl-3",children:(_r=br.payer)==null?void 0:_r.name}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-3 mercoa-text-sm mercoa-text-gray-900 mercoa-hidden sm:mercoa-table-cell",children:br.invoiceNumber}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-3 mercoa-text-sm mercoa-text-gray-900",children:dayjs$1(br.dueDate).format("MMM DD, YYYY")}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-3 mercoa-text-sm mercoa-text-gray-900",children:accounting.formatMoney(br.amount??"",currencyCodeToSymbol(br.currency))}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-3 mercoa-text-sm mercoa-hidden lg:mercoa-table-cell",children:br.status})]},br.id)})})]})}),jsx(TableNavigation,{data:re,page:Sr,setPage:Er,hasMore:cr,startingAfter:dr,setStartingAfter:mr,count:ur,resultsPerPage:yr,setResultsPerPage:Mr})]}):jsx(LoadingSpinner,{})}):jsx("div",{className:"mercoa-mt-7",children:jsx(Skeleton,{rows:10})})}function Receivables({onSelectInvoice:ee}){const te=useMercoaSession(),[ce,re]=React$1.useState(""),[nr,or]=React$1.useState([]);function ar(sr){return sr.reduce((cr,lr)=>(cr+=lr.totalCount,cr),0)}function ir(sr,cr){return!sr||sr.length<1?accounting.formatMoney(0,currencyCodeToSymbol("USD")):sr.length<2?accounting.formatMoney(sr[0][cr]??0??"",currencyCodeToSymbol(sr[0].currency)):jsx("div",{children:sr.map(lr=>jsxs("p",{children:[jsx("span",{children:accounting.formatMoney(lr[cr]??0??"",currencyCodeToSymbol(lr.currency))}),jsxs("span",{className:"mercoa-text-gray-500 mercoa-text-xs",children:[" ",lr.currency]})]},lr.currency))})}return React$1.useEffect(()=>{var sr,cr;!te.token||!((sr=te.entity)!=null&&sr.id)||(cr=te.client)==null||cr.entity.invoice.metrics(te.entity.id,{search:ce,excludePayables:!0}).then(lr=>{or(lr)})},[ce,te.client,te.entity,te.refreshId]),jsxs("div",{className:"mercoa-mt-8",children:[jsxs("div",{className:"mercoa-grid mercoa-items-center mercoa-grid-cols-3",children:[jsx("div",{className:"mercoa-hidden md:mercoa-block md:mercoa-col-span-2"}),jsx("div",{className:"mercoa-mt-2 mercoa-flex mercoa-w-full mercoa-rounded-md mercoa-shadow-sm mercoa-mr-2 mercoa-col-span-3 md:mercoa-col-span-1",children:jsx(DebouncedSearch,{placeholder:"Search Payers",onSettle:re})})]}),jsxs("div",{className:"mercoa-grid mercoa-grid-cols-3 mercoa-space-x-3 mercoa-mt-2",children:[jsx(StatCard,{size:"sm",title:"Total Invoices",value:ar(nr)??0}),jsx(StatCard,{size:"sm",title:"Total Amount",value:ir(nr,"totalAmount")}),jsx(StatCard,{size:"sm",title:"Average Amount",value:ir(nr,"averageAmount")})]}),jsx(ReceivablesTable,{search:ce,onClick:ee})]})}exports.AcceptToSButton=AcceptToSButton,exports.AcceptTosForm=AcceptTosForm,exports.AccountTypeRadioBlock=AccountTypeRadioBlock,exports.AccountTypeSelectBlock=AccountTypeSelectBlock,exports.AddBankAccount=AddBankAccount,exports.AddBankAccountForm=AddBankAccountForm,exports.AddBankViaPlaidOrManual=AddBankViaPlaidOrManual,exports.AddCheck=AddCheck,exports.AddCheckForm=AddCheckForm,exports.AddCounterpartyModal=AddCounterpartyModal,exports.AddCustomPaymentMethod=AddCustomPaymentMethod,exports.AddCustomPaymentMethodForm=AddCustomPaymentMethodForm,exports.AddDialog=AddDialog,exports.AddressBlock=AddressBlock,exports.ApprovalPolicies=ApprovalPolicies,exports.BankAccountComponent=BankAccountComponent,exports.BankAccounts=BankAccounts,exports.BusinessTypeBlock=BusinessTypeBlock,exports.CheckComponent=CheckComponent,exports.Counterparties=Counterparties,exports.CounterpartyDetails=CounterpartyDetails,exports.CounterpartySearch=CounterpartySearch,exports.CustomPaymentMethod=CustomPaymentMethod,exports.CustomPaymentMethodComponent=CustomPaymentMethodComponent,exports.DateOfBirthBlock=DateOfBirthBlock,exports.DebouncedSearch=DebouncedSearch,exports.DefaultPaymentMethodIndicator=DefaultPaymentMethodIndicator,exports.DescriptionBlock=DescriptionBlock,exports.DoingBusinessAsBlock=DoingBusinessAsBlock,exports.EINBlock=EINBlock,exports.EditBankAccount=EditBankAccount,exports.EditInvoiceForm=EditInvoiceForm,exports.EmailBlock=EmailBlock,exports.EntityCreation=EntityCreation,exports.EntityDetails=EntityDetails,exports.EntityOnboarding=EntityOnboarding,exports.EntityOnboardingButton=EntityOnboardingButton,exports.EntityPortal=EntityPortal,exports.EntityStatus=EntityStatus,exports.EntityUserNotificationTable=EntityUserNotificationTable,exports.EntityUsersTable=EntityUsersTable,exports.FormationDateBlock=FormationDateBlock,exports.InvoiceComments=InvoiceComments,exports.InvoiceDetails=InvoiceDetails,exports.InvoiceInbox=InvoiceInbox,exports.InvoiceStatusPill=InvoiceStatusPill,exports.LegalBusinessNameBlock=LegalBusinessNameBlock,exports.LoadingSpinner=LoadingSpinner,exports.LoadingSpinnerIcon=LoadingSpinnerIcon,exports.MercoaButton=MercoaButton,exports.MercoaCombobox=MercoaCombobox,exports.MercoaSession=MercoaSession,exports.MetadataSelection=MetadataSelection,exports.NameBlock=NameBlock,exports.PhoneBlock=PhoneBlock,exports.Receivables=Receivables,exports.RepresentativeComponent=RepresentativeComponent,exports.RepresentativeOnboardingForm=RepresentativeOnboardingForm,exports.Representatives=Representatives,exports.SSNBlock=SSNBlock,exports.SSNSchema=SSNSchema,exports.Skeleton=Skeleton,exports.StatCard=StatCard,exports.Switch=Switch,exports.TableNavigation=TableNavigation,exports.TableOrderHeader=TableOrderHeader,exports.TokenVerification=TokenVerification,exports.Tooltip=Tooltip,exports.VerifyOwnersButton=VerifyOwnersButton,exports.WebsiteBlock=WebsiteBlock,exports.accountTypeSchema=accountTypeSchema,exports.addressBlockSchema=addressBlockSchema,exports.createOrUpdateEntity=createOrUpdateEntity,exports.dateOfBirthSchema=dateOfBirthSchema,exports.descriptionSchema=descriptionSchema,exports.doingBusinessAsSchema=doingBusinessAsSchema,exports.einSchema=einSchema,exports.emailSchema=emailSchema,exports.entityDetailsForMercoaPaymentsCompleted=entityDetailsForMercoaPaymentsCompleted,exports.findCustomPaymentMethodAccountNameAndNumber=findCustomPaymentMethodAccountNameAndNumber,exports.formationDateSchema=formationDateSchema,exports.legalBusinessNameSchema=legalBusinessNameSchema,exports.nameBlockSchema=nameBlockSchema,exports.phoneSchema=phoneSchema,exports.useDebounce=useDebounce,exports.useMercoaSession=useMercoaSession,exports.websiteSchema=websiteSchema,Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"})});
|
|
274
|
+
Error: ${cr.body}`),console.error(cr)}return sr}function EntityOnboardingButton({className:ee,buttonText:te,title:ce,onClose:re,isPayee:nr,isPayor:or}){const[ar,ir]=React$1.useState(!1),sr=useMercoaSession();function cr(dr){ir(dr),!dr&&re&&re()}const{register:lr,handleSubmit:ur,watch:fr,formState:hr}=useForm({defaultValues:{accountType:javascript.Mercoa.AccountType.Business,legalBusinessName:"",email:"",firstName:"",lastName:""},resolver:async(dr,mr,yr)=>dr.accountType===javascript.Mercoa.AccountType.Business?await o(create$3({...accountTypeSchema,...legalBusinessNameSchema,...emailSchema}))(dr,mr,yr):await o(create$3({...accountTypeSchema,...nameBlockSchema,...emailSchema}))(dr,mr,yr)}),pr=fr("accountType");return jsxs(Fragment,{children:[jsx("button",{onClick:()=>{cr(!0)},className:ee||"mercoa-inline-flex mercoa-items-center mercoa-justify-center mercoa-rounded-md mercoa-border mercoa-border-transparent mercoa-bg-mercoa-primary mercoa-px-4 mercoa-py-2 mercoa-text-sm mercoa-font-medium mercoa-text-white mercoa-shadow-sm hover:mercoa-bg-mercoa-primary-dark focus:mercoa-outline-none focus:mercoa-ring-2 focus:mercoa-ring-mercoa-primary focus:mercoa-ring-offset-2 sm:mercoa-w-auto",children:te||"Get Started"}),jsx(tt$1.Root,{show:ar,as:React$1.Fragment,children:jsxs(_t$1,{as:"div",className:"mercoa-relative mercoa-z-10",onClose:cr,children:[jsx(tt$1.Child,{as:React$1.Fragment,enter:"mercoa-ease-out mercoa-duration-300",enterFrom:"mercoa-opacity-0",enterTo:"mercoa-opacity-100",leave:"mercoa-ease-in mercoa-duration-200",leaveFrom:"mercoa-opacity-100",leaveTo:"mercoa-opacity-0",children:jsx("div",{className:"mercoa-fixed mercoa-inset-0 mercoa-bg-gray-500 mercoa-bg-mercoa-opacity-75 mercoa-transition-opacity"})}),jsx("div",{className:"mercoa-fixed mercoa-inset-0 mercoa-z-10 mercoa-overflow-y-auto",children:jsx("div",{className:"mercoa-flex mercoa-min-h-full mercoa-items-end mercoa-justify-center mercoa-p-4 mercoa-text-center sm:mercoa-items-center sm:mercoa-p-0",children:jsx(tt$1.Child,{as:React$1.Fragment,enter:"mercoa-ease-out mercoa-duration-300",enterFrom:"mercoa-opacity-0 mercoa-translate-y-4 sm:mercoa-translate-y-0 sm:mercoa-scale-95",enterTo:"mercoa-opacity-100 mercoa-translate-y-0 sm:mercoa-scale-100",leave:"mercoa-ease-in mercoa-duration-200",leaveFrom:"mercoa-opacity-100 mercoa-translate-y-0 sm:mercoa-scale-100",leaveTo:"mercoa-opacity-0 mercoa-translate-y-4 sm:mercoa-translate-y-0 sm:mercoa-scale-95",children:jsx(_t$1.Panel,{className:"mercoa-relative mercoa-transform mercoa-rounded-lg mercoa-bg-white mercoa-px-4 mercoa-pt-5 mercoa-pb-4 mercoa-text-left mercoa-shadow-xl mercoa-transition-all sm:mercoa-my-8 sm:mercoa-w-full sm:mercoa-max-w-sm sm:mercoa-p-6",children:jsxs("form",{onSubmit:ur(async dr=>{if(!sr.client)return;const mr=await createOrUpdateEntity({data:dr,onClose:cr,isPayee:nr,isPayor:or,mercoaClient:sr.client});if(mr&&confirm("Do you want to onboard the entity?")){const Mr=await sr.client.entity.getOnboardingLink(mr.id,{type:nr?"PAYEE":"PAYOR"});window.location.href=Mr}}),children:[jsxs("div",{children:[jsx(AccountTypeSelectBlock,{register:lr,errors:hr.errors}),pr===javascript.Mercoa.AccountType.Business?jsx(LegalBusinessNameBlock,{register:lr,errors:hr.errors}):jsx(NameBlock,{register:lr,errors:hr.errors}),jsx(EmailBlock,{register:lr,errors:hr.errors})]}),jsx("div",{className:"mercoa-mt-4",children:jsx("button",{type:"submit",className:"mercoa-w-full mercoa-inline-flex mercoa-justify-center mercoa-rounded-md mercoa-border mercoa-border-transparent mercoa-bg-mercoa-primary mercoa-px-4 mercoa-py-2 mercoa-text-sm mercoa-font-medium mercoa-text-white mercoa-shadow-sm hover:mercoa-bg-mercoa-primary-dark focus:mercoa-outline-none focus:mercoa-ring-2 focus:mercoa-ring-mercoa-primary focus:mercoa-ring-offset-2 sm:mercoa-w-auto",children:"Continue"})})]})})})})})]})})]})}function RepresentativeOnboardingForm({entityId:ee,title:te,onClose:ce}){var pr,dr,mr,yr;const re=useMercoaSession(),nr=create$3({email:create$6().email("Email is not valid").required("Email is required"),...phoneSchema,...addressBlockSchema,...nameBlockSchema,...dateOfBirthSchema,...SSNSchema,jobTitle:create$6().required("Job title is required"),ownershipPercentage:create$5().typeError("Ownership percentage is required").min(0,"Ownership percentage must be greater than 0").max(100,"Ownership percentage must be less than 100").required("Ownership percentage is required"),isController:create$7().required()}).required(),{control:or,register:ar,handleSubmit:ir,setValue:sr,trigger:cr,watch:lr,formState:{errors:ur,isValid:fr}}=useForm({mode:"onChange",resolver:o(nr)});async function hr(Mr){var Er;const Sr={email:Mr.email,phone:{number:Mr.phoneNumber,countryCode:"1"},name:{firstName:Mr.firstName,lastName:Mr.lastName,middleName:Mr.middleName,suffix:Mr.suffix},birthDate:{day:dayjs$1(Mr.dob).format("D"),month:dayjs$1(Mr.dob).format("M"),year:dayjs$1(Mr.dob).format("YYYY")},address:{addressLine1:Mr.addressLine1,addressLine2:Mr.addressLine2,postalCode:Mr.postalCode,stateOrProvince:Mr.stateOrProvince,city:Mr.city,country:"US"},governmentId:{ssn:Mr.taxID},responsibilities:{isController:Mr.isController,isOwner:Mr.ownershipPercentage>=25,ownershipPercentage:Number(Mr.ownershipPercentage),jobTitle:Mr.jobTitle}};try{await((Er=re.client)==null?void 0:Er.entity.representative.create(ee,Sr)),await re.refresh(),ce&&ce(Mr)}catch(br){console.error(br),Q$1.error("There was an issue creating this representative. Please check your information and try again.")}}return jsxs("form",{onSubmit:ir(hr),children:[jsx("div",{children:jsxs("div",{className:"mercoa-mt-1",children:[jsxs("div",{className:"mercoa-flex",children:[jsx("div",{className:"mercoa-flex-1"}),jsxs(_t$1.Title,{as:"h3",className:"mercoa-text-lg mercoa-font-medium mercoa-leading-6 mercoa-text-gray-900",children:[jsx("button",{}),te||"Create Account"]}),jsx("div",{className:"mercoa-flex-1"}),jsx(XMarkIcon$1,{className:"mercoa-h-5 mercoa-w-5 mercoa-cursor-pointer mercoa-rounded-md mercoa-p-0.5 hover:mercoa-bg-gray-100",type:"button",onClick:()=>{ce&&ce()}})]}),jsx(NameBlock,{register:ar,errors:ur}),jsxs("div",{className:"mercoa-grid mercoa-grid-cols-2 mercoa-gap-3",children:[jsx(EmailBlock,{register:ar,errors:ur}),jsx(PhoneBlock,{control:or,errors:ur}),jsx(DateOfBirthBlock,{control:or,errors:ur}),jsx(SSNBlock,{control:or,errors:ur}),jsxs("div",{className:"mercoa-mt-2",children:[jsx("label",{htmlFor:"jobTitle",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Job Title"}),jsx("div",{className:"mercoa-mt-1",children:jsx("input",{...ar("jobTitle"),type:"text",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm"})}),((pr=ur.jobTitle)==null?void 0:pr.message)&&jsx("p",{className:"mercoa-text-sm mercoa-text-red-500",children:(dr=ur.jobTitle)==null?void 0:dr.message.toString()})]}),jsxs("div",{className:"mercoa-mt-2",children:[jsx("label",{htmlFor:"ownershipPercentage",className:"mercoa-block mercoa-text-left mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Percent Ownership"}),jsx("div",{className:"mercoa-mt-1",children:jsx("input",{...ar("ownershipPercentage"),type:"number",min:0,max:100,placeholder:"0-100",className:"mercoa-block mercoa-w-full mercoa-rounded-md mercoa-border-gray-300 mercoa-shadow-sm focus:mercoa-border-mercoa-primary focus:mercoa-ring-mercoa-primary sm:mercoa-text-sm"})}),((mr=ur.ownershipPercentage)==null?void 0:mr.message)&&jsx("p",{className:"mercoa-text-sm mercoa-text-red-500",children:(yr=ur.ownershipPercentage)==null?void 0:yr.message.toString()})]})]}),jsx(AddressBlock,{register:ar,errors:ur,setValue:sr,trigger:cr,watch:lr,label:"Residential Address"}),jsxs("div",{className:"mercoa-relative mercoa-mt-2 mercoa-flex mercoa-items-start mercoa-items-center",children:[jsx("div",{className:"mercoa-flex mercoa-h-5 mercoa-items-center",children:jsx("input",{...ar("isController"),type:"checkbox",className:"mercoa-h-4 mercoa-w-4 mercoa-rounded mercoa-border-gray-300 mercoa-text-mercoa-primary-text focus:mercoa-ring-mercoa-primary"})}),jsx("div",{className:"mercoa-ml-3 mercoa-text-sm",children:jsx(Tooltip,{title:"Every business requires a controller. Examples include the CEO, COO, Treasurer, President, Vice President, or Managing Partner.",children:jsxs("label",{htmlFor:"isController",className:"mercoa-font-medium mercoa-text-gray-700",children:["This person is a company controller"," ",jsx(InformationCircleIcon$1,{className:"mercoa-inline mercoa-h-5 mercoa-w-5"})]})})})]})]})}),jsx("div",{className:"mercoa-mt-5 sm:mercoa-mt-6",children:jsx("button",{disabled:!fr,className:"mercoa-inline-flex mercoa-w-full mercoa-justify-center mercoa-rounded-md mercoa-border mercoa-border-transparent mercoa-bg-mercoa-primary mercoa-px-4 mercoa-py-2 mercoa-text-base mercoa-font-medium mercoa-text-white mercoa-shadow-sm hover:mercoa-bg-mercoa-primary-dark focus:mercoa-outline-none focus:mercoa-ring-2 focus:mercoa-ring-mercoa-primary focus:mercoa-ring-offset-2 disabled:mercoa-bg-mercoa-primary-light sm:mercoa-text-sm",children:"Add Representative"})})]})}function Representatives({children:ee,onSelect:te,showAdd:ce,showEdit:re}){var lr;const[nr,or]=React$1.useState(),[ar,ir]=React$1.useState(!1),sr=useMercoaSession();React$1.useEffect(()=>{var ur,fr;sr.token&&((ur=sr.entity)!=null&&ur.id)&&((fr=sr.client)==null||fr.entity.representative.getAll(sr.entity.id).then(hr=>{or(hr)}))},[sr.entity,sr.token,ar,sr.refreshId]);const cr=()=>{ir(!1)};return ee?ee({representatives:nr}):jsxs(Fragment,{children:[nr&&nr.map(ur=>jsx("div",{className:"mercoa-mt-2",children:jsx(RepresentativeComponent,{representative:ur,onSelect:te,showEdit:re})},ur.id)),ce&&jsxs("div",{className:"mercoa-mt-2",children:[jsx(AddDialog,{show:ar,onClose:cr,component:jsx(RepresentativeOnboardingForm,{title:"Create Representative",onClose:cr,entityId:((lr=sr.entity)==null?void 0:lr.id)??""})}),jsx(RepresentativeComponent,{onSelect:()=>ir(!0)})]})]})}function RepresentativeComponent({children:ee,representative:te,onSelect:ce,showEdit:re,selected:nr}){var ir,sr,cr;const or=useMercoaSession();async function ar(){var lr,ur,fr;if(or.token){if(!((lr=or.entity)!=null&&lr.id)){Q$1.error("Entity not found");return}(fr=(ur=or.client)==null?void 0:ur.entity.representative)==null||fr.delete(or.entity.id,(te==null?void 0:te.id)??""),or.refresh()}}return te?jsxs("div",{onClick:()=>{ce&&ce(te)},className:`mercoa-relative mercoa-flex mercoa-items-center mercoa-space-x-3 mercoa-rounded-lg mercoa-border ${nr?"mercoa-border-mercoa-primary":"mercoa-border-gray-300"} mercoa-bg-white mercoa-px-6 mercoa-py-5 mercoa-shadow-sm focus-within:mercoa-ring-2 focus-within:mercoa-ring-mercoa-primary focus-within:mercoa-ring-offset-2 ${ce?"mercoa-cursor-pointer hover:mercoa-border-gray-400":""}`,children:[jsx("div",{className:`mercoa-flex-shrink-0 mercoa-rounded-full mercoa-p-1 ${nr?"mercoa-text-mercoa-primary-text-invert mercoa-bg-mercoa-primary-light":"mercoa-bg-gray-200 mercoa-text-gray-600"}`,children:jsx(UserIcon$1,{className:"mercoa-h-5 mercoa-w-5"})}),jsxs("div",{className:"mercoa-min-w-0 mercoa-flex-1",children:[!re&&jsx("span",{className:"mercoa-absolute mercoa-inset-0","aria-hidden":"true"}),jsxs("p",{className:`mercoa-text-sm mercoa-font-medium mercoa-text-gray-900 ${nr?"mercoa-underline":""}`,children:[te.name.firstName," ",te.name.lastName," - ",(ir=te.responsibilities)==null?void 0:ir.jobTitle]}),jsxs("p",{className:`mercoa-text-xs mercoa-font-medium mercoa-text-gray-900 ${nr?"mercoa-underline":""}`,children:["Ownership: ",(sr=te.responsibilities)==null?void 0:sr.ownershipPercentage,"%"]}),((cr=te.responsibilities)==null?void 0:cr.isController)&&jsx("p",{className:`mercoa-text-xs mercoa-font-medium mercoa-text-gray-900 ${nr?"mercoa-underline":""}`,children:"Controller"})]}),re&&jsx("div",{className:"mercoa-flex-shrink-0",children:jsxs("button",{className:"mercoa-ml-1 mercoa-cursor-pointer hover:mercoa-text-red-300",onClick:()=>ar(),children:[" ",jsx(TrashIcon$1,{className:"mercoa-h-5 mercoa-w-5"})]})})]},te==null?void 0:te.id):jsxs("div",{onClick:()=>{ce&&ce(te)},className:`mercoa-relative mercoa-flex mercoa-items-center mercoa-space-x-3 mercoa-rounded-lg mercoa-border mercoa-border-gray-300 mercoa-bg-white mercoa-px-6 mercoa-py-5 mercoa-shadow-sm focus-within:mercoa-ring-2 focus-within:mercoa-ring-mercoa-primary focus-within:mercoa-ring-offset-2 hover:mercoa-border-gray-400 ${ce?"mercoa-cursor-pointer ":""}`,children:[jsx("div",{className:`mercoa-flex-shrink-0 mercoa-rounded-full mercoa-p-1 ${nr?"mercoa-text-mercoa-primary-text-invert mercoa-bg-mercoa-primary-light":"mercoa-bg-gray-200 mercoa-text-gray-600"}`,children:jsx(PlusIcon$1,{className:"mercoa-h-5 mercoa-w-5"})}),jsxs("div",{className:"mercoa-min-w-0 mercoa-flex-1",children:[jsx("span",{className:"mercoa-absolute mercoa-inset-0","aria-hidden":"true"}),jsx("p",{className:"mercoa-text-sm mercoa-font-medium mercoa-text-gray-900",children:"Add new representative"}),jsx("p",{className:"mercoa-truncate mercoa-text-sm mercoa-text-gray-500"})]})]})}function VerifyOwnersButton({entity:ee}){var or,ar;const te=useMercoaSession(),[ce,re]=React$1.useState();React$1.useEffect(()=>{var ir,sr;te.token&&((ir=te.entity)!=null&&ir.id)&&((sr=te.client)==null||sr.entity.representative.getAll(te.entity.id).then(cr=>{re(cr)}))},[te.entity,te.token,te.refreshId]);const nr=ce==null?void 0:ce.some(ir=>ir.responsibilities.isController);return!ee||(ar=(or=ee.profile)==null?void 0:or.business)!=null&&ar.ownersProvided?jsx(Fragment,{}):jsx(MercoaButton,{onClick:async()=>{var ir;ee.accountType==="business"?(await((ir=te.client)==null?void 0:ir.entity.initiateKyb(ee.id)),Q$1.success("Verification Started")):ee.accountType==="individual"&&Q$1.error("not implemented yet!"),te.refresh()},disabled:!nr,tooltip:nr?void 0:"Please add at least one representative who is a controller",isEmphasized:!0,className:"mercoa-mt-2",children:"Verify Account"})}function AcceptToSButton({className:ee,buttonText:te,title:ce,onClose:re,entity:nr}){const[or,ar]=React$1.useState(!1);function ir(sr){ar(sr),!sr&&re&&re()}return jsxs(Fragment,{children:[jsx(MercoaButton,{onClick:()=>{ir(!0)},isEmphasized:!0,size:"md",children:te||"Terms of Service"}),jsx(tt$1.Root,{show:or,as:React$1.Fragment,children:jsxs(_t$1,{as:"div",className:"mercoa-relative mercoa-z-10",onClose:ir,children:[jsx(tt$1.Child,{as:React$1.Fragment,enter:"mercoa-ease-out mercoa-duration-300",enterFrom:"mercoa-opacity-0",enterTo:"mercoa-opacity-100",leave:"mercoa-ease-in mercoa-duration-200",leaveFrom:"mercoa-opacity-100",leaveTo:"mercoa-opacity-0",children:jsx("div",{className:"mercoa-fixed mercoa-inset-0 mercoa-bg-gray-500 mercoa-bg-mercoa-opacity-75 mercoa-transition-opacity"})}),jsx("div",{className:"mercoa-fixed mercoa-inset-0 mercoa-z-10 mercoa-overflow-y-auto",children:jsx("div",{className:"mercoa-flex mercoa-min-h-full mercoa-items-end mercoa-justify-center mercoa-p-4 mercoa-text-center sm:mercoa-items-center sm:mercoa-p-0",children:jsx(tt$1.Child,{as:React$1.Fragment,enter:"mercoa-ease-out mercoa-duration-300",enterFrom:"mercoa-opacity-0 mercoa-translate-y-4 sm:mercoa-translate-y-0 sm:mercoa-scale-95",enterTo:"mercoa-opacity-100 mercoa-translate-y-0 sm:mercoa-scale-100",leave:"mercoa-ease-in mercoa-duration-200",leaveFrom:"mercoa-opacity-100 mercoa-translate-y-0 sm:mercoa-scale-100",leaveTo:"mercoa-opacity-0 mercoa-translate-y-4 sm:mercoa-translate-y-0 sm:mercoa-scale-95",children:jsxs(_t$1.Panel,{className:"mercoa-relative mercoa-transform mercoa-rounded-lg mercoa-bg-white mercoa-px-4 mercoa-pt-5 mercoa-pb-4 mercoa-text-left mercoa-shadow-xl mercoa-transition-all sm:mercoa-my-8 sm:mercoa-w-full sm:mercoa-max-w-md sm:mercoa-p-6",children:[jsx(_t$1.Title,{className:"mercoa-mb-3 mercoa-w-full mercoa-text-center mercoa-text-xl mercoa-text-gray-800 mercoa-underline",children:ce||"Terms of Service"}),jsx(AcceptTosForm,{entity:nr,onComplete:ir})]})})})})]})})]})}function AcceptTosForm({entity:ee,onComplete:te}){var ir;const ce=useMercoaSession(),{register:re,watch:nr,handleSubmit:or}=useForm(),ar=nr();return jsxs("form",{onSubmit:or(async()=>{var sr;if(!ee.id){Q$1.error("Entity not found");return}await((sr=ce.client)==null?void 0:sr.entity.acceptTermsOfService(ee.id)),te&&te(!1),ce.refresh()}),children:[jsxs("div",{className:"mercoa-mb-10 mercoa-text-sm",children:[jsx("b",{children:capitalize((ir=ce.organization)==null?void 0:ir.name)})," has partnered with"," ",jsx("a",{href:"https://mercoa.com",target:"_blank",rel:"noreferrer",className:"mercoa-text-blue-500 mercoa-underline",children:"Mercoa"})," ","to provide financial services.",jsx("br",{}),jsx("br",{}),"By clicking the button below, you agree to the"," ",jsx("a",{href:"https://mercoa.com/legal/platform-agreement/",target:"_blank",rel:"noreferrer",className:"mercoa-text-blue-500 mercoa-underline",children:"Mercoa Platform Agreement"})," ","and"," ",jsx("a",{href:"https://mercoa.com/legal/privacy-policy/",target:"_blank",rel:"noreferrer",className:"mercoa-text-blue-500 mercoa-underline",children:"Privacy Policy"}),"."]}),jsxs("div",{className:"mercoa-relative mercoa-mt-2 mercoa-flex mercoa-items-start mercoa-items-center",children:[jsx("div",{className:"mercoa-flex mercoa-h-5 mercoa-items-center",children:jsx("input",{...re("mercoa"),type:"checkbox",className:"mercoa-h-4 mercoa-w-4 mercoa-rounded mercoa-border-gray-300 mercoa-text-mercoa-primary-text focus:mercoa-ring-mercoa-primary"})}),jsx("div",{className:"mercoa-ml-3 mercoa-text-sm",children:jsxs("label",{htmlFor:"isController",className:"mercoa-font-medium mercoa-text-gray-700",children:["I have read and accept the"," ",jsxs("a",{href:"https://mercoa.com/legal/platform-agreement/",target:"_blank",rel:"noreferrer",className:"mercoa-text-blue-500 mercoa-underline",children:[" ","Mercoa terms of service"]})]})})]}),jsx(MercoaButton,{isEmphasized:!0,disabled:!ar.mercoa,className:"mercoa-mt-5",size:"md",children:"Confirm"})]})}function EntityOnboarding({entity:ee,organization:te,type:ce,setEntityData:re}){var hr,pr,dr,mr,yr,Mr,Sr,Er,br,_r,xr,jr,wr,Ir,Br,Ar,Ur,Lr,Zr,nn,rn,tn,Nr,Fr,Yr,Dr,vr,Or,Tr,Pr,gr,$r,Rr,kr,Cr,qr,on,sn;const{register:nr,handleSubmit:or,setValue:ar,trigger:ir,control:sr,watch:cr,formState:{errors:lr}}=useForm({defaultValues:{accountType:ee.accountType,email:ee.email,firstName:((hr=ee.profile.individual)==null?void 0:hr.name.firstName)??"",middleName:(pr=ee.profile.individual)==null?void 0:pr.name.middleName,lastName:((dr=ee.profile.individual)==null?void 0:dr.name.lastName)??"",suffix:(mr=ee.profile.individual)==null?void 0:mr.name.suffix,phoneNumber:formatPhoneNumber(((Mr=(yr=ee.profile.individual)==null?void 0:yr.phone)==null?void 0:Mr.number)??((Er=(Sr=ee.profile.business)==null?void 0:Sr.phone)==null?void 0:Er.number)),addressLine1:((_r=(br=ee.profile.individual)==null?void 0:br.address)==null?void 0:_r.addressLine1)??((jr=(xr=ee.profile.business)==null?void 0:xr.address)==null?void 0:jr.addressLine1),addressLine2:((Ir=(wr=ee.profile.individual)==null?void 0:wr.address)==null?void 0:Ir.addressLine2)??((Ar=(Br=ee.profile.business)==null?void 0:Br.address)==null?void 0:Ar.addressLine2),city:((Lr=(Ur=ee.profile.individual)==null?void 0:Ur.address)==null?void 0:Lr.city)??((nn=(Zr=ee.profile.business)==null?void 0:Zr.address)==null?void 0:nn.city),stateOrProvince:((tn=(rn=ee.profile.individual)==null?void 0:rn.address)==null?void 0:tn.stateOrProvince)??((Fr=(Nr=ee.profile.business)==null?void 0:Nr.address)==null?void 0:Fr.stateOrProvince),postalCode:((Dr=(Yr=ee.profile.individual)==null?void 0:Yr.address)==null?void 0:Dr.postalCode)??((Or=(vr=ee.profile.business)==null?void 0:vr.address)==null?void 0:Or.postalCode),country:((Pr=(Tr=ee.profile.individual)==null?void 0:Tr.address)==null?void 0:Pr.country)??(($r=(gr=ee.profile.business)==null?void 0:gr.address)==null?void 0:$r.country)??"US",taxID:(Rr=ee.profile.individual)!=null&&Rr.governmentIdProvided?"****":(kr=ee.profile.business)!=null&&kr.taxIdProvided?"**-*******":"",dob:new Date,legalBusinessName:((Cr=ee.profile.business)==null?void 0:Cr.legalBusinessName)??"",doingBusinessAs:(qr=ee.profile.business)==null?void 0:qr.doingBusinessAs,description:(on=ee.profile.business)==null?void 0:on.description,website:(sn=ee.profile.business)==null?void 0:sn.website,formationDate:new Date},resolver:async(yn,jn,wn)=>yn.accountType===javascript.Mercoa.AccountType.Individual?o(create$3({...(fr==null?void 0:fr.individual.name.required)&&nameBlockSchema,...(fr==null?void 0:fr.individual.email.required)&&emailSchema,...(fr==null?void 0:fr.individual.phone.required)&&phoneSchema,...(fr==null?void 0:fr.individual.dateOfBirth.required)&&dateOfBirthSchema,...(fr==null?void 0:fr.individual.address.required)&&addressBlockSchema,...(fr==null?void 0:fr.individual.ssn.required)&&SSNSchema}).required())(yn,jn,wn):o(create$3({...(fr==null?void 0:fr.business.name.required)&&legalBusinessNameSchema,...(fr==null?void 0:fr.business.email.required)&&emailSchema,...(fr==null?void 0:fr.business.phone.required)&&phoneSchema,...(fr==null?void 0:fr.business.website.required)&&websiteSchema,...(fr==null?void 0:fr.business.address.required)&&addressBlockSchema,...(fr==null?void 0:fr.business.ein.required)&&einSchema,...(fr==null?void 0:fr.business.formationDate.required)&&formationDateSchema,...(fr==null?void 0:fr.business.description.required)&&descriptionSchema}).required())(yn,jn,wn)}),ur=cr("accountType"),fr=ce==="payee"?te.payeeOnboardingOptions:te.payorOnboardingOptions;return jsxs("form",{onSubmit:or(async yn=>{re(yn)}),children:[jsxs("div",{className:"sm:mercoa-grid sm:mercoa-grid-cols-2 mercoa-gap-4",children:[(fr==null?void 0:fr.enableBusiness)&&(fr==null?void 0:fr.enableIndividual)&&jsx("div",{className:"mercoa-col-span-2",children:jsx(AccountTypeSelectBlock,{register:nr,errors:lr})}),ur==="individual"&&jsxs(Fragment,{children:[(fr==null?void 0:fr.individual.email.show)&&jsx("div",{className:"mercoa-col-span-2",children:jsx(EmailBlock,{register:nr,errors:lr,readOnly:!fr.individual.email.edit,required:fr.individual.email.required})}),(fr==null?void 0:fr.individual.name.show)&&jsx("div",{className:"mercoa-col-span-2",children:jsx(NameBlock,{register:nr,errors:lr,readOnly:!fr.individual.name.edit,required:fr.individual.name.required})}),(fr==null?void 0:fr.individual.phone.show)&&jsx(PhoneBlock,{control:sr,errors:lr,readOnly:!fr.individual.phone.edit,required:fr.individual.phone.required}),(fr==null?void 0:fr.individual.dateOfBirth.show)&&jsx(DateOfBirthBlock,{control:sr,errors:lr,readOnly:!fr.individual.dateOfBirth.edit,required:fr.individual.dateOfBirth.required}),(fr==null?void 0:fr.individual.address.show)&&jsx("div",{className:"mercoa-col-span-2",children:jsx(AddressBlock,{register:nr,errors:lr,setValue:ar,trigger:ir,watch:cr,readOnly:!fr.individual.address.edit,required:fr.individual.address.required})}),(fr==null?void 0:fr.individual.ssn.show)&&jsx(SSNBlock,{control:sr,errors:lr,readOnly:!fr.individual.ssn.edit,required:fr.individual.ssn.required})]}),ur==="business"&&jsxs(Fragment,{children:[(fr==null?void 0:fr.business.name.show)&&jsx(LegalBusinessNameBlock,{register:nr,errors:lr,readOnly:!fr.business.name.edit,required:fr.business.name.required}),(fr==null?void 0:fr.business.email.show)&&jsx(EmailBlock,{register:nr,errors:lr,readOnly:!fr.business.email.edit,required:fr.business.email.required}),(fr==null?void 0:fr.business.phone.show)&&jsx(PhoneBlock,{control:sr,errors:lr,readOnly:!fr.business.phone.edit,required:fr.business.phone.required}),(fr==null?void 0:fr.business.website.show)&&jsx(WebsiteBlock,{register:nr,errors:lr,readOnly:!fr.business.website.edit,required:fr.business.website.required}),(fr==null?void 0:fr.business.address.show)&&jsx("div",{className:"mercoa-col-span-2",children:jsx(AddressBlock,{label:"Business Address",register:nr,errors:lr,setValue:ar,trigger:ir,watch:cr,readOnly:!fr.business.address.edit,required:fr.business.address.required})}),(fr==null?void 0:fr.business.type.show)&&jsx(BusinessTypeBlock,{register:nr,errors:lr,readOnly:!fr.business.type.edit,required:fr.business.type.required}),(fr==null?void 0:fr.business.ein.show)&&jsx(EINBlock,{control:sr,errors:lr,readOnly:!fr.business.ein.edit,required:fr.business.ein.required}),(fr==null?void 0:fr.business.formationDate.show)&&jsx(FormationDateBlock,{control:sr,errors:lr,readOnly:!fr.business.formationDate.edit,required:fr.business.formationDate.required}),(fr==null?void 0:fr.business.description.show)&&jsx("div",{className:"mercoa-col-span-2",children:jsx(DescriptionBlock,{register:nr,errors:lr,readOnly:!fr.business.description.edit,required:fr.business.description.required})})]})]}),jsxs("div",{className:"mercoa-mt-8 mercoa-flex",children:[jsx("div",{className:"mercoa-flex-1"}),jsx(MercoaButton,{isEmphasized:!0,children:"Next"})]})]})}function EntityCreation({organization:ee,type:te,setEntityData:ce}){const re=te==="payee"?ee.payeeOnboardingOptions:ee.payorOnboardingOptions,{register:nr,handleSubmit:or,watch:ar,formState:{errors:ir}}=useForm({defaultValues:{accountType:re!=null&&re.enableBusiness?javascript.Mercoa.AccountType.Business:javascript.Mercoa.AccountType.Individual,email:"",legalBusinessName:"",firstName:"",middleName:"",lastName:"",suffix:""}}),sr=ar("accountType");return jsxs("form",{onSubmit:or(async cr=>{ce(cr)}),children:[jsxs("div",{className:"mercoa-gap-4",children:[(re==null?void 0:re.enableBusiness)&&(re==null?void 0:re.enableIndividual)&&jsx("div",{className:"mercoa-col-span-2",children:jsx(AccountTypeSelectBlock,{register:nr,errors:ir})}),sr==="individual"&&jsxs(Fragment,{children:[(re==null?void 0:re.individual.email.show)&&jsx(EmailBlock,{register:nr,errors:ir,readOnly:!re.individual.email.edit,required:re.individual.email.required}),(re==null?void 0:re.individual.name.show)&&jsx(NameBlock,{register:nr,errors:ir,readOnly:!re.individual.name.edit,required:re.individual.name.required})]}),sr==="business"&&jsxs(Fragment,{children:[(re==null?void 0:re.business.name.show)&&jsx(LegalBusinessNameBlock,{register:nr,errors:ir,readOnly:!re.business.name.edit,required:re.business.name.required}),(re==null?void 0:re.business.email.show)&&jsx(EmailBlock,{register:nr,errors:ir,readOnly:!re.business.email.edit,required:re.business.email.required})]})]}),jsxs("div",{className:"mercoa-mt-8 mercoa-flex",children:[jsx("div",{className:"mercoa-flex-1"}),jsx(MercoaButton,{isEmphasized:!0,children:"Next"})]})]})}function entityDetailsForMercoaPaymentsCompleted(ee){if(!ee.profile)return!1;if(ee.accountType==="business"){if(!ee.profile.business||!ee.profile.business.address||!ee.profile.business.legalBusinessName||!ee.profile.business.taxIdProvided||!ee.profile.business.businessType||!(ee.profile.business.description||ee.profile.business.website))return!1}else if(ee.accountType==="individual"&&(!ee.profile.individual||!ee.profile.individual.address||!ee.profile.individual.name||!ee.profile.individual.phone||!ee.profile.individual.birthDateProvided||!ee.profile.individual.governmentIdProvided))return!1;return!0}function formatPhoneNumber(ee){var te=(""+ee).replace(/\D/g,""),ce=te.match(/^(\d{3})(\d{3})(\d{4})$/);return ce?"("+ce[1]+") "+ce[2]+"-"+ce[3]:ee}function EntityPortal({token:ee}){var dr,mr,yr,Mr,Sr,Er,br,_r,xr,jr,wr,Ir,Br,Ar,Ur,Lr,Zr,nn,rn,tn,Nr,Fr,Yr,Dr,vr,Or,Tr,Pr,gr;const te=useMercoaSession(),ce=typeof window<"u"?window.location.search:"",re=new URLSearchParams(ce),nr=Object.fromEntries(re.entries()),{invoiceId:or}=nr,[ar,ir]=React$1.useState("inbox"),[sr,cr]=React$1.useState(),lr=te.entity,ur=te.user,fr=te.organization;let hr;try{const{options:$r}=jwtDecode(ee);hr=$r}catch($r){console.error($r)}async function pr($r){await te.getNewToken(),ir($r)}if(React$1.useEffect(()=>{te.setIframeOptions({options:hr})},[ee]),React$1.useEffect(()=>{var $r;or&&(($r=te.client)==null||$r.invoice.get(or).then(Rr=>{cr(Rr),pr("invoice")}))},[or]),!lr||!te.organization)return jsx(LoadingSpinner,{});if(lr&&((yr=(mr=(dr=te.iframeOptions)==null?void 0:dr.options)==null?void 0:mr.entity)!=null&&yr.enableMercoaPayments)&&lr.status!=javascript.Mercoa.EntityStatus.Verified){let $r=jsx(Fragment,{});return lr!=null&&lr.acceptedTos?entityDetailsForMercoaPaymentsCompleted(lr)?!((Sr=(Mr=lr==null?void 0:lr.profile)==null?void 0:Mr.business)!=null&&Sr.ownersProvided)&&lr.accountType==="business"?$r=jsxs(Fragment,{children:[jsxs("p",{className:"mercoa-mb-5",children:[" ","Before you can pay bills, you must add business representatives and verify your account."]}),jsx("div",{className:"mercoa-mt-8",children:jsx(Representatives,{showEdit:!0,showAdd:!0})}),!((br=(Er=te.entity)==null?void 0:Er.profile.business)!=null&&br.ownersProvided)&&jsxs("div",{className:"mercoa-mt-8 mercoa-text-left",children:[jsx("h2",{className:"mercoa-font-gray-800 mercoa-text-lg",children:"KYC Verification"}),jsx("p",{className:"mercoa-font-gray-700 mercoa-mt-2 mercoa-text-sm",children:'Banking regulations require that we perform a "Know Your Customer" (KYC) process to verify account identity before enabling the ability to pay bills or send invoices.'}),jsx("p",{className:"mercoa-font-gray-700 mercoa-mt-2 mercoa-text-sm",children:"Individuals with significant ownership in the business (over 25%) must be added as representatives."}),jsx("p",{className:"mercoa-font-gray-700 mercoa-mt-2 mercoa-text-sm",children:"At least one controller must be added as a representative. Examples include the CEO, COO, Treasurer, President, Vice President, or Managing Partner."}),jsx("p",{className:"mercoa-font-gray-700 mercoa-mt-2 mercoa-text-sm",children:'Once all representatives have been added, click "Verify Account" to start this process.'}),jsx(VerifyOwnersButton,{entity:lr})]})]}):$r=jsx("div",{className:"mercoa-mt-10 mercoa-text-center mercoa-text-gray-800",children:jsx("p",{className:"mercoa-mb-5",children:" We are currently verifying your account. Please come back shortly."})}):$r=jsxs(Fragment,{children:[jsxs("div",{className:"mercoa-text-gray-800",children:[jsxs("p",{className:"mercoa-text-lg mercoa-font-normal",children:["To pay bills and invoices with ",te.organization.name,", you'll need to provide us with a few pieces of information."]}),jsxs("div",{className:"mercoa-p-4 mercoa-text-sm mercoa-rounded-md mercoa-bg-gray-100 mercoa-my-4 mercoa-grid mercoa-gap-3",children:[jsxs("p",{className:"mercoa-flex mercoa-items-center",children:[jsx(LockClosedIcon$1,{className:"mercoa-w-5 mercoa-h-5 mercoa-mr-5"})," Your information is used for verification purposes and isn't used for third-party marketing. We take your privacy seriously."]}),jsxs("p",{className:"mercoa-flex mercoa-items-center",children:[jsx(ClockIcon$1,{className:"mercoa-w-4 mercoa-h-4 mercoa-mr-5"})," This process should take approximately 5 minutes to complete."]})]})]}),jsx(EntityOnboarding,{entity:lr,organization:te.organization,type:"payor",setEntityData:async Rr=>{lr&&Rr&&te.client&&(await createOrUpdateEntity({data:Rr,entityId:lr.id,mercoaClient:te.client,isPayee:!1,isPayor:!0}),te.refresh())}})]}):$r=jsxs(Fragment,{children:[jsx("p",{className:"mercoa-font-gray-700 mercoa-my-2 mercoa-text-sm",children:"Before you can get started, please read and accept the terms of service"}),jsx(AcceptToSButton,{title:"Terms of Service",buttonText:"View Terms of Service",entity:lr})]}),jsxs("div",{className:" mercoa-container mercoa-mx-auto mercoa-mt-5 mercoa-text-center",children:[jsx("h2",{className:"mercoa-font-gray-800 mercoa-text-lg",children:"Welcome to your Accounts Payable Dashboard"}),$r]})}return jsxs("div",{className:" mercoa-container mercoa-mx-auto mercoa-px-4 sm:mercoa-px-6 lg:mercoa-px-8",children:[jsxs("div",{className:"mercoa-flex mercoa-items-center",children:[jsx("div",{className:"mercoa-flex-auto mercoa-text-sm mercoa-text-gray-700 mercoa-my-4 sm:mercoa-mt-0",children:ar==="inbox"?jsx(Fragment,{children:((_r=fr==null?void 0:fr.emailProvider)==null?void 0:_r.inboxDomain)&&jsxs(Fragment,{children:["Forward invoices to: ",jsx("br",{}),jsxs("b",{children:[lr==null?void 0:lr.emailTo,"@",(xr=fr==null?void 0:fr.emailProvider)==null?void 0:xr.inboxDomain]})]})}):jsxs(MercoaButton,{onClick:()=>pr("inbox"),type:"button",isEmphasized:!1,className:"mercoa-ml-2 mercoa-inline-flex mercoa-text-sm",children:[jsx(ArrowLeftIcon$1,{className:"-mercoa-ml-1 mercoa-inline-flex mercoa-h-5 mercoa-w-5 md:mercoa-mr-2"})," ",jsx("span",{className:"mercoa-hidden md:mercoa-inline-block",children:"Back"})]})}),jsxs("div",{className:"mercoa-my-4 mercoa-flex-none sm:mercoa-mt-0 sm:mercoa-ml-16",children:[ur&&((jr=hr==null?void 0:hr.pages)==null?void 0:jr.notifications)&&ar!=="notifications"&&ar!=="invoice"&&jsxs(MercoaButton,{onClick:()=>pr("notifications"),type:"button",isEmphasized:!1,className:"mercoa-ml-2 mercoa-inline-flex mercoa-text-sm",children:[jsx(EnvelopeIcon$1,{className:"-mercoa-ml-1 mercoa-inline-flex mercoa-h-5 mercoa-w-5 md:mercoa-mr-2"})," ",jsx("span",{className:"mercoa-hidden md:mercoa-inline-block",children:"Notifications"})]}),((wr=hr==null?void 0:hr.pages)==null?void 0:wr.representatives)&&ar!=="representatives"&&ar!=="invoice"&&jsxs(MercoaButton,{onClick:()=>pr("representatives"),type:"button",isEmphasized:!1,className:"mercoa-ml-2 mercoa-inline-flex mercoa-text-sm",children:[jsx(UsersIcon$1,{className:"-mercoa-ml-1 mercoa-inline-flex mercoa-h-5 mercoa-w-5 md:mercoa-mr-2"})," ",jsx("span",{className:"mercoa-hidden md:mercoa-inline-block",children:"Representatives"})]}),((Ir=hr==null?void 0:hr.pages)==null?void 0:Ir.counterparties)&&ar!=="counterparties"&&ar!=="invoice"&&jsxs(MercoaButton,{onClick:()=>pr("counterparties"),type:"button",isEmphasized:!1,className:"mercoa-ml-2 mercoa-inline-flex mercoa-text-sm",children:[jsx(BriefcaseIcon$1,{className:"-mercoa-ml-1 mercoa-inline-flex mercoa-h-5 mercoa-w-5 md:mercoa-mr-2"})," ",jsx("span",{className:"mercoa-hidden md:mercoa-inline-block",children:"Vendors"})]}),((Br=hr==null?void 0:hr.pages)==null?void 0:Br.approvals)&&ar!=="approvals"&&ar!=="invoice"&&jsxs(MercoaButton,{onClick:()=>pr("approvals"),type:"button",isEmphasized:!1,className:"mercoa-ml-2 mercoa-inline-flex mercoa-text-sm",children:[jsx(LockOpenIcon$1,{className:"-mercoa-ml-1 mercoa-inline-flex mercoa-h-5 mercoa-w-5 md:mercoa-mr-2"})," ",jsx("span",{className:"mercoa-hidden md:mercoa-inline-block",children:"Approval Rules"})]}),((Lr=(Ur=(Ar=te.iframeOptions)==null?void 0:Ar.options)==null?void 0:Ur.entity)==null?void 0:Lr.enableMercoaPayments)&&((Zr=hr==null?void 0:hr.pages)==null?void 0:Zr.paymentMethods)&&ar!=="payments"&&ar!=="invoice"&&jsxs(MercoaButton,{onClick:()=>pr("payments"),type:"button",isEmphasized:!1,className:"mercoa-ml-2 mercoa-inline-flex mercoa-text-sm",children:[jsx(BuildingLibraryIcon$1,{className:"-mercoa-ml-1 mercoa-inline-flex mercoa-h-5 mercoa-w-5 md:mercoa-mr-2"})," ",jsx("span",{className:"mercoa-hidden md:mercoa-inline-block",children:"Payment Methods"})]}),ar!=="invoice"&&ar!=="counterparties"&&jsxs(MercoaButton,{isEmphasized:!0,type:"button",className:"mercoa-ml-2 mercoa-inline-flex mercoa-text-sm",onClick:()=>{pr("invoice"),cr(void 0)},children:[jsx(PlusIcon$1,{className:"-mercoa-ml-1 mercoa-inline-flex mercoa-h-5 mercoa-w-5 md:mercoa-mr-2"})," ",jsx("span",{className:"mercoa-hidden md:mercoa-inline-block",children:"New Invoice"})]})]})]}),ar==="inbox"&&jsx(InvoiceInbox,{statuses:(nn=hr==null?void 0:hr.invoice)==null?void 0:nn.status,onSelectInvoice:$r=>{cr($r),pr("invoice")}}),ar==="payments"&&jsxs("div",{children:[((Nr=(tn=(rn=te.organization)==null?void 0:rn.paymentMethods)==null?void 0:tn.payerPayments)==null?void 0:Nr.find($r=>$r.type===javascript.Mercoa.PaymentMethodType.BankAccount&&$r.active))&&jsxs(Fragment,{children:[jsx("h3",{className:"mercoa-mt-8",children:"Bank Accounts"}),jsx(BankAccounts,{showEdit:!0,showAdd:!0})]}),((Dr=(Yr=(Fr=te.organization)==null?void 0:Fr.paymentMethods)==null?void 0:Yr.payerPayments)==null?void 0:Dr.find($r=>$r.type===javascript.Mercoa.PaymentMethodType.Card&&$r.active))&&jsxs(Fragment,{children:[jsx("h3",{className:"mercoa-mt-8",children:"Cards"}),jsx(CreditCards,{showEdit:!0,showAdd:!0})]}),((Tr=(Or=(vr=te.organization)==null?void 0:vr.paymentMethods)==null?void 0:Or.payerPayments)==null?void 0:Tr.find($r=>$r.type===javascript.Mercoa.PaymentMethodType.Custom&&$r.active))&&jsxs(Fragment,{children:[jsx("h3",{className:"mercoa-mt-8"}),jsx(CustomPaymentMethod,{showEdit:!0})]})]}),ur&&ar==="notifications"&&jsxs("div",{children:[jsx("h3",{className:"mercoa-mt-8",children:"Notifications"}),jsx(EntityUserNotificationTable,{entityId:lr.id,userId:ur.id})]}),ar==="approvals"&&jsxs("div",{children:[jsx("h3",{className:"mercoa-my-8",children:"Approval Rules"}),jsx(ApprovalPolicies,{})]}),ar==="counterparties"&&jsx(Counterparties,{type:"payee"}),ar==="representatives"&&jsxs("div",{children:[jsx("p",{className:"mercoa-font-gray-700 mercoa-mt-2 mercoa-text-sm",children:"Regulatory guidelines require that all individuals with significant ownership in the business (over 25%) must be added as representatives."}),jsx("p",{className:"mercoa-font-gray-700 mercoa-mt-1 mercoa-text-sm",children:"Every business also requires a controller. Examples include the CEO, COO, Treasurer, President, Vice President, or Managing Partner."}),jsx(Representatives,{showEdit:!0,showAdd:!0}),lr&&lr.accountType==="business"&&!((gr=(Pr=lr.profile)==null?void 0:Pr.business)!=null&&gr.ownersProvided)&&jsxs("div",{className:"mercoa-mt-8",children:[jsx("h2",{className:"mercoa-font-gray-800 mercoa-text-lg",children:"KYC Verification"}),jsx("p",{className:"mercoa-font-gray-700 mercoa-mt-2 mercoa-text-sm",children:'Banking regulations require that we perform a "Know Your Customer" (KYC) process to verify account identity before enabling the ability to pay bills or send invoices.'}),jsx("p",{className:"mercoa-font-gray-700 mercoa-mt-2 mercoa-text-sm",children:'Once all representatives have been added, click "Verify Account" to start this process.'}),jsx(VerifyOwnersButton,{entity:lr})]})]}),ar==="invoice"&&jsx(InvoiceDetails,{invoice:sr,addPaymentMethodRedirect:()=>pr("payments"),onRedirect:$r=>{if(!$r){pr("inbox");return}}})]})}const notificationTypeToText={[javascript.Mercoa.NotificationType.InvoiceEmailed]:"Invoice Email Received",[javascript.Mercoa.NotificationType.InvoiceCreated]:"Invoice Created",[javascript.Mercoa.NotificationType.InvoicePaid]:"Invoice Paid",[javascript.Mercoa.NotificationType.InvoiceScheduled]:"Invoice Scheduled",[javascript.Mercoa.NotificationType.InvoiceApprovalNeeded]:"Invoice Approval Needed",[javascript.Mercoa.NotificationType.InvoiceApproved]:"Invoice Approved",[javascript.Mercoa.NotificationType.InvoiceCanceled]:"Invoice Canceled",[javascript.Mercoa.NotificationType.InvoiceRejected]:"Invoice Rejected",[javascript.Mercoa.NotificationType.InvoicePending]:"Invoice Payment Initiated",[javascript.Mercoa.NotificationType.InvoiceFailed]:"Invoice Payment Failed"};function EntityUserNotificationTable({entityId:ee,userId:te,onClick:ce}){const re=useMercoaSession(),[nr,or]=React$1.useState(),[ar,ir]=React$1.useState(),[sr,cr]=React$1.useState([]),[lr,ur]=React$1.useState(20),[fr,hr]=React$1.useState(1),[pr,dr]=React$1.useState(!0),[mr,yr]=React$1.useState(0),{handleSubmit:Mr}=useForm({defaultValues:{}});return React$1.useEffect(()=>{var Sr;(Sr=re.client)==null||Sr.entity.user.notifications.find(ee,te,{limit:lr,startingAfter:sr[sr.length-1]}).then(Er=>{Er&&(dr(Er.hasMore),yr(Er.count),or(Er.data))})},[re.client,sr,lr]),React$1.useEffect(()=>{var Sr;(Sr=re.client)==null||Sr.entity.invoice.find(ee,{invoiceId:(nr==null?void 0:nr.filter(Er=>Er.invoiceId).map(Er=>`${Er.invoiceId}`))??[],limit:lr}).then(Er=>{Er&&ir(Er.data)})},[re.client,ee,nr]),jsxs("div",{children:[jsxs("div",{className:"mercoa-flex mercoa-flex-col",children:[jsxs("form",{className:"mercoa-grid mercoa-items-center mercoa-grid-cols-3 mercoa-mb-3",onSubmit:Mr(Sr=>{console.log(Sr)}),children:[jsx("div",{className:"mercoa-hidden md:mercoa-block md:mercoa-col-span-2"}),jsx("div",{className:"mercoa-mt-2 mercoa-flex mercoa-w-full mercoa-rounded-md mercoa-shadow-sm mercoa-mr-2 mercoa-col-span-3 md:mercoa-col-span-1"})]}),jsx("div",{className:"-mercoa-my-2 -mercoa-mx-4 mercoa-overflow-x-auto sm:-mercoa-mx-6 lg:-mercoa-mx-8",children:jsx("div",{className:"mercoa-inline-block mercoa-min-w-full mercoa-py-2 mercoa-align-middle md:mercoa-px-6 lg:mercoa-px-8",children:jsx("div",{className:"mercoa-overflow-hidden mercoa-shadow mercoa-ring-1 mercoa-ring-black mercoa-ring-opacity-5 md:mercoa-rounded-lg",children:jsxs("table",{className:"mercoa-min-w-full mercoa-divide-y mercoa-divide-gray-300",children:[jsx("thead",{className:"mercoa-bg-gray-50",children:jsxs("tr",{children:[jsx("th",{scope:"col",className:"mercoa-py-3.5 mercoa-pl-4 mercoa-pr-3 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 sm:mercoa-pl-6",children:"Action"}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900",children:"Date"}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900",children:"Vendor"}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900",children:"Amount"}),jsx("th",{scope:"col",className:"mercoa-py-3.5 mercoa-pl-4 mercoa-pr-3 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 sm:mercoa-pl-6",children:"Invoice ID"}),jsx("th",{})]})}),jsxs("tbody",{className:"mercoa-bg-white",children:[!nr&&jsx("tr",{children:jsx("td",{colSpan:5,className:"mercoa-p-9 mercoa-text-center",children:jsx(LoadingSpinnerIcon,{})})}),nr&&nr.map((Sr,Er)=>{var br,_r,xr,jr;return jsxs("tr",{onClick:()=>ce==null?void 0:ce({entityId:ee,userId:te,invoiceId:Sr.invoiceId}),className:`hover:mercoa-bg-gray-100 ${Er%2===0?void 0:"mercoa-bg-gray-50"}`,children:[jsx("td",{className:"mercoa-whitespace-nowrap mercoa-py-4 mercoa-pl-4 mercoa-pr-3 mercoa-text-sm mercoa-font-medium mercoa-text-gray-900 sm:mercoa-pl-6",children:notificationTypeToText[Sr.type]}),jsxs("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-4 mercoa-text-sm mercoa-text-gray-900",children:[" ",dayjs$1(Sr.createdAt).format("MM/DD/YY")]}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-4 mercoa-text-sm mercoa-text-gray-900",children:((_r=(br=ar==null?void 0:ar.find(wr=>Sr.invoiceId===wr.id))==null?void 0:br.vendor)==null?void 0:_r.name)??""}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-4 mercoa-text-sm mercoa-text-gray-900",children:accounting.formatMoney(((xr=ar==null?void 0:ar.find(wr=>Sr.invoiceId===wr.id))==null?void 0:xr.amount)??"",currencyCodeToSymbol((jr=ar==null?void 0:ar.find(wr=>Sr.invoiceId===wr.id))==null?void 0:jr.currency))}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-4 mercoa-text-sm mercoa-text-gray-900",children:Sr.invoiceId})]},Sr.id)})]})]})})})})]}),nr&&jsx(TableNavigation,{data:nr,page:fr,setPage:hr,hasMore:pr,startingAfter:sr,setStartingAfter:cr,count:mr,resultsPerPage:lr,setResultsPerPage:ur})]})}function EntityUsersTable({openNotificationPreferences:ee}){var ur;const[te,ce]=React$1.useState(),[re,nr]=React$1.useState({}),[or,ar]=React$1.useState([]),[ir,sr]=React$1.useState(),cr=useMercoaSession();React$1.useEffect(()=>{var fr,hr;!cr.token||!((fr=cr.entity)!=null&&fr.id)||(hr=cr.client)==null||hr.entity.user.getAll(cr.entity.id).then(pr=>{if(pr){ce(pr);const dr=new Set;pr.forEach(mr=>{mr.roles.forEach(yr=>{dr.add(yr)})}),ar(Array.from(dr))}})},[(ur=cr.entity)==null?void 0:ur.id,cr.refreshId,cr.token]);function lr({user:fr}){const{register:hr,handleSubmit:pr,setValue:dr,watch:mr}=useForm({defaultValues:{id:fr==null?void 0:fr.id,roles:fr==null?void 0:fr.roles.join(", "),email:fr==null?void 0:fr.email,name:fr==null?void 0:fr.name,foreignId:fr==null?void 0:fr.foreignId}});return jsxs("form",{onSubmit:pr(async yr=>{var Sr,Er,br,_r,xr;if(!((Sr=cr.entity)!=null&&Sr.id))return;const Mr={roles:[...new Set((br=(Er=yr==null?void 0:yr.roles)==null?void 0:Er.trim())==null?void 0:br.split(",").filter(jr=>jr).map(jr=>jr.trim()))],email:yr.email,name:yr.name,foreignId:yr.foreignId};fr!=null&&fr.id&&(fr==null?void 0:fr.id)!="new"?await((_r=cr.client)==null?void 0:_r.entity.user.update(cr.entity.id,fr.id,Mr)):await((xr=cr.client)==null?void 0:xr.entity.user.create(cr.entity.id,Mr)),sr(void 0),Q$1("User Saved!",{type:"success"}),cr.refresh()}),children:[jsxs("div",{className:"mercoa-mt-2 mercoa-w-96",children:[jsx("label",{htmlFor:"email",className:"mercoa-block mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Email"}),jsx("div",{className:"mercoa-mt-1",children:jsx("input",{...hr("email",{required:!0}),type:"text",placeholder:"person@yourcustomer.com",className:"mercoa-w-full mercoa-border mercoa-border-gray-300 mercoa-rounded-md mercoa-shadow-sm focus:mercoa-ring-indigo-500 focus:mercoa-border-indigo-500 sm:mercoa-text-sm"})})]}),jsxs("div",{className:"mercoa-mt-2",children:[jsx("label",{htmlFor:"name",className:"mercoa-block mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Name"}),jsx("div",{className:"mercoa-mt-1",children:jsx("input",{...hr("name",{required:!0}),type:"text",placeholder:"Your User's Full Name",className:"mercoa-w-full mercoa-border mercoa-border-gray-300 mercoa-rounded-md mercoa-shadow-sm focus:mercoa-ring-indigo-500 focus:mercoa-border-indigo-500 sm:mercoa-text-sm"})})]}),jsxs("div",{className:"mercoa-mt-2",children:[jsx("label",{htmlFor:"roles",className:"mercoa-block mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Roles"}),jsxs("div",{className:"mercoa-mt-1 mercoa-flex mercoa-items-center mercoa-gap-x-1",children:[jsx("div",{className:"mercoa-flex-grow",children:jsx(MercoaCombobox,{options:or.map(yr=>({disabled:!1,value:yr})),onChange:yr=>{yr.length!=0&&dr("roles",yr.filter(Mr=>Mr).join(","),{shouldDirty:!0})},value:mr("roles").split(","),multiple:!0})}),jsxs("button",{className:"mercoa-mt-1",onClick:()=>{const yr=prompt("Create a new role");yr&&ar([...or,yr])},children:[" ",jsxs(Tooltip,{title:"Create a new role",children:[jsx(PlusCircleIcon$1,{className:"mercoa-h-6 mercoa-w-6 mercoa-text-gray-400"})," "]})]})]})]}),jsxs("div",{className:"mercoa-mt-2",children:[jsx("label",{htmlFor:"foreignId",className:"mercoa-block mercoa-text-sm mercoa-font-medium mercoa-text-gray-700",children:"Foreign ID"}),jsx("div",{className:"mercoa-mt-1",children:jsx("input",{...hr("foreignId",{required:!0}),type:"text",placeholder:"The ID of the user in your system",className:"mercoa-w-full mercoa-border mercoa-border-gray-300 mercoa-rounded-md mercoa-shadow-sm focus:mercoa-ring-indigo-500 focus:mercoa-border-indigo-500 sm:mercoa-text-sm"})})]}),jsx(MercoaButton,{isEmphasized:!0,color:"green",className:"mercoa-mt-5 mercoa-w-full",children:"Save"})]})}return jsxs(Fragment,{children:[jsx("div",{className:"mercoa-rounded-md mercoa-bg-gray-100 mercoa-p-8",children:jsxs("ul",{role:"list",className:"mercoa-divide-y mercoa-divide-gray-100 mercoa-overflow-hidden mercoa-bg-white mercoa-shadow-sm mercoa-ring-1 mercoa-ring-gray-900/5 sm:mercoa-rounded-xl",children:[te==null?void 0:te.map((fr,hr)=>{var pr,dr,mr,yr,Mr,Sr,Er;return jsx("li",{onClick:()=>sr(fr),className:"mercoa-relative mercoa-flex mercoa-gap-x-6 mercoa-px-4 mercoa-py-5 hover:mercoa-bg-gray-50 sm:mercoa-px-6 mercoa-cursor-pointer ",children:jsxs("div",{className:"mercoa-flex mercoa-gap-x-4 mercoa-w-full",children:[jsx("div",{className:"mercoa-flex mercoa-justify-left",children:jsx("span",{className:"mercoa-inline-flex mercoa-h-16 mercoa-w-16 mercoa-items-center mercoa-justify-center mercoa-rounded-full mercoa-bg-gray-500",children:jsxs("span",{className:"mercoa-mt-0.5 mercoa-text-xl mercoa-font-medium mercoa-leading-none mercoa-text-white",children:[((pr=fr.name)==null?void 0:pr.charAt(0))??"N/A",((yr=(mr=(dr=fr.name)==null?void 0:dr.split(" "))==null?void 0:mr[1])==null?void 0:yr.charAt(0))??""]})})}),jsxs("div",{children:[jsx("p",{className:"mercoa-text-sm mercoa-font-semibold mercoa-leading-6 mercoa-text-gray-900",children:jsx("a",{children:fr.name})}),jsx("p",{className:"mercoa-mt-1 mercoa-flex mercoa-text-xs mercoa-leading-5 mercoa-text-gray-600",children:fr.email}),jsx("p",{className:"mercoa-mt-1 mercoa-flex mercoa-text-xs mercoa-leading-5 mercoa-text-gray-500",children:fr.id})]}),jsx("div",{className:"mercoa-flex mercoa-items-center mercoa-gap-x-2 grow",children:(Mr=fr==null?void 0:fr.roles)==null?void 0:Mr.map(br=>jsx("span",{className:"mercoa-inline-flex mercoa-items-center mercoa-px-2.5 mercoa-py-0.5 mercoa-rounded-full mercoa-text-xs mercoa-font-medium mercoa-bg-green-100 mercoa-text-green-800",children:br},br))}),jsx("div",{className:"mercoa-flex mercoa-items-center mercoa-rounded-md mercoa-p-2 hover:mercoa-bg-gray-200",onClick:br=>{var _r;br.preventDefault(),br.stopPropagation(),ee&&((_r=cr.entity)!=null&&_r.id)&&fr.id&&ee({entityId:cr.entity.id,userId:fr.id})},children:re[fr.id]&&jsxs("div",{className:"mercoa-flex mercoa-flex-col mercoa-items-center mercoa-gap-y-2",children:[(Sr=re[fr.id])!=null&&Sr.every(br=>br.disabled)?jsx("span",{className:"mercoa-inline-flex mercoa-items-center mercoa-px-2.5 mercoa-py-0.5 mercoa-rounded-full mercoa-text-xs mercoa-font-medium mercoa-bg-red-100 mercoa-text-red-800",children:"Notifications Disabled"}):jsx("span",{className:"mercoa-inline-flex mercoa-items-center mercoa-px-2.5 mercoa-py-0.5 mercoa-rounded-full mercoa-text-xs mercoa-font-medium mercoa-bg-green-100 mercoa-text-green-800",children:"Notifications Enabled"}),((Er=re[fr.id])==null?void 0:Er.every(br=>br.digest))&&jsx("span",{className:"mercoa-inline-flex mercoa-items-center mercoa-px-2.5 mercoa-py-0.5 mercoa-rounded-full mercoa-text-xs mercoa-font-medium mercoa-bg-blue-100 mercoa-text-blue-800",children:"Daily Digest Enabled"})]})}),jsxs("div",{className:"mercoa-flex mercoa-gap-3",children:[jsx("button",{onMouseOver:br=>{var _r,xr,jr;!((_r=cr.entity)!=null&&_r.id)||!fr.id||(jr=cr.client)==null||jr.entity.user.notificationPolicy.getAll((xr=cr.entity)==null?void 0:xr.id,fr.id).then(wr=>{wr&&nr(Ir=>({...Ir,[fr.id]:wr}))})},onClick:br=>{var _r;br.preventDefault(),br.stopPropagation(),ee&&((_r=cr.entity)!=null&&_r.id)&&fr.id&&ee({entityId:cr.entity.id,userId:fr.id})},children:jsx(EnvelopeIcon$1,{className:"mercoa-p-2 mercoa-rounded-xl mercoa-h-10 mercoa-w-10 mercoa-text-gray-400 hover:mercoa-text-gray-500 hover:mercoa-bg-gray-200"})}),jsx("button",{onClick:async br=>{var _r,xr;if(br.preventDefault(),br.stopPropagation(),confirm("Are you sure you want to delete this user?")){if(!((_r=cr.entity)!=null&&_r.id))return;if(fr!=null&&fr.id&&(fr==null?void 0:fr.id)!="new")try{await((xr=cr.client)==null?void 0:xr.entity.user.delete(cr.entity.id,fr.id))}catch(jr){Q$1.error(jr.body);return}cr.refresh()}},children:jsx(TrashIcon$1,{className:"mercoa-p-2 mercoa-rounded-xl mercoa-h-10 mercoa-w-10 mercoa-text-gray-400 hover:mercoa-text-gray-500 hover:mercoa-bg-gray-200"})})]})]})},(fr==null?void 0:fr.id)??hr)}),jsxs("li",{className:"mercoa-relative mercoa-flex mercoa-gap-x-6 mercoa-px-4 mercoa-py-5 hover:mercoa-bg-gray-50 sm:mercoa-px-6 mercoa-cursor-pointer mercoa-items-center mercoa-justify-center mercoa-align-center",onClick:()=>{sr({id:"",roles:[""],email:"",name:"",foreignId:"",createdAt:new Date,updatedAt:new Date})},children:[jsx(PlusCircleIcon$1,{className:"mercoa-h-6 mercoa-w-6 mercoa-text-gray-400"}),jsx("div",{className:"mercoa-text-sm mercoa-font-semibold mercoa-leading-6 mercoa-text-gray-900",children:"Add User"})]})]})}),jsx(tt$1.Root,{show:!!ir,as:React$1.Fragment,children:jsxs(_t$1,{as:"div",className:"mercoa-relative mercoa-z-10",onClose:()=>sr(void 0),children:[jsx(tt$1.Child,{as:React$1.Fragment,enter:"mercoa-ease-out mercoa-duration-300",enterFrom:"mercoa-opacity-0",enterTo:"mercoa-opacity-100",leave:"mercoa-ease-in mercoa-duration-200",leaveFrom:"mercoa-opacity-100",leaveTo:"mercoa-opacity-0",children:jsx("div",{className:"mercoa-fixed mercoa-inset-0 mercoa-bg-gray-500 mercoa-bg-mercoa-opacity-75 mercoa-transition-opacity"})}),jsx("div",{className:"mercoa-fixed mercoa-inset-0 mercoa-z-10 mercoa-overflow-y-auto",children:jsx("div",{className:"mercoa-flex mercoa-min-h-full mercoa-items-end mercoa-justify-center mercoa-p-4 mercoa-text-center sm:mercoa-items-center sm:mercoa-p-0",children:jsx(tt$1.Child,{as:React$1.Fragment,enter:"mercoa-ease-out mercoa-duration-300",enterFrom:"mercoa-opacity-0 mercoa-translate-y-4 sm:mercoa-translate-y-0 sm:mercoa-scale-95",enterTo:"mercoa-opacity-100 mercoa-translate-y-0 sm:mercoa-scale-100",leave:"mercoa-ease-in mercoa-duration-200",leaveFrom:"mercoa-opacity-100 mercoa-translate-y-0 sm:mercoa-scale-100",leaveTo:"mercoa-opacity-0 mercoa-translate-y-4 sm:mercoa-translate-y-0 sm:mercoa-scale-95",children:jsx(_t$1.Panel,{className:"mercoa-relative mercoa-transform mercoa-rounded-lg mercoa-bg-white mercoa-px-4 mercoa-pt-5 mercoa-pb-4 mercoa-text-left mercoa-shadow-xl mercoa-transition-all sm:mercoa-my-8 sm:mercoa-max-w-lg sm:mercoa-p-6",children:ir&&jsx(lr,{user:ir})})})})})]})})]})}pdfjs$1.GlobalWorkerOptions.workerSrc=`//unpkg.com/pdfjs-dist@${pdfjs$1.version}/build/pdf.worker.min.js`,dayjs$1.extend(utc);function ReceivablesTable({search:ee,onClick:te}){const ce=useMercoaSession(),[re,nr]=React$1.useState(),[or,ar]=React$1.useState(javascript.Mercoa.InvoiceOrderByField.CreatedAt),[ir,sr]=React$1.useState(javascript.Mercoa.OrderDirection.Asc),[cr,lr]=React$1.useState(!0),[ur,fr]=React$1.useState(0),[hr,pr]=React$1.useState(!1),[dr,mr]=React$1.useState([]),[yr,Mr]=React$1.useState(20),[Sr,Er]=React$1.useState(1);return React$1.useEffect(()=>{var br,_r;!ce.token||!((br=ce.entity)!=null&&br.id)||(_r=ce.client)==null||_r.entity.invoice.find(ce.entity.id,{search:ee,orderBy:or,orderDirection:ir,limit:yr,startingAfter:dr[dr.length-1],excludePayables:!0}).then(xr=>{xr&&(lr(xr.hasMore),fr(xr.count),nr(xr.data),pr(!0))})},[ce.token,ce.entity,ce.refreshId,ee,or,ir,dr,yr]),hr?jsx(Fragment,{children:ce.entity&&re?jsxs(Fragment,{children:[jsx("div",{className:"mercoa-min-h-[600px]",children:jsxs("table",{className:"mercoa-min-w-full mercoa-divide-y mercoa-divide-gray-300 mercoa-mt-5",children:[jsx("thead",{children:jsxs("tr",{children:[jsx("th",{scope:"col",className:"mercoa-py-3.5 mercoa-pl-4 mercoa-pr-3 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 sm:mercoa-pl-3",children:jsx(TableOrderHeader,{title:"Payer",setOrder:br=>{ar(javascript.Mercoa.InvoiceOrderByField.PayerName),sr(br)},isSelected:or===javascript.Mercoa.InvoiceOrderByField.PayerName,orderDirection:ir})}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 mercoa-hidden sm:mercoa-table-cell",children:jsx(TableOrderHeader,{title:"Invoice Number",setOrder:br=>{ar(javascript.Mercoa.InvoiceOrderByField.InvoiceNumber),sr(br)},isSelected:or===javascript.Mercoa.InvoiceOrderByField.InvoiceNumber,orderDirection:ir})}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900",children:jsx(TableOrderHeader,{title:"Due Date",setOrder:br=>{ar(javascript.Mercoa.InvoiceOrderByField.DueDate),sr(br)},isSelected:or===javascript.Mercoa.InvoiceOrderByField.DueDate,orderDirection:ir})}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900",children:jsx(TableOrderHeader,{title:"Amount",setOrder:br=>{ar(javascript.Mercoa.InvoiceOrderByField.Amount),sr(br)},isSelected:or===javascript.Mercoa.InvoiceOrderByField.Amount,orderDirection:ir})}),jsx("th",{scope:"col",className:"mercoa-px-3 mercoa-py-3.5 mercoa-text-left mercoa-text-sm mercoa-font-semibold mercoa-text-gray-900 mercoa-pl-6 mercoa-hidden lg:mercoa-table-cell",children:"Status"})]})}),jsx("tbody",{className:"mercoa-divide-y mercoa-divide-gray-200 mercoa-bg-white",children:re.map(br=>{var _r;return jsxs("tr",{className:"mercoa-cursor-pointer hover:mercoa-bg-gray-100",onClick:()=>{te&&te(br)},children:[jsx("td",{className:"mercoa-whitespace-nowrap mercoa-py-3 mercoa-pl-4 mercoa-pr-3 mercoa-text-sm mercoa-font-medium mercoa-text-gray-900 sm:mercoa-pl-3",children:(_r=br.payer)==null?void 0:_r.name}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-3 mercoa-text-sm mercoa-text-gray-900 mercoa-hidden sm:mercoa-table-cell",children:br.invoiceNumber}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-3 mercoa-text-sm mercoa-text-gray-900",children:dayjs$1(br.dueDate).format("MMM DD, YYYY")}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-3 mercoa-text-sm mercoa-text-gray-900",children:accounting.formatMoney(br.amount??"",currencyCodeToSymbol(br.currency))}),jsx("td",{className:"mercoa-whitespace-nowrap mercoa-px-3 mercoa-py-3 mercoa-text-sm mercoa-hidden lg:mercoa-table-cell",children:br.status})]},br.id)})})]})}),jsx(TableNavigation,{data:re,page:Sr,setPage:Er,hasMore:cr,startingAfter:dr,setStartingAfter:mr,count:ur,resultsPerPage:yr,setResultsPerPage:Mr})]}):jsx(LoadingSpinner,{})}):jsx("div",{className:"mercoa-mt-7",children:jsx(Skeleton,{rows:10})})}function Receivables({onSelectInvoice:ee}){const te=useMercoaSession(),[ce,re]=React$1.useState(""),[nr,or]=React$1.useState([]);function ar(sr){return sr.reduce((cr,lr)=>(cr+=lr.totalCount,cr),0)}function ir(sr,cr){return!sr||sr.length<1?accounting.formatMoney(0,currencyCodeToSymbol("USD")):sr.length<2?accounting.formatMoney(sr[0][cr]??0??"",currencyCodeToSymbol(sr[0].currency)):jsx("div",{children:sr.map(lr=>jsxs("p",{children:[jsx("span",{children:accounting.formatMoney(lr[cr]??0??"",currencyCodeToSymbol(lr.currency))}),jsxs("span",{className:"mercoa-text-gray-500 mercoa-text-xs",children:[" ",lr.currency]})]},lr.currency))})}return React$1.useEffect(()=>{var sr,cr;!te.token||!((sr=te.entity)!=null&&sr.id)||(cr=te.client)==null||cr.entity.invoice.metrics(te.entity.id,{search:ce,excludePayables:!0}).then(lr=>{or(lr)})},[ce,te.client,te.entity,te.refreshId]),jsxs("div",{className:"mercoa-mt-8",children:[jsxs("div",{className:"mercoa-grid mercoa-items-center mercoa-grid-cols-3",children:[jsx("div",{className:"mercoa-hidden md:mercoa-block md:mercoa-col-span-2"}),jsx("div",{className:"mercoa-mt-2 mercoa-flex mercoa-w-full mercoa-rounded-md mercoa-shadow-sm mercoa-mr-2 mercoa-col-span-3 md:mercoa-col-span-1",children:jsx(DebouncedSearch,{placeholder:"Search Payers",onSettle:re})})]}),jsxs("div",{className:"mercoa-grid mercoa-grid-cols-3 mercoa-space-x-3 mercoa-mt-2",children:[jsx(StatCard,{size:"sm",title:"Total Invoices",value:ar(nr)??0}),jsx(StatCard,{size:"sm",title:"Total Amount",value:ir(nr,"totalAmount")}),jsx(StatCard,{size:"sm",title:"Average Amount",value:ir(nr,"averageAmount")})]}),jsx(ReceivablesTable,{search:ce,onClick:ee})]})}exports.AcceptToSButton=AcceptToSButton,exports.AcceptTosForm=AcceptTosForm,exports.AccountTypeRadioBlock=AccountTypeRadioBlock,exports.AccountTypeSelectBlock=AccountTypeSelectBlock,exports.AddBankAccount=AddBankAccount,exports.AddBankAccountForm=AddBankAccountForm,exports.AddBankViaPlaidOrManual=AddBankViaPlaidOrManual,exports.AddCheck=AddCheck,exports.AddCheckForm=AddCheckForm,exports.AddCounterpartyModal=AddCounterpartyModal,exports.AddCustomPaymentMethod=AddCustomPaymentMethod,exports.AddCustomPaymentMethodForm=AddCustomPaymentMethodForm,exports.AddDialog=AddDialog,exports.AddressBlock=AddressBlock,exports.ApprovalPolicies=ApprovalPolicies,exports.BankAccountComponent=BankAccountComponent,exports.BankAccounts=BankAccounts,exports.BusinessTypeBlock=BusinessTypeBlock,exports.CheckComponent=CheckComponent,exports.Counterparties=Counterparties,exports.CounterpartyDetails=CounterpartyDetails,exports.CounterpartySearch=CounterpartySearch,exports.CustomPaymentMethod=CustomPaymentMethod,exports.CustomPaymentMethodComponent=CustomPaymentMethodComponent,exports.DateOfBirthBlock=DateOfBirthBlock,exports.DebouncedSearch=DebouncedSearch,exports.DefaultPaymentMethodIndicator=DefaultPaymentMethodIndicator,exports.DescriptionBlock=DescriptionBlock,exports.DoingBusinessAsBlock=DoingBusinessAsBlock,exports.EINBlock=EINBlock,exports.EditBankAccount=EditBankAccount,exports.EditInvoiceForm=EditInvoiceForm,exports.EmailBlock=EmailBlock,exports.EntityCreation=EntityCreation,exports.EntityDetails=EntityDetails,exports.EntityOnboarding=EntityOnboarding,exports.EntityOnboardingButton=EntityOnboardingButton,exports.EntityPortal=EntityPortal,exports.EntityStatus=EntityStatus,exports.EntityUserNotificationTable=EntityUserNotificationTable,exports.EntityUsersTable=EntityUsersTable,exports.FormationDateBlock=FormationDateBlock,exports.InvoiceComments=InvoiceComments,exports.InvoiceDetails=InvoiceDetails,exports.InvoiceInbox=InvoiceInbox,exports.InvoiceStatusPill=InvoiceStatusPill,exports.LegalBusinessNameBlock=LegalBusinessNameBlock,exports.LoadingSpinner=LoadingSpinner,exports.LoadingSpinnerIcon=LoadingSpinnerIcon,exports.MercoaButton=MercoaButton,exports.MercoaCombobox=MercoaCombobox,exports.MercoaSession=MercoaSession,exports.MetadataSelection=MetadataSelection,exports.NameBlock=NameBlock,exports.PhoneBlock=PhoneBlock,exports.Receivables=Receivables,exports.RepresentativeComponent=RepresentativeComponent,exports.RepresentativeOnboardingForm=RepresentativeOnboardingForm,exports.Representatives=Representatives,exports.SSNBlock=SSNBlock,exports.SSNSchema=SSNSchema,exports.Skeleton=Skeleton,exports.StatCard=StatCard,exports.Switch=Switch,exports.TableNavigation=TableNavigation,exports.TableOrderHeader=TableOrderHeader,exports.TokenVerification=TokenVerification,exports.Tooltip=Tooltip,exports.VerifyOwnersButton=VerifyOwnersButton,exports.WebsiteBlock=WebsiteBlock,exports.accountTypeSchema=accountTypeSchema,exports.addressBlockSchema=addressBlockSchema,exports.createOrUpdateEntity=createOrUpdateEntity,exports.dateOfBirthSchema=dateOfBirthSchema,exports.descriptionSchema=descriptionSchema,exports.doingBusinessAsSchema=doingBusinessAsSchema,exports.einSchema=einSchema,exports.emailSchema=emailSchema,exports.entityDetailsForMercoaPaymentsCompleted=entityDetailsForMercoaPaymentsCompleted,exports.findCustomPaymentMethodAccountNameAndNumber=findCustomPaymentMethodAccountNameAndNumber,exports.formationDateSchema=formationDateSchema,exports.legalBusinessNameSchema=legalBusinessNameSchema,exports.nameBlockSchema=nameBlockSchema,exports.phoneSchema=phoneSchema,exports.useDebounce=useDebounce,exports.useMercoaSession=useMercoaSession,exports.websiteSchema=websiteSchema,Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"})});
|
|
275
275
|
//# sourceMappingURL=index.umd.js.map
|