@vpdev2/metakyc-sdk 1.0.103 → 1.0.105
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/components/identity/IdentityVerificationStep.d.ts.map +1 -1
- package/dist/index.cjs +5 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2248 -2252
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Wr=Object.defineProperty;var Ur=(t,r,s)=>r in t?Wr(t,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[r]=s;var ue=(t,r,s)=>Ur(t,typeof r!="symbol"?r+"":r,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Kr=require("axios"),o=require("react"),e=require("react/jsx-runtime"),ut=require("react-dom"),Ue=require("react-hook-form"),$e=require("zod");function qr(t){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(r,s,n.get?n:{enumerable:!0,get:()=>t[s]})}}return r.default=t,Object.freeze(r)}const jt=qr(o);var ae=(t=>(t[t.IdentitySdk=0]="IdentitySdk",t[t.RiskScoring=1]="RiskScoring",t[t.Questionaries=2]="Questionaries",t[t.AdditionalData=3]="AdditionalData",t[t.AppropriatenessTest=4]="AppropriatenessTest",t[t.UploadDocument=5]="UploadDocument",t[t.ManualReview=6]="ManualReview",t[t.Overview=7]="Overview",t[t.InvestorCategorization=8]="InvestorCategorization",t))(ae||{}),it=(t=>(t[t.NotStarted=0]="NotStarted",t[t.InProgress=1]="InProgress",t[t.Success=2]="Success",t[t.PartialSuccess=3]="PartialSuccess",t[t.Failed=4]="Failed",t[t.Skipped=5]="Skipped",t[t.AdminReview=6]="AdminReview",t[t.SkippedAndAdminReview=7]="SkippedAndAdminReview",t))(it||{}),Ae=(t=>(t[t.None=0]="None",t[t.InProgress=1]="InProgress",t[t.Finished=2]="Finished",t[t.OnHold=3]="OnHold",t[t.IdentityPending=4]="IdentityPending",t))(Ae||{}),Et=(t=>(t[t.None=0]="None",t[t.RepresentativeKYC=1]="RepresentativeKYC",t[t.ManualRiskCriteria=2]="ManualRiskCriteria",t[t.UploadDocumentReview=3]="UploadDocumentReview",t[t.AdminReview=4]="AdminReview",t))(Et||{}),At=(t=>(t[t.LowRisk=0]="LowRisk",t[t.MediumRisk=1]="MediumRisk",t[t.HighRisk=2]="HighRisk",t[t.Alert=3]="Alert",t))(At||{}),Ke=(t=>(t[t.None=0]="None",t[t.Pending=1]="Pending",t[t.Approved=2]="Approved",t[t.Rejected=3]="Rejected",t[t.ResendRequested=4]="ResendRequested",t[t.Unknown=5]="Unknown",t[t.InProgress=6]="InProgress",t))(Ke||{}),qe=(t=>(t[t.Approved=0]="Approved",t[t.Reject=1]="Reject",t[t.UnderReview=2]="UnderReview",t[t.Closed=3]="Closed",t[t.AdminReview=4]="AdminReview",t[t.New=5]="New",t[t.InProgress=6]="InProgress",t))(qe||{}),Ft=(t=>(t[t.ProviderResultPending=0]="ProviderResultPending",t[t.ProviderResultReceived=1]="ProviderResultReceived",t[t.Canceled=2]="Canceled",t[t.ExtendedToNewApplicant=3]="ExtendedToNewApplicant",t))(Ft||{}),Tt=(t=>(t[t.None=0]="None",t[t.ProviderResultPending=1]="ProviderResultPending",t[t.ProviderResultReceived=2]="ProviderResultReceived",t[t.Canceled=3]="Canceled",t))(Tt||{}),Ee=(t=>(t[t.Onfido=0]="Onfido",t[t.Sumsub=2]="Sumsub",t[t.SardinAI=3]="SardinAI",t))(Ee||{}),Pt=(t=>(t[t.Individual=0]="Individual",t[t.Company=1]="Company",t))(Pt||{}),ot=(t=>(t[t.Male=0]="Male",t[t.Female=1]="Female",t[t.Other=2]="Other",t))(ot||{}),Lt=(t=>(t[t.Image=0]="Image",t[t.Video=1]="Video",t[t.PDF=2]="PDF",t[t.OfficePDF=3]="OfficePDF",t[t.Custom=4]="Custom",t))(Lt||{}),Dt=(t=>(t[t.Pending=0]="Pending",t[t.Approved=1]="Approved",t[t.Rejected=2]="Rejected",t[t.RequiresRevision=3]="RequiresRevision",t))(Dt||{}),Mt=(t=>(t[t.SingleChoice=0]="SingleChoice",t[t.MultipleChoice=1]="MultipleChoice",t[t.Text=2]="Text",t))(Mt||{}),Le=(t=>(t[t.String=0]="String",t[t.Integer=1]="Integer",t[t.Money=2]="Money",t[t.Boolean=3]="Boolean",t[t.Date=4]="Date",t[t.Country=5]="Country",t[t.DigitOnly=6]="DigitOnly",t))(Le||{}),Ot=(t=>(t[t.Text=0]="Text",t[t.Radio=1]="Radio",t[t.Checkbox=2]="Checkbox",t[t.Dropdown=3]="Dropdown",t[t.Country=4]="Country",t))(Ot||{}),zt=(t=>(t[t.None=0]="None",t[t.Country=1]="Country",t))(zt||{}),ke=(t=>(t[t.Individual=0]="Individual",t[t.Sophisticated=1]="Sophisticated",t[t.HighNetWorth=2]="HighNetWorth",t[t.Business=3]="Business",t))(ke||{}),Bt=(t=>(t[t.Retail=0]="Retail",t[t.Professional=1]="Professional",t[t.EligibleCounterparty=2]="EligibleCounterparty",t))(Bt||{});const _e={Nationality:10,Address:20,CountryOfBirth:30,PhoneNumber:40,UboAddress:50},Ve={firstName:{label:"First Name",type:"text"},lastName:{label:"Last Name",type:"text"},email:{label:"Email",type:"email"},phonenumber:{label:"Phone Number",type:"tel"},dateOfBirth:{label:"Date of Birth",type:"date"},salutation:{label:"Salutation",type:"select"},title:{label:"Title",type:"text"},mobileCountryCode:{label:"Mobile Country Code",type:"select",countriesType:_e.PhoneNumber},street:{label:"Street",type:"text"},streetNumber:{label:"Street Number",type:"text"},zip:{label:"ZIP / Postal Code",type:"text"},city:{label:"City",type:"text"},country:{label:"Country",type:"select",countriesType:_e.Address},nationality:{label:"Nationality",type:"select",countriesType:_e.Nationality},otherNationality:{label:"Other Nationalities",type:"multiselect",countriesType:_e.Nationality},countryOfBirth:{label:"Country of Birth",type:"select",countriesType:_e.CountryOfBirth},placeOfBirth:{label:"Place of Birth",type:"text"},taxCountry:{label:"Tax Country",type:"select",countriesType:_e.Address},taxNumber:{label:"Tax Number",type:"text"},defaultLanguage:{label:"Default Language",type:"select"},educationLevel:{label:"Education Level",type:"text"},occupation:{label:"Occupation",type:"text"}},Ge={companyName:{label:"Company Name",type:"text"},email:{label:"Email",type:"email"},phone:{label:"Phone",type:"tel"},registrationNumber:{label:"Registration Number",type:"text"},countryResidence:{label:"Country of Residence",type:"select",countriesType:_e.Address},legalAddress:{label:"Legal Address",type:"text"},incorporatedOn:{label:"Incorporation Date",type:"date"},controlScheme:{label:"Control Scheme",type:"text"},taxId:{label:"Tax ID",type:"text"},registrationLocation:{label:"Registration Location",type:"text"},website:{label:"Website",type:"text"},postalAddress:{label:"Postal Address",type:"text"},street:{label:"Street",type:"text"},streetNumber:{label:"Street Number",type:"text"},city:{label:"City",type:"text"},state:{label:"State / Province",type:"text"},postalCode:{label:"Postal Code",type:"text"},addressCountry:{label:"Address Country",type:"select",countriesType:_e.Address},lei:{label:"LEI",type:"text"}},_t=["companyName","email","phone","registrationNumber"],$t=["firstName","lastName","email","phonenumber","dateOfBirth"],xt=[{value:"EN",label:"English"},{value:"DE",label:"German"},{value:"FR",label:"French"},{value:"ES",label:"Spanish"},{value:"IT",label:"Italian"},{value:"PT",label:"Portuguese"},{value:"NL",label:"Dutch"},{value:"PL",label:"Polish"},{value:"RU",label:"Russian"},{value:"ZH",label:"Chinese"},{value:"JA",label:"Japanese"},{value:"AR",label:"Arabic"},{value:"TR",label:"Turkish"},{value:"SV",label:"Swedish"},{value:"DA",label:"Danish"},{value:"FI",label:"Finnish"},{value:"NO",label:"Norwegian"}];var je=(t=>(t.Default="default",t.Corporate="corporate",t.Fintech="fintech",t.Healthcare="healthcare",t.Modern="modern",t.Minimal="minimal",t))(je||{});const Ht={timeout:3e4,retries:3,locale:"en",endpoints:{pattern:"host-controller"}};class Wt{constructor(r){this.config=r}build(r,s){const n=`${r}.${s}`;if(this.config.customPaths&&this.config.customPaths[n])return this.config.customPaths[n];switch(this.config.pattern){case"host-controller":return`/api/${r}/${s}`;case"application-service":return`/services/app/${this.getServiceName(r)}/${s}`;case"custom":throw new Error(`Custom endpoint path not found for ${n}. Please provide it in customPaths.`);default:throw new Error(`Unknown endpoint pattern: ${this.config.pattern}`)}}getServiceName(r){return{Applicant:"MetaKYCVerification",Questionnaire:"MetaKYCVerification",UploadDocument:"MetaKYCVerification",AppropriatenessTest:"MetaKYCVerification",BaseInformation:"MetaKYCVerification"}[r]||r}}class Pe extends Error{constructor(s,n,i,l,c){super(s);ue(this,"response");this.code=n,this.details=i,this.validationErrors=l,this.name="MetaKYCError",this.response=c,Object.setPrototypeOf(this,Pe.prototype)}}class tt{static handleApiError(r){return new Pe(r.message||"An unknown error occurred",r.code,r.details||void 0,r.validationErrors||void 0)}static handleAxiosError(r){if(r.response){const s=r.response.data;return s&&s.error?new Pe(s.error.message||"An unknown error occurred",s.error.code,s.error.details||void 0,s.error.validationErrors||void 0,r.response):s&&s.result&&s.result.message?new Pe(s.result.message,r.response.status,`HTTP ${r.response.status}: ${r.response.statusText}`,void 0,r.response):new Pe((s==null?void 0:s.message)||r.message||"Request failed",r.response.status,`HTTP ${r.response.status}: ${r.response.statusText}`,void 0,r.response)}else return r.request?new Pe("No response from server",0,"The request was made but no response was received. Please check your network connection."):new Pe(r.message||"An unexpected error occurred",0,r.toString())}static isMetaKYCError(r){return r instanceof Pe}}class Ut{constructor(r){ue(this,"axiosInstance");ue(this,"endpointBuilder");ue(this,"config");this.config={...Ht,...r},this.endpointBuilder=new Wt(this.config.endpoints),this.axiosInstance=Kr.create({baseURL:this.config.baseUrl,timeout:this.config.timeout,headers:{"Content-Type":"application/json"}}),this.axiosInstance.interceptors.request.use(s=>(s.headers["Abp-TenantId"]=this.config.tenantId.toString(),s.headers.ApiKey=this.config.apiKey,s.headers["X-API-KEY"]=this.config.apiKey,this.config.locale&&(s.headers["Accept-Language"]=this.config.locale),s),s=>Promise.reject(s)),this.axiosInstance.interceptors.response.use(s=>s,async s=>{var i;const n=s.config;return((i=s.response)==null?void 0:i.status)>=500&&!n._retry&&(n._retry=!0,n._retryCount=(n._retryCount||0)+1,n._retryCount<(this.config.retries||3))?(await new Promise(l=>setTimeout(l,1e3*n._retryCount)),this.axiosInstance(n)):Promise.reject(s)})}buildEndpoint(r,s){return this.endpointBuilder.build(r,s)}async get(r,s,n){try{const i=this.buildEndpoint(r,s),l=await this.axiosInstance.get(i,{params:n});return this.handleResponse(l)}catch(i){throw tt.handleAxiosError(i)}}async post(r,s,n){try{const i=this.buildEndpoint(r,s),l=await this.axiosInstance.post(i,n);return this.handleResponse(l)}catch(i){throw tt.handleAxiosError(i)}}async put(r,s,n){try{const i=this.buildEndpoint(r,s),l=await this.axiosInstance.put(i,n);return this.handleResponse(l)}catch(i){throw tt.handleAxiosError(i)}}async delete(r,s,n){try{const i=this.buildEndpoint(r,s),l=await this.axiosInstance.delete(i,{params:n});return this.handleResponse(l)}catch(i){throw tt.handleAxiosError(i)}}handleResponse(r){const s=r.data;if(!s.success&&s.error)throw tt.handleApiError(s.error);return s}getAxiosInstance(){return this.axiosInstance}}class Kt{constructor(r){this.httpClient=r}async createApplicant(r){return(await this.httpClient.post("Applicant","ApplicantRegistrationRequest",r)).result}async createCompanyApplicant(r){return(await this.httpClient.post("Applicant","ApplicantCompanyRegistrationRequest",r)).result}async duplicateApplicant(r){return(await this.httpClient.post("Applicant","DuplicateApplicantRegistrationRequest",r)).result}async getProgress(r){return(await this.httpClient.get("Applicant","GetApplicantProgress",{applicantId:r})).result}async getProgressStatus(r){return(await this.httpClient.get("Applicant","GetApplicantProgressStaus",{applicantId:r})).result}async getApplicantData(r){return(await this.httpClient.get("Applicant","GetApplicantData",{applicantId:r})).result}async getApplicantStatus(r){return(await this.httpClient.get("Applicant","GetApplicantStatus",{applicantId:r})).result}async stopProgress(r){await this.httpClient.get("Applicant","StopProgress",{applicantId:r})}async progressStepBack(r){await this.httpClient.get("Applicant","ProgressStepBack",{applicantId:r})}async setLanguage(r,s){await this.httpClient.post("Applicant","SetApplicantLng",{applicantId:r,language:s})}async activateApplicant(r){await this.httpClient.get("Applicant","ActivateApplicant",{applicantId:r})}async deleteApplicant(r){await this.httpClient.delete("Applicant","DeleteApplicant",{applicantId:r})}async checkApplicantExists(r){return(await this.httpClient.get("Applicant","CheckApplicantIfExists",{externalRefId:r})).result}}class qt{constructor(r){this.httpClient=r}async getQuestionnaire(r){return(await this.httpClient.get("Questionnaire","GetQuestionnaire",{applicantid:r})).result}async fillQuestionnaire(r){return(await this.httpClient.post("Applicant","FillQuestionnarie",r)).result}}class Vt{constructor(r){this.httpClient=r}async getUploadDocument(r){return(await this.httpClient.get("UploadDocument","GetUploadDocument",{applicantid:r})).result}async fillUploadDocument(r){await this.httpClient.post("Applicant","FillUploadDocument",r)}async reviewUploadDocument(r){await this.httpClient.post("UploadDocument","ReviewUploadDocument",r)}}class Yt{constructor(r){this.httpClient=r}async getAppropriatenessTest(r){return(await this.httpClient.get("AppropriatenessTest","GetAppropriatenessTest",{applicantid:r})).result}async fillAppropriatenessTest(r){return(await this.httpClient.post("Applicant","FillAppropriatenessTest",r)).result}}class Qt{constructor(r){this.httpClient=r}async getOverviewData(r){return(await this.httpClient.get("Applicant","GetOverviewData",{ApplicantId:r})).result}async passOverview(r){await this.httpClient.get("Applicant","PassOverview",{applicantId:r})}}class Gt{constructor(r){this.httpClient=r}async getRiskScoringPlan(){return(await this.httpClient.get("Applicant","GetRiskScoringPlanInfo")).result}async getRiskCriterias(r){return(await this.httpClient.get("Risk","GetCriterias",{applicantId:r})).result}async submitRiskScoring(r){return(await this.httpClient.post("Applicant","RiskScoringRequest",r)).result}}class Jt{constructor(r){this.httpClient=r}async identityRequest(r){console.log("[IdentityService] Calling IdentityRequest with input:",r);const s=await this.httpClient.post("Applicant","IdentityRequest",r);return console.log("[IdentityService] IdentityRequest response:",s),s.result}async identityCompanyRequest(r){return(await this.httpClient.post("Applicant","IdentityCompanyRequest",r)).result}async restartIdentityRequest(r){const s={applicantId:r,restart:!0,redirectUrl:"",ttl:604800};return console.log("[IdentityService] Restarting identity with restart=true:",s),this.identityRequest(s)}async restartIdentityCompanyRequest(r){const s={applicantId:r,restart:!0,redirectUrl:"",ttl:604800};return this.identityCompanyRequest(s)}async refreshSumsubToken(r){console.log("[IdentityService] Refreshing Sumsub token for applicant:",r);const s=await this.httpClient.post("Applicant","RefreshSumsubToken",{applicantId:r});return console.log("[IdentityService] Sumsub token refresh result:",s),s.result.accessToken}}class Zt{constructor(r){this.httpClient=r}async getCountries(r,s,n){return(await this.httpClient.get("BaseInformation","GetAllCountries",{filter:r||"",lng:s||"en",type:n})).result}async getBranches(){return(await this.httpClient.get("BaseInformation","GetBranches")).result}async getLegalEntities(){return(await this.httpClient.get("BaseInformation","GetLegalEntities")).result}}class Xt{constructor(r){this.httpClient=r}async setInvestorCategorization(r){return(await this.httpClient.post("Applicant","SetInvestorCategorization",r)).result}async getInvestorCategorization(r){return(await this.httpClient.get("Applicant","GetInvestorCategorisation",{applicantId:r})).result}}const Ne={name:"Default",title:"KYC Verification",logo:{url:"",height:"40px",visible:!0},colors:{primary:"#2563eb",primaryHover:"#1d4ed8",primaryLight:"#dbeafe",primaryDark:"#1e40af",secondary:"#64748b",secondaryHover:"#475569",success:"#10b981",warning:"#f59e0b",danger:"#ef4444",info:"#3b82f6",background:"#ffffff",surface:"#f9fafb",border:"#e5e7eb",textPrimary:"#111827",textSecondary:"#6b7280",textMuted:"#9ca3af"},typography:{fontFamily:"Inter, system-ui, -apple-system, sans-serif",fontSize:{xs:"0.75rem",sm:"0.875rem",base:"1rem",lg:"1.125rem",xl:"1.25rem","2xl":"1.5rem","3xl":"1.875rem"},fontWeight:{normal:400,medium:500,semibold:600,bold:700}},spacing:{borderRadius:"0.5rem",cardPadding:"1.5rem",inputHeight:"2.5rem"},darkMode:{colors:{background:"#111827",surface:"#1f2937",border:"#374151",textPrimary:"#f9fafb",textSecondary:"#d1d5db",textMuted:"#9ca3af"}}},er={name:"Corporate",logo:{url:"",height:"40px",visible:!0},colors:{primary:"#0052CC",primaryHover:"#0747A6",primaryLight:"#DEEBFF",primaryDark:"#0747A6",secondary:"#6B778C",secondaryHover:"#5E6C84",success:"#00875A",warning:"#FF991F",danger:"#DE350B",info:"#0065FF",background:"#ffffff",surface:"#F4F5F7",border:"#DFE1E6",textPrimary:"#172B4D",textSecondary:"#5E6C84",textMuted:"#97A0AF"},typography:{fontFamily:"system-ui, -apple-system, sans-serif"},spacing:{borderRadius:"0.25rem",cardPadding:"1.5rem",inputHeight:"2.5rem"}},tr={name:"Fintech",logo:{url:"",height:"36px",visible:!0},colors:{primary:"#00B386",primaryHover:"#009973",primaryLight:"#D1FAE5",primaryDark:"#047857",secondary:"#7C3AED",secondaryHover:"#6D28D9",success:"#10B981",warning:"#F59E0B",danger:"#EF4444",info:"#3B82F6",background:"#ffffff",surface:"#F9FAFB",border:"#E5E7EB",textPrimary:"#111827",textSecondary:"#6B7280",textMuted:"#9CA3AF"},typography:{fontFamily:"Montserrat, system-ui, sans-serif"},spacing:{borderRadius:"0.75rem",cardPadding:"2rem",inputHeight:"3rem"}},rr={name:"Healthcare",logo:{url:"",height:"44px",visible:!0},colors:{primary:"#06B6D4",primaryHover:"#0891B2",primaryLight:"#CFFAFE",primaryDark:"#0E7490",secondary:"#8B5CF6",secondaryHover:"#7C3AED",success:"#059669",warning:"#D97706",danger:"#DC2626",info:"#0284C7",background:"#ffffff",surface:"#F0F9FF",border:"#E0F2FE",textPrimary:"#0F172A",textSecondary:"#475569",textMuted:"#94A3B8"},typography:{fontFamily:"Lato, system-ui, sans-serif"},spacing:{borderRadius:"0.5rem",cardPadding:"1.75rem",inputHeight:"2.75rem"},darkMode:{colors:{background:"#0F172A",surface:"#1E293B",border:"#334155",textPrimary:"#F1F5F9",textSecondary:"#CBD5E1"}}},sr={name:"Modern",logo:{url:"",height:"38px",visible:!0},colors:{primary:"#8B5CF6",primaryHover:"#7C3AED",primaryLight:"#EDE9FE",primaryDark:"#6D28D9",secondary:"#EC4899",secondaryHover:"#DB2777",success:"#10B981",warning:"#F59E0B",danger:"#EF4444",info:"#3B82F6",background:"#ffffff",surface:"#FAFAFA",border:"#E5E5E5",textPrimary:"#171717",textSecondary:"#737373",textMuted:"#A3A3A3"},typography:{fontFamily:"Poppins, system-ui, sans-serif"},spacing:{borderRadius:"1rem",cardPadding:"2rem",inputHeight:"3rem"}},nr={name:"Minimal",logo:{url:"",height:"32px",visible:!0},colors:{primary:"#000000",primaryHover:"#18181B",primaryLight:"#F4F4F5",primaryDark:"#000000",secondary:"#71717A",secondaryHover:"#52525B",success:"#22C55E",warning:"#EAB308",danger:"#EF4444",info:"#3B82F6",background:"#ffffff",surface:"#FAFAFA",border:"#E4E4E7",textPrimary:"#09090B",textSecondary:"#71717A",textMuted:"#A1A1AA"},typography:{fontFamily:"system-ui, -apple-system, sans-serif"},spacing:{borderRadius:"0.25rem",cardPadding:"1.25rem",inputHeight:"2.25rem"}},ar={[je.Default]:Ne,[je.Corporate]:er,[je.Fintech]:tr,[je.Healthcare]:rr,[je.Modern]:sr,[je.Minimal]:nr};function rt(t){return ar[t]||Ne}class ir{constructor(r){this.httpClient=r}async getThemeConfiguration(){var r;try{const s=await this.httpClient.get("Tenant","GetThemeConfiguration");if(!s.result.isEnabled)return rt(je.Default);let n=s.result.preset?rt(s.result.preset):rt(je.Default);if(s.result.title&&(n.title=s.result.title),s.result.logo&&(n.logo={...n.logo,...s.result.logo}),s.result.colors&&(n.colors={...n.colors,...s.result.colors}),s.result.typography&&(n.typography={...n.typography,...s.result.typography}),s.result.spacing&&(n.spacing={...n.spacing,...s.result.spacing}),s.result.customCSS&&(n.customCSS=s.result.customCSS),s.result.darkMode&&(n.darkMode={colors:{...(r=n.darkMode)==null?void 0:r.colors,...s.result.darkMode.colors}}),s.result.applicantFormVisibleFields&&s.result.applicantFormVisibleFields.length>0&&(n.applicantFormVisibleFields=s.result.applicantFormVisibleFields),s.result.applicantFormRequiredFields&&s.result.applicantFormRequiredFields.length>0&&(n.applicantFormRequiredFields=s.result.applicantFormRequiredFields),s.result.allowedLanguages&&s.result.allowedLanguages.length>0&&(n.allowedLanguages=s.result.allowedLanguages),s.result.applicantFormPages)try{const i=typeof s.result.applicantFormPages=="string"?JSON.parse(s.result.applicantFormPages):s.result.applicantFormPages;Array.isArray(i)&&i.length>0&&(n.applicantFormPages=i.map(l=>{const c=!l._v||l._v<4;return{...l,fields:(l.fields||[]).map(d=>({...d,colSpan:c?d.colSpan===1?2:4:Math.min(4,Math.max(1,d.colSpan??4))}))}}))}catch{}if(s.result.reviewPageFields)try{const i=typeof s.result.reviewPageFields=="string"?JSON.parse(s.result.reviewPageFields):s.result.reviewPageFields;Array.isArray(i)&&i.length>0&&(n.reviewPageFields=i)}catch{}if(s.result.reviewPageDisabled&&(n.reviewPageDisabled=!0),s.result.fieldLabelMode==="placeholder"&&(n.fieldLabelMode="placeholder"),s.result.companyFormVisibleFields&&s.result.companyFormVisibleFields.length>0&&(n.companyFormVisibleFields=s.result.companyFormVisibleFields),s.result.companyFormRequiredFields&&s.result.companyFormRequiredFields.length>0&&(n.companyFormRequiredFields=s.result.companyFormRequiredFields),s.result.companyFormPages)try{const i=typeof s.result.companyFormPages=="string"?JSON.parse(s.result.companyFormPages):s.result.companyFormPages;Array.isArray(i)&&i.length>0&&(n.companyFormPages=i.map(l=>{const c=!l._v||l._v<4;return{...l,fields:(l.fields||[]).map(d=>({...d,colSpan:c?d.colSpan===1?2:4:Math.min(4,Math.max(1,d.colSpan??4))}))}}))}catch{}if(s.result.companyReviewPageFields)try{const i=typeof s.result.companyReviewPageFields=="string"?JSON.parse(s.result.companyReviewPageFields):s.result.companyReviewPageFields;Array.isArray(i)&&i.length>0&&(n.companyReviewPageFields=i)}catch{}return n}catch(s){return console.warn("[ThemeService] Failed to fetch theme configuration:",s),rt(je.Default)}}async saveThemeConfiguration(r){await this.httpClient.post("Tenant","SaveThemeConfiguration",r)}getAvailablePresets(){return[{id:je.Default,name:"Default"},{id:je.Corporate,name:"Corporate"},{id:je.Fintech,name:"Fintech"},{id:je.Healthcare,name:"Healthcare"},{id:je.Modern,name:"Modern"},{id:je.Minimal,name:"Minimal"}]}getPreviewTheme(r,s){const n=rt(r);return s?{...n,...s,logo:{...n.logo,...s.logo},colors:{...n.colors,...s.colors},typography:s.typography?{...n.typography,...s.typography}:n.typography,spacing:s.spacing?{...n.spacing,...s.spacing}:n.spacing}:n}}class or{constructor(){ue(this,"listeners",new Map)}on(r,s){return this.listeners.has(r)||this.listeners.set(r,new Set),this.listeners.get(r).add(s),()=>{this.off(r,s)}}off(r,s){const n=this.listeners.get(r);n&&n.delete(s)}emit(r,s){const n=this.listeners.get(r);n&&n.forEach(i=>{try{i(s)}catch(l){console.error(`Error in event listener for "${r}":`,l)}})}clear(){this.listeners.clear()}clearEvent(r){this.listeners.delete(r)}}class lr{constructor(){ue(this,"events",new or);ue(this,"_applicantId",null);ue(this,"_progress",null);ue(this,"_error",null)}get applicantId(){return this._applicantId}get progress(){return this._progress}get currentStep(){var r;return((r=this._progress)==null?void 0:r.currentStep)||null}get steps(){var r;return((r=this._progress)==null?void 0:r.stepInfoList)||[]}get status(){var r;return((r=this._progress)==null?void 0:r.status)||Ae.None}get workflowResult(){var r;return((r=this._progress)==null?void 0:r.workflowResult)||null}get error(){return this._error}get isComplete(){return this.status===Ae.Finished}get isOnHold(){return this.status===Ae.OnHold}get isInProgress(){return this.status===Ae.InProgress}setApplicantId(r){this._applicantId=r}updateProgress(r){var n,i;const s=(n=this._progress)==null?void 0:n.currentStep;this._progress=r,this._applicantId=r.applicantId,this._error=null,this.events.emit("progressUpdated",r),(s==null?void 0:s.order)!==((i=r.currentStep)==null?void 0:i.order)&&this.events.emit("stepChanged",r.currentStep),this.events.emit("statusChanged",r.status),r.status===Ae.Finished&&r.workflowResult&&this.events.emit("completed",r.workflowResult)}setError(r){this._error=r,this.events.emit("error",r)}clearError(){this._error=null}reset(){this._applicantId=null,this._progress=null,this._error=null}onProgressUpdated(r){return this.events.on("progressUpdated",r)}onStepChanged(r){return this.events.on("stepChanged",r)}onStatusChanged(r){return this.events.on("statusChanged",r)}onError(r){return this.events.on("error",r)}onCompleted(r){return this.events.on("completed",r)}clearListeners(){this.events.clear()}}class cr{constructor(){ue(this,"handlers",new Map)}registerHandler(r,s){this.handlers.set(r,s)}getHandler(r){return this.handlers.get(r)}hasHandler(r){return this.handlers.has(r)}async loadStepData(r,s){const n=this.getHandler(r);if(!n)throw new Error(`No handler registered for step action: ${ae[r]}`);return n.loadData(s)}async submitStepData(r,s){const n=this.getHandler(r);if(!n)throw new Error(`No handler registered for step action: ${ae[r]}`);return n.submitData(s)}}class dr{constructor(r,s,n,i,l,c,d,m){ue(this,"state");ue(this,"stepRouter");this.applicantService=r,this.questionnaireService=s,this.uploadDocumentService=n,this.appropriatenessTestService=i,this.overviewService=l,this.riskScoringService=c,this.investorCategorizationService=m,this.state=new lr,this.stepRouter=new cr,this.registerStepHandlers()}registerStepHandlers(){this.stepRouter.registerHandler(ae.Questionaries,{loadData:r=>this.questionnaireService.getQuestionnaire(r),submitData:async r=>{await this.questionnaireService.fillQuestionnaire(r)}}),this.stepRouter.registerHandler(ae.UploadDocument,{loadData:r=>this.uploadDocumentService.getUploadDocument(r),submitData:r=>this.uploadDocumentService.fillUploadDocument(r)}),this.stepRouter.registerHandler(ae.AppropriatenessTest,{loadData:r=>this.appropriatenessTestService.getAppropriatenessTest(r),submitData:async r=>{await this.appropriatenessTestService.fillAppropriatenessTest(r)}}),this.stepRouter.registerHandler(ae.Overview,{loadData:r=>this.overviewService.getOverviewData(r),submitData:r=>this.overviewService.passOverview(r.applicantId)}),this.stepRouter.registerHandler(ae.RiskScoring,{loadData:r=>this.riskScoringService.getRiskCriterias(r),submitData:async r=>{await this.riskScoringService.submitRiskScoring(r)}}),this.stepRouter.registerHandler(ae.IdentitySdk,{loadData:async r=>({applicantId:r,message:"Identity verification required"}),submitData:async()=>{}}),this.stepRouter.registerHandler(ae.InvestorCategorization,{loadData:r=>this.investorCategorizationService.getInvestorCategorization(r),submitData:async r=>{await this.investorCategorizationService.setInvestorCategorization(r)}}),this.stepRouter.registerHandler(ae.ManualReview,{loadData:async r=>({applicantId:r,message:"Your application is under manual review"}),submitData:async()=>{}}),this.stepRouter.registerHandler(ae.AdditionalData,{loadData:async r=>({applicantId:r,message:"Additional data required"}),submitData:async()=>{}})}async initialize(r){try{this.state.setApplicantId(r);const s=await this.applicantService.getProgress(r);return this.state.updateProgress(s),s}catch(s){throw this.state.setError(s),s}}async refreshProgress(){if(!this.state.applicantId)throw new Error("Workflow not initialized. Call initialize() first.");try{const r=await this.applicantService.getProgress(this.state.applicantId);return this.state.updateProgress(r),r}catch(r){throw this.state.setError(r),r}}async getCurrentStepData(){if(!this.state.currentStep)throw new Error("No current step available");if(!this.state.applicantId)throw new Error("Workflow not initialized");try{return await this.stepRouter.loadStepData(this.state.currentStep.action,this.state.applicantId)}catch(r){throw this.state.setError(r),r}}async submitCurrentStep(r){if(!this.state.currentStep)throw new Error("No current step available");try{await this.stepRouter.submitStepData(this.state.currentStep.action,r),await this.refreshProgress()}catch(s){throw this.state.setError(s),s}}async moveToNextStep(){return this.refreshProgress()}async moveToPreviousStep(){if(!this.state.applicantId)throw new Error("Workflow not initialized");try{return await this.applicantService.progressStepBack(this.state.applicantId),await this.refreshProgress()}catch(r){throw this.state.setError(r),r}}getState(){return this.state}getStepRouter(){return this.stepRouter}}function ft(t,r){return new Promise((s,n)=>{if(r&&document.getElementById(r)){s();return}const i=document.createElement("script");i.src=t,r&&(i.id=r),i.async=!0,i.onload=()=>s(),i.onerror=()=>n(new Error(`Failed to load script: ${t}`)),document.head.appendChild(i)})}function Vr(t){return!!document.getElementById(t)}function Yr(t){const r=document.getElementById(t);r&&r.remove()}const Qr="https://static.sumsub.com/idensic/static/sns-websdk-builder.js";class ur{constructor(r){ue(this,"sdk",null);ue(this,"config");ue(this,"completeCallback",null);ue(this,"errorCallback",null);this.config=r}async loadSDK(){if(!window.snsWebSdk&&(await ft(Qr,"sumsub-websdk"),!window.snsWebSdk))throw new Error("Sumsub Web SDK failed to load from CDN")}async initialize(r){await this.loadSDK();const s=window.snsWebSdk.init(this.config.accessToken,()=>this.config.onTokenRefresh()).withConf({lang:this.config.lang||"en",...this.config.applicantEmail?{email:this.config.applicantEmail}:{},...this.config.applicantPhone?{phone:this.config.applicantPhone}:{},...this.config.theme?{theme:this.config.theme}:{},...this.config.customCss?{uiConf:{customCss:this.config.customCss}}:{}}).withOptions({addViewportTag:!1,adaptIframeHeight:this.config.adaptIframeHeight!==!1}).on("idCheck.onStepCompleted",n=>{console.log("[Sumsub] Step completed:",n)}).on("idCheck.applicantStatus",n=>{var i,l;console.log("[Sumsub] Applicant status:",n),((n==null?void 0:n.reviewStatus)==="completed"||((i=n==null?void 0:n.reviewResult)==null?void 0:i.reviewAnswer)==="GREEN")&&((l=this.completeCallback)==null||l.call(this,n))}).on("idCheck.onError",n=>{var i;console.error("[Sumsub] Error:",n),(i=this.errorCallback)==null||i.call(this,n)}).onMessage((n,i)=>{var l;console.log("[Sumsub] Message:",n,i),n==="idCheck.onApplicantSubmitted"&&((l=this.completeCallback)==null||l.call(this,i))});this.sdk=s.build(),this.sdk.launch(`#${r}`)}destroy(){if(this.sdk){try{this.sdk.destroy()}catch{}this.sdk=null}}onComplete(r){this.completeCallback=r}onError(r){this.errorCallback=r}}class pr{constructor(r){ue(this,"sdk",null);ue(this,"config");this.config=r}async loadSDK(){await ft("https://sdk.onfido.com/v12.0.0/onfido.min.js","onfido-sdk")}async initialize(r){if(window.Onfido||await this.loadSDK(),!window.Onfido)throw new Error("Onfido SDK failed to load");this.sdk=window.Onfido.init({token:this.config.token,containerId:r,steps:this.config.steps||[{type:"welcome",options:{title:"Identity Verification"}},{type:"document",options:{documentTypes:{passport:!0,driving_licence:!0,national_identity_card:!0}}},{type:"face",options:{requestedVariant:"standard"}},{type:"complete"}],onComplete:()=>{this.config.onComplete&&this.config.onComplete()},onError:s=>{this.config.onError&&this.config.onError(s)}})}destroy(){this.sdk&&(this.sdk.tearDown(),this.sdk=null)}}class mr{constructor(r){ue(this,"sardineContext",null);ue(this,"config");ue(this,"sessionKey");this.config=r,this.sessionKey=r.sessionKey||this.generateSessionKey()}generateSessionKey(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(r){const s=Math.random()*16|0;return(r==="x"?s:s&3|8).toString(16)})}getSardineHost(){const{environment:r,region:s}=this.config;if(r==="sandbox")return"api.sandbox.sardine.ai";switch(s){case"eu":return"api.eu.sardine.ai";case"ca":return"api.ca.sardine.ai";case"au":return"api.au.sardine.ai";default:return"api.sardine.ai"}}async loadSDK(){return new Promise((r,s)=>{if(window._Sardine){r();return}const n=this.getSardineHost(),i=document.createElement("script");i.type="text/javascript",i.async=!0,i.src=`https://${n}/assets/loader.min.js`,i.onload=()=>{console.log("[SardinAI] SDK loaded successfully"),r()},i.onerror=()=>{s(new Error("Failed to load SardinAI SDK"))};const l=document.getElementsByTagName("script")[0];l&&l.parentNode?l.parentNode.insertBefore(i,l):document.head.appendChild(i)})}async initialize(){try{if(await this.loadSDK(),!window._Sardine)throw new Error("SardinAI SDK not available after loading");const r=this.getSardineHost(),{clientId:s,environment:n,flow:i,enableBiometrics:l,enablePortScanning:c}=this.config;this.sardineContext=window._Sardine.createContext({clientId:s,sessionKey:this.sessionKey,userIdHash:void 0,flow:i||window.location.pathname,environment:n||"production",parentElement:document.body,enableBiometrics:l!==!1,enablePortScanning:c===!0,region:this.config.region,onDeviceResponse:d=>{console.log(`[SardinAI] Device ID: ${d.deviceId}`)},onConfigUpdate:(d,m,u)=>{switch(d){case"SESSION_UPDATE_FAILED":console.error("[SardinAI] Session update failed:",u);break;case"SESSION_UPDATED":console.log("[SardinAI] Session updated:",m);break;case"SESSION_NO_UPDATE":console.log("[SardinAI] No session update");break;default:console.warn("[SardinAI] Unknown event:",d)}}}),this.addNoScriptFallback(r),console.log("[SardinAI] SDK initialized with sessionKey:",this.sessionKey)}catch(r){throw console.error("[SardinAI] Initialization failed:",r),r}}addNoScriptFallback(r){const s=document.createElement("noscript"),n=document.createElement("img"),{clientId:i,flow:l}=this.config;n.src=`https://${r}/v1/a.png?clientId=${i}&sessionKey=${this.sessionKey}&flow=${l||"kyc"}&ns=1`,n.style.display="none",s.appendChild(n),document.body.appendChild(s)}updateConfig(r){if(!this.sardineContext){console.warn("[SardinAI] Cannot update config - SDK not initialized");return}r.sessionKey&&(this.sessionKey=r.sessionKey),this.sardineContext.updateConfig({...r,onConfigUpdate:(s,n,i)=>{switch(s){case"SESSION_UPDATE_FAILED":console.error("[SardinAI] Config update failed:",i);break;case"SESSION_UPDATED":console.log("[SardinAI] Config updated:",n);break;case"SESSION_NO_UPDATE":console.log("[SardinAI] No config update needed");break}}})}getSessionKey(){return this.sessionKey}destroy(){this.sardineContext&&(this.sardineContext=null)}}class Be{static createProvider(r,s){switch(r){case Ee.Sumsub:return new ur(s);case Ee.Onfido:return new pr(s);case Ee.SardinAI:return new mr(s);default:throw new Error(`Unsupported identity provider: ${r}`)}}static parseProviderConfig(r,s,n){var i,l;switch(r){case Ee.Sumsub:const c=((i=n==null?void 0:n.identityProviders)==null?void 0:i.sumsub)||{};return{accessToken:s.accessToken||s.token,applicantEmail:s.email,applicantPhone:s.phone,externalUserId:s.externalUserId,lang:c.lang||s.lang||"en",theme:c.theme,customCss:c.customCss,adaptIframeHeight:c.adaptIframeHeight};case Ee.Onfido:return{token:s.token||s.sdkToken};case Ee.SardinAI:const d=((l=n==null?void 0:n.identityProviders)==null?void 0:l.sardinai)||{};return{clientId:d.clientId||s.clientId,sessionKey:d.sessionKey||s.sessionKey,environment:d.environment||s.environment||"production",flow:d.flow||s.flow,region:d.region,enableBiometrics:d.enableBiometrics,enablePortScanning:d.enablePortScanning};default:throw new Error(`Unsupported identity provider: ${r}`)}}}function Gr(){return`
|
|
1
|
+
"use strict";var Wr=Object.defineProperty;var Ur=(t,r,s)=>r in t?Wr(t,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[r]=s;var pe=(t,r,s)=>Ur(t,typeof r!="symbol"?r+"":r,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Kr=require("axios"),i=require("react"),e=require("react/jsx-runtime"),ut=require("react-dom"),Ke=require("react-hook-form"),He=require("zod");function qr(t){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(r,s,n.get?n:{enumerable:!0,get:()=>t[s]})}}return r.default=t,Object.freeze(r)}const jt=qr(i);var oe=(t=>(t[t.IdentitySdk=0]="IdentitySdk",t[t.RiskScoring=1]="RiskScoring",t[t.Questionaries=2]="Questionaries",t[t.AdditionalData=3]="AdditionalData",t[t.AppropriatenessTest=4]="AppropriatenessTest",t[t.UploadDocument=5]="UploadDocument",t[t.ManualReview=6]="ManualReview",t[t.Overview=7]="Overview",t[t.InvestorCategorization=8]="InvestorCategorization",t))(oe||{}),it=(t=>(t[t.NotStarted=0]="NotStarted",t[t.InProgress=1]="InProgress",t[t.Success=2]="Success",t[t.PartialSuccess=3]="PartialSuccess",t[t.Failed=4]="Failed",t[t.Skipped=5]="Skipped",t[t.AdminReview=6]="AdminReview",t[t.SkippedAndAdminReview=7]="SkippedAndAdminReview",t))(it||{}),Fe=(t=>(t[t.None=0]="None",t[t.InProgress=1]="InProgress",t[t.Finished=2]="Finished",t[t.OnHold=3]="OnHold",t[t.IdentityPending=4]="IdentityPending",t))(Fe||{}),Et=(t=>(t[t.None=0]="None",t[t.RepresentativeKYC=1]="RepresentativeKYC",t[t.ManualRiskCriteria=2]="ManualRiskCriteria",t[t.UploadDocumentReview=3]="UploadDocumentReview",t[t.AdminReview=4]="AdminReview",t))(Et||{}),At=(t=>(t[t.LowRisk=0]="LowRisk",t[t.MediumRisk=1]="MediumRisk",t[t.HighRisk=2]="HighRisk",t[t.Alert=3]="Alert",t))(At||{}),qe=(t=>(t[t.None=0]="None",t[t.Pending=1]="Pending",t[t.Approved=2]="Approved",t[t.Rejected=3]="Rejected",t[t.ResendRequested=4]="ResendRequested",t[t.Unknown=5]="Unknown",t[t.InProgress=6]="InProgress",t))(qe||{}),Ve=(t=>(t[t.Approved=0]="Approved",t[t.Reject=1]="Reject",t[t.UnderReview=2]="UnderReview",t[t.Closed=3]="Closed",t[t.AdminReview=4]="AdminReview",t[t.New=5]="New",t[t.InProgress=6]="InProgress",t))(Ve||{}),Ft=(t=>(t[t.ProviderResultPending=0]="ProviderResultPending",t[t.ProviderResultReceived=1]="ProviderResultReceived",t[t.Canceled=2]="Canceled",t[t.ExtendedToNewApplicant=3]="ExtendedToNewApplicant",t))(Ft||{}),Tt=(t=>(t[t.None=0]="None",t[t.ProviderResultPending=1]="ProviderResultPending",t[t.ProviderResultReceived=2]="ProviderResultReceived",t[t.Canceled=3]="Canceled",t))(Tt||{}),Ae=(t=>(t[t.Onfido=0]="Onfido",t[t.Sumsub=2]="Sumsub",t[t.SardinAI=3]="SardinAI",t))(Ae||{}),Pt=(t=>(t[t.Individual=0]="Individual",t[t.Company=1]="Company",t))(Pt||{}),ot=(t=>(t[t.Male=0]="Male",t[t.Female=1]="Female",t[t.Other=2]="Other",t))(ot||{}),Lt=(t=>(t[t.Image=0]="Image",t[t.Video=1]="Video",t[t.PDF=2]="PDF",t[t.OfficePDF=3]="OfficePDF",t[t.Custom=4]="Custom",t))(Lt||{}),Dt=(t=>(t[t.Pending=0]="Pending",t[t.Approved=1]="Approved",t[t.Rejected=2]="Rejected",t[t.RequiresRevision=3]="RequiresRevision",t))(Dt||{}),Mt=(t=>(t[t.SingleChoice=0]="SingleChoice",t[t.MultipleChoice=1]="MultipleChoice",t[t.Text=2]="Text",t))(Mt||{}),De=(t=>(t[t.String=0]="String",t[t.Integer=1]="Integer",t[t.Money=2]="Money",t[t.Boolean=3]="Boolean",t[t.Date=4]="Date",t[t.Country=5]="Country",t[t.DigitOnly=6]="DigitOnly",t))(De||{}),Ot=(t=>(t[t.Text=0]="Text",t[t.Radio=1]="Radio",t[t.Checkbox=2]="Checkbox",t[t.Dropdown=3]="Dropdown",t[t.Country=4]="Country",t))(Ot||{}),zt=(t=>(t[t.None=0]="None",t[t.Country=1]="Country",t))(zt||{}),je=(t=>(t[t.Individual=0]="Individual",t[t.Sophisticated=1]="Sophisticated",t[t.HighNetWorth=2]="HighNetWorth",t[t.Business=3]="Business",t))(je||{}),Bt=(t=>(t[t.Retail=0]="Retail",t[t.Professional=1]="Professional",t[t.EligibleCounterparty=2]="EligibleCounterparty",t))(Bt||{});const $e={Nationality:10,Address:20,CountryOfBirth:30,PhoneNumber:40,UboAddress:50},Ye={firstName:{label:"First Name",type:"text"},lastName:{label:"Last Name",type:"text"},email:{label:"Email",type:"email"},phonenumber:{label:"Phone Number",type:"tel"},dateOfBirth:{label:"Date of Birth",type:"date"},salutation:{label:"Salutation",type:"select"},title:{label:"Title",type:"text"},mobileCountryCode:{label:"Mobile Country Code",type:"select",countriesType:$e.PhoneNumber},street:{label:"Street",type:"text"},streetNumber:{label:"Street Number",type:"text"},zip:{label:"ZIP / Postal Code",type:"text"},city:{label:"City",type:"text"},country:{label:"Country",type:"select",countriesType:$e.Address},nationality:{label:"Nationality",type:"select",countriesType:$e.Nationality},otherNationality:{label:"Other Nationalities",type:"multiselect",countriesType:$e.Nationality},countryOfBirth:{label:"Country of Birth",type:"select",countriesType:$e.CountryOfBirth},placeOfBirth:{label:"Place of Birth",type:"text"},taxCountry:{label:"Tax Country",type:"select",countriesType:$e.Address},taxNumber:{label:"Tax Number",type:"text"},defaultLanguage:{label:"Default Language",type:"select"},educationLevel:{label:"Education Level",type:"text"},occupation:{label:"Occupation",type:"text"}},Je={companyName:{label:"Company Name",type:"text"},email:{label:"Email",type:"email"},phone:{label:"Phone",type:"tel"},registrationNumber:{label:"Registration Number",type:"text"},countryResidence:{label:"Country of Residence",type:"select",countriesType:$e.Address},legalAddress:{label:"Legal Address",type:"text"},incorporatedOn:{label:"Incorporation Date",type:"date"},controlScheme:{label:"Control Scheme",type:"text"},taxId:{label:"Tax ID",type:"text"},registrationLocation:{label:"Registration Location",type:"text"},website:{label:"Website",type:"text"},postalAddress:{label:"Postal Address",type:"text"},street:{label:"Street",type:"text"},streetNumber:{label:"Street Number",type:"text"},city:{label:"City",type:"text"},state:{label:"State / Province",type:"text"},postalCode:{label:"Postal Code",type:"text"},addressCountry:{label:"Address Country",type:"select",countriesType:$e.Address},lei:{label:"LEI",type:"text"}},_t=["companyName","email","phone","registrationNumber"],$t=["firstName","lastName","email","phonenumber","dateOfBirth"],xt=[{value:"EN",label:"English"},{value:"DE",label:"German"},{value:"FR",label:"French"},{value:"ES",label:"Spanish"},{value:"IT",label:"Italian"},{value:"PT",label:"Portuguese"},{value:"NL",label:"Dutch"},{value:"PL",label:"Polish"},{value:"RU",label:"Russian"},{value:"ZH",label:"Chinese"},{value:"JA",label:"Japanese"},{value:"AR",label:"Arabic"},{value:"TR",label:"Turkish"},{value:"SV",label:"Swedish"},{value:"DA",label:"Danish"},{value:"FI",label:"Finnish"},{value:"NO",label:"Norwegian"}];var we=(t=>(t.Default="default",t.Corporate="corporate",t.Fintech="fintech",t.Healthcare="healthcare",t.Modern="modern",t.Minimal="minimal",t))(we||{});const Ht={timeout:3e4,retries:3,locale:"en",endpoints:{pattern:"host-controller"}};class Wt{constructor(r){this.config=r}build(r,s){const n=`${r}.${s}`;if(this.config.customPaths&&this.config.customPaths[n])return this.config.customPaths[n];switch(this.config.pattern){case"host-controller":return`/api/${r}/${s}`;case"application-service":return`/services/app/${this.getServiceName(r)}/${s}`;case"custom":throw new Error(`Custom endpoint path not found for ${n}. Please provide it in customPaths.`);default:throw new Error(`Unknown endpoint pattern: ${this.config.pattern}`)}}getServiceName(r){return{Applicant:"MetaKYCVerification",Questionnaire:"MetaKYCVerification",UploadDocument:"MetaKYCVerification",AppropriatenessTest:"MetaKYCVerification",BaseInformation:"MetaKYCVerification"}[r]||r}}class Le extends Error{constructor(s,n,a,l,c){super(s);pe(this,"response");this.code=n,this.details=a,this.validationErrors=l,this.name="MetaKYCError",this.response=c,Object.setPrototypeOf(this,Le.prototype)}}class tt{static handleApiError(r){return new Le(r.message||"An unknown error occurred",r.code,r.details||void 0,r.validationErrors||void 0)}static handleAxiosError(r){if(r.response){const s=r.response.data;return s&&s.error?new Le(s.error.message||"An unknown error occurred",s.error.code,s.error.details||void 0,s.error.validationErrors||void 0,r.response):s&&s.result&&s.result.message?new Le(s.result.message,r.response.status,`HTTP ${r.response.status}: ${r.response.statusText}`,void 0,r.response):new Le((s==null?void 0:s.message)||r.message||"Request failed",r.response.status,`HTTP ${r.response.status}: ${r.response.statusText}`,void 0,r.response)}else return r.request?new Le("No response from server",0,"The request was made but no response was received. Please check your network connection."):new Le(r.message||"An unexpected error occurred",0,r.toString())}static isMetaKYCError(r){return r instanceof Le}}class Ut{constructor(r){pe(this,"axiosInstance");pe(this,"endpointBuilder");pe(this,"config");this.config={...Ht,...r},this.endpointBuilder=new Wt(this.config.endpoints),this.axiosInstance=Kr.create({baseURL:this.config.baseUrl,timeout:this.config.timeout,headers:{"Content-Type":"application/json"}}),this.axiosInstance.interceptors.request.use(s=>(s.headers["Abp-TenantId"]=this.config.tenantId.toString(),s.headers.ApiKey=this.config.apiKey,s.headers["X-API-KEY"]=this.config.apiKey,this.config.locale&&(s.headers["Accept-Language"]=this.config.locale),s),s=>Promise.reject(s)),this.axiosInstance.interceptors.response.use(s=>s,async s=>{var a;const n=s.config;return((a=s.response)==null?void 0:a.status)>=500&&!n._retry&&(n._retry=!0,n._retryCount=(n._retryCount||0)+1,n._retryCount<(this.config.retries||3))?(await new Promise(l=>setTimeout(l,1e3*n._retryCount)),this.axiosInstance(n)):Promise.reject(s)})}buildEndpoint(r,s){return this.endpointBuilder.build(r,s)}async get(r,s,n){try{const a=this.buildEndpoint(r,s),l=await this.axiosInstance.get(a,{params:n});return this.handleResponse(l)}catch(a){throw tt.handleAxiosError(a)}}async post(r,s,n){try{const a=this.buildEndpoint(r,s),l=await this.axiosInstance.post(a,n);return this.handleResponse(l)}catch(a){throw tt.handleAxiosError(a)}}async put(r,s,n){try{const a=this.buildEndpoint(r,s),l=await this.axiosInstance.put(a,n);return this.handleResponse(l)}catch(a){throw tt.handleAxiosError(a)}}async delete(r,s,n){try{const a=this.buildEndpoint(r,s),l=await this.axiosInstance.delete(a,{params:n});return this.handleResponse(l)}catch(a){throw tt.handleAxiosError(a)}}handleResponse(r){const s=r.data;if(!s.success&&s.error)throw tt.handleApiError(s.error);return s}getAxiosInstance(){return this.axiosInstance}}class Kt{constructor(r){this.httpClient=r}async createApplicant(r){return(await this.httpClient.post("Applicant","ApplicantRegistrationRequest",r)).result}async createCompanyApplicant(r){return(await this.httpClient.post("Applicant","ApplicantCompanyRegistrationRequest",r)).result}async duplicateApplicant(r){return(await this.httpClient.post("Applicant","DuplicateApplicantRegistrationRequest",r)).result}async getProgress(r){return(await this.httpClient.get("Applicant","GetApplicantProgress",{applicantId:r})).result}async getProgressStatus(r){return(await this.httpClient.get("Applicant","GetApplicantProgressStaus",{applicantId:r})).result}async getApplicantData(r){return(await this.httpClient.get("Applicant","GetApplicantData",{applicantId:r})).result}async getApplicantStatus(r){return(await this.httpClient.get("Applicant","GetApplicantStatus",{applicantId:r})).result}async stopProgress(r){await this.httpClient.get("Applicant","StopProgress",{applicantId:r})}async progressStepBack(r){await this.httpClient.get("Applicant","ProgressStepBack",{applicantId:r})}async setLanguage(r,s){await this.httpClient.post("Applicant","SetApplicantLng",{applicantId:r,language:s})}async activateApplicant(r){await this.httpClient.get("Applicant","ActivateApplicant",{applicantId:r})}async deleteApplicant(r){await this.httpClient.delete("Applicant","DeleteApplicant",{applicantId:r})}async checkApplicantExists(r){return(await this.httpClient.get("Applicant","CheckApplicantIfExists",{externalRefId:r})).result}}class qt{constructor(r){this.httpClient=r}async getQuestionnaire(r){return(await this.httpClient.get("Questionnaire","GetQuestionnaire",{applicantid:r})).result}async fillQuestionnaire(r){return(await this.httpClient.post("Applicant","FillQuestionnarie",r)).result}}class Vt{constructor(r){this.httpClient=r}async getUploadDocument(r){return(await this.httpClient.get("UploadDocument","GetUploadDocument",{applicantid:r})).result}async fillUploadDocument(r){await this.httpClient.post("Applicant","FillUploadDocument",r)}async reviewUploadDocument(r){await this.httpClient.post("UploadDocument","ReviewUploadDocument",r)}}class Yt{constructor(r){this.httpClient=r}async getAppropriatenessTest(r){return(await this.httpClient.get("AppropriatenessTest","GetAppropriatenessTest",{applicantid:r})).result}async fillAppropriatenessTest(r){return(await this.httpClient.post("Applicant","FillAppropriatenessTest",r)).result}}class Qt{constructor(r){this.httpClient=r}async getOverviewData(r){return(await this.httpClient.get("Applicant","GetOverviewData",{ApplicantId:r})).result}async passOverview(r){await this.httpClient.get("Applicant","PassOverview",{applicantId:r})}}class Gt{constructor(r){this.httpClient=r}async getRiskScoringPlan(){return(await this.httpClient.get("Applicant","GetRiskScoringPlanInfo")).result}async getRiskCriterias(r){return(await this.httpClient.get("Risk","GetCriterias",{applicantId:r})).result}async submitRiskScoring(r){return(await this.httpClient.post("Applicant","RiskScoringRequest",r)).result}}class Jt{constructor(r){this.httpClient=r}async identityRequest(r){console.log("[IdentityService] Calling IdentityRequest with input:",r);const s=await this.httpClient.post("Applicant","IdentityRequest",r);return console.log("[IdentityService] IdentityRequest response:",s),s.result}async identityCompanyRequest(r){return(await this.httpClient.post("Applicant","IdentityCompanyRequest",r)).result}async restartIdentityRequest(r){const s={applicantId:r,restart:!0,redirectUrl:"",ttl:604800};return console.log("[IdentityService] Restarting identity with restart=true:",s),this.identityRequest(s)}async restartIdentityCompanyRequest(r){const s={applicantId:r,restart:!0,redirectUrl:"",ttl:604800};return this.identityCompanyRequest(s)}async refreshSumsubToken(r){console.log("[IdentityService] Refreshing Sumsub token for applicant:",r);const s=await this.httpClient.post("Applicant","RefreshSumsubToken",{applicantId:r});return console.log("[IdentityService] Sumsub token refresh result:",s),s.result.accessToken}}class Zt{constructor(r){this.httpClient=r}async getCountries(r,s,n){return(await this.httpClient.get("BaseInformation","GetAllCountries",{filter:r||"",lng:s||"en",type:n})).result}async getBranches(){return(await this.httpClient.get("BaseInformation","GetBranches")).result}async getLegalEntities(){return(await this.httpClient.get("BaseInformation","GetLegalEntities")).result}}class Xt{constructor(r){this.httpClient=r}async setInvestorCategorization(r){return(await this.httpClient.post("Applicant","SetInvestorCategorization",r)).result}async getInvestorCategorization(r){return(await this.httpClient.get("Applicant","GetInvestorCategorisation",{applicantId:r})).result}}const Re={name:"Default",title:"KYC Verification",logo:{url:"",height:"40px",visible:!0},colors:{primary:"#2563eb",primaryHover:"#1d4ed8",primaryLight:"#dbeafe",primaryDark:"#1e40af",secondary:"#64748b",secondaryHover:"#475569",success:"#10b981",warning:"#f59e0b",danger:"#ef4444",info:"#3b82f6",background:"#ffffff",surface:"#f9fafb",border:"#e5e7eb",textPrimary:"#111827",textSecondary:"#6b7280",textMuted:"#9ca3af"},typography:{fontFamily:"Inter, system-ui, -apple-system, sans-serif",fontSize:{xs:"0.75rem",sm:"0.875rem",base:"1rem",lg:"1.125rem",xl:"1.25rem","2xl":"1.5rem","3xl":"1.875rem"},fontWeight:{normal:400,medium:500,semibold:600,bold:700}},spacing:{borderRadius:"0.5rem",cardPadding:"1.5rem",inputHeight:"2.5rem"},darkMode:{colors:{background:"#111827",surface:"#1f2937",border:"#374151",textPrimary:"#f9fafb",textSecondary:"#d1d5db",textMuted:"#9ca3af"}}},er={name:"Corporate",logo:{url:"",height:"40px",visible:!0},colors:{primary:"#0052CC",primaryHover:"#0747A6",primaryLight:"#DEEBFF",primaryDark:"#0747A6",secondary:"#6B778C",secondaryHover:"#5E6C84",success:"#00875A",warning:"#FF991F",danger:"#DE350B",info:"#0065FF",background:"#ffffff",surface:"#F4F5F7",border:"#DFE1E6",textPrimary:"#172B4D",textSecondary:"#5E6C84",textMuted:"#97A0AF"},typography:{fontFamily:"system-ui, -apple-system, sans-serif"},spacing:{borderRadius:"0.25rem",cardPadding:"1.5rem",inputHeight:"2.5rem"}},tr={name:"Fintech",logo:{url:"",height:"36px",visible:!0},colors:{primary:"#00B386",primaryHover:"#009973",primaryLight:"#D1FAE5",primaryDark:"#047857",secondary:"#7C3AED",secondaryHover:"#6D28D9",success:"#10B981",warning:"#F59E0B",danger:"#EF4444",info:"#3B82F6",background:"#ffffff",surface:"#F9FAFB",border:"#E5E7EB",textPrimary:"#111827",textSecondary:"#6B7280",textMuted:"#9CA3AF"},typography:{fontFamily:"Montserrat, system-ui, sans-serif"},spacing:{borderRadius:"0.75rem",cardPadding:"2rem",inputHeight:"3rem"}},rr={name:"Healthcare",logo:{url:"",height:"44px",visible:!0},colors:{primary:"#06B6D4",primaryHover:"#0891B2",primaryLight:"#CFFAFE",primaryDark:"#0E7490",secondary:"#8B5CF6",secondaryHover:"#7C3AED",success:"#059669",warning:"#D97706",danger:"#DC2626",info:"#0284C7",background:"#ffffff",surface:"#F0F9FF",border:"#E0F2FE",textPrimary:"#0F172A",textSecondary:"#475569",textMuted:"#94A3B8"},typography:{fontFamily:"Lato, system-ui, sans-serif"},spacing:{borderRadius:"0.5rem",cardPadding:"1.75rem",inputHeight:"2.75rem"},darkMode:{colors:{background:"#0F172A",surface:"#1E293B",border:"#334155",textPrimary:"#F1F5F9",textSecondary:"#CBD5E1"}}},sr={name:"Modern",logo:{url:"",height:"38px",visible:!0},colors:{primary:"#8B5CF6",primaryHover:"#7C3AED",primaryLight:"#EDE9FE",primaryDark:"#6D28D9",secondary:"#EC4899",secondaryHover:"#DB2777",success:"#10B981",warning:"#F59E0B",danger:"#EF4444",info:"#3B82F6",background:"#ffffff",surface:"#FAFAFA",border:"#E5E5E5",textPrimary:"#171717",textSecondary:"#737373",textMuted:"#A3A3A3"},typography:{fontFamily:"Poppins, system-ui, sans-serif"},spacing:{borderRadius:"1rem",cardPadding:"2rem",inputHeight:"3rem"}},nr={name:"Minimal",logo:{url:"",height:"32px",visible:!0},colors:{primary:"#000000",primaryHover:"#18181B",primaryLight:"#F4F4F5",primaryDark:"#000000",secondary:"#71717A",secondaryHover:"#52525B",success:"#22C55E",warning:"#EAB308",danger:"#EF4444",info:"#3B82F6",background:"#ffffff",surface:"#FAFAFA",border:"#E4E4E7",textPrimary:"#09090B",textSecondary:"#71717A",textMuted:"#A1A1AA"},typography:{fontFamily:"system-ui, -apple-system, sans-serif"},spacing:{borderRadius:"0.25rem",cardPadding:"1.25rem",inputHeight:"2.25rem"}},ar={[we.Default]:Re,[we.Corporate]:er,[we.Fintech]:tr,[we.Healthcare]:rr,[we.Modern]:sr,[we.Minimal]:nr};function rt(t){return ar[t]||Re}class ir{constructor(r){this.httpClient=r}async getThemeConfiguration(){var r;try{const s=await this.httpClient.get("Tenant","GetThemeConfiguration");if(!s.result.isEnabled)return rt(we.Default);let n=s.result.preset?rt(s.result.preset):rt(we.Default);if(s.result.title&&(n.title=s.result.title),s.result.logo&&(n.logo={...n.logo,...s.result.logo}),s.result.colors&&(n.colors={...n.colors,...s.result.colors}),s.result.typography&&(n.typography={...n.typography,...s.result.typography}),s.result.spacing&&(n.spacing={...n.spacing,...s.result.spacing}),s.result.customCSS&&(n.customCSS=s.result.customCSS),s.result.darkMode&&(n.darkMode={colors:{...(r=n.darkMode)==null?void 0:r.colors,...s.result.darkMode.colors}}),s.result.applicantFormVisibleFields&&s.result.applicantFormVisibleFields.length>0&&(n.applicantFormVisibleFields=s.result.applicantFormVisibleFields),s.result.applicantFormRequiredFields&&s.result.applicantFormRequiredFields.length>0&&(n.applicantFormRequiredFields=s.result.applicantFormRequiredFields),s.result.allowedLanguages&&s.result.allowedLanguages.length>0&&(n.allowedLanguages=s.result.allowedLanguages),s.result.applicantFormPages)try{const a=typeof s.result.applicantFormPages=="string"?JSON.parse(s.result.applicantFormPages):s.result.applicantFormPages;Array.isArray(a)&&a.length>0&&(n.applicantFormPages=a.map(l=>{const c=!l._v||l._v<4;return{...l,fields:(l.fields||[]).map(u=>({...u,colSpan:c?u.colSpan===1?2:4:Math.min(4,Math.max(1,u.colSpan??4))}))}}))}catch{}if(s.result.reviewPageFields)try{const a=typeof s.result.reviewPageFields=="string"?JSON.parse(s.result.reviewPageFields):s.result.reviewPageFields;Array.isArray(a)&&a.length>0&&(n.reviewPageFields=a)}catch{}if(s.result.reviewPageDisabled&&(n.reviewPageDisabled=!0),s.result.fieldLabelMode==="placeholder"&&(n.fieldLabelMode="placeholder"),s.result.companyFormVisibleFields&&s.result.companyFormVisibleFields.length>0&&(n.companyFormVisibleFields=s.result.companyFormVisibleFields),s.result.companyFormRequiredFields&&s.result.companyFormRequiredFields.length>0&&(n.companyFormRequiredFields=s.result.companyFormRequiredFields),s.result.companyFormPages)try{const a=typeof s.result.companyFormPages=="string"?JSON.parse(s.result.companyFormPages):s.result.companyFormPages;Array.isArray(a)&&a.length>0&&(n.companyFormPages=a.map(l=>{const c=!l._v||l._v<4;return{...l,fields:(l.fields||[]).map(u=>({...u,colSpan:c?u.colSpan===1?2:4:Math.min(4,Math.max(1,u.colSpan??4))}))}}))}catch{}if(s.result.companyReviewPageFields)try{const a=typeof s.result.companyReviewPageFields=="string"?JSON.parse(s.result.companyReviewPageFields):s.result.companyReviewPageFields;Array.isArray(a)&&a.length>0&&(n.companyReviewPageFields=a)}catch{}return n}catch(s){return console.warn("[ThemeService] Failed to fetch theme configuration:",s),rt(we.Default)}}async saveThemeConfiguration(r){await this.httpClient.post("Tenant","SaveThemeConfiguration",r)}getAvailablePresets(){return[{id:we.Default,name:"Default"},{id:we.Corporate,name:"Corporate"},{id:we.Fintech,name:"Fintech"},{id:we.Healthcare,name:"Healthcare"},{id:we.Modern,name:"Modern"},{id:we.Minimal,name:"Minimal"}]}getPreviewTheme(r,s){const n=rt(r);return s?{...n,...s,logo:{...n.logo,...s.logo},colors:{...n.colors,...s.colors},typography:s.typography?{...n.typography,...s.typography}:n.typography,spacing:s.spacing?{...n.spacing,...s.spacing}:n.spacing}:n}}class or{constructor(){pe(this,"listeners",new Map)}on(r,s){return this.listeners.has(r)||this.listeners.set(r,new Set),this.listeners.get(r).add(s),()=>{this.off(r,s)}}off(r,s){const n=this.listeners.get(r);n&&n.delete(s)}emit(r,s){const n=this.listeners.get(r);n&&n.forEach(a=>{try{a(s)}catch(l){console.error(`Error in event listener for "${r}":`,l)}})}clear(){this.listeners.clear()}clearEvent(r){this.listeners.delete(r)}}class lr{constructor(){pe(this,"events",new or);pe(this,"_applicantId",null);pe(this,"_progress",null);pe(this,"_error",null)}get applicantId(){return this._applicantId}get progress(){return this._progress}get currentStep(){var r;return((r=this._progress)==null?void 0:r.currentStep)||null}get steps(){var r;return((r=this._progress)==null?void 0:r.stepInfoList)||[]}get status(){var r;return((r=this._progress)==null?void 0:r.status)||Fe.None}get workflowResult(){var r;return((r=this._progress)==null?void 0:r.workflowResult)||null}get error(){return this._error}get isComplete(){return this.status===Fe.Finished}get isOnHold(){return this.status===Fe.OnHold}get isInProgress(){return this.status===Fe.InProgress}setApplicantId(r){this._applicantId=r}updateProgress(r){var n,a;const s=(n=this._progress)==null?void 0:n.currentStep;this._progress=r,this._applicantId=r.applicantId,this._error=null,this.events.emit("progressUpdated",r),(s==null?void 0:s.order)!==((a=r.currentStep)==null?void 0:a.order)&&this.events.emit("stepChanged",r.currentStep),this.events.emit("statusChanged",r.status),r.status===Fe.Finished&&r.workflowResult&&this.events.emit("completed",r.workflowResult)}setError(r){this._error=r,this.events.emit("error",r)}clearError(){this._error=null}reset(){this._applicantId=null,this._progress=null,this._error=null}onProgressUpdated(r){return this.events.on("progressUpdated",r)}onStepChanged(r){return this.events.on("stepChanged",r)}onStatusChanged(r){return this.events.on("statusChanged",r)}onError(r){return this.events.on("error",r)}onCompleted(r){return this.events.on("completed",r)}clearListeners(){this.events.clear()}}class cr{constructor(){pe(this,"handlers",new Map)}registerHandler(r,s){this.handlers.set(r,s)}getHandler(r){return this.handlers.get(r)}hasHandler(r){return this.handlers.has(r)}async loadStepData(r,s){const n=this.getHandler(r);if(!n)throw new Error(`No handler registered for step action: ${oe[r]}`);return n.loadData(s)}async submitStepData(r,s){const n=this.getHandler(r);if(!n)throw new Error(`No handler registered for step action: ${oe[r]}`);return n.submitData(s)}}class dr{constructor(r,s,n,a,l,c,u,y){pe(this,"state");pe(this,"stepRouter");this.applicantService=r,this.questionnaireService=s,this.uploadDocumentService=n,this.appropriatenessTestService=a,this.overviewService=l,this.riskScoringService=c,this.investorCategorizationService=y,this.state=new lr,this.stepRouter=new cr,this.registerStepHandlers()}registerStepHandlers(){this.stepRouter.registerHandler(oe.Questionaries,{loadData:r=>this.questionnaireService.getQuestionnaire(r),submitData:async r=>{await this.questionnaireService.fillQuestionnaire(r)}}),this.stepRouter.registerHandler(oe.UploadDocument,{loadData:r=>this.uploadDocumentService.getUploadDocument(r),submitData:r=>this.uploadDocumentService.fillUploadDocument(r)}),this.stepRouter.registerHandler(oe.AppropriatenessTest,{loadData:r=>this.appropriatenessTestService.getAppropriatenessTest(r),submitData:async r=>{await this.appropriatenessTestService.fillAppropriatenessTest(r)}}),this.stepRouter.registerHandler(oe.Overview,{loadData:r=>this.overviewService.getOverviewData(r),submitData:r=>this.overviewService.passOverview(r.applicantId)}),this.stepRouter.registerHandler(oe.RiskScoring,{loadData:r=>this.riskScoringService.getRiskCriterias(r),submitData:async r=>{await this.riskScoringService.submitRiskScoring(r)}}),this.stepRouter.registerHandler(oe.IdentitySdk,{loadData:async r=>({applicantId:r,message:"Identity verification required"}),submitData:async()=>{}}),this.stepRouter.registerHandler(oe.InvestorCategorization,{loadData:r=>this.investorCategorizationService.getInvestorCategorization(r),submitData:async r=>{await this.investorCategorizationService.setInvestorCategorization(r)}}),this.stepRouter.registerHandler(oe.ManualReview,{loadData:async r=>({applicantId:r,message:"Your application is under manual review"}),submitData:async()=>{}}),this.stepRouter.registerHandler(oe.AdditionalData,{loadData:async r=>({applicantId:r,message:"Additional data required"}),submitData:async()=>{}})}async initialize(r){try{this.state.setApplicantId(r);const s=await this.applicantService.getProgress(r);return this.state.updateProgress(s),s}catch(s){throw this.state.setError(s),s}}async refreshProgress(){if(!this.state.applicantId)throw new Error("Workflow not initialized. Call initialize() first.");try{const r=await this.applicantService.getProgress(this.state.applicantId);return this.state.updateProgress(r),r}catch(r){throw this.state.setError(r),r}}async getCurrentStepData(){if(!this.state.currentStep)throw new Error("No current step available");if(!this.state.applicantId)throw new Error("Workflow not initialized");try{return await this.stepRouter.loadStepData(this.state.currentStep.action,this.state.applicantId)}catch(r){throw this.state.setError(r),r}}async submitCurrentStep(r){if(!this.state.currentStep)throw new Error("No current step available");try{await this.stepRouter.submitStepData(this.state.currentStep.action,r),await this.refreshProgress()}catch(s){throw this.state.setError(s),s}}async moveToNextStep(){return this.refreshProgress()}async moveToPreviousStep(){if(!this.state.applicantId)throw new Error("Workflow not initialized");try{return await this.applicantService.progressStepBack(this.state.applicantId),await this.refreshProgress()}catch(r){throw this.state.setError(r),r}}getState(){return this.state}getStepRouter(){return this.stepRouter}}function ft(t,r){return new Promise((s,n)=>{if(r&&document.getElementById(r)){s();return}const a=document.createElement("script");a.src=t,r&&(a.id=r),a.async=!0,a.onload=()=>s(),a.onerror=()=>n(new Error(`Failed to load script: ${t}`)),document.head.appendChild(a)})}function Vr(t){return!!document.getElementById(t)}function Yr(t){const r=document.getElementById(t);r&&r.remove()}const Qr="https://static.sumsub.com/idensic/static/sns-websdk-builder.js";class ur{constructor(r){pe(this,"sdk",null);pe(this,"config");pe(this,"completeCallback",null);pe(this,"errorCallback",null);this.config=r}async loadSDK(){if(!window.snsWebSdk&&(await ft(Qr,"sumsub-websdk"),!window.snsWebSdk))throw new Error("Sumsub Web SDK failed to load from CDN")}async initialize(r){await this.loadSDK();const s=window.snsWebSdk.init(this.config.accessToken,()=>this.config.onTokenRefresh()).withConf({lang:this.config.lang||"en",...this.config.applicantEmail?{email:this.config.applicantEmail}:{},...this.config.applicantPhone?{phone:this.config.applicantPhone}:{},...this.config.theme?{theme:this.config.theme}:{},...this.config.customCss?{uiConf:{customCss:this.config.customCss}}:{}}).withOptions({addViewportTag:!1,adaptIframeHeight:this.config.adaptIframeHeight!==!1}).on("idCheck.onStepCompleted",n=>{console.log("[Sumsub] Step completed:",n)}).on("idCheck.applicantStatus",n=>{var a,l;console.log("[Sumsub] Applicant status:",n),((n==null?void 0:n.reviewStatus)==="completed"||((a=n==null?void 0:n.reviewResult)==null?void 0:a.reviewAnswer)==="GREEN")&&((l=this.completeCallback)==null||l.call(this,n))}).on("idCheck.onError",n=>{var a;console.error("[Sumsub] Error:",n),(a=this.errorCallback)==null||a.call(this,n)}).onMessage((n,a)=>{var l;console.log("[Sumsub] Message:",n,a),n==="idCheck.onApplicantSubmitted"&&((l=this.completeCallback)==null||l.call(this,a))});this.sdk=s.build(),this.sdk.launch(`#${r}`)}destroy(){if(this.sdk){try{this.sdk.destroy()}catch{}this.sdk=null}}onComplete(r){this.completeCallback=r}onError(r){this.errorCallback=r}}class pr{constructor(r){pe(this,"sdk",null);pe(this,"config");this.config=r}async loadSDK(){await ft("https://sdk.onfido.com/v12.0.0/onfido.min.js","onfido-sdk")}async initialize(r){if(window.Onfido||await this.loadSDK(),!window.Onfido)throw new Error("Onfido SDK failed to load");this.sdk=window.Onfido.init({token:this.config.token,containerId:r,steps:this.config.steps||[{type:"welcome",options:{title:"Identity Verification"}},{type:"document",options:{documentTypes:{passport:!0,driving_licence:!0,national_identity_card:!0}}},{type:"face",options:{requestedVariant:"standard"}},{type:"complete"}],onComplete:()=>{this.config.onComplete&&this.config.onComplete()},onError:s=>{this.config.onError&&this.config.onError(s)}})}destroy(){this.sdk&&(this.sdk.tearDown(),this.sdk=null)}}class mr{constructor(r){pe(this,"sardineContext",null);pe(this,"config");pe(this,"sessionKey");this.config=r,this.sessionKey=r.sessionKey||this.generateSessionKey()}generateSessionKey(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(r){const s=Math.random()*16|0;return(r==="x"?s:s&3|8).toString(16)})}getSardineHost(){const{environment:r,region:s}=this.config;if(r==="sandbox")return"api.sandbox.sardine.ai";switch(s){case"eu":return"api.eu.sardine.ai";case"ca":return"api.ca.sardine.ai";case"au":return"api.au.sardine.ai";default:return"api.sardine.ai"}}async loadSDK(){return new Promise((r,s)=>{if(window._Sardine){r();return}const n=this.getSardineHost(),a=document.createElement("script");a.type="text/javascript",a.async=!0,a.src=`https://${n}/assets/loader.min.js`,a.onload=()=>{console.log("[SardinAI] SDK loaded successfully"),r()},a.onerror=()=>{s(new Error("Failed to load SardinAI SDK"))};const l=document.getElementsByTagName("script")[0];l&&l.parentNode?l.parentNode.insertBefore(a,l):document.head.appendChild(a)})}async initialize(){try{if(await this.loadSDK(),!window._Sardine)throw new Error("SardinAI SDK not available after loading");const r=this.getSardineHost(),{clientId:s,environment:n,flow:a,enableBiometrics:l,enablePortScanning:c}=this.config;this.sardineContext=window._Sardine.createContext({clientId:s,sessionKey:this.sessionKey,userIdHash:void 0,flow:a||window.location.pathname,environment:n||"production",parentElement:document.body,enableBiometrics:l!==!1,enablePortScanning:c===!0,region:this.config.region,onDeviceResponse:u=>{console.log(`[SardinAI] Device ID: ${u.deviceId}`)},onConfigUpdate:(u,y,p)=>{switch(u){case"SESSION_UPDATE_FAILED":console.error("[SardinAI] Session update failed:",p);break;case"SESSION_UPDATED":console.log("[SardinAI] Session updated:",y);break;case"SESSION_NO_UPDATE":console.log("[SardinAI] No session update");break;default:console.warn("[SardinAI] Unknown event:",u)}}}),this.addNoScriptFallback(r),console.log("[SardinAI] SDK initialized with sessionKey:",this.sessionKey)}catch(r){throw console.error("[SardinAI] Initialization failed:",r),r}}addNoScriptFallback(r){const s=document.createElement("noscript"),n=document.createElement("img"),{clientId:a,flow:l}=this.config;n.src=`https://${r}/v1/a.png?clientId=${a}&sessionKey=${this.sessionKey}&flow=${l||"kyc"}&ns=1`,n.style.display="none",s.appendChild(n),document.body.appendChild(s)}updateConfig(r){if(!this.sardineContext){console.warn("[SardinAI] Cannot update config - SDK not initialized");return}r.sessionKey&&(this.sessionKey=r.sessionKey),this.sardineContext.updateConfig({...r,onConfigUpdate:(s,n,a)=>{switch(s){case"SESSION_UPDATE_FAILED":console.error("[SardinAI] Config update failed:",a);break;case"SESSION_UPDATED":console.log("[SardinAI] Config updated:",n);break;case"SESSION_NO_UPDATE":console.log("[SardinAI] No config update needed");break}}})}getSessionKey(){return this.sessionKey}destroy(){this.sardineContext&&(this.sardineContext=null)}}class _e{static createProvider(r,s){switch(r){case Ae.Sumsub:return new ur(s);case Ae.Onfido:return new pr(s);case Ae.SardinAI:return new mr(s);default:throw new Error(`Unsupported identity provider: ${r}`)}}static parseProviderConfig(r,s,n){var a,l;switch(r){case Ae.Sumsub:const c=((a=n==null?void 0:n.identityProviders)==null?void 0:a.sumsub)||{};return{accessToken:s.accessToken||s.token,applicantEmail:s.email,applicantPhone:s.phone,externalUserId:s.externalUserId,lang:c.lang||s.lang||"en",theme:c.theme,customCss:c.customCss,adaptIframeHeight:c.adaptIframeHeight};case Ae.Onfido:return{token:s.token||s.sdkToken};case Ae.SardinAI:const u=((l=n==null?void 0:n.identityProviders)==null?void 0:l.sardinai)||{};return{clientId:u.clientId||s.clientId,sessionKey:u.sessionKey||s.sessionKey,environment:u.environment||s.environment||"production",flow:u.flow||s.flow,region:u.region,enableBiometrics:u.enableBiometrics,enablePortScanning:u.enablePortScanning};default:throw new Error(`Unsupported identity provider: ${r}`)}}}function Gr(){return`
|
|
2
2
|
/* ── metakyc-input-colors (ThemeManager failsafe — same rules as globals.css) ── */
|
|
3
3
|
.metakyc-sdk input:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="range"]),
|
|
4
4
|
.metakyc-sdk select,
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
position: relative !important;
|
|
30
30
|
z-index: 2 !important;
|
|
31
31
|
}
|
|
32
|
-
`}class yr{constructor(r){ue(this,"currentTheme",Ne);ue(this,"customStyleElement",null);ue(this,"inputStyleElement",null);ue(this,"container");this.container=r||document.documentElement}applyTheme(r){this.currentTheme=this.mergeWithDefault(r),this.applyColors(this.currentTheme.colors),this.currentTheme.typography&&this.applyTypography(this.currentTheme.typography),this.currentTheme.spacing&&this.applySpacing(this.currentTheme.spacing),this.currentTheme.customCSS&&this.injectCustomCSS(this.currentTheme.customCSS),console.log("[ThemeManager] Theme applied:",this.currentTheme.name||"Custom")}applyColors(r){var n;const s={primary:r.primary,"primary-hover":r.primaryHover,"primary-light":r.primaryLight,"primary-dark":r.primaryDark,secondary:r.secondary,"secondary-hover":r.secondaryHover,success:r.success,warning:r.warning,danger:r.danger,info:r.info,background:r.background,surface:r.surface,border:r.border,"text-primary":r.textPrimary,"text-secondary":r.textSecondary,"text-muted":r.textMuted,"input-bg":r.inputBg||r.background,"input-text":r.inputText||r.textPrimary,"input-border":r.inputBorder||r.border,"input-border-focus":r.inputBorderFocus||r.primary,"input-placeholder":r.inputPlaceholder||r.textMuted};Object.entries(s).forEach(([i,l])=>{l&&this.container.style.setProperty(`--metakyc-${i}`,l)}),this.injectInputColors(),(n=this.currentTheme.darkMode)!=null&&n.colors&&this.applyDarkModeColors(this.currentTheme.darkMode.colors)}applyDarkModeColors(r){Object.entries(r).forEach(([s,n])=>{if(n){const i=`--metakyc-dark-${this.kebabCase(s)}`;this.container.style.setProperty(i,n)}})}applyTypography(r){r&&(r.fontFamily&&this.container.style.setProperty("--metakyc-font-family",r.fontFamily),r.headingFont&&this.container.style.setProperty("--metakyc-heading-font",r.headingFont),r.fontSize&&Object.entries(r.fontSize).forEach(([s,n])=>{this.container.style.setProperty(`--metakyc-font-size-${s}`,n)}),r.fontWeight&&Object.entries(r.fontWeight).forEach(([s,n])=>{this.container.style.setProperty(`--metakyc-font-weight-${s}`,n.toString())}))}applySpacing(r){r&&Object.entries(r).forEach(([s,n])=>{const i=`--metakyc-${this.kebabCase(s)}`;this.container.style.setProperty(i,n)})}injectInputColors(){this.inputStyleElement&&this.inputStyleElement.remove(),this.inputStyleElement=document.createElement("style"),this.inputStyleElement.id="metakyc-input-colors",this.inputStyleElement.textContent=Gr(),this.customStyleElement&&this.customStyleElement.parentNode?document.head.insertBefore(this.inputStyleElement,this.customStyleElement):document.head.appendChild(this.inputStyleElement)}injectCustomCSS(r){this.customStyleElement&&this.customStyleElement.remove(),this.customStyleElement=document.createElement("style"),this.customStyleElement.id="metakyc-custom-css",this.customStyleElement.textContent=r,document.head.appendChild(this.customStyleElement)}mergeWithDefault(r){var s;return{name:r.name||Ne.name,title:r.title||Ne.title,logo:{...Ne.logo,...r.logo},colors:{...Ne.colors,...r.colors},typography:r.typography?{...Ne.typography,...r.typography}:Ne.typography,spacing:r.spacing?{...Ne.spacing,...r.spacing}:Ne.spacing,customCSS:r.customCSS,darkMode:r.darkMode?{colors:{...(s=Ne.darkMode)==null?void 0:s.colors,...r.darkMode.colors}}:Ne.darkMode,applicantFormVisibleFields:r.applicantFormVisibleFields,applicantFormRequiredFields:r.applicantFormRequiredFields,allowedLanguages:r.allowedLanguages,applicantFormPages:r.applicantFormPages,reviewPageFields:r.reviewPageFields,reviewPageDisabled:r.reviewPageDisabled,fieldLabelMode:r.fieldLabelMode,companyFormVisibleFields:r.companyFormVisibleFields,companyFormRequiredFields:r.companyFormRequiredFields,companyFormPages:r.companyFormPages,companyReviewPageFields:r.companyReviewPageFields}}getCurrentTheme(){return this.currentTheme}resetTheme(){this.applyTheme(Ne)}cleanup(){this.inputStyleElement&&(this.inputStyleElement.remove(),this.inputStyleElement=null),this.customStyleElement&&(this.customStyleElement.remove(),this.customStyleElement=null)}kebabCase(r){return r.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}}const gt=o.createContext(null),Jr=({config:t,children:r})=>{const[s,n]=o.useState(null),i=o.useRef(!1),l=o.useRef(!1),c=o.useMemo(()=>{const m=new Ut(t),u=new Kt(m),x=new qt(m),P=new Vt(m),b=new Yt(m),A=new Qt(m),F=new Gt(m),j=new Jt(m),N=new Zt(m),M=new Xt(m),Y=new ir(m),L=new yr;return{httpClient:m,applicantService:u,questionnaireService:x,uploadDocumentService:P,appropriatenessTestService:b,overviewService:A,riskScoringService:F,identityService:j,baseInformationService:N,investorCategorizationService:M,themeService:Y,themeManager:L}},[t]),d=o.useMemo(()=>({config:t,...c,currentTheme:s,createOrchestrator:()=>new dr(c.applicantService,c.questionnaireService,c.uploadDocumentService,c.appropriatenessTestService,c.overviewService,c.riskScoringService,c.identityService,c.investorCategorizationService)}),[t,c,s]);return o.useEffect(()=>((async()=>{if(i.current||l.current){console.log("[MetaKYC] Theme already loading or loaded, skipping...");return}i.current=!0;try{if(t.theme){console.log("[MetaKYC] Applying static theme from config"),c.themeManager.applyTheme(t.theme),n(c.themeManager.getCurrentTheme()),l.current=!0;return}console.log("[MetaKYC] Fetching theme from backend...");const u=await c.themeService.getThemeConfiguration();c.themeManager.applyTheme(u),n(c.themeManager.getCurrentTheme()),l.current=!0,console.log("[MetaKYC] Theme loaded and applied",u)}catch(u){console.warn("[MetaKYC] Failed to load theme, using default:",u),n(c.themeManager.getCurrentTheme()),l.current=!0}finally{i.current=!1}})(),()=>{c.themeManager.cleanup()}),[]),e.jsx(gt.Provider,{value:d,children:r})};function Ce(){const t=o.useContext(gt);if(!t)throw new Error("useMetaKYC must be used within a MetaKYCProvider");return t}async function xr(t){return new Promise((r,s)=>{const n=new FileReader;n.readAsDataURL(t),n.onload=()=>{const l=n.result.split(",")[1];r(l)},n.onerror=i=>s(i)})}function Zr(t,r){return t.size<=r}function Xr(t,r){return r.split(",").map(n=>n.trim()).some(n=>{if(n.endsWith("/*")){const i=n.slice(0,-2);return t.type.startsWith(i)}return t.type===n})}function dt(t){if(t===0)return"0 Bytes";const r=1024,s=["Bytes","KB","MB","GB"],n=Math.floor(Math.log(t)/Math.log(r));return Math.round(t/Math.pow(r,n)*100)/100+" "+s[n]}function es(t){return t}function we(...t){return t.filter(Boolean).join(" ")}const nt={APPLICANT_ID:"metakyc_applicant_id",WORKFLOW_STATE:"metakyc_workflow_state"};function hr(t){try{localStorage.setItem(nt.APPLICANT_ID,t.toString())}catch(r){console.warn("Failed to save applicant ID to storage:",r)}}function fr(){try{const t=localStorage.getItem(nt.APPLICANT_ID);return t?parseInt(t,10):null}catch(t){return console.warn("Failed to retrieve applicant ID from storage:",t),null}}function gr(){try{localStorage.removeItem(nt.APPLICANT_ID)}catch(t){console.warn("Failed to clear applicant ID from storage:",t)}}function br(t){try{localStorage.setItem(nt.WORKFLOW_STATE,JSON.stringify(t))}catch(r){console.warn("Failed to save workflow state to storage:",r)}}function ts(){try{const t=localStorage.getItem(nt.WORKFLOW_STATE);return t?JSON.parse(t):null}catch(t){return console.warn("Failed to retrieve workflow state from storage:",t),null}}function vr(){try{localStorage.removeItem(nt.WORKFLOW_STATE)}catch(t){console.warn("Failed to clear workflow state from storage:",t)}}function rs(){gr(),vr()}function kr(t){const{createOrchestrator:r}=Ce(),[s,n]=o.useState(null),[i,l]=o.useState(!1),[c,d]=o.useState(null),m=o.useRef(null),u=t||fr();o.useEffect(()=>{m.current||(m.current=r())},[r]),o.useEffect(()=>{var L;s&&u&&(hr(u),br({applicantId:u,currentStepOrder:(L=s.currentStep)==null?void 0:L.order,status:s.status,lastUpdated:new Date().toISOString(),workflowKey:s.workFlowKey,nextWorkflowKey:s.nextWorkflowKey}))},[s,u]);const x=o.useRef(!1),P=o.useRef(!1),b=o.useCallback(async()=>{if(!(!u||!m.current)){if(x.current){console.log("[Workflow] Load already in progress, skipping...");return}x.current=!0,l(!0),d(null);try{const L=await m.current.initialize(u);n(L),P.current=!0}catch(L){d(L)}finally{l(!1),x.current=!1}}},[u]);o.useEffect(()=>{u&&!P.current&&b()},[u,b]);const A=o.useCallback(async()=>{if(m.current){if(x.current){console.log("[Workflow] Refresh already in progress, skipping...");return}x.current=!0,l(!0),d(null);try{const L=await m.current.refreshProgress();n(L)}catch(L){d(L)}finally{l(!1),x.current=!1}}},[]),F=o.useCallback(async()=>{if(m.current){l(!0),d(null);try{const L=await m.current.moveToNextStep();n(L)}catch(L){d(L)}finally{l(!1)}}},[]),j=o.useCallback(async()=>{if(m.current){l(!0),d(null);try{const L=await m.current.moveToPreviousStep();n(L)}catch(L){d(L)}finally{l(!1)}}},[]),N=o.useCallback(async L=>{if(m.current){l(!0),d(null);try{await m.current.submitCurrentStep(L);const $=await m.current.refreshProgress();n($)}catch($){throw d($),$}finally{l(!1)}}},[]),M=jt.useMemo(()=>s!=null&&s.stepInfoList?[...s.stepInfoList].sort((L,$)=>L.order-$.order):[],[s==null?void 0:s.stepInfoList]),Y=jt.useMemo(()=>s?s.nextWorkflowKey&&s.nextWorkflowKey!==s.workFlowKey:!1,[s]);return{progress:s,applicantId:u,currentStep:(s==null?void 0:s.currentStep)||null,steps:M,status:(s==null?void 0:s.status)||Ae.None,workflowResult:(s==null?void 0:s.workflowResult)||null,workflowKey:s==null?void 0:s.workFlowKey,nextWorkflowKey:s==null?void 0:s.nextWorkflowKey,hasWorkflowChanged:Y,isLoading:i,error:c,isComplete:(s==null?void 0:s.status)===Ae.Finished,isOnHold:(s==null?void 0:s.status)===Ae.OnHold,refreshProgress:A,moveToNext:F,moveBack:j,submitCurrentStep:N,orchestrator:m.current}}function jr(t){const{questionnaireService:r,applicantService:s}=Ce(),[n,i]=o.useState(null),[l,c]=o.useState({}),[d,m]=o.useState(!1),[u,x]=o.useState(!1),[P,b]=o.useState(null),A=o.useRef(!1),F=o.useRef(null),j=o.useCallback(async()=>{var M,Y;if(t){if(A.current){console.log("[Questionnaire] Load already in progress, skipping...");return}A.current=!0,m(!0),b(null);try{const[L,$]=await Promise.all([r.getQuestionnaire(t),s.getApplicantData(t).catch(()=>null)]);if(i(L),(M=$==null?void 0:$.questionnaireResults)!=null&&M.length&&L){const K=new Map;for(const f of $.questionnaireResults)f.question&&((Y=f.answers)!=null&&Y.length)&&K.set(f.question.trim().toLowerCase(),f.answers);const ee={},I=L.questionGroups.flatMap(f=>f.questions??[]);for(const f of I){const O=f.text.trim().toLowerCase();K.has(O)&&(ee[f.id]=K.get(O))}c(ee)}F.current=t}catch(L){b(L)}finally{m(!1),A.current=!1}}},[t,r,s]);o.useEffect(()=>{t&&F.current!==t&&j()},[t]);const N=o.useCallback(async M=>{x(!0),b(null);try{return await r.fillQuestionnaire(M)}catch(Y){throw b(Y),Y}finally{x(!1)}},[r]);return{questionnaire:n,initialAnswers:l,isLoading:d,isSubmitting:u,error:P,load:j,submit:N}}function wr(t){const{uploadDocumentService:r}=Ce(),[s,n]=o.useState(null),[i,l]=o.useState(!1),[c,d]=o.useState(!1),[m,u]=o.useState(0),[x,P]=o.useState(null),b=o.useRef(!1),A=o.useRef(null),F=o.useCallback(async()=>{if(t){if(b.current){console.log("[UploadDocument] Load already in progress, skipping...");return}b.current=!0,l(!0),P(null);try{const N=await r.getUploadDocument(t);n(N),A.current=t}catch(N){P(N)}finally{l(!1),b.current=!1}}},[t,r]);o.useEffect(()=>{t&&A.current!==t&&F()},[t]);const j=o.useCallback(async N=>{d(!0),u(0),P(null);try{await r.fillUploadDocument(N),u(100)}catch(M){throw P(M),M}finally{d(!1)}},[r]);return{uploadDocument:s,isLoading:i,isSubmitting:c,uploadProgress:m,error:x,load:F,submit:j}}function ss(t){const{appropriatenessTestService:r}=Ce(),[s,n]=o.useState(null),[i,l]=o.useState(!1),[c,d]=o.useState(!1),[m,u]=o.useState(null),[x,P]=o.useState(null),b=o.useRef(!1),A=o.useRef(null),F=o.useCallback(async()=>{if(t){if(b.current){console.log("[AppropriatenessTest] Load already in progress, skipping...");return}b.current=!0,l(!0),u(null);try{const N=await r.getAppropriatenessTest(t);n(N),A.current=t}catch(N){u(N)}finally{l(!1),b.current=!1}}},[t,r]);o.useEffect(()=>{t&&A.current!==t&&F()},[t]);const j=o.useCallback(async N=>{d(!0),u(null);try{const M=await r.fillAppropriatenessTest(N);return P(M),M}catch(M){throw u(M),M}finally{d(!1)}},[r]);return{test:s,result:x,isLoading:i,isSubmitting:c,error:m,load:F,submit:j}}function Sr(t){const{overviewService:r}=Ce(),[s,n]=o.useState(null),[i,l]=o.useState(!1),[c,d]=o.useState(!1),[m,u]=o.useState(null),x=o.useRef(!1),P=o.useRef(null),b=o.useCallback(async()=>{if(t){if(x.current){console.log("[Overview] Load already in progress, skipping...");return}x.current=!0,l(!0),u(null);try{const F=await r.getOverviewData(t);n(F),P.current=t}catch(F){u(F)}finally{l(!1),x.current=!1}}},[t,r]);o.useEffect(()=>{t&&P.current!==t&&b()},[t]);const A=o.useCallback(async()=>{if(t){d(!0),u(null);try{await r.passOverview(t)}catch(F){throw u(F),F}finally{d(!1)}}},[t,r]);return{overview:s,isLoading:i,isSubmitting:c,error:m,load:b,passOverview:A}}function Cr(t){const{identityService:r}=Ce(),[s,n]=o.useState(null),[i,l]=o.useState(!1),[c,d]=o.useState(null),m=o.useRef(!1),u=o.useCallback(async(b,A)=>{if(t){if(m.current){console.log("[Identity] Request already in progress, skipping...");return}m.current=!0,l(!0),d(null);try{const F={applicantId:t,restart:!1,redirectUrl:b||"",ttl:A||604800};console.log("Identity request input:",F);const j=await r.identityRequest(F);return console.log("Identity request result:",j),n(j),j}catch(F){throw d(F),F}finally{l(!1),m.current=!1}}},[t,r]),x=o.useCallback(async(b,A)=>{if(t){l(!0),d(null);try{const F={applicantId:t,restart:!1,redirectUrl:b,ttl:A},j=await r.identityCompanyRequest(F);return n(j),j}catch(F){throw d(F),F}finally{l(!1)}}},[t,r]),P=o.useCallback(async()=>{if(t){if(m.current){console.log("[Identity] Restart already in progress, skipping...");return}m.current=!0,l(!0),d(null);try{const b={applicantId:t,restart:!0,redirectUrl:"",ttl:604800};console.log("Restarting identity with input:",b);const A=await r.identityRequest(b);return console.log("Restart identity result:",A),n(A),A}catch(b){throw d(b),b}finally{l(!1),m.current=!1}}},[t,r]);return{identityData:s,provider:(s==null?void 0:s.provider)||null,token:(s==null?void 0:s.publicProviderTokenObject)||null,isLoading:i,error:c,requestIdentity:u,requestCompanyIdentity:x,restartIdentity:P}}function Nr(t){const{riskScoringService:r,applicantService:s}=Ce(),[n,i]=o.useState(null),[l,c]=o.useState({}),[d,m]=o.useState(!1),[u,x]=o.useState(!1),[P,b]=o.useState(null),[A,F]=o.useState(null),j=o.useRef(!1),N=o.useRef(null),M=o.useCallback(async()=>{var L;if(t){if(j.current){console.log("[RiskScoring] Load already in progress, skipping...");return}j.current=!0,m(!0),b(null);try{const[$,K]=await Promise.all([r.getRiskCriterias(t),s.getApplicantData(t).catch(()=>null)]);if(i($),(L=K==null?void 0:K.riskScoringResults)!=null&&L.length){const ee=K.riskScoringResults[0],I={};for(const f of ee.riskCriteriaResults??[])if(f.riskCriteriaId!=null&&f.answer!=null&&f.answer!==""){const O=[...new Set(f.answer.split(",").map(q=>q.trim()).filter(q=>q!==""))];O.length>0&&(I[f.riskCriteriaId]=O)}c(I)}N.current=t}catch($){b($)}finally{m(!1),j.current=!1}}},[t,r,s]);o.useEffect(()=>{t&&N.current!==t&&M()},[t]);const Y=o.useCallback(async L=>{x(!0),b(null);try{const $=await r.submitRiskScoring(L);return F($),$}catch($){throw b($),$}finally{x(!1)}},[r]);return{criteria:n,initialAnswers:l,result:A,isLoading:d,isSubmitting:u,error:P,load:M,submit:Y}}function bt(){const{applicantService:t,config:r}=Ce(),[s,n]=o.useState(!1),[i,l]=o.useState(null),c=o.useRef(!1),d=o.useRef(!1),m=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(A){const F=Math.random()*16|0;return(A==="x"?F:F&3|8).toString(16)}),u=o.useCallback(async A=>{var F;if(c.current)throw console.log("[Applicant] Create already in progress, skipping..."),new Error("Creation already in progress");c.current=!0,n(!0),l(null);try{if(A.applicantAdditionalDatas||(A.applicantAdditionalDatas=[]),(F=r.identityProviders)!=null&&F.sardinai){const N=m();console.log("[SardinAI] Generated session key:",N),A.applicantAdditionalDatas.push({paramName:"sessionKey",value:N})}return await t.createApplicant(A)}catch(j){throw l(j),j}finally{n(!1),c.current=!1}},[t,r]),x=o.useCallback(async A=>{n(!0),l(null);try{return await t.createCompanyApplicant(A)}catch(F){throw l(F),F}finally{n(!1)}},[t]),P=o.useCallback(async A=>{if(d.current)throw console.log("[Applicant] Data load already in progress, skipping..."),new Error("Data load already in progress");d.current=!0,n(!0),l(null);try{return await t.getApplicantData(A)}catch(F){throw l(F),F}finally{n(!1),d.current=!1}},[t]),b=o.useCallback(async A=>{n(!0),l(null);try{await t.stopProgress(A)}catch(F){throw l(F),F}finally{n(!1)}},[t]);return{isLoading:s,error:i,createApplicant:u,createCompanyApplicant:x,getApplicantData:P,stopProgress:b}}const ns={primary:{backgroundColor:"var(--metakyc-primary, #2563eb)",color:"#ffffff",borderColor:"transparent"},secondary:{backgroundColor:"var(--metakyc-surface, #f3f4f6)",color:"var(--metakyc-text-primary, #111827)",borderColor:"var(--metakyc-border, #e5e7eb)"},outline:{backgroundColor:"transparent",color:"var(--metakyc-primary, #2563eb)",borderColor:"var(--metakyc-primary, #2563eb)"},danger:{backgroundColor:"var(--metakyc-danger, #ef4444)",color:"#ffffff",borderColor:"transparent"},ghost:{backgroundColor:"transparent",color:"var(--metakyc-text-secondary, #6b7280)",borderColor:"transparent"}},G=({children:t,variant:r="primary",size:s="md",isLoading:n=!1,disabled:i,className:l,style:c,...d})=>{const m="inline-flex items-center justify-center rounded-lg font-medium transition-opacity border focus:outline-none focus:ring-2 focus:ring-offset-1 disabled:opacity-50 disabled:cursor-not-allowed",u={sm:"px-3 py-1.5 text-sm",md:"px-4 py-2 text-sm",lg:"px-6 py-3 text-base"};return e.jsxs("button",{className:we(m,u[s],l),style:{...ns[r],...c},disabled:i||n,...d,children:[n&&e.jsxs("svg",{className:"animate-spin -ml-1 mr-2 h-4 w-4",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),t]})},me=o.forwardRef(({label:t,error:r,helperText:s,leftIcon:n,rightIcon:i,className:l,style:c,...d},m)=>e.jsxs("div",{className:"w-full",children:[t&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[t,d.required&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),e.jsxs("div",{className:"relative",children:[n&&e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:n}),e.jsx("input",{ref:m,className:we("block w-full rounded-lg border px-3 py-2 text-sm transition-colors","focus:outline-none focus:ring-2 focus:ring-offset-0","disabled:opacity-60 disabled:cursor-not-allowed",n?"pl-10":"",i?"pr-10":"",l),style:{backgroundColor:d.readOnly?"var(--metakyc-surface, #f3f4f6)":"var(--metakyc-input-bg, #ffffff)",color:"var(--metakyc-input-text, var(--metakyc-text-primary, #111827))",borderColor:r?"var(--metakyc-danger, #ef4444)":"var(--metakyc-input-border, var(--metakyc-border, #d1d5db))",cursor:d.readOnly?"default":void 0,...c},...d}),i&&e.jsx("div",{className:"absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none",children:i})]}),r&&e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-danger, #ef4444)"},children:r}),!r&&s&&e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:s})]}));me.displayName="Input";const Z=({children:t,className:r,...s})=>e.jsx("div",{className:we("metakyc-card rounded-xl shadow-sm border",r),style:{backgroundColor:"var(--metakyc-surface, #ffffff)",borderColor:"var(--metakyc-border, #e5e7eb)"},...s,children:t}),he=({children:t,className:r,...s})=>e.jsx("div",{className:we("px-6 py-4 border-b",r),style:{borderColor:"var(--metakyc-border, #e5e7eb)"},...s,children:t}),X=({children:t,className:r,...s})=>e.jsx("div",{className:we("px-6 py-4",r),...s,children:t}),fe=({children:t,className:r,...s})=>e.jsx("div",{className:we("px-6 py-4 border-t",r),style:{borderColor:"var(--metakyc-border, #e5e7eb)"},...s,children:t}),as={default:{backgroundColor:"var(--metakyc-surface, #f3f4f6)",color:"var(--metakyc-text-secondary, #6b7280)"},info:{backgroundColor:"var(--metakyc-primary-light, #dbeafe)",color:"var(--metakyc-primary, #2563eb)"},success:{backgroundColor:"#d1fae5",color:"#065f46"},danger:{backgroundColor:"#fee2e2",color:"#991b1b"},warning:{backgroundColor:"#fef3c7",color:"#92400e"}},vt=({children:t,variant:r="default",className:s,style:n,...i})=>e.jsx("span",{className:we("inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium",s),style:{...as[r],...n},...i,children:t}),Ie=({size:t="md",className:r,...s})=>{const n={sm:"h-4 w-4",md:"h-8 w-8",lg:"h-12 w-12"};return e.jsx("div",{className:we("flex items-center justify-center",r),...s,children:e.jsxs("svg",{className:we("animate-spin text-primary-500",n[t]),xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})})},pt=o.forwardRef(({label:t,error:r,helperText:s,options:n,placeholder:i,className:l,style:c,...d},m)=>e.jsxs("div",{className:"w-full",children:[t&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[t,d.required&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),e.jsxs("select",{ref:m,className:we("block w-full rounded-lg border px-3 py-2 text-sm transition-colors","focus:outline-none focus:ring-2 focus:ring-offset-0","disabled:opacity-60 disabled:cursor-not-allowed",r?"border-danger-500":"",l),style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:"var(--metakyc-input-text, var(--metakyc-text-primary, #111827))",borderColor:r?"var(--metakyc-danger, #ef4444)":"var(--metakyc-input-border, var(--metakyc-border, #d1d5db))",...c},...d,children:[i&&e.jsx("option",{value:"",disabled:!0,style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:"var(--metakyc-text-secondary, #6b7280)"},children:i},"__placeholder__"),n.map((u,x)=>e.jsx("option",{value:u.value,disabled:u.disabled,style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:u.disabled?"var(--metakyc-text-muted, #9ca3af)":"var(--metakyc-input-text, var(--metakyc-text-primary, #111827))"},children:u.label},u.value||`option-${x}`))]}),r&&e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-error, #ef4444)"},children:r}),!r&&s&&e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:s})]}));pt.displayName="Select";const wt=280,Rr=({label:t,value:r,onChange:s,options:n,placeholder:i="Select...",disabled:l=!1,readOnly:c=!1,required:d=!1})=>{const m=l||c,[u,x]=o.useState(!1),[P,b]=o.useState(""),[A,F]=o.useState(null),[j,N]=o.useState({bg:"#ffffff",borderColor:"#d1d5db",textPrimary:"#111827",textSecondary:"#6b7280",primaryColor:"#2563eb",primaryLight:"#eff6ff",hoverBg:"#f9fafb"}),M=o.useRef(null),Y=o.useRef(null),L=o.useRef(null),$=o.useCallback(()=>{if(!Y.current)return null;const E=Y.current.getBoundingClientRect(),z=window.innerHeight-E.bottom<wt&&E.top>wt;return{top:z?E.top:E.bottom+4,left:E.left,width:E.width,openUp:z}},[]),K=o.useCallback(()=>{const E=getComputedStyle(document.documentElement),W=(H,pe)=>E.getPropertyValue(H).trim()||pe,z=W("--metakyc-input-bg",W("--metakyc-background","#ffffff"));N({bg:z,borderColor:W("--metakyc-input-border",W("--metakyc-border","#d1d5db")),textPrimary:W("--metakyc-input-text",W("--metakyc-text-primary","#111827")),textSecondary:W("--metakyc-text-secondary","#6b7280"),primaryColor:W("--metakyc-primary","#2563eb"),primaryLight:W("--metakyc-primary-light","#eff6ff"),hoverBg:W("--metakyc-surface",z)})},[]),ee=o.useCallback(()=>{if(m)return;K();const E=$();E&&F(E),x(!0)},[m,$,K]),I=o.useCallback(()=>{x(!1),b("")},[]);o.useEffect(()=>{if(!u)return;const E=W=>{var H,pe;const z=W.target;!((H=M.current)!=null&&H.contains(z))&&!((pe=L.current)!=null&&pe.contains(z))&&I()};return document.addEventListener("mousedown",E),()=>document.removeEventListener("mousedown",E)},[u,I]),o.useEffect(()=>{if(!u)return;const E=()=>{const W=$();W&&F(W)};return window.addEventListener("scroll",E,!0),window.addEventListener("resize",E),()=>{window.removeEventListener("scroll",E,!0),window.removeEventListener("resize",E)}},[u,$]);const f=n.filter(E=>E.label.toLowerCase().includes(P.toLowerCase())),O=E=>{m||s(r.includes(E)?r.filter(W=>W!==E):[...r,E])},q=(E,W)=>{W.stopPropagation(),m||s(r.filter(z=>z!==E))},Q=E=>{var W;return((W=n.find(z=>z.value===E))==null?void 0:W.label)||E},{bg:B,borderColor:J,textPrimary:se,textSecondary:V,primaryColor:ge,primaryLight:ie,hoverBg:de}=j,be=u&&A&&e.jsxs("div",{ref:L,className:"metakyc-multiselect-dropdown",style:{position:"fixed",top:A.openUp?void 0:A.top,bottom:A.openUp?window.innerHeight-A.top+4:void 0,left:A.left,width:A.width,zIndex:99999,borderRadius:"8px",boxShadow:"0 4px 16px rgba(0,0,0,0.18)",border:`1px solid ${J}`,backgroundColor:B,overflow:"hidden"},children:[e.jsx("div",{style:{padding:"8px",borderBottom:`1px solid ${J}`},children:e.jsx("input",{type:"text",value:P,onChange:E=>b(E.target.value),placeholder:"Search...",autoFocus:!0,onClick:E=>E.stopPropagation(),className:"metakyc-multiselect-search w-full",style:{display:"block",width:"100%",padding:"6px 8px",fontSize:"13px",borderRadius:"6px",border:`1px solid ${J}`,backgroundColor:B,color:se,outline:"none",boxSizing:"border-box"},onFocus:E=>{const W=getComputedStyle(document.documentElement),z=W.getPropertyValue("--metakyc-input-border-focus").trim()||W.getPropertyValue("--metakyc-primary").trim()||"#2563eb";E.currentTarget.style.backgroundColor=B,E.currentTarget.style.color=se,E.currentTarget.style.borderColor=z,E.currentTarget.style.outline="none",E.currentTarget.style.boxShadow=`0 0 0 2px ${z}33`},onBlur:E=>{E.currentTarget.style.backgroundColor=B,E.currentTarget.style.color=se,E.currentTarget.style.borderColor=J,E.currentTarget.style.outline="none",E.currentTarget.style.boxShadow="none"}})}),e.jsx("ul",{style:{listStyle:"none",margin:0,padding:"4px 0",maxHeight:"192px",overflowY:"auto"},children:f.length===0?e.jsx("li",{style:{padding:"8px 12px",fontSize:"13px",color:V},children:"No results"}):f.map(E=>{const W=r.includes(E.value);return e.jsxs("li",{onClick:()=>O(E.value),className:"metakyc-multiselect-option",style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",fontSize:"13px",cursor:"pointer",backgroundColor:W?ie:"transparent",color:W?ge:se,userSelect:"none"},onMouseEnter:z=>{W||(z.currentTarget.style.backgroundColor=de)},onMouseLeave:z=>{W||(z.currentTarget.style.backgroundColor="transparent")},children:[e.jsx("input",{type:"checkbox",checked:W,readOnly:!0,style:{accentColor:ge,pointerEvents:"none",flexShrink:0}}),e.jsx("span",{children:E.label})]},E.value)})}),r.length>0&&e.jsx("div",{style:{padding:"6px 12px",borderTop:`1px solid ${J}`},children:e.jsxs("button",{type:"button",onClick:()=>{s([]),b("")},style:{fontSize:"12px",color:"#ef4444",background:"none",border:"none",cursor:"pointer",padding:0},children:["Clear all (",r.length," selected)"]})})]});return e.jsxs("div",{className:"w-full metakyc-multiselect",ref:M,children:[t&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[t,d&&e.jsx("span",{style:{color:"var(--metakyc-error, #ef4444)",marginLeft:"4px"},children:"*"})]}),e.jsxs("div",{ref:Y,onClick:()=>u?I():ee(),className:we("metakyc-multiselect-trigger","min-h-[42px] w-full px-3 py-2 rounded-lg border text-sm transition-colors relative",m?"opacity-50 cursor-not-allowed":"cursor-pointer"),style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",borderColor:u?"var(--metakyc-input-border-focus, var(--metakyc-primary, #2563eb))":"var(--metakyc-input-border, var(--metakyc-border, #d1d5db))",outline:u?"2px solid var(--metakyc-input-border-focus, var(--metakyc-primary, #2563eb))":"none",outlineOffset:"-1px"},children:[r.length===0?e.jsx("span",{className:"metakyc-multiselect-placeholder leading-6",style:{color:"var(--metakyc-text-secondary, #9ca3af)"},children:i}):e.jsx("div",{className:"flex flex-wrap gap-1 pr-6",children:r.map(E=>e.jsxs("span",{className:"metakyc-multiselect-chip inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium",style:{backgroundColor:"var(--metakyc-primary-light, #eff6ff)",color:"var(--metakyc-primary, #2563eb)"},children:[Q(E),!m&&e.jsx("button",{type:"button",onClick:W=>q(E,W),className:"metakyc-multiselect-chip-remove",style:{background:"transparent",border:"none",padding:"0 0 0 2px",margin:0,cursor:"pointer",fontSize:"14px",lineHeight:1,fontWeight:"bold",display:"inline-flex",alignItems:"center",boxShadow:"none",transform:"none",minWidth:0,width:"auto",height:"auto",letterSpacing:"normal",textTransform:"none"},children:"×"})]},E))}),e.jsx("span",{className:"metakyc-multiselect-arrow absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none text-xs",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:u?"▲":"▼"})]}),typeof document<"u"&&be?ut.createPortal(be,document.body):null]})},St=260,De=({label:t,error:r,helperText:s,options:n,placeholder:i="Select...",value:l,onChange:c,disabled:d=!1,readOnly:m=!1,required:u=!1,className:x})=>{var pe;const P=d||m,[b,A]=o.useState(!1),[F,j]=o.useState(""),[N,M]=o.useState(null),[Y,L]=o.useState({bg:"#ffffff",border:"#d1d5db",text:"#111827",textSecondary:"#6b7280",primary:"#2563eb",primaryLight:"#eff6ff",hoverBg:"#f9fafb"}),$=o.useCallback(()=>{const R=getComputedStyle(document.documentElement),te=(ye,ce)=>R.getPropertyValue(ye).trim()||ce,oe=te("--metakyc-input-bg",te("--metakyc-background","#ffffff"));L({bg:oe,border:te("--metakyc-input-border",te("--metakyc-border","#d1d5db")),text:te("--metakyc-input-text",te("--metakyc-text-primary","#111827")),textSecondary:te("--metakyc-text-secondary","#6b7280"),primary:te("--metakyc-primary","#2563eb"),primaryLight:te("--metakyc-primary-light","#eff6ff"),hoverBg:te("--metakyc-surface",oe)})},[]),K=o.useRef(null),ee=o.useRef(null),I=o.useRef(null),f=o.useRef(null),O=o.useCallback(()=>{if(!ee.current)return null;const R=ee.current.getBoundingClientRect(),oe=window.innerHeight-R.bottom<St&&R.top>St;return{top:oe?R.top:R.bottom+4,left:R.left,width:R.width,openUp:oe}},[]),q=o.useCallback(()=>{if(P)return;$();const R=O();R&&M(R),A(!0)},[P,O,$]),Q=o.useCallback(()=>{A(!1),j("")},[]),B=()=>b?Q():q();o.useEffect(()=>{if(!b)return;const R=te=>{var ye,ce;const oe=te.target;!((ye=K.current)!=null&&ye.contains(oe))&&!((ce=I.current)!=null&&ce.contains(oe))&&Q()};return document.addEventListener("mousedown",R),()=>document.removeEventListener("mousedown",R)},[b,Q]),o.useEffect(()=>{if(!b)return;const R=()=>{const te=O();te&&M(te)};return window.addEventListener("scroll",R,!0),window.addEventListener("resize",R),()=>{window.removeEventListener("scroll",R,!0),window.removeEventListener("resize",R)}},[b,O]),o.useEffect(()=>{b&&f.current&&setTimeout(()=>{var R;return(R=f.current)==null?void 0:R.focus()},0)},[b]);const J=n.filter(R=>R.label.toLowerCase().includes(F.toLowerCase())||R.value.toLowerCase().includes(F.toLowerCase())),se=(pe=n.find(R=>R.value===l))==null?void 0:pe.label,V=(R,te)=>{P||te||(c(R),Q())},{bg:ge,border:ie,text:de,textSecondary:be,primary:E,primaryLight:W,hoverBg:z}=Y,H=b&&N&&e.jsxs("div",{ref:I,className:"metakyc-searchable-select-dropdown",style:{position:"fixed",top:N.openUp?void 0:N.top,bottom:N.openUp?window.innerHeight-N.top+4:void 0,left:N.left,width:N.width,zIndex:99999,borderRadius:"8px",boxShadow:"0 4px 16px rgba(0,0,0,0.18)",border:`1px solid ${ie}`,backgroundColor:ge,overflow:"hidden"},children:[e.jsx("div",{style:{padding:"8px",borderBottom:`1px solid ${ie}`},children:e.jsx("input",{ref:f,type:"text",value:F,onChange:R=>j(R.target.value),placeholder:"Search...",onClick:R=>R.stopPropagation(),className:"metakyc-searchable-select-search w-full",style:{display:"block",width:"100%",padding:"6px 8px",fontSize:"13px",borderRadius:"6px",border:`1px solid ${ie}`,backgroundColor:ge,color:de,outline:"none",boxSizing:"border-box"},onFocus:R=>{const te=getComputedStyle(document.documentElement),oe=te.getPropertyValue("--metakyc-input-border-focus").trim()||te.getPropertyValue("--metakyc-primary").trim()||"#2563eb";R.currentTarget.style.backgroundColor=ge,R.currentTarget.style.color=de,R.currentTarget.style.borderColor=oe,R.currentTarget.style.outline="none",R.currentTarget.style.boxShadow=`0 0 0 2px ${oe}33`},onBlur:R=>{R.currentTarget.style.backgroundColor=ge,R.currentTarget.style.color=de,R.currentTarget.style.borderColor=ie,R.currentTarget.style.outline="none",R.currentTarget.style.boxShadow="none"}})}),e.jsx("ul",{style:{listStyle:"none",margin:0,padding:"4px 0",maxHeight:"208px",overflowY:"auto"},children:J.length===0?e.jsx("li",{style:{padding:"8px 12px",fontSize:"13px",color:be},children:"No results"}):J.map(R=>{const te=R.value===l;return e.jsx("li",{className:"metakyc-searchable-select-option",onClick:()=>V(R.value,R.disabled),style:{padding:"8px 12px",fontSize:"13px",cursor:R.disabled?"not-allowed":"pointer",opacity:R.disabled?.4:1,backgroundColor:te?W:"transparent",color:te?E:de,userSelect:"none"},onMouseEnter:oe=>{!te&&!R.disabled&&(oe.currentTarget.style.backgroundColor=z)},onMouseLeave:oe=>{te||(oe.currentTarget.style.backgroundColor="transparent")},children:R.label},R.value)})})]});return e.jsxs("div",{className:we("w-full metakyc-searchable-select",x),ref:K,children:[t&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[t,u&&e.jsx("span",{style:{color:"var(--metakyc-error, #ef4444)",marginLeft:"4px"},children:"*"})]}),e.jsxs("div",{ref:ee,role:"button",tabIndex:P?-1:0,onClick:B,onKeyDown:R=>{(R.key==="Enter"||R.key===" ")&&(R.preventDefault(),B()),R.key==="Escape"&&Q()},className:we("metakyc-searchable-select-trigger","w-full px-3 py-2 rounded-lg border text-sm transition-colors text-left","flex items-center justify-between gap-2","focus:outline-none",P?"opacity-60 cursor-not-allowed":"cursor-pointer"),style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:se?"var(--metakyc-input-text, var(--metakyc-text-primary, #111827))":"var(--metakyc-input-placeholder, var(--metakyc-text-muted, #9ca3af))",borderColor:r?"var(--metakyc-danger, #ef4444)":b?"var(--metakyc-input-border-focus, var(--metakyc-primary, #2563eb))":"var(--metakyc-input-border, var(--metakyc-border, #d1d5db))",minHeight:"42px",outline:b?"2px solid var(--metakyc-input-border-focus, var(--metakyc-primary, #2563eb))":"none",outlineOffset:"-1px"},children:[e.jsx("span",{className:"truncate flex-1",children:se||i}),e.jsx("span",{className:"flex-shrink-0 text-xs pointer-events-none",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:b?"▲":"▼"})]}),typeof document<"u"&&H?ut.createPortal(H,document.body):null,r&&e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-error, #ef4444)"},children:r}),!r&&s&&e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:s})]})};De.displayName="SearchableSelect";function is(t){const r=t.type;return r.startsWith("image/")?"image":r==="application/pdf"?"pdf":"file"}const Ir=({label:t,subtitle:r,error:s,accept:n,multiple:i=!1,maxSize:l,required:c,onChange:d,value:m=[],className:u})=>{const[x,P]=o.useState(!1),[b,A]=o.useState(null),F=o.useRef(null),j=o.useCallback(I=>{if(!I)return;A(null);const f=Array.from(I);if(l&&f.filter(q=>q.size>l).length>0){A(`File exceeds the maximum size of ${dt(l)}`);return}d==null||d(i?[...m,...f]:[f[0]])},[l,i,d,m]),N=o.useCallback(I=>{I.preventDefault(),I.stopPropagation(),P(!0)},[]),M=o.useCallback(I=>{I.preventDefault(),I.stopPropagation(),P(!1)},[]),Y=o.useCallback(I=>{I.preventDefault(),I.stopPropagation(),P(!1),j(I.dataTransfer.files)},[j]),L=()=>{var I;(I=F.current)==null||I.click()},$=I=>{A(null);const f=m.filter((O,q)=>q!==I);d==null||d(f)},K=s||b,ee=m.length>0;return e.jsxs("div",{className:we("metakyc-file-upload",u),style:{width:"100%"},children:[t&&e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"14px",fontWeight:600,color:"var(--metakyc-text-primary, #111827)"},children:[t,c&&e.jsx("span",{style:{color:"var(--metakyc-danger, #ef4444)",marginLeft:"2px"},children:"*"})]}),r&&e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"2px"},children:r})]}),e.jsxs("div",{className:"metakyc-file-dropzone",onClick:L,onDragOver:N,onDragLeave:M,onDrop:Y,style:{border:`2px dashed ${K?"var(--metakyc-danger, #ef4444)":x?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #d1d5db)"}`,borderRadius:"12px",padding:ee?"20px":"32px 20px",textAlign:"center",cursor:"pointer",transition:"all 0.2s ease",backgroundColor:x?"color-mix(in srgb, var(--metakyc-primary, #2563eb) 5%, var(--metakyc-background, #ffffff))":"var(--metakyc-background, #ffffff)"},children:[e.jsx("input",{ref:F,type:"file",style:{display:"none"},accept:n,multiple:i,onChange:I=>{j(I.target.files),I.target.value=""}}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"12px"},children:[e.jsx("div",{style:{width:"48px",height:"48px",borderRadius:"12px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:x?"color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)":"var(--metakyc-surface, #f9fafb)",transition:"background-color 0.2s ease"},children:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:x?"var(--metakyc-primary, #2563eb)":"var(--metakyc-text-muted, #9ca3af)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{transition:"stroke 0.2s ease"},children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"17 8 12 3 7 8"}),e.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"15"})]})}),e.jsxs("div",{children:[e.jsxs("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",margin:0},children:[e.jsx("span",{style:{fontWeight:600,color:"var(--metakyc-primary, #2563eb)"},children:"Click to upload"})," ","or drag and drop"]}),(n||l)&&e.jsxs("p",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"4px"},children:[n&&e.jsx("span",{children:n}),n&&l&&e.jsx("span",{children:" · "}),l&&e.jsxs("span",{children:["Max ",dt(l)]})]})]})]})]}),ee&&e.jsx("div",{style:{marginTop:"12px",display:"flex",flexDirection:"column",gap:"8px"},children:m.map((I,f)=>{const O=is(I),q=O==="image",Q=q?URL.createObjectURL(I):null;return e.jsxs("div",{className:"metakyc-file-item",style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 12px",borderRadius:"10px",backgroundColor:"var(--metakyc-surface, #f9fafb)",border:"1px solid var(--metakyc-border, #e5e7eb)",transition:"background-color 0.15s ease"},children:[e.jsx("div",{style:{width:"40px",height:"40px",borderRadius:"8px",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden",backgroundColor:q?"transparent":"color-mix(in srgb, var(--metakyc-primary, #2563eb) 10%, transparent)"},children:q&&Q?e.jsx("img",{src:Q,alt:I.name,style:{width:"100%",height:"100%",objectFit:"cover",borderRadius:"8px"}}):O==="pdf"?e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"}),e.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),e.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"}),e.jsx("polyline",{points:"10 9 9 9 8 9"})]}):e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-primary, #2563eb)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("p",{style:{fontSize:"13px",fontWeight:500,color:"var(--metakyc-text-primary, #111827)",margin:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:I.name}),e.jsx("p",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)",margin:0,marginTop:"2px"},children:dt(I.size)})]}),e.jsx("button",{type:"button",onClick:B=>{B.stopPropagation(),$(f)},style:{display:"flex",alignItems:"center",justifyContent:"center",width:"28px",height:"28px",borderRadius:"6px",border:"none",backgroundColor:"transparent",color:"var(--metakyc-text-muted, #9ca3af)",cursor:"pointer",flexShrink:0,transition:"all 0.15s ease",padding:0},onMouseEnter:B=>{B.currentTarget.style.backgroundColor="color-mix(in srgb, var(--metakyc-danger, #ef4444) 10%, transparent)",B.currentTarget.style.color="var(--metakyc-danger, #ef4444)"},onMouseLeave:B=>{B.currentTarget.style.backgroundColor="transparent",B.currentTarget.style.color="var(--metakyc-text-muted, #9ca3af)"},children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},`${I.name}-${f}`)})}),K&&e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",marginTop:"6px"},children:K})]})},Er=o.forwardRef(({countryCode:t="+1",onCountryCodeChange:r,className:s,...n},i)=>e.jsxs("div",{className:"w-full",children:[n.label&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[n.label,n.required&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:t,onChange:l=>r==null?void 0:r(l.target.value),className:we("w-20 rounded-lg border px-3 py-2 text-sm","focus:outline-none focus:ring-2 focus:ring-offset-0"),style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:"var(--metakyc-text-primary, #111827)",borderColor:"var(--metakyc-border, #d1d5db)"},placeholder:"+1"}),e.jsx(me,{ref:i,type:"tel",className:we("flex-1",s),...n,label:""})]}),n.error&&e.jsx("p",{className:"mt-1 text-sm text-danger-500",children:n.error})]}));Er.displayName="PhoneInput";/**
|
|
32
|
+
`}class yr{constructor(r){pe(this,"currentTheme",Re);pe(this,"customStyleElement",null);pe(this,"inputStyleElement",null);pe(this,"container");this.container=r||document.documentElement}applyTheme(r){this.currentTheme=this.mergeWithDefault(r),this.applyColors(this.currentTheme.colors),this.currentTheme.typography&&this.applyTypography(this.currentTheme.typography),this.currentTheme.spacing&&this.applySpacing(this.currentTheme.spacing),this.currentTheme.customCSS&&this.injectCustomCSS(this.currentTheme.customCSS),console.log("[ThemeManager] Theme applied:",this.currentTheme.name||"Custom")}applyColors(r){var n;const s={primary:r.primary,"primary-hover":r.primaryHover,"primary-light":r.primaryLight,"primary-dark":r.primaryDark,secondary:r.secondary,"secondary-hover":r.secondaryHover,success:r.success,warning:r.warning,danger:r.danger,info:r.info,background:r.background,surface:r.surface,border:r.border,"text-primary":r.textPrimary,"text-secondary":r.textSecondary,"text-muted":r.textMuted,"input-bg":r.inputBg||r.background,"input-text":r.inputText||r.textPrimary,"input-border":r.inputBorder||r.border,"input-border-focus":r.inputBorderFocus||r.primary,"input-placeholder":r.inputPlaceholder||r.textMuted};Object.entries(s).forEach(([a,l])=>{l&&this.container.style.setProperty(`--metakyc-${a}`,l)}),this.injectInputColors(),(n=this.currentTheme.darkMode)!=null&&n.colors&&this.applyDarkModeColors(this.currentTheme.darkMode.colors)}applyDarkModeColors(r){Object.entries(r).forEach(([s,n])=>{if(n){const a=`--metakyc-dark-${this.kebabCase(s)}`;this.container.style.setProperty(a,n)}})}applyTypography(r){r&&(r.fontFamily&&this.container.style.setProperty("--metakyc-font-family",r.fontFamily),r.headingFont&&this.container.style.setProperty("--metakyc-heading-font",r.headingFont),r.fontSize&&Object.entries(r.fontSize).forEach(([s,n])=>{this.container.style.setProperty(`--metakyc-font-size-${s}`,n)}),r.fontWeight&&Object.entries(r.fontWeight).forEach(([s,n])=>{this.container.style.setProperty(`--metakyc-font-weight-${s}`,n.toString())}))}applySpacing(r){r&&Object.entries(r).forEach(([s,n])=>{const a=`--metakyc-${this.kebabCase(s)}`;this.container.style.setProperty(a,n)})}injectInputColors(){this.inputStyleElement&&this.inputStyleElement.remove(),this.inputStyleElement=document.createElement("style"),this.inputStyleElement.id="metakyc-input-colors",this.inputStyleElement.textContent=Gr(),this.customStyleElement&&this.customStyleElement.parentNode?document.head.insertBefore(this.inputStyleElement,this.customStyleElement):document.head.appendChild(this.inputStyleElement)}injectCustomCSS(r){this.customStyleElement&&this.customStyleElement.remove(),this.customStyleElement=document.createElement("style"),this.customStyleElement.id="metakyc-custom-css",this.customStyleElement.textContent=r,document.head.appendChild(this.customStyleElement)}mergeWithDefault(r){var s;return{name:r.name||Re.name,title:r.title||Re.title,logo:{...Re.logo,...r.logo},colors:{...Re.colors,...r.colors},typography:r.typography?{...Re.typography,...r.typography}:Re.typography,spacing:r.spacing?{...Re.spacing,...r.spacing}:Re.spacing,customCSS:r.customCSS,darkMode:r.darkMode?{colors:{...(s=Re.darkMode)==null?void 0:s.colors,...r.darkMode.colors}}:Re.darkMode,applicantFormVisibleFields:r.applicantFormVisibleFields,applicantFormRequiredFields:r.applicantFormRequiredFields,allowedLanguages:r.allowedLanguages,applicantFormPages:r.applicantFormPages,reviewPageFields:r.reviewPageFields,reviewPageDisabled:r.reviewPageDisabled,fieldLabelMode:r.fieldLabelMode,companyFormVisibleFields:r.companyFormVisibleFields,companyFormRequiredFields:r.companyFormRequiredFields,companyFormPages:r.companyFormPages,companyReviewPageFields:r.companyReviewPageFields}}getCurrentTheme(){return this.currentTheme}resetTheme(){this.applyTheme(Re)}cleanup(){this.inputStyleElement&&(this.inputStyleElement.remove(),this.inputStyleElement=null),this.customStyleElement&&(this.customStyleElement.remove(),this.customStyleElement=null)}kebabCase(r){return r.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}}const gt=i.createContext(null),Jr=({config:t,children:r})=>{const[s,n]=i.useState(null),a=i.useRef(!1),l=i.useRef(!1),c=i.useMemo(()=>{const y=new Ut(t),p=new Kt(y),b=new qt(y),T=new Vt(y),v=new Yt(y),E=new Qt(y),A=new Gt(y),k=new Jt(y),S=new Zt(y),M=new Xt(y),Y=new ir(y),L=new yr;return{httpClient:y,applicantService:p,questionnaireService:b,uploadDocumentService:T,appropriatenessTestService:v,overviewService:E,riskScoringService:A,identityService:k,baseInformationService:S,investorCategorizationService:M,themeService:Y,themeManager:L}},[t]),u=i.useMemo(()=>({config:t,...c,currentTheme:s,createOrchestrator:()=>new dr(c.applicantService,c.questionnaireService,c.uploadDocumentService,c.appropriatenessTestService,c.overviewService,c.riskScoringService,c.identityService,c.investorCategorizationService)}),[t,c,s]);return i.useEffect(()=>((async()=>{if(a.current||l.current){console.log("[MetaKYC] Theme already loading or loaded, skipping...");return}a.current=!0;try{if(t.theme){console.log("[MetaKYC] Applying static theme from config"),c.themeManager.applyTheme(t.theme),n(c.themeManager.getCurrentTheme()),l.current=!0;return}console.log("[MetaKYC] Fetching theme from backend...");const p=await c.themeService.getThemeConfiguration();c.themeManager.applyTheme(p),n(c.themeManager.getCurrentTheme()),l.current=!0,console.log("[MetaKYC] Theme loaded and applied",p)}catch(p){console.warn("[MetaKYC] Failed to load theme, using default:",p),n(c.themeManager.getCurrentTheme()),l.current=!0}finally{a.current=!1}})(),()=>{c.themeManager.cleanup()}),[]),e.jsx(gt.Provider,{value:u,children:r})};function Ne(){const t=i.useContext(gt);if(!t)throw new Error("useMetaKYC must be used within a MetaKYCProvider");return t}async function xr(t){return new Promise((r,s)=>{const n=new FileReader;n.readAsDataURL(t),n.onload=()=>{const l=n.result.split(",")[1];r(l)},n.onerror=a=>s(a)})}function Zr(t,r){return t.size<=r}function Xr(t,r){return r.split(",").map(n=>n.trim()).some(n=>{if(n.endsWith("/*")){const a=n.slice(0,-2);return t.type.startsWith(a)}return t.type===n})}function dt(t){if(t===0)return"0 Bytes";const r=1024,s=["Bytes","KB","MB","GB"],n=Math.floor(Math.log(t)/Math.log(r));return Math.round(t/Math.pow(r,n)*100)/100+" "+s[n]}function es(t){return t}function Se(...t){return t.filter(Boolean).join(" ")}const nt={APPLICANT_ID:"metakyc_applicant_id",WORKFLOW_STATE:"metakyc_workflow_state"};function hr(t){try{localStorage.setItem(nt.APPLICANT_ID,t.toString())}catch(r){console.warn("Failed to save applicant ID to storage:",r)}}function fr(){try{const t=localStorage.getItem(nt.APPLICANT_ID);return t?parseInt(t,10):null}catch(t){return console.warn("Failed to retrieve applicant ID from storage:",t),null}}function gr(){try{localStorage.removeItem(nt.APPLICANT_ID)}catch(t){console.warn("Failed to clear applicant ID from storage:",t)}}function br(t){try{localStorage.setItem(nt.WORKFLOW_STATE,JSON.stringify(t))}catch(r){console.warn("Failed to save workflow state to storage:",r)}}function ts(){try{const t=localStorage.getItem(nt.WORKFLOW_STATE);return t?JSON.parse(t):null}catch(t){return console.warn("Failed to retrieve workflow state from storage:",t),null}}function vr(){try{localStorage.removeItem(nt.WORKFLOW_STATE)}catch(t){console.warn("Failed to clear workflow state from storage:",t)}}function rs(){gr(),vr()}function kr(t){const{createOrchestrator:r}=Ne(),[s,n]=i.useState(null),[a,l]=i.useState(!1),[c,u]=i.useState(null),y=i.useRef(null),p=t||fr();i.useEffect(()=>{y.current||(y.current=r())},[r]),i.useEffect(()=>{var L;s&&p&&(hr(p),br({applicantId:p,currentStepOrder:(L=s.currentStep)==null?void 0:L.order,status:s.status,lastUpdated:new Date().toISOString(),workflowKey:s.workFlowKey,nextWorkflowKey:s.nextWorkflowKey}))},[s,p]);const b=i.useRef(!1),T=i.useRef(!1),v=i.useCallback(async()=>{if(!(!p||!y.current)){if(b.current){console.log("[Workflow] Load already in progress, skipping...");return}b.current=!0,l(!0),u(null);try{const L=await y.current.initialize(p);n(L),T.current=!0}catch(L){u(L)}finally{l(!1),b.current=!1}}},[p]);i.useEffect(()=>{p&&!T.current&&v()},[p,v]);const E=i.useCallback(async()=>{if(y.current){if(b.current){console.log("[Workflow] Refresh already in progress, skipping...");return}b.current=!0,l(!0),u(null);try{const L=await y.current.refreshProgress();n(L)}catch(L){u(L)}finally{l(!1),b.current=!1}}},[]),A=i.useCallback(async()=>{if(y.current){l(!0),u(null);try{const L=await y.current.moveToNextStep();n(L)}catch(L){u(L)}finally{l(!1)}}},[]),k=i.useCallback(async()=>{if(y.current){l(!0),u(null);try{const L=await y.current.moveToPreviousStep();n(L)}catch(L){u(L)}finally{l(!1)}}},[]),S=i.useCallback(async L=>{if(y.current){l(!0),u(null);try{await y.current.submitCurrentStep(L);const _=await y.current.refreshProgress();n(_)}catch(_){throw u(_),_}finally{l(!1)}}},[]),M=jt.useMemo(()=>s!=null&&s.stepInfoList?[...s.stepInfoList].sort((L,_)=>L.order-_.order):[],[s==null?void 0:s.stepInfoList]),Y=jt.useMemo(()=>s?s.nextWorkflowKey&&s.nextWorkflowKey!==s.workFlowKey:!1,[s]);return{progress:s,applicantId:p,currentStep:(s==null?void 0:s.currentStep)||null,steps:M,status:(s==null?void 0:s.status)||Fe.None,workflowResult:(s==null?void 0:s.workflowResult)||null,workflowKey:s==null?void 0:s.workFlowKey,nextWorkflowKey:s==null?void 0:s.nextWorkflowKey,hasWorkflowChanged:Y,isLoading:a,error:c,isComplete:(s==null?void 0:s.status)===Fe.Finished,isOnHold:(s==null?void 0:s.status)===Fe.OnHold,refreshProgress:E,moveToNext:A,moveBack:k,submitCurrentStep:S,orchestrator:y.current}}function jr(t){const{questionnaireService:r,applicantService:s}=Ne(),[n,a]=i.useState(null),[l,c]=i.useState({}),[u,y]=i.useState(!1),[p,b]=i.useState(!1),[T,v]=i.useState(null),E=i.useRef(!1),A=i.useRef(null),k=i.useCallback(async()=>{var M,Y;if(t){if(E.current){console.log("[Questionnaire] Load already in progress, skipping...");return}E.current=!0,y(!0),v(null);try{const[L,_]=await Promise.all([r.getQuestionnaire(t),s.getApplicantData(t).catch(()=>null)]);if(a(L),(M=_==null?void 0:_.questionnaireResults)!=null&&M.length&&L){const U=new Map;for(const g of _.questionnaireResults)g.question&&((Y=g.answers)!=null&&Y.length)&&U.set(g.question.trim().toLowerCase(),g.answers);const te={},R=L.questionGroups.flatMap(g=>g.questions??[]);for(const g of R){const O=g.text.trim().toLowerCase();U.has(O)&&(te[g.id]=U.get(O))}c(te)}A.current=t}catch(L){v(L)}finally{y(!1),E.current=!1}}},[t,r,s]);i.useEffect(()=>{t&&A.current!==t&&k()},[t]);const S=i.useCallback(async M=>{b(!0),v(null);try{return await r.fillQuestionnaire(M)}catch(Y){throw v(Y),Y}finally{b(!1)}},[r]);return{questionnaire:n,initialAnswers:l,isLoading:u,isSubmitting:p,error:T,load:k,submit:S}}function wr(t){const{uploadDocumentService:r}=Ne(),[s,n]=i.useState(null),[a,l]=i.useState(!1),[c,u]=i.useState(!1),[y,p]=i.useState(0),[b,T]=i.useState(null),v=i.useRef(!1),E=i.useRef(null),A=i.useCallback(async()=>{if(t){if(v.current){console.log("[UploadDocument] Load already in progress, skipping...");return}v.current=!0,l(!0),T(null);try{const S=await r.getUploadDocument(t);n(S),E.current=t}catch(S){T(S)}finally{l(!1),v.current=!1}}},[t,r]);i.useEffect(()=>{t&&E.current!==t&&A()},[t]);const k=i.useCallback(async S=>{u(!0),p(0),T(null);try{await r.fillUploadDocument(S),p(100)}catch(M){throw T(M),M}finally{u(!1)}},[r]);return{uploadDocument:s,isLoading:a,isSubmitting:c,uploadProgress:y,error:b,load:A,submit:k}}function ss(t){const{appropriatenessTestService:r}=Ne(),[s,n]=i.useState(null),[a,l]=i.useState(!1),[c,u]=i.useState(!1),[y,p]=i.useState(null),[b,T]=i.useState(null),v=i.useRef(!1),E=i.useRef(null),A=i.useCallback(async()=>{if(t){if(v.current){console.log("[AppropriatenessTest] Load already in progress, skipping...");return}v.current=!0,l(!0),p(null);try{const S=await r.getAppropriatenessTest(t);n(S),E.current=t}catch(S){p(S)}finally{l(!1),v.current=!1}}},[t,r]);i.useEffect(()=>{t&&E.current!==t&&A()},[t]);const k=i.useCallback(async S=>{u(!0),p(null);try{const M=await r.fillAppropriatenessTest(S);return T(M),M}catch(M){throw p(M),M}finally{u(!1)}},[r]);return{test:s,result:b,isLoading:a,isSubmitting:c,error:y,load:A,submit:k}}function Sr(t){const{overviewService:r}=Ne(),[s,n]=i.useState(null),[a,l]=i.useState(!1),[c,u]=i.useState(!1),[y,p]=i.useState(null),b=i.useRef(!1),T=i.useRef(null),v=i.useCallback(async()=>{if(t){if(b.current){console.log("[Overview] Load already in progress, skipping...");return}b.current=!0,l(!0),p(null);try{const A=await r.getOverviewData(t);n(A),T.current=t}catch(A){p(A)}finally{l(!1),b.current=!1}}},[t,r]);i.useEffect(()=>{t&&T.current!==t&&v()},[t]);const E=i.useCallback(async()=>{if(t){u(!0),p(null);try{await r.passOverview(t)}catch(A){throw p(A),A}finally{u(!1)}}},[t,r]);return{overview:s,isLoading:a,isSubmitting:c,error:y,load:v,passOverview:E}}function Cr(t){const{identityService:r}=Ne(),[s,n]=i.useState(null),[a,l]=i.useState(!1),[c,u]=i.useState(null),y=i.useRef(!1),p=i.useCallback(async(v,E)=>{if(t){if(y.current){console.log("[Identity] Request already in progress, skipping...");return}y.current=!0,l(!0),u(null);try{const A={applicantId:t,restart:!1,redirectUrl:v||"",ttl:E||604800};console.log("Identity request input:",A);const k=await r.identityRequest(A);return console.log("Identity request result:",k),n(k),k}catch(A){throw u(A),A}finally{l(!1),y.current=!1}}},[t,r]),b=i.useCallback(async(v,E)=>{if(t){l(!0),u(null);try{const A={applicantId:t,restart:!1,redirectUrl:v,ttl:E},k=await r.identityCompanyRequest(A);return n(k),k}catch(A){throw u(A),A}finally{l(!1)}}},[t,r]),T=i.useCallback(async()=>{if(t){if(y.current){console.log("[Identity] Restart already in progress, skipping...");return}y.current=!0,l(!0),u(null);try{const v={applicantId:t,restart:!0,redirectUrl:"",ttl:604800};console.log("Restarting identity with input:",v);const E=await r.identityRequest(v);return console.log("Restart identity result:",E),n(E),E}catch(v){throw u(v),v}finally{l(!1),y.current=!1}}},[t,r]);return{identityData:s,provider:(s==null?void 0:s.provider)||null,token:(s==null?void 0:s.publicProviderTokenObject)||null,isLoading:a,error:c,requestIdentity:p,requestCompanyIdentity:b,restartIdentity:T}}function Nr(t){const{riskScoringService:r,applicantService:s}=Ne(),[n,a]=i.useState(null),[l,c]=i.useState({}),[u,y]=i.useState(!1),[p,b]=i.useState(!1),[T,v]=i.useState(null),[E,A]=i.useState(null),k=i.useRef(!1),S=i.useRef(null),M=i.useCallback(async()=>{var L;if(t){if(k.current){console.log("[RiskScoring] Load already in progress, skipping...");return}k.current=!0,y(!0),v(null);try{const[_,U]=await Promise.all([r.getRiskCriterias(t),s.getApplicantData(t).catch(()=>null)]);if(a(_),(L=U==null?void 0:U.riskScoringResults)!=null&&L.length){const te=U.riskScoringResults[0],R={};for(const g of te.riskCriteriaResults??[])if(g.riskCriteriaId!=null&&g.answer!=null&&g.answer!==""){const O=[...new Set(g.answer.split(",").map(q=>q.trim()).filter(q=>q!==""))];O.length>0&&(R[g.riskCriteriaId]=O)}c(R)}S.current=t}catch(_){v(_)}finally{y(!1),k.current=!1}}},[t,r,s]);i.useEffect(()=>{t&&S.current!==t&&M()},[t]);const Y=i.useCallback(async L=>{b(!0),v(null);try{const _=await r.submitRiskScoring(L);return A(_),_}catch(_){throw v(_),_}finally{b(!1)}},[r]);return{criteria:n,initialAnswers:l,result:E,isLoading:u,isSubmitting:p,error:T,load:M,submit:Y}}function bt(){const{applicantService:t,config:r}=Ne(),[s,n]=i.useState(!1),[a,l]=i.useState(null),c=i.useRef(!1),u=i.useRef(!1),y=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(E){const A=Math.random()*16|0;return(E==="x"?A:A&3|8).toString(16)}),p=i.useCallback(async E=>{var A;if(c.current)throw console.log("[Applicant] Create already in progress, skipping..."),new Error("Creation already in progress");c.current=!0,n(!0),l(null);try{if(E.applicantAdditionalDatas||(E.applicantAdditionalDatas=[]),(A=r.identityProviders)!=null&&A.sardinai){const S=y();console.log("[SardinAI] Generated session key:",S),E.applicantAdditionalDatas.push({paramName:"sessionKey",value:S})}return await t.createApplicant(E)}catch(k){throw l(k),k}finally{n(!1),c.current=!1}},[t,r]),b=i.useCallback(async E=>{n(!0),l(null);try{return await t.createCompanyApplicant(E)}catch(A){throw l(A),A}finally{n(!1)}},[t]),T=i.useCallback(async E=>{if(u.current)throw console.log("[Applicant] Data load already in progress, skipping..."),new Error("Data load already in progress");u.current=!0,n(!0),l(null);try{return await t.getApplicantData(E)}catch(A){throw l(A),A}finally{n(!1),u.current=!1}},[t]),v=i.useCallback(async E=>{n(!0),l(null);try{await t.stopProgress(E)}catch(A){throw l(A),A}finally{n(!1)}},[t]);return{isLoading:s,error:a,createApplicant:p,createCompanyApplicant:b,getApplicantData:T,stopProgress:v}}const ns={primary:{backgroundColor:"var(--metakyc-primary, #2563eb)",color:"#ffffff",borderColor:"transparent"},secondary:{backgroundColor:"var(--metakyc-surface, #f3f4f6)",color:"var(--metakyc-text-primary, #111827)",borderColor:"var(--metakyc-border, #e5e7eb)"},outline:{backgroundColor:"transparent",color:"var(--metakyc-primary, #2563eb)",borderColor:"var(--metakyc-primary, #2563eb)"},danger:{backgroundColor:"var(--metakyc-danger, #ef4444)",color:"#ffffff",borderColor:"transparent"},ghost:{backgroundColor:"transparent",color:"var(--metakyc-text-secondary, #6b7280)",borderColor:"transparent"}},G=({children:t,variant:r="primary",size:s="md",isLoading:n=!1,disabled:a,className:l,style:c,...u})=>{const y="inline-flex items-center justify-center rounded-lg font-medium transition-opacity border focus:outline-none focus:ring-2 focus:ring-offset-1 disabled:opacity-50 disabled:cursor-not-allowed",p={sm:"px-3 py-1.5 text-sm",md:"px-4 py-2 text-sm",lg:"px-6 py-3 text-base"};return e.jsxs("button",{className:Se(y,p[s],l),style:{...ns[r],...c},disabled:a||n,...u,children:[n&&e.jsxs("svg",{className:"animate-spin -ml-1 mr-2 h-4 w-4",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),t]})},ye=i.forwardRef(({label:t,error:r,helperText:s,leftIcon:n,rightIcon:a,className:l,style:c,...u},y)=>e.jsxs("div",{className:"w-full",children:[t&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[t,u.required&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),e.jsxs("div",{className:"relative",children:[n&&e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:n}),e.jsx("input",{ref:y,className:Se("block w-full rounded-lg border px-3 py-2 text-sm transition-colors","focus:outline-none focus:ring-2 focus:ring-offset-0","disabled:opacity-60 disabled:cursor-not-allowed",n?"pl-10":"",a?"pr-10":"",l),style:{backgroundColor:u.readOnly?"var(--metakyc-surface, #f3f4f6)":"var(--metakyc-input-bg, #ffffff)",color:"var(--metakyc-input-text, var(--metakyc-text-primary, #111827))",borderColor:r?"var(--metakyc-danger, #ef4444)":"var(--metakyc-input-border, var(--metakyc-border, #d1d5db))",cursor:u.readOnly?"default":void 0,...c},...u}),a&&e.jsx("div",{className:"absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none",children:a})]}),r&&e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-danger, #ef4444)"},children:r}),!r&&s&&e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:s})]}));ye.displayName="Input";const X=({children:t,className:r,...s})=>e.jsx("div",{className:Se("metakyc-card rounded-xl shadow-sm border",r),style:{backgroundColor:"var(--metakyc-surface, #ffffff)",borderColor:"var(--metakyc-border, #e5e7eb)"},...s,children:t}),he=({children:t,className:r,...s})=>e.jsx("div",{className:Se("px-6 py-4 border-b",r),style:{borderColor:"var(--metakyc-border, #e5e7eb)"},...s,children:t}),ee=({children:t,className:r,...s})=>e.jsx("div",{className:Se("px-6 py-4",r),...s,children:t}),fe=({children:t,className:r,...s})=>e.jsx("div",{className:Se("px-6 py-4 border-t",r),style:{borderColor:"var(--metakyc-border, #e5e7eb)"},...s,children:t}),as={default:{backgroundColor:"var(--metakyc-surface, #f3f4f6)",color:"var(--metakyc-text-secondary, #6b7280)"},info:{backgroundColor:"var(--metakyc-primary-light, #dbeafe)",color:"var(--metakyc-primary, #2563eb)"},success:{backgroundColor:"#d1fae5",color:"#065f46"},danger:{backgroundColor:"#fee2e2",color:"#991b1b"},warning:{backgroundColor:"#fef3c7",color:"#92400e"}},vt=({children:t,variant:r="default",className:s,style:n,...a})=>e.jsx("span",{className:Se("inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium",s),style:{...as[r],...n},...a,children:t}),Ee=({size:t="md",className:r,...s})=>{const n={sm:"h-4 w-4",md:"h-8 w-8",lg:"h-12 w-12"};return e.jsx("div",{className:Se("flex items-center justify-center",r),...s,children:e.jsxs("svg",{className:Se("animate-spin text-primary-500",n[t]),xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})})},pt=i.forwardRef(({label:t,error:r,helperText:s,options:n,placeholder:a,className:l,style:c,...u},y)=>e.jsxs("div",{className:"w-full",children:[t&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[t,u.required&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),e.jsxs("select",{ref:y,className:Se("block w-full rounded-lg border px-3 py-2 text-sm transition-colors","focus:outline-none focus:ring-2 focus:ring-offset-0","disabled:opacity-60 disabled:cursor-not-allowed",r?"border-danger-500":"",l),style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:"var(--metakyc-input-text, var(--metakyc-text-primary, #111827))",borderColor:r?"var(--metakyc-danger, #ef4444)":"var(--metakyc-input-border, var(--metakyc-border, #d1d5db))",...c},...u,children:[a&&e.jsx("option",{value:"",disabled:!0,style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:"var(--metakyc-text-secondary, #6b7280)"},children:a},"__placeholder__"),n.map((p,b)=>e.jsx("option",{value:p.value,disabled:p.disabled,style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:p.disabled?"var(--metakyc-text-muted, #9ca3af)":"var(--metakyc-input-text, var(--metakyc-text-primary, #111827))"},children:p.label},p.value||`option-${b}`))]}),r&&e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-error, #ef4444)"},children:r}),!r&&s&&e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:s})]}));pt.displayName="Select";const wt=280,Rr=({label:t,value:r,onChange:s,options:n,placeholder:a="Select...",disabled:l=!1,readOnly:c=!1,required:u=!1})=>{const y=l||c,[p,b]=i.useState(!1),[T,v]=i.useState(""),[E,A]=i.useState(null),[k,S]=i.useState({bg:"#ffffff",borderColor:"#d1d5db",textPrimary:"#111827",textSecondary:"#6b7280",primaryColor:"#2563eb",primaryLight:"#eff6ff",hoverBg:"#f9fafb"}),M=i.useRef(null),Y=i.useRef(null),L=i.useRef(null),_=i.useCallback(()=>{if(!Y.current)return null;const I=Y.current.getBoundingClientRect(),z=window.innerHeight-I.bottom<wt&&I.top>wt;return{top:z?I.top:I.bottom+4,left:I.left,width:I.width,openUp:z}},[]),U=i.useCallback(()=>{const I=getComputedStyle(document.documentElement),W=($,me)=>I.getPropertyValue($).trim()||me,z=W("--metakyc-input-bg",W("--metakyc-background","#ffffff"));S({bg:z,borderColor:W("--metakyc-input-border",W("--metakyc-border","#d1d5db")),textPrimary:W("--metakyc-input-text",W("--metakyc-text-primary","#111827")),textSecondary:W("--metakyc-text-secondary","#6b7280"),primaryColor:W("--metakyc-primary","#2563eb"),primaryLight:W("--metakyc-primary-light","#eff6ff"),hoverBg:W("--metakyc-surface",z)})},[]),te=i.useCallback(()=>{if(y)return;U();const I=_();I&&A(I),b(!0)},[y,_,U]),R=i.useCallback(()=>{b(!1),v("")},[]);i.useEffect(()=>{if(!p)return;const I=W=>{var $,me;const z=W.target;!(($=M.current)!=null&&$.contains(z))&&!((me=L.current)!=null&&me.contains(z))&&R()};return document.addEventListener("mousedown",I),()=>document.removeEventListener("mousedown",I)},[p,R]),i.useEffect(()=>{if(!p)return;const I=()=>{const W=_();W&&A(W)};return window.addEventListener("scroll",I,!0),window.addEventListener("resize",I),()=>{window.removeEventListener("scroll",I,!0),window.removeEventListener("resize",I)}},[p,_]);const g=n.filter(I=>I.label.toLowerCase().includes(T.toLowerCase())),O=I=>{y||s(r.includes(I)?r.filter(W=>W!==I):[...r,I])},q=(I,W)=>{W.stopPropagation(),y||s(r.filter(z=>z!==I))},Q=I=>{var W;return((W=n.find(z=>z.value===I))==null?void 0:W.label)||I},{bg:B,borderColor:J,textPrimary:ne,textSecondary:V,primaryColor:ge,primaryLight:le,hoverBg:de}=k,be=p&&E&&e.jsxs("div",{ref:L,className:"metakyc-multiselect-dropdown",style:{position:"fixed",top:E.openUp?void 0:E.top,bottom:E.openUp?window.innerHeight-E.top+4:void 0,left:E.left,width:E.width,zIndex:99999,borderRadius:"8px",boxShadow:"0 4px 16px rgba(0,0,0,0.18)",border:`1px solid ${J}`,backgroundColor:B,overflow:"hidden"},children:[e.jsx("div",{style:{padding:"8px",borderBottom:`1px solid ${J}`},children:e.jsx("input",{type:"text",value:T,onChange:I=>v(I.target.value),placeholder:"Search...",autoFocus:!0,onClick:I=>I.stopPropagation(),className:"metakyc-multiselect-search w-full",style:{display:"block",width:"100%",padding:"6px 8px",fontSize:"13px",borderRadius:"6px",border:`1px solid ${J}`,backgroundColor:B,color:ne,outline:"none",boxSizing:"border-box"},onFocus:I=>{const W=getComputedStyle(document.documentElement),z=W.getPropertyValue("--metakyc-input-border-focus").trim()||W.getPropertyValue("--metakyc-primary").trim()||"#2563eb";I.currentTarget.style.backgroundColor=B,I.currentTarget.style.color=ne,I.currentTarget.style.borderColor=z,I.currentTarget.style.outline="none",I.currentTarget.style.boxShadow=`0 0 0 2px ${z}33`},onBlur:I=>{I.currentTarget.style.backgroundColor=B,I.currentTarget.style.color=ne,I.currentTarget.style.borderColor=J,I.currentTarget.style.outline="none",I.currentTarget.style.boxShadow="none"}})}),e.jsx("ul",{style:{listStyle:"none",margin:0,padding:"4px 0",maxHeight:"192px",overflowY:"auto"},children:g.length===0?e.jsx("li",{style:{padding:"8px 12px",fontSize:"13px",color:V},children:"No results"}):g.map(I=>{const W=r.includes(I.value);return e.jsxs("li",{onClick:()=>O(I.value),className:"metakyc-multiselect-option",style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",fontSize:"13px",cursor:"pointer",backgroundColor:W?le:"transparent",color:W?ge:ne,userSelect:"none"},onMouseEnter:z=>{W||(z.currentTarget.style.backgroundColor=de)},onMouseLeave:z=>{W||(z.currentTarget.style.backgroundColor="transparent")},children:[e.jsx("input",{type:"checkbox",checked:W,readOnly:!0,style:{accentColor:ge,pointerEvents:"none",flexShrink:0}}),e.jsx("span",{children:I.label})]},I.value)})}),r.length>0&&e.jsx("div",{style:{padding:"6px 12px",borderTop:`1px solid ${J}`},children:e.jsxs("button",{type:"button",onClick:()=>{s([]),v("")},style:{fontSize:"12px",color:"#ef4444",background:"none",border:"none",cursor:"pointer",padding:0},children:["Clear all (",r.length," selected)"]})})]});return e.jsxs("div",{className:"w-full metakyc-multiselect",ref:M,children:[t&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[t,u&&e.jsx("span",{style:{color:"var(--metakyc-error, #ef4444)",marginLeft:"4px"},children:"*"})]}),e.jsxs("div",{ref:Y,onClick:()=>p?R():te(),className:Se("metakyc-multiselect-trigger","min-h-[42px] w-full px-3 py-2 rounded-lg border text-sm transition-colors relative",y?"opacity-50 cursor-not-allowed":"cursor-pointer"),style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",borderColor:p?"var(--metakyc-input-border-focus, var(--metakyc-primary, #2563eb))":"var(--metakyc-input-border, var(--metakyc-border, #d1d5db))",outline:p?"2px solid var(--metakyc-input-border-focus, var(--metakyc-primary, #2563eb))":"none",outlineOffset:"-1px"},children:[r.length===0?e.jsx("span",{className:"metakyc-multiselect-placeholder leading-6",style:{color:"var(--metakyc-text-secondary, #9ca3af)"},children:a}):e.jsx("div",{className:"flex flex-wrap gap-1 pr-6",children:r.map(I=>e.jsxs("span",{className:"metakyc-multiselect-chip inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium",style:{backgroundColor:"var(--metakyc-primary-light, #eff6ff)",color:"var(--metakyc-primary, #2563eb)"},children:[Q(I),!y&&e.jsx("button",{type:"button",onClick:W=>q(I,W),className:"metakyc-multiselect-chip-remove",style:{background:"transparent",border:"none",padding:"0 0 0 2px",margin:0,cursor:"pointer",fontSize:"14px",lineHeight:1,fontWeight:"bold",display:"inline-flex",alignItems:"center",boxShadow:"none",transform:"none",minWidth:0,width:"auto",height:"auto",letterSpacing:"normal",textTransform:"none"},children:"×"})]},I))}),e.jsx("span",{className:"metakyc-multiselect-arrow absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none text-xs",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:p?"▲":"▼"})]}),typeof document<"u"&&be?ut.createPortal(be,document.body):null]})},St=260,Me=({label:t,error:r,helperText:s,options:n,placeholder:a="Select...",value:l,onChange:c,disabled:u=!1,readOnly:y=!1,required:p=!1,className:b})=>{var me;const T=u||y,[v,E]=i.useState(!1),[A,k]=i.useState(""),[S,M]=i.useState(null),[Y,L]=i.useState({bg:"#ffffff",border:"#d1d5db",text:"#111827",textSecondary:"#6b7280",primary:"#2563eb",primaryLight:"#eff6ff",hoverBg:"#f9fafb"}),_=i.useCallback(()=>{const N=getComputedStyle(document.documentElement),re=(ae,ve)=>N.getPropertyValue(ae).trim()||ve,ue=re("--metakyc-input-bg",re("--metakyc-background","#ffffff"));L({bg:ue,border:re("--metakyc-input-border",re("--metakyc-border","#d1d5db")),text:re("--metakyc-input-text",re("--metakyc-text-primary","#111827")),textSecondary:re("--metakyc-text-secondary","#6b7280"),primary:re("--metakyc-primary","#2563eb"),primaryLight:re("--metakyc-primary-light","#eff6ff"),hoverBg:re("--metakyc-surface",ue)})},[]),U=i.useRef(null),te=i.useRef(null),R=i.useRef(null),g=i.useRef(null),O=i.useCallback(()=>{if(!te.current)return null;const N=te.current.getBoundingClientRect(),ue=window.innerHeight-N.bottom<St&&N.top>St;return{top:ue?N.top:N.bottom+4,left:N.left,width:N.width,openUp:ue}},[]),q=i.useCallback(()=>{if(T)return;_();const N=O();N&&M(N),E(!0)},[T,O,_]),Q=i.useCallback(()=>{E(!1),k("")},[]),B=()=>v?Q():q();i.useEffect(()=>{if(!v)return;const N=re=>{var ae,ve;const ue=re.target;!((ae=U.current)!=null&&ae.contains(ue))&&!((ve=R.current)!=null&&ve.contains(ue))&&Q()};return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},[v,Q]),i.useEffect(()=>{if(!v)return;const N=()=>{const re=O();re&&M(re)};return window.addEventListener("scroll",N,!0),window.addEventListener("resize",N),()=>{window.removeEventListener("scroll",N,!0),window.removeEventListener("resize",N)}},[v,O]),i.useEffect(()=>{v&&g.current&&setTimeout(()=>{var N;return(N=g.current)==null?void 0:N.focus()},0)},[v]);const J=n.filter(N=>N.label.toLowerCase().includes(A.toLowerCase())||N.value.toLowerCase().includes(A.toLowerCase())),ne=(me=n.find(N=>N.value===l))==null?void 0:me.label,V=(N,re)=>{T||re||(c(N),Q())},{bg:ge,border:le,text:de,textSecondary:be,primary:I,primaryLight:W,hoverBg:z}=Y,$=v&&S&&e.jsxs("div",{ref:R,className:"metakyc-searchable-select-dropdown",style:{position:"fixed",top:S.openUp?void 0:S.top,bottom:S.openUp?window.innerHeight-S.top+4:void 0,left:S.left,width:S.width,zIndex:99999,borderRadius:"8px",boxShadow:"0 4px 16px rgba(0,0,0,0.18)",border:`1px solid ${le}`,backgroundColor:ge,overflow:"hidden"},children:[e.jsx("div",{style:{padding:"8px",borderBottom:`1px solid ${le}`},children:e.jsx("input",{ref:g,type:"text",value:A,onChange:N=>k(N.target.value),placeholder:"Search...",onClick:N=>N.stopPropagation(),className:"metakyc-searchable-select-search w-full",style:{display:"block",width:"100%",padding:"6px 8px",fontSize:"13px",borderRadius:"6px",border:`1px solid ${le}`,backgroundColor:ge,color:de,outline:"none",boxSizing:"border-box"},onFocus:N=>{const re=getComputedStyle(document.documentElement),ue=re.getPropertyValue("--metakyc-input-border-focus").trim()||re.getPropertyValue("--metakyc-primary").trim()||"#2563eb";N.currentTarget.style.backgroundColor=ge,N.currentTarget.style.color=de,N.currentTarget.style.borderColor=ue,N.currentTarget.style.outline="none",N.currentTarget.style.boxShadow=`0 0 0 2px ${ue}33`},onBlur:N=>{N.currentTarget.style.backgroundColor=ge,N.currentTarget.style.color=de,N.currentTarget.style.borderColor=le,N.currentTarget.style.outline="none",N.currentTarget.style.boxShadow="none"}})}),e.jsx("ul",{style:{listStyle:"none",margin:0,padding:"4px 0",maxHeight:"208px",overflowY:"auto"},children:J.length===0?e.jsx("li",{style:{padding:"8px 12px",fontSize:"13px",color:be},children:"No results"}):J.map(N=>{const re=N.value===l;return e.jsx("li",{className:"metakyc-searchable-select-option",onClick:()=>V(N.value,N.disabled),style:{padding:"8px 12px",fontSize:"13px",cursor:N.disabled?"not-allowed":"pointer",opacity:N.disabled?.4:1,backgroundColor:re?W:"transparent",color:re?I:de,userSelect:"none"},onMouseEnter:ue=>{!re&&!N.disabled&&(ue.currentTarget.style.backgroundColor=z)},onMouseLeave:ue=>{re||(ue.currentTarget.style.backgroundColor="transparent")},children:N.label},N.value)})})]});return e.jsxs("div",{className:Se("w-full metakyc-searchable-select",b),ref:U,children:[t&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[t,p&&e.jsx("span",{style:{color:"var(--metakyc-error, #ef4444)",marginLeft:"4px"},children:"*"})]}),e.jsxs("div",{ref:te,role:"button",tabIndex:T?-1:0,onClick:B,onKeyDown:N=>{(N.key==="Enter"||N.key===" ")&&(N.preventDefault(),B()),N.key==="Escape"&&Q()},className:Se("metakyc-searchable-select-trigger","w-full px-3 py-2 rounded-lg border text-sm transition-colors text-left","flex items-center justify-between gap-2","focus:outline-none",T?"opacity-60 cursor-not-allowed":"cursor-pointer"),style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:ne?"var(--metakyc-input-text, var(--metakyc-text-primary, #111827))":"var(--metakyc-input-placeholder, var(--metakyc-text-muted, #9ca3af))",borderColor:r?"var(--metakyc-danger, #ef4444)":v?"var(--metakyc-input-border-focus, var(--metakyc-primary, #2563eb))":"var(--metakyc-input-border, var(--metakyc-border, #d1d5db))",minHeight:"42px",outline:v?"2px solid var(--metakyc-input-border-focus, var(--metakyc-primary, #2563eb))":"none",outlineOffset:"-1px"},children:[e.jsx("span",{className:"truncate flex-1",children:ne||a}),e.jsx("span",{className:"flex-shrink-0 text-xs pointer-events-none",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:v?"▲":"▼"})]}),typeof document<"u"&&$?ut.createPortal($,document.body):null,r&&e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-error, #ef4444)"},children:r}),!r&&s&&e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:s})]})};Me.displayName="SearchableSelect";function is(t){const r=t.type;return r.startsWith("image/")?"image":r==="application/pdf"?"pdf":"file"}const Ir=({label:t,subtitle:r,error:s,accept:n,multiple:a=!1,maxSize:l,required:c,onChange:u,value:y=[],className:p})=>{const[b,T]=i.useState(!1),[v,E]=i.useState(null),A=i.useRef(null),k=i.useCallback(R=>{if(!R)return;E(null);const g=Array.from(R);if(l&&g.filter(q=>q.size>l).length>0){E(`File exceeds the maximum size of ${dt(l)}`);return}u==null||u(a?[...y,...g]:[g[0]])},[l,a,u,y]),S=i.useCallback(R=>{R.preventDefault(),R.stopPropagation(),T(!0)},[]),M=i.useCallback(R=>{R.preventDefault(),R.stopPropagation(),T(!1)},[]),Y=i.useCallback(R=>{R.preventDefault(),R.stopPropagation(),T(!1),k(R.dataTransfer.files)},[k]),L=()=>{var R;(R=A.current)==null||R.click()},_=R=>{E(null);const g=y.filter((O,q)=>q!==R);u==null||u(g)},U=s||v,te=y.length>0;return e.jsxs("div",{className:Se("metakyc-file-upload",p),style:{width:"100%"},children:[t&&e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"14px",fontWeight:600,color:"var(--metakyc-text-primary, #111827)"},children:[t,c&&e.jsx("span",{style:{color:"var(--metakyc-danger, #ef4444)",marginLeft:"2px"},children:"*"})]}),r&&e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"2px"},children:r})]}),e.jsxs("div",{className:"metakyc-file-dropzone",onClick:L,onDragOver:S,onDragLeave:M,onDrop:Y,style:{border:`2px dashed ${U?"var(--metakyc-danger, #ef4444)":b?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #d1d5db)"}`,borderRadius:"12px",padding:te?"20px":"32px 20px",textAlign:"center",cursor:"pointer",transition:"all 0.2s ease",backgroundColor:b?"color-mix(in srgb, var(--metakyc-primary, #2563eb) 5%, var(--metakyc-background, #ffffff))":"var(--metakyc-background, #ffffff)"},children:[e.jsx("input",{ref:A,type:"file",style:{display:"none"},accept:n,multiple:a,onChange:R=>{k(R.target.files),R.target.value=""}}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"12px"},children:[e.jsx("div",{style:{width:"48px",height:"48px",borderRadius:"12px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:b?"color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)":"var(--metakyc-surface, #f9fafb)",transition:"background-color 0.2s ease"},children:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:b?"var(--metakyc-primary, #2563eb)":"var(--metakyc-text-muted, #9ca3af)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{transition:"stroke 0.2s ease"},children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"17 8 12 3 7 8"}),e.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"15"})]})}),e.jsxs("div",{children:[e.jsxs("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",margin:0},children:[e.jsx("span",{style:{fontWeight:600,color:"var(--metakyc-primary, #2563eb)"},children:"Click to upload"})," ","or drag and drop"]}),(n||l)&&e.jsxs("p",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"4px"},children:[n&&e.jsx("span",{children:n}),n&&l&&e.jsx("span",{children:" · "}),l&&e.jsxs("span",{children:["Max ",dt(l)]})]})]})]})]}),te&&e.jsx("div",{style:{marginTop:"12px",display:"flex",flexDirection:"column",gap:"8px"},children:y.map((R,g)=>{const O=is(R),q=O==="image",Q=q?URL.createObjectURL(R):null;return e.jsxs("div",{className:"metakyc-file-item",style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 12px",borderRadius:"10px",backgroundColor:"var(--metakyc-surface, #f9fafb)",border:"1px solid var(--metakyc-border, #e5e7eb)",transition:"background-color 0.15s ease"},children:[e.jsx("div",{style:{width:"40px",height:"40px",borderRadius:"8px",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden",backgroundColor:q?"transparent":"color-mix(in srgb, var(--metakyc-primary, #2563eb) 10%, transparent)"},children:q&&Q?e.jsx("img",{src:Q,alt:R.name,style:{width:"100%",height:"100%",objectFit:"cover",borderRadius:"8px"}}):O==="pdf"?e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"}),e.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),e.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"}),e.jsx("polyline",{points:"10 9 9 9 8 9"})]}):e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-primary, #2563eb)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("p",{style:{fontSize:"13px",fontWeight:500,color:"var(--metakyc-text-primary, #111827)",margin:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:R.name}),e.jsx("p",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)",margin:0,marginTop:"2px"},children:dt(R.size)})]}),e.jsx("button",{type:"button",onClick:B=>{B.stopPropagation(),_(g)},style:{display:"flex",alignItems:"center",justifyContent:"center",width:"28px",height:"28px",borderRadius:"6px",border:"none",backgroundColor:"transparent",color:"var(--metakyc-text-muted, #9ca3af)",cursor:"pointer",flexShrink:0,transition:"all 0.15s ease",padding:0},onMouseEnter:B=>{B.currentTarget.style.backgroundColor="color-mix(in srgb, var(--metakyc-danger, #ef4444) 10%, transparent)",B.currentTarget.style.color="var(--metakyc-danger, #ef4444)"},onMouseLeave:B=>{B.currentTarget.style.backgroundColor="transparent",B.currentTarget.style.color="var(--metakyc-text-muted, #9ca3af)"},children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},`${R.name}-${g}`)})}),U&&e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",marginTop:"6px"},children:U})]})},Er=i.forwardRef(({countryCode:t="+1",onCountryCodeChange:r,className:s,...n},a)=>e.jsxs("div",{className:"w-full",children:[n.label&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[n.label,n.required&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:t,onChange:l=>r==null?void 0:r(l.target.value),className:Se("w-20 rounded-lg border px-3 py-2 text-sm","focus:outline-none focus:ring-2 focus:ring-offset-0"),style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:"var(--metakyc-text-primary, #111827)",borderColor:"var(--metakyc-border, #d1d5db)"},placeholder:"+1"}),e.jsx(ye,{ref:a,type:"tel",className:Se("flex-1",s),...n,label:""})]}),n.error&&e.jsx("p",{className:"mt-1 text-sm text-danger-500",children:n.error})]}));Er.displayName="PhoneInput";/**
|
|
33
33
|
* @license lucide-react v0.574.0 - ISC
|
|
34
34
|
*
|
|
35
35
|
* This source code is licensed under the ISC license.
|
|
@@ -64,12 +64,12 @@
|
|
|
64
64
|
*
|
|
65
65
|
* This source code is licensed under the ISC license.
|
|
66
66
|
* See the LICENSE file in the root directory of this source tree.
|
|
67
|
-
*/const us=
|
|
67
|
+
*/const us=i.forwardRef(({color:t="currentColor",size:r=24,strokeWidth:s=2,absoluteStrokeWidth:n,className:a="",children:l,iconNode:c,...u},y)=>i.createElement("svg",{ref:y,...cs,width:r,height:r,stroke:t,strokeWidth:n?Number(s)*24/Number(r):s,className:Ar("lucide",a),...!l&&!ds(u)&&{"aria-hidden":"true"},...u},[...c.map(([p,b])=>i.createElement(p,b)),...Array.isArray(l)?l:[l]]));/**
|
|
68
68
|
* @license lucide-react v0.574.0 - ISC
|
|
69
69
|
*
|
|
70
70
|
* This source code is licensed under the ISC license.
|
|
71
71
|
* See the LICENSE file in the root directory of this source tree.
|
|
72
|
-
*/const Fr=(t,r)=>{const s=
|
|
72
|
+
*/const Fr=(t,r)=>{const s=i.forwardRef(({className:n,...a},l)=>i.createElement(us,{ref:l,iconNode:r,className:Ar(`lucide-${os(Ct(t))}`,`lucide-${t}`,n),...a}));return s.displayName=Ct(t),s};/**
|
|
73
73
|
* @license lucide-react v0.574.0 - ISC
|
|
74
74
|
*
|
|
75
75
|
* This source code is licensed under the ISC license.
|
|
@@ -79,5 +79,5 @@
|
|
|
79
79
|
*
|
|
80
80
|
* This source code is licensed under the ISC license.
|
|
81
81
|
* See the LICENSE file in the root directory of this source tree.
|
|
82
|
-
*/const ms=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],Pr=Fr("chevron-right",ms);function ys(t,r){const s=!r||r.length===0||r.every(n=>!n||!n.trim());if(t.isRequired&&s)return t.errorMessage||"This field is required";if(!s){const n=r[0]??"";if(n&&t.regex)try{if(!new RegExp(t.regex).test(n))return t.errorMessage||"Invalid format"}catch{}if(n!==""){const i=Number(n);if(!isNaN(i)&&n.trim()!==""){if(t.min!==void 0&&t.min!==null&&i<t.min)return`Minimum value is ${t.min}`;if(t.max!==void 0&&t.max!==null&&i>t.max)return`Maximum value is ${t.max}`}else{if(t.min!==void 0&&t.min!==null&&n.length<t.min)return`Minimum length is ${t.min} characters`;if(t.max!==void 0&&t.max!==null&&n.length>t.max)return`Maximum length is ${t.max} characters`}}}return null}function xs(t){const r=t.flatMap((n,i)=>(n.questions??[]).map((l,c)=>({question:l,groupIndex:i,qIdx:c}))),s=new Map;for(const n of r){const i=n.question.pageNumber!=null&&n.question.pageNumber>0?n.question.pageNumber:1;s.has(i)||s.set(i,[]),s.get(i).push(n)}return Array.from(s.entries()).sort(([n],[i])=>n-i).map(([,n])=>n)}const Lr=({applicantId:t,onComplete:r,onBack:s})=>{const{questionnaire:n,initialAnswers:i,isLoading:l,isSubmitting:c,error:d,submit:m}=jr(t),[u,x]=o.useState({}),[P,b]=o.useState({}),[A,F]=o.useState(0);o.useEffect(()=>{i&&Object.keys(i).length>0&&Object.keys(u).length===0&&x(i)},[i]);const j=o.useMemo(()=>n?xs(n.questionGroups):[],[n]),N=A===j.length-1,M=j[A]??[],Y=o.useCallback((I,f)=>{x(O=>({...O,[I]:f})),b(O=>{const q={...O};return delete q[I],q})},[]),L=o.useCallback(()=>{const I={};for(const{question:f}of M){const O=ys(f,u[f.id]??[]);O&&(I[f.id]=O)}return b(f=>({...f,...I})),Object.keys(I).length===0},[M,u]),$=()=>{L()&&F(I=>I+1)},K=()=>{A>0?F(I=>I-1):s==null||s()},ee=async()=>{if(!(!L()||!n))try{const I=n.questionGroups.flatMap(O=>(O.questions??[]).map(q=>({questionId:q.id,values:u[q.id]??[]}))),f={applicantId:t,questionnarieId:n.id,questionResults:I};await m(f),r==null||r()}catch(I){console.error("Questionnaire submit error:",I)}};return l?e.jsx(Z,{children:e.jsx(X,{children:e.jsx(Ie,{className:"my-8"})})}):d?e.jsx(Z,{children:e.jsx(X,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading questionnaire: ",d.message]})})}):n?e.jsxs(Z,{children:[e.jsxs(he,{children:[e.jsx("h2",{className:"text-lg font-bold",children:n.displayName}),n.subtitle&&e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:n.subtitle}),j.length>1&&e.jsxs("div",{className:"flex items-center justify-between mt-3",children:[e.jsxs("span",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:["Page ",A+1," of ",j.length]}),e.jsx("div",{className:"flex items-center gap-1.5",children:j.map((I,f)=>e.jsx("div",{className:"rounded-full transition-all duration-200",style:{height:"6px",width:f===A?"20px":"6px",backgroundColor:f<=A?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},f))})]})]}),e.jsx(X,{className:"space-y-6",children:M.map(({question:I})=>e.jsx(hs,{question:I,value:u[I.id]??[],error:P[I.id],onChange:f=>Y(I.id,f)},I.id))}),e.jsxs(fe,{className:"flex items-center justify-between",children:[e.jsxs(G,{type:"button",variant:"outline",onClick:K,style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(Tr,{size:14}),A>0?"Previous":"Back"]}),N?e.jsx(G,{type:"button",isLoading:c,onClick:ee,children:"Continue"}):e.jsxs(G,{type:"button",onClick:$,style:{display:"flex",alignItems:"center",gap:"4px"},children:["Next",e.jsx(Pr,{size:14})]})]}),d&&e.jsx("div",{className:"mx-6 mb-4 p-3 bg-red-50 border border-red-200 rounded",children:e.jsx("p",{className:"text-red-600 text-sm",children:d.message})})]}):null},hs=({question:t,value:r,error:s,onChange:n})=>{var c;const l=(((c=t.defaultAnswers)==null?void 0:c.length)??0)>0?t.showAsDropdown?t.canMultipleAnswer?"multi-select":"single-select":t.canMultipleAnswer?"checkbox":"radio":"text";return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[t.text,t.isRequired&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),t.subtitle&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:t.subtitle}),t.description&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:t.description}),l==="text"&&e.jsx(me,{value:r[0]??"",onChange:d=>n([d.target.value]),placeholder:t.subtitle?void 0:"Enter your answer…",error:s,required:t.isRequired}),l==="single-select"&&e.jsx(pt,{value:r[0]??"",onChange:d=>n([d.target.value]),options:(t.defaultAnswers??[]).map(d=>({value:d,label:d})),placeholder:"Select an option…",error:s,required:t.isRequired}),l==="radio"&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultAnswers??[]).map(d=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"radio",checked:r[0]===d,onChange:()=>n([d]),className:"metakyc-option-input",style:{width:"16px",height:"16px",minWidth:"16px",flexShrink:0,flexGrow:0,accentColor:"var(--metakyc-primary, #2563eb)",cursor:"pointer",margin:0,padding:0,display:"inline-block",verticalAlign:"middle"}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:d})]},d)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),(l==="checkbox"||l==="multi-select")&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultAnswers??[]).map(d=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"checkbox",checked:r.includes(d),onChange:m=>{m.target.checked?n([...r,d]):n(r.filter(u=>u!==d))},className:"metakyc-option-input",style:{width:"16px",height:"16px",minWidth:"16px",flexShrink:0,flexGrow:0,accentColor:"var(--metakyc-primary, #2563eb)",cursor:"pointer",margin:0,padding:0,display:"inline-block",verticalAlign:"middle"}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:d})]},d)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),s&&l==="text"&&null]})};function fs(t){const r=new Map;for(const s of t){const n=s.pageNumber!=null&&s.pageNumber>0?s.pageNumber:1;r.has(n)||r.set(n,[]),r.get(n).push(s)}return Array.from(r.entries()).sort(([s],[n])=>s-n).map(([,s])=>s)}const Dr=({applicantId:t,onComplete:r,onBack:s})=>{const{uploadDocument:n,isLoading:i,isSubmitting:l,error:c,submit:d}=wr(t),[m,u]=o.useState({}),[x,P]=o.useState(null),[b,A]=o.useState(0),[F,j]=o.useState({}),N=o.useMemo(()=>n?fs(n.uploadDocumentFiles):[],[n]),M=N[b]??[],Y=b===N.length-1,L=N.length,$=o.useCallback(()=>{const f={};for(const O of M)O.isRequired&&(m[O.id]||[]).length===0&&(f[O.id]=`${O.displayName} is required`);return j(f),Object.keys(f).length===0},[M,m]),K=()=>{$()&&(A(f=>f+1),j({}))},ee=()=>{b>0?(A(f=>f-1),j({})):s==null||s()},I=async()=>{if(!(!$()||!n)){P(null);try{const f=await Promise.all(n.uploadDocumentFiles.map(async q=>{const Q=m[q.id]||[],B=await Promise.all(Q.map(async J=>({fileName:J.name,fileData:await xr(J)})));return{uploadDocumentFileId:q.id,valueList:B}})),O={applicantId:t,uploadDocumentId:n.id,uploadDocumentResults:f};await d(O),r==null||r()}catch(f){P((f==null?void 0:f.message)||"Failed to submit documents. Please try again.")}}};return i?e.jsx(Z,{children:e.jsx(X,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"48px 0",gap:"16px"},children:[e.jsx(Ie,{className:"my-8"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)"},children:"Loading document requirements..."})]})})}):c?e.jsx(Z,{children:e.jsx(X,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"32px 0",gap:"12px",textAlign:"center"},children:[e.jsx("div",{style:{width:"48px",height:"48px",borderRadius:"50%",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 10%, transparent)",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),e.jsx("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]})}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-danger, #ef4444)",fontWeight:500},children:"Error loading document requirements"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-muted, #9ca3af)"},children:c.message})]})})}):n?e.jsxs(Z,{children:[e.jsxs(he,{children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:n.displayName||"Upload Documents"}),n.subtitle&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",marginTop:"4px"},children:n.subtitle}),L>1&&e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginTop:"12px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)"},children:["Page ",b+1," of ",L]}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:N.map((f,O)=>e.jsx("div",{style:{height:"6px",width:O===b?"20px":"6px",borderRadius:"999px",transition:"all 0.2s ease",backgroundColor:O<=b?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},O))})]})]}),n.description&&b===0&&e.jsxs("div",{style:{margin:"0 24px",marginTop:"4px",display:"flex",gap:"10px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-primary, #2563eb) 5%, var(--metakyc-background, #ffffff))",border:"1px solid color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-primary, #2563eb)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:"1px"},children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-secondary, #374151)",margin:0,lineHeight:1.5},children:n.description})]}),e.jsx(X,{children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"24px"},children:M.map(f=>e.jsx(Ir,{label:f.displayName,subtitle:f.subtitle,accept:f.allowedTypes,multiple:f.multipleFile,maxSize:f.maxEachFileSizeByte,required:f.isRequired,error:F[f.id],value:m[f.id]||[],onChange:O=>{P(null),j(q=>{const Q={...q};return delete Q[f.id],Q}),u(q=>({...q,[f.id]:O}))}},f.id))})}),x&&e.jsxs("div",{style:{margin:"0 24px",padding:"10px 14px",borderRadius:"8px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:x})]}),e.jsx(fe,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[e.jsx(G,{type:"button",variant:"outline",onClick:ee,children:b>0?"Previous":"Back"}),Y?e.jsx(G,{type:"button",isLoading:l,onClick:I,children:l?"Uploading...":"Continue"}):e.jsx(G,{type:"button",onClick:K,children:"Next"})]})})]}):null},Mr=({applicantId:t,onComplete:r,onBack:s})=>{const{overview:n,isLoading:i,isSubmitting:l,error:c,passOverview:d}=Sr(t),m=async()=>{await d(),r==null||r()};return i?e.jsx(Z,{children:e.jsx(X,{children:e.jsx(Ie,{className:"my-8"})})}):c?e.jsx(Z,{children:e.jsx(X,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading overview: ",c.message]})})}):n?e.jsxs(Z,{children:[e.jsxs(he,{children:[e.jsx("h2",{className:"text-lg font-bold",children:n.title||"Overview"}),n.description&&e.jsx("p",{className:"mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:n.description})]}),e.jsx(X,{className:"space-y-8",children:n.steps&&n.steps.length>0?n.steps.sort((u,x)=>u.order-x.order).map(u=>e.jsxs("div",{className:"metakyc-overview-step-item flex items-center space-x-3",children:[e.jsx("div",{className:"metakyc-step-icon flex-shrink-0",children:e.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center font-medium text-sm",style:{backgroundColor:"var(--metakyc-primary, #2563eb)",color:"#ffffff"},children:u.order+1})}),e.jsxs("div",{className:"metakyc-step-content",style:{flex:1,border:"none",height:"auto",background:"transparent"},children:[e.jsx("span",{className:"metakyc-step-title text-sm font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:u.title}),u.description&&e.jsx("p",{className:"metakyc-step-description text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:u.description})]})]},u.order)):e.jsx("div",{className:"text-center py-8",children:e.jsx("p",{style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Loading overview data..."})})}),e.jsxs(fe,{className:"flex justify-between",children:[s&&e.jsx(G,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(G,{onClick:m,isLoading:l,children:"Continue"})]})]}):null};function gs(t){const r=(t??"en").toLowerCase().replace("_","-");try{return Intl.NumberFormat.supportedLocalesOf([r]),r}catch{return"en"}}function bs(t){return t.valueDataType===Le.Money&&Array.isArray(t.defaultValues)&&t.defaultValues.length>0}function vs(t,r){const s=new Intl.NumberFormat(gs(r),{minimumFractionDigits:0,maximumFractionDigits:2});return t.replace(/([\d]+(?:\.\d+)?)/g,n=>{const i=parseFloat(n);return isNaN(i)?n:s.format(i)})}function ks(t,r){const s=!r||r.length===0||r.every(n=>!n||!n.trim());if(t.isRequired&&s)return t.errorMessage||`${t.displayName} is required`;if(!s){const n=r[0]??"";if(n&&t.regex)try{if(!new RegExp(t.regex).test(n))return t.errorMessage||"Invalid format"}catch{}const i=t.valueDataType===Le.Integer||t.valueDataType===Le.Money||t.valueDataType===Le.DigitOnly;if(i&&n.trim()!==""){const l=Number(n);if(!isNaN(l)){if(t.min!==void 0&&t.min!==null&&l<t.min)return`Minimum value is ${t.min}`;if(t.max!==void 0&&t.max!==null&&l>t.max)return`Maximum value is ${t.max}`}}else if(!i&&n!==""){if(t.min!==void 0&&t.min!==null&&n.length<t.min)return`Minimum length is ${t.min} characters`;if(t.max!==void 0&&t.max!==null&&n.length>t.max)return`Maximum length is ${t.max} characters`}}return null}function js(t){const r=new Map;return t.forEach((s,n)=>{const i=s.pageNumber!=null&&s.pageNumber>0?s.pageNumber:1;r.has(i)||r.set(i,[]),r.get(i).push({criterion:s,idx:n})}),Array.from(r.entries()).sort(([s],[n])=>s-n).map(([,s])=>s)}function ws(t){return t.builtInType===1?"country":!t.defaultValues||t.defaultValues.length===0?"text":t.multipleValue?"checkbox":"radio"}const Or=({applicantId:t,onComplete:r,onBack:s})=>{const{config:n}=Ce(),i=n.locale??"en",{criteria:l,initialAnswers:c,isLoading:d,isSubmitting:m,error:u,submit:x}=Nr(t),[P,b]=o.useState({}),[A,F]=o.useState({}),[j,N]=o.useState(0),[M,Y]=o.useState(!1);o.useEffect(()=>{c&&Object.keys(c).length>0&&Object.keys(P).length===0&&b(c)},[c]);const L=o.useMemo(()=>l&&l.length>0?js(l):[],[l]),$=j===L.length-1,K=L[j]??[];o.useEffect(()=>{!d&&l&&l.length===0&&!M&&!m&&(Y(!0),x({applicantId:t,criteriaValueInputs:[]}).then(()=>r==null?void 0:r()).catch(console.error))},[d,l,M,m,x,t,r]);const ee=o.useCallback((Q,B)=>{b(J=>({...J,[Q]:B})),F(J=>{const se={...J};return delete se[Q],se})},[]),I=o.useCallback(()=>{const Q={};for(const{criterion:B}of K){const J=ks(B,P[B.id]??[]);J&&(Q[B.id]=J)}return F(B=>({...B,...Q})),Object.keys(Q).length===0},[K,P]),f=()=>{I()&&N(Q=>Q+1)},O=()=>{j>0?N(Q=>Q-1):s==null||s()},q=async()=>{if(!(!I()||!l))try{const Q=l.map(J=>{const se=(P[J.id]??[]).filter(V=>V&&V.trim());return se.length>0?{riskCriteriaId:J.id,values:se}:null}).filter(J=>J!==null);await x({applicantId:t,criteriaValueInputs:Q}),r==null||r()}catch(Q){console.error("Risk scoring submit error:",Q)}};return d?e.jsx(Z,{children:e.jsxs(X,{children:[e.jsx(Ie,{className:"my-8"}),e.jsx("p",{className:"text-center text-sm mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Loading risk scoring criteria…"})]})}):!d&&l&&l.length===0?e.jsx(Z,{children:e.jsxs(X,{children:[e.jsx(Ie,{className:"my-8"}),e.jsx("p",{className:"text-center text-sm mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"No criteria required. Moving to next step…"})]})}):u?e.jsx(Z,{children:e.jsx(X,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading criteria: ",u.message]})})}):l?e.jsxs(Z,{children:[e.jsxs(he,{children:[e.jsx("h2",{className:"text-lg font-bold",children:"Risk Assessment"}),e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Please answer the following questions for risk evaluation"}),L.length>1&&e.jsxs("div",{className:"flex items-center justify-between mt-3",children:[e.jsxs("span",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:["Page ",j+1," of ",L.length]}),e.jsx("div",{className:"flex items-center gap-1.5",children:L.map((Q,B)=>e.jsx("div",{className:"rounded-full transition-all duration-200",style:{height:"6px",width:B===j?"20px":"6px",backgroundColor:B<=j?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},B))})]})]}),e.jsx(X,{className:"space-y-6",children:K.map(({criterion:Q})=>e.jsx(Ss,{criterion:Q,value:P[Q.id]??[],error:A[Q.id],locale:i,onChange:B=>ee(Q.id,B)},Q.id))}),e.jsxs(fe,{className:"flex items-center justify-between",children:[e.jsxs(G,{type:"button",variant:"outline",onClick:O,style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(Tr,{size:14}),j>0?"Previous":"Back"]}),$?e.jsx(G,{type:"button",isLoading:m,onClick:q,children:"Continue"}):e.jsxs(G,{type:"button",onClick:f,style:{display:"flex",alignItems:"center",gap:"4px"},children:["Next",e.jsx(Pr,{size:14})]})]}),u&&e.jsx("div",{className:"mx-6 mb-4 p-3 bg-red-50 border border-red-200 rounded",children:e.jsx("p",{className:"text-red-600 text-sm",children:u.message})})]}):null},Ss=({criterion:t,value:r,error:s,locale:n,onChange:i})=>{const l=ws(t),c=t.valueDataType===Le.Integer||t.valueDataType===Le.Money||t.valueDataType===Le.DigitOnly,d=bs(t),m=u=>d?vs(u,n):u;return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[t.displayName,t.isRequired&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),t.description&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:t.description}),c&&(t.min!==void 0||t.max!==void 0)&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:t.min!==void 0&&t.max!==void 0?`Range: ${t.min} – ${t.max}`:t.min!==void 0?`Minimum: ${t.min}`:`Maximum: ${t.max}`}),l==="text"&&e.jsx(me,{value:r[0]??"",onChange:u=>i([u.target.value]),type:c?"number":"text",placeholder:"Enter your answer…",error:s,required:t.isRequired,min:t.min,max:t.max,onKeyDown:u=>{t.valueDataType===Le.DigitOnly&&["e","E","+","-","."].includes(u.key)&&u.preventDefault()}}),l==="radio"&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultValues??[]).map(u=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"radio",checked:r[0]===u,onChange:()=>i([u]),className:"metakyc-option-input",style:{width:"16px",height:"16px",minWidth:"16px",flexShrink:0,flexGrow:0,accentColor:"var(--metakyc-primary, #2563eb)",cursor:"pointer",margin:0,padding:0,display:"inline-block",verticalAlign:"middle"}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:m(u)})]},u)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),l==="checkbox"&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultValues??[]).map(u=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"checkbox",checked:r.includes(u),onChange:x=>{x.target.checked?i([...r,u]):i(r.filter(P=>P!==u))},className:"metakyc-option-input",style:{width:"16px",height:"16px",minWidth:"16px",flexShrink:0,flexGrow:0,accentColor:"var(--metakyc-primary, #2563eb)",cursor:"pointer",margin:0,padding:0,display:"inline-block",verticalAlign:"middle"}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:m(u)})]},u)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),l==="country"&&e.jsx(pt,{value:r[0]??"",onChange:u=>i([u.target.value]),options:[{value:"US",label:"United States"},{value:"GB",label:"United Kingdom"},{value:"DE",label:"Germany"},{value:"FR",label:"France"},{value:"AE",label:"United Arab Emirates"}],placeholder:"Select a country…",error:s,required:t.isRequired})]})},zr=({applicantId:t,onComplete:r,onBack:s})=>{const{investorCategorizationService:n}=Ce(),[i,l]=o.useState(null),[c,d]=o.useState(!1),[m,u]=o.useState(null),x=async P=>{if(P.preventDefault(),i===null){u("Please select an investor type");return}d(!0),u(null);try{const b={applicantId:t,investorType:i};console.log("Submitting investor categorization:",b);const A=await n.setInvestorCategorization(b);console.log("Investor categorization result:",A),r==null||r()}catch(b){console.error("Error submitting investor categorization:",b),u(b.message||"Failed to submit investor categorization")}finally{d(!1)}};return e.jsx("form",{onSubmit:x,children:e.jsxs(Z,{children:[e.jsxs(he,{children:[e.jsx("h2",{className:"text-lg font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Which statement best describes you?"}),e.jsx("p",{className:"mt-2",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"All Tokenise clients are treated as Retail Investors under EU regulation, which gives you the highest level of investor protection. For our internal purposes, we ask you to select the description that best matches your situation"})]}),e.jsxs(X,{className:"space-y-4",children:[e.jsx("p",{className:"text-sm font-medium mb-3",style:{color:"var(--metakyc-text-secondary, #374151)"},children:"Choose one"}),e.jsx("label",{className:"block p-4 border-2 rounded-lg cursor-pointer transition-all",style:{borderColor:i===ke.Individual?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:i===ke.Individual?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:ke.Individual,checked:i===ke.Individual,onChange:()=>l(ke.Individual),className:"mt-1"}),e.jsxs("div",{className:"ml-3",children:[e.jsx("div",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Individual investor"}),e.jsx("div",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"(Recommended) Most of our clients choose this option. Provides the strongest protection and aligns with our mission to make investing accessible to everyone."})]})]})}),e.jsx("label",{className:"block p-4 border-2 rounded-lg cursor-pointer transition-all",style:{borderColor:i===ke.Sophisticated?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:i===ke.Sophisticated?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:ke.Sophisticated,checked:i===ke.Sophisticated,onChange:()=>l(ke.Sophisticated),className:"mt-1"}),e.jsxs("div",{className:"ml-3",children:[e.jsx("div",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Sophisticated investor"}),e.jsx("div",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"In the last 2 years, I have done one or more of the following:"}),e.jsxs("ul",{className:"text-sm mt-2 space-y-1 list-none",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:[e.jsx("li",{children:"Worked in private equity or provided capital to small and medium enterprises, and/or"}),e.jsx("li",{children:"Been the director of a company with an annual turnover of at least (USD) $2m million, and/or"}),e.jsx("li",{children:"Invested directly in at least 2 private (not listed) companies."})]})]})]})}),e.jsx("label",{className:"block p-4 border-2 rounded-lg cursor-pointer transition-all",style:{borderColor:i===ke.HighNetWorth?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:i===ke.HighNetWorth?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:ke.HighNetWorth,checked:i===ke.HighNetWorth,onChange:()=>l(ke.HighNetWorth),className:"mt-1"}),e.jsxs("div",{className:"ml-3",children:[e.jsx("div",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"High networth investor"}),e.jsxs("div",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:["I earn more than (USD/EUR) $150,000 per year, and/or",e.jsx("br",{}),"I have net assets (excluding my main property) of at least $/EUR 300,000"]})]})]})}),m&&e.jsx("div",{className:"p-4 rounded-lg",style:{backgroundColor:"#fee2e2",border:"1px solid #fca5a5"},children:e.jsxs("p",{className:"text-sm",style:{color:"#991b1b"},children:[e.jsx("strong",{children:"Error:"})," ",m]})})]}),e.jsxs(fe,{className:"flex justify-between",children:[s&&e.jsx(G,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(G,{type:"submit",isLoading:c,disabled:i===null,children:"Submit"})]})]})})};function Nt(t){const r=t.split(":").map(Number);return r.length===3?r[0]*3600+r[1]*60+r[2]:0}function mt(t){const r=Math.floor(t/60),s=t%60;return`${r.toString().padStart(2,"0")}:${s.toString().padStart(2,"0")}`}const Br=({applicantId:t,onComplete:r,onBack:s})=>{const{appropriatenessTestService:n}=Ce(),[i,l]=o.useState(null),[c,d]=o.useState(!0),[m,u]=o.useState(!1),[x,P]=o.useState(null),[b,A]=o.useState({}),[F,j]=o.useState(0),[N,M]=o.useState(!1),[Y,L]=o.useState(!1),[$,K]=o.useState(0),[ee,I]=o.useState(0),[f,O]=o.useState(null);o.useEffect(()=>{(async()=>{try{d(!0),P(null);const z=await n.getAppropriatenessTest(t);if(l(z),z.waitTimeSpanForNextTry&&z.waitTimeSpanForNextTry!=="00:00:00"){const H=Nt(z.waitTimeSpanForNextTry);H>0&&K(H)}}catch(z){P(z.message||"Failed to load appropriateness test")}finally{d(!1)}})()},[t,n]),o.useEffect(()=>{if(!N||F<=0)return;const z=setInterval(()=>{j(H=>H<=1?(L(!0),0):H-1)},1e3);return()=>clearInterval(z)},[N,F]),o.useEffect(()=>{if($<=0)return;const z=setInterval(()=>{K(H=>H<=1?0:H-1)},1e3);return()=>clearInterval(z)},[$]),o.useEffect(()=>{Y&&!m&&J()},[Y]);const q=()=>{i&&(M(!0),j(i.testDurationSec),I(0),A({}),P(null))},Q=(z,H)=>{A(pe=>({...pe,[z]:H}))},B=o.useCallback(async()=>{try{const z=await n.getAppropriatenessTest(t);if(l(z),z.waitTimeSpanForNextTry&&z.waitTimeSpanForNextTry!=="00:00:00"){const H=Nt(z.waitTimeSpanForNextTry);H>0&&K(H)}}catch{}},[t,n]),J=async z=>{if(i){if(!Y){const H=i.appropriatenessQuestions.length-Object.keys(b).length;if(H>0){P(`Please answer all questions. ${H} remaining.`);return}}u(!0),P(null);try{const H=i.appropriatenessQuestions.map(R=>({appropriatenessQuestionId:R.id,value:b[R.id]||""})),pe={applicantId:t,appropriatenessTestId:i.id,appropriatenessQuestionResults:H};try{const R=await n.fillAppropriatenessTest(pe);R.isSuccess?O({success:!0,message:R.message||"Congratulations! You have passed the test."}):(O({success:!1,message:R.message||"You did not pass the test."}),setTimeout(()=>B(),1e3))}catch(R){if(R.code===400&&R.message)O({success:!1,message:R.message}),setTimeout(()=>B(),1500);else throw R}}catch(H){P(H.message||"Failed to submit test. Please try again."),se()}finally{u(!1)}}},se=()=>{M(!1),L(!1),A({}),I(0)};if(c)return e.jsx(Z,{children:e.jsx(X,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"48px 0",gap:"16px"},children:[e.jsx(Ie,{className:"my-8"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)"},children:"Loading test..."})]})})});if(!i)return e.jsx(Z,{children:e.jsx(X,{children:e.jsxs("div",{style:{textAlign:"center",padding:"48px 0"},children:[e.jsx("p",{style:{fontSize:"16px",fontWeight:600,color:"var(--metakyc-danger, #ef4444)"},children:"No test data available"}),x&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"8px"},children:x})]})})});const V=i.testAllowedMaxTry-i.totalFailedTries,ge=i.appropriatenessQuestions.length,ie=Object.keys(b).length;if($>0)return e.jsxs(Z,{children:[e.jsx(he,{children:e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:i.displayName})}),e.jsx(X,{children:e.jsxs("div",{style:{textAlign:"center",padding:"32px 0"},children:[e.jsx("div",{style:{width:"100px",height:"100px",borderRadius:"50%",margin:"0 auto 20px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"color-mix(in srgb, var(--metakyc-primary, #2563eb) 8%, transparent)"},children:e.jsx("span",{style:{fontSize:"28px",fontWeight:700,color:"var(--metakyc-primary, #2563eb)",fontVariantNumeric:"tabular-nums"},children:mt($)})}),e.jsx("p",{style:{fontSize:"15px",fontWeight:500,color:"var(--metakyc-text-primary, #111827)"},children:"Please wait before retrying"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"4px"},children:"You can attempt the test again once the timer expires"}),x&&e.jsx("div",{style:{marginTop:"20px",padding:"12px 16px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:x})})]})})]});if(f){const z=()=>{O(null),se(),P(null)};return e.jsxs(Z,{children:[e.jsx(X,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",textAlign:"center",padding:"40px 16px",gap:"16px"},children:[e.jsx("div",{style:{width:"72px",height:"72px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:f.success?"color-mix(in srgb, var(--metakyc-success, #10b981) 12%, transparent)":"color-mix(in srgb, var(--metakyc-danger, #ef4444) 10%, transparent)"},children:f.success?e.jsxs("svg",{width:"36",height:"36",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-success, #10b981)",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),e.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]}):e.jsxs("svg",{width:"36",height:"36",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),e.jsx("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]})}),e.jsx("h2",{style:{fontSize:"20px",fontWeight:700,color:f.success?"var(--metakyc-success, #10b981)":"var(--metakyc-danger, #ef4444)",margin:0},children:f.success?"Test Passed":"Test Failed"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",margin:0,lineHeight:1.6,maxWidth:"400px",whiteSpace:"pre-line"},children:f.message}),!f.success&&V>0&&e.jsx("div",{style:{marginTop:"4px",padding:"10px 20px",borderRadius:"10px",backgroundColor:"var(--metakyc-surface, #f9fafb)",border:"1px solid var(--metakyc-border, #e5e7eb)"},children:e.jsxs("p",{style:{fontSize:"13px",color:"var(--metakyc-text-muted, #9ca3af)",margin:0},children:["You have ",e.jsx("strong",{style:{color:"var(--metakyc-text-primary, #111827)"},children:V})," attempt",V!==1?"s":""," remaining"]})}),!f.success&&V<=0&&e.jsx("div",{style:{marginTop:"4px",padding:"10px 20px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:"No attempts remaining. Please contact support for assistance."})})]})}),e.jsx(fe,{children:e.jsx("div",{style:{display:"flex",justifyContent:"center",width:"100%",gap:"12px"},children:f.success?e.jsx(G,{type:"button",onClick:()=>r==null?void 0:r(),children:"Continue"}):e.jsxs(e.Fragment,{children:[V>0&&$<=0&&e.jsx(G,{type:"button",onClick:z,children:"Retake Test"}),V>0&&$>0&&e.jsx(G,{type:"button",onClick:z,children:"OK"}),V<=0&&s&&e.jsx(G,{type:"button",variant:"outline",onClick:s,children:"Back"})]})})})]})}if(!N)return e.jsxs(Z,{children:[e.jsxs(he,{children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:i.displayName}),i.subtitle&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",marginTop:"4px"},children:i.subtitle})]}),e.jsxs(X,{children:[i.description&&e.jsxs("div",{style:{marginBottom:"20px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-primary, #2563eb) 5%, var(--metakyc-background, #ffffff))",border:"1px solid color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)",display:"flex",gap:"10px"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-primary, #2563eb)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:"1px"},children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-secondary, #374151)",margin:0,lineHeight:1.5},children:i.description})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px",marginBottom:"20px"},children:[e.jsx(lt,{icon:"questions",label:"Questions",value:String(i.totalQuestionCount)}),e.jsx(lt,{icon:"time",label:"Time Limit",value:mt(i.testDurationSec)}),e.jsx(lt,{icon:"target",label:"Pass Requirement",value:`${i.testCorrectAnswerPassLimit} correct`}),e.jsx(lt,{icon:"retry",label:"Attempts Left",value:String(V),variant:V<=1?"warning":"default"})]}),x&&e.jsxs("div",{style:{marginBottom:"16px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)",display:"flex",gap:"10px"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:"1px"},children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),e.jsxs("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0,lineHeight:1.5},children:[e.jsx("strong",{children:"Previous attempt:"})," ",x]})]}),V<=0&&e.jsx("div",{style:{padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:"You have used all your attempts. Please contact support for assistance."})})]}),e.jsx(fe,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:s?"space-between":"flex-end",width:"100%"},children:[s&&e.jsx(G,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(G,{type:"button",onClick:q,disabled:V<=0,children:"Start Test"})]})})]});const de=i.appropriatenessQuestions[ee],be=ee===ge-1,E=ie===ge,W=F<=60;return e.jsxs(Z,{children:[e.jsxs(he,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:i.displayName}),e.jsxs("p",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"2px"},children:["Question ",ee+1," of ",ge]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 14px",borderRadius:"999px",backgroundColor:W?"color-mix(in srgb, var(--metakyc-danger, #ef4444) 10%, transparent)":"var(--metakyc-surface, #f3f4f6)",transition:"all 0.3s ease"},children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:W?"var(--metakyc-danger, #ef4444)":"var(--metakyc-text-muted, #9ca3af)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),e.jsx("span",{style:{fontSize:"16px",fontWeight:700,fontVariantNumeric:"tabular-nums",color:W?"var(--metakyc-danger, #ef4444)":"var(--metakyc-text-primary, #111827)",transition:"color 0.3s ease"},children:mt(F)})]})]}),e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsx("div",{style:{height:"4px",borderRadius:"999px",backgroundColor:"var(--metakyc-border, #e5e7eb)",overflow:"hidden"},children:e.jsx("div",{style:{height:"100%",borderRadius:"999px",backgroundColor:"var(--metakyc-primary, #2563eb)",width:`${ie/ge*100}%`,transition:"width 0.3s ease"}})}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:"4px"},children:[e.jsxs("span",{style:{fontSize:"11px",color:"var(--metakyc-text-muted, #9ca3af)"},children:[ie," answered"]}),e.jsxs("span",{style:{fontSize:"11px",color:"var(--metakyc-text-muted, #9ca3af)"},children:[V," attempt",V!==1?"s":""," left"]})]})]})]}),e.jsxs(X,{children:[de&&e.jsx(Ns,{question:de,index:ee,selectedAnswer:b[de.id],onSelect:z=>Q(de.id,z),disabled:m}),ge>1&&e.jsx("div",{style:{display:"flex",justifyContent:"center",gap:"6px",marginTop:"20px",flexWrap:"wrap"},children:i.appropriatenessQuestions.map((z,H)=>e.jsx("button",{type:"button",onClick:()=>I(H),style:{width:"28px",height:"28px",borderRadius:"8px",border:H===ee?"2px solid var(--metakyc-primary, #2563eb)":"1px solid var(--metakyc-border, #e5e7eb)",backgroundColor:b[z.id]?H===ee?"color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)":"color-mix(in srgb, var(--metakyc-primary, #2563eb) 8%, transparent)":H===ee?"var(--metakyc-surface, #f9fafb)":"var(--metakyc-background, #ffffff)",color:b[z.id]?"var(--metakyc-primary, #2563eb)":"var(--metakyc-text-muted, #9ca3af)",fontSize:"12px",fontWeight:600,cursor:"pointer",transition:"all 0.15s ease",padding:0,display:"flex",alignItems:"center",justifyContent:"center"},children:H+1},z.id))}),Y&&e.jsxs("div",{style:{marginTop:"16px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, #f59e0b 10%, transparent)",border:"1px solid color-mix(in srgb, #f59e0b 25%, transparent)",display:"flex",alignItems:"center",gap:"10px"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"#f59e0b",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),e.jsx("p",{style:{fontSize:"13px",color:"#b45309",margin:0,fontWeight:500},children:"Time's up! Your answers are being submitted."})]}),x&&!Y&&e.jsx("div",{style:{marginTop:"16px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:x})})]}),e.jsx(fe,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[e.jsx(G,{type:"button",variant:"outline",onClick:()=>{ee>0?I(z=>z-1):s==null||s()},disabled:m,children:ee>0?"Previous":"Cancel"}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[!be&&e.jsx(G,{type:"button",onClick:()=>I(z=>z+1),children:"Next"}),(be||E)&&e.jsx(G,{type:"button",isLoading:m,onClick:()=>J(),disabled:!E&&!Y,style:{opacity:E||Y?1:.5},children:Y?"Submitting...":"Submit Test"})]})]})})]})},Cs={questions:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M9 11l3 3L22 4"}),e.jsx("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),time:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),target:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("circle",{cx:"12",cy:"12",r:"6"}),e.jsx("circle",{cx:"12",cy:"12",r:"2"})]}),retry:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})},lt=({icon:t,label:r,value:s,variant:n="default"})=>{const i=n==="warning";return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px",padding:"14px",borderRadius:"10px",backgroundColor:i?"color-mix(in srgb, #f59e0b 8%, transparent)":"var(--metakyc-surface, #f9fafb)",border:i?"1px solid color-mix(in srgb, #f59e0b 20%, transparent)":"1px solid var(--metakyc-border, #e5e7eb)"},children:[e.jsx("div",{style:{color:i?"#f59e0b":"var(--metakyc-primary, #2563eb)",flexShrink:0},children:Cs[t]}),e.jsxs("div",{children:[e.jsx("p",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)",margin:0},children:r}),e.jsx("p",{style:{fontSize:"15px",fontWeight:600,color:i?"#b45309":"var(--metakyc-text-primary, #111827)",margin:0,marginTop:"1px"},children:s})]})]})},Ns=({question:t,selectedAnswer:r,onSelect:s,disabled:n})=>e.jsxs("div",{children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[t.groupName&&e.jsx("span",{style:{display:"inline-block",fontSize:"11px",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em",color:"var(--metakyc-primary, #2563eb)",marginBottom:"8px"},children:t.groupName}),e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--metakyc-text-primary, #111827)",margin:0,lineHeight:1.5},children:t.question})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.answers.map((i,l)=>{const c=r===i;return e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"12px",padding:"14px 16px",borderRadius:"10px",border:`2px solid ${c?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}`,backgroundColor:c?"color-mix(in srgb, var(--metakyc-primary, #2563eb) 5%, var(--metakyc-background, #ffffff))":"var(--metakyc-background, #ffffff)",cursor:n?"default":"pointer",transition:"all 0.15s ease",opacity:n?.6:1},onMouseEnter:d=>{!n&&!c&&(d.currentTarget.style.borderColor="color-mix(in srgb, var(--metakyc-primary, #2563eb) 50%, var(--metakyc-border, #e5e7eb))")},onMouseLeave:d=>{c||(d.currentTarget.style.borderColor="var(--metakyc-border, #e5e7eb)")},children:[e.jsx("div",{style:{width:"20px",height:"20px",borderRadius:"50%",border:`2px solid ${c?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #d1d5db)"}`,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,transition:"border-color 0.15s ease"},children:c&&e.jsx("div",{style:{width:"10px",height:"10px",borderRadius:"50%",backgroundColor:"var(--metakyc-primary, #2563eb)"}})}),e.jsx("input",{type:"radio",name:`q-${t.id}`,value:i,checked:c,onChange:()=>s(i),disabled:n,style:{position:"absolute",opacity:0,width:0,height:0}}),e.jsx("span",{style:{fontSize:"14px",color:c?"var(--metakyc-text-primary, #111827)":"var(--metakyc-text-secondary, #6b7280)",fontWeight:c?500:400,transition:"color 0.15s ease"},children:i})]},l)})})]}),_r=({applicantId:t,onComplete:r,onBack:s})=>{var Oe,Xe,He,Ye;const{applicantService:n,baseInformationService:i,identityService:l,config:c,currentTheme:d}=Ce(),{identityData:m,provider:u,token:x,isLoading:P,error:b,requestIdentity:A,restartIdentity:F}=Cr(t),[j,N]=o.useState(null),[M,Y]=o.useState(null),[L,$]=o.useState([]),[K,ee]=o.useState([]),[I,f]=o.useState(!0),[O,q]=o.useState(!1),[Q,B]=o.useState(null),[J,se]=o.useState(!1),V=o.useRef(!1),[ge,ie]=o.useState({}),[de,be]=o.useState({}),E=d!=null&&d.reviewPageFields&&d.reviewPageFields.length>0?d.reviewPageFields[0]:null,W=!!(d!=null&&d.reviewPageDisabled),z=o.useRef(!1);z.current=W;const H=Ue.useForm({defaultValues:{street:"",streetNumber:"",city:"",zip:"",country:"",nationality:"",phonenumber:""}});o.useEffect(()=>{if(W){V.current||(V.current=!0,A().then(()=>q(!0)).catch(D=>console.error("[Identity] Auto-request failed:",D)).finally(()=>f(!1)));return}(async()=>{try{const[D,U,_]=await Promise.all([n.getApplicantData(t),i.getCountries("","en"),i.getCountries("","en",40)]);Y(D);const p=new Set,v=U.map(S=>({value:S.abbreviation3||S.abbreviation,label:S.name})).filter(S=>!S.value||p.has(S.value)?!1:(p.add(S.value),!0));$(v);const T=new Set,k=_.filter(S=>S.countryCode).map(S=>({value:S.countryCode,label:`${S.countryCode} – ${S.name}`})).filter(S=>T.has(S.value)?!1:(T.add(S.value),!0));ee(k);const a=D.applicantRequestData;if(ie({firstName:(a==null?void 0:a.firstName)||"",lastName:(a==null?void 0:a.lastName)||"",email:(a==null?void 0:a.email)||"",dateOfBirth:(a==null?void 0:a.dateOfBirth)||"",title:(a==null?void 0:a.title)||"",salutation:(a==null?void 0:a.salutation)||"",phonenumber:(a==null?void 0:a.phonenumber)||"",mobileCountryCode:(a==null?void 0:a.mobileCountryCode)||"",street:(a==null?void 0:a.street)||"",streetNumber:(a==null?void 0:a.streetNumber)||"",city:(a==null?void 0:a.city)||"",zip:(a==null?void 0:a.zip)||"",country:(a==null?void 0:a.country)||"",nationality:(a==null?void 0:a.nationality)||"",taxCountry:(a==null?void 0:a.taxCountry)||"",countryOfBirth:(a==null?void 0:a.countryOfBirth)||"",placeOfBirth:(a==null?void 0:a.placeOfBirth)||"",educationLevel:(a==null?void 0:a.educationLevel)||"",occupation:(a==null?void 0:a.occupation)||"",taxNumber:(a==null?void 0:a.taxNumber)||"",defaultLanguage:(a==null?void 0:a.defaultLanguage)||""}),H.reset({street:(a==null?void 0:a.street)||"",streetNumber:(a==null?void 0:a.streetNumber)||"",city:(a==null?void 0:a.city)||"",zip:(a==null?void 0:a.zip)||"",country:(a==null?void 0:a.country)||"",nationality:(a==null?void 0:a.nationality)||"",phonenumber:(a==null?void 0:a.phonenumber)||""}),D.kycRecords&&D.kycRecords.length>0&&D.kycRecords[0].providerTokenObject!==null&&!V.current&&z.current){console.log("[Identity] Review page disabled + existing identity — auto-requesting..."),V.current=!0;try{await A(),q(!0)}catch(S){console.error("[Identity] Auto-request failed:",S)}}}catch(D){console.error("Error loading applicant data:",D)}finally{f(!1)}})()},[t]),o.useEffect(()=>{m&&!O&&z.current&&(console.log("[Identity] Review page disabled — showing cached provider"),q(!0))},[m,O]),o.useEffect(()=>{if(x){if(x.expiresAt){const y=new Date(x.expiresAt).getTime();if(Date.now()>=y){console.warn("[Identity] Token has expired (expiresAt)"),se(!0),B("Your verification session has expired. Please restart.");return}}if(x.url)try{const D=new URL(x.url).toString().toLowerCase();if(D.includes("expired")||D.includes("invalid")||D.includes("error")){console.warn("[Identity] Token URL indicates expiration"),se(!0),B("Your verification link has expired. Please restart.");return}}catch{console.error("[Identity] Invalid token URL")}if(x.status==="expired"||x.error==="expired"||x.expired===!0){console.warn("[Identity] Token object indicates expiration"),se(!0),B("Your verification session has expired. Please restart.");return}}},[x]);const pe=(x==null?void 0:x.accessToken)||(x==null?void 0:x.token),R=u!==null&&u===Ee.Sumsub&&!!pe;o.useEffect(()=>{if(u!==null&&x&&!j&&O&&!J){const y=u;if(R){console.log("[Sumsub] Initializing Web SDK with accessToken"),B(null);try{const D=Be.parseProviderConfig(u,x,c);D.onTokenRefresh=()=>l.refreshSumsubToken(t);const U=Be.createProvider(u,D);U.onComplete(_=>{console.log("[Sumsub] Verification complete:",_),r==null||r()}),U.onError(_=>{console.error("[Sumsub] SDK error:",_),(typeof _=="string"?_:(_==null?void 0:_.message)||"Unknown error").toLowerCase().includes("expired")&&(se(!0),B("Session expired. Please restart."))}),U.initialize("sumsub-websdk-container").then(()=>{console.log("[Sumsub] Web SDK launched"),N(U)}).catch(_=>{var p;console.error("[Sumsub] Initialization error:",_),B(`Failed to initialize: ${_.message}`),(p=_.message)!=null&&p.toLowerCase().includes("expired")&&se(!0)})}catch(D){console.error("[Sumsub] Setup error:",D),B(`Configuration error: ${D.message}`)}return}if(x.url){console.log("[Identity] Loading provider URL for user verification:",x.url),B(null);try{if(new URL(x.url),y===Ee.SardinAI){console.log("[SardinAI] Initializing Risk SDK in background...");try{const D=Be.parseProviderConfig(u,x,c);Be.createProvider(u,D).initialize().then(()=>console.log("[SardinAI] Risk SDK initialized in background")).catch(_=>console.warn("[SardinAI] Risk SDK init failed (non-blocking):",_))}catch(D){console.warn("[SardinAI] Risk SDK setup failed (non-blocking):",D)}}N({type:"url",url:x.url})}catch(D){console.error("[Identity] Invalid URL:",D),B("Invalid verification URL. Please restart."),se(!0)}return}if(y===Ee.SardinAI){console.log("[SardinAI] No URL provided - initializing Risk SDK only..."),B(null);try{const D=Be.parseProviderConfig(u,x,c),U=Be.createProvider(u,D);U.initialize().then(()=>{console.log("[SardinAI] Risk SDK initialized successfully"),N(U),setTimeout(()=>r==null?void 0:r(),2e3)}).catch(_=>{var v;console.error("[SardinAI] Failed to initialize:",_);const p=((v=_.message)==null?void 0:v.toLowerCase())||"";p.includes("expired")||p.includes("invalid")||p.includes("401")||p.includes("400")?(se(!0),B("Session expired or invalid. Please restart verification.")):B(`Failed to initialize: ${_.message}`)})}catch(D){console.error("[SardinAI] Error creating provider:",D),B(`Configuration error: ${D.message}`)}return}try{B(null);const D=Be.parseProviderConfig(u,x,c),U=Be.createProvider(u,D);y===Ee.Onfido&&U.initialize("identity-container").catch(_=>{console.error("[Onfido] Initialization error:",_),B(`Failed to initialize: ${_.message}`)}),N(U)}catch(D){console.error("[Identity] Provider setup error:",D),B(`Setup error: ${D.message}`)}}return()=>{if(j&&j.destroy)try{j.destroy()}catch(y){console.error("[Identity] Error destroying provider:",y)}}},[u,x,j,O,r,J,R,t,c,l]);const te=async()=>{try{B(null),se(!1),await A(),q(!0)}catch(y){console.error("Error starting identity verification:",y)}},oe=async()=>{try{B(null),se(!1),N(null),console.log("[Identity] Restarting verification..."),await F(),q(!0)}catch(y){console.error("Error restarting identity verification:",y),B(y.message||"Failed to restart verification")}};if(I||P)return e.jsx(Z,{children:e.jsxs(X,{children:[e.jsx(Ie,{className:"my-8"}),e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-4",children:"Loading identity verification..."})]})});if(b)return e.jsx(Z,{children:e.jsx(X,{children:e.jsxs("p",{className:"text-danger-500",children:["Error: ",b.message]})})});if(O&&(Q||J))return e.jsxs(Z,{children:[e.jsx(he,{children:e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"Verification Session Issue"})}),e.jsxs(X,{children:[e.jsx("div",{className:"p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg mb-6",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("svg",{className:"h-6 w-6 text-red-600 dark:text-red-400 mr-3 mt-0.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-red-900 dark:text-red-100 mb-1",children:J?"Session Expired":"Verification Error"}),e.jsx("p",{className:"text-red-800 dark:text-red-200 text-sm",children:Q||"Your verification session has expired and needs to be restarted."})]})]})}),e.jsxs("div",{className:"bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-4",children:[e.jsx("h3",{className:"font-semibold text-blue-900 dark:text-blue-100 mb-2",children:"What to do next:"}),e.jsxs("ul",{className:"text-blue-800 dark:text-blue-200 text-sm space-y-1 list-disc list-inside",children:[e.jsx("li",{children:'Click "Restart Verification" below to generate a new session'}),e.jsx("li",{children:"Complete the verification process without delays"}),e.jsx("li",{children:"If issues persist, contact support"})]})]})]}),e.jsxs(fe,{className:"flex justify-between",children:[s&&e.jsx(G,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(G,{type:"button",onClick:oe,disabled:P,children:P?"Restarting...":"Restart Verification"})]})]});if(O&&m){const y=u;return R?e.jsxs(Z,{children:[e.jsx(he,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Identity Verification"}),e.jsx("p",{style:{color:"var(--metakyc-text-secondary, #6b7280)",marginTop:"4px",fontSize:"14px"},children:"Please complete the identity verification process"})]}),e.jsx(G,{type:"button",variant:"outline",size:"sm",onClick:oe,disabled:P,children:"Restart"})]})}),e.jsx(X,{children:e.jsx("div",{id:"sumsub-websdk-container",style:{minHeight:"500px",width:"100%"}})}),s&&e.jsx(fe,{children:e.jsx(G,{variant:"outline",onClick:s,children:"Back"})})]}):x!=null&&x.url?e.jsxs(Z,{children:[e.jsx(he,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Identity Verification"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:"Please complete the identity verification process"})]}),e.jsx(G,{type:"button",variant:"outline",size:"sm",onClick:oe,disabled:P,children:"Restart"})]})}),e.jsxs(X,{children:[e.jsx("div",{className:"mb-4 p-3 bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg",children:e.jsxs("p",{className:"text-yellow-800 dark:text-yellow-200 text-sm",children:[e.jsx("strong",{children:"Important:"}),' If you see an "expired" or "invalid link" message below, click the "Restart" button above to generate a new verification session.']})}),e.jsx("div",{className:"w-full",style:{height:"600px"},children:e.jsx("iframe",{src:x.url,className:"w-full h-full border-0 rounded-lg",allow:"camera; microphone; geolocation",title:"Identity Verification",onLoad:D=>{var U,_,p;console.log("[Identity] Iframe loaded");try{const v=D.target,T=v.contentDocument||((U=v.contentWindow)==null?void 0:U.document);if(T){const k=((p=(_=T.body)==null?void 0:_.textContent)==null?void 0:p.toLowerCase())||"";(k.includes("expired")||k.includes("invalid")||k.includes("error"))&&(console.warn("[Identity] Iframe shows expiration message"),se(!0),B("Your verification link has expired."))}}catch{console.log("[Identity] Cannot check iframe content (CORS)")}}})})]}),s&&e.jsx(fe,{children:e.jsx(G,{variant:"outline",onClick:s,children:"Back"})})]}):y===Ee.SardinAI?e.jsxs(Z,{children:[e.jsxs(he,{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Device Risk Assessment"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:"Analyzing device security and behavioral patterns..."})]}),e.jsx(X,{children:e.jsxs("div",{className:"text-center py-12",children:[e.jsx(Ie,{className:"mb-4"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Please wait while we verify your device security"}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-500 mt-2",children:"This process is automatic and will complete in a few seconds"})]})})]}):e.jsxs(Z,{children:[e.jsxs(he,{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Identity Verification"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:"Please complete the identity verification process"})]}),e.jsx(X,{children:e.jsx("div",{id:"identity-container",className:"min-h-[400px]"})}),s&&e.jsx(fe,{children:e.jsx(G,{variant:"outline",onClick:s,children:"Back"})})]})}const ye=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),ce=(y=4)=>({1:"col-span-1",2:"col-span-2",3:"col-span-3",4:"col-span-4"})[y]||"col-span-4",Fe=(y,D)=>{if(!D&&D!==0)return"—";if(ye.has(y)&&y!=="mobileCountryCode"){const U=L.find(_=>_.value===D);return U?U.label:String(D)}return String(D)},Me=({helpText:y})=>{const[D,U]=o.useState(!1),_=o.useRef(null),[,p]=o.useState({top:0,left:0}),v=()=>{if(_.current){const T=_.current.getBoundingClientRect();p({top:T.bottom+window.scrollY+6,left:T.left+window.scrollX})}U(!0)};return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"metakyc-help-btn",ref:_,onClick:v,style:{width:18,height:18,borderRadius:"50%",border:"1.5px solid var(--metakyc-primary, #2563eb)",background:"transparent",color:"var(--metakyc-primary, #2563eb)",fontSize:11,fontWeight:700,cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,lineHeight:1,position:"relative",zIndex:2},children:"?"}),D&&ut.createPortal(e.jsx("div",{style:{position:"fixed",inset:0,zIndex:99999,background:"rgba(0,0,0,0.55)",backdropFilter:"blur(6px)",WebkitBackdropFilter:"blur(6px)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:()=>U(!1),children:e.jsxs("div",{onClick:T=>T.stopPropagation(),style:{background:"var(--metakyc-surface, var(--metakyc-background, #ffffff))",border:"1px solid var(--metakyc-border, #e5e7eb)",borderRadius:"var(--metakyc-border-radius, 8px)",padding:"20px 24px",maxWidth:400,width:"90%",boxShadow:"0 24px 64px rgba(0,0,0,0.4)"},children:[e.jsx("div",{dangerouslySetInnerHTML:{__html:y},style:{fontSize:13,color:"var(--metakyc-text-primary, #111827)",lineHeight:1.6}}),e.jsx("button",{type:"button",onClick:()=>U(!1),style:{marginTop:12,padding:"4px 12px",fontSize:12,border:"1px solid var(--metakyc-border, #e5e7eb)",borderRadius:"var(--metakyc-border-radius, 6px)",background:"transparent",cursor:"pointer",color:"var(--metakyc-text-secondary, #6b7280)"},children:"Close"})]})}),document.body)]})},ve=(y,D)=>D?e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:5,flexWrap:"nowrap"},children:[e.jsx("div",{style:{flex:1,minWidth:0},children:y}),e.jsx("div",{style:{paddingTop:24},children:e.jsx(Me,{helpText:D})})]}):y,Je=(y,D)=>{const U=`cf-${D}`,_=y.paramName??"",p=de[_];if(y.customType==="br")return e.jsx("div",{className:ce(y.colSpan),style:{minHeight:"0.5rem"}},U);if(y.customType==="paragraph")return e.jsx("div",{className:ce(y.colSpan),children:e.jsx("div",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:y.label||""}})},U);if(y.customType==="html")return e.jsx("div",{className:ce(y.colSpan),dangerouslySetInnerHTML:{__html:y.label||""}},U);if(y.customType==="link")return e.jsx("div",{className:ce(y.colSpan),children:ve(e.jsx("a",{href:y.linkUrl??"#",target:"_blank",rel:"noopener noreferrer",className:"text-sm underline",style:{color:"var(--metakyc-primary, #6366f1)"},children:y.displayText||y.label||y.linkText||y.linkUrl}),y.helpText)},U);if(y.customType==="checkbox"||y.customType==="link_checkbox"){const v=p==="true"||p===!0;return e.jsx("div",{className:ce(y.colSpan),children:ve(e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:!!v,onChange:T=>be(k=>({...k,[_]:String(T.target.checked)})),style:{width:16,height:16,flexShrink:0,marginTop:2,accentColor:"var(--metakyc-primary, #6366f1)"}}),e.jsx("span",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)"},children:y.customType==="link_checkbox"&&y.linkUrl?e.jsxs(e.Fragment,{children:[e.jsx("a",{href:y.linkUrl,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--metakyc-primary, #6366f1)",textDecoration:"underline"},children:y.linkText||y.label}),y.label&&y.linkText?` ${y.label}`:""]}):y.displayText||y.label})]}),y.helpText)},U)}if(y.customType==="group_checkbox"){const v=Array.isArray(p)?p:p?[p]:[],T=k=>{y.singleSelect?be(a=>({...a,[_]:v[0]===k?[]:[k]})):be(a=>({...a,[_]:v.includes(k)?v.filter(g=>g!==k):[...v,k]}))};return e.jsx("div",{className:ce(y.colSpan),children:ve(e.jsxs("div",{className:"space-y-1.5",children:[y.label&&e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:y.displayText||y.label}),(y.options||[]).map(k=>e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:v.includes(k.value),onChange:()=>T(k.value),style:{width:16,height:16,flexShrink:0,marginTop:2,accentColor:"var(--metakyc-primary, #6366f1)"}}),e.jsx("span",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)"},children:k.label})]},k.value))]}),y.helpText)},U)}return y.customType==="radio_group"?e.jsx("div",{className:ce(y.colSpan),children:ve(e.jsxs("div",{className:"space-y-1.5",children:[y.label&&e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:y.displayText||y.label}),(y.options||[]).map(v=>e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"radio",name:`rg-${_}`,value:v.value,checked:p===v.value,onChange:()=>be(T=>({...T,[_]:v.value})),style:{width:16,height:16,flexShrink:0,marginTop:2,accentColor:"var(--metakyc-primary, #6366f1)"}}),e.jsx("span",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)"},children:v.label})]},v.value))]}),y.helpText)},U):e.jsx("div",{className:ce(y.colSpan),children:ve(e.jsx(me,{label:y.displayText||y.label||_,value:String(p??""),onChange:v=>be(T=>({...T,[_]:v.target.value}))}),y.helpText)},U)},Ze=(y,D)=>{if(y.isCustom)return Je(y,D);const U=y.name??"",_=Ve[U],p=y.displayText||(_==null?void 0:_.label)||U,v=ge[U]??"",T=U==="mobileCountryCode",k=!!(_!=null&&_.countriesType)&&!T;return y.editable?T?e.jsx("div",{className:ce(y.colSpan??2),children:ve(e.jsx(De,{label:p,value:String(v),onChange:a=>ie(g=>({...g,[U]:a})),options:[{value:"",label:"Select country code…"},...K]}),y.helpText)},`epc-${D}`):k?e.jsx("div",{className:ce(y.colSpan??2),children:ve(e.jsx(De,{label:p,value:String(v),onChange:a=>ie(g=>({...g,[U]:a})),options:[{value:"",label:`Select ${p.toLowerCase()}…`},...L]}),y.helpText)},`ec-${D}`):e.jsx("div",{className:ce(y.colSpan??2),children:ve(e.jsx(me,{label:p,type:(_==null?void 0:_.type)==="date"?"date":(_==null?void 0:_.type)==="email"?"email":"text",value:String(v),onChange:a=>ie(g=>({...g,[U]:a.target.value}))}),y.helpText)},`ei-${D}`):e.jsx("div",{className:ce(y.colSpan??2),children:ve(e.jsxs(e.Fragment,{children:[e.jsx("label",{className:"block text-sm font-medium mb-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:p}),e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)",minHeight:"1.5rem"},children:Fe(U,v)})]}),y.helpText)},`ro-${D}`)};if(E){const y=E.title||"Review Your Information",D=E.subtitle||"Please review and confirm your information before starting identity verification";return e.jsx("form",{onSubmit:U=>{U.preventDefault(),te()},children:e.jsxs(Z,{children:[e.jsxs(he,{children:[e.jsx("h2",{className:"text-lg font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:y}),e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:D})]}),e.jsx(X,{children:e.jsx("div",{className:"grid grid-cols-4 gap-4",children:E.fields.map((U,_)=>Ze(U,_))})}),e.jsxs(fe,{className:"flex justify-between",children:[s&&e.jsx(G,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(G,{type:"submit",isLoading:P,children:"Confirm and Start Verification"})]})]})})}return e.jsx("form",{onSubmit:H.handleSubmit(te),children:e.jsxs(Z,{children:[e.jsxs(he,{children:[e.jsx("h2",{className:"text-lg font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Review Your Information"}),e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Please review and confirm your information before starting identity verification"})]}),e.jsxs(X,{className:"space-y-6",children:[e.jsx("div",{className:"space-y-4 pb-4",style:{borderBottom:"1px solid var(--metakyc-border, #e5e7eb)"},children:[{label:"Name",value:`${((Oe=M==null?void 0:M.applicantRequestData)==null?void 0:Oe.firstName)||""} ${((Xe=M==null?void 0:M.applicantRequestData)==null?void 0:Xe.lastName)||""}`.trim()},{label:"Email",value:(He=M==null?void 0:M.applicantRequestData)==null?void 0:He.email},{label:"Date of Birth",value:((Ye=M==null?void 0:M.applicantRequestData)==null?void 0:Ye.dateOfBirth)||"Not provided"}].map(({label:y,value:D})=>e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:y}),e.jsx("p",{className:"mt-1 text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:D})]},y))}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Address Information"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Ue.Controller,{control:H.control,name:"country",render:({field:y})=>e.jsx(De,{label:"Country",value:y.value,onChange:y.onChange,options:[{value:"",label:"Select country…"},...L]})}),e.jsx(Ue.Controller,{control:H.control,name:"nationality",render:({field:y})=>e.jsx(De,{label:"Nationality",value:y.value,onChange:y.onChange,options:[{value:"",label:"Select nationality…"},...L]})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Ue.Controller,{control:H.control,name:"street",render:({field:y})=>e.jsx(me,{...y,label:"Street"})}),e.jsx(Ue.Controller,{control:H.control,name:"streetNumber",render:({field:y})=>e.jsx(me,{...y,label:"Street Number"})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Ue.Controller,{control:H.control,name:"city",render:({field:y})=>e.jsx(me,{...y,label:"City"})}),e.jsx(Ue.Controller,{control:H.control,name:"zip",render:({field:y})=>e.jsx(me,{...y,label:"ZIP / Postal Code"})})]}),e.jsx(Ue.Controller,{control:H.control,name:"phonenumber",render:({field:y})=>e.jsx(me,{...y,label:"Phone Number",type:"tel"})})]})]}),e.jsxs(fe,{className:"flex justify-between",children:[s&&e.jsx(G,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(G,{type:"submit",isLoading:P,children:"Confirm and Start Verification"})]})]})})},ht=({kycStatus:t,reviewStatus:r,workflowResult:s,customMessage:n,onContinue:i,onContactSupport:l})=>{const d=t===Ke.Approved?{type:"success",title:"Verification Approved",icon:"✓",iconBg:"bg-green-100 dark:bg-green-900/30",iconColor:"text-green-600 dark:text-green-400",message:"Your identity verification has been successfully approved."}:t===Ke.Rejected?{type:"error",title:"Verification Rejected",icon:"✕",iconBg:"bg-red-100 dark:bg-red-900/30",iconColor:"text-red-600 dark:text-red-400",message:"Unfortunately, your identity verification was not approved."}:t===Ke.Pending||t===Ke.InProgress?{type:"pending",title:"Verification Pending",icon:"⏱",iconBg:"bg-blue-100 dark:bg-blue-900/30",iconColor:"text-blue-600 dark:text-blue-400",message:"Your identity verification is currently being processed."}:r===qe.Approved?{type:"success",title:"Application Approved",icon:"✓",iconBg:"bg-green-100 dark:bg-green-900/30",iconColor:"text-green-600 dark:text-green-400",message:"Your application has been approved."}:r===qe.Reject?{type:"error",title:"Application Rejected",icon:"✕",iconBg:"bg-red-100 dark:bg-red-900/30",iconColor:"text-red-600 dark:text-red-400",message:"Your application has been rejected."}:r===qe.UnderReview||r===qe.AdminReview?{type:"pending",title:"Under Review",icon:"📋",iconBg:"bg-yellow-100 dark:bg-yellow-900/30",iconColor:"text-yellow-700 dark:text-yellow-400",message:"Your application is currently under manual review."}:s===it.Success?{type:"success",title:"Process Complete",icon:"✓",iconBg:"bg-green-100 dark:bg-green-900/30",iconColor:"text-green-600 dark:text-green-400",message:"Your verification process has been completed successfully."}:s===it.Failed?{type:"error",title:"Process Failed",icon:"✕",iconBg:"bg-red-100 dark:bg-red-900/30",iconColor:"text-red-600 dark:text-red-400",message:"The verification process could not be completed."}:s===it.AdminReview?{type:"pending",title:"Admin Review Required",icon:"📋",iconBg:"bg-yellow-100 dark:bg-yellow-900/30",iconColor:"text-yellow-700 dark:text-yellow-400",message:"Your application requires administrator review."}:{type:"pending",title:"Processing",icon:"⏱",iconBg:"bg-blue-100 dark:bg-blue-900/30",iconColor:"text-blue-600 dark:text-blue-400",message:"Your application is being reviewed."};return e.jsxs(Z,{children:[e.jsxs(X,{className:"py-12",children:[e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx("div",{className:`w-24 h-24 rounded-full flex items-center justify-center ${d.iconBg}`,children:e.jsx("span",{className:`text-5xl ${d.iconColor}`,children:d.icon})})}),e.jsx("h2",{className:"text-3xl font-bold text-center mb-4",style:{color:"var(--metakyc-text-primary, #111827)"},children:d.title}),e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx(vt,{variant:d.type==="success"?"success":d.type==="error"?"danger":d.type==="pending"?"warning":"info",children:t!=null?Ke[t]:qe[r]})}),e.jsx("p",{className:"text-center mb-6 max-w-md mx-auto",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:n||d.message}),d.type==="success"&&e.jsxs("div",{className:"bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg p-4 mb-6",children:[e.jsx("h3",{className:"font-semibold text-green-900 dark:text-green-100 mb-2",children:"What's Next?"}),e.jsxs("ul",{className:"text-sm text-green-800 dark:text-green-200 space-y-1",children:[e.jsx("li",{children:"✓ Your identity has been verified"}),e.jsx("li",{children:"✓ You can now proceed with your application"}),e.jsx("li",{children:"✓ All features are now accessible"})]})]}),d.type==="error"&&e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 mb-6",children:[e.jsx("h3",{className:"font-semibold text-red-900 dark:text-red-100 mb-2",children:"What Can You Do?"}),e.jsxs("ul",{className:"text-sm text-red-800 dark:text-red-200 space-y-2",children:[e.jsx("li",{children:"• Review the requirements and ensure all information is correct"}),e.jsx("li",{children:"• Contact our support team for assistance"}),e.jsx("li",{children:"• You may be able to resubmit your application"})]})]}),d.type==="pending"&&e.jsxs("div",{className:"bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-4 mb-6",children:[e.jsx("h3",{className:"font-semibold text-blue-900 dark:text-blue-100 mb-2",children:"What Happens Next?"}),e.jsxs("ul",{className:"text-sm text-blue-800 dark:text-blue-200 space-y-2",children:[e.jsx("li",{children:"• Our team is reviewing your information"}),e.jsx("li",{children:"• You will be notified via email once the review is complete"}),e.jsx("li",{children:"• This typically takes 24-48 hours"}),e.jsx("li",{children:"• No action is required from you at this time"})]})]}),e.jsx("div",{className:"mt-6 pt-6",style:{borderTop:"1px solid var(--metakyc-border, #e5e7eb)"},children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"KYC Status:"}),e.jsx("div",{className:"font-medium mt-1",style:{color:"var(--metakyc-text-primary, #111827)"},children:t!=null?Ke[t]:"Not Available"})]}),e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"Review Status:"}),e.jsx("div",{className:"font-medium mt-1",style:{color:"var(--metakyc-text-primary, #111827)"},children:qe[r]})]})]})})]}),e.jsxs(fe,{className:"flex justify-center gap-4",children:[d.type==="success"&&i&&e.jsx(G,{onClick:i,size:"lg",children:"Continue"}),d.type==="error"&&e.jsxs(e.Fragment,{children:[l&&e.jsx(G,{variant:"outline",onClick:l,children:"Contact Support"}),i&&e.jsx(G,{onClick:i,children:"Try Again"})]}),d.type==="pending"&&e.jsx("div",{className:"text-center",children:e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Please check back later or wait for our email notification"})})]})]})},$r=({config:t,className:r=""})=>!(t!=null&&t.visible)||!(t!=null&&t.url)?null:e.jsx("div",{className:`metakyc-logo ${r}`,children:e.jsx("img",{src:t.url,alt:t.alt||"Company Logo",style:{width:t.width||"auto",height:t.height||"40px",maxWidth:"100%",objectFit:"contain"},onError:s=>{console.warn("[Logo] Failed to load logo:",t.url),s.target.style.display="none"}})}),st=({title:t,subtitle:r,className:s=""})=>{const{currentTheme:n}=Ce(),i=t||(n==null?void 0:n.title)||"",l=!!(n!=null&&n.logo&&n.logo.visible&&n.logo.url),c=!!i;return!l&&!c?null:e.jsxs("div",{className:`metakyc-header ${s}`,children:[e.jsxs("div",{className:"metakyc-header-title flex items-center text-xl font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:[l&&e.jsx($r,{config:n.logo}),l&&c&&e.jsx("span",{style:{fontSize:"1.5rem",fontWeight:300,color:"var(--metakyc-text-muted, #9ca3af)",margin:"0 12px"},children:"|"}),c&&e.jsx("span",{style:{color:"var(--metakyc-text-primary, #111827)"},children:i})]}),r&&e.jsx("p",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:r})]})},ct=["firstName","lastName","email","phonenumber","dateOfBirth"];function et(t){return t==null||t===""||Array.isArray(t)&&t.length===0}const at={width:"16px",height:"16px",minWidth:"16px",flexShrink:0,flexGrow:0,accentColor:"var(--metakyc-primary, #2563eb)",cursor:"pointer",margin:0,padding:0,display:"inline-block",verticalAlign:"middle"},Rt=({helpText:t,children:r})=>{const[s,n]=o.useState(!1);if(!t)return e.jsx(e.Fragment,{children:r});const i=s?e.jsx("div",{role:"dialog","aria-modal":"true",onClick:()=>n(!1),style:{position:"fixed",inset:0,zIndex:999999,background:"rgba(0, 0, 0, 0.55)",backdropFilter:"blur(6px)",WebkitBackdropFilter:"blur(6px)",display:"flex",alignItems:"center",justifyContent:"center",padding:"16px"},children:e.jsxs("div",{onClick:l=>l.stopPropagation(),style:{background:"var(--metakyc-surface, var(--metakyc-background, #ffffff))",border:"1px solid var(--metakyc-border, #e5e7eb)",borderRadius:"12px",padding:"28px 24px 24px",maxWidth:"480px",width:"100%",maxHeight:"80vh",overflowY:"auto",boxShadow:"0 24px 64px rgba(0,0,0,0.4)",position:"relative"},children:[e.jsx("button",{type:"button",onClick:()=>n(!1),"aria-label":"Close",style:{position:"absolute",top:"12px",right:"12px",width:"28px",height:"28px",borderRadius:"50%",border:"1px solid var(--metakyc-border, #e5e7eb)",background:"var(--metakyc-input-bg, #f3f4f6)",color:"var(--metakyc-text-secondary, #6b7280)",fontSize:"16px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:"×"}),e.jsx("div",{style:{color:"var(--metakyc-text-primary, #111827)",fontSize:"14px",lineHeight:1.75},dangerouslySetInnerHTML:{__html:t}})]})}):null;return e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"5px",flexWrap:"nowrap"},children:[r,e.jsx("button",{type:"button",className:"metakyc-help-btn",onClick:()=>n(!0),"aria-label":"Help",style:{flexShrink:0,marginTop:"2px",width:"18px",height:"18px",borderRadius:"50%",border:"1.5px solid var(--metakyc-primary, #2563eb)",background:"transparent",color:"var(--metakyc-primary, #2563eb)",fontSize:"10px",fontWeight:"700",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,padding:0,position:"relative",zIndex:2,transition:"background 0.15s, color 0.15s"},onMouseEnter:l=>{l.currentTarget.style.background="var(--metakyc-primary, #2563eb)",l.currentTarget.style.color="#ffffff"},onMouseLeave:l=>{l.currentTarget.style.background="transparent",l.currentTarget.style.color="var(--metakyc-primary, #2563eb)"},children:"?"}),typeof document<"u"&&i?ut.createPortal(i,document.body):null]})},Rs=({workflowKey:t,externalRefId:r,onSuccess:s,onCancel:n})=>{var D,U,_,p,v,T,k;const{config:i,baseInformationService:l,currentTheme:c}=Ce(),{createApplicant:d,isLoading:m}=bt(),u=t||((D=i.applicantForm)==null?void 0:D.workflowKey);if(!u)throw new Error("workflowKey is required. Provide it either as a prop to CreateApplicantForm or set it in config.applicantForm.workflowKey");const x=r||((U=i.applicantForm)==null?void 0:U.externalRefId)||"",P=((_=i.applicantForm)==null?void 0:_.email)||"",b=((p=i.applicantForm)==null?void 0:p.hiddenValues)||{},A=((v=i.applicantForm)==null?void 0:v.initialValues)||{},j=(((T=i.applicantForm)==null?void 0:T.fieldLabelMode)||(c==null?void 0:c.fieldLabelMode)||"label")!=="placeholder",N=o.useMemo(()=>c!=null&&c.applicantFormPages&&c.applicantFormPages.length>0?c.applicantFormPages:null,[c==null?void 0:c.applicantFormPages]),M=o.useMemo(()=>{const a=new Set(ct),g=c==null?void 0:c.applicantFormRequiredFields;if(g)for(const S of g)a.add(S);if(N)for(const S of N)for(const h of S.fields)!h.isCustom&&h.name&&h.required&&a.add(h.name);return Array.from(a)},[c==null?void 0:c.applicantFormRequiredFields,N]),Y=o.useMemo(()=>{var S;if(N){const h=N.flatMap(w=>w.fields).filter(w=>!w.isCustom&&w.name).map(w=>w.name),C=new Set(h);for(const w of ct)C.add(w);return Array.from(C)}let a;(S=i.applicantForm)!=null&&S.visibleFields?a=i.applicantForm.visibleFields:c!=null&&c.applicantFormVisibleFields&&c.applicantFormVisibleFields.length>0?a=c.applicantFormVisibleFields:a=$t;const g=new Set(a);for(const h of ct)g.add(h);return Array.from(g)},[(k=i.applicantForm)==null?void 0:k.visibleFields,c==null?void 0:c.applicantFormVisibleFields,N]),L=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),$=o.useMemo(()=>{var g,S;const a=new Set;if(N)for(const h of N)for(const C of h.fields)!C.isCustom&&C.name&&L.has(C.name)&&a.add(C.countriesType??((g=Ve[C.name])==null?void 0:g.countriesType));else for(const h of Y)L.has(h)&&a.add((S=Ve[h])==null?void 0:S.countriesType);return a.size===0&&a.add(void 0),Array.from(a)},[Y,N]),[K,ee]=o.useState({}),[I,f]=o.useState(!0),O=o.useRef(new Set),q=o.useRef(new Set);o.useEffect(()=>{if(!c)return;const a=$.filter(h=>{const C=h!=null?String(h):"all";return!q.current.has(C)&&!O.current.has(C)});if(a.length===0){$.every(C=>{const w=C!=null?String(C):"all";return q.current.has(w)})&&f(!1);return}f(!0);const g=a.map(h=>h!=null?String(h):"all");g.forEach(h=>O.current.add(h)),(async()=>{try{const h=await Promise.all(a.map(async C=>{const w=C!=null?String(C):"all",le=await l.getCountries("",i.locale||"en",C),re=C===40,xe=new Set,Re=le.map(ne=>re&&ne.countryCode?{value:ne.countryCode,label:`${ne.countryCode} – ${ne.name}`}:{value:ne.abbreviation3||ne.abbreviation,label:ne.name}).filter(ne=>!ne.value||xe.has(ne.value)?!1:(xe.add(ne.value),!0));return q.current.add(w),O.current.delete(w),[w,Re]}));ee(C=>({...C,...Object.fromEntries(h)}))}catch(h){g.forEach(C=>O.current.delete(C)),console.error("Failed to load countries:",h)}finally{$.every(C=>{const w=C!=null?String(C):"all";return q.current.has(w)})&&f(!1)}})()},[$,c]);const Q=(a,g)=>{var C;const S=g??((C=Ve[a])==null?void 0:C.countriesType),h=S!=null?String(S):"all";return K[h]||[]},B={firstName:1,lastName:1,title:1,email:1,dateOfBirth:1,phonenumber:1,mobileCountryCode:1,street:1,streetNumber:1,zip:1,city:1,country:1,nationality:1,otherNationality:1,defaultLanguage:1,taxCountry:1,placeOfBirth:1,countryOfBirth:1,salutation:1,educationLevel:1,occupation:1,taxNumber:1},J=Object.fromEntries(Object.entries(b).filter(([a])=>a in B)),se=Object.fromEntries(Object.entries(A).filter(([a])=>a in B)),[V,ge]=o.useState({workflowKey:u,firstName:"",lastName:"",title:"",email:P,dateOfBirth:"",phonenumber:"",externalRefId:x,mobileCountryCode:"",street:"",streetNumber:"",zip:"",city:"",country:"",nationality:"",otherNationality:[],defaultLanguage:"EN",taxCountry:"",placeOfBirth:"",countryOfBirth:"",salutation:null,educationLevel:"",occupation:"",taxNumber:"",...J,...se}),ie=Object.fromEntries(Object.entries(b).filter(([a])=>!(a in J)&&a!=="externalRefId"&&a!=="workflowKey")),[de,be]=o.useState({...ie}),[E,W]=o.useState(0),[z,H]=o.useState({}),[pe,R]=o.useState(null),[te,oe]=o.useState(!1),ye=(a,g)=>ge(S=>({...S,[a]:g})),ce=(a,g)=>be(S=>({...S,[a]:g})),Fe=a=>!a.conditionalOn||de[a.conditionalOn]==="true",Me=N&&E<N.length-1?E+1:-1,ve=N&&E>0?E-1:-1,Je=a=>{var S;const g={};for(const h of a.fields)if(h.isCustom){if(h.customType==="paragraph"||h.customType==="html"||h.customType==="br"||h.customType==="link")continue;if(h.required&&h.paramName){const C=de[h.paramName],w=h.displayText||h.label||h.paramName;h.customType==="checkbox"||h.customType==="link_checkbox"?C!=="true"&&(g[h.paramName]=`${w} is required.`):(!C||C.trim()==="")&&(g[h.paramName]=`${w} is required.`)}}else if(h.name){const C=h.name;if(M.includes(C)&&et(V[C])){const w=h.displayText||((S=Ve[C])==null?void 0:S.label)||C;g[C]=`${w} is required.`}}return g},Ze=async()=>{if(!N)return;const a=N[E];if(a.conditionalOn&&!Fe(a)){H({}),Me>=0?W(Me):await Oe();return}const g=Je(a);if(Object.keys(g).length>0){H(g);return}H({}),Me>=0?W(Me):await Oe()},Oe=async()=>{if(N){let a={};for(const g of N)Fe(g)&&(a={...a,...Je(g)});if(Object.keys(a).length>0){H(a);return}}oe(!0),R(null);try{if(!V.externalRefId||V.externalRefId.trim()===""){R("External Reference ID is required. Please pass it via config.applicantForm.externalRefId.");return}const a={workflowKey:V.workflowKey,externalRefId:V.externalRefId.trim()};if(N){for(const C of N)if(Fe(C)){for(const w of C.fields)if(!w.isCustom&&w.name){const le=w.name,re=V[le];et(re)||(a[le]=re)}}for(const C of ct)if(a[C]===void 0){const w=V[C];et(w)||(a[C]=w)}}else Y.forEach(C=>{if(C==="externalRefId")return;const w=V[C];et(w)||(a[C]=w)});const g=[];if(N){for(const C of N)if(Fe(C))for(const w of C.fields){if(!w.isCustom||!w.paramName||w.customType==="paragraph"||w.customType==="html"||w.customType==="br"||w.customType==="link")continue;const le=de[w.paramName]??"";let re;if(w.customType==="checkbox"||w.customType==="link_checkbox")re=le==="true"?"yes":"no";else if(re=le,!re&&!w.required)continue;g.push({paramName:w.paramName,value:re})}}for(const[C,w]of Object.entries(J))a[C]===void 0&&!et(w)&&(a[C]=w);const S=new Set(g.map(C=>C.paramName));for(const[C,w]of Object.entries(ie))!S.has(C)&&w&&g.push({paramName:C,value:w});g.length>0&&(a.applicantAdditionalDatas=g);const h=await d(a);s(h.applicantId)}catch(a){console.error("Error creating applicant:",a),R(a.message||"Failed to create applicant")}finally{oe(!1)}},Xe=async a=>{var g;a.preventDefault();for(const S of M)if(et(V[S])){const h=((g=Ve[S])==null?void 0:g.label)||S;R(`${h} is required.`);return}await Oe()},He=(a,g,S,h,C)=>{var kt;const w=Ve[a];if(!w)return null;const le=M.includes(a),re=z[a],xe=S||w.label,Re=a in se,ne=g??a,Te={required:le},ze=C?C!=="placeholder":j,We=ze?xe:void 0,Hr=ze?"...":xe;switch(w.type){case"select":if(a==="country"||a==="nationality"||a==="taxCountry"||a==="countryOfBirth"||a==="mobileCountryCode"){const Se=Q(a,h);return e.jsx(De,{...Te,label:We,value:V[a]||"",onChange:Qe=>ye(a,Qe),options:[{value:"",label:`Select ${Hr.toLowerCase()}`},...Se],disabled:I,readOnly:Re,error:re},ne)}if(a==="salutation")return e.jsx(De,{...Te,label:We,value:((kt=V[a])==null?void 0:kt.toString())||"",onChange:Se=>ye(a,Se?Number(Se):null),options:[{value:"",label:ze?"Select salutation...":xe},{value:ot.Male.toString(),label:"Male"},{value:ot.Female.toString(),label:"Female"},{value:ot.Other.toString(),label:"Other"}],readOnly:Re,error:re},ne);if(a==="defaultLanguage"){const Se=c!=null&&c.allowedLanguages&&c.allowedLanguages.length>0?xt.filter(Qe=>c.allowedLanguages.includes(Qe.value)):xt;return e.jsx(De,{...Te,label:We,value:V[a]||"",onChange:Qe=>ye(a,Qe),options:[{value:"",label:ze?"Select language...":xe},...Se],readOnly:Re,error:re},ne)}return null;case"multiselect":if(a==="otherNationality"){const Se=Q(a,h);return e.jsx(Rr,{...Te,label:We,value:V[a]||[],onChange:Qe=>ye(a,Qe),options:Se,placeholder:ze?"Select other nationalities...":xe,disabled:I,readOnly:Re},ne)}return null;case"date":return e.jsx(me,{...Te,type:"date",label:We,placeholder:ze?void 0:xe,value:V[a]||"",onChange:Se=>ye(a,Se.target.value),readOnly:Re,error:re},ne);case"email":return e.jsx(me,{...Te,type:"email",label:We,placeholder:ze?void 0:xe,value:V[a]||"",onChange:Se=>ye(a,Se.target.value),readOnly:Re,error:re},ne);case"tel":return e.jsx(me,{...Te,type:"tel",label:We,placeholder:ze?void 0:xe,value:V[a]||"",onChange:Se=>ye(a,Se.target.value),readOnly:Re,error:re},ne);default:return e.jsx(me,{...Te,type:"text",label:We,placeholder:ze?void 0:xe,value:V[a]||"",onChange:Se=>ye(a,Se.target.value),readOnly:Re,error:re},ne)}},Ye=(a,g)=>{const S=a.labelMode?a.labelMode!=="placeholder":j;if(a.customType==="paragraph"){const w=a.displayText||a.label||"";return e.jsx("p",{className:"metakyc-paragraph",style:{fontSize:"14px",lineHeight:"1.7",margin:0,color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:w}},`custom-${g}`)}if(a.customType==="html")return e.jsx("div",{dangerouslySetInnerHTML:{__html:a.label||""}},`custom-${g}`);if(a.customType==="br")return e.jsx("div",{style:{height:"12px"}},`custom-${g}`);if(a.customType==="link"){const w=a.displayText||a.label||a.linkText||a.linkUrl||"";return e.jsx("div",{className:"metakyc-link-field",children:e.jsxs("a",{href:a.linkUrl||"#",target:"_blank",rel:"noopener noreferrer",style:{display:"inline-flex",alignItems:"center",gap:"4px",color:"var(--metakyc-primary, #2563eb)",fontSize:"14px",textDecoration:"underline",cursor:"pointer"},children:[w,e.jsx("span",{style:{fontSize:"10px",opacity:.7},children:"↗"})]})},`custom-${g}`)}if(!a.paramName)return null;const h=z[a.paramName],C=a.displayText||a.label||a.paramName;if(a.customType==="checkbox")return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"checkbox",checked:de[a.paramName]==="true",onChange:w=>ce(a.paramName,w.target.checked?"true":"false"),className:"metakyc-option-input",style:at}),e.jsxs("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:[C,a.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),h&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:h})]},`custom-${g}`);if(a.customType==="link_checkbox")return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"checkbox",checked:de[a.paramName]==="true",onChange:w=>ce(a.paramName,w.target.checked?"true":"false"),className:"metakyc-option-input",style:{...at,alignSelf:"flex-start",marginTop:"2px"}}),e.jsxs("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:[C," ",a.linkUrl&&e.jsx("a",{href:a.linkUrl,target:"_blank",rel:"noopener noreferrer",className:"underline",style:{color:"var(--metakyc-primary, #2563eb)"},onClick:w=>w.stopPropagation(),children:a.linkText||a.linkUrl}),a.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),h&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:h})]},`custom-${g}`);if(a.customType==="group_checkbox"){const w=(de[a.paramName]||"").split(",").filter(Boolean);return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[S&&e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[C,a.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]}),e.jsx("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:(a.options||[]).map(le=>{const re=a.singleSelect?de[a.paramName]===le.value:w.includes(le.value);return e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"checkbox",checked:re,onChange:xe=>{if(a.singleSelect)ce(a.paramName,xe.target.checked?le.value:"");else{const Re=xe.target.checked?[...w,le.value]:w.filter(ne=>ne!==le.value);ce(a.paramName,Re.join(","))}},className:"metakyc-option-input",style:at}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:le.label})]},le.value)})}),h&&e.jsx("p",{className:"text-red-500 text-xs",children:h})]},`custom-${g}`)}return a.customType==="radio_group"?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[S&&e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[C,a.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]}),e.jsx("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:(a.options||[]).map(w=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"radio",checked:de[a.paramName]===w.value,onChange:()=>ce(a.paramName,w.value),name:`radio-group-${a.paramName}-${g}`,className:"metakyc-option-input",style:at}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:w.label})]},w.value))}),h&&e.jsx("p",{className:"text-red-500 text-xs",children:h})]},`custom-${g}`):e.jsx(me,{type:"text",label:S?`${C}${a.required?" *":""}`:void 0,placeholder:S?void 0:C,value:de[a.paramName]||"",onChange:w=>ce(a.paramName,w.target.value),required:a.required,error:h},`custom-${g}`)},y=(a,g)=>{const S=Fe(a);return e.jsxs("div",{className:"space-y-4",children:[a.conditionalOn&&e.jsx(Rt,{helpText:a.conditionalHelpText,children:e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"checkbox",checked:S,onChange:h=>ce(a.conditionalOn,h.target.checked?"true":"false"),className:"metakyc-option-input",style:at}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",fontWeight:500},children:a.conditionalOn})]})}),S&&e.jsx("div",{className:"grid grid-cols-4 gap-4",children:a.fields.map((h,C)=>{const w=h.colSpan===1?"col-span-1":h.colSpan===2?"col-span-2":h.colSpan===3?"col-span-3":"col-span-4",le=h.isCustom?`custom-${C}-${h.paramName}`:`builtin-${h.name}-${C}`;return e.jsx("div",{className:w,children:e.jsx(Rt,{helpText:h.helpText,children:h.isCustom?Ye(h,C):He(h.name,le,h.displayText,h.countriesType,h.labelMode)})},le)})})]})};if(!c||I)return e.jsx("div",{className:"metakyc-sdk",children:e.jsx(Z,{children:e.jsxs(X,{children:[e.jsx(Ie,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)",fontSize:"0.875rem"},children:"Loading form…"})]})})});if(N){const a=N[E]??N[0],g=ve===-1,S=Me===-1,h=N.length,C=Fe(a),w=Object.values(z);return e.jsx("div",{className:"metakyc-sdk",children:e.jsxs(Z,{children:[e.jsx(he,{children:e.jsx(st,{title:(c==null?void 0:c.title)||"Create Applicant"})}),e.jsxs(X,{children:[(a.title||a.subtitle||a.description)&&e.jsxs("div",{className:"mb-4",children:[a.title&&e.jsx("h3",{className:"font-semibold text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:a.title}),a.subtitle&&e.jsx("p",{className:"text-sm mt-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:a.subtitle}),a.description&&a.description!==a.subtitle&&e.jsx("p",{className:"text-xs mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:a.description})]}),(pe||w.length>0)&&e.jsxs("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-lg",children:[pe&&e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",pe]}),w.map((le,re)=>e.jsx("p",{className:"text-red-600 text-sm",children:le},re))]}),h>1&&e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[N.map((le,re)=>e.jsx("div",{className:`h-1.5 rounded-full transition-all ${re===E?"flex-1":"w-8"}`,style:re===E?{backgroundColor:"var(--metakyc-primary, #2563eb)"}:re<E?{backgroundColor:"var(--metakyc-primary-light, #93c5fd)",opacity:.7}:{backgroundColor:"#e5e7eb"}},re)),e.jsxs("span",{className:"text-xs text-gray-400 flex-shrink-0",children:[E+1," / ",h]})]}),y(a)]}),e.jsxs(fe,{className:"flex justify-between",children:[e.jsxs("div",{children:[!g&&e.jsx(G,{type:"button",variant:"outline",onClick:()=>{W(ve),H({})},disabled:te||m,children:"Previous"}),g&&n&&e.jsx(G,{type:"button",variant:"outline",onClick:n,disabled:te||m,children:"Cancel"})]}),e.jsx(G,{type:"button",isLoading:te||m,onClick:S?Oe:Ze,children:S?a.conditionalOn&&!C?"Skip & Submit":"Submit":a.conditionalOn&&!C?"Skip":"Next"})]})]})})}return e.jsx("div",{className:"metakyc-sdk",children:e.jsx("form",{onSubmit:Xe,children:e.jsxs(Z,{children:[e.jsx(he,{children:e.jsx(st,{title:(c==null?void 0:c.title)||"Create Applicant"})}),e.jsxs(X,{children:[pe&&e.jsx("div",{className:"mb-6 p-4 bg-red-50 border border-red-200 rounded-lg",children:e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",pe]})}),e.jsx("div",{className:"grid grid-cols-4 gap-4",children:Y.map(a=>e.jsx("div",{className:"col-span-4",children:He(a)},a))})]}),e.jsxs(fe,{className:"flex justify-between",children:[n&&e.jsx(G,{type:"button",variant:"outline",onClick:n,disabled:te||m,children:"Cancel"}),e.jsx(G,{type:"submit",isLoading:te||m,children:"Create Applicant"})]})]})})})},It=["companyName","email"];function yt(t){return t==null||t===""||Array.isArray(t)&&t.length===0}const Is=({workflowKey:t,externalRefId:r,onSuccess:s,onCancel:n})=>{var He,Ye,y,D,U,_;const{config:i,baseInformationService:l,currentTheme:c}=Ce(),{createCompanyApplicant:d,isLoading:m}=bt(),u=t||((He=i.applicantForm)==null?void 0:He.workflowKey);if(!u)throw new Error("workflowKey is required. Provide it either as a prop to CreateCompanyApplicantForm or set it in config.applicantForm.workflowKey");const x=r||((Ye=i.applicantForm)==null?void 0:Ye.externalRefId)||"",P=((y=i.applicantForm)==null?void 0:y.email)||"",b=((D=i.applicantForm)==null?void 0:D.initialValues)||{},F=(((U=i.applicantForm)==null?void 0:U.fieldLabelMode)||(c==null?void 0:c.fieldLabelMode)||"label")!=="placeholder",j=o.useMemo(()=>c!=null&&c.companyFormPages&&c.companyFormPages.length>0?c.companyFormPages:null,[c==null?void 0:c.companyFormPages]),N=o.useMemo(()=>{const p=new Set(It),v=c==null?void 0:c.companyFormRequiredFields;if(v)for(const T of v)p.add(T);if(j)for(const T of j)for(const k of T.fields)!k.isCustom&&k.name&&k.required&&p.add(k.name);return Array.from(p)},[c==null?void 0:c.companyFormRequiredFields,j]),M=o.useMemo(()=>{var p;if(j){const v=j.flatMap(k=>k.fields).filter(k=>!k.isCustom&&k.name).map(k=>k.name),T=new Set(v);for(const k of It)T.add(k);return Array.from(T)}return(p=i.applicantForm)!=null&&p.visibleFields?i.applicantForm.visibleFields:c!=null&&c.companyFormVisibleFields&&c.companyFormVisibleFields.length>0?c.companyFormVisibleFields:_t},[(_=i.applicantForm)==null?void 0:_.visibleFields,c==null?void 0:c.companyFormVisibleFields,j]),Y=new Set(["countryResidence","addressCountry"]),L=o.useMemo(()=>{var v,T;const p=new Set;if(j)for(const k of j)for(const a of k.fields)!a.isCustom&&a.name&&Y.has(a.name)&&p.add(a.countriesType??((v=Ge[a.name])==null?void 0:v.countriesType));else for(const k of M)Y.has(k)&&p.add((T=Ge[k])==null?void 0:T.countriesType);return p.size===0&&p.add(void 0),Array.from(p)},[M,j]),[$,K]=o.useState({}),[ee,I]=o.useState(!0),f=o.useRef(new Set),O=o.useRef(new Set);o.useEffect(()=>{if(!c)return;const p=L.filter(k=>{const a=k!=null?String(k):"all";return!O.current.has(a)&&!f.current.has(a)});if(p.length===0){L.every(a=>O.current.has(a!=null?String(a):"all"))&&I(!1);return}I(!0);const v=p.map(k=>k!=null?String(k):"all");v.forEach(k=>f.current.add(k)),(async()=>{try{const k=await Promise.all(p.map(async a=>{const g=a!=null?String(a):"all",S=await l.getCountries("",i.locale||"en",a),h=new Set,C=S.map(w=>({value:w.abbreviation3||w.abbreviation,label:w.name})).filter(w=>!w.value||h.has(w.value)?!1:(h.add(w.value),!0));return O.current.add(g),f.current.delete(g),[g,C]}));K(a=>({...a,...Object.fromEntries(k)}))}catch(k){v.forEach(a=>f.current.delete(a)),console.error("Failed to load countries:",k)}finally{L.every(a=>O.current.has(a!=null?String(a):"all"))&&I(!1)}})()},[L,c]);const q=(p,v)=>{var a;const T=v??((a=Ge[p])==null?void 0:a.countriesType),k=T!=null?String(T):"all";return $[k]||[]},Q={companyName:1,registrationNumber:1,email:1,phone:1,countryResidence:1,legalAddress:1,incorporatedOn:1,controlScheme:1,taxId:1,registrationLocation:1,website:1,postalAddress:1,street:1,streetNumber:1,city:1,state:1,postalCode:1,addressCountry:1,lei:1},B=Object.fromEntries(Object.entries(b).filter(([p])=>p in Q)),[J,se]=o.useState({workflowKey:u,companyName:"",email:P,phone:"",registrationNumber:"",countryResidence:"",legalAddress:"",incorporatedOn:"",controlScheme:"",taxId:"",registrationLocation:"",website:"",postalAddress:"",street:"",streetNumber:"",city:"",state:"",postalCode:"",addressCountry:"",lei:"",externalRefId:x,...B}),[V,ge]=o.useState({}),[ie,de]=o.useState(0),[be,E]=o.useState({}),[W,z]=o.useState(null),[H,pe]=o.useState(!1),R=(p,v)=>se(T=>({...T,[p]:v})),te=(p,v)=>ge(T=>({...T,[p]:v})),oe=p=>!p.conditionalOn||V[p.conditionalOn]==="true",ye=j&&ie<j.length-1?ie+1:-1,ce=j&&ie>0?ie-1:-1,Fe=p=>{var T;const v={};for(const k of p.fields)if(k.isCustom){if(k.customType==="paragraph"||k.customType==="html"||k.customType==="br"||k.customType==="link")continue;if(k.required&&k.paramName){const a=V[k.paramName],g=k.displayText||k.label||k.paramName;k.customType==="checkbox"||k.customType==="link_checkbox"?a!=="true"&&(v[k.paramName]=`${g} is required.`):(!a||a.trim()==="")&&(v[k.paramName]=`${g} is required.`)}}else if(k.name){const a=k.name;if(N.includes(a)&&yt(J[a])){const g=k.displayText||((T=Ge[a])==null?void 0:T.label)||a;v[a]=`${g} is required.`}}return v},Me=async()=>{if(!j)return;const p=j[ie];if(p.conditionalOn&&!oe(p)){E({}),ye>=0?de(ye):await ve();return}const v=Fe(p);if(Object.keys(v).length>0){E(v);return}E({}),ye>=0?de(ye):await ve()},ve=async()=>{var p;if(j){let v={};for(const T of j)oe(T)&&(v={...v,...Fe(T)});if(Object.keys(v).length>0){E(v);return}}pe(!0),z(null);try{const v={workflowKey:J.workflowKey,externalRefId:((p=J.externalRefId)==null?void 0:p.trim())||void 0},T=j?j.filter(g=>oe(g)).flatMap(g=>g.fields).filter(g=>!g.isCustom&&g.name).map(g=>g.name):M;for(const g of T){const S=J[g];if(!yt(S))switch(g){case"companyName":v.companyName=S;break;case"email":v.companyEmail=S;break;case"phone":v.companyPhone=S;break;case"registrationNumber":v.companyRegistrationNumber=S;break;case"countryResidence":v.companyCountry=S;break;case"city":v.companyCity=S;break;case"street":v.companyStreet=S;break;case"postalCode":v.companyZip=S;break;default:v[g]=S;break}}const k=[];if(j){for(const g of j)if(oe(g))for(const S of g.fields){if(!S.isCustom||!S.paramName||S.customType==="paragraph"||S.customType==="html"||S.customType==="br"||S.customType==="link")continue;const h=V[S.paramName]??"";let C;if(S.customType==="checkbox"||S.customType==="link_checkbox")C=h==="true"?"yes":"no";else if(C=h,!C&&!S.required)continue;k.push({paramName:S.paramName,value:C})}}k.length>0&&(v.applicantAdditionalDatas=k);const a=await d(v);s(a.applicantId)}catch(v){console.error("Error creating company applicant:",v),z(v.message||"Failed to create company applicant")}finally{pe(!1)}},Je=async p=>{var v;p.preventDefault();for(const T of N)if(yt(J[T])){const k=((v=Ge[T])==null?void 0:v.label)||T;z(`${k} is required.`);return}await ve()},Ze=(p,v,T,k,a)=>{const g=Ge[p];if(!g)return null;const S=N.includes(p),h=be[p],C=T||g.label,w=p in B,le=v??p,re=a?a!=="placeholder":F,xe=re?C:void 0,Re=re?"...":C;switch(g.type){case"select":if(p==="countryResidence"||p==="addressCountry"){const ne=q(p,k);return e.jsx(De,{required:S,label:xe,value:J[p]||"",onChange:Te=>R(p,Te),options:[{value:"",label:`Select ${Re.toLowerCase()}`},...ne],disabled:ee,readOnly:w,error:h},le)}return null;case"date":return e.jsx(me,{required:S,type:"date",label:xe,placeholder:re?void 0:C,value:J[p]||"",onChange:ne=>R(p,ne.target.value),readOnly:w,error:h},le);case"email":return e.jsx(me,{required:S,type:"email",label:xe,placeholder:re?void 0:C,value:J[p]||"",onChange:ne=>R(p,ne.target.value),readOnly:w,error:h},le);case"tel":return e.jsx(me,{required:S,type:"tel",label:xe,placeholder:re?void 0:C,value:J[p]||"",onChange:ne=>R(p,ne.target.value),readOnly:w,error:h},le);default:return e.jsx(me,{required:S,type:"text",label:xe,placeholder:re?void 0:C,value:J[p]||"",onChange:ne=>R(p,ne.target.value),readOnly:w,error:h},le)}},Oe=(p,v)=>{if(p.customType==="paragraph")return e.jsx("p",{style:{fontSize:"14px",lineHeight:"1.7",margin:0,color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:p.displayText||p.label||""}},`custom-${v}`);if(p.customType==="html")return e.jsx("div",{dangerouslySetInnerHTML:{__html:p.label||""}},`custom-${v}`);if(p.customType==="br")return e.jsx("div",{style:{height:"12px"}},`custom-${v}`);if(p.customType==="link")return e.jsx("div",{children:e.jsx("a",{href:p.linkUrl||"#",target:"_blank",rel:"noopener noreferrer",style:{color:"var(--metakyc-primary, #2563eb)",fontSize:"14px",textDecoration:"underline"},children:p.displayText||p.label||p.linkText||p.linkUrl||""})},`custom-${v}`);if(!p.paramName)return null;const T=be[p.paramName],k=p.displayText||p.label||p.paramName,a=p.labelMode?p.labelMode!=="placeholder":F;return p.customType==="checkbox"?e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:V[p.paramName]==="true",onChange:g=>te(p.paramName,g.target.checked?"true":"false"),style:{width:"16px",height:"16px",accentColor:"var(--metakyc-primary, #2563eb)"}}),e.jsxs("span",{style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)"},children:[k,p.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),T&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:T})]},`custom-${v}`):e.jsx(me,{type:"text",label:a?`${k}${p.required?" *":""}`:void 0,placeholder:a?void 0:k,value:V[p.paramName]||"",onChange:g=>te(p.paramName,g.target.value),required:p.required,error:T},`custom-${v}`)},Xe=p=>{const v=oe(p);return e.jsxs("div",{className:"space-y-4",children:[p.conditionalOn&&e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:v,onChange:T=>te(p.conditionalOn,T.target.checked?"true":"false"),style:{width:"16px",height:"16px",accentColor:"var(--metakyc-primary, #2563eb)"}}),e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:p.conditionalOn})]}),v&&e.jsx("div",{className:"grid grid-cols-4 gap-4",children:p.fields.map((T,k)=>{const a=T.colSpan===1?"col-span-1":T.colSpan===2?"col-span-2":T.colSpan===3?"col-span-3":"col-span-4",g=T.isCustom?`custom-${k}-${T.paramName}`:`builtin-${T.name}-${k}`;return e.jsx("div",{className:a,children:T.isCustom?Oe(T,k):Ze(T.name,g,T.displayText,T.countriesType,T.labelMode)},g)})})]})};if(!c||ee)return e.jsx("div",{className:"metakyc-sdk",children:e.jsx(Z,{children:e.jsxs(X,{children:[e.jsx(Ie,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)",fontSize:"0.875rem"},children:"Loading form…"})]})})});if(j){const p=j[ie]??j[0],v=ce===-1,T=ye===-1,k=j.length,a=oe(p),g=Object.values(be);return e.jsx("div",{className:"metakyc-sdk",children:e.jsxs(Z,{children:[e.jsx(he,{children:e.jsx(st,{title:(c==null?void 0:c.title)||"Company Registration"})}),e.jsxs(X,{children:[(p.title||p.subtitle)&&e.jsxs("div",{className:"mb-4",children:[p.title&&e.jsx("h3",{className:"font-semibold text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:p.title}),p.subtitle&&e.jsx("p",{className:"text-sm mt-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:p.subtitle})]}),(W||g.length>0)&&e.jsxs("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-lg",children:[W&&e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",W]}),g.map((S,h)=>e.jsx("p",{className:"text-red-600 text-sm",children:S},h))]}),k>1&&e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[j.map((S,h)=>e.jsx("div",{className:`h-1.5 rounded-full transition-all ${h===ie?"flex-1":"w-8"}`,style:h===ie?{backgroundColor:"var(--metakyc-primary, #2563eb)"}:h<ie?{backgroundColor:"var(--metakyc-primary-light, #93c5fd)",opacity:.7}:{backgroundColor:"#e5e7eb"}},h)),e.jsxs("span",{className:"text-xs text-gray-400 flex-shrink-0",children:[ie+1," / ",k]})]}),Xe(p)]}),e.jsxs(fe,{className:"flex justify-between",children:[e.jsxs("div",{children:[!v&&e.jsx(G,{type:"button",variant:"outline",onClick:()=>{de(ce),E({})},disabled:H||m,children:"Previous"}),v&&n&&e.jsx(G,{type:"button",variant:"outline",onClick:n,disabled:H||m,children:"Cancel"})]}),e.jsx(G,{type:"button",isLoading:H||m,onClick:T?ve:Me,children:T?p.conditionalOn&&!a?"Skip & Submit":"Submit":p.conditionalOn&&!a?"Skip":"Next"})]})]})})}return e.jsx("div",{className:"metakyc-sdk",children:e.jsx("form",{onSubmit:Je,children:e.jsxs(Z,{children:[e.jsx(he,{children:e.jsx(st,{title:(c==null?void 0:c.title)||"Company Registration"})}),e.jsxs(X,{children:[W&&e.jsx("div",{className:"mb-6 p-4 bg-red-50 border border-red-200 rounded-lg",children:e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",W]})}),e.jsx("div",{className:"grid grid-cols-4 gap-4",children:M.map(p=>e.jsx("div",{className:"col-span-4",children:Ze(p)},p))})]}),e.jsxs(fe,{className:"flex justify-between",children:[n&&e.jsx(G,{type:"button",variant:"outline",onClick:n,disabled:H||m,children:"Cancel"}),e.jsx(G,{type:"submit",isLoading:H||m,children:"Register Company"})]})]})})})},Es=({applicantId:t,onComplete:r,onError:s,theme:n="light",className:i})=>{const{progress:l,currentStep:c,steps:d,workflowKey:m,nextWorkflowKey:u,hasWorkflowChanged:x,isLoading:P,error:b,moveBack:A,refreshProgress:F}=kr(t),[j,N]=o.useState(!1),M=o.useRef(null);if(o.useEffect(()=>{b&&s&&s(b)},[b,s]),o.useEffect(()=>{l!=null&&l.workflowResult&&r&&r(l.workflowResult)},[l==null?void 0:l.workflowResult,r]),o.useEffect(()=>{n==="dark"?document.documentElement.classList.add("dark"):document.documentElement.classList.remove("dark")},[n]),o.useEffect(()=>{x&&N(!1)},[x]),P||!l)return e.jsx("div",{className:`metakyc-sdk ${i||""}`,children:e.jsx(Z,{children:e.jsxs(X,{children:[e.jsx(Ie,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Loading workflow..."})]})})});if(b)return e.jsx("div",{className:`metakyc-sdk ${i||""}`,children:e.jsx(Z,{children:e.jsx(X,{children:e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-lg mb-4",style:{color:"var(--metakyc-danger, #ef4444)"},children:"An error occurred"}),e.jsx("p",{style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:b.message})]})})})});if(x&&!j)return e.jsx("div",{className:`metakyc-sdk ${i||""}`,children:e.jsx(Z,{children:e.jsx(X,{children:e.jsxs("div",{className:"text-center py-8",children:[e.jsx("div",{className:"mb-6",children:e.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-full mb-4",style:{backgroundColor:"var(--metakyc-primary-light, #dbeafe)"},children:e.jsx("svg",{className:"w-8 h-8",style:{color:"var(--metakyc-primary, #2563eb)"},fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})})}),e.jsx("h3",{className:"text-xl font-semibold mb-2",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Workflow Transition"}),e.jsx("p",{className:"mb-6",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Your application workflow has been updated based on your progress."}),e.jsxs("div",{className:"rounded-lg p-4 mb-6 max-w-md mx-auto",style:{backgroundColor:"var(--metakyc-surface, #f9fafb)"},children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"mb-1",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"Previous Workflow"}),e.jsx("p",{className:"font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:m})]}),e.jsx("svg",{className:"w-6 h-6 mx-4",style:{color:"var(--metakyc-text-muted, #9ca3af)"},fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 7l5 5m0 0l-5 5m5-5H6"})}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"mb-1",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"New Workflow"}),e.jsx("p",{className:"font-medium",style:{color:"var(--metakyc-primary, #2563eb)"},children:u})]})]}),l.nextWorkflowName&&e.jsx("p",{className:"text-center mt-2 text-xs",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:l.nextWorkflowName})]}),e.jsx("button",{onClick:()=>N(!0),className:"px-6 py-3 font-medium rounded-lg transition-opacity hover:opacity-90",style:{backgroundColor:"var(--metakyc-primary, #2563eb)",color:"#ffffff"},children:"Continue with New Workflow"})]})})})});if(l.status===Ae.Finished||l.status===Ae.OnHold)return e.jsx("div",{className:`metakyc-sdk ${i||""}`,children:e.jsx(ht,{kycStatus:l.kycStatus,reviewStatus:l.reviewStatus,workflowResult:l.workflowResult,customMessage:l.customMessage,onContinue:r&&l.workflowResult?()=>r(l.workflowResult):void 0,onContactSupport:()=>{typeof window<"u"&&(window.location.href="mailto:support@example.com")}})});if(!c)return e.jsx("div",{className:`metakyc-sdk ${i||""}`,children:e.jsx(Z,{children:e.jsxs(X,{children:[e.jsx(Ie,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:l.status===Ae.IdentityPending?"Loading identity verification...":"Loading current step..."})]})})});const Y=K=>{switch(K){case ae.Overview:return"Overview";case ae.Questionaries:return"Questionnaire";case ae.UploadDocument:return"Documents";case ae.IdentitySdk:return"Identity";case ae.RiskScoring:return"Risk Assessment";case ae.InvestorCategorization:return"Investor Categorization";case ae.AppropriatenessTest:return"Appropriateness Test";case ae.AdditionalData:return"Additional Data";case ae.ManualReview:return"Review";default:return""}},L=()=>{const K=d.filter(q=>q.visibility!==!1),ee=K.findIndex(q=>q.order===c.order),I=ee>=0?ee+1:1,f=K.length,O=f>1?ee/(f-1)*100:100;return e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",marginBottom:"16px"},children:[e.jsx(st,{}),e.jsxs(vt,{variant:l.status===1?"info":"success",children:["Step ",I," of ",f]})]}),e.jsx("div",{style:{marginBottom:"16px"},children:e.jsx("div",{style:{height:"4px",borderRadius:"999px",backgroundColor:"var(--metakyc-border, #e5e7eb)",overflow:"hidden"},children:e.jsx("div",{style:{height:"100%",borderRadius:"999px",backgroundColor:"var(--metakyc-primary, #2563eb)",width:`${O}%`,transition:"width 0.4s ease"}})})}),e.jsx(As,{ref:M,visibleSteps:K,currentVisibleStepIndex:ee,getStepFallbackName:Y})]})},$=()=>{const K={applicantId:t,onComplete:async()=>{await F()},onBack:c.order>0?A:void 0};switch(c.action){case ae.Questionaries:return e.jsx(Lr,{...K});case ae.UploadDocument:return e.jsx(Dr,{...K});case ae.Overview:return e.jsx(Mr,{...K});case ae.IdentitySdk:return e.jsx(_r,{...K});case ae.RiskScoring:return e.jsx(Or,{...K});case ae.AdditionalData:case ae.InvestorCategorization:return e.jsx(zr,{...K});case ae.AppropriatenessTest:return e.jsx(Br,{...K});case ae.ManualReview:return e.jsx(ht,{kycStatus:l.kycStatus,reviewStatus:l.reviewStatus,workflowResult:l.workflowResult,customMessage:l.customMessage});default:return e.jsx(Z,{children:e.jsxs(X,{className:"py-12 text-center",children:[e.jsx("div",{className:"mb-4",children:e.jsx(Ie,{})}),e.jsxs("p",{className:"text-gray-600 dark:text-gray-400 mb-2",children:["Processing step: ",c.title||c.name]}),e.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:["Action type: ",ae[c.action]]})]})})}};return e.jsxs("div",{className:`metakyc-sdk ${i||""}`,children:[L(),$()]})},As=o.forwardRef(({visibleSteps:t,currentVisibleStepIndex:r,getStepFallbackName:s},n)=>{const i=o.useRef(null),l=o.useRef(null);return o.useImperativeHandle(n,()=>i.current),o.useEffect(()=>{if(l.current&&i.current){const c=i.current,d=l.current,m=d.offsetLeft-c.offsetWidth/2+d.offsetWidth/2;c.scrollTo({left:Math.max(0,m),behavior:"smooth"})}},[r]),e.jsx("div",{ref:i,className:"metakyc-stepper-scroll",style:{display:"flex",alignItems:"center",overflowX:"auto",overflowY:"hidden",scrollbarWidth:"none",msOverflowStyle:"none",WebkitOverflowScrolling:"touch",padding:"4px 0",gap:"0"},children:t.map((c,d)=>{const m=d<r,u=d===r,x=m||u,P=c.displayName||c.name||s(c.action)||`Step ${d+1}`;return e.jsxs(o.Fragment,{children:[e.jsxs("div",{ref:u?l:void 0,style:{display:"flex",alignItems:"center",flexShrink:0},children:[e.jsx("div",{style:{width:"28px",height:"28px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"12px",fontWeight:600,flexShrink:0,transition:"all 0.2s ease",...x?{backgroundColor:"var(--metakyc-primary, #2563eb)",color:"#ffffff",border:"none"}:{backgroundColor:"transparent",color:"var(--metakyc-text-muted, #9ca3af)",border:"2px solid var(--metakyc-border, #e5e7eb)"}},children:m?e.jsx("svg",{width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:2.5,viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}):d+1}),e.jsx("span",{style:{marginLeft:"6px",fontSize:"13px",whiteSpace:"nowrap",fontWeight:u?600:400,color:u?"var(--metakyc-text-primary, #111827)":m?"var(--metakyc-primary, #2563eb)":"var(--metakyc-text-muted, #9ca3af)",transition:"color 0.2s ease"},children:P})]}),d<t.length-1&&e.jsx("div",{style:{width:"32px",minWidth:"16px",height:"2px",margin:"0 8px",flexShrink:0,borderRadius:"999px",backgroundColor:m?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",transition:"background-color 0.2s ease"}})]},c.order)})})});function Fs(t){return $e.z.object({questionResults:$e.z.any()}).passthrough()}function Ts(t){let r=$e.z.array($e.z.instanceof(File));if(t.isRequired?r=r.min(1,`${t.displayName} is required`):r=r.optional(),t.multipleFile||(r=r.refine(s=>!s||s.length<=1,{message:"Only one file is allowed"})),t.maxEachFileSizeByte>0&&(r=r.refine(s=>!s||s.every(n=>n.size<=t.maxEachFileSizeByte),{message:`File size must not exceed ${Math.round(t.maxEachFileSizeByte/1024/1024)}MB`})),t.allowedTypes){const s=t.allowedTypes.split(",").map(n=>n.trim());r=r.refine(n=>n?n.every(i=>s.some(l=>l.endsWith("/*")?i.type.startsWith(l.slice(0,-2)):i.type===l)):!0,{message:"Invalid file type"})}return r}function Ps(t){const r={};return t.uploadDocumentFiles.forEach(s=>{const n=`file_${s.id}`;r[n]=Ts(s)}),$e.z.object(r)}function Ls(t){return $e.z.any()}function Ds(t){return $e.z.string().min(1,"This question is required")}function Ms(t){const r={};return t.appropriatenessQuestions.forEach(s=>{const n=`question_${s.id}`;r[n]=Ds()}),$e.z.object(r)}const Os=$e.z.any();exports.ALLOWED_LANGUAGES=xt;exports.ApplicantProgressOnHoldReason=Et;exports.ApplicantProgressStatus=Ae;exports.ApplicantService=Kt;exports.ApplicantStatus=Ft;exports.AppropriatenessQuestionType=Mt;exports.AppropriatenessTestService=Yt;exports.AppropriatenessTestStep=Br;exports.Badge=vt;exports.BaseInformationService=Zt;exports.Button=G;exports.COMPANY_FIELD_METADATA=Ge;exports.Card=Z;exports.CardContent=X;exports.CardFooter=fe;exports.CardHeader=he;exports.CountriesType=_e;exports.CreateApplicantForm=Rs;exports.CreateCompanyApplicantForm=Is;exports.CriteriaBuiltInType=zt;exports.DEFAULT_COMPANY_VISIBLE_FIELDS=_t;exports.DEFAULT_VISIBLE_FIELDS=$t;exports.DocumentReviewStatus=Dt;exports.EndpointBuilder=Wt;exports.ErrorHandler=tt;exports.EventEmitter=or;exports.FIELD_METADATA=Ve;exports.FileType=Lt;exports.FileUpload=Ir;exports.GenderType=ot;exports.Header=st;exports.HttpClient=Ut;exports.IdentityProviderManager=Be;exports.IdentityService=Jt;exports.IdentityVerificationProvider=Ee;exports.IdentityVerificationStep=_r;exports.Input=me;exports.InvestorCategorizationService=Xt;exports.InvestorCategorizationStep=zr;exports.InvestorCategorizationType=ke;exports.InvestorCategoryType=Bt;exports.KycProcessStatus=Tt;exports.KycStatus=Ke;exports.KycStatusDisplay=ht;exports.KycWorkflow=Es;exports.Logo=$r;exports.MetaKYCContext=gt;exports.MetaKYCError=Pe;exports.MetaKYCProvider=Jr;exports.MultiSelect=Rr;exports.OnfidoProvider=pr;exports.OverviewService=Qt;exports.OverviewStep=Mr;exports.PhoneInput=Er;exports.QuestionnaireService=qt;exports.QuestionnaireStep=Lr;exports.ReviewStatus=qe;exports.RiskCriteriaType=Ot;exports.RiskLevel=At;exports.RiskScoringService=Gt;exports.RiskScoringStep=Or;exports.SardinAIProvider=mr;exports.SearchableSelect=De;exports.Select=pt;exports.Spinner=Ie;exports.StepRouter=cr;exports.SumsubProvider=ur;exports.ThemeManager=yr;exports.ThemePreset=je;exports.ThemeService=ir;exports.UploadDocumentService=Vt;exports.UploadDocumentStep=Dr;exports.UserType=Pt;exports.ValueDataType=Le;exports.WorkflowOrchestrator=dr;exports.WorkflowResultType=it;exports.WorkflowState=lr;exports.WorkflowStepAction=ae;exports.appropriatenessTestSchema=Os;exports.clearAllStorage=rs;exports.clearApplicantId=gr;exports.clearWorkflowState=vr;exports.cn=we;exports.corporateTheme=er;exports.defaultConfig=Ht;exports.defaultTheme=Ne;exports.fileToBase64=xr;exports.fintechTheme=tr;exports.formatFileSize=dt;exports.generateAppropriatenessSchema=Ms;exports.generateQuestionnaireSchema=Fs;exports.generateRiskScoringSchema=Ls;exports.generateUploadDocumentSchema=Ps;exports.getAcceptString=es;exports.getApplicantId=fr;exports.getThemePreset=rt;exports.getWorkflowState=ts;exports.healthcareTheme=rr;exports.isScriptLoaded=Vr;exports.loadScript=ft;exports.minimalTheme=nr;exports.modernTheme=sr;exports.removeScript=Yr;exports.saveApplicantId=hr;exports.saveWorkflowState=br;exports.themePresets=ar;exports.useApplicant=bt;exports.useAppropriatenessTest=ss;exports.useIdentityVerification=Cr;exports.useKycWorkflow=kr;exports.useMetaKYC=Ce;exports.useOverview=Sr;exports.useQuestionnaire=jr;exports.useRiskScoring=Nr;exports.useUploadDocument=wr;exports.validateFileSize=Zr;exports.validateFileType=Xr;
|
|
82
|
+
*/const ms=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],Pr=Fr("chevron-right",ms);function ys(t,r){const s=!r||r.length===0||r.every(n=>!n||!n.trim());if(t.isRequired&&s)return t.errorMessage||"This field is required";if(!s){const n=r[0]??"";if(n&&t.regex)try{if(!new RegExp(t.regex).test(n))return t.errorMessage||"Invalid format"}catch{}if(n!==""){const a=Number(n);if(!isNaN(a)&&n.trim()!==""){if(t.min!==void 0&&t.min!==null&&a<t.min)return`Minimum value is ${t.min}`;if(t.max!==void 0&&t.max!==null&&a>t.max)return`Maximum value is ${t.max}`}else{if(t.min!==void 0&&t.min!==null&&n.length<t.min)return`Minimum length is ${t.min} characters`;if(t.max!==void 0&&t.max!==null&&n.length>t.max)return`Maximum length is ${t.max} characters`}}}return null}function xs(t){const r=t.flatMap((n,a)=>(n.questions??[]).map((l,c)=>({question:l,groupIndex:a,qIdx:c}))),s=new Map;for(const n of r){const a=n.question.pageNumber!=null&&n.question.pageNumber>0?n.question.pageNumber:1;s.has(a)||s.set(a,[]),s.get(a).push(n)}return Array.from(s.entries()).sort(([n],[a])=>n-a).map(([,n])=>n)}const Lr=({applicantId:t,onComplete:r,onBack:s})=>{const{questionnaire:n,initialAnswers:a,isLoading:l,isSubmitting:c,error:u,submit:y}=jr(t),[p,b]=i.useState({}),[T,v]=i.useState({}),[E,A]=i.useState(0);i.useEffect(()=>{a&&Object.keys(a).length>0&&Object.keys(p).length===0&&b(a)},[a]);const k=i.useMemo(()=>n?xs(n.questionGroups):[],[n]),S=E===k.length-1,M=k[E]??[],Y=i.useCallback((R,g)=>{b(O=>({...O,[R]:g})),v(O=>{const q={...O};return delete q[R],q})},[]),L=i.useCallback(()=>{const R={};for(const{question:g}of M){const O=ys(g,p[g.id]??[]);O&&(R[g.id]=O)}return v(g=>({...g,...R})),Object.keys(R).length===0},[M,p]),_=()=>{L()&&A(R=>R+1)},U=()=>{E>0?A(R=>R-1):s==null||s()},te=async()=>{if(!(!L()||!n))try{const R=n.questionGroups.flatMap(O=>(O.questions??[]).map(q=>({questionId:q.id,values:p[q.id]??[]}))),g={applicantId:t,questionnarieId:n.id,questionResults:R};await y(g),r==null||r()}catch(R){console.error("Questionnaire submit error:",R)}};return l?e.jsx(X,{children:e.jsx(ee,{children:e.jsx(Ee,{className:"my-8"})})}):u?e.jsx(X,{children:e.jsx(ee,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading questionnaire: ",u.message]})})}):n?e.jsxs(X,{children:[e.jsxs(he,{children:[e.jsx("h2",{className:"text-lg font-bold",children:n.displayName}),n.subtitle&&e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:n.subtitle}),k.length>1&&e.jsxs("div",{className:"flex items-center justify-between mt-3",children:[e.jsxs("span",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:["Page ",E+1," of ",k.length]}),e.jsx("div",{className:"flex items-center gap-1.5",children:k.map((R,g)=>e.jsx("div",{className:"rounded-full transition-all duration-200",style:{height:"6px",width:g===E?"20px":"6px",backgroundColor:g<=E?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},g))})]})]}),e.jsx(ee,{className:"space-y-6",children:M.map(({question:R})=>e.jsx(hs,{question:R,value:p[R.id]??[],error:T[R.id],onChange:g=>Y(R.id,g)},R.id))}),e.jsxs(fe,{className:"flex items-center justify-between",children:[e.jsxs(G,{type:"button",variant:"outline",onClick:U,style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(Tr,{size:14}),E>0?"Previous":"Back"]}),S?e.jsx(G,{type:"button",isLoading:c,onClick:te,children:"Continue"}):e.jsxs(G,{type:"button",onClick:_,style:{display:"flex",alignItems:"center",gap:"4px"},children:["Next",e.jsx(Pr,{size:14})]})]}),u&&e.jsx("div",{className:"mx-6 mb-4 p-3 bg-red-50 border border-red-200 rounded",children:e.jsx("p",{className:"text-red-600 text-sm",children:u.message})})]}):null},hs=({question:t,value:r,error:s,onChange:n})=>{var c;const l=(((c=t.defaultAnswers)==null?void 0:c.length)??0)>0?t.showAsDropdown?t.canMultipleAnswer?"multi-select":"single-select":t.canMultipleAnswer?"checkbox":"radio":"text";return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[t.text,t.isRequired&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),t.subtitle&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:t.subtitle}),t.description&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:t.description}),l==="text"&&e.jsx(ye,{value:r[0]??"",onChange:u=>n([u.target.value]),placeholder:t.subtitle?void 0:"Enter your answer…",error:s,required:t.isRequired}),l==="single-select"&&e.jsx(pt,{value:r[0]??"",onChange:u=>n([u.target.value]),options:(t.defaultAnswers??[]).map(u=>({value:u,label:u})),placeholder:"Select an option…",error:s,required:t.isRequired}),l==="radio"&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultAnswers??[]).map(u=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"radio",checked:r[0]===u,onChange:()=>n([u]),className:"metakyc-option-input",style:{width:"16px",height:"16px",minWidth:"16px",flexShrink:0,flexGrow:0,accentColor:"var(--metakyc-primary, #2563eb)",cursor:"pointer",margin:0,padding:0,display:"inline-block",verticalAlign:"middle"}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:u})]},u)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),(l==="checkbox"||l==="multi-select")&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultAnswers??[]).map(u=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"checkbox",checked:r.includes(u),onChange:y=>{y.target.checked?n([...r,u]):n(r.filter(p=>p!==u))},className:"metakyc-option-input",style:{width:"16px",height:"16px",minWidth:"16px",flexShrink:0,flexGrow:0,accentColor:"var(--metakyc-primary, #2563eb)",cursor:"pointer",margin:0,padding:0,display:"inline-block",verticalAlign:"middle"}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:u})]},u)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),s&&l==="text"&&null]})};function fs(t){const r=new Map;for(const s of t){const n=s.pageNumber!=null&&s.pageNumber>0?s.pageNumber:1;r.has(n)||r.set(n,[]),r.get(n).push(s)}return Array.from(r.entries()).sort(([s],[n])=>s-n).map(([,s])=>s)}const Dr=({applicantId:t,onComplete:r,onBack:s})=>{const{uploadDocument:n,isLoading:a,isSubmitting:l,error:c,submit:u}=wr(t),[y,p]=i.useState({}),[b,T]=i.useState(null),[v,E]=i.useState(0),[A,k]=i.useState({}),S=i.useMemo(()=>n?fs(n.uploadDocumentFiles):[],[n]),M=S[v]??[],Y=v===S.length-1,L=S.length,_=i.useCallback(()=>{const g={};for(const O of M)O.isRequired&&(y[O.id]||[]).length===0&&(g[O.id]=`${O.displayName} is required`);return k(g),Object.keys(g).length===0},[M,y]),U=()=>{_()&&(E(g=>g+1),k({}))},te=()=>{v>0?(E(g=>g-1),k({})):s==null||s()},R=async()=>{if(!(!_()||!n)){T(null);try{const g=await Promise.all(n.uploadDocumentFiles.map(async q=>{const Q=y[q.id]||[],B=await Promise.all(Q.map(async J=>({fileName:J.name,fileData:await xr(J)})));return{uploadDocumentFileId:q.id,valueList:B}})),O={applicantId:t,uploadDocumentId:n.id,uploadDocumentResults:g};await u(O),r==null||r()}catch(g){T((g==null?void 0:g.message)||"Failed to submit documents. Please try again.")}}};return a?e.jsx(X,{children:e.jsx(ee,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"48px 0",gap:"16px"},children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)"},children:"Loading document requirements..."})]})})}):c?e.jsx(X,{children:e.jsx(ee,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"32px 0",gap:"12px",textAlign:"center"},children:[e.jsx("div",{style:{width:"48px",height:"48px",borderRadius:"50%",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 10%, transparent)",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),e.jsx("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]})}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-danger, #ef4444)",fontWeight:500},children:"Error loading document requirements"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-muted, #9ca3af)"},children:c.message})]})})}):n?e.jsxs(X,{children:[e.jsxs(he,{children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:n.displayName||"Upload Documents"}),n.subtitle&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",marginTop:"4px"},children:n.subtitle}),L>1&&e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginTop:"12px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)"},children:["Page ",v+1," of ",L]}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:S.map((g,O)=>e.jsx("div",{style:{height:"6px",width:O===v?"20px":"6px",borderRadius:"999px",transition:"all 0.2s ease",backgroundColor:O<=v?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},O))})]})]}),n.description&&v===0&&e.jsxs("div",{style:{margin:"0 24px",marginTop:"4px",display:"flex",gap:"10px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-primary, #2563eb) 5%, var(--metakyc-background, #ffffff))",border:"1px solid color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-primary, #2563eb)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:"1px"},children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-secondary, #374151)",margin:0,lineHeight:1.5},children:n.description})]}),e.jsx(ee,{children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"24px"},children:M.map(g=>e.jsx(Ir,{label:g.displayName,subtitle:g.subtitle,accept:g.allowedTypes,multiple:g.multipleFile,maxSize:g.maxEachFileSizeByte,required:g.isRequired,error:A[g.id],value:y[g.id]||[],onChange:O=>{T(null),k(q=>{const Q={...q};return delete Q[g.id],Q}),p(q=>({...q,[g.id]:O}))}},g.id))})}),b&&e.jsxs("div",{style:{margin:"0 24px",padding:"10px 14px",borderRadius:"8px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:b})]}),e.jsx(fe,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[e.jsx(G,{type:"button",variant:"outline",onClick:te,children:v>0?"Previous":"Back"}),Y?e.jsx(G,{type:"button",isLoading:l,onClick:R,children:l?"Uploading...":"Continue"}):e.jsx(G,{type:"button",onClick:U,children:"Next"})]})})]}):null},Mr=({applicantId:t,onComplete:r,onBack:s})=>{const{overview:n,isLoading:a,isSubmitting:l,error:c,passOverview:u}=Sr(t),y=async()=>{await u(),r==null||r()};return a?e.jsx(X,{children:e.jsx(ee,{children:e.jsx(Ee,{className:"my-8"})})}):c?e.jsx(X,{children:e.jsx(ee,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading overview: ",c.message]})})}):n?e.jsxs(X,{children:[e.jsxs(he,{children:[e.jsx("h2",{className:"text-lg font-bold",children:n.title||"Overview"}),n.description&&e.jsx("p",{className:"mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:n.description})]}),e.jsx(ee,{className:"space-y-8",children:n.steps&&n.steps.length>0?n.steps.sort((p,b)=>p.order-b.order).map(p=>e.jsxs("div",{className:"metakyc-overview-step-item flex items-center space-x-3",children:[e.jsx("div",{className:"metakyc-step-icon flex-shrink-0",children:e.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center font-medium text-sm",style:{backgroundColor:"var(--metakyc-primary, #2563eb)",color:"#ffffff"},children:p.order+1})}),e.jsxs("div",{className:"metakyc-step-content",style:{flex:1,border:"none",height:"auto",background:"transparent"},children:[e.jsx("span",{className:"metakyc-step-title text-sm font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:p.title}),p.description&&e.jsx("p",{className:"metakyc-step-description text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:p.description})]})]},p.order)):e.jsx("div",{className:"text-center py-8",children:e.jsx("p",{style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Loading overview data..."})})}),e.jsxs(fe,{className:"flex justify-between",children:[s&&e.jsx(G,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(G,{onClick:y,isLoading:l,children:"Continue"})]})]}):null};function gs(t){const r=(t??"en").toLowerCase().replace("_","-");try{return Intl.NumberFormat.supportedLocalesOf([r]),r}catch{return"en"}}function bs(t){return t.valueDataType===De.Money&&Array.isArray(t.defaultValues)&&t.defaultValues.length>0}function vs(t,r){const s=new Intl.NumberFormat(gs(r),{minimumFractionDigits:0,maximumFractionDigits:2});return t.replace(/([\d]+(?:\.\d+)?)/g,n=>{const a=parseFloat(n);return isNaN(a)?n:s.format(a)})}function ks(t,r){const s=!r||r.length===0||r.every(n=>!n||!n.trim());if(t.isRequired&&s)return t.errorMessage||`${t.displayName} is required`;if(!s){const n=r[0]??"";if(n&&t.regex)try{if(!new RegExp(t.regex).test(n))return t.errorMessage||"Invalid format"}catch{}const a=t.valueDataType===De.Integer||t.valueDataType===De.Money||t.valueDataType===De.DigitOnly;if(a&&n.trim()!==""){const l=Number(n);if(!isNaN(l)){if(t.min!==void 0&&t.min!==null&&l<t.min)return`Minimum value is ${t.min}`;if(t.max!==void 0&&t.max!==null&&l>t.max)return`Maximum value is ${t.max}`}}else if(!a&&n!==""){if(t.min!==void 0&&t.min!==null&&n.length<t.min)return`Minimum length is ${t.min} characters`;if(t.max!==void 0&&t.max!==null&&n.length>t.max)return`Maximum length is ${t.max} characters`}}return null}function js(t){const r=new Map;return t.forEach((s,n)=>{const a=s.pageNumber!=null&&s.pageNumber>0?s.pageNumber:1;r.has(a)||r.set(a,[]),r.get(a).push({criterion:s,idx:n})}),Array.from(r.entries()).sort(([s],[n])=>s-n).map(([,s])=>s)}function ws(t){return t.builtInType===1?"country":!t.defaultValues||t.defaultValues.length===0?"text":t.multipleValue?"checkbox":"radio"}const Or=({applicantId:t,onComplete:r,onBack:s})=>{const{config:n}=Ne(),a=n.locale??"en",{criteria:l,initialAnswers:c,isLoading:u,isSubmitting:y,error:p,submit:b}=Nr(t),[T,v]=i.useState({}),[E,A]=i.useState({}),[k,S]=i.useState(0),[M,Y]=i.useState(!1);i.useEffect(()=>{c&&Object.keys(c).length>0&&Object.keys(T).length===0&&v(c)},[c]);const L=i.useMemo(()=>l&&l.length>0?js(l):[],[l]),_=k===L.length-1,U=L[k]??[];i.useEffect(()=>{!u&&l&&l.length===0&&!M&&!y&&(Y(!0),b({applicantId:t,criteriaValueInputs:[]}).then(()=>r==null?void 0:r()).catch(console.error))},[u,l,M,y,b,t,r]);const te=i.useCallback((Q,B)=>{v(J=>({...J,[Q]:B})),A(J=>{const ne={...J};return delete ne[Q],ne})},[]),R=i.useCallback(()=>{const Q={};for(const{criterion:B}of U){const J=ks(B,T[B.id]??[]);J&&(Q[B.id]=J)}return A(B=>({...B,...Q})),Object.keys(Q).length===0},[U,T]),g=()=>{R()&&S(Q=>Q+1)},O=()=>{k>0?S(Q=>Q-1):s==null||s()},q=async()=>{if(!(!R()||!l))try{const Q=l.map(J=>{const ne=(T[J.id]??[]).filter(V=>V&&V.trim());return ne.length>0?{riskCriteriaId:J.id,values:ne}:null}).filter(J=>J!==null);await b({applicantId:t,criteriaValueInputs:Q}),r==null||r()}catch(Q){console.error("Risk scoring submit error:",Q)}};return u?e.jsx(X,{children:e.jsxs(ee,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center text-sm mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Loading risk scoring criteria…"})]})}):!u&&l&&l.length===0?e.jsx(X,{children:e.jsxs(ee,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center text-sm mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"No criteria required. Moving to next step…"})]})}):p?e.jsx(X,{children:e.jsx(ee,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading criteria: ",p.message]})})}):l?e.jsxs(X,{children:[e.jsxs(he,{children:[e.jsx("h2",{className:"text-lg font-bold",children:"Risk Assessment"}),e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Please answer the following questions for risk evaluation"}),L.length>1&&e.jsxs("div",{className:"flex items-center justify-between mt-3",children:[e.jsxs("span",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:["Page ",k+1," of ",L.length]}),e.jsx("div",{className:"flex items-center gap-1.5",children:L.map((Q,B)=>e.jsx("div",{className:"rounded-full transition-all duration-200",style:{height:"6px",width:B===k?"20px":"6px",backgroundColor:B<=k?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},B))})]})]}),e.jsx(ee,{className:"space-y-6",children:U.map(({criterion:Q})=>e.jsx(Ss,{criterion:Q,value:T[Q.id]??[],error:E[Q.id],locale:a,onChange:B=>te(Q.id,B)},Q.id))}),e.jsxs(fe,{className:"flex items-center justify-between",children:[e.jsxs(G,{type:"button",variant:"outline",onClick:O,style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(Tr,{size:14}),k>0?"Previous":"Back"]}),_?e.jsx(G,{type:"button",isLoading:y,onClick:q,children:"Continue"}):e.jsxs(G,{type:"button",onClick:g,style:{display:"flex",alignItems:"center",gap:"4px"},children:["Next",e.jsx(Pr,{size:14})]})]}),p&&e.jsx("div",{className:"mx-6 mb-4 p-3 bg-red-50 border border-red-200 rounded",children:e.jsx("p",{className:"text-red-600 text-sm",children:p.message})})]}):null},Ss=({criterion:t,value:r,error:s,locale:n,onChange:a})=>{const l=ws(t),c=t.valueDataType===De.Integer||t.valueDataType===De.Money||t.valueDataType===De.DigitOnly,u=bs(t),y=p=>u?vs(p,n):p;return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[t.displayName,t.isRequired&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),t.description&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:t.description}),c&&(t.min!==void 0||t.max!==void 0)&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:t.min!==void 0&&t.max!==void 0?`Range: ${t.min} – ${t.max}`:t.min!==void 0?`Minimum: ${t.min}`:`Maximum: ${t.max}`}),l==="text"&&e.jsx(ye,{value:r[0]??"",onChange:p=>a([p.target.value]),type:c?"number":"text",placeholder:"Enter your answer…",error:s,required:t.isRequired,min:t.min,max:t.max,onKeyDown:p=>{t.valueDataType===De.DigitOnly&&["e","E","+","-","."].includes(p.key)&&p.preventDefault()}}),l==="radio"&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultValues??[]).map(p=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"radio",checked:r[0]===p,onChange:()=>a([p]),className:"metakyc-option-input",style:{width:"16px",height:"16px",minWidth:"16px",flexShrink:0,flexGrow:0,accentColor:"var(--metakyc-primary, #2563eb)",cursor:"pointer",margin:0,padding:0,display:"inline-block",verticalAlign:"middle"}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:y(p)})]},p)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),l==="checkbox"&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultValues??[]).map(p=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"checkbox",checked:r.includes(p),onChange:b=>{b.target.checked?a([...r,p]):a(r.filter(T=>T!==p))},className:"metakyc-option-input",style:{width:"16px",height:"16px",minWidth:"16px",flexShrink:0,flexGrow:0,accentColor:"var(--metakyc-primary, #2563eb)",cursor:"pointer",margin:0,padding:0,display:"inline-block",verticalAlign:"middle"}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:y(p)})]},p)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),l==="country"&&e.jsx(pt,{value:r[0]??"",onChange:p=>a([p.target.value]),options:[{value:"US",label:"United States"},{value:"GB",label:"United Kingdom"},{value:"DE",label:"Germany"},{value:"FR",label:"France"},{value:"AE",label:"United Arab Emirates"}],placeholder:"Select a country…",error:s,required:t.isRequired})]})},zr=({applicantId:t,onComplete:r,onBack:s})=>{const{investorCategorizationService:n}=Ne(),[a,l]=i.useState(null),[c,u]=i.useState(!1),[y,p]=i.useState(null),b=async T=>{if(T.preventDefault(),a===null){p("Please select an investor type");return}u(!0),p(null);try{const v={applicantId:t,investorType:a};console.log("Submitting investor categorization:",v);const E=await n.setInvestorCategorization(v);console.log("Investor categorization result:",E),r==null||r()}catch(v){console.error("Error submitting investor categorization:",v),p(v.message||"Failed to submit investor categorization")}finally{u(!1)}};return e.jsx("form",{onSubmit:b,children:e.jsxs(X,{children:[e.jsxs(he,{children:[e.jsx("h2",{className:"text-lg font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Which statement best describes you?"}),e.jsx("p",{className:"mt-2",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"All Tokenise clients are treated as Retail Investors under EU regulation, which gives you the highest level of investor protection. For our internal purposes, we ask you to select the description that best matches your situation"})]}),e.jsxs(ee,{className:"space-y-4",children:[e.jsx("p",{className:"text-sm font-medium mb-3",style:{color:"var(--metakyc-text-secondary, #374151)"},children:"Choose one"}),e.jsx("label",{className:"block p-4 border-2 rounded-lg cursor-pointer transition-all",style:{borderColor:a===je.Individual?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:a===je.Individual?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:je.Individual,checked:a===je.Individual,onChange:()=>l(je.Individual),className:"mt-1"}),e.jsxs("div",{className:"ml-3",children:[e.jsx("div",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Individual investor"}),e.jsx("div",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"(Recommended) Most of our clients choose this option. Provides the strongest protection and aligns with our mission to make investing accessible to everyone."})]})]})}),e.jsx("label",{className:"block p-4 border-2 rounded-lg cursor-pointer transition-all",style:{borderColor:a===je.Sophisticated?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:a===je.Sophisticated?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:je.Sophisticated,checked:a===je.Sophisticated,onChange:()=>l(je.Sophisticated),className:"mt-1"}),e.jsxs("div",{className:"ml-3",children:[e.jsx("div",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Sophisticated investor"}),e.jsx("div",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"In the last 2 years, I have done one or more of the following:"}),e.jsxs("ul",{className:"text-sm mt-2 space-y-1 list-none",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:[e.jsx("li",{children:"Worked in private equity or provided capital to small and medium enterprises, and/or"}),e.jsx("li",{children:"Been the director of a company with an annual turnover of at least (USD) $2m million, and/or"}),e.jsx("li",{children:"Invested directly in at least 2 private (not listed) companies."})]})]})]})}),e.jsx("label",{className:"block p-4 border-2 rounded-lg cursor-pointer transition-all",style:{borderColor:a===je.HighNetWorth?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:a===je.HighNetWorth?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:je.HighNetWorth,checked:a===je.HighNetWorth,onChange:()=>l(je.HighNetWorth),className:"mt-1"}),e.jsxs("div",{className:"ml-3",children:[e.jsx("div",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"High networth investor"}),e.jsxs("div",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:["I earn more than (USD/EUR) $150,000 per year, and/or",e.jsx("br",{}),"I have net assets (excluding my main property) of at least $/EUR 300,000"]})]})]})}),y&&e.jsx("div",{className:"p-4 rounded-lg",style:{backgroundColor:"#fee2e2",border:"1px solid #fca5a5"},children:e.jsxs("p",{className:"text-sm",style:{color:"#991b1b"},children:[e.jsx("strong",{children:"Error:"})," ",y]})})]}),e.jsxs(fe,{className:"flex justify-between",children:[s&&e.jsx(G,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(G,{type:"submit",isLoading:c,disabled:a===null,children:"Submit"})]})]})})};function Nt(t){const r=t.split(":").map(Number);return r.length===3?r[0]*3600+r[1]*60+r[2]:0}function mt(t){const r=Math.floor(t/60),s=t%60;return`${r.toString().padStart(2,"0")}:${s.toString().padStart(2,"0")}`}const Br=({applicantId:t,onComplete:r,onBack:s})=>{const{appropriatenessTestService:n}=Ne(),[a,l]=i.useState(null),[c,u]=i.useState(!0),[y,p]=i.useState(!1),[b,T]=i.useState(null),[v,E]=i.useState({}),[A,k]=i.useState(0),[S,M]=i.useState(!1),[Y,L]=i.useState(!1),[_,U]=i.useState(0),[te,R]=i.useState(0),[g,O]=i.useState(null);i.useEffect(()=>{(async()=>{try{u(!0),T(null);const z=await n.getAppropriatenessTest(t);if(l(z),z.waitTimeSpanForNextTry&&z.waitTimeSpanForNextTry!=="00:00:00"){const $=Nt(z.waitTimeSpanForNextTry);$>0&&U($)}}catch(z){T(z.message||"Failed to load appropriateness test")}finally{u(!1)}})()},[t,n]),i.useEffect(()=>{if(!S||A<=0)return;const z=setInterval(()=>{k($=>$<=1?(L(!0),0):$-1)},1e3);return()=>clearInterval(z)},[S,A]),i.useEffect(()=>{if(_<=0)return;const z=setInterval(()=>{U($=>$<=1?0:$-1)},1e3);return()=>clearInterval(z)},[_]),i.useEffect(()=>{Y&&!y&&J()},[Y]);const q=()=>{a&&(M(!0),k(a.testDurationSec),R(0),E({}),T(null))},Q=(z,$)=>{E(me=>({...me,[z]:$}))},B=i.useCallback(async()=>{try{const z=await n.getAppropriatenessTest(t);if(l(z),z.waitTimeSpanForNextTry&&z.waitTimeSpanForNextTry!=="00:00:00"){const $=Nt(z.waitTimeSpanForNextTry);$>0&&U($)}}catch{}},[t,n]),J=async z=>{if(a){if(!Y){const $=a.appropriatenessQuestions.length-Object.keys(v).length;if($>0){T(`Please answer all questions. ${$} remaining.`);return}}p(!0),T(null);try{const $=a.appropriatenessQuestions.map(N=>({appropriatenessQuestionId:N.id,value:v[N.id]||""})),me={applicantId:t,appropriatenessTestId:a.id,appropriatenessQuestionResults:$};try{const N=await n.fillAppropriatenessTest(me);N.isSuccess?O({success:!0,message:N.message||"Congratulations! You have passed the test."}):(O({success:!1,message:N.message||"You did not pass the test."}),setTimeout(()=>B(),1e3))}catch(N){if(N.code===400&&N.message)O({success:!1,message:N.message}),setTimeout(()=>B(),1500);else throw N}}catch($){T($.message||"Failed to submit test. Please try again."),ne()}finally{p(!1)}}},ne=()=>{M(!1),L(!1),E({}),R(0)};if(c)return e.jsx(X,{children:e.jsx(ee,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"48px 0",gap:"16px"},children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)"},children:"Loading test..."})]})})});if(!a)return e.jsx(X,{children:e.jsx(ee,{children:e.jsxs("div",{style:{textAlign:"center",padding:"48px 0"},children:[e.jsx("p",{style:{fontSize:"16px",fontWeight:600,color:"var(--metakyc-danger, #ef4444)"},children:"No test data available"}),b&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"8px"},children:b})]})})});const V=a.testAllowedMaxTry-a.totalFailedTries,ge=a.appropriatenessQuestions.length,le=Object.keys(v).length;if(_>0)return e.jsxs(X,{children:[e.jsx(he,{children:e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:a.displayName})}),e.jsx(ee,{children:e.jsxs("div",{style:{textAlign:"center",padding:"32px 0"},children:[e.jsx("div",{style:{width:"100px",height:"100px",borderRadius:"50%",margin:"0 auto 20px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"color-mix(in srgb, var(--metakyc-primary, #2563eb) 8%, transparent)"},children:e.jsx("span",{style:{fontSize:"28px",fontWeight:700,color:"var(--metakyc-primary, #2563eb)",fontVariantNumeric:"tabular-nums"},children:mt(_)})}),e.jsx("p",{style:{fontSize:"15px",fontWeight:500,color:"var(--metakyc-text-primary, #111827)"},children:"Please wait before retrying"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"4px"},children:"You can attempt the test again once the timer expires"}),b&&e.jsx("div",{style:{marginTop:"20px",padding:"12px 16px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:b})})]})})]});if(g){const z=()=>{O(null),ne(),T(null)};return e.jsxs(X,{children:[e.jsx(ee,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",textAlign:"center",padding:"40px 16px",gap:"16px"},children:[e.jsx("div",{style:{width:"72px",height:"72px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:g.success?"color-mix(in srgb, var(--metakyc-success, #10b981) 12%, transparent)":"color-mix(in srgb, var(--metakyc-danger, #ef4444) 10%, transparent)"},children:g.success?e.jsxs("svg",{width:"36",height:"36",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-success, #10b981)",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),e.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]}):e.jsxs("svg",{width:"36",height:"36",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),e.jsx("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]})}),e.jsx("h2",{style:{fontSize:"20px",fontWeight:700,color:g.success?"var(--metakyc-success, #10b981)":"var(--metakyc-danger, #ef4444)",margin:0},children:g.success?"Test Passed":"Test Failed"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",margin:0,lineHeight:1.6,maxWidth:"400px",whiteSpace:"pre-line"},children:g.message}),!g.success&&V>0&&e.jsx("div",{style:{marginTop:"4px",padding:"10px 20px",borderRadius:"10px",backgroundColor:"var(--metakyc-surface, #f9fafb)",border:"1px solid var(--metakyc-border, #e5e7eb)"},children:e.jsxs("p",{style:{fontSize:"13px",color:"var(--metakyc-text-muted, #9ca3af)",margin:0},children:["You have ",e.jsx("strong",{style:{color:"var(--metakyc-text-primary, #111827)"},children:V})," attempt",V!==1?"s":""," remaining"]})}),!g.success&&V<=0&&e.jsx("div",{style:{marginTop:"4px",padding:"10px 20px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:"No attempts remaining. Please contact support for assistance."})})]})}),e.jsx(fe,{children:e.jsx("div",{style:{display:"flex",justifyContent:"center",width:"100%",gap:"12px"},children:g.success?e.jsx(G,{type:"button",onClick:()=>r==null?void 0:r(),children:"Continue"}):e.jsxs(e.Fragment,{children:[V>0&&_<=0&&e.jsx(G,{type:"button",onClick:z,children:"Retake Test"}),V>0&&_>0&&e.jsx(G,{type:"button",onClick:z,children:"OK"}),V<=0&&s&&e.jsx(G,{type:"button",variant:"outline",onClick:s,children:"Back"})]})})})]})}if(!S)return e.jsxs(X,{children:[e.jsxs(he,{children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:a.displayName}),a.subtitle&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",marginTop:"4px"},children:a.subtitle})]}),e.jsxs(ee,{children:[a.description&&e.jsxs("div",{style:{marginBottom:"20px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-primary, #2563eb) 5%, var(--metakyc-background, #ffffff))",border:"1px solid color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)",display:"flex",gap:"10px"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-primary, #2563eb)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:"1px"},children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-secondary, #374151)",margin:0,lineHeight:1.5},children:a.description})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px",marginBottom:"20px"},children:[e.jsx(lt,{icon:"questions",label:"Questions",value:String(a.totalQuestionCount)}),e.jsx(lt,{icon:"time",label:"Time Limit",value:mt(a.testDurationSec)}),e.jsx(lt,{icon:"target",label:"Pass Requirement",value:`${a.testCorrectAnswerPassLimit} correct`}),e.jsx(lt,{icon:"retry",label:"Attempts Left",value:String(V),variant:V<=1?"warning":"default"})]}),b&&e.jsxs("div",{style:{marginBottom:"16px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)",display:"flex",gap:"10px"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:"1px"},children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),e.jsxs("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0,lineHeight:1.5},children:[e.jsx("strong",{children:"Previous attempt:"})," ",b]})]}),V<=0&&e.jsx("div",{style:{padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:"You have used all your attempts. Please contact support for assistance."})})]}),e.jsx(fe,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:s?"space-between":"flex-end",width:"100%"},children:[s&&e.jsx(G,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(G,{type:"button",onClick:q,disabled:V<=0,children:"Start Test"})]})})]});const de=a.appropriatenessQuestions[te],be=te===ge-1,I=le===ge,W=A<=60;return e.jsxs(X,{children:[e.jsxs(he,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:a.displayName}),e.jsxs("p",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"2px"},children:["Question ",te+1," of ",ge]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 14px",borderRadius:"999px",backgroundColor:W?"color-mix(in srgb, var(--metakyc-danger, #ef4444) 10%, transparent)":"var(--metakyc-surface, #f3f4f6)",transition:"all 0.3s ease"},children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:W?"var(--metakyc-danger, #ef4444)":"var(--metakyc-text-muted, #9ca3af)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),e.jsx("span",{style:{fontSize:"16px",fontWeight:700,fontVariantNumeric:"tabular-nums",color:W?"var(--metakyc-danger, #ef4444)":"var(--metakyc-text-primary, #111827)",transition:"color 0.3s ease"},children:mt(A)})]})]}),e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsx("div",{style:{height:"4px",borderRadius:"999px",backgroundColor:"var(--metakyc-border, #e5e7eb)",overflow:"hidden"},children:e.jsx("div",{style:{height:"100%",borderRadius:"999px",backgroundColor:"var(--metakyc-primary, #2563eb)",width:`${le/ge*100}%`,transition:"width 0.3s ease"}})}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:"4px"},children:[e.jsxs("span",{style:{fontSize:"11px",color:"var(--metakyc-text-muted, #9ca3af)"},children:[le," answered"]}),e.jsxs("span",{style:{fontSize:"11px",color:"var(--metakyc-text-muted, #9ca3af)"},children:[V," attempt",V!==1?"s":""," left"]})]})]})]}),e.jsxs(ee,{children:[de&&e.jsx(Ns,{question:de,index:te,selectedAnswer:v[de.id],onSelect:z=>Q(de.id,z),disabled:y}),ge>1&&e.jsx("div",{style:{display:"flex",justifyContent:"center",gap:"6px",marginTop:"20px",flexWrap:"wrap"},children:a.appropriatenessQuestions.map((z,$)=>e.jsx("button",{type:"button",onClick:()=>R($),style:{width:"28px",height:"28px",borderRadius:"8px",border:$===te?"2px solid var(--metakyc-primary, #2563eb)":"1px solid var(--metakyc-border, #e5e7eb)",backgroundColor:v[z.id]?$===te?"color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)":"color-mix(in srgb, var(--metakyc-primary, #2563eb) 8%, transparent)":$===te?"var(--metakyc-surface, #f9fafb)":"var(--metakyc-background, #ffffff)",color:v[z.id]?"var(--metakyc-primary, #2563eb)":"var(--metakyc-text-muted, #9ca3af)",fontSize:"12px",fontWeight:600,cursor:"pointer",transition:"all 0.15s ease",padding:0,display:"flex",alignItems:"center",justifyContent:"center"},children:$+1},z.id))}),Y&&e.jsxs("div",{style:{marginTop:"16px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, #f59e0b 10%, transparent)",border:"1px solid color-mix(in srgb, #f59e0b 25%, transparent)",display:"flex",alignItems:"center",gap:"10px"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"#f59e0b",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),e.jsx("p",{style:{fontSize:"13px",color:"#b45309",margin:0,fontWeight:500},children:"Time's up! Your answers are being submitted."})]}),b&&!Y&&e.jsx("div",{style:{marginTop:"16px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:b})})]}),e.jsx(fe,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[e.jsx(G,{type:"button",variant:"outline",onClick:()=>{te>0?R(z=>z-1):s==null||s()},disabled:y,children:te>0?"Previous":"Cancel"}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[!be&&e.jsx(G,{type:"button",onClick:()=>R(z=>z+1),children:"Next"}),(be||I)&&e.jsx(G,{type:"button",isLoading:y,onClick:()=>J(),disabled:!I&&!Y,style:{opacity:I||Y?1:.5},children:Y?"Submitting...":"Submit Test"})]})]})})]})},Cs={questions:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M9 11l3 3L22 4"}),e.jsx("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),time:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),target:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("circle",{cx:"12",cy:"12",r:"6"}),e.jsx("circle",{cx:"12",cy:"12",r:"2"})]}),retry:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})},lt=({icon:t,label:r,value:s,variant:n="default"})=>{const a=n==="warning";return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px",padding:"14px",borderRadius:"10px",backgroundColor:a?"color-mix(in srgb, #f59e0b 8%, transparent)":"var(--metakyc-surface, #f9fafb)",border:a?"1px solid color-mix(in srgb, #f59e0b 20%, transparent)":"1px solid var(--metakyc-border, #e5e7eb)"},children:[e.jsx("div",{style:{color:a?"#f59e0b":"var(--metakyc-primary, #2563eb)",flexShrink:0},children:Cs[t]}),e.jsxs("div",{children:[e.jsx("p",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)",margin:0},children:r}),e.jsx("p",{style:{fontSize:"15px",fontWeight:600,color:a?"#b45309":"var(--metakyc-text-primary, #111827)",margin:0,marginTop:"1px"},children:s})]})]})},Ns=({question:t,selectedAnswer:r,onSelect:s,disabled:n})=>e.jsxs("div",{children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[t.groupName&&e.jsx("span",{style:{display:"inline-block",fontSize:"11px",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em",color:"var(--metakyc-primary, #2563eb)",marginBottom:"8px"},children:t.groupName}),e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--metakyc-text-primary, #111827)",margin:0,lineHeight:1.5},children:t.question})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.answers.map((a,l)=>{const c=r===a;return e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"12px",padding:"14px 16px",borderRadius:"10px",border:`2px solid ${c?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}`,backgroundColor:c?"color-mix(in srgb, var(--metakyc-primary, #2563eb) 5%, var(--metakyc-background, #ffffff))":"var(--metakyc-background, #ffffff)",cursor:n?"default":"pointer",transition:"all 0.15s ease",opacity:n?.6:1},onMouseEnter:u=>{!n&&!c&&(u.currentTarget.style.borderColor="color-mix(in srgb, var(--metakyc-primary, #2563eb) 50%, var(--metakyc-border, #e5e7eb))")},onMouseLeave:u=>{c||(u.currentTarget.style.borderColor="var(--metakyc-border, #e5e7eb)")},children:[e.jsx("div",{style:{width:"20px",height:"20px",borderRadius:"50%",border:`2px solid ${c?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #d1d5db)"}`,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,transition:"border-color 0.15s ease"},children:c&&e.jsx("div",{style:{width:"10px",height:"10px",borderRadius:"50%",backgroundColor:"var(--metakyc-primary, #2563eb)"}})}),e.jsx("input",{type:"radio",name:`q-${t.id}`,value:a,checked:c,onChange:()=>s(a),disabled:n,style:{position:"absolute",opacity:0,width:0,height:0}}),e.jsx("span",{style:{fontSize:"14px",color:c?"var(--metakyc-text-primary, #111827)":"var(--metakyc-text-secondary, #6b7280)",fontWeight:c?500:400,transition:"color 0.15s ease"},children:a})]},l)})})]}),_r=({applicantId:t,onComplete:r,onBack:s})=>{var Qe,ze,Xe,We;const{applicantService:n,baseInformationService:a,identityService:l,config:c,currentTheme:u}=Ne(),{identityData:y,provider:p,token:b,isLoading:T,error:v,requestIdentity:E,restartIdentity:A}=Cr(t),[k,S]=i.useState(null),[M,Y]=i.useState(null),[L,_]=i.useState([]),[U,te]=i.useState([]),[R,g]=i.useState(!0),[O,q]=i.useState(!1),[Q,B]=i.useState(null),[J,ne]=i.useState(!1),V=i.useRef(!1),[ge,le]=i.useState({}),[de,be]=i.useState({}),I=u!=null&&u.reviewPageFields&&u.reviewPageFields.length>0?u.reviewPageFields[0]:null,W=!!(u!=null&&u.reviewPageDisabled),z=i.useRef(!1);z.current=W;const $=Ke.useForm({defaultValues:{street:"",streetNumber:"",city:"",zip:"",country:"",nationality:"",phonenumber:""}});i.useEffect(()=>{if(W){V.current||(V.current=!0,E().then(()=>q(!0)).catch(D=>console.error("[Identity] Auto-request failed:",D)).finally(()=>g(!1)));return}(async()=>{try{const[D,K,H]=await Promise.all([n.getApplicantData(t),a.getCountries("","en"),a.getCountries("","en",40)]);Y(D);const Z=new Set,m=K.map(h=>({value:h.abbreviation3||h.abbreviation,label:h.name})).filter(h=>!h.value||Z.has(h.value)?!1:(Z.add(h.value),!0));_(m);const C=new Set,F=H.filter(h=>h.countryCode).map(h=>({value:h.countryCode,label:`${h.countryCode} – ${h.name}`})).filter(h=>C.has(h.value)?!1:(C.add(h.value),!0));te(F);const d=D.applicantRequestData;if(le({firstName:(d==null?void 0:d.firstName)||"",lastName:(d==null?void 0:d.lastName)||"",email:(d==null?void 0:d.email)||"",dateOfBirth:(d==null?void 0:d.dateOfBirth)||"",title:(d==null?void 0:d.title)||"",salutation:(d==null?void 0:d.salutation)||"",phonenumber:(d==null?void 0:d.phonenumber)||"",mobileCountryCode:(d==null?void 0:d.mobileCountryCode)||"",street:(d==null?void 0:d.street)||"",streetNumber:(d==null?void 0:d.streetNumber)||"",city:(d==null?void 0:d.city)||"",zip:(d==null?void 0:d.zip)||"",country:(d==null?void 0:d.country)||"",nationality:(d==null?void 0:d.nationality)||"",taxCountry:(d==null?void 0:d.taxCountry)||"",countryOfBirth:(d==null?void 0:d.countryOfBirth)||"",placeOfBirth:(d==null?void 0:d.placeOfBirth)||"",educationLevel:(d==null?void 0:d.educationLevel)||"",occupation:(d==null?void 0:d.occupation)||"",taxNumber:(d==null?void 0:d.taxNumber)||"",defaultLanguage:(d==null?void 0:d.defaultLanguage)||""}),$.reset({street:(d==null?void 0:d.street)||"",streetNumber:(d==null?void 0:d.streetNumber)||"",city:(d==null?void 0:d.city)||"",zip:(d==null?void 0:d.zip)||"",country:(d==null?void 0:d.country)||"",nationality:(d==null?void 0:d.nationality)||"",phonenumber:(d==null?void 0:d.phonenumber)||""}),D.kycRecords&&D.kycRecords.length>0&&D.kycRecords[0].providerTokenObject!==null&&!V.current&&z.current){console.log("[Identity] Review page disabled + existing identity — auto-requesting..."),V.current=!0;try{await E(),q(!0)}catch(h){console.error("[Identity] Auto-request failed:",h)}}}catch(D){console.error("Error loading applicant data:",D)}finally{g(!1)}})()},[t]),i.useEffect(()=>{y&&!O&&z.current&&(console.log("[Identity] Review page disabled — showing cached provider"),q(!0))},[y,O]),i.useEffect(()=>{if(b){if(b.expiresAt){const x=new Date(b.expiresAt).getTime();if(Date.now()>=x){console.warn("[Identity] Token has expired (expiresAt)"),ne(!0),B("Your verification session has expired. Please restart.");return}}if(b.url)try{const D=new URL(b.url).toString().toLowerCase();if(D.includes("expired")||D.includes("invalid")||D.includes("error")){console.warn("[Identity] Token URL indicates expiration"),ne(!0),B("Your verification link has expired. Please restart.");return}}catch{console.error("[Identity] Invalid token URL")}if(b.status==="expired"||b.error==="expired"||b.expired===!0){console.warn("[Identity] Token object indicates expiration"),ne(!0),B("Your verification session has expired. Please restart.");return}}},[b]);const me=p!==null&&p===Ae.Sumsub;i.useEffect(()=>{if(p!==null&&b&&!k&&O&&!J){const x=p;if(me){console.log("[Sumsub] Fetching access token for Web SDK…"),B(null),(async()=>{try{const D=await l.refreshSumsubToken(t),K=_e.parseProviderConfig(p,b,c);K.accessToken=D,K.onTokenRefresh=()=>l.refreshSumsubToken(t);const H=_e.createProvider(p,K);H.onComplete(Z=>{console.log("[Sumsub] Verification complete:",Z),r==null||r()}),H.onError(Z=>{console.error("[Sumsub] SDK error:",Z),(typeof Z=="string"?Z:(Z==null?void 0:Z.message)||"Unknown error").toLowerCase().includes("expired")&&(ne(!0),B("Session expired. Please restart."))}),await H.initialize("sumsub-websdk-container"),console.log("[Sumsub] Web SDK launched"),S(H)}catch(D){console.error("[Sumsub] Initialization error:",D),B(`Failed to initialize: ${D.message||D}`),String(D.message||D).toLowerCase().includes("expired")&&ne(!0)}})();return}if(b.url){console.log("[Identity] Loading provider URL for user verification:",b.url),B(null);try{if(new URL(b.url),x===Ae.SardinAI){console.log("[SardinAI] Initializing Risk SDK in background...");try{const D=_e.parseProviderConfig(p,b,c);_e.createProvider(p,D).initialize().then(()=>console.log("[SardinAI] Risk SDK initialized in background")).catch(H=>console.warn("[SardinAI] Risk SDK init failed (non-blocking):",H))}catch(D){console.warn("[SardinAI] Risk SDK setup failed (non-blocking):",D)}}S({type:"url",url:b.url})}catch(D){console.error("[Identity] Invalid URL:",D),B("Invalid verification URL. Please restart."),ne(!0)}return}if(x===Ae.SardinAI){console.log("[SardinAI] No URL provided - initializing Risk SDK only..."),B(null);try{const D=_e.parseProviderConfig(p,b,c),K=_e.createProvider(p,D);K.initialize().then(()=>{console.log("[SardinAI] Risk SDK initialized successfully"),S(K),setTimeout(()=>r==null?void 0:r(),2e3)}).catch(H=>{var m;console.error("[SardinAI] Failed to initialize:",H);const Z=((m=H.message)==null?void 0:m.toLowerCase())||"";Z.includes("expired")||Z.includes("invalid")||Z.includes("401")||Z.includes("400")?(ne(!0),B("Session expired or invalid. Please restart verification.")):B(`Failed to initialize: ${H.message}`)})}catch(D){console.error("[SardinAI] Error creating provider:",D),B(`Configuration error: ${D.message}`)}return}try{B(null);const D=_e.parseProviderConfig(p,b,c),K=_e.createProvider(p,D);x===Ae.Onfido&&K.initialize("identity-container").catch(H=>{console.error("[Onfido] Initialization error:",H),B(`Failed to initialize: ${H.message}`)}),S(K)}catch(D){console.error("[Identity] Provider setup error:",D),B(`Setup error: ${D.message}`)}}return()=>{if(k&&k.destroy)try{k.destroy()}catch(x){console.error("[Identity] Error destroying provider:",x)}}},[p,b,k,O,r,J,me,t,c,l]);const N=async()=>{try{B(null),ne(!1),await E(),q(!0)}catch(x){console.error("Error starting identity verification:",x)}},re=async()=>{try{B(null),ne(!1),S(null),console.log("[Identity] Restarting verification..."),await A(),q(!0)}catch(x){console.error("Error restarting identity verification:",x),B(x.message||"Failed to restart verification")}};if(R||T)return e.jsx(X,{children:e.jsxs(ee,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-4",children:"Loading identity verification..."})]})});if(v)return e.jsx(X,{children:e.jsx(ee,{children:e.jsxs("p",{className:"text-danger-500",children:["Error: ",v.message]})})});if(O&&(Q||J))return e.jsxs(X,{children:[e.jsx(he,{children:e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"Verification Session Issue"})}),e.jsxs(ee,{children:[e.jsx("div",{className:"p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg mb-6",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("svg",{className:"h-6 w-6 text-red-600 dark:text-red-400 mr-3 mt-0.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-red-900 dark:text-red-100 mb-1",children:J?"Session Expired":"Verification Error"}),e.jsx("p",{className:"text-red-800 dark:text-red-200 text-sm",children:Q||"Your verification session has expired and needs to be restarted."})]})]})}),e.jsxs("div",{className:"bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-4",children:[e.jsx("h3",{className:"font-semibold text-blue-900 dark:text-blue-100 mb-2",children:"What to do next:"}),e.jsxs("ul",{className:"text-blue-800 dark:text-blue-200 text-sm space-y-1 list-disc list-inside",children:[e.jsx("li",{children:'Click "Restart Verification" below to generate a new session'}),e.jsx("li",{children:"Complete the verification process without delays"}),e.jsx("li",{children:"If issues persist, contact support"})]})]})]}),e.jsxs(fe,{className:"flex justify-between",children:[s&&e.jsx(G,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(G,{type:"button",onClick:re,disabled:T,children:T?"Restarting...":"Restart Verification"})]})]});if(O&&y){const x=p;return me?e.jsxs(X,{children:[e.jsx(he,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Identity Verification"}),e.jsx("p",{style:{color:"var(--metakyc-text-secondary, #6b7280)",marginTop:"4px",fontSize:"14px"},children:"Please complete the identity verification process"})]}),e.jsx(G,{type:"button",variant:"outline",size:"sm",onClick:re,disabled:T,children:"Restart"})]})}),e.jsx(ee,{children:e.jsx("div",{id:"sumsub-websdk-container",style:{minHeight:"500px",width:"100%"}})}),s&&e.jsx(fe,{children:e.jsx(G,{variant:"outline",onClick:s,children:"Back"})})]}):b!=null&&b.url?e.jsxs(X,{children:[e.jsx(he,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Identity Verification"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:"Please complete the identity verification process"})]}),e.jsx(G,{type:"button",variant:"outline",size:"sm",onClick:re,disabled:T,children:"Restart"})]})}),e.jsxs(ee,{children:[e.jsx("div",{className:"mb-4 p-3 bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg",children:e.jsxs("p",{className:"text-yellow-800 dark:text-yellow-200 text-sm",children:[e.jsx("strong",{children:"Important:"}),' If you see an "expired" or "invalid link" message below, click the "Restart" button above to generate a new verification session.']})}),e.jsx("div",{className:"w-full",style:{height:"600px"},children:e.jsx("iframe",{src:b.url,className:"w-full h-full border-0 rounded-lg",allow:"camera; microphone; geolocation",title:"Identity Verification",onLoad:D=>{var K,H,Z;console.log("[Identity] Iframe loaded");try{const m=D.target,C=m.contentDocument||((K=m.contentWindow)==null?void 0:K.document);if(C){const F=((Z=(H=C.body)==null?void 0:H.textContent)==null?void 0:Z.toLowerCase())||"";(F.includes("expired")||F.includes("invalid")||F.includes("error"))&&(console.warn("[Identity] Iframe shows expiration message"),ne(!0),B("Your verification link has expired."))}}catch{console.log("[Identity] Cannot check iframe content (CORS)")}}})})]}),s&&e.jsx(fe,{children:e.jsx(G,{variant:"outline",onClick:s,children:"Back"})})]}):x===Ae.SardinAI?e.jsxs(X,{children:[e.jsxs(he,{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Device Risk Assessment"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:"Analyzing device security and behavioral patterns..."})]}),e.jsx(ee,{children:e.jsxs("div",{className:"text-center py-12",children:[e.jsx(Ee,{className:"mb-4"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Please wait while we verify your device security"}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-500 mt-2",children:"This process is automatic and will complete in a few seconds"})]})})]}):e.jsxs(X,{children:[e.jsxs(he,{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Identity Verification"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:"Please complete the identity verification process"})]}),e.jsx(ee,{children:e.jsx("div",{id:"identity-container",className:"min-h-[400px]"})}),s&&e.jsx(fe,{children:e.jsx(G,{variant:"outline",onClick:s,children:"Back"})})]})}const ue=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),ae=(x=4)=>({1:"col-span-1",2:"col-span-2",3:"col-span-3",4:"col-span-4"})[x]||"col-span-4",ve=(x,D)=>{if(!D&&D!==0)return"—";if(ue.has(x)&&x!=="mobileCountryCode"){const K=L.find(H=>H.value===D);return K?K.label:String(D)}return String(D)},Te=({helpText:x})=>{const[D,K]=i.useState(!1),H=i.useRef(null),[,Z]=i.useState({top:0,left:0}),m=()=>{if(H.current){const C=H.current.getBoundingClientRect();Z({top:C.bottom+window.scrollY+6,left:C.left+window.scrollX})}K(!0)};return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"metakyc-help-btn",ref:H,onClick:m,style:{width:18,height:18,borderRadius:"50%",border:"1.5px solid var(--metakyc-primary, #2563eb)",background:"transparent",color:"var(--metakyc-primary, #2563eb)",fontSize:11,fontWeight:700,cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,lineHeight:1,position:"relative",zIndex:2},children:"?"}),D&&ut.createPortal(e.jsx("div",{style:{position:"fixed",inset:0,zIndex:99999,background:"rgba(0,0,0,0.55)",backdropFilter:"blur(6px)",WebkitBackdropFilter:"blur(6px)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:()=>K(!1),children:e.jsxs("div",{onClick:C=>C.stopPropagation(),style:{background:"var(--metakyc-surface, var(--metakyc-background, #ffffff))",border:"1px solid var(--metakyc-border, #e5e7eb)",borderRadius:"var(--metakyc-border-radius, 8px)",padding:"20px 24px",maxWidth:400,width:"90%",boxShadow:"0 24px 64px rgba(0,0,0,0.4)"},children:[e.jsx("div",{dangerouslySetInnerHTML:{__html:x},style:{fontSize:13,color:"var(--metakyc-text-primary, #111827)",lineHeight:1.6}}),e.jsx("button",{type:"button",onClick:()=>K(!1),style:{marginTop:12,padding:"4px 12px",fontSize:12,border:"1px solid var(--metakyc-border, #e5e7eb)",borderRadius:"var(--metakyc-border-radius, 6px)",background:"transparent",cursor:"pointer",color:"var(--metakyc-text-secondary, #6b7280)"},children:"Close"})]})}),document.body)]})},ke=(x,D)=>D?e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:5,flexWrap:"nowrap"},children:[e.jsx("div",{style:{flex:1,minWidth:0},children:x}),e.jsx("div",{style:{paddingTop:24},children:e.jsx(Te,{helpText:D})})]}):x,Oe=(x,D)=>{const K=`cf-${D}`,H=x.paramName??"",Z=de[H];if(x.customType==="br")return e.jsx("div",{className:ae(x.colSpan),style:{minHeight:"0.5rem"}},K);if(x.customType==="paragraph")return e.jsx("div",{className:ae(x.colSpan),children:e.jsx("div",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:x.label||""}})},K);if(x.customType==="html")return e.jsx("div",{className:ae(x.colSpan),dangerouslySetInnerHTML:{__html:x.label||""}},K);if(x.customType==="link")return e.jsx("div",{className:ae(x.colSpan),children:ke(e.jsx("a",{href:x.linkUrl??"#",target:"_blank",rel:"noopener noreferrer",className:"text-sm underline",style:{color:"var(--metakyc-primary, #6366f1)"},children:x.displayText||x.label||x.linkText||x.linkUrl}),x.helpText)},K);if(x.customType==="checkbox"||x.customType==="link_checkbox"){const m=Z==="true"||Z===!0;return e.jsx("div",{className:ae(x.colSpan),children:ke(e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:!!m,onChange:C=>be(F=>({...F,[H]:String(C.target.checked)})),style:{width:16,height:16,flexShrink:0,marginTop:2,accentColor:"var(--metakyc-primary, #6366f1)"}}),e.jsx("span",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)"},children:x.customType==="link_checkbox"&&x.linkUrl?e.jsxs(e.Fragment,{children:[e.jsx("a",{href:x.linkUrl,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--metakyc-primary, #6366f1)",textDecoration:"underline"},children:x.linkText||x.label}),x.label&&x.linkText?` ${x.label}`:""]}):x.displayText||x.label})]}),x.helpText)},K)}if(x.customType==="group_checkbox"){const m=Array.isArray(Z)?Z:Z?[Z]:[],C=F=>{x.singleSelect?be(d=>({...d,[H]:m[0]===F?[]:[F]})):be(d=>({...d,[H]:m.includes(F)?m.filter(o=>o!==F):[...m,F]}))};return e.jsx("div",{className:ae(x.colSpan),children:ke(e.jsxs("div",{className:"space-y-1.5",children:[x.label&&e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:x.displayText||x.label}),(x.options||[]).map(F=>e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:m.includes(F.value),onChange:()=>C(F.value),style:{width:16,height:16,flexShrink:0,marginTop:2,accentColor:"var(--metakyc-primary, #6366f1)"}}),e.jsx("span",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)"},children:F.label})]},F.value))]}),x.helpText)},K)}return x.customType==="radio_group"?e.jsx("div",{className:ae(x.colSpan),children:ke(e.jsxs("div",{className:"space-y-1.5",children:[x.label&&e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:x.displayText||x.label}),(x.options||[]).map(m=>e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"radio",name:`rg-${H}`,value:m.value,checked:Z===m.value,onChange:()=>be(C=>({...C,[H]:m.value})),style:{width:16,height:16,flexShrink:0,marginTop:2,accentColor:"var(--metakyc-primary, #6366f1)"}}),e.jsx("span",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)"},children:m.label})]},m.value))]}),x.helpText)},K):e.jsx("div",{className:ae(x.colSpan),children:ke(e.jsx(ye,{label:x.displayText||x.label||H,value:String(Z??""),onChange:m=>be(C=>({...C,[H]:m.target.value}))}),x.helpText)},K)},Ze=(x,D)=>{if(x.isCustom)return Oe(x,D);const K=x.name??"",H=Ye[K],Z=x.displayText||(H==null?void 0:H.label)||K,m=ge[K]??"",C=K==="mobileCountryCode",F=!!(H!=null&&H.countriesType)&&!C;return x.editable?C?e.jsx("div",{className:ae(x.colSpan??2),children:ke(e.jsx(Me,{label:Z,value:String(m),onChange:d=>le(o=>({...o,[K]:d})),options:[{value:"",label:"Select country code…"},...U]}),x.helpText)},`epc-${D}`):F?e.jsx("div",{className:ae(x.colSpan??2),children:ke(e.jsx(Me,{label:Z,value:String(m),onChange:d=>le(o=>({...o,[K]:d})),options:[{value:"",label:`Select ${Z.toLowerCase()}…`},...L]}),x.helpText)},`ec-${D}`):e.jsx("div",{className:ae(x.colSpan??2),children:ke(e.jsx(ye,{label:Z,type:(H==null?void 0:H.type)==="date"?"date":(H==null?void 0:H.type)==="email"?"email":"text",value:String(m),onChange:d=>le(o=>({...o,[K]:d.target.value}))}),x.helpText)},`ei-${D}`):e.jsx("div",{className:ae(x.colSpan??2),children:ke(e.jsxs(e.Fragment,{children:[e.jsx("label",{className:"block text-sm font-medium mb-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:Z}),e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)",minHeight:"1.5rem"},children:ve(K,m)})]}),x.helpText)},`ro-${D}`)};if(I){const x=I.title||"Review Your Information",D=I.subtitle||"Please review and confirm your information before starting identity verification";return e.jsx("form",{onSubmit:K=>{K.preventDefault(),N()},children:e.jsxs(X,{children:[e.jsxs(he,{children:[e.jsx("h2",{className:"text-lg font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:x}),e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:D})]}),e.jsx(ee,{children:e.jsx("div",{className:"grid grid-cols-4 gap-4",children:I.fields.map((K,H)=>Ze(K,H))})}),e.jsxs(fe,{className:"flex justify-between",children:[s&&e.jsx(G,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(G,{type:"submit",isLoading:T,children:"Confirm and Start Verification"})]})]})})}return e.jsx("form",{onSubmit:$.handleSubmit(N),children:e.jsxs(X,{children:[e.jsxs(he,{children:[e.jsx("h2",{className:"text-lg font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Review Your Information"}),e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Please review and confirm your information before starting identity verification"})]}),e.jsxs(ee,{className:"space-y-6",children:[e.jsx("div",{className:"space-y-4 pb-4",style:{borderBottom:"1px solid var(--metakyc-border, #e5e7eb)"},children:[{label:"Name",value:`${((Qe=M==null?void 0:M.applicantRequestData)==null?void 0:Qe.firstName)||""} ${((ze=M==null?void 0:M.applicantRequestData)==null?void 0:ze.lastName)||""}`.trim()},{label:"Email",value:(Xe=M==null?void 0:M.applicantRequestData)==null?void 0:Xe.email},{label:"Date of Birth",value:((We=M==null?void 0:M.applicantRequestData)==null?void 0:We.dateOfBirth)||"Not provided"}].map(({label:x,value:D})=>e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:x}),e.jsx("p",{className:"mt-1 text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:D})]},x))}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Address Information"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Ke.Controller,{control:$.control,name:"country",render:({field:x})=>e.jsx(Me,{label:"Country",value:x.value,onChange:x.onChange,options:[{value:"",label:"Select country…"},...L]})}),e.jsx(Ke.Controller,{control:$.control,name:"nationality",render:({field:x})=>e.jsx(Me,{label:"Nationality",value:x.value,onChange:x.onChange,options:[{value:"",label:"Select nationality…"},...L]})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Ke.Controller,{control:$.control,name:"street",render:({field:x})=>e.jsx(ye,{...x,label:"Street"})}),e.jsx(Ke.Controller,{control:$.control,name:"streetNumber",render:({field:x})=>e.jsx(ye,{...x,label:"Street Number"})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Ke.Controller,{control:$.control,name:"city",render:({field:x})=>e.jsx(ye,{...x,label:"City"})}),e.jsx(Ke.Controller,{control:$.control,name:"zip",render:({field:x})=>e.jsx(ye,{...x,label:"ZIP / Postal Code"})})]}),e.jsx(Ke.Controller,{control:$.control,name:"phonenumber",render:({field:x})=>e.jsx(ye,{...x,label:"Phone Number",type:"tel"})})]})]}),e.jsxs(fe,{className:"flex justify-between",children:[s&&e.jsx(G,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(G,{type:"submit",isLoading:T,children:"Confirm and Start Verification"})]})]})})},ht=({kycStatus:t,reviewStatus:r,workflowResult:s,customMessage:n,onContinue:a,onContactSupport:l})=>{const u=t===qe.Approved?{type:"success",title:"Verification Approved",icon:"✓",iconBg:"bg-green-100 dark:bg-green-900/30",iconColor:"text-green-600 dark:text-green-400",message:"Your identity verification has been successfully approved."}:t===qe.Rejected?{type:"error",title:"Verification Rejected",icon:"✕",iconBg:"bg-red-100 dark:bg-red-900/30",iconColor:"text-red-600 dark:text-red-400",message:"Unfortunately, your identity verification was not approved."}:t===qe.Pending||t===qe.InProgress?{type:"pending",title:"Verification Pending",icon:"⏱",iconBg:"bg-blue-100 dark:bg-blue-900/30",iconColor:"text-blue-600 dark:text-blue-400",message:"Your identity verification is currently being processed."}:r===Ve.Approved?{type:"success",title:"Application Approved",icon:"✓",iconBg:"bg-green-100 dark:bg-green-900/30",iconColor:"text-green-600 dark:text-green-400",message:"Your application has been approved."}:r===Ve.Reject?{type:"error",title:"Application Rejected",icon:"✕",iconBg:"bg-red-100 dark:bg-red-900/30",iconColor:"text-red-600 dark:text-red-400",message:"Your application has been rejected."}:r===Ve.UnderReview||r===Ve.AdminReview?{type:"pending",title:"Under Review",icon:"📋",iconBg:"bg-yellow-100 dark:bg-yellow-900/30",iconColor:"text-yellow-700 dark:text-yellow-400",message:"Your application is currently under manual review."}:s===it.Success?{type:"success",title:"Process Complete",icon:"✓",iconBg:"bg-green-100 dark:bg-green-900/30",iconColor:"text-green-600 dark:text-green-400",message:"Your verification process has been completed successfully."}:s===it.Failed?{type:"error",title:"Process Failed",icon:"✕",iconBg:"bg-red-100 dark:bg-red-900/30",iconColor:"text-red-600 dark:text-red-400",message:"The verification process could not be completed."}:s===it.AdminReview?{type:"pending",title:"Admin Review Required",icon:"📋",iconBg:"bg-yellow-100 dark:bg-yellow-900/30",iconColor:"text-yellow-700 dark:text-yellow-400",message:"Your application requires administrator review."}:{type:"pending",title:"Processing",icon:"⏱",iconBg:"bg-blue-100 dark:bg-blue-900/30",iconColor:"text-blue-600 dark:text-blue-400",message:"Your application is being reviewed."};return e.jsxs(X,{children:[e.jsxs(ee,{className:"py-12",children:[e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx("div",{className:`w-24 h-24 rounded-full flex items-center justify-center ${u.iconBg}`,children:e.jsx("span",{className:`text-5xl ${u.iconColor}`,children:u.icon})})}),e.jsx("h2",{className:"text-3xl font-bold text-center mb-4",style:{color:"var(--metakyc-text-primary, #111827)"},children:u.title}),e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx(vt,{variant:u.type==="success"?"success":u.type==="error"?"danger":u.type==="pending"?"warning":"info",children:t!=null?qe[t]:Ve[r]})}),e.jsx("p",{className:"text-center mb-6 max-w-md mx-auto",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:n||u.message}),u.type==="success"&&e.jsxs("div",{className:"bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg p-4 mb-6",children:[e.jsx("h3",{className:"font-semibold text-green-900 dark:text-green-100 mb-2",children:"What's Next?"}),e.jsxs("ul",{className:"text-sm text-green-800 dark:text-green-200 space-y-1",children:[e.jsx("li",{children:"✓ Your identity has been verified"}),e.jsx("li",{children:"✓ You can now proceed with your application"}),e.jsx("li",{children:"✓ All features are now accessible"})]})]}),u.type==="error"&&e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 mb-6",children:[e.jsx("h3",{className:"font-semibold text-red-900 dark:text-red-100 mb-2",children:"What Can You Do?"}),e.jsxs("ul",{className:"text-sm text-red-800 dark:text-red-200 space-y-2",children:[e.jsx("li",{children:"• Review the requirements and ensure all information is correct"}),e.jsx("li",{children:"• Contact our support team for assistance"}),e.jsx("li",{children:"• You may be able to resubmit your application"})]})]}),u.type==="pending"&&e.jsxs("div",{className:"bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-4 mb-6",children:[e.jsx("h3",{className:"font-semibold text-blue-900 dark:text-blue-100 mb-2",children:"What Happens Next?"}),e.jsxs("ul",{className:"text-sm text-blue-800 dark:text-blue-200 space-y-2",children:[e.jsx("li",{children:"• Our team is reviewing your information"}),e.jsx("li",{children:"• You will be notified via email once the review is complete"}),e.jsx("li",{children:"• This typically takes 24-48 hours"}),e.jsx("li",{children:"• No action is required from you at this time"})]})]}),e.jsx("div",{className:"mt-6 pt-6",style:{borderTop:"1px solid var(--metakyc-border, #e5e7eb)"},children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"KYC Status:"}),e.jsx("div",{className:"font-medium mt-1",style:{color:"var(--metakyc-text-primary, #111827)"},children:t!=null?qe[t]:"Not Available"})]}),e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"Review Status:"}),e.jsx("div",{className:"font-medium mt-1",style:{color:"var(--metakyc-text-primary, #111827)"},children:Ve[r]})]})]})})]}),e.jsxs(fe,{className:"flex justify-center gap-4",children:[u.type==="success"&&a&&e.jsx(G,{onClick:a,size:"lg",children:"Continue"}),u.type==="error"&&e.jsxs(e.Fragment,{children:[l&&e.jsx(G,{variant:"outline",onClick:l,children:"Contact Support"}),a&&e.jsx(G,{onClick:a,children:"Try Again"})]}),u.type==="pending"&&e.jsx("div",{className:"text-center",children:e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Please check back later or wait for our email notification"})})]})]})},$r=({config:t,className:r=""})=>!(t!=null&&t.visible)||!(t!=null&&t.url)?null:e.jsx("div",{className:`metakyc-logo ${r}`,children:e.jsx("img",{src:t.url,alt:t.alt||"Company Logo",style:{width:t.width||"auto",height:t.height||"40px",maxWidth:"100%",objectFit:"contain"},onError:s=>{console.warn("[Logo] Failed to load logo:",t.url),s.target.style.display="none"}})}),st=({title:t,subtitle:r,className:s=""})=>{const{currentTheme:n}=Ne(),a=t||(n==null?void 0:n.title)||"",l=!!(n!=null&&n.logo&&n.logo.visible&&n.logo.url),c=!!a;return!l&&!c?null:e.jsxs("div",{className:`metakyc-header ${s}`,children:[e.jsxs("div",{className:"metakyc-header-title flex items-center text-xl font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:[l&&e.jsx($r,{config:n.logo}),l&&c&&e.jsx("span",{style:{fontSize:"1.5rem",fontWeight:300,color:"var(--metakyc-text-muted, #9ca3af)",margin:"0 12px"},children:"|"}),c&&e.jsx("span",{style:{color:"var(--metakyc-text-primary, #111827)"},children:a})]}),r&&e.jsx("p",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:r})]})},ct=["firstName","lastName","email","phonenumber","dateOfBirth"];function et(t){return t==null||t===""||Array.isArray(t)&&t.length===0}const at={width:"16px",height:"16px",minWidth:"16px",flexShrink:0,flexGrow:0,accentColor:"var(--metakyc-primary, #2563eb)",cursor:"pointer",margin:0,padding:0,display:"inline-block",verticalAlign:"middle"},Rt=({helpText:t,children:r})=>{const[s,n]=i.useState(!1);if(!t)return e.jsx(e.Fragment,{children:r});const a=s?e.jsx("div",{role:"dialog","aria-modal":"true",onClick:()=>n(!1),style:{position:"fixed",inset:0,zIndex:999999,background:"rgba(0, 0, 0, 0.55)",backdropFilter:"blur(6px)",WebkitBackdropFilter:"blur(6px)",display:"flex",alignItems:"center",justifyContent:"center",padding:"16px"},children:e.jsxs("div",{onClick:l=>l.stopPropagation(),style:{background:"var(--metakyc-surface, var(--metakyc-background, #ffffff))",border:"1px solid var(--metakyc-border, #e5e7eb)",borderRadius:"12px",padding:"28px 24px 24px",maxWidth:"480px",width:"100%",maxHeight:"80vh",overflowY:"auto",boxShadow:"0 24px 64px rgba(0,0,0,0.4)",position:"relative"},children:[e.jsx("button",{type:"button",onClick:()=>n(!1),"aria-label":"Close",style:{position:"absolute",top:"12px",right:"12px",width:"28px",height:"28px",borderRadius:"50%",border:"1px solid var(--metakyc-border, #e5e7eb)",background:"var(--metakyc-input-bg, #f3f4f6)",color:"var(--metakyc-text-secondary, #6b7280)",fontSize:"16px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:"×"}),e.jsx("div",{style:{color:"var(--metakyc-text-primary, #111827)",fontSize:"14px",lineHeight:1.75},dangerouslySetInnerHTML:{__html:t}})]})}):null;return e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"5px",flexWrap:"nowrap"},children:[r,e.jsx("button",{type:"button",className:"metakyc-help-btn",onClick:()=>n(!0),"aria-label":"Help",style:{flexShrink:0,marginTop:"2px",width:"18px",height:"18px",borderRadius:"50%",border:"1.5px solid var(--metakyc-primary, #2563eb)",background:"transparent",color:"var(--metakyc-primary, #2563eb)",fontSize:"10px",fontWeight:"700",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,padding:0,position:"relative",zIndex:2,transition:"background 0.15s, color 0.15s"},onMouseEnter:l=>{l.currentTarget.style.background="var(--metakyc-primary, #2563eb)",l.currentTarget.style.color="#ffffff"},onMouseLeave:l=>{l.currentTarget.style.background="transparent",l.currentTarget.style.color="var(--metakyc-primary, #2563eb)"},children:"?"}),typeof document<"u"&&a?ut.createPortal(a,document.body):null]})},Rs=({workflowKey:t,externalRefId:r,onSuccess:s,onCancel:n})=>{var K,H,Z,m,C,F,d;const{config:a,baseInformationService:l,currentTheme:c}=Ne(),{createApplicant:u,isLoading:y}=bt(),p=t||((K=a.applicantForm)==null?void 0:K.workflowKey);if(!p)throw new Error("workflowKey is required. Provide it either as a prop to CreateApplicantForm or set it in config.applicantForm.workflowKey");const b=r||((H=a.applicantForm)==null?void 0:H.externalRefId)||"",T=((Z=a.applicantForm)==null?void 0:Z.email)||"",v=((m=a.applicantForm)==null?void 0:m.hiddenValues)||{},E=((C=a.applicantForm)==null?void 0:C.initialValues)||{},k=(((F=a.applicantForm)==null?void 0:F.fieldLabelMode)||(c==null?void 0:c.fieldLabelMode)||"label")!=="placeholder",S=i.useMemo(()=>c!=null&&c.applicantFormPages&&c.applicantFormPages.length>0?c.applicantFormPages:null,[c==null?void 0:c.applicantFormPages]),M=i.useMemo(()=>{const o=new Set(ct),h=c==null?void 0:c.applicantFormRequiredFields;if(h)for(const P of h)o.add(P);if(S)for(const P of S)for(const f of P.fields)!f.isCustom&&f.name&&f.required&&o.add(f.name);return Array.from(o)},[c==null?void 0:c.applicantFormRequiredFields,S]),Y=i.useMemo(()=>{var P;if(S){const f=S.flatMap(j=>j.fields).filter(j=>!j.isCustom&&j.name).map(j=>j.name),w=new Set(f);for(const j of ct)w.add(j);return Array.from(w)}let o;(P=a.applicantForm)!=null&&P.visibleFields?o=a.applicantForm.visibleFields:c!=null&&c.applicantFormVisibleFields&&c.applicantFormVisibleFields.length>0?o=c.applicantFormVisibleFields:o=$t;const h=new Set(o);for(const f of ct)h.add(f);return Array.from(h)},[(d=a.applicantForm)==null?void 0:d.visibleFields,c==null?void 0:c.applicantFormVisibleFields,S]),L=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),_=i.useMemo(()=>{var h,P;const o=new Set;if(S)for(const f of S)for(const w of f.fields)!w.isCustom&&w.name&&L.has(w.name)&&o.add(w.countriesType??((h=Ye[w.name])==null?void 0:h.countriesType));else for(const f of Y)L.has(f)&&o.add((P=Ye[f])==null?void 0:P.countriesType);return o.size===0&&o.add(void 0),Array.from(o)},[Y,S]),[U,te]=i.useState({}),[R,g]=i.useState(!0),O=i.useRef(new Set),q=i.useRef(new Set);i.useEffect(()=>{if(!c)return;const o=_.filter(f=>{const w=f!=null?String(f):"all";return!q.current.has(w)&&!O.current.has(w)});if(o.length===0){_.every(w=>{const j=w!=null?String(w):"all";return q.current.has(j)})&&g(!1);return}g(!0);const h=o.map(f=>f!=null?String(f):"all");h.forEach(f=>O.current.add(f)),(async()=>{try{const f=await Promise.all(o.map(async w=>{const j=w!=null?String(w):"all",ce=await l.getCountries("",a.locale||"en",w),se=w===40,xe=new Set,Ie=ce.map(ie=>se&&ie.countryCode?{value:ie.countryCode,label:`${ie.countryCode} – ${ie.name}`}:{value:ie.abbreviation3||ie.abbreviation,label:ie.name}).filter(ie=>!ie.value||xe.has(ie.value)?!1:(xe.add(ie.value),!0));return q.current.add(j),O.current.delete(j),[j,Ie]}));te(w=>({...w,...Object.fromEntries(f)}))}catch(f){h.forEach(w=>O.current.delete(w)),console.error("Failed to load countries:",f)}finally{_.every(w=>{const j=w!=null?String(w):"all";return q.current.has(j)})&&g(!1)}})()},[_,c]);const Q=(o,h)=>{var w;const P=h??((w=Ye[o])==null?void 0:w.countriesType),f=P!=null?String(P):"all";return U[f]||[]},B={firstName:1,lastName:1,title:1,email:1,dateOfBirth:1,phonenumber:1,mobileCountryCode:1,street:1,streetNumber:1,zip:1,city:1,country:1,nationality:1,otherNationality:1,defaultLanguage:1,taxCountry:1,placeOfBirth:1,countryOfBirth:1,salutation:1,educationLevel:1,occupation:1,taxNumber:1},J=Object.fromEntries(Object.entries(v).filter(([o])=>o in B)),ne=Object.fromEntries(Object.entries(E).filter(([o])=>o in B)),[V,ge]=i.useState({workflowKey:p,firstName:"",lastName:"",title:"",email:T,dateOfBirth:"",phonenumber:"",externalRefId:b,mobileCountryCode:"",street:"",streetNumber:"",zip:"",city:"",country:"",nationality:"",otherNationality:[],defaultLanguage:"EN",taxCountry:"",placeOfBirth:"",countryOfBirth:"",salutation:null,educationLevel:"",occupation:"",taxNumber:"",...J,...ne}),le=Object.fromEntries(Object.entries(v).filter(([o])=>!(o in J)&&o!=="externalRefId"&&o!=="workflowKey")),[de,be]=i.useState({...le}),[I,W]=i.useState(0),[z,$]=i.useState({}),[me,N]=i.useState(null),[re,ue]=i.useState(!1),ae=(o,h)=>ge(P=>({...P,[o]:h})),ve=(o,h)=>be(P=>({...P,[o]:h})),Te=o=>!o.conditionalOn||de[o.conditionalOn]==="true",ke=S&&I<S.length-1?I+1:-1,Oe=S&&I>0?I-1:-1,Ze=o=>{var P;const h={};for(const f of o.fields)if(f.isCustom){if(f.customType==="paragraph"||f.customType==="html"||f.customType==="br"||f.customType==="link")continue;if(f.required&&f.paramName){const w=de[f.paramName],j=f.displayText||f.label||f.paramName;f.customType==="checkbox"||f.customType==="link_checkbox"?w!=="true"&&(h[f.paramName]=`${j} is required.`):(!w||w.trim()==="")&&(h[f.paramName]=`${j} is required.`)}}else if(f.name){const w=f.name;if(M.includes(w)&&et(V[w])){const j=f.displayText||((P=Ye[w])==null?void 0:P.label)||w;h[w]=`${j} is required.`}}return h},Qe=async()=>{if(!S)return;const o=S[I];if(o.conditionalOn&&!Te(o)){$({}),ke>=0?W(ke):await ze();return}const h=Ze(o);if(Object.keys(h).length>0){$(h);return}$({}),ke>=0?W(ke):await ze()},ze=async()=>{if(S){let o={};for(const h of S)Te(h)&&(o={...o,...Ze(h)});if(Object.keys(o).length>0){$(o);return}}ue(!0),N(null);try{if(!V.externalRefId||V.externalRefId.trim()===""){N("External Reference ID is required. Please pass it via config.applicantForm.externalRefId.");return}const o={workflowKey:V.workflowKey,externalRefId:V.externalRefId.trim()};if(S){for(const w of S)if(Te(w)){for(const j of w.fields)if(!j.isCustom&&j.name){const ce=j.name,se=V[ce];et(se)||(o[ce]=se)}}for(const w of ct)if(o[w]===void 0){const j=V[w];et(j)||(o[w]=j)}}else Y.forEach(w=>{if(w==="externalRefId")return;const j=V[w];et(j)||(o[w]=j)});const h=[];if(S){for(const w of S)if(Te(w))for(const j of w.fields){if(!j.isCustom||!j.paramName||j.customType==="paragraph"||j.customType==="html"||j.customType==="br"||j.customType==="link")continue;const ce=de[j.paramName]??"";let se;if(j.customType==="checkbox"||j.customType==="link_checkbox")se=ce==="true"?"yes":"no";else if(se=ce,!se&&!j.required)continue;h.push({paramName:j.paramName,value:se})}}for(const[w,j]of Object.entries(J))o[w]===void 0&&!et(j)&&(o[w]=j);const P=new Set(h.map(w=>w.paramName));for(const[w,j]of Object.entries(le))!P.has(w)&&j&&h.push({paramName:w,value:j});h.length>0&&(o.applicantAdditionalDatas=h);const f=await u(o);s(f.applicantId)}catch(o){console.error("Error creating applicant:",o),N(o.message||"Failed to create applicant")}finally{ue(!1)}},Xe=async o=>{var h;o.preventDefault();for(const P of M)if(et(V[P])){const f=((h=Ye[P])==null?void 0:h.label)||P;N(`${f} is required.`);return}await ze()},We=(o,h,P,f,w)=>{var kt;const j=Ye[o];if(!j)return null;const ce=M.includes(o),se=z[o],xe=P||j.label,Ie=o in ne,ie=h??o,Pe={required:ce},Be=w?w!=="placeholder":k,Ue=Be?xe:void 0,Hr=Be?"...":xe;switch(j.type){case"select":if(o==="country"||o==="nationality"||o==="taxCountry"||o==="countryOfBirth"||o==="mobileCountryCode"){const Ce=Q(o,f);return e.jsx(Me,{...Pe,label:Ue,value:V[o]||"",onChange:Ge=>ae(o,Ge),options:[{value:"",label:`Select ${Hr.toLowerCase()}`},...Ce],disabled:R,readOnly:Ie,error:se},ie)}if(o==="salutation")return e.jsx(Me,{...Pe,label:Ue,value:((kt=V[o])==null?void 0:kt.toString())||"",onChange:Ce=>ae(o,Ce?Number(Ce):null),options:[{value:"",label:Be?"Select salutation...":xe},{value:ot.Male.toString(),label:"Male"},{value:ot.Female.toString(),label:"Female"},{value:ot.Other.toString(),label:"Other"}],readOnly:Ie,error:se},ie);if(o==="defaultLanguage"){const Ce=c!=null&&c.allowedLanguages&&c.allowedLanguages.length>0?xt.filter(Ge=>c.allowedLanguages.includes(Ge.value)):xt;return e.jsx(Me,{...Pe,label:Ue,value:V[o]||"",onChange:Ge=>ae(o,Ge),options:[{value:"",label:Be?"Select language...":xe},...Ce],readOnly:Ie,error:se},ie)}return null;case"multiselect":if(o==="otherNationality"){const Ce=Q(o,f);return e.jsx(Rr,{...Pe,label:Ue,value:V[o]||[],onChange:Ge=>ae(o,Ge),options:Ce,placeholder:Be?"Select other nationalities...":xe,disabled:R,readOnly:Ie},ie)}return null;case"date":return e.jsx(ye,{...Pe,type:"date",label:Ue,placeholder:Be?void 0:xe,value:V[o]||"",onChange:Ce=>ae(o,Ce.target.value),readOnly:Ie,error:se},ie);case"email":return e.jsx(ye,{...Pe,type:"email",label:Ue,placeholder:Be?void 0:xe,value:V[o]||"",onChange:Ce=>ae(o,Ce.target.value),readOnly:Ie,error:se},ie);case"tel":return e.jsx(ye,{...Pe,type:"tel",label:Ue,placeholder:Be?void 0:xe,value:V[o]||"",onChange:Ce=>ae(o,Ce.target.value),readOnly:Ie,error:se},ie);default:return e.jsx(ye,{...Pe,type:"text",label:Ue,placeholder:Be?void 0:xe,value:V[o]||"",onChange:Ce=>ae(o,Ce.target.value),readOnly:Ie,error:se},ie)}},x=(o,h)=>{const P=o.labelMode?o.labelMode!=="placeholder":k;if(o.customType==="paragraph"){const j=o.displayText||o.label||"";return e.jsx("p",{className:"metakyc-paragraph",style:{fontSize:"14px",lineHeight:"1.7",margin:0,color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:j}},`custom-${h}`)}if(o.customType==="html")return e.jsx("div",{dangerouslySetInnerHTML:{__html:o.label||""}},`custom-${h}`);if(o.customType==="br")return e.jsx("div",{style:{height:"12px"}},`custom-${h}`);if(o.customType==="link"){const j=o.displayText||o.label||o.linkText||o.linkUrl||"";return e.jsx("div",{className:"metakyc-link-field",children:e.jsxs("a",{href:o.linkUrl||"#",target:"_blank",rel:"noopener noreferrer",style:{display:"inline-flex",alignItems:"center",gap:"4px",color:"var(--metakyc-primary, #2563eb)",fontSize:"14px",textDecoration:"underline",cursor:"pointer"},children:[j,e.jsx("span",{style:{fontSize:"10px",opacity:.7},children:"↗"})]})},`custom-${h}`)}if(!o.paramName)return null;const f=z[o.paramName],w=o.displayText||o.label||o.paramName;if(o.customType==="checkbox")return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"checkbox",checked:de[o.paramName]==="true",onChange:j=>ve(o.paramName,j.target.checked?"true":"false"),className:"metakyc-option-input",style:at}),e.jsxs("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:[w,o.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),f&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:f})]},`custom-${h}`);if(o.customType==="link_checkbox")return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"checkbox",checked:de[o.paramName]==="true",onChange:j=>ve(o.paramName,j.target.checked?"true":"false"),className:"metakyc-option-input",style:{...at,alignSelf:"flex-start",marginTop:"2px"}}),e.jsxs("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:[w," ",o.linkUrl&&e.jsx("a",{href:o.linkUrl,target:"_blank",rel:"noopener noreferrer",className:"underline",style:{color:"var(--metakyc-primary, #2563eb)"},onClick:j=>j.stopPropagation(),children:o.linkText||o.linkUrl}),o.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),f&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:f})]},`custom-${h}`);if(o.customType==="group_checkbox"){const j=(de[o.paramName]||"").split(",").filter(Boolean);return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[P&&e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[w,o.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]}),e.jsx("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:(o.options||[]).map(ce=>{const se=o.singleSelect?de[o.paramName]===ce.value:j.includes(ce.value);return e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"checkbox",checked:se,onChange:xe=>{if(o.singleSelect)ve(o.paramName,xe.target.checked?ce.value:"");else{const Ie=xe.target.checked?[...j,ce.value]:j.filter(ie=>ie!==ce.value);ve(o.paramName,Ie.join(","))}},className:"metakyc-option-input",style:at}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:ce.label})]},ce.value)})}),f&&e.jsx("p",{className:"text-red-500 text-xs",children:f})]},`custom-${h}`)}return o.customType==="radio_group"?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[P&&e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[w,o.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]}),e.jsx("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:(o.options||[]).map(j=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"radio",checked:de[o.paramName]===j.value,onChange:()=>ve(o.paramName,j.value),name:`radio-group-${o.paramName}-${h}`,className:"metakyc-option-input",style:at}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:j.label})]},j.value))}),f&&e.jsx("p",{className:"text-red-500 text-xs",children:f})]},`custom-${h}`):e.jsx(ye,{type:"text",label:P?`${w}${o.required?" *":""}`:void 0,placeholder:P?void 0:w,value:de[o.paramName]||"",onChange:j=>ve(o.paramName,j.target.value),required:o.required,error:f},`custom-${h}`)},D=(o,h)=>{const P=Te(o);return e.jsxs("div",{className:"space-y-4",children:[o.conditionalOn&&e.jsx(Rt,{helpText:o.conditionalHelpText,children:e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"checkbox",checked:P,onChange:f=>ve(o.conditionalOn,f.target.checked?"true":"false"),className:"metakyc-option-input",style:at}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",fontWeight:500},children:o.conditionalOn})]})}),P&&e.jsx("div",{className:"grid grid-cols-4 gap-4",children:o.fields.map((f,w)=>{const j=f.colSpan===1?"col-span-1":f.colSpan===2?"col-span-2":f.colSpan===3?"col-span-3":"col-span-4",ce=f.isCustom?`custom-${w}-${f.paramName}`:`builtin-${f.name}-${w}`;return e.jsx("div",{className:j,children:e.jsx(Rt,{helpText:f.helpText,children:f.isCustom?x(f,w):We(f.name,ce,f.displayText,f.countriesType,f.labelMode)})},ce)})})]})};if(!c||R)return e.jsx("div",{className:"metakyc-sdk",children:e.jsx(X,{children:e.jsxs(ee,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)",fontSize:"0.875rem"},children:"Loading form…"})]})})});if(S){const o=S[I]??S[0],h=Oe===-1,P=ke===-1,f=S.length,w=Te(o),j=Object.values(z);return e.jsx("div",{className:"metakyc-sdk",children:e.jsxs(X,{children:[e.jsx(he,{children:e.jsx(st,{title:(c==null?void 0:c.title)||"Create Applicant"})}),e.jsxs(ee,{children:[(o.title||o.subtitle||o.description)&&e.jsxs("div",{className:"mb-4",children:[o.title&&e.jsx("h3",{className:"font-semibold text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:o.title}),o.subtitle&&e.jsx("p",{className:"text-sm mt-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:o.subtitle}),o.description&&o.description!==o.subtitle&&e.jsx("p",{className:"text-xs mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:o.description})]}),(me||j.length>0)&&e.jsxs("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-lg",children:[me&&e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",me]}),j.map((ce,se)=>e.jsx("p",{className:"text-red-600 text-sm",children:ce},se))]}),f>1&&e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[S.map((ce,se)=>e.jsx("div",{className:`h-1.5 rounded-full transition-all ${se===I?"flex-1":"w-8"}`,style:se===I?{backgroundColor:"var(--metakyc-primary, #2563eb)"}:se<I?{backgroundColor:"var(--metakyc-primary-light, #93c5fd)",opacity:.7}:{backgroundColor:"#e5e7eb"}},se)),e.jsxs("span",{className:"text-xs text-gray-400 flex-shrink-0",children:[I+1," / ",f]})]}),D(o)]}),e.jsxs(fe,{className:"flex justify-between",children:[e.jsxs("div",{children:[!h&&e.jsx(G,{type:"button",variant:"outline",onClick:()=>{W(Oe),$({})},disabled:re||y,children:"Previous"}),h&&n&&e.jsx(G,{type:"button",variant:"outline",onClick:n,disabled:re||y,children:"Cancel"})]}),e.jsx(G,{type:"button",isLoading:re||y,onClick:P?ze:Qe,children:P?o.conditionalOn&&!w?"Skip & Submit":"Submit":o.conditionalOn&&!w?"Skip":"Next"})]})]})})}return e.jsx("div",{className:"metakyc-sdk",children:e.jsx("form",{onSubmit:Xe,children:e.jsxs(X,{children:[e.jsx(he,{children:e.jsx(st,{title:(c==null?void 0:c.title)||"Create Applicant"})}),e.jsxs(ee,{children:[me&&e.jsx("div",{className:"mb-6 p-4 bg-red-50 border border-red-200 rounded-lg",children:e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",me]})}),e.jsx("div",{className:"grid grid-cols-4 gap-4",children:Y.map(o=>e.jsx("div",{className:"col-span-4",children:We(o)},o))})]}),e.jsxs(fe,{className:"flex justify-between",children:[n&&e.jsx(G,{type:"button",variant:"outline",onClick:n,disabled:re||y,children:"Cancel"}),e.jsx(G,{type:"submit",isLoading:re||y,children:"Create Applicant"})]})]})})})},It=["companyName","email"];function yt(t){return t==null||t===""||Array.isArray(t)&&t.length===0}const Is=({workflowKey:t,externalRefId:r,onSuccess:s,onCancel:n})=>{var We,x,D,K,H,Z;const{config:a,baseInformationService:l,currentTheme:c}=Ne(),{createCompanyApplicant:u,isLoading:y}=bt(),p=t||((We=a.applicantForm)==null?void 0:We.workflowKey);if(!p)throw new Error("workflowKey is required. Provide it either as a prop to CreateCompanyApplicantForm or set it in config.applicantForm.workflowKey");const b=r||((x=a.applicantForm)==null?void 0:x.externalRefId)||"",T=((D=a.applicantForm)==null?void 0:D.email)||"",v=((K=a.applicantForm)==null?void 0:K.initialValues)||{},A=(((H=a.applicantForm)==null?void 0:H.fieldLabelMode)||(c==null?void 0:c.fieldLabelMode)||"label")!=="placeholder",k=i.useMemo(()=>c!=null&&c.companyFormPages&&c.companyFormPages.length>0?c.companyFormPages:null,[c==null?void 0:c.companyFormPages]),S=i.useMemo(()=>{const m=new Set(It),C=c==null?void 0:c.companyFormRequiredFields;if(C)for(const F of C)m.add(F);if(k)for(const F of k)for(const d of F.fields)!d.isCustom&&d.name&&d.required&&m.add(d.name);return Array.from(m)},[c==null?void 0:c.companyFormRequiredFields,k]),M=i.useMemo(()=>{var m;if(k){const C=k.flatMap(d=>d.fields).filter(d=>!d.isCustom&&d.name).map(d=>d.name),F=new Set(C);for(const d of It)F.add(d);return Array.from(F)}return(m=a.applicantForm)!=null&&m.visibleFields?a.applicantForm.visibleFields:c!=null&&c.companyFormVisibleFields&&c.companyFormVisibleFields.length>0?c.companyFormVisibleFields:_t},[(Z=a.applicantForm)==null?void 0:Z.visibleFields,c==null?void 0:c.companyFormVisibleFields,k]),Y=new Set(["countryResidence","addressCountry"]),L=i.useMemo(()=>{var C,F;const m=new Set;if(k)for(const d of k)for(const o of d.fields)!o.isCustom&&o.name&&Y.has(o.name)&&m.add(o.countriesType??((C=Je[o.name])==null?void 0:C.countriesType));else for(const d of M)Y.has(d)&&m.add((F=Je[d])==null?void 0:F.countriesType);return m.size===0&&m.add(void 0),Array.from(m)},[M,k]),[_,U]=i.useState({}),[te,R]=i.useState(!0),g=i.useRef(new Set),O=i.useRef(new Set);i.useEffect(()=>{if(!c)return;const m=L.filter(d=>{const o=d!=null?String(d):"all";return!O.current.has(o)&&!g.current.has(o)});if(m.length===0){L.every(o=>O.current.has(o!=null?String(o):"all"))&&R(!1);return}R(!0);const C=m.map(d=>d!=null?String(d):"all");C.forEach(d=>g.current.add(d)),(async()=>{try{const d=await Promise.all(m.map(async o=>{const h=o!=null?String(o):"all",P=await l.getCountries("",a.locale||"en",o),f=new Set,w=P.map(j=>({value:j.abbreviation3||j.abbreviation,label:j.name})).filter(j=>!j.value||f.has(j.value)?!1:(f.add(j.value),!0));return O.current.add(h),g.current.delete(h),[h,w]}));U(o=>({...o,...Object.fromEntries(d)}))}catch(d){C.forEach(o=>g.current.delete(o)),console.error("Failed to load countries:",d)}finally{L.every(o=>O.current.has(o!=null?String(o):"all"))&&R(!1)}})()},[L,c]);const q=(m,C)=>{var o;const F=C??((o=Je[m])==null?void 0:o.countriesType),d=F!=null?String(F):"all";return _[d]||[]},Q={companyName:1,registrationNumber:1,email:1,phone:1,countryResidence:1,legalAddress:1,incorporatedOn:1,controlScheme:1,taxId:1,registrationLocation:1,website:1,postalAddress:1,street:1,streetNumber:1,city:1,state:1,postalCode:1,addressCountry:1,lei:1},B=Object.fromEntries(Object.entries(v).filter(([m])=>m in Q)),[J,ne]=i.useState({workflowKey:p,companyName:"",email:T,phone:"",registrationNumber:"",countryResidence:"",legalAddress:"",incorporatedOn:"",controlScheme:"",taxId:"",registrationLocation:"",website:"",postalAddress:"",street:"",streetNumber:"",city:"",state:"",postalCode:"",addressCountry:"",lei:"",externalRefId:b,...B}),[V,ge]=i.useState({}),[le,de]=i.useState(0),[be,I]=i.useState({}),[W,z]=i.useState(null),[$,me]=i.useState(!1),N=(m,C)=>ne(F=>({...F,[m]:C})),re=(m,C)=>ge(F=>({...F,[m]:C})),ue=m=>!m.conditionalOn||V[m.conditionalOn]==="true",ae=k&&le<k.length-1?le+1:-1,ve=k&&le>0?le-1:-1,Te=m=>{var F;const C={};for(const d of m.fields)if(d.isCustom){if(d.customType==="paragraph"||d.customType==="html"||d.customType==="br"||d.customType==="link")continue;if(d.required&&d.paramName){const o=V[d.paramName],h=d.displayText||d.label||d.paramName;d.customType==="checkbox"||d.customType==="link_checkbox"?o!=="true"&&(C[d.paramName]=`${h} is required.`):(!o||o.trim()==="")&&(C[d.paramName]=`${h} is required.`)}}else if(d.name){const o=d.name;if(S.includes(o)&&yt(J[o])){const h=d.displayText||((F=Je[o])==null?void 0:F.label)||o;C[o]=`${h} is required.`}}return C},ke=async()=>{if(!k)return;const m=k[le];if(m.conditionalOn&&!ue(m)){I({}),ae>=0?de(ae):await Oe();return}const C=Te(m);if(Object.keys(C).length>0){I(C);return}I({}),ae>=0?de(ae):await Oe()},Oe=async()=>{var m;if(k){let C={};for(const F of k)ue(F)&&(C={...C,...Te(F)});if(Object.keys(C).length>0){I(C);return}}me(!0),z(null);try{const C={workflowKey:J.workflowKey,externalRefId:((m=J.externalRefId)==null?void 0:m.trim())||void 0},F=k?k.filter(h=>ue(h)).flatMap(h=>h.fields).filter(h=>!h.isCustom&&h.name).map(h=>h.name):M;for(const h of F){const P=J[h];if(!yt(P))switch(h){case"companyName":C.companyName=P;break;case"email":C.companyEmail=P;break;case"phone":C.companyPhone=P;break;case"registrationNumber":C.companyRegistrationNumber=P;break;case"countryResidence":C.companyCountry=P;break;case"city":C.companyCity=P;break;case"street":C.companyStreet=P;break;case"postalCode":C.companyZip=P;break;default:C[h]=P;break}}const d=[];if(k){for(const h of k)if(ue(h))for(const P of h.fields){if(!P.isCustom||!P.paramName||P.customType==="paragraph"||P.customType==="html"||P.customType==="br"||P.customType==="link")continue;const f=V[P.paramName]??"";let w;if(P.customType==="checkbox"||P.customType==="link_checkbox")w=f==="true"?"yes":"no";else if(w=f,!w&&!P.required)continue;d.push({paramName:P.paramName,value:w})}}d.length>0&&(C.applicantAdditionalDatas=d);const o=await u(C);s(o.applicantId)}catch(C){console.error("Error creating company applicant:",C),z(C.message||"Failed to create company applicant")}finally{me(!1)}},Ze=async m=>{var C;m.preventDefault();for(const F of S)if(yt(J[F])){const d=((C=Je[F])==null?void 0:C.label)||F;z(`${d} is required.`);return}await Oe()},Qe=(m,C,F,d,o)=>{const h=Je[m];if(!h)return null;const P=S.includes(m),f=be[m],w=F||h.label,j=m in B,ce=C??m,se=o?o!=="placeholder":A,xe=se?w:void 0,Ie=se?"...":w;switch(h.type){case"select":if(m==="countryResidence"||m==="addressCountry"){const ie=q(m,d);return e.jsx(Me,{required:P,label:xe,value:J[m]||"",onChange:Pe=>N(m,Pe),options:[{value:"",label:`Select ${Ie.toLowerCase()}`},...ie],disabled:te,readOnly:j,error:f},ce)}return null;case"date":return e.jsx(ye,{required:P,type:"date",label:xe,placeholder:se?void 0:w,value:J[m]||"",onChange:ie=>N(m,ie.target.value),readOnly:j,error:f},ce);case"email":return e.jsx(ye,{required:P,type:"email",label:xe,placeholder:se?void 0:w,value:J[m]||"",onChange:ie=>N(m,ie.target.value),readOnly:j,error:f},ce);case"tel":return e.jsx(ye,{required:P,type:"tel",label:xe,placeholder:se?void 0:w,value:J[m]||"",onChange:ie=>N(m,ie.target.value),readOnly:j,error:f},ce);default:return e.jsx(ye,{required:P,type:"text",label:xe,placeholder:se?void 0:w,value:J[m]||"",onChange:ie=>N(m,ie.target.value),readOnly:j,error:f},ce)}},ze=(m,C)=>{if(m.customType==="paragraph")return e.jsx("p",{style:{fontSize:"14px",lineHeight:"1.7",margin:0,color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:m.displayText||m.label||""}},`custom-${C}`);if(m.customType==="html")return e.jsx("div",{dangerouslySetInnerHTML:{__html:m.label||""}},`custom-${C}`);if(m.customType==="br")return e.jsx("div",{style:{height:"12px"}},`custom-${C}`);if(m.customType==="link")return e.jsx("div",{children:e.jsx("a",{href:m.linkUrl||"#",target:"_blank",rel:"noopener noreferrer",style:{color:"var(--metakyc-primary, #2563eb)",fontSize:"14px",textDecoration:"underline"},children:m.displayText||m.label||m.linkText||m.linkUrl||""})},`custom-${C}`);if(!m.paramName)return null;const F=be[m.paramName],d=m.displayText||m.label||m.paramName,o=m.labelMode?m.labelMode!=="placeholder":A;return m.customType==="checkbox"?e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:V[m.paramName]==="true",onChange:h=>re(m.paramName,h.target.checked?"true":"false"),style:{width:"16px",height:"16px",accentColor:"var(--metakyc-primary, #2563eb)"}}),e.jsxs("span",{style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)"},children:[d,m.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),F&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:F})]},`custom-${C}`):e.jsx(ye,{type:"text",label:o?`${d}${m.required?" *":""}`:void 0,placeholder:o?void 0:d,value:V[m.paramName]||"",onChange:h=>re(m.paramName,h.target.value),required:m.required,error:F},`custom-${C}`)},Xe=m=>{const C=ue(m);return e.jsxs("div",{className:"space-y-4",children:[m.conditionalOn&&e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:C,onChange:F=>re(m.conditionalOn,F.target.checked?"true":"false"),style:{width:"16px",height:"16px",accentColor:"var(--metakyc-primary, #2563eb)"}}),e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:m.conditionalOn})]}),C&&e.jsx("div",{className:"grid grid-cols-4 gap-4",children:m.fields.map((F,d)=>{const o=F.colSpan===1?"col-span-1":F.colSpan===2?"col-span-2":F.colSpan===3?"col-span-3":"col-span-4",h=F.isCustom?`custom-${d}-${F.paramName}`:`builtin-${F.name}-${d}`;return e.jsx("div",{className:o,children:F.isCustom?ze(F,d):Qe(F.name,h,F.displayText,F.countriesType,F.labelMode)},h)})})]})};if(!c||te)return e.jsx("div",{className:"metakyc-sdk",children:e.jsx(X,{children:e.jsxs(ee,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)",fontSize:"0.875rem"},children:"Loading form…"})]})})});if(k){const m=k[le]??k[0],C=ve===-1,F=ae===-1,d=k.length,o=ue(m),h=Object.values(be);return e.jsx("div",{className:"metakyc-sdk",children:e.jsxs(X,{children:[e.jsx(he,{children:e.jsx(st,{title:(c==null?void 0:c.title)||"Company Registration"})}),e.jsxs(ee,{children:[(m.title||m.subtitle)&&e.jsxs("div",{className:"mb-4",children:[m.title&&e.jsx("h3",{className:"font-semibold text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:m.title}),m.subtitle&&e.jsx("p",{className:"text-sm mt-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:m.subtitle})]}),(W||h.length>0)&&e.jsxs("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-lg",children:[W&&e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",W]}),h.map((P,f)=>e.jsx("p",{className:"text-red-600 text-sm",children:P},f))]}),d>1&&e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[k.map((P,f)=>e.jsx("div",{className:`h-1.5 rounded-full transition-all ${f===le?"flex-1":"w-8"}`,style:f===le?{backgroundColor:"var(--metakyc-primary, #2563eb)"}:f<le?{backgroundColor:"var(--metakyc-primary-light, #93c5fd)",opacity:.7}:{backgroundColor:"#e5e7eb"}},f)),e.jsxs("span",{className:"text-xs text-gray-400 flex-shrink-0",children:[le+1," / ",d]})]}),Xe(m)]}),e.jsxs(fe,{className:"flex justify-between",children:[e.jsxs("div",{children:[!C&&e.jsx(G,{type:"button",variant:"outline",onClick:()=>{de(ve),I({})},disabled:$||y,children:"Previous"}),C&&n&&e.jsx(G,{type:"button",variant:"outline",onClick:n,disabled:$||y,children:"Cancel"})]}),e.jsx(G,{type:"button",isLoading:$||y,onClick:F?Oe:ke,children:F?m.conditionalOn&&!o?"Skip & Submit":"Submit":m.conditionalOn&&!o?"Skip":"Next"})]})]})})}return e.jsx("div",{className:"metakyc-sdk",children:e.jsx("form",{onSubmit:Ze,children:e.jsxs(X,{children:[e.jsx(he,{children:e.jsx(st,{title:(c==null?void 0:c.title)||"Company Registration"})}),e.jsxs(ee,{children:[W&&e.jsx("div",{className:"mb-6 p-4 bg-red-50 border border-red-200 rounded-lg",children:e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",W]})}),e.jsx("div",{className:"grid grid-cols-4 gap-4",children:M.map(m=>e.jsx("div",{className:"col-span-4",children:Qe(m)},m))})]}),e.jsxs(fe,{className:"flex justify-between",children:[n&&e.jsx(G,{type:"button",variant:"outline",onClick:n,disabled:$||y,children:"Cancel"}),e.jsx(G,{type:"submit",isLoading:$||y,children:"Register Company"})]})]})})})},Es=({applicantId:t,onComplete:r,onError:s,theme:n="light",className:a})=>{const{progress:l,currentStep:c,steps:u,workflowKey:y,nextWorkflowKey:p,hasWorkflowChanged:b,isLoading:T,error:v,moveBack:E,refreshProgress:A}=kr(t),[k,S]=i.useState(!1),M=i.useRef(null);if(i.useEffect(()=>{v&&s&&s(v)},[v,s]),i.useEffect(()=>{l!=null&&l.workflowResult&&r&&r(l.workflowResult)},[l==null?void 0:l.workflowResult,r]),i.useEffect(()=>{n==="dark"?document.documentElement.classList.add("dark"):document.documentElement.classList.remove("dark")},[n]),i.useEffect(()=>{b&&S(!1)},[b]),T||!l)return e.jsx("div",{className:`metakyc-sdk ${a||""}`,children:e.jsx(X,{children:e.jsxs(ee,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Loading workflow..."})]})})});if(v)return e.jsx("div",{className:`metakyc-sdk ${a||""}`,children:e.jsx(X,{children:e.jsx(ee,{children:e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-lg mb-4",style:{color:"var(--metakyc-danger, #ef4444)"},children:"An error occurred"}),e.jsx("p",{style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:v.message})]})})})});if(b&&!k)return e.jsx("div",{className:`metakyc-sdk ${a||""}`,children:e.jsx(X,{children:e.jsx(ee,{children:e.jsxs("div",{className:"text-center py-8",children:[e.jsx("div",{className:"mb-6",children:e.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-full mb-4",style:{backgroundColor:"var(--metakyc-primary-light, #dbeafe)"},children:e.jsx("svg",{className:"w-8 h-8",style:{color:"var(--metakyc-primary, #2563eb)"},fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})})}),e.jsx("h3",{className:"text-xl font-semibold mb-2",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Workflow Transition"}),e.jsx("p",{className:"mb-6",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Your application workflow has been updated based on your progress."}),e.jsxs("div",{className:"rounded-lg p-4 mb-6 max-w-md mx-auto",style:{backgroundColor:"var(--metakyc-surface, #f9fafb)"},children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"mb-1",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"Previous Workflow"}),e.jsx("p",{className:"font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:y})]}),e.jsx("svg",{className:"w-6 h-6 mx-4",style:{color:"var(--metakyc-text-muted, #9ca3af)"},fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 7l5 5m0 0l-5 5m5-5H6"})}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"mb-1",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"New Workflow"}),e.jsx("p",{className:"font-medium",style:{color:"var(--metakyc-primary, #2563eb)"},children:p})]})]}),l.nextWorkflowName&&e.jsx("p",{className:"text-center mt-2 text-xs",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:l.nextWorkflowName})]}),e.jsx("button",{onClick:()=>S(!0),className:"px-6 py-3 font-medium rounded-lg transition-opacity hover:opacity-90",style:{backgroundColor:"var(--metakyc-primary, #2563eb)",color:"#ffffff"},children:"Continue with New Workflow"})]})})})});if(l.status===Fe.Finished||l.status===Fe.OnHold)return e.jsx("div",{className:`metakyc-sdk ${a||""}`,children:e.jsx(ht,{kycStatus:l.kycStatus,reviewStatus:l.reviewStatus,workflowResult:l.workflowResult,customMessage:l.customMessage,onContinue:r&&l.workflowResult?()=>r(l.workflowResult):void 0,onContactSupport:()=>{typeof window<"u"&&(window.location.href="mailto:support@example.com")}})});if(!c)return e.jsx("div",{className:`metakyc-sdk ${a||""}`,children:e.jsx(X,{children:e.jsxs(ee,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:l.status===Fe.IdentityPending?"Loading identity verification...":"Loading current step..."})]})})});const Y=U=>{switch(U){case oe.Overview:return"Overview";case oe.Questionaries:return"Questionnaire";case oe.UploadDocument:return"Documents";case oe.IdentitySdk:return"Identity";case oe.RiskScoring:return"Risk Assessment";case oe.InvestorCategorization:return"Investor Categorization";case oe.AppropriatenessTest:return"Appropriateness Test";case oe.AdditionalData:return"Additional Data";case oe.ManualReview:return"Review";default:return""}},L=()=>{const U=u.filter(q=>q.visibility!==!1),te=U.findIndex(q=>q.order===c.order),R=te>=0?te+1:1,g=U.length,O=g>1?te/(g-1)*100:100;return e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",marginBottom:"16px"},children:[e.jsx(st,{}),e.jsxs(vt,{variant:l.status===1?"info":"success",children:["Step ",R," of ",g]})]}),e.jsx("div",{style:{marginBottom:"16px"},children:e.jsx("div",{style:{height:"4px",borderRadius:"999px",backgroundColor:"var(--metakyc-border, #e5e7eb)",overflow:"hidden"},children:e.jsx("div",{style:{height:"100%",borderRadius:"999px",backgroundColor:"var(--metakyc-primary, #2563eb)",width:`${O}%`,transition:"width 0.4s ease"}})})}),e.jsx(As,{ref:M,visibleSteps:U,currentVisibleStepIndex:te,getStepFallbackName:Y})]})},_=()=>{const U={applicantId:t,onComplete:async()=>{await A()},onBack:c.order>0?E:void 0};switch(c.action){case oe.Questionaries:return e.jsx(Lr,{...U});case oe.UploadDocument:return e.jsx(Dr,{...U});case oe.Overview:return e.jsx(Mr,{...U});case oe.IdentitySdk:return e.jsx(_r,{...U});case oe.RiskScoring:return e.jsx(Or,{...U});case oe.AdditionalData:case oe.InvestorCategorization:return e.jsx(zr,{...U});case oe.AppropriatenessTest:return e.jsx(Br,{...U});case oe.ManualReview:return e.jsx(ht,{kycStatus:l.kycStatus,reviewStatus:l.reviewStatus,workflowResult:l.workflowResult,customMessage:l.customMessage});default:return e.jsx(X,{children:e.jsxs(ee,{className:"py-12 text-center",children:[e.jsx("div",{className:"mb-4",children:e.jsx(Ee,{})}),e.jsxs("p",{className:"text-gray-600 dark:text-gray-400 mb-2",children:["Processing step: ",c.title||c.name]}),e.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:["Action type: ",oe[c.action]]})]})})}};return e.jsxs("div",{className:`metakyc-sdk ${a||""}`,children:[L(),_()]})},As=i.forwardRef(({visibleSteps:t,currentVisibleStepIndex:r,getStepFallbackName:s},n)=>{const a=i.useRef(null),l=i.useRef(null);return i.useImperativeHandle(n,()=>a.current),i.useEffect(()=>{if(l.current&&a.current){const c=a.current,u=l.current,y=u.offsetLeft-c.offsetWidth/2+u.offsetWidth/2;c.scrollTo({left:Math.max(0,y),behavior:"smooth"})}},[r]),e.jsx("div",{ref:a,className:"metakyc-stepper-scroll",style:{display:"flex",alignItems:"center",overflowX:"auto",overflowY:"hidden",scrollbarWidth:"none",msOverflowStyle:"none",WebkitOverflowScrolling:"touch",padding:"4px 0",gap:"0"},children:t.map((c,u)=>{const y=u<r,p=u===r,b=y||p,T=c.displayName||c.name||s(c.action)||`Step ${u+1}`;return e.jsxs(i.Fragment,{children:[e.jsxs("div",{ref:p?l:void 0,style:{display:"flex",alignItems:"center",flexShrink:0},children:[e.jsx("div",{style:{width:"28px",height:"28px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"12px",fontWeight:600,flexShrink:0,transition:"all 0.2s ease",...b?{backgroundColor:"var(--metakyc-primary, #2563eb)",color:"#ffffff",border:"none"}:{backgroundColor:"transparent",color:"var(--metakyc-text-muted, #9ca3af)",border:"2px solid var(--metakyc-border, #e5e7eb)"}},children:y?e.jsx("svg",{width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:2.5,viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}):u+1}),e.jsx("span",{style:{marginLeft:"6px",fontSize:"13px",whiteSpace:"nowrap",fontWeight:p?600:400,color:p?"var(--metakyc-text-primary, #111827)":y?"var(--metakyc-primary, #2563eb)":"var(--metakyc-text-muted, #9ca3af)",transition:"color 0.2s ease"},children:T})]}),u<t.length-1&&e.jsx("div",{style:{width:"32px",minWidth:"16px",height:"2px",margin:"0 8px",flexShrink:0,borderRadius:"999px",backgroundColor:y?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",transition:"background-color 0.2s ease"}})]},c.order)})})});function Fs(t){return He.z.object({questionResults:He.z.any()}).passthrough()}function Ts(t){let r=He.z.array(He.z.instanceof(File));if(t.isRequired?r=r.min(1,`${t.displayName} is required`):r=r.optional(),t.multipleFile||(r=r.refine(s=>!s||s.length<=1,{message:"Only one file is allowed"})),t.maxEachFileSizeByte>0&&(r=r.refine(s=>!s||s.every(n=>n.size<=t.maxEachFileSizeByte),{message:`File size must not exceed ${Math.round(t.maxEachFileSizeByte/1024/1024)}MB`})),t.allowedTypes){const s=t.allowedTypes.split(",").map(n=>n.trim());r=r.refine(n=>n?n.every(a=>s.some(l=>l.endsWith("/*")?a.type.startsWith(l.slice(0,-2)):a.type===l)):!0,{message:"Invalid file type"})}return r}function Ps(t){const r={};return t.uploadDocumentFiles.forEach(s=>{const n=`file_${s.id}`;r[n]=Ts(s)}),He.z.object(r)}function Ls(t){return He.z.any()}function Ds(t){return He.z.string().min(1,"This question is required")}function Ms(t){const r={};return t.appropriatenessQuestions.forEach(s=>{const n=`question_${s.id}`;r[n]=Ds()}),He.z.object(r)}const Os=He.z.any();exports.ALLOWED_LANGUAGES=xt;exports.ApplicantProgressOnHoldReason=Et;exports.ApplicantProgressStatus=Fe;exports.ApplicantService=Kt;exports.ApplicantStatus=Ft;exports.AppropriatenessQuestionType=Mt;exports.AppropriatenessTestService=Yt;exports.AppropriatenessTestStep=Br;exports.Badge=vt;exports.BaseInformationService=Zt;exports.Button=G;exports.COMPANY_FIELD_METADATA=Je;exports.Card=X;exports.CardContent=ee;exports.CardFooter=fe;exports.CardHeader=he;exports.CountriesType=$e;exports.CreateApplicantForm=Rs;exports.CreateCompanyApplicantForm=Is;exports.CriteriaBuiltInType=zt;exports.DEFAULT_COMPANY_VISIBLE_FIELDS=_t;exports.DEFAULT_VISIBLE_FIELDS=$t;exports.DocumentReviewStatus=Dt;exports.EndpointBuilder=Wt;exports.ErrorHandler=tt;exports.EventEmitter=or;exports.FIELD_METADATA=Ye;exports.FileType=Lt;exports.FileUpload=Ir;exports.GenderType=ot;exports.Header=st;exports.HttpClient=Ut;exports.IdentityProviderManager=_e;exports.IdentityService=Jt;exports.IdentityVerificationProvider=Ae;exports.IdentityVerificationStep=_r;exports.Input=ye;exports.InvestorCategorizationService=Xt;exports.InvestorCategorizationStep=zr;exports.InvestorCategorizationType=je;exports.InvestorCategoryType=Bt;exports.KycProcessStatus=Tt;exports.KycStatus=qe;exports.KycStatusDisplay=ht;exports.KycWorkflow=Es;exports.Logo=$r;exports.MetaKYCContext=gt;exports.MetaKYCError=Le;exports.MetaKYCProvider=Jr;exports.MultiSelect=Rr;exports.OnfidoProvider=pr;exports.OverviewService=Qt;exports.OverviewStep=Mr;exports.PhoneInput=Er;exports.QuestionnaireService=qt;exports.QuestionnaireStep=Lr;exports.ReviewStatus=Ve;exports.RiskCriteriaType=Ot;exports.RiskLevel=At;exports.RiskScoringService=Gt;exports.RiskScoringStep=Or;exports.SardinAIProvider=mr;exports.SearchableSelect=Me;exports.Select=pt;exports.Spinner=Ee;exports.StepRouter=cr;exports.SumsubProvider=ur;exports.ThemeManager=yr;exports.ThemePreset=we;exports.ThemeService=ir;exports.UploadDocumentService=Vt;exports.UploadDocumentStep=Dr;exports.UserType=Pt;exports.ValueDataType=De;exports.WorkflowOrchestrator=dr;exports.WorkflowResultType=it;exports.WorkflowState=lr;exports.WorkflowStepAction=oe;exports.appropriatenessTestSchema=Os;exports.clearAllStorage=rs;exports.clearApplicantId=gr;exports.clearWorkflowState=vr;exports.cn=Se;exports.corporateTheme=er;exports.defaultConfig=Ht;exports.defaultTheme=Re;exports.fileToBase64=xr;exports.fintechTheme=tr;exports.formatFileSize=dt;exports.generateAppropriatenessSchema=Ms;exports.generateQuestionnaireSchema=Fs;exports.generateRiskScoringSchema=Ls;exports.generateUploadDocumentSchema=Ps;exports.getAcceptString=es;exports.getApplicantId=fr;exports.getThemePreset=rt;exports.getWorkflowState=ts;exports.healthcareTheme=rr;exports.isScriptLoaded=Vr;exports.loadScript=ft;exports.minimalTheme=nr;exports.modernTheme=sr;exports.removeScript=Yr;exports.saveApplicantId=hr;exports.saveWorkflowState=br;exports.themePresets=ar;exports.useApplicant=bt;exports.useAppropriatenessTest=ss;exports.useIdentityVerification=Cr;exports.useKycWorkflow=kr;exports.useMetaKYC=Ne;exports.useOverview=Sr;exports.useQuestionnaire=jr;exports.useRiskScoring=Nr;exports.useUploadDocument=wr;exports.validateFileSize=Zr;exports.validateFileType=Xr;
|
|
83
83
|
//# sourceMappingURL=index.cjs.map
|