import{h as s,r as t,c as i}from"./p-CV0Pyo1O.js";import{c as e,F as r}from"./p-D9sqTVmd.js";import{b as o,i as a,a as n,c as h,d as p,e as l,f as m}from"./p-DK_bjvk1.js";import"./p-DVJaoI_m.js";import"./p-HXpYMWUU.js";import{C as c,b as d}from"./p-DaIKrQry.js";import"./p-CLHwhyvu.js";import{C as j,B as u,b as v}from"./p-BcNb9bVO.js";import{J as b}from"./p-Bw3Rgnjn.js";import{B as f}from"./p-CHo7TfsM.js";import{S as w}from"./p-DzEdYT8R.js";import{H as g}from"./p-jIDKmNHy.js";import"./p-CZfYo5-1.js";import{c as C}from"./p-Bo7v8x6H.js";import{S as y}from"./p-uZ5KAseb.js";import{B}from"./p-XYgDHrVL.js";import{m as x,a as D}from"./p-B6ZYciEI.js";import{B as _}from"./p-s8KSaX8d.js";import"./p-BFTU3MAI.js";import"./p-BxpXvXn-.js";import"./p-DPA5TKvQ.js";import"./p-BBSnDYJw.js";import"./p-D8GTwl9v.js";import"./p-BXrbGZ_R.js";import"./p-CqcLgdsl.js";import"./p-C2jRLMNW.js";import"./p-CPKMvyV_.js";import"./p-Cb8cfh-k.js";const O=e(Object.assign(Object.assign({},o().fields),{legal_address:h(),additional_questions:n(),representative:a("representative")}));e(Object.assign(Object.assign({},p().fields),{legal_address:m(),additional_questions:n(),representative:l("representative")}));const S=O,k=()=>s("div",{class:"row gap-3"},s("div",{class:"col-12"},s(y,{width:"25%"})),s("div",{class:"col-12"},s(y,{width:"100%"})),s("div",{class:"col-12 d-flex gap-3"},s(y,{width:"50%"}),s(y,{width:"50%"})),s("div",{class:"col-12 d-flex gap-3"},s(y,{width:"65%"}),s(y,{width:"35%"}))),I=()=>s("div",{class:"row gap-5"},s("div",{class:"col-12"},s(y,{width:"40%",height:"40px"})),s(k,null),s(k,null),s(k,null)),T=class{constructor(s){t(this,s),this.submitEvent=i(this,"submit-event",7),this.clickEvent=i(this,"click-event",7),this.errorEvent=i(this,"error-event",7),this.isLoading=!1,this.isSaving=!1,this.country=j.USA,this.hideErrors=!1,this.formTitle="Business Information",this.removeTitle=!1,this.instantiateBusiness=s=>{const t=new u(s);this.country=t.country_of_establishment,this.formController.setInitialValues(Object.assign({},t))},this.sendData=async()=>{this.isSaving=!0;const s=this.formController.values.getValue(),t=this.formController.getInitialValues(),i=new u(Object.assign(Object.assign({},t),s)).payload;this.patchBusiness({payload:i,onSuccess:s=>{this.handleReponse(s)},onError:({error:s,code:t,severity:i})=>{this.errorMessage=s.message,this.errorEvent.emit({errorCode:t,message:s.message,severity:i})},final:()=>{this.isSaving=!1}})},this.validateAndSubmit=s=>{s.preventDefault(),this.formController.validateAndSubmit(this.sendData)}}componentWillLoad(){C(),this.analytics=new b(this),this.formController=new r(S),this.initializeApi()}disconnectedCallback(){var s;null===(s=this.analytics)||void 0===s||s.cleanup()}get title(){return this.removeTitle?"":this.formTitle}get disabledState(){return this.isSaving}get businessEndpoint(){return`entities/business/${this.businessId}`}initializeApi(){this.authToken&&this.businessId?(this.getBusiness=x({authToken:this.authToken,businessId:this.businessId,service:new _}),this.patchBusiness=D({authToken:this.authToken,businessId:this.businessId,service:new _}),this.getBusiness({onSuccess:s=>{this.instantiateBusiness(s.data)},onError:({error:s,code:t,severity:i})=>{this.errorMessage=s.message,this.errorEvent.emit({errorCode:t,message:s.message,severity:i})},final:()=>{this.isLoading=!1}})):this.errorEvent.emit({message:"auth-token and business-id are required",errorCode:d.MISSING_PROPS,severity:c.ERROR})}handleReponse(s){s.error&&(this.errorMessage=v.patchData),this.submitEvent.emit({response:s}),this.instantiateBusiness(s.data)}render(){return s(w,null,this.isLoading?s(I,null):s("form",{onSubmit:this.validateAndSubmit},s("div",{class:"row gap-3"},s(g,{text:this.title}),s("form-alert",{text:this.errorMessage,hideAlert:this.hideErrors}),s("div",{class:"col-12 mb-4"},s("business-core-info",{formController:this.formController,country:this.country})),s("div",{class:"col-12 mb-4"},s("legal-address-form",{formController:this.formController,country:this.country})),s("div",{class:"col-12 mb-4"},s("additional-questions",{formController:this.formController})),s("div",{class:"col-12 mb-4"},s("business-representative",{formController:this.formController,country:this.country})),s("div",{class:"col-12 d-flex flex-row-reverse"},s(f,{type:"submit",disabled:this.disabledState,variant:"primary",onClick:()=>this.clickEvent.emit({name:B.submit}),isLoading:this.isSaving},"Submit")))))}};export{T as justifi_business_form}