@vpdev2/metakyc-sdk 1.0.100 → 1.0.102

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var Or=Object.defineProperty;var Br=(t,r,s)=>r in t?Or(t,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[r]=s;var de=(t,r,s)=>Br(t,typeof r!="symbol"?r+"":r,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const $r=require("axios"),o=require("react"),e=require("react/jsx-runtime"),it=require("react-dom"),Oe=require("react-hook-form"),De=require("zod");function _r(t){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const a=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(r,s,a.get?a:{enumerable:!0,get:()=>t[s]})}}return r.default=t,Object.freeze(r)}const ft=_r(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||{}),tt=(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))(tt||{}),Re=(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))(Re||{}),St=(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))(St||{}),Ct=(t=>(t[t.LowRisk=0]="LowRisk",t[t.MediumRisk=1]="MediumRisk",t[t.HighRisk=2]="HighRisk",t[t.Alert=3]="Alert",t))(Ct||{}),Be=(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))(Be||{}),$e=(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))($e||{}),Nt=(t=>(t[t.ProviderResultPending=0]="ProviderResultPending",t[t.ProviderResultReceived=1]="ProviderResultReceived",t[t.Canceled=2]="Canceled",t[t.ExtendedToNewApplicant=3]="ExtendedToNewApplicant",t))(Nt||{}),Rt=(t=>(t[t.None=0]="None",t[t.ProviderResultPending=1]="ProviderResultPending",t[t.ProviderResultReceived=2]="ProviderResultReceived",t[t.Canceled=3]="Canceled",t))(Rt||{}),Ne=(t=>(t[t.Onfido=0]="Onfido",t[t.Sumsub=2]="Sumsub",t[t.SardinAI=3]="SardinAI",t))(Ne||{}),It=(t=>(t[t.Individual=0]="Individual",t[t.Company=1]="Company",t))(It||{}),rt=(t=>(t[t.Male=0]="Male",t[t.Female=1]="Female",t[t.Other=2]="Other",t))(rt||{}),Et=(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))(Et||{}),At=(t=>(t[t.Pending=0]="Pending",t[t.Approved=1]="Approved",t[t.Rejected=2]="Rejected",t[t.RequiresRevision=3]="RequiresRevision",t))(At||{}),Ft=(t=>(t[t.SingleChoice=0]="SingleChoice",t[t.MultipleChoice=1]="MultipleChoice",t[t.Text=2]="Text",t))(Ft||{}),Ee=(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))(Ee||{}),Tt=(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))(Tt||{}),Pt=(t=>(t[t.None=0]="None",t[t.Country=1]="Country",t))(Pt||{}),ge=(t=>(t[t.Individual=0]="Individual",t[t.Sophisticated=1]="Sophisticated",t[t.HighNetWorth=2]="HighNetWorth",t[t.Business=3]="Business",t))(ge||{}),Lt=(t=>(t[t.Retail=0]="Retail",t[t.Professional=1]="Professional",t[t.EligibleCounterparty=2]="EligibleCounterparty",t))(Lt||{});const Le={Nationality:10,Address:20,CountryOfBirth:30,PhoneNumber:40,UboAddress:50},_e={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:Le.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:Le.Address},nationality:{label:"Nationality",type:"select",countriesType:Le.Nationality},otherNationality:{label:"Other Nationalities",type:"multiselect",countriesType:Le.Nationality},countryOfBirth:{label:"Country of Birth",type:"select",countriesType:Le.CountryOfBirth},placeOfBirth:{label:"Place of Birth",type:"text"},taxCountry:{label:"Tax Country",type:"select",countriesType:Le.Address},taxNumber:{label:"Tax Number",type:"text"},defaultLanguage:{label:"Default Language",type:"select"},educationLevel:{label:"Education Level",type:"text"},occupation:{label:"Occupation",type:"text"}},Ue={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:Le.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:Le.Address},lei:{label:"LEI",type:"text"}},Dt=["companyName","email","phone","registrationNumber"],Mt=["firstName","lastName","email","phonenumber","dateOfBirth"],dt=[{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 be=(t=>(t.Default="default",t.Corporate="corporate",t.Fintech="fintech",t.Healthcare="healthcare",t.Modern="modern",t.Minimal="minimal",t))(be||{});const zt={timeout:3e4,retries:3,locale:"en",endpoints:{pattern:"host-controller"}};class Ot{constructor(r){this.config=r}build(r,s){const a=`${r}.${s}`;if(this.config.customPaths&&this.config.customPaths[a])return this.config.customPaths[a];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 ${a}. 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 Ie extends Error{constructor(s,a,n,l,c){super(s);de(this,"response");this.code=a,this.details=n,this.validationErrors=l,this.name="MetaKYCError",this.response=c,Object.setPrototypeOf(this,Ie.prototype)}}class Ge{static handleApiError(r){return new Ie(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 Ie(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 Ie(s.result.message,r.response.status,`HTTP ${r.response.status}: ${r.response.statusText}`,void 0,r.response):new Ie((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 Ie("No response from server",0,"The request was made but no response was received. Please check your network connection."):new Ie(r.message||"An unexpected error occurred",0,r.toString())}static isMetaKYCError(r){return r instanceof Ie}}class Bt{constructor(r){de(this,"axiosInstance");de(this,"endpointBuilder");de(this,"config");this.config={...zt,...r},this.endpointBuilder=new Ot(this.config.endpoints),this.axiosInstance=$r.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 n;const a=s.config;return((n=s.response)==null?void 0:n.status)>=500&&!a._retry&&(a._retry=!0,a._retryCount=(a._retryCount||0)+1,a._retryCount<(this.config.retries||3))?(await new Promise(l=>setTimeout(l,1e3*a._retryCount)),this.axiosInstance(a)):Promise.reject(s)})}buildEndpoint(r,s){return this.endpointBuilder.build(r,s)}async get(r,s,a){try{const n=this.buildEndpoint(r,s),l=await this.axiosInstance.get(n,{params:a});return this.handleResponse(l)}catch(n){throw Ge.handleAxiosError(n)}}async post(r,s,a){try{const n=this.buildEndpoint(r,s),l=await this.axiosInstance.post(n,a);return this.handleResponse(l)}catch(n){throw Ge.handleAxiosError(n)}}async put(r,s,a){try{const n=this.buildEndpoint(r,s),l=await this.axiosInstance.put(n,a);return this.handleResponse(l)}catch(n){throw Ge.handleAxiosError(n)}}async delete(r,s,a){try{const n=this.buildEndpoint(r,s),l=await this.axiosInstance.delete(n,{params:a});return this.handleResponse(l)}catch(n){throw Ge.handleAxiosError(n)}}handleResponse(r){const s=r.data;if(!s.success&&s.error)throw Ge.handleApiError(s.error);return s}getAxiosInstance(){return this.axiosInstance}}class $t{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 _t{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 Ht{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 Wt{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 Ut{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 Kt{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 qt{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)}}class Yt{constructor(r){this.httpClient=r}async getCountries(r,s,a){return(await this.httpClient.get("BaseInformation","GetAllCountries",{filter:r||"",lng:s||"en",type:a})).result}async getBranches(){return(await this.httpClient.get("BaseInformation","GetBranches")).result}async getLegalEntities(){return(await this.httpClient.get("BaseInformation","GetLegalEntities")).result}}class Vt{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 Se={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"}}},Qt={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"}},Gt={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"}},Jt={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"}}},Zt={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"}},Xt={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"}},er={[be.Default]:Se,[be.Corporate]:Qt,[be.Fintech]:Gt,[be.Healthcare]:Jt,[be.Modern]:Zt,[be.Minimal]:Xt};function Je(t){return er[t]||Se}class tr{constructor(r){this.httpClient=r}async getThemeConfiguration(){var r;try{const s=await this.httpClient.get("Tenant","GetThemeConfiguration");if(!s.result.isEnabled)return Je(be.Default);let a=s.result.preset?Je(s.result.preset):Je(be.Default);if(s.result.title&&(a.title=s.result.title),s.result.logo&&(a.logo={...a.logo,...s.result.logo}),s.result.colors&&(a.colors={...a.colors,...s.result.colors}),s.result.typography&&(a.typography={...a.typography,...s.result.typography}),s.result.spacing&&(a.spacing={...a.spacing,...s.result.spacing}),s.result.customCSS&&(a.customCSS=s.result.customCSS),s.result.darkMode&&(a.darkMode={colors:{...(r=a.darkMode)==null?void 0:r.colors,...s.result.darkMode.colors}}),s.result.applicantFormVisibleFields&&s.result.applicantFormVisibleFields.length>0&&(a.applicantFormVisibleFields=s.result.applicantFormVisibleFields),s.result.applicantFormRequiredFields&&s.result.applicantFormRequiredFields.length>0&&(a.applicantFormRequiredFields=s.result.applicantFormRequiredFields),s.result.allowedLanguages&&s.result.allowedLanguages.length>0&&(a.allowedLanguages=s.result.allowedLanguages),s.result.applicantFormPages)try{const n=typeof s.result.applicantFormPages=="string"?JSON.parse(s.result.applicantFormPages):s.result.applicantFormPages;Array.isArray(n)&&n.length>0&&(a.applicantFormPages=n.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 n=typeof s.result.reviewPageFields=="string"?JSON.parse(s.result.reviewPageFields):s.result.reviewPageFields;Array.isArray(n)&&n.length>0&&(a.reviewPageFields=n)}catch{}if(s.result.reviewPageDisabled&&(a.reviewPageDisabled=!0),s.result.fieldLabelMode==="placeholder"&&(a.fieldLabelMode="placeholder"),s.result.companyFormVisibleFields&&s.result.companyFormVisibleFields.length>0&&(a.companyFormVisibleFields=s.result.companyFormVisibleFields),s.result.companyFormRequiredFields&&s.result.companyFormRequiredFields.length>0&&(a.companyFormRequiredFields=s.result.companyFormRequiredFields),s.result.companyFormPages)try{const n=typeof s.result.companyFormPages=="string"?JSON.parse(s.result.companyFormPages):s.result.companyFormPages;Array.isArray(n)&&n.length>0&&(a.companyFormPages=n.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 n=typeof s.result.companyReviewPageFields=="string"?JSON.parse(s.result.companyReviewPageFields):s.result.companyReviewPageFields;Array.isArray(n)&&n.length>0&&(a.companyReviewPageFields=n)}catch{}return a}catch(s){return console.warn("[ThemeService] Failed to fetch theme configuration:",s),Je(be.Default)}}async saveThemeConfiguration(r){await this.httpClient.post("Tenant","SaveThemeConfiguration",r)}getAvailablePresets(){return[{id:be.Default,name:"Default"},{id:be.Corporate,name:"Corporate"},{id:be.Fintech,name:"Fintech"},{id:be.Healthcare,name:"Healthcare"},{id:be.Modern,name:"Modern"},{id:be.Minimal,name:"Minimal"}]}getPreviewTheme(r,s){const a=Je(r);return s?{...a,...s,logo:{...a.logo,...s.logo},colors:{...a.colors,...s.colors},typography:s.typography?{...a.typography,...s.typography}:a.typography,spacing:s.spacing?{...a.spacing,...s.spacing}:a.spacing}:a}}class rr{constructor(){de(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 a=this.listeners.get(r);a&&a.delete(s)}emit(r,s){const a=this.listeners.get(r);a&&a.forEach(n=>{try{n(s)}catch(l){console.error(`Error in event listener for "${r}":`,l)}})}clear(){this.listeners.clear()}clearEvent(r){this.listeners.delete(r)}}class sr{constructor(){de(this,"events",new rr);de(this,"_applicantId",null);de(this,"_progress",null);de(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)||Re.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===Re.Finished}get isOnHold(){return this.status===Re.OnHold}get isInProgress(){return this.status===Re.InProgress}setApplicantId(r){this._applicantId=r}updateProgress(r){var a,n;const s=(a=this._progress)==null?void 0:a.currentStep;this._progress=r,this._applicantId=r.applicantId,this._error=null,this.events.emit("progressUpdated",r),(s==null?void 0:s.order)!==((n=r.currentStep)==null?void 0:n.order)&&this.events.emit("stepChanged",r.currentStep),this.events.emit("statusChanged",r.status),r.status===Re.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 ar{constructor(){de(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 a=this.getHandler(r);if(!a)throw new Error(`No handler registered for step action: ${ae[r]}`);return a.loadData(s)}async submitStepData(r,s){const a=this.getHandler(r);if(!a)throw new Error(`No handler registered for step action: ${ae[r]}`);return a.submitData(s)}}class nr{constructor(r,s,a,n,l,c,u,y){de(this,"state");de(this,"stepRouter");this.applicantService=r,this.questionnaireService=s,this.uploadDocumentService=a,this.appropriatenessTestService=n,this.overviewService=l,this.riskScoringService=c,this.investorCategorizationService=y,this.state=new sr,this.stepRouter=new ar,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 pt(t,r){return new Promise((s,a)=>{if(r&&document.getElementById(r)){s();return}const n=document.createElement("script");n.src=t,r&&(n.id=r),n.async=!0,n.onload=()=>s(),n.onerror=()=>a(new Error(`Failed to load script: ${t}`)),document.head.appendChild(n)})}function Hr(t){return!!document.getElementById(t)}function Wr(t){const r=document.getElementById(t);r&&r.remove()}class ir{constructor(r){de(this,"sdk",null);de(this,"config");this.config=r}async loadSDK(){await pt("https://cdn.sumsub.com/websdk/v2/production/websdk.js","sumsub-sdk")}async initialize(r){if(window.snsWebSdk||await this.loadSDK(),!window.snsWebSdk)throw new Error("Sumsub SDK failed to load");this.sdk=window.snsWebSdk.init(this.config.accessToken,()=>this.config.accessToken).withConf({lang:this.config.lang||"en",email:this.config.applicantEmail,phone:this.config.applicantPhone,i18n:{}}).on("idCheck.onStepCompleted",s=>{console.log("Sumsub step completed:",s)}).on("idCheck.onError",s=>{console.error("Sumsub error:",s)}).build(),this.sdk.launch(`#${r}`)}destroy(){this.sdk&&(this.sdk.destroy(),this.sdk=null)}onComplete(r){this.sdk&&this.sdk.on("idCheck.applicantStatus",s=>{s.applicantStatus==="completed"&&r(s)})}onError(r){this.sdk&&this.sdk.on("idCheck.onError",r)}}class or{constructor(r){de(this,"sdk",null);de(this,"config");this.config=r}async loadSDK(){await pt("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 lr{constructor(r){de(this,"sardineContext",null);de(this,"config");de(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 a=this.getSardineHost(),n=document.createElement("script");n.type="text/javascript",n.async=!0,n.src=`https://${a}/assets/loader.min.js`,n.onload=()=>{console.log("[SardinAI] SDK loaded successfully"),r()},n.onerror=()=>{s(new Error("Failed to load SardinAI SDK"))};const l=document.getElementsByTagName("script")[0];l&&l.parentNode?l.parentNode.insertBefore(n,l):document.head.appendChild(n)})}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:a,flow:n,enableBiometrics:l,enablePortScanning:c}=this.config;this.sardineContext=window._Sardine.createContext({clientId:s,sessionKey:this.sessionKey,userIdHash:void 0,flow:n||window.location.pathname,environment:a||"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,m)=>{switch(u){case"SESSION_UPDATE_FAILED":console.error("[SardinAI] Session update failed:",m);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"),a=document.createElement("img"),{clientId:n,flow:l}=this.config;a.src=`https://${r}/v1/a.png?clientId=${n}&sessionKey=${this.sessionKey}&flow=${l||"kyc"}&ns=1`,a.style.display="none",s.appendChild(a),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,a,n)=>{switch(s){case"SESSION_UPDATE_FAILED":console.error("[SardinAI] Config update failed:",n);break;case"SESSION_UPDATED":console.log("[SardinAI] Config updated:",a);break;case"SESSION_NO_UPDATE":console.log("[SardinAI] No config update needed");break}}})}getSessionKey(){return this.sessionKey}destroy(){this.sardineContext&&(this.sardineContext=null)}}class Ke{static createProvider(r,s){switch(r){case Ne.Sumsub:return new ir(s);case Ne.Onfido:return new or(s);case Ne.SardinAI:return new lr(s);default:throw new Error(`Unsupported identity provider: ${r}`)}}static parseProviderConfig(r,s,a){var n;switch(r){case Ne.Sumsub:return{accessToken:s.accessToken||s.token,applicantEmail:s.email,applicantPhone:s.phone,externalUserId:s.externalUserId,lang:s.lang||"en"};case Ne.Onfido:return{token:s.token||s.sdkToken};case Ne.SardinAI:const l=((n=a==null?void 0:a.identityProviders)==null?void 0:n.sardinai)||{};return{clientId:l.clientId||s.clientId,sessionKey:l.sessionKey||s.sessionKey,environment:l.environment||s.environment||"production",flow:l.flow||s.flow,region:l.region,enableBiometrics:l.enableBiometrics,enablePortScanning:l.enablePortScanning};default:throw new Error(`Unsupported identity provider: ${r}`)}}}function Ur(){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 ye=(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"),We=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 a=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(r,s,a.get?a:{enumerable:!0,get:()=>t[s]})}}return r.default=t,Object.freeze(r)}const jt=qr(i);var ie=(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))(ie||{}),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||{}),Te=(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))(Te||{}),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||{}),Ye=(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))(Ye||{}),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||{}),Fe=(t=>(t[t.Onfido=0]="Onfido",t[t.Sumsub=2]="Sumsub",t[t.SardinAI=3]="SardinAI",t))(Fe||{}),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||{}),Oe=(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))(Oe||{}),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||{}),we=(t=>(t[t.Individual=0]="Individual",t[t.Sophisticated=1]="Sophisticated",t[t.HighNetWorth=2]="HighNetWorth",t[t.Business=3]="Business",t))(we||{}),Bt=(t=>(t[t.Retail=0]="Retail",t[t.Professional=1]="Professional",t[t.EligibleCounterparty=2]="EligibleCounterparty",t))(Bt||{});const He={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:He.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:He.Address},nationality:{label:"Nationality",type:"select",countriesType:He.Nationality},otherNationality:{label:"Other Nationalities",type:"multiselect",countriesType:He.Nationality},countryOfBirth:{label:"Country of Birth",type:"select",countriesType:He.CountryOfBirth},placeOfBirth:{label:"Place of Birth",type:"text"},taxCountry:{label:"Tax Country",type:"select",countriesType:He.Address},taxNumber:{label:"Tax Number",type:"text"},defaultLanguage:{label:"Default Language",type:"select"},educationLevel:{label:"Education Level",type:"text"},occupation:{label:"Occupation",type:"text"}},Ze={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:He.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:He.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 Se=(t=>(t.Default="default",t.Corporate="corporate",t.Fintech="fintech",t.Healthcare="healthcare",t.Modern="modern",t.Minimal="minimal",t))(Se||{});const Ht={timeout:3e4,retries:3,locale:"en",endpoints:{pattern:"host-controller"}};class Wt{constructor(r){this.config=r}build(r,s){const a=`${r}.${s}`;if(this.config.customPaths&&this.config.customPaths[a])return this.config.customPaths[a];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 ${a}. 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 Me extends Error{constructor(s,a,n,o,c){super(s);ye(this,"response");this.code=a,this.details=n,this.validationErrors=o,this.name="MetaKYCError",this.response=c,Object.setPrototypeOf(this,Me.prototype)}}class tt{static handleApiError(r){return new Me(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 Me(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 Me(s.result.message,r.response.status,`HTTP ${r.response.status}: ${r.response.statusText}`,void 0,r.response):new Me((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 Me("No response from server",0,"The request was made but no response was received. Please check your network connection."):new Me(r.message||"An unexpected error occurred",0,r.toString())}static isMetaKYCError(r){return r instanceof Me}}class Ut{constructor(r){ye(this,"axiosInstance");ye(this,"endpointBuilder");ye(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 n;const a=s.config;return((n=s.response)==null?void 0:n.status)>=500&&!a._retry&&(a._retry=!0,a._retryCount=(a._retryCount||0)+1,a._retryCount<(this.config.retries||3))?(await new Promise(o=>setTimeout(o,1e3*a._retryCount)),this.axiosInstance(a)):Promise.reject(s)})}buildEndpoint(r,s){return this.endpointBuilder.build(r,s)}async get(r,s,a){try{const n=this.buildEndpoint(r,s),o=await this.axiosInstance.get(n,{params:a});return this.handleResponse(o)}catch(n){throw tt.handleAxiosError(n)}}async post(r,s,a){try{const n=this.buildEndpoint(r,s),o=await this.axiosInstance.post(n,a);return this.handleResponse(o)}catch(n){throw tt.handleAxiosError(n)}}async put(r,s,a){try{const n=this.buildEndpoint(r,s),o=await this.axiosInstance.put(n,a);return this.handleResponse(o)}catch(n){throw tt.handleAxiosError(n)}}async delete(r,s,a){try{const n=this.buildEndpoint(r,s),o=await this.axiosInstance.delete(n,{params:a});return this.handleResponse(o)}catch(n){throw tt.handleAxiosError(n)}}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 Yt{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 Vt{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)}}class Zt{constructor(r){this.httpClient=r}async getCountries(r,s,a){return(await this.httpClient.get("BaseInformation","GetAllCountries",{filter:r||"",lng:s||"en",type:a})).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 Ie={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"}},ar={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"}},nr={[Se.Default]:Ie,[Se.Corporate]:er,[Se.Fintech]:tr,[Se.Healthcare]:rr,[Se.Modern]:sr,[Se.Minimal]:ar};function rt(t){return nr[t]||Ie}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(Se.Default);let a=s.result.preset?rt(s.result.preset):rt(Se.Default);if(s.result.title&&(a.title=s.result.title),s.result.logo&&(a.logo={...a.logo,...s.result.logo}),s.result.colors&&(a.colors={...a.colors,...s.result.colors}),s.result.typography&&(a.typography={...a.typography,...s.result.typography}),s.result.spacing&&(a.spacing={...a.spacing,...s.result.spacing}),s.result.customCSS&&(a.customCSS=s.result.customCSS),s.result.darkMode&&(a.darkMode={colors:{...(r=a.darkMode)==null?void 0:r.colors,...s.result.darkMode.colors}}),s.result.applicantFormVisibleFields&&s.result.applicantFormVisibleFields.length>0&&(a.applicantFormVisibleFields=s.result.applicantFormVisibleFields),s.result.applicantFormRequiredFields&&s.result.applicantFormRequiredFields.length>0&&(a.applicantFormRequiredFields=s.result.applicantFormRequiredFields),s.result.allowedLanguages&&s.result.allowedLanguages.length>0&&(a.allowedLanguages=s.result.allowedLanguages),s.result.applicantFormPages)try{const n=typeof s.result.applicantFormPages=="string"?JSON.parse(s.result.applicantFormPages):s.result.applicantFormPages;Array.isArray(n)&&n.length>0&&(a.applicantFormPages=n.map(o=>{const c=!o._v||o._v<4;return{...o,fields:(o.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 n=typeof s.result.reviewPageFields=="string"?JSON.parse(s.result.reviewPageFields):s.result.reviewPageFields;Array.isArray(n)&&n.length>0&&(a.reviewPageFields=n)}catch{}if(s.result.reviewPageDisabled&&(a.reviewPageDisabled=!0),s.result.fieldLabelMode==="placeholder"&&(a.fieldLabelMode="placeholder"),s.result.companyFormVisibleFields&&s.result.companyFormVisibleFields.length>0&&(a.companyFormVisibleFields=s.result.companyFormVisibleFields),s.result.companyFormRequiredFields&&s.result.companyFormRequiredFields.length>0&&(a.companyFormRequiredFields=s.result.companyFormRequiredFields),s.result.companyFormPages)try{const n=typeof s.result.companyFormPages=="string"?JSON.parse(s.result.companyFormPages):s.result.companyFormPages;Array.isArray(n)&&n.length>0&&(a.companyFormPages=n.map(o=>{const c=!o._v||o._v<4;return{...o,fields:(o.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 n=typeof s.result.companyReviewPageFields=="string"?JSON.parse(s.result.companyReviewPageFields):s.result.companyReviewPageFields;Array.isArray(n)&&n.length>0&&(a.companyReviewPageFields=n)}catch{}return a}catch(s){return console.warn("[ThemeService] Failed to fetch theme configuration:",s),rt(Se.Default)}}async saveThemeConfiguration(r){await this.httpClient.post("Tenant","SaveThemeConfiguration",r)}getAvailablePresets(){return[{id:Se.Default,name:"Default"},{id:Se.Corporate,name:"Corporate"},{id:Se.Fintech,name:"Fintech"},{id:Se.Healthcare,name:"Healthcare"},{id:Se.Modern,name:"Modern"},{id:Se.Minimal,name:"Minimal"}]}getPreviewTheme(r,s){const a=rt(r);return s?{...a,...s,logo:{...a.logo,...s.logo},colors:{...a.colors,...s.colors},typography:s.typography?{...a.typography,...s.typography}:a.typography,spacing:s.spacing?{...a.spacing,...s.spacing}:a.spacing}:a}}class or{constructor(){ye(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 a=this.listeners.get(r);a&&a.delete(s)}emit(r,s){const a=this.listeners.get(r);a&&a.forEach(n=>{try{n(s)}catch(o){console.error(`Error in event listener for "${r}":`,o)}})}clear(){this.listeners.clear()}clearEvent(r){this.listeners.delete(r)}}class lr{constructor(){ye(this,"events",new or);ye(this,"_applicantId",null);ye(this,"_progress",null);ye(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)||Te.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===Te.Finished}get isOnHold(){return this.status===Te.OnHold}get isInProgress(){return this.status===Te.InProgress}setApplicantId(r){this._applicantId=r}updateProgress(r){var a,n;const s=(a=this._progress)==null?void 0:a.currentStep;this._progress=r,this._applicantId=r.applicantId,this._error=null,this.events.emit("progressUpdated",r),(s==null?void 0:s.order)!==((n=r.currentStep)==null?void 0:n.order)&&this.events.emit("stepChanged",r.currentStep),this.events.emit("statusChanged",r.status),r.status===Te.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(){ye(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 a=this.getHandler(r);if(!a)throw new Error(`No handler registered for step action: ${ie[r]}`);return a.loadData(s)}async submitStepData(r,s){const a=this.getHandler(r);if(!a)throw new Error(`No handler registered for step action: ${ie[r]}`);return a.submitData(s)}}class dr{constructor(r,s,a,n,o,c,u,m){ye(this,"state");ye(this,"stepRouter");this.applicantService=r,this.questionnaireService=s,this.uploadDocumentService=a,this.appropriatenessTestService=n,this.overviewService=o,this.riskScoringService=c,this.investorCategorizationService=m,this.state=new lr,this.stepRouter=new cr,this.registerStepHandlers()}registerStepHandlers(){this.stepRouter.registerHandler(ie.Questionaries,{loadData:r=>this.questionnaireService.getQuestionnaire(r),submitData:async r=>{await this.questionnaireService.fillQuestionnaire(r)}}),this.stepRouter.registerHandler(ie.UploadDocument,{loadData:r=>this.uploadDocumentService.getUploadDocument(r),submitData:r=>this.uploadDocumentService.fillUploadDocument(r)}),this.stepRouter.registerHandler(ie.AppropriatenessTest,{loadData:r=>this.appropriatenessTestService.getAppropriatenessTest(r),submitData:async r=>{await this.appropriatenessTestService.fillAppropriatenessTest(r)}}),this.stepRouter.registerHandler(ie.Overview,{loadData:r=>this.overviewService.getOverviewData(r),submitData:r=>this.overviewService.passOverview(r.applicantId)}),this.stepRouter.registerHandler(ie.RiskScoring,{loadData:r=>this.riskScoringService.getRiskCriterias(r),submitData:async r=>{await this.riskScoringService.submitRiskScoring(r)}}),this.stepRouter.registerHandler(ie.IdentitySdk,{loadData:async r=>({applicantId:r,message:"Identity verification required"}),submitData:async()=>{}}),this.stepRouter.registerHandler(ie.InvestorCategorization,{loadData:r=>this.investorCategorizationService.getInvestorCategorization(r),submitData:async r=>{await this.investorCategorizationService.setInvestorCategorization(r)}}),this.stepRouter.registerHandler(ie.ManualReview,{loadData:async r=>({applicantId:r,message:"Your application is under manual review"}),submitData:async()=>{}}),this.stepRouter.registerHandler(ie.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,a)=>{if(r&&document.getElementById(r)){s();return}const n=document.createElement("script");n.src=t,r&&(n.id=r),n.async=!0,n.onload=()=>s(),n.onerror=()=>a(new Error(`Failed to load script: ${t}`)),document.head.appendChild(n)})}function Yr(t){return!!document.getElementById(t)}function Vr(t){const r=document.getElementById(t);r&&r.remove()}class ur{constructor(r){ye(this,"sdk",null);ye(this,"config");this.config=r}async loadSDK(){await ft("https://cdn.sumsub.com/websdk/v2/production/websdk.js","sumsub-sdk")}async initialize(r){if(window.snsWebSdk||await this.loadSDK(),!window.snsWebSdk)throw new Error("Sumsub SDK failed to load");this.sdk=window.snsWebSdk.init(this.config.accessToken,()=>this.config.accessToken).withConf({lang:this.config.lang||"en",email:this.config.applicantEmail,phone:this.config.applicantPhone,i18n:{}}).on("idCheck.onStepCompleted",s=>{console.log("Sumsub step completed:",s)}).on("idCheck.onError",s=>{console.error("Sumsub error:",s)}).build(),this.sdk.launch(`#${r}`)}destroy(){this.sdk&&(this.sdk.destroy(),this.sdk=null)}onComplete(r){this.sdk&&this.sdk.on("idCheck.applicantStatus",s=>{s.applicantStatus==="completed"&&r(s)})}onError(r){this.sdk&&this.sdk.on("idCheck.onError",r)}}class pr{constructor(r){ye(this,"sdk",null);ye(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){ye(this,"sardineContext",null);ye(this,"config");ye(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 a=this.getSardineHost(),n=document.createElement("script");n.type="text/javascript",n.async=!0,n.src=`https://${a}/assets/loader.min.js`,n.onload=()=>{console.log("[SardinAI] SDK loaded successfully"),r()},n.onerror=()=>{s(new Error("Failed to load SardinAI SDK"))};const o=document.getElementsByTagName("script")[0];o&&o.parentNode?o.parentNode.insertBefore(n,o):document.head.appendChild(n)})}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:a,flow:n,enableBiometrics:o,enablePortScanning:c}=this.config;this.sardineContext=window._Sardine.createContext({clientId:s,sessionKey:this.sessionKey,userIdHash:void 0,flow:n||window.location.pathname,environment:a||"production",parentElement:document.body,enableBiometrics:o!==!1,enablePortScanning:c===!0,region:this.config.region,onDeviceResponse:u=>{console.log(`[SardinAI] Device ID: ${u.deviceId}`)},onConfigUpdate:(u,m,p)=>{switch(u){case"SESSION_UPDATE_FAILED":console.error("[SardinAI] Session update failed:",p);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:",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"),a=document.createElement("img"),{clientId:n,flow:o}=this.config;a.src=`https://${r}/v1/a.png?clientId=${n}&sessionKey=${this.sessionKey}&flow=${o||"kyc"}&ns=1`,a.style.display="none",s.appendChild(a),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,a,n)=>{switch(s){case"SESSION_UPDATE_FAILED":console.error("[SardinAI] Config update failed:",n);break;case"SESSION_UPDATED":console.log("[SardinAI] Config updated:",a);break;case"SESSION_NO_UPDATE":console.log("[SardinAI] No config update needed");break}}})}getSessionKey(){return this.sessionKey}destroy(){this.sardineContext&&(this.sardineContext=null)}}class Xe{static createProvider(r,s){switch(r){case Fe.Sumsub:return new ur(s);case Fe.Onfido:return new pr(s);case Fe.SardinAI:return new mr(s);default:throw new Error(`Unsupported identity provider: ${r}`)}}static parseProviderConfig(r,s,a){var n;switch(r){case Fe.Sumsub:return{accessToken:s.accessToken||s.token,applicantEmail:s.email,applicantPhone:s.phone,externalUserId:s.externalUserId,lang:s.lang||"en"};case Fe.Onfido:return{token:s.token||s.sdkToken};case Fe.SardinAI:const o=((n=a==null?void 0:a.identityProviders)==null?void 0:n.sardinai)||{};return{clientId:o.clientId||s.clientId,sessionKey:o.sessionKey||s.sessionKey,environment:o.environment||s.environment||"production",flow:o.flow||s.flow,region:o.region,enableBiometrics:o.enableBiometrics,enablePortScanning:o.enablePortScanning};default:throw new Error(`Unsupported identity provider: ${r}`)}}}function Qr(){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,55 +29,55 @@
29
29
  position: relative !important;
30
30
  z-index: 2 !important;
31
31
  }
32
- `}class cr{constructor(r){de(this,"currentTheme",Se);de(this,"customStyleElement",null);de(this,"inputStyleElement",null);de(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 a;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(([n,l])=>{l&&this.container.style.setProperty(`--metakyc-${n}`,l)}),this.injectInputColors(),(a=this.currentTheme.darkMode)!=null&&a.colors&&this.applyDarkModeColors(this.currentTheme.darkMode.colors)}applyDarkModeColors(r){Object.entries(r).forEach(([s,a])=>{if(a){const n=`--metakyc-dark-${this.kebabCase(s)}`;this.container.style.setProperty(n,a)}})}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,a])=>{this.container.style.setProperty(`--metakyc-font-size-${s}`,a)}),r.fontWeight&&Object.entries(r.fontWeight).forEach(([s,a])=>{this.container.style.setProperty(`--metakyc-font-weight-${s}`,a.toString())}))}applySpacing(r){r&&Object.entries(r).forEach(([s,a])=>{const n=`--metakyc-${this.kebabCase(s)}`;this.container.style.setProperty(n,a)})}injectInputColors(){this.inputStyleElement&&this.inputStyleElement.remove(),this.inputStyleElement=document.createElement("style"),this.inputStyleElement.id="metakyc-input-colors",this.inputStyleElement.textContent=Ur(),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||Se.name,title:r.title||Se.title,logo:{...Se.logo,...r.logo},colors:{...Se.colors,...r.colors},typography:r.typography?{...Se.typography,...r.typography}:Se.typography,spacing:r.spacing?{...Se.spacing,...r.spacing}:Se.spacing,customCSS:r.customCSS,darkMode:r.darkMode?{colors:{...(s=Se.darkMode)==null?void 0:s.colors,...r.darkMode.colors}}:Se.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(Se)}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 mt=o.createContext(null),Kr=({config:t,children:r})=>{const[s,a]=o.useState(null),n=o.useRef(!1),l=o.useRef(!1),c=o.useMemo(()=>{const y=new Bt(t),m=new $t(y),w=new _t(y),T=new Ht(y),N=new Wt(y),F=new Ut(y),f=new Kt(y),j=new qt(y),P=new Yt(y),_=new Vt(y),H=new tr(y),L=new cr;return{httpClient:y,applicantService:m,questionnaireService:w,uploadDocumentService:T,appropriatenessTestService:N,overviewService:F,riskScoringService:f,identityService:j,baseInformationService:P,investorCategorizationService:_,themeService:H,themeManager:L}},[t]),u=o.useMemo(()=>({config:t,...c,currentTheme:s,createOrchestrator:()=>new nr(c.applicantService,c.questionnaireService,c.uploadDocumentService,c.appropriatenessTestService,c.overviewService,c.riskScoringService,c.identityService,c.investorCategorizationService)}),[t,c,s]);return o.useEffect(()=>((async()=>{if(n.current||l.current){console.log("[MetaKYC] Theme already loading or loaded, skipping...");return}n.current=!0;try{if(t.theme){console.log("[MetaKYC] Applying static theme from config"),c.themeManager.applyTheme(t.theme),a(c.themeManager.getCurrentTheme()),l.current=!0;return}console.log("[MetaKYC] Fetching theme from backend...");const m=await c.themeService.getThemeConfiguration();c.themeManager.applyTheme(m),a(c.themeManager.getCurrentTheme()),l.current=!0,console.log("[MetaKYC] Theme loaded and applied",m)}catch(m){console.warn("[MetaKYC] Failed to load theme, using default:",m),a(c.themeManager.getCurrentTheme()),l.current=!0}finally{n.current=!1}})(),()=>{c.themeManager.cleanup()}),[]),e.jsx(mt.Provider,{value:u,children:r})};function we(){const t=o.useContext(mt);if(!t)throw new Error("useMetaKYC must be used within a MetaKYCProvider");return t}async function dr(t){return new Promise((r,s)=>{const a=new FileReader;a.readAsDataURL(t),a.onload=()=>{const l=a.result.split(",")[1];r(l)},a.onerror=n=>s(n)})}function qr(t,r){return t.size<=r}function Yr(t,r){return r.split(",").map(a=>a.trim()).some(a=>{if(a.endsWith("/*")){const n=a.slice(0,-2);return t.type.startsWith(n)}return t.type===a})}function nt(t){if(t===0)return"0 Bytes";const r=1024,s=["Bytes","KB","MB","GB"],a=Math.floor(Math.log(t)/Math.log(r));return Math.round(t/Math.pow(r,a)*100)/100+" "+s[a]}function Vr(t){return t}function ve(...t){return t.filter(Boolean).join(" ")}const Xe={APPLICANT_ID:"metakyc_applicant_id",WORKFLOW_STATE:"metakyc_workflow_state"};function ur(t){try{localStorage.setItem(Xe.APPLICANT_ID,t.toString())}catch(r){console.warn("Failed to save applicant ID to storage:",r)}}function pr(){try{const t=localStorage.getItem(Xe.APPLICANT_ID);return t?parseInt(t,10):null}catch(t){return console.warn("Failed to retrieve applicant ID from storage:",t),null}}function mr(){try{localStorage.removeItem(Xe.APPLICANT_ID)}catch(t){console.warn("Failed to clear applicant ID from storage:",t)}}function yr(t){try{localStorage.setItem(Xe.WORKFLOW_STATE,JSON.stringify(t))}catch(r){console.warn("Failed to save workflow state to storage:",r)}}function Qr(){try{const t=localStorage.getItem(Xe.WORKFLOW_STATE);return t?JSON.parse(t):null}catch(t){return console.warn("Failed to retrieve workflow state from storage:",t),null}}function xr(){try{localStorage.removeItem(Xe.WORKFLOW_STATE)}catch(t){console.warn("Failed to clear workflow state from storage:",t)}}function Gr(){mr(),xr()}function hr(t){const{createOrchestrator:r}=we(),[s,a]=o.useState(null),[n,l]=o.useState(!1),[c,u]=o.useState(null),y=o.useRef(null),m=t||pr();o.useEffect(()=>{y.current||(y.current=r())},[r]),o.useEffect(()=>{var L;s&&m&&(ur(m),yr({applicantId:m,currentStepOrder:(L=s.currentStep)==null?void 0:L.order,status:s.status,lastUpdated:new Date().toISOString(),workflowKey:s.workFlowKey,nextWorkflowKey:s.nextWorkflowKey}))},[s,m]);const w=o.useRef(!1),T=o.useRef(!1),N=o.useCallback(async()=>{if(!(!m||!y.current)){if(w.current){console.log("[Workflow] Load already in progress, skipping...");return}w.current=!0,l(!0),u(null);try{const L=await y.current.initialize(m);a(L),T.current=!0}catch(L){u(L)}finally{l(!1),w.current=!1}}},[m]);o.useEffect(()=>{m&&!T.current&&N()},[m,N]);const F=o.useCallback(async()=>{if(y.current){if(w.current){console.log("[Workflow] Refresh already in progress, skipping...");return}w.current=!0,l(!0),u(null);try{const L=await y.current.refreshProgress();a(L)}catch(L){u(L)}finally{l(!1),w.current=!1}}},[]),f=o.useCallback(async()=>{if(y.current){l(!0),u(null);try{const L=await y.current.moveToNextStep();a(L)}catch(L){u(L)}finally{l(!1)}}},[]),j=o.useCallback(async()=>{if(y.current){l(!0),u(null);try{const L=await y.current.moveToPreviousStep();a(L)}catch(L){u(L)}finally{l(!1)}}},[]),P=o.useCallback(async L=>{if(y.current){l(!0),u(null);try{await y.current.submitCurrentStep(L);const K=await y.current.refreshProgress();a(K)}catch(K){throw u(K),K}finally{l(!1)}}},[]),_=ft.useMemo(()=>s!=null&&s.stepInfoList?[...s.stepInfoList].sort((L,K)=>L.order-K.order):[],[s==null?void 0:s.stepInfoList]),H=ft.useMemo(()=>s?s.nextWorkflowKey&&s.nextWorkflowKey!==s.workFlowKey:!1,[s]);return{progress:s,applicantId:m,currentStep:(s==null?void 0:s.currentStep)||null,steps:_,status:(s==null?void 0:s.status)||Re.None,workflowResult:(s==null?void 0:s.workflowResult)||null,workflowKey:s==null?void 0:s.workFlowKey,nextWorkflowKey:s==null?void 0:s.nextWorkflowKey,hasWorkflowChanged:H,isLoading:n,error:c,isComplete:(s==null?void 0:s.status)===Re.Finished,isOnHold:(s==null?void 0:s.status)===Re.OnHold,refreshProgress:F,moveToNext:f,moveBack:j,submitCurrentStep:P,orchestrator:y.current}}function fr(t){const{questionnaireService:r,applicantService:s}=we(),[a,n]=o.useState(null),[l,c]=o.useState({}),[u,y]=o.useState(!1),[m,w]=o.useState(!1),[T,N]=o.useState(null),F=o.useRef(!1),f=o.useRef(null),j=o.useCallback(async()=>{var _,H;if(t){if(F.current){console.log("[Questionnaire] Load already in progress, skipping...");return}F.current=!0,y(!0),N(null);try{const[L,K]=await Promise.all([r.getQuestionnaire(t),s.getApplicantData(t).catch(()=>null)]);if(n(L),(_=K==null?void 0:K.questionnaireResults)!=null&&_.length&&L){const W=new Map;for(const g of K.questionnaireResults)g.question&&((H=g.answers)!=null&&H.length)&&W.set(g.question.trim().toLowerCase(),g.answers);const Y={},I=L.questionGroups.flatMap(g=>g.questions??[]);for(const g of I){const z=g.text.trim().toLowerCase();W.has(z)&&(Y[g.id]=W.get(z))}c(Y)}f.current=t}catch(L){N(L)}finally{y(!1),F.current=!1}}},[t,r,s]);o.useEffect(()=>{t&&f.current!==t&&j()},[t]);const P=o.useCallback(async _=>{w(!0),N(null);try{return await r.fillQuestionnaire(_)}catch(H){throw N(H),H}finally{w(!1)}},[r]);return{questionnaire:a,initialAnswers:l,isLoading:u,isSubmitting:m,error:T,load:j,submit:P}}function gr(t){const{uploadDocumentService:r}=we(),[s,a]=o.useState(null),[n,l]=o.useState(!1),[c,u]=o.useState(!1),[y,m]=o.useState(0),[w,T]=o.useState(null),N=o.useRef(!1),F=o.useRef(null),f=o.useCallback(async()=>{if(t){if(N.current){console.log("[UploadDocument] Load already in progress, skipping...");return}N.current=!0,l(!0),T(null);try{const P=await r.getUploadDocument(t);a(P),F.current=t}catch(P){T(P)}finally{l(!1),N.current=!1}}},[t,r]);o.useEffect(()=>{t&&F.current!==t&&f()},[t]);const j=o.useCallback(async P=>{u(!0),m(0),T(null);try{await r.fillUploadDocument(P),m(100)}catch(_){throw T(_),_}finally{u(!1)}},[r]);return{uploadDocument:s,isLoading:n,isSubmitting:c,uploadProgress:y,error:w,load:f,submit:j}}function Jr(t){const{appropriatenessTestService:r}=we(),[s,a]=o.useState(null),[n,l]=o.useState(!1),[c,u]=o.useState(!1),[y,m]=o.useState(null),[w,T]=o.useState(null),N=o.useRef(!1),F=o.useRef(null),f=o.useCallback(async()=>{if(t){if(N.current){console.log("[AppropriatenessTest] Load already in progress, skipping...");return}N.current=!0,l(!0),m(null);try{const P=await r.getAppropriatenessTest(t);a(P),F.current=t}catch(P){m(P)}finally{l(!1),N.current=!1}}},[t,r]);o.useEffect(()=>{t&&F.current!==t&&f()},[t]);const j=o.useCallback(async P=>{u(!0),m(null);try{const _=await r.fillAppropriatenessTest(P);return T(_),_}catch(_){throw m(_),_}finally{u(!1)}},[r]);return{test:s,result:w,isLoading:n,isSubmitting:c,error:y,load:f,submit:j}}function br(t){const{overviewService:r}=we(),[s,a]=o.useState(null),[n,l]=o.useState(!1),[c,u]=o.useState(!1),[y,m]=o.useState(null),w=o.useRef(!1),T=o.useRef(null),N=o.useCallback(async()=>{if(t){if(w.current){console.log("[Overview] Load already in progress, skipping...");return}w.current=!0,l(!0),m(null);try{const f=await r.getOverviewData(t);a(f),T.current=t}catch(f){m(f)}finally{l(!1),w.current=!1}}},[t,r]);o.useEffect(()=>{t&&T.current!==t&&N()},[t]);const F=o.useCallback(async()=>{if(t){u(!0),m(null);try{await r.passOverview(t)}catch(f){throw m(f),f}finally{u(!1)}}},[t,r]);return{overview:s,isLoading:n,isSubmitting:c,error:y,load:N,passOverview:F}}function vr(t){const{identityService:r}=we(),[s,a]=o.useState(null),[n,l]=o.useState(!1),[c,u]=o.useState(null),y=o.useRef(!1),m=o.useCallback(async(N,F)=>{if(t){if(y.current){console.log("[Identity] Request already in progress, skipping...");return}y.current=!0,l(!0),u(null);try{const f={applicantId:t,restart:!1,redirectUrl:N||"",ttl:F||604800};console.log("Identity request input:",f);const j=await r.identityRequest(f);return console.log("Identity request result:",j),a(j),j}catch(f){throw u(f),f}finally{l(!1),y.current=!1}}},[t,r]),w=o.useCallback(async(N,F)=>{if(t){l(!0),u(null);try{const f={applicantId:t,restart:!1,redirectUrl:N,ttl:F},j=await r.identityCompanyRequest(f);return a(j),j}catch(f){throw u(f),f}finally{l(!1)}}},[t,r]),T=o.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 N={applicantId:t,restart:!0,redirectUrl:"",ttl:604800};console.log("Restarting identity with input:",N);const F=await r.identityRequest(N);return console.log("Restart identity result:",F),a(F),F}catch(N){throw u(N),N}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:n,error:c,requestIdentity:m,requestCompanyIdentity:w,restartIdentity:T}}function kr(t){const{riskScoringService:r,applicantService:s}=we(),[a,n]=o.useState(null),[l,c]=o.useState({}),[u,y]=o.useState(!1),[m,w]=o.useState(!1),[T,N]=o.useState(null),[F,f]=o.useState(null),j=o.useRef(!1),P=o.useRef(null),_=o.useCallback(async()=>{var L;if(t){if(j.current){console.log("[RiskScoring] Load already in progress, skipping...");return}j.current=!0,y(!0),N(null);try{const[K,W]=await Promise.all([r.getRiskCriterias(t),s.getApplicantData(t).catch(()=>null)]);if(n(K),(L=W==null?void 0:W.riskScoringResults)!=null&&L.length){const Y=W.riskScoringResults[0],I={};for(const g of Y.riskCriteriaResults??[])if(g.riskCriteriaId!=null&&g.answer!=null&&g.answer!==""){const z=[...new Set(g.answer.split(",").map($=>$.trim()).filter($=>$!==""))];z.length>0&&(I[g.riskCriteriaId]=z)}c(I)}P.current=t}catch(K){N(K)}finally{y(!1),j.current=!1}}},[t,r,s]);o.useEffect(()=>{t&&P.current!==t&&_()},[t]);const H=o.useCallback(async L=>{w(!0),N(null);try{const K=await r.submitRiskScoring(L);return f(K),K}catch(K){throw N(K),K}finally{w(!1)}},[r]);return{criteria:a,initialAnswers:l,result:F,isLoading:u,isSubmitting:m,error:T,load:_,submit:H}}function yt(){const{applicantService:t,config:r}=we(),[s,a]=o.useState(!1),[n,l]=o.useState(null),c=o.useRef(!1),u=o.useRef(!1),y=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(F){const f=Math.random()*16|0;return(F==="x"?f:f&3|8).toString(16)}),m=o.useCallback(async F=>{var f;if(c.current)throw console.log("[Applicant] Create already in progress, skipping..."),new Error("Creation already in progress");c.current=!0,a(!0),l(null);try{if(F.applicantAdditionalDatas||(F.applicantAdditionalDatas=[]),(f=r.identityProviders)!=null&&f.sardinai){const P=y();console.log("[SardinAI] Generated session key:",P),F.applicantAdditionalDatas.push({paramName:"sessionKey",value:P})}return await t.createApplicant(F)}catch(j){throw l(j),j}finally{a(!1),c.current=!1}},[t,r]),w=o.useCallback(async F=>{a(!0),l(null);try{return await t.createCompanyApplicant(F)}catch(f){throw l(f),f}finally{a(!1)}},[t]),T=o.useCallback(async F=>{if(u.current)throw console.log("[Applicant] Data load already in progress, skipping..."),new Error("Data load already in progress");u.current=!0,a(!0),l(null);try{return await t.getApplicantData(F)}catch(f){throw l(f),f}finally{a(!1),u.current=!1}},[t]),N=o.useCallback(async F=>{a(!0),l(null);try{await t.stopProgress(F)}catch(f){throw l(f),f}finally{a(!1)}},[t]);return{isLoading:s,error:n,createApplicant:m,createCompanyApplicant:w,getApplicantData:T,stopProgress:N}}const Zr={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"}},V=({children:t,variant:r="primary",size:s="md",isLoading:a=!1,disabled:n,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",m={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:ve(y,m[s],l),style:{...Zr[r],...c},disabled:n||a,...u,children:[a&&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:a,rightIcon:n,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:[a&&e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:a}),e.jsx("input",{ref:y,className:ve("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",a?"pl-10":"",n?"pr-10":"",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}),n&&e.jsx("div",{className:"absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none",children:n})]}),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 J=({children:t,className:r,...s})=>e.jsx("div",{className:ve("metakyc-card rounded-xl shadow-sm border",r),style:{backgroundColor:"var(--metakyc-surface, #ffffff)",borderColor:"var(--metakyc-border, #e5e7eb)"},...s,children:t}),ye=({children:t,className:r,...s})=>e.jsx("div",{className:ve("px-6 py-4 border-b",r),style:{borderColor:"var(--metakyc-border, #e5e7eb)"},...s,children:t}),Z=({children:t,className:r,...s})=>e.jsx("div",{className:ve("px-6 py-4",r),...s,children:t}),xe=({children:t,className:r,...s})=>e.jsx("div",{className:ve("px-6 py-4 border-t",r),style:{borderColor:"var(--metakyc-border, #e5e7eb)"},...s,children:t}),Xr={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"}},xt=({children:t,variant:r="default",className:s,style:a,...n})=>e.jsx("span",{className:ve("inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium",s),style:{...Xr[r],...a},...n,children:t}),Ce=({size:t="md",className:r,...s})=>{const a={sm:"h-4 w-4",md:"h-8 w-8",lg:"h-12 w-12"};return e.jsx("div",{className:ve("flex items-center justify-center",r),...s,children:e.jsxs("svg",{className:ve("animate-spin text-primary-500",a[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"})]})})},ot=o.forwardRef(({label:t,error:r,helperText:s,options:a,placeholder:n,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:ve("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:[n&&e.jsx("option",{value:"",disabled:!0,style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:"var(--metakyc-text-secondary, #6b7280)"},children:n},"__placeholder__"),a.map((m,w)=>e.jsx("option",{value:m.value,disabled:m.disabled,style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:m.disabled?"var(--metakyc-text-muted, #9ca3af)":"var(--metakyc-input-text, var(--metakyc-text-primary, #111827))"},children:m.label},m.value||`option-${w}`))]}),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})]}));ot.displayName="Select";const gt=280,jr=({label:t,value:r,onChange:s,options:a,placeholder:n="Select...",disabled:l=!1,required:c=!1})=>{const[u,y]=o.useState(!1),[m,w]=o.useState(""),[T,N]=o.useState(null),[F,f]=o.useState({bg:"#ffffff",borderColor:"#d1d5db",textPrimary:"#111827",textSecondary:"#6b7280",primaryColor:"#2563eb",primaryLight:"#eff6ff",hoverBg:"#f9fafb"}),j=o.useRef(null),P=o.useRef(null),_=o.useRef(null),H=o.useCallback(()=>{if(!P.current)return null;const A=P.current.getBoundingClientRect(),X=window.innerHeight-A.bottom<gt&&A.top>gt;return{top:X?A.top:A.bottom+4,left:A.left,width:A.width,openUp:X}},[]),L=o.useCallback(()=>{const A=getComputedStyle(document.documentElement),U=(le,B)=>A.getPropertyValue(le).trim()||B,X=U("--metakyc-input-bg",U("--metakyc-background","#ffffff"));f({bg:X,borderColor:U("--metakyc-input-border",U("--metakyc-border","#d1d5db")),textPrimary:U("--metakyc-input-text",U("--metakyc-text-primary","#111827")),textSecondary:U("--metakyc-text-secondary","#6b7280"),primaryColor:U("--metakyc-primary","#2563eb"),primaryLight:U("--metakyc-primary-light","#eff6ff"),hoverBg:U("--metakyc-surface",X)})},[]),K=o.useCallback(()=>{if(l)return;L();const A=H();A&&N(A),y(!0)},[l,H,L]),W=o.useCallback(()=>{y(!1),w("")},[]);o.useEffect(()=>{if(!u)return;const A=U=>{var le,B;const X=U.target;!((le=j.current)!=null&&le.contains(X))&&!((B=_.current)!=null&&B.contains(X))&&W()};return document.addEventListener("mousedown",A),()=>document.removeEventListener("mousedown",A)},[u,W]),o.useEffect(()=>{if(!u)return;const A=()=>{const U=H();U&&N(U)};return window.addEventListener("scroll",A,!0),window.addEventListener("resize",A),()=>{window.removeEventListener("scroll",A,!0),window.removeEventListener("resize",A)}},[u,H]);const Y=a.filter(A=>A.label.toLowerCase().includes(m.toLowerCase())),I=A=>{l||s(r.includes(A)?r.filter(U=>U!==A):[...r,A])},g=(A,U)=>{U.stopPropagation(),l||s(r.filter(X=>X!==A))},z=A=>{var U;return((U=a.find(X=>X.value===A))==null?void 0:U.label)||A},{bg:$,borderColor:D,textPrimary:M,textSecondary:te,primaryColor:re,primaryLight:ee,hoverBg:ue}=F,oe=u&&T&&e.jsxs("div",{ref:_,className:"metakyc-multiselect-dropdown",style:{position:"fixed",top:T.openUp?void 0:T.top,bottom:T.openUp?window.innerHeight-T.top+4:void 0,left:T.left,width:T.width,zIndex:99999,borderRadius:"8px",boxShadow:"0 4px 16px rgba(0,0,0,0.18)",border:`1px solid ${D}`,backgroundColor:$,overflow:"hidden"},children:[e.jsx("div",{style:{padding:"8px",borderBottom:`1px solid ${D}`},children:e.jsx("input",{type:"text",value:m,onChange:A=>w(A.target.value),placeholder:"Search...",autoFocus:!0,onClick:A=>A.stopPropagation(),className:"metakyc-multiselect-search w-full",style:{display:"block",width:"100%",padding:"6px 8px",fontSize:"13px",borderRadius:"6px",border:`1px solid ${D}`,backgroundColor:$,color:M,outline:"none",boxSizing:"border-box"},onFocus:A=>{const U=getComputedStyle(document.documentElement),X=U.getPropertyValue("--metakyc-input-border-focus").trim()||U.getPropertyValue("--metakyc-primary").trim()||"#2563eb";A.currentTarget.style.backgroundColor=$,A.currentTarget.style.color=M,A.currentTarget.style.borderColor=X,A.currentTarget.style.outline="none",A.currentTarget.style.boxShadow=`0 0 0 2px ${X}33`},onBlur:A=>{A.currentTarget.style.backgroundColor=$,A.currentTarget.style.color=M,A.currentTarget.style.borderColor=D,A.currentTarget.style.outline="none",A.currentTarget.style.boxShadow="none"}})}),e.jsx("ul",{style:{listStyle:"none",margin:0,padding:"4px 0",maxHeight:"192px",overflowY:"auto"},children:Y.length===0?e.jsx("li",{style:{padding:"8px 12px",fontSize:"13px",color:te},children:"No results"}):Y.map(A=>{const U=r.includes(A.value);return e.jsxs("li",{onClick:()=>I(A.value),className:"metakyc-multiselect-option",style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",fontSize:"13px",cursor:"pointer",backgroundColor:U?ee:"transparent",color:U?re:M,userSelect:"none"},onMouseEnter:X=>{U||(X.currentTarget.style.backgroundColor=ue)},onMouseLeave:X=>{U||(X.currentTarget.style.backgroundColor="transparent")},children:[e.jsx("input",{type:"checkbox",checked:U,readOnly:!0,style:{accentColor:re,pointerEvents:"none",flexShrink:0}}),e.jsx("span",{children:A.label})]},A.value)})}),r.length>0&&e.jsx("div",{style:{padding:"6px 12px",borderTop:`1px solid ${D}`},children:e.jsxs("button",{type:"button",onClick:()=>{s([]),w("")},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:j,children:[t&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[t,c&&e.jsx("span",{style:{color:"var(--metakyc-error, #ef4444)",marginLeft:"4px"},children:"*"})]}),e.jsxs("div",{ref:P,onClick:()=>u?W():K(),className:ve("metakyc-multiselect-trigger","min-h-[42px] w-full px-3 py-2 rounded-lg border text-sm transition-colors relative",l?"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:n}):e.jsx("div",{className:"flex flex-wrap gap-1 pr-6",children:r.map(A=>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:[z(A),!l&&e.jsx("button",{type:"button",onClick:U=>g(A,U),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:"×"})]},A))}),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"&&oe?it.createPortal(oe,document.body):null]})},bt=260,Ae=({label:t,error:r,helperText:s,options:a,placeholder:n="Select...",value:l,onChange:c,disabled:u=!1,required:y=!1,className:m})=>{var B;const[w,T]=o.useState(!1),[N,F]=o.useState(""),[f,j]=o.useState(null),[P,_]=o.useState({bg:"#ffffff",border:"#d1d5db",text:"#111827",textSecondary:"#6b7280",primary:"#2563eb",primaryLight:"#eff6ff",hoverBg:"#f9fafb"}),H=o.useCallback(()=>{const b=getComputedStyle(document.documentElement),G=(ie,ke)=>b.getPropertyValue(ie).trim()||ke,Q=G("--metakyc-input-bg",G("--metakyc-background","#ffffff"));_({bg:Q,border:G("--metakyc-input-border",G("--metakyc-border","#d1d5db")),text:G("--metakyc-input-text",G("--metakyc-text-primary","#111827")),textSecondary:G("--metakyc-text-secondary","#6b7280"),primary:G("--metakyc-primary","#2563eb"),primaryLight:G("--metakyc-primary-light","#eff6ff"),hoverBg:G("--metakyc-surface",Q)})},[]),L=o.useRef(null),K=o.useRef(null),W=o.useRef(null),Y=o.useRef(null),I=o.useCallback(()=>{if(!K.current)return null;const b=K.current.getBoundingClientRect(),Q=window.innerHeight-b.bottom<bt&&b.top>bt;return{top:Q?b.top:b.bottom+4,left:b.left,width:b.width,openUp:Q}},[]),g=o.useCallback(()=>{if(u)return;H();const b=I();b&&j(b),T(!0)},[u,I,H]),z=o.useCallback(()=>{T(!1),F("")},[]),$=()=>w?z():g();o.useEffect(()=>{if(!w)return;const b=G=>{var ie,ke;const Q=G.target;!((ie=L.current)!=null&&ie.contains(Q))&&!((ke=W.current)!=null&&ke.contains(Q))&&z()};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[w,z]),o.useEffect(()=>{if(!w)return;const b=()=>{const G=I();G&&j(G)};return window.addEventListener("scroll",b,!0),window.addEventListener("resize",b),()=>{window.removeEventListener("scroll",b,!0),window.removeEventListener("resize",b)}},[w,I]),o.useEffect(()=>{w&&Y.current&&setTimeout(()=>{var b;return(b=Y.current)==null?void 0:b.focus()},0)},[w]);const D=a.filter(b=>b.label.toLowerCase().includes(N.toLowerCase())||b.value.toLowerCase().includes(N.toLowerCase())),M=(B=a.find(b=>b.value===l))==null?void 0:B.label,te=(b,G)=>{u||G||(c(b),z())},{bg:re,border:ee,text:ue,textSecondary:oe,primary:A,primaryLight:U,hoverBg:X}=P,le=w&&f&&e.jsxs("div",{ref:W,className:"metakyc-searchable-select-dropdown",style:{position:"fixed",top:f.openUp?void 0:f.top,bottom:f.openUp?window.innerHeight-f.top+4:void 0,left:f.left,width:f.width,zIndex:99999,borderRadius:"8px",boxShadow:"0 4px 16px rgba(0,0,0,0.18)",border:`1px solid ${ee}`,backgroundColor:re,overflow:"hidden"},children:[e.jsx("div",{style:{padding:"8px",borderBottom:`1px solid ${ee}`},children:e.jsx("input",{ref:Y,type:"text",value:N,onChange:b=>F(b.target.value),placeholder:"Search...",onClick:b=>b.stopPropagation(),className:"metakyc-searchable-select-search w-full",style:{display:"block",width:"100%",padding:"6px 8px",fontSize:"13px",borderRadius:"6px",border:`1px solid ${ee}`,backgroundColor:re,color:ue,outline:"none",boxSizing:"border-box"},onFocus:b=>{const G=getComputedStyle(document.documentElement),Q=G.getPropertyValue("--metakyc-input-border-focus").trim()||G.getPropertyValue("--metakyc-primary").trim()||"#2563eb";b.currentTarget.style.backgroundColor=re,b.currentTarget.style.color=ue,b.currentTarget.style.borderColor=Q,b.currentTarget.style.outline="none",b.currentTarget.style.boxShadow=`0 0 0 2px ${Q}33`},onBlur:b=>{b.currentTarget.style.backgroundColor=re,b.currentTarget.style.color=ue,b.currentTarget.style.borderColor=ee,b.currentTarget.style.outline="none",b.currentTarget.style.boxShadow="none"}})}),e.jsx("ul",{style:{listStyle:"none",margin:0,padding:"4px 0",maxHeight:"208px",overflowY:"auto"},children:D.length===0?e.jsx("li",{style:{padding:"8px 12px",fontSize:"13px",color:oe},children:"No results"}):D.map(b=>{const G=b.value===l;return e.jsx("li",{className:"metakyc-searchable-select-option",onClick:()=>te(b.value,b.disabled),style:{padding:"8px 12px",fontSize:"13px",cursor:b.disabled?"not-allowed":"pointer",opacity:b.disabled?.4:1,backgroundColor:G?U:"transparent",color:G?A:ue,userSelect:"none"},onMouseEnter:Q=>{!G&&!b.disabled&&(Q.currentTarget.style.backgroundColor=X)},onMouseLeave:Q=>{G||(Q.currentTarget.style.backgroundColor="transparent")},children:b.label},b.value)})})]});return e.jsxs("div",{className:ve("w-full metakyc-searchable-select",m),ref:L,children:[t&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[t,y&&e.jsx("span",{style:{color:"var(--metakyc-error, #ef4444)",marginLeft:"4px"},children:"*"})]}),e.jsxs("div",{ref:K,role:"button",tabIndex:u?-1:0,onClick:$,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),$()),b.key==="Escape"&&z()},className:ve("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",u?"opacity-60 cursor-not-allowed":"cursor-pointer"),style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:M?"var(--metakyc-input-text, var(--metakyc-text-primary, #111827))":"var(--metakyc-input-placeholder, var(--metakyc-text-muted, #9ca3af))",borderColor:r?"var(--metakyc-danger, #ef4444)":w?"var(--metakyc-input-border-focus, var(--metakyc-primary, #2563eb))":"var(--metakyc-input-border, var(--metakyc-border, #d1d5db))",minHeight:"42px",outline:w?"2px solid var(--metakyc-input-border-focus, var(--metakyc-primary, #2563eb))":"none",outlineOffset:"-1px"},children:[e.jsx("span",{className:"truncate flex-1",children:M||n}),e.jsx("span",{className:"flex-shrink-0 text-xs pointer-events-none",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:w?"▲":"▼"})]}),typeof document<"u"&&le?it.createPortal(le,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})]})};Ae.displayName="SearchableSelect";function es(t){const r=t.type;return r.startsWith("image/")?"image":r==="application/pdf"?"pdf":"file"}const wr=({label:t,subtitle:r,error:s,accept:a,multiple:n=!1,maxSize:l,required:c,onChange:u,value:y=[],className:m})=>{const[w,T]=o.useState(!1),[N,F]=o.useState(null),f=o.useRef(null),j=o.useCallback(I=>{if(!I)return;F(null);const g=Array.from(I);if(l&&g.filter($=>$.size>l).length>0){F(`File exceeds the maximum size of ${nt(l)}`);return}u==null||u(n?[...y,...g]:[g[0]])},[l,n,u,y]),P=o.useCallback(I=>{I.preventDefault(),I.stopPropagation(),T(!0)},[]),_=o.useCallback(I=>{I.preventDefault(),I.stopPropagation(),T(!1)},[]),H=o.useCallback(I=>{I.preventDefault(),I.stopPropagation(),T(!1),j(I.dataTransfer.files)},[j]),L=()=>{var I;(I=f.current)==null||I.click()},K=I=>{F(null);const g=y.filter((z,$)=>$!==I);u==null||u(g)},W=s||N,Y=y.length>0;return e.jsxs("div",{className:ve("metakyc-file-upload",m),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:P,onDragLeave:_,onDrop:H,style:{border:`2px dashed ${W?"var(--metakyc-danger, #ef4444)":w?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #d1d5db)"}`,borderRadius:"12px",padding:Y?"20px":"32px 20px",textAlign:"center",cursor:"pointer",transition:"all 0.2s ease",backgroundColor:w?"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:a,multiple:n,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:w?"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:w?"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"]}),(a||l)&&e.jsxs("p",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"4px"},children:[a&&e.jsx("span",{children:a}),a&&l&&e.jsx("span",{children:" · "}),l&&e.jsxs("span",{children:["Max ",nt(l)]})]})]})]})]}),Y&&e.jsx("div",{style:{marginTop:"12px",display:"flex",flexDirection:"column",gap:"8px"},children:y.map((I,g)=>{const z=es(I),$=z==="image",D=$?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:$?"transparent":"color-mix(in srgb, var(--metakyc-primary, #2563eb) 10%, transparent)"},children:$&&D?e.jsx("img",{src:D,alt:I.name,style:{width:"100%",height:"100%",objectFit:"cover",borderRadius:"8px"}}):z==="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:nt(I.size)})]}),e.jsx("button",{type:"button",onClick:M=>{M.stopPropagation(),K(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:M=>{M.currentTarget.style.backgroundColor="color-mix(in srgb, var(--metakyc-danger, #ef4444) 10%, transparent)",M.currentTarget.style.color="var(--metakyc-danger, #ef4444)"},onMouseLeave:M=>{M.currentTarget.style.backgroundColor="transparent",M.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}-${g}`)})}),W&&e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",marginTop:"6px"},children:W})]})},Sr=o.forwardRef(({countryCode:t="+1",onCountryCodeChange:r,className:s,...a},n)=>e.jsxs("div",{className:"w-full",children:[a.label&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[a.label,a.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:ve("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:n,type:"tel",className:ve("flex-1",s),...a,label:""})]}),a.error&&e.jsx("p",{className:"mt-1 text-sm text-danger-500",children:a.error})]}));Sr.displayName="PhoneInput";/**
32
+ `}class yr{constructor(r){ye(this,"currentTheme",Ie);ye(this,"customStyleElement",null);ye(this,"inputStyleElement",null);ye(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 a;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(([n,o])=>{o&&this.container.style.setProperty(`--metakyc-${n}`,o)}),this.injectInputColors(),(a=this.currentTheme.darkMode)!=null&&a.colors&&this.applyDarkModeColors(this.currentTheme.darkMode.colors)}applyDarkModeColors(r){Object.entries(r).forEach(([s,a])=>{if(a){const n=`--metakyc-dark-${this.kebabCase(s)}`;this.container.style.setProperty(n,a)}})}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,a])=>{this.container.style.setProperty(`--metakyc-font-size-${s}`,a)}),r.fontWeight&&Object.entries(r.fontWeight).forEach(([s,a])=>{this.container.style.setProperty(`--metakyc-font-weight-${s}`,a.toString())}))}applySpacing(r){r&&Object.entries(r).forEach(([s,a])=>{const n=`--metakyc-${this.kebabCase(s)}`;this.container.style.setProperty(n,a)})}injectInputColors(){this.inputStyleElement&&this.inputStyleElement.remove(),this.inputStyleElement=document.createElement("style"),this.inputStyleElement.id="metakyc-input-colors",this.inputStyleElement.textContent=Qr(),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||Ie.name,title:r.title||Ie.title,logo:{...Ie.logo,...r.logo},colors:{...Ie.colors,...r.colors},typography:r.typography?{...Ie.typography,...r.typography}:Ie.typography,spacing:r.spacing?{...Ie.spacing,...r.spacing}:Ie.spacing,customCSS:r.customCSS,darkMode:r.darkMode?{colors:{...(s=Ie.darkMode)==null?void 0:s.colors,...r.darkMode.colors}}:Ie.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(Ie)}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),Gr=({config:t,children:r})=>{const[s,a]=i.useState(null),n=i.useRef(!1),o=i.useRef(!1),c=i.useMemo(()=>{const m=new Ut(t),p=new Kt(m),I=new qt(m),P=new Yt(m),g=new Vt(m),A=new Qt(m),N=new Gt(m),k=new Jt(m),b=new Zt(m),_=new Xt(m),U=new ir(m),L=new yr;return{httpClient:m,applicantService:p,questionnaireService:I,uploadDocumentService:P,appropriatenessTestService:g,overviewService:A,riskScoringService:N,identityService:k,baseInformationService:b,investorCategorizationService:_,themeService:U,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(n.current||o.current){console.log("[MetaKYC] Theme already loading or loaded, skipping...");return}n.current=!0;try{if(t.theme){console.log("[MetaKYC] Applying static theme from config"),c.themeManager.applyTheme(t.theme),a(c.themeManager.getCurrentTheme()),o.current=!0;return}console.log("[MetaKYC] Fetching theme from backend...");const p=await c.themeService.getThemeConfiguration();c.themeManager.applyTheme(p),a(c.themeManager.getCurrentTheme()),o.current=!0,console.log("[MetaKYC] Theme loaded and applied",p)}catch(p){console.warn("[MetaKYC] Failed to load theme, using default:",p),a(c.themeManager.getCurrentTheme()),o.current=!0}finally{n.current=!1}})(),()=>{c.themeManager.cleanup()}),[]),e.jsx(gt.Provider,{value:u,children:r})};function Re(){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 a=new FileReader;a.readAsDataURL(t),a.onload=()=>{const o=a.result.split(",")[1];r(o)},a.onerror=n=>s(n)})}function Jr(t,r){return t.size<=r}function Zr(t,r){return r.split(",").map(a=>a.trim()).some(a=>{if(a.endsWith("/*")){const n=a.slice(0,-2);return t.type.startsWith(n)}return t.type===a})}function dt(t){if(t===0)return"0 Bytes";const r=1024,s=["Bytes","KB","MB","GB"],a=Math.floor(Math.log(t)/Math.log(r));return Math.round(t/Math.pow(r,a)*100)/100+" "+s[a]}function Xr(t){return t}function Ce(...t){return t.filter(Boolean).join(" ")}const at={APPLICANT_ID:"metakyc_applicant_id",WORKFLOW_STATE:"metakyc_workflow_state"};function hr(t){try{localStorage.setItem(at.APPLICANT_ID,t.toString())}catch(r){console.warn("Failed to save applicant ID to storage:",r)}}function fr(){try{const t=localStorage.getItem(at.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(at.APPLICANT_ID)}catch(t){console.warn("Failed to clear applicant ID from storage:",t)}}function br(t){try{localStorage.setItem(at.WORKFLOW_STATE,JSON.stringify(t))}catch(r){console.warn("Failed to save workflow state to storage:",r)}}function es(){try{const t=localStorage.getItem(at.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(at.WORKFLOW_STATE)}catch(t){console.warn("Failed to clear workflow state from storage:",t)}}function ts(){gr(),vr()}function kr(t){const{createOrchestrator:r}=Re(),[s,a]=i.useState(null),[n,o]=i.useState(!1),[c,u]=i.useState(null),m=i.useRef(null),p=t||fr();i.useEffect(()=>{m.current||(m.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 I=i.useRef(!1),P=i.useRef(!1),g=i.useCallback(async()=>{if(!(!p||!m.current)){if(I.current){console.log("[Workflow] Load already in progress, skipping...");return}I.current=!0,o(!0),u(null);try{const L=await m.current.initialize(p);a(L),P.current=!0}catch(L){u(L)}finally{o(!1),I.current=!1}}},[p]);i.useEffect(()=>{p&&!P.current&&g()},[p,g]);const A=i.useCallback(async()=>{if(m.current){if(I.current){console.log("[Workflow] Refresh already in progress, skipping...");return}I.current=!0,o(!0),u(null);try{const L=await m.current.refreshProgress();a(L)}catch(L){u(L)}finally{o(!1),I.current=!1}}},[]),N=i.useCallback(async()=>{if(m.current){o(!0),u(null);try{const L=await m.current.moveToNextStep();a(L)}catch(L){u(L)}finally{o(!1)}}},[]),k=i.useCallback(async()=>{if(m.current){o(!0),u(null);try{const L=await m.current.moveToPreviousStep();a(L)}catch(L){u(L)}finally{o(!1)}}},[]),b=i.useCallback(async L=>{if(m.current){o(!0),u(null);try{await m.current.submitCurrentStep(L);const B=await m.current.refreshProgress();a(B)}catch(B){throw u(B),B}finally{o(!1)}}},[]),_=jt.useMemo(()=>s!=null&&s.stepInfoList?[...s.stepInfoList].sort((L,B)=>L.order-B.order):[],[s==null?void 0:s.stepInfoList]),U=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:_,status:(s==null?void 0:s.status)||Te.None,workflowResult:(s==null?void 0:s.workflowResult)||null,workflowKey:s==null?void 0:s.workFlowKey,nextWorkflowKey:s==null?void 0:s.nextWorkflowKey,hasWorkflowChanged:U,isLoading:n,error:c,isComplete:(s==null?void 0:s.status)===Te.Finished,isOnHold:(s==null?void 0:s.status)===Te.OnHold,refreshProgress:A,moveToNext:N,moveBack:k,submitCurrentStep:b,orchestrator:m.current}}function jr(t){const{questionnaireService:r,applicantService:s}=Re(),[a,n]=i.useState(null),[o,c]=i.useState({}),[u,m]=i.useState(!1),[p,I]=i.useState(!1),[P,g]=i.useState(null),A=i.useRef(!1),N=i.useRef(null),k=i.useCallback(async()=>{var _,U;if(t){if(A.current){console.log("[Questionnaire] Load already in progress, skipping...");return}A.current=!0,m(!0),g(null);try{const[L,B]=await Promise.all([r.getQuestionnaire(t),s.getApplicantData(t).catch(()=>null)]);if(n(L),(_=B==null?void 0:B.questionnaireResults)!=null&&_.length&&L){const K=new Map;for(const h of B.questionnaireResults)h.question&&((U=h.answers)!=null&&U.length)&&K.set(h.question.trim().toLowerCase(),h.answers);const X={},C=L.questionGroups.flatMap(h=>h.questions??[]);for(const h of C){const M=h.text.trim().toLowerCase();K.has(M)&&(X[h.id]=K.get(M))}c(X)}N.current=t}catch(L){g(L)}finally{m(!1),A.current=!1}}},[t,r,s]);i.useEffect(()=>{t&&N.current!==t&&k()},[t]);const b=i.useCallback(async _=>{I(!0),g(null);try{return await r.fillQuestionnaire(_)}catch(U){throw g(U),U}finally{I(!1)}},[r]);return{questionnaire:a,initialAnswers:o,isLoading:u,isSubmitting:p,error:P,load:k,submit:b}}function wr(t){const{uploadDocumentService:r}=Re(),[s,a]=i.useState(null),[n,o]=i.useState(!1),[c,u]=i.useState(!1),[m,p]=i.useState(0),[I,P]=i.useState(null),g=i.useRef(!1),A=i.useRef(null),N=i.useCallback(async()=>{if(t){if(g.current){console.log("[UploadDocument] Load already in progress, skipping...");return}g.current=!0,o(!0),P(null);try{const b=await r.getUploadDocument(t);a(b),A.current=t}catch(b){P(b)}finally{o(!1),g.current=!1}}},[t,r]);i.useEffect(()=>{t&&A.current!==t&&N()},[t]);const k=i.useCallback(async b=>{u(!0),p(0),P(null);try{await r.fillUploadDocument(b),p(100)}catch(_){throw P(_),_}finally{u(!1)}},[r]);return{uploadDocument:s,isLoading:n,isSubmitting:c,uploadProgress:m,error:I,load:N,submit:k}}function rs(t){const{appropriatenessTestService:r}=Re(),[s,a]=i.useState(null),[n,o]=i.useState(!1),[c,u]=i.useState(!1),[m,p]=i.useState(null),[I,P]=i.useState(null),g=i.useRef(!1),A=i.useRef(null),N=i.useCallback(async()=>{if(t){if(g.current){console.log("[AppropriatenessTest] Load already in progress, skipping...");return}g.current=!0,o(!0),p(null);try{const b=await r.getAppropriatenessTest(t);a(b),A.current=t}catch(b){p(b)}finally{o(!1),g.current=!1}}},[t,r]);i.useEffect(()=>{t&&A.current!==t&&N()},[t]);const k=i.useCallback(async b=>{u(!0),p(null);try{const _=await r.fillAppropriatenessTest(b);return P(_),_}catch(_){throw p(_),_}finally{u(!1)}},[r]);return{test:s,result:I,isLoading:n,isSubmitting:c,error:m,load:N,submit:k}}function Sr(t){const{overviewService:r}=Re(),[s,a]=i.useState(null),[n,o]=i.useState(!1),[c,u]=i.useState(!1),[m,p]=i.useState(null),I=i.useRef(!1),P=i.useRef(null),g=i.useCallback(async()=>{if(t){if(I.current){console.log("[Overview] Load already in progress, skipping...");return}I.current=!0,o(!0),p(null);try{const N=await r.getOverviewData(t);a(N),P.current=t}catch(N){p(N)}finally{o(!1),I.current=!1}}},[t,r]);i.useEffect(()=>{t&&P.current!==t&&g()},[t]);const A=i.useCallback(async()=>{if(t){u(!0),p(null);try{await r.passOverview(t)}catch(N){throw p(N),N}finally{u(!1)}}},[t,r]);return{overview:s,isLoading:n,isSubmitting:c,error:m,load:g,passOverview:A}}function Cr(t){const{identityService:r}=Re(),[s,a]=i.useState(null),[n,o]=i.useState(!1),[c,u]=i.useState(null),m=i.useRef(!1),p=i.useCallback(async(g,A)=>{if(t){if(m.current){console.log("[Identity] Request already in progress, skipping...");return}m.current=!0,o(!0),u(null);try{const N={applicantId:t,restart:!1,redirectUrl:g||"",ttl:A||604800};console.log("Identity request input:",N);const k=await r.identityRequest(N);return console.log("Identity request result:",k),a(k),k}catch(N){throw u(N),N}finally{o(!1),m.current=!1}}},[t,r]),I=i.useCallback(async(g,A)=>{if(t){o(!0),u(null);try{const N={applicantId:t,restart:!1,redirectUrl:g,ttl:A},k=await r.identityCompanyRequest(N);return a(k),k}catch(N){throw u(N),N}finally{o(!1)}}},[t,r]),P=i.useCallback(async()=>{if(t){if(m.current){console.log("[Identity] Restart already in progress, skipping...");return}m.current=!0,o(!0),u(null);try{const g={applicantId:t,restart:!0,redirectUrl:"",ttl:604800};console.log("Restarting identity with input:",g);const A=await r.identityRequest(g);return console.log("Restart identity result:",A),a(A),A}catch(g){throw u(g),g}finally{o(!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:n,error:c,requestIdentity:p,requestCompanyIdentity:I,restartIdentity:P}}function Nr(t){const{riskScoringService:r,applicantService:s}=Re(),[a,n]=i.useState(null),[o,c]=i.useState({}),[u,m]=i.useState(!1),[p,I]=i.useState(!1),[P,g]=i.useState(null),[A,N]=i.useState(null),k=i.useRef(!1),b=i.useRef(null),_=i.useCallback(async()=>{var L;if(t){if(k.current){console.log("[RiskScoring] Load already in progress, skipping...");return}k.current=!0,m(!0),g(null);try{const[B,K]=await Promise.all([r.getRiskCriterias(t),s.getApplicantData(t).catch(()=>null)]);if(n(B),(L=K==null?void 0:K.riskScoringResults)!=null&&L.length){const X=K.riskScoringResults[0],C={};for(const h of X.riskCriteriaResults??[])if(h.riskCriteriaId!=null&&h.answer!=null&&h.answer!==""){const M=[...new Set(h.answer.split(",").map(Q=>Q.trim()).filter(Q=>Q!==""))];M.length>0&&(C[h.riskCriteriaId]=M)}c(C)}b.current=t}catch(B){g(B)}finally{m(!1),k.current=!1}}},[t,r,s]);i.useEffect(()=>{t&&b.current!==t&&_()},[t]);const U=i.useCallback(async L=>{I(!0),g(null);try{const B=await r.submitRiskScoring(L);return N(B),B}catch(B){throw g(B),B}finally{I(!1)}},[r]);return{criteria:a,initialAnswers:o,result:A,isLoading:u,isSubmitting:p,error:P,load:_,submit:U}}function bt(){const{applicantService:t,config:r}=Re(),[s,a]=i.useState(!1),[n,o]=i.useState(null),c=i.useRef(!1),u=i.useRef(!1),m=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(A){const N=Math.random()*16|0;return(A==="x"?N:N&3|8).toString(16)}),p=i.useCallback(async A=>{var N;if(c.current)throw console.log("[Applicant] Create already in progress, skipping..."),new Error("Creation already in progress");c.current=!0,a(!0),o(null);try{if(A.applicantAdditionalDatas||(A.applicantAdditionalDatas=[]),(N=r.identityProviders)!=null&&N.sardinai){const b=m();console.log("[SardinAI] Generated session key:",b),A.applicantAdditionalDatas.push({paramName:"sessionKey",value:b})}return await t.createApplicant(A)}catch(k){throw o(k),k}finally{a(!1),c.current=!1}},[t,r]),I=i.useCallback(async A=>{a(!0),o(null);try{return await t.createCompanyApplicant(A)}catch(N){throw o(N),N}finally{a(!1)}},[t]),P=i.useCallback(async A=>{if(u.current)throw console.log("[Applicant] Data load already in progress, skipping..."),new Error("Data load already in progress");u.current=!0,a(!0),o(null);try{return await t.getApplicantData(A)}catch(N){throw o(N),N}finally{a(!1),u.current=!1}},[t]),g=i.useCallback(async A=>{a(!0),o(null);try{await t.stopProgress(A)}catch(N){throw o(N),N}finally{a(!1)}},[t]);return{isLoading:s,error:n,createApplicant:p,createCompanyApplicant:I,getApplicantData:P,stopProgress:g}}const ss={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"}},Z=({children:t,variant:r="primary",size:s="md",isLoading:a=!1,disabled:n,className:o,style:c,...u})=>{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",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:Ce(m,p[s],o),style:{...ss[r],...c},disabled:n||a,...u,children:[a&&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]})},fe=i.forwardRef(({label:t,error:r,helperText:s,leftIcon:a,rightIcon:n,className:o,style:c,...u},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,u.required&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),e.jsxs("div",{className:"relative",children:[a&&e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:a}),e.jsx("input",{ref:m,className:Ce("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",a?"pl-10":"",n?"pr-10":"",o),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}),n&&e.jsx("div",{className:"absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none",children:n})]}),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})]}));fe.displayName="Input";const ee=({children:t,className:r,...s})=>e.jsx("div",{className:Ce("metakyc-card rounded-xl shadow-sm border",r),style:{backgroundColor:"var(--metakyc-surface, #ffffff)",borderColor:"var(--metakyc-border, #e5e7eb)"},...s,children:t}),ve=({children:t,className:r,...s})=>e.jsx("div",{className:Ce("px-6 py-4 border-b",r),style:{borderColor:"var(--metakyc-border, #e5e7eb)"},...s,children:t}),te=({children:t,className:r,...s})=>e.jsx("div",{className:Ce("px-6 py-4",r),...s,children:t}),ke=({children:t,className:r,...s})=>e.jsx("div",{className:Ce("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:a,...n})=>e.jsx("span",{className:Ce("inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium",s),style:{...as[r],...a},...n,children:t}),Ae=({size:t="md",className:r,...s})=>{const a={sm:"h-4 w-4",md:"h-8 w-8",lg:"h-12 w-12"};return e.jsx("div",{className:Ce("flex items-center justify-center",r),...s,children:e.jsxs("svg",{className:Ce("animate-spin text-primary-500",a[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:a,placeholder:n,className:o,style:c,...u},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,u.required&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),e.jsxs("select",{ref:m,className:Ce("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":"",o),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:[n&&e.jsx("option",{value:"",disabled:!0,style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:"var(--metakyc-text-secondary, #6b7280)"},children:n},"__placeholder__"),a.map((p,I)=>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-${I}`))]}),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:a,placeholder:n="Select...",disabled:o=!1,readOnly:c=!1,required:u=!1})=>{const m=o||c,[p,I]=i.useState(!1),[P,g]=i.useState(""),[A,N]=i.useState(null),[k,b]=i.useState({bg:"#ffffff",borderColor:"#d1d5db",textPrimary:"#111827",textSecondary:"#6b7280",primaryColor:"#2563eb",primaryLight:"#eff6ff",hoverBg:"#f9fafb"}),_=i.useRef(null),U=i.useRef(null),L=i.useRef(null),B=i.useCallback(()=>{if(!U.current)return null;const E=U.current.getBoundingClientRect(),T=window.innerHeight-E.bottom<wt&&E.top>wt;return{top:T?E.top:E.bottom+4,left:E.left,width:E.width,openUp:T}},[]),K=i.useCallback(()=>{const E=getComputedStyle(document.documentElement),$=(q,xe)=>E.getPropertyValue(q).trim()||xe,T=$("--metakyc-input-bg",$("--metakyc-background","#ffffff"));b({bg:T,borderColor:$("--metakyc-input-border",$("--metakyc-border","#d1d5db")),textPrimary:$("--metakyc-input-text",$("--metakyc-text-primary","#111827")),textSecondary:$("--metakyc-text-secondary","#6b7280"),primaryColor:$("--metakyc-primary","#2563eb"),primaryLight:$("--metakyc-primary-light","#eff6ff"),hoverBg:$("--metakyc-surface",T)})},[]),X=i.useCallback(()=>{if(m)return;K();const E=B();E&&N(E),I(!0)},[m,B,K]),C=i.useCallback(()=>{I(!1),g("")},[]);i.useEffect(()=>{if(!p)return;const E=$=>{var q,xe;const T=$.target;!((q=_.current)!=null&&q.contains(T))&&!((xe=L.current)!=null&&xe.contains(T))&&C()};return document.addEventListener("mousedown",E),()=>document.removeEventListener("mousedown",E)},[p,C]),i.useEffect(()=>{if(!p)return;const E=()=>{const $=B();$&&N($)};return window.addEventListener("scroll",E,!0),window.addEventListener("resize",E),()=>{window.removeEventListener("scroll",E,!0),window.removeEventListener("resize",E)}},[p,B]);const h=a.filter(E=>E.label.toLowerCase().includes(P.toLowerCase())),M=E=>{m||s(r.includes(E)?r.filter($=>$!==E):[...r,E])},Q=(E,$)=>{$.stopPropagation(),m||s(r.filter(T=>T!==E))},O=E=>{var $;return(($=a.find(T=>T.value===E))==null?void 0:$.label)||E},{bg:G,borderColor:W,textPrimary:ue,textSecondary:J,primaryColor:he,primaryLight:pe,hoverBg:oe}=k,je=p&&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 ${W}`,backgroundColor:G,overflow:"hidden"},children:[e.jsx("div",{style:{padding:"8px",borderBottom:`1px solid ${W}`},children:e.jsx("input",{type:"text",value:P,onChange:E=>g(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 ${W}`,backgroundColor:G,color:ue,outline:"none",boxSizing:"border-box"},onFocus:E=>{const $=getComputedStyle(document.documentElement),T=$.getPropertyValue("--metakyc-input-border-focus").trim()||$.getPropertyValue("--metakyc-primary").trim()||"#2563eb";E.currentTarget.style.backgroundColor=G,E.currentTarget.style.color=ue,E.currentTarget.style.borderColor=T,E.currentTarget.style.outline="none",E.currentTarget.style.boxShadow=`0 0 0 2px ${T}33`},onBlur:E=>{E.currentTarget.style.backgroundColor=G,E.currentTarget.style.color=ue,E.currentTarget.style.borderColor=W,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:h.length===0?e.jsx("li",{style:{padding:"8px 12px",fontSize:"13px",color:J},children:"No results"}):h.map(E=>{const $=r.includes(E.value);return e.jsxs("li",{onClick:()=>M(E.value),className:"metakyc-multiselect-option",style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",fontSize:"13px",cursor:"pointer",backgroundColor:$?pe:"transparent",color:$?he:ue,userSelect:"none"},onMouseEnter:T=>{$||(T.currentTarget.style.backgroundColor=oe)},onMouseLeave:T=>{$||(T.currentTarget.style.backgroundColor="transparent")},children:[e.jsx("input",{type:"checkbox",checked:$,readOnly:!0,style:{accentColor:he,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 ${W}`},children:e.jsxs("button",{type:"button",onClick:()=>{s([]),g("")},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:_,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:U,onClick:()=>p?C():X(),className:Ce("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: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:n}):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:[O(E),!m&&e.jsx("button",{type:"button",onClick:$=>Q(E,$),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:p?"▲":"▼"})]}),typeof document<"u"&&je?ut.createPortal(je,document.body):null]})},St=260,ze=({label:t,error:r,helperText:s,options:a,placeholder:n="Select...",value:o,onChange:c,disabled:u=!1,readOnly:m=!1,required:p=!1,className:I})=>{var xe;const P=u||m,[g,A]=i.useState(!1),[N,k]=i.useState(""),[b,_]=i.useState(null),[U,L]=i.useState({bg:"#ffffff",border:"#d1d5db",text:"#111827",textSecondary:"#6b7280",primary:"#2563eb",primaryLight:"#eff6ff",hoverBg:"#f9fafb"}),B=i.useCallback(()=>{const R=getComputedStyle(document.documentElement),Y=(ge,me)=>R.getPropertyValue(ge).trim()||me,ce=Y("--metakyc-input-bg",Y("--metakyc-background","#ffffff"));L({bg:ce,border:Y("--metakyc-input-border",Y("--metakyc-border","#d1d5db")),text:Y("--metakyc-input-text",Y("--metakyc-text-primary","#111827")),textSecondary:Y("--metakyc-text-secondary","#6b7280"),primary:Y("--metakyc-primary","#2563eb"),primaryLight:Y("--metakyc-primary-light","#eff6ff"),hoverBg:Y("--metakyc-surface",ce)})},[]),K=i.useRef(null),X=i.useRef(null),C=i.useRef(null),h=i.useRef(null),M=i.useCallback(()=>{if(!X.current)return null;const R=X.current.getBoundingClientRect(),ce=window.innerHeight-R.bottom<St&&R.top>St;return{top:ce?R.top:R.bottom+4,left:R.left,width:R.width,openUp:ce}},[]),Q=i.useCallback(()=>{if(P)return;B();const R=M();R&&_(R),A(!0)},[P,M,B]),O=i.useCallback(()=>{A(!1),k("")},[]),G=()=>g?O():Q();i.useEffect(()=>{if(!g)return;const R=Y=>{var ge,me;const ce=Y.target;!((ge=K.current)!=null&&ge.contains(ce))&&!((me=C.current)!=null&&me.contains(ce))&&O()};return document.addEventListener("mousedown",R),()=>document.removeEventListener("mousedown",R)},[g,O]),i.useEffect(()=>{if(!g)return;const R=()=>{const Y=M();Y&&_(Y)};return window.addEventListener("scroll",R,!0),window.addEventListener("resize",R),()=>{window.removeEventListener("scroll",R,!0),window.removeEventListener("resize",R)}},[g,M]),i.useEffect(()=>{g&&h.current&&setTimeout(()=>{var R;return(R=h.current)==null?void 0:R.focus()},0)},[g]);const W=a.filter(R=>R.label.toLowerCase().includes(N.toLowerCase())||R.value.toLowerCase().includes(N.toLowerCase())),ue=(xe=a.find(R=>R.value===o))==null?void 0:xe.label,J=(R,Y)=>{P||Y||(c(R),O())},{bg:he,border:pe,text:oe,textSecondary:je,primary:E,primaryLight:$,hoverBg:T}=U,q=g&&b&&e.jsxs("div",{ref:C,className:"metakyc-searchable-select-dropdown",style:{position:"fixed",top:b.openUp?void 0:b.top,bottom:b.openUp?window.innerHeight-b.top+4:void 0,left:b.left,width:b.width,zIndex:99999,borderRadius:"8px",boxShadow:"0 4px 16px rgba(0,0,0,0.18)",border:`1px solid ${pe}`,backgroundColor:he,overflow:"hidden"},children:[e.jsx("div",{style:{padding:"8px",borderBottom:`1px solid ${pe}`},children:e.jsx("input",{ref:h,type:"text",value:N,onChange:R=>k(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 ${pe}`,backgroundColor:he,color:oe,outline:"none",boxSizing:"border-box"},onFocus:R=>{const Y=getComputedStyle(document.documentElement),ce=Y.getPropertyValue("--metakyc-input-border-focus").trim()||Y.getPropertyValue("--metakyc-primary").trim()||"#2563eb";R.currentTarget.style.backgroundColor=he,R.currentTarget.style.color=oe,R.currentTarget.style.borderColor=ce,R.currentTarget.style.outline="none",R.currentTarget.style.boxShadow=`0 0 0 2px ${ce}33`},onBlur:R=>{R.currentTarget.style.backgroundColor=he,R.currentTarget.style.color=oe,R.currentTarget.style.borderColor=pe,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:W.length===0?e.jsx("li",{style:{padding:"8px 12px",fontSize:"13px",color:je},children:"No results"}):W.map(R=>{const Y=R.value===o;return e.jsx("li",{className:"metakyc-searchable-select-option",onClick:()=>J(R.value,R.disabled),style:{padding:"8px 12px",fontSize:"13px",cursor:R.disabled?"not-allowed":"pointer",opacity:R.disabled?.4:1,backgroundColor:Y?$:"transparent",color:Y?E:oe,userSelect:"none"},onMouseEnter:ce=>{!Y&&!R.disabled&&(ce.currentTarget.style.backgroundColor=T)},onMouseLeave:ce=>{Y||(ce.currentTarget.style.backgroundColor="transparent")},children:R.label},R.value)})})]});return e.jsxs("div",{className:Ce("w-full metakyc-searchable-select",I),ref:K,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:X,role:"button",tabIndex:P?-1:0,onClick:G,onKeyDown:R=>{(R.key==="Enter"||R.key===" ")&&(R.preventDefault(),G()),R.key==="Escape"&&O()},className:Ce("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:ue?"var(--metakyc-input-text, var(--metakyc-text-primary, #111827))":"var(--metakyc-input-placeholder, var(--metakyc-text-muted, #9ca3af))",borderColor:r?"var(--metakyc-danger, #ef4444)":g?"var(--metakyc-input-border-focus, var(--metakyc-primary, #2563eb))":"var(--metakyc-input-border, var(--metakyc-border, #d1d5db))",minHeight:"42px",outline:g?"2px solid var(--metakyc-input-border-focus, var(--metakyc-primary, #2563eb))":"none",outlineOffset:"-1px"},children:[e.jsx("span",{className:"truncate flex-1",children:ue||n}),e.jsx("span",{className:"flex-shrink-0 text-xs pointer-events-none",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:g?"▲":"▼"})]}),typeof document<"u"&&q?ut.createPortal(q,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})]})};ze.displayName="SearchableSelect";function ns(t){const r=t.type;return r.startsWith("image/")?"image":r==="application/pdf"?"pdf":"file"}const Ir=({label:t,subtitle:r,error:s,accept:a,multiple:n=!1,maxSize:o,required:c,onChange:u,value:m=[],className:p})=>{const[I,P]=i.useState(!1),[g,A]=i.useState(null),N=i.useRef(null),k=i.useCallback(C=>{if(!C)return;A(null);const h=Array.from(C);if(o&&h.filter(Q=>Q.size>o).length>0){A(`File exceeds the maximum size of ${dt(o)}`);return}u==null||u(n?[...m,...h]:[h[0]])},[o,n,u,m]),b=i.useCallback(C=>{C.preventDefault(),C.stopPropagation(),P(!0)},[]),_=i.useCallback(C=>{C.preventDefault(),C.stopPropagation(),P(!1)},[]),U=i.useCallback(C=>{C.preventDefault(),C.stopPropagation(),P(!1),k(C.dataTransfer.files)},[k]),L=()=>{var C;(C=N.current)==null||C.click()},B=C=>{A(null);const h=m.filter((M,Q)=>Q!==C);u==null||u(h)},K=s||g,X=m.length>0;return e.jsxs("div",{className:Ce("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:b,onDragLeave:_,onDrop:U,style:{border:`2px dashed ${K?"var(--metakyc-danger, #ef4444)":I?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #d1d5db)"}`,borderRadius:"12px",padding:X?"20px":"32px 20px",textAlign:"center",cursor:"pointer",transition:"all 0.2s ease",backgroundColor:I?"color-mix(in srgb, var(--metakyc-primary, #2563eb) 5%, var(--metakyc-background, #ffffff))":"var(--metakyc-background, #ffffff)"},children:[e.jsx("input",{ref:N,type:"file",style:{display:"none"},accept:a,multiple:n,onChange:C=>{k(C.target.files),C.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:I?"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:I?"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"]}),(a||o)&&e.jsxs("p",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"4px"},children:[a&&e.jsx("span",{children:a}),a&&o&&e.jsx("span",{children:" · "}),o&&e.jsxs("span",{children:["Max ",dt(o)]})]})]})]})]}),X&&e.jsx("div",{style:{marginTop:"12px",display:"flex",flexDirection:"column",gap:"8px"},children:m.map((C,h)=>{const M=ns(C),Q=M==="image",O=Q?URL.createObjectURL(C):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&&O?e.jsx("img",{src:O,alt:C.name,style:{width:"100%",height:"100%",objectFit:"cover",borderRadius:"8px"}}):M==="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:C.name}),e.jsx("p",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)",margin:0,marginTop:"2px"},children:dt(C.size)})]}),e.jsx("button",{type:"button",onClick:G=>{G.stopPropagation(),B(h)},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:G=>{G.currentTarget.style.backgroundColor="color-mix(in srgb, var(--metakyc-danger, #ef4444) 10%, transparent)",G.currentTarget.style.color="var(--metakyc-danger, #ef4444)"},onMouseLeave:G=>{G.currentTarget.style.backgroundColor="transparent",G.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"})]})})]},`${C.name}-${h}`)})}),K&&e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",marginTop:"6px"},children:K})]})},Er=i.forwardRef(({countryCode:t="+1",onCountryCodeChange:r,className:s,...a},n)=>e.jsxs("div",{className:"w-full",children:[a.label&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[a.label,a.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:o=>r==null?void 0:r(o.target.value),className:Ce("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(fe,{ref:n,type:"tel",className:Ce("flex-1",s),...a,label:""})]}),a.error&&e.jsx("p",{className:"mt-1 text-sm text-danger-500",children:a.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.
36
36
  * See the LICENSE file in the root directory of this source tree.
37
- */const Cr=(...t)=>t.filter((r,s,a)=>!!r&&r.trim()!==""&&a.indexOf(r)===s).join(" ").trim();/**
37
+ */const Ar=(...t)=>t.filter((r,s,a)=>!!r&&r.trim()!==""&&a.indexOf(r)===s).join(" ").trim();/**
38
38
  * @license lucide-react v0.574.0 - ISC
39
39
  *
40
40
  * This source code is licensed under the ISC license.
41
41
  * See the LICENSE file in the root directory of this source tree.
42
- */const ts=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();/**
42
+ */const is=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();/**
43
43
  * @license lucide-react v0.574.0 - ISC
44
44
  *
45
45
  * This source code is licensed under the ISC license.
46
46
  * See the LICENSE file in the root directory of this source tree.
47
- */const rs=t=>t.replace(/^([A-Z])|[\s-_]+(\w)/g,(r,s,a)=>a?a.toUpperCase():s.toLowerCase());/**
47
+ */const os=t=>t.replace(/^([A-Z])|[\s-_]+(\w)/g,(r,s,a)=>a?a.toUpperCase():s.toLowerCase());/**
48
48
  * @license lucide-react v0.574.0 - ISC
49
49
  *
50
50
  * This source code is licensed under the ISC license.
51
51
  * See the LICENSE file in the root directory of this source tree.
52
- */const vt=t=>{const r=rs(t);return r.charAt(0).toUpperCase()+r.slice(1)};/**
52
+ */const Ct=t=>{const r=os(t);return r.charAt(0).toUpperCase()+r.slice(1)};/**
53
53
  * @license lucide-react v0.574.0 - ISC
54
54
  *
55
55
  * This source code is licensed under the ISC license.
56
56
  * See the LICENSE file in the root directory of this source tree.
57
- */var ss={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
57
+ */var ls={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
58
58
  * @license lucide-react v0.574.0 - ISC
59
59
  *
60
60
  * This source code is licensed under the ISC license.
61
61
  * See the LICENSE file in the root directory of this source tree.
62
- */const as=t=>{for(const r in t)if(r.startsWith("aria-")||r==="role"||r==="title")return!0;return!1};/**
62
+ */const cs=t=>{for(const r in t)if(r.startsWith("aria-")||r==="role"||r==="title")return!0;return!1};/**
63
63
  * @license lucide-react v0.574.0 - ISC
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 ns=o.forwardRef(({color:t="currentColor",size:r=24,strokeWidth:s=2,absoluteStrokeWidth:a,className:n="",children:l,iconNode:c,...u},y)=>o.createElement("svg",{ref:y,...ss,width:r,height:r,stroke:t,strokeWidth:a?Number(s)*24/Number(r):s,className:Cr("lucide",n),...!l&&!as(u)&&{"aria-hidden":"true"},...u},[...c.map(([m,w])=>o.createElement(m,w)),...Array.isArray(l)?l:[l]]));/**
67
+ */const ds=i.forwardRef(({color:t="currentColor",size:r=24,strokeWidth:s=2,absoluteStrokeWidth:a,className:n="",children:o,iconNode:c,...u},m)=>i.createElement("svg",{ref:m,...ls,width:r,height:r,stroke:t,strokeWidth:a?Number(s)*24/Number(r):s,className:Ar("lucide",n),...!o&&!cs(u)&&{"aria-hidden":"true"},...u},[...c.map(([p,I])=>i.createElement(p,I)),...Array.isArray(o)?o:[o]]));/**
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 Nr=(t,r)=>{const s=o.forwardRef(({className:a,...n},l)=>o.createElement(ns,{ref:l,iconNode:r,className:Cr(`lucide-${ts(vt(t))}`,`lucide-${t}`,a),...n}));return s.displayName=vt(t),s};/**
72
+ */const Fr=(t,r)=>{const s=i.forwardRef(({className:a,...n},o)=>i.createElement(ds,{ref:o,iconNode:r,className:Ar(`lucide-${is(Ct(t))}`,`lucide-${t}`,a),...n}));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.
76
76
  * See the LICENSE file in the root directory of this source tree.
77
- */const is=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],Rr=Nr("chevron-left",is);/**
77
+ */const us=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],Tr=Fr("chevron-left",us);/**
78
78
  * @license lucide-react v0.574.0 - ISC
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 os=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],Ir=Nr("chevron-right",os);function ls(t,r){const s=!r||r.length===0||r.every(a=>!a||!a.trim());if(t.isRequired&&s)return t.errorMessage||"This field is required";if(!s){const a=r[0]??"";if(a&&t.regex)try{if(!new RegExp(t.regex).test(a))return t.errorMessage||"Invalid format"}catch{}if(a!==""){const n=Number(a);if(!isNaN(n)&&a.trim()!==""){if(t.min!==void 0&&t.min!==null&&n<t.min)return`Minimum value is ${t.min}`;if(t.max!==void 0&&t.max!==null&&n>t.max)return`Maximum value is ${t.max}`}else{if(t.min!==void 0&&t.min!==null&&a.length<t.min)return`Minimum length is ${t.min} characters`;if(t.max!==void 0&&t.max!==null&&a.length>t.max)return`Maximum length is ${t.max} characters`}}}return null}function cs(t){const r=t.flatMap((a,n)=>(a.questions??[]).map((l,c)=>({question:l,groupIndex:n,qIdx:c}))),s=new Map;for(const a of r){const n=a.question.pageNumber!=null&&a.question.pageNumber>0?a.question.pageNumber:1;s.has(n)||s.set(n,[]),s.get(n).push(a)}return Array.from(s.entries()).sort(([a],[n])=>a-n).map(([,a])=>a)}const Er=({applicantId:t,onComplete:r,onBack:s})=>{const{questionnaire:a,initialAnswers:n,isLoading:l,isSubmitting:c,error:u,submit:y}=fr(t),[m,w]=o.useState({}),[T,N]=o.useState({}),[F,f]=o.useState(0);o.useEffect(()=>{n&&Object.keys(n).length>0&&Object.keys(m).length===0&&w(n)},[n]);const j=o.useMemo(()=>a?cs(a.questionGroups):[],[a]),P=F===j.length-1,_=j[F]??[],H=o.useCallback((I,g)=>{w(z=>({...z,[I]:g})),N(z=>{const $={...z};return delete $[I],$})},[]),L=o.useCallback(()=>{const I={};for(const{question:g}of _){const z=ls(g,m[g.id]??[]);z&&(I[g.id]=z)}return N(g=>({...g,...I})),Object.keys(I).length===0},[_,m]),K=()=>{L()&&f(I=>I+1)},W=()=>{F>0?f(I=>I-1):s==null||s()},Y=async()=>{if(!(!L()||!a))try{const I=a.questionGroups.flatMap(z=>(z.questions??[]).map($=>({questionId:$.id,values:m[$.id]??[]}))),g={applicantId:t,questionnarieId:a.id,questionResults:I};await y(g),r==null||r()}catch(I){console.error("Questionnaire submit error:",I)}};return l?e.jsx(J,{children:e.jsx(Z,{children:e.jsx(Ce,{className:"my-8"})})}):u?e.jsx(J,{children:e.jsx(Z,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading questionnaire: ",u.message]})})}):a?e.jsxs(J,{children:[e.jsxs(ye,{children:[e.jsx("h2",{className:"text-lg font-bold",children:a.displayName}),a.subtitle&&e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:a.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 ",F+1," of ",j.length]}),e.jsx("div",{className:"flex items-center gap-1.5",children:j.map((I,g)=>e.jsx("div",{className:"rounded-full transition-all duration-200",style:{height:"6px",width:g===F?"20px":"6px",backgroundColor:g<=F?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},g))})]})]}),e.jsx(Z,{className:"space-y-6",children:_.map(({question:I})=>e.jsx(ds,{question:I,value:m[I.id]??[],error:T[I.id],onChange:g=>H(I.id,g)},I.id))}),e.jsxs(xe,{className:"flex items-center justify-between",children:[e.jsxs(V,{type:"button",variant:"outline",onClick:W,style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(Rr,{size:14}),F>0?"Previous":"Back"]}),P?e.jsx(V,{type:"button",isLoading:c,onClick:Y,children:"Continue"}):e.jsxs(V,{type:"button",onClick:K,style:{display:"flex",alignItems:"center",gap:"4px"},children:["Next",e.jsx(Ir,{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},ds=({question:t,value:r,error:s,onChange:a})=>{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:u=>a([u.target.value]),placeholder:t.subtitle?void 0:"Enter your answer…",error:s,required:t.isRequired}),l==="single-select"&&e.jsx(ot,{value:r[0]??"",onChange:u=>a([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:()=>a([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?a([...r,u]):a(r.filter(m=>m!==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 us(t){const r=new Map;for(const s of t){const a=s.pageNumber!=null&&s.pageNumber>0?s.pageNumber:1;r.has(a)||r.set(a,[]),r.get(a).push(s)}return Array.from(r.entries()).sort(([s],[a])=>s-a).map(([,s])=>s)}const Ar=({applicantId:t,onComplete:r,onBack:s})=>{const{uploadDocument:a,isLoading:n,isSubmitting:l,error:c,submit:u}=gr(t),[y,m]=o.useState({}),[w,T]=o.useState(null),[N,F]=o.useState(0),[f,j]=o.useState({}),P=o.useMemo(()=>a?us(a.uploadDocumentFiles):[],[a]),_=P[N]??[],H=N===P.length-1,L=P.length,K=o.useCallback(()=>{const g={};for(const z of _)z.isRequired&&(y[z.id]||[]).length===0&&(g[z.id]=`${z.displayName} is required`);return j(g),Object.keys(g).length===0},[_,y]),W=()=>{K()&&(F(g=>g+1),j({}))},Y=()=>{N>0?(F(g=>g-1),j({})):s==null||s()},I=async()=>{if(!(!K()||!a)){T(null);try{const g=await Promise.all(a.uploadDocumentFiles.map(async $=>{const D=y[$.id]||[],M=await Promise.all(D.map(async te=>({fileName:te.name,fileData:await dr(te)})));return{uploadDocumentFileId:$.id,valueList:M}})),z={applicantId:t,uploadDocumentId:a.id,uploadDocumentResults:g};await u(z),r==null||r()}catch(g){T((g==null?void 0:g.message)||"Failed to submit documents. Please try again.")}}};return n?e.jsx(J,{children:e.jsx(Z,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"48px 0",gap:"16px"},children:[e.jsx(Ce,{className:"my-8"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)"},children:"Loading document requirements..."})]})})}):c?e.jsx(J,{children:e.jsx(Z,{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})]})})}):a?e.jsxs(J,{children:[e.jsxs(ye,{children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:a.displayName||"Upload Documents"}),a.subtitle&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",marginTop:"4px"},children:a.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 ",N+1," of ",L]}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:P.map((g,z)=>e.jsx("div",{style:{height:"6px",width:z===N?"20px":"6px",borderRadius:"999px",transition:"all 0.2s ease",backgroundColor:z<=N?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},z))})]})]}),a.description&&N===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:a.description})]}),e.jsx(Z,{children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"24px"},children:_.map(g=>e.jsx(wr,{label:g.displayName,subtitle:g.subtitle,accept:g.allowedTypes,multiple:g.multipleFile,maxSize:g.maxEachFileSizeByte,required:g.isRequired,error:f[g.id],value:y[g.id]||[],onChange:z=>{T(null),j($=>{const D={...$};return delete D[g.id],D}),m($=>({...$,[g.id]:z}))}},g.id))})}),w&&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:w})]}),e.jsx(xe,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[e.jsx(V,{type:"button",variant:"outline",onClick:Y,children:N>0?"Previous":"Back"}),H?e.jsx(V,{type:"button",isLoading:l,onClick:I,children:l?"Uploading...":"Continue"}):e.jsx(V,{type:"button",onClick:W,children:"Next"})]})})]}):null},Fr=({applicantId:t,onComplete:r,onBack:s})=>{const{overview:a,isLoading:n,isSubmitting:l,error:c,passOverview:u}=br(t),y=async()=>{await u(),r==null||r()};return n?e.jsx(J,{children:e.jsx(Z,{children:e.jsx(Ce,{className:"my-8"})})}):c?e.jsx(J,{children:e.jsx(Z,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading overview: ",c.message]})})}):a?e.jsxs(J,{children:[e.jsxs(ye,{children:[e.jsx("h2",{className:"text-lg font-bold",children:a.title||"Overview"}),a.description&&e.jsx("p",{className:"mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:a.description})]}),e.jsx(Z,{className:"space-y-8",children:a.steps&&a.steps.length>0?a.steps.sort((m,w)=>m.order-w.order).map(m=>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:m.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:m.title}),m.description&&e.jsx("p",{className:"metakyc-step-description text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:m.description})]})]},m.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(xe,{className:"flex justify-between",children:[s&&e.jsx(V,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(V,{onClick:y,isLoading:l,children:"Continue"})]})]}):null};function ps(t){const r=(t??"en").toLowerCase().replace("_","-");try{return Intl.NumberFormat.supportedLocalesOf([r]),r}catch{return"en"}}function ms(t){return t.valueDataType===Ee.Money&&Array.isArray(t.defaultValues)&&t.defaultValues.length>0}function ys(t,r){const s=new Intl.NumberFormat(ps(r),{minimumFractionDigits:0,maximumFractionDigits:2});return t.replace(/([\d]+(?:\.\d+)?)/g,a=>{const n=parseFloat(a);return isNaN(n)?a:s.format(n)})}function xs(t,r){const s=!r||r.length===0||r.every(a=>!a||!a.trim());if(t.isRequired&&s)return t.errorMessage||`${t.displayName} is required`;if(!s){const a=r[0]??"";if(a&&t.regex)try{if(!new RegExp(t.regex).test(a))return t.errorMessage||"Invalid format"}catch{}const n=t.valueDataType===Ee.Integer||t.valueDataType===Ee.Money||t.valueDataType===Ee.DigitOnly;if(n&&a.trim()!==""){const l=Number(a);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(!n&&a!==""){if(t.min!==void 0&&t.min!==null&&a.length<t.min)return`Minimum length is ${t.min} characters`;if(t.max!==void 0&&t.max!==null&&a.length>t.max)return`Maximum length is ${t.max} characters`}}return null}function hs(t){const r=new Map;return t.forEach((s,a)=>{const n=s.pageNumber!=null&&s.pageNumber>0?s.pageNumber:1;r.has(n)||r.set(n,[]),r.get(n).push({criterion:s,idx:a})}),Array.from(r.entries()).sort(([s],[a])=>s-a).map(([,s])=>s)}function fs(t){return t.builtInType===1?"country":!t.defaultValues||t.defaultValues.length===0?"text":t.multipleValue?"checkbox":"radio"}const Tr=({applicantId:t,onComplete:r,onBack:s})=>{const{config:a}=we(),n=a.locale??"en",{criteria:l,initialAnswers:c,isLoading:u,isSubmitting:y,error:m,submit:w}=kr(t),[T,N]=o.useState({}),[F,f]=o.useState({}),[j,P]=o.useState(0),[_,H]=o.useState(!1);o.useEffect(()=>{c&&Object.keys(c).length>0&&Object.keys(T).length===0&&N(c)},[c]);const L=o.useMemo(()=>l&&l.length>0?hs(l):[],[l]),K=j===L.length-1,W=L[j]??[];o.useEffect(()=>{!u&&l&&l.length===0&&!_&&!y&&(H(!0),w({applicantId:t,criteriaValueInputs:[]}).then(()=>r==null?void 0:r()).catch(console.error))},[u,l,_,y,w,t,r]);const Y=o.useCallback((D,M)=>{N(te=>({...te,[D]:M})),f(te=>{const re={...te};return delete re[D],re})},[]),I=o.useCallback(()=>{const D={};for(const{criterion:M}of W){const te=xs(M,T[M.id]??[]);te&&(D[M.id]=te)}return f(M=>({...M,...D})),Object.keys(D).length===0},[W,T]),g=()=>{I()&&P(D=>D+1)},z=()=>{j>0?P(D=>D-1):s==null||s()},$=async()=>{if(!(!I()||!l))try{const D=l.map(te=>{const re=(T[te.id]??[]).filter(ee=>ee&&ee.trim());return re.length>0?{riskCriteriaId:te.id,values:re}:null}).filter(te=>te!==null);await w({applicantId:t,criteriaValueInputs:D}),r==null||r()}catch(D){console.error("Risk scoring submit error:",D)}};return u?e.jsx(J,{children:e.jsxs(Z,{children:[e.jsx(Ce,{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(J,{children:e.jsxs(Z,{children:[e.jsx(Ce,{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…"})]})}):m?e.jsx(J,{children:e.jsx(Z,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading criteria: ",m.message]})})}):l?e.jsxs(J,{children:[e.jsxs(ye,{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((D,M)=>e.jsx("div",{className:"rounded-full transition-all duration-200",style:{height:"6px",width:M===j?"20px":"6px",backgroundColor:M<=j?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},M))})]})]}),e.jsx(Z,{className:"space-y-6",children:W.map(({criterion:D})=>e.jsx(gs,{criterion:D,value:T[D.id]??[],error:F[D.id],locale:n,onChange:M=>Y(D.id,M)},D.id))}),e.jsxs(xe,{className:"flex items-center justify-between",children:[e.jsxs(V,{type:"button",variant:"outline",onClick:z,style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(Rr,{size:14}),j>0?"Previous":"Back"]}),K?e.jsx(V,{type:"button",isLoading:y,onClick:$,children:"Continue"}):e.jsxs(V,{type:"button",onClick:g,style:{display:"flex",alignItems:"center",gap:"4px"},children:["Next",e.jsx(Ir,{size:14})]})]}),m&&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:m.message})})]}):null},gs=({criterion:t,value:r,error:s,locale:a,onChange:n})=>{const l=fs(t),c=t.valueDataType===Ee.Integer||t.valueDataType===Ee.Money||t.valueDataType===Ee.DigitOnly,u=ms(t),y=m=>u?ys(m,a):m;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:m=>n([m.target.value]),type:c?"number":"text",placeholder:"Enter your answer…",error:s,required:t.isRequired,min:t.min,max:t.max,onKeyDown:m=>{t.valueDataType===Ee.DigitOnly&&["e","E","+","-","."].includes(m.key)&&m.preventDefault()}}),l==="radio"&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultValues??[]).map(m=>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]===m,onChange:()=>n([m]),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(m)})]},m)),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(m=>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(m),onChange:w=>{w.target.checked?n([...r,m]):n(r.filter(T=>T!==m))},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(m)})]},m)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),l==="country"&&e.jsx(ot,{value:r[0]??"",onChange:m=>n([m.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})]})},Pr=({applicantId:t,onComplete:r,onBack:s})=>{const{investorCategorizationService:a}=we(),[n,l]=o.useState(null),[c,u]=o.useState(!1),[y,m]=o.useState(null),w=async T=>{if(T.preventDefault(),n===null){m("Please select an investor type");return}u(!0),m(null);try{const N={applicantId:t,investorType:n};console.log("Submitting investor categorization:",N);const F=await a.setInvestorCategorization(N);console.log("Investor categorization result:",F),r==null||r()}catch(N){console.error("Error submitting investor categorization:",N),m(N.message||"Failed to submit investor categorization")}finally{u(!1)}};return e.jsx("form",{onSubmit:w,children:e.jsxs(J,{children:[e.jsxs(ye,{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(Z,{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:n===ge.Individual?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:n===ge.Individual?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:ge.Individual,checked:n===ge.Individual,onChange:()=>l(ge.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:n===ge.Sophisticated?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:n===ge.Sophisticated?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:ge.Sophisticated,checked:n===ge.Sophisticated,onChange:()=>l(ge.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:n===ge.HighNetWorth?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:n===ge.HighNetWorth?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:ge.HighNetWorth,checked:n===ge.HighNetWorth,onChange:()=>l(ge.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(xe,{className:"flex justify-between",children:[s&&e.jsx(V,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(V,{type:"submit",isLoading:c,disabled:n===null,children:"Submit"})]})]})})};function kt(t){const r=t.split(":").map(Number);return r.length===3?r[0]*3600+r[1]*60+r[2]:0}function lt(t){const r=Math.floor(t/60),s=t%60;return`${r.toString().padStart(2,"0")}:${s.toString().padStart(2,"0")}`}const Lr=({applicantId:t,onComplete:r,onBack:s})=>{const{appropriatenessTestService:a}=we(),[n,l]=o.useState(null),[c,u]=o.useState(!0),[y,m]=o.useState(!1),[w,T]=o.useState(null),[N,F]=o.useState({}),[f,j]=o.useState(0),[P,_]=o.useState(!1),[H,L]=o.useState(!1),[K,W]=o.useState(0),[Y,I]=o.useState(0),[g,z]=o.useState(null);o.useEffect(()=>{(async()=>{try{u(!0),T(null);const B=await a.getAppropriatenessTest(t);if(l(B),B.waitTimeSpanForNextTry&&B.waitTimeSpanForNextTry!=="00:00:00"){const b=kt(B.waitTimeSpanForNextTry);b>0&&W(b)}}catch(B){T(B.message||"Failed to load appropriateness test")}finally{u(!1)}})()},[t,a]),o.useEffect(()=>{if(!P||f<=0)return;const B=setInterval(()=>{j(b=>b<=1?(L(!0),0):b-1)},1e3);return()=>clearInterval(B)},[P,f]),o.useEffect(()=>{if(K<=0)return;const B=setInterval(()=>{W(b=>b<=1?0:b-1)},1e3);return()=>clearInterval(B)},[K]),o.useEffect(()=>{H&&!y&&te()},[H]);const $=()=>{n&&(_(!0),j(n.testDurationSec),I(0),F({}),T(null))},D=(B,b)=>{F(G=>({...G,[B]:b}))},M=o.useCallback(async()=>{try{const B=await a.getAppropriatenessTest(t);if(l(B),B.waitTimeSpanForNextTry&&B.waitTimeSpanForNextTry!=="00:00:00"){const b=kt(B.waitTimeSpanForNextTry);b>0&&W(b)}}catch{}},[t,a]),te=async B=>{if(n){if(!H){const b=n.appropriatenessQuestions.length-Object.keys(N).length;if(b>0){T(`Please answer all questions. ${b} remaining.`);return}}m(!0),T(null);try{const b=n.appropriatenessQuestions.map(Q=>({appropriatenessQuestionId:Q.id,value:N[Q.id]||""})),G={applicantId:t,appropriatenessTestId:n.id,appropriatenessQuestionResults:b};try{const Q=await a.fillAppropriatenessTest(G);Q.isSuccess?z({success:!0,message:Q.message||"Congratulations! You have passed the test."}):(z({success:!1,message:Q.message||"You did not pass the test."}),setTimeout(()=>M(),1e3))}catch(Q){if(Q.code===400&&Q.message)z({success:!1,message:Q.message}),setTimeout(()=>M(),1500);else throw Q}}catch(b){T(b.message||"Failed to submit test. Please try again."),re()}finally{m(!1)}}},re=()=>{_(!1),L(!1),F({}),I(0)};if(c)return e.jsx(J,{children:e.jsx(Z,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"48px 0",gap:"16px"},children:[e.jsx(Ce,{className:"my-8"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)"},children:"Loading test..."})]})})});if(!n)return e.jsx(J,{children:e.jsx(Z,{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"}),w&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"8px"},children:w})]})})});const ee=n.testAllowedMaxTry-n.totalFailedTries,ue=n.appropriatenessQuestions.length,oe=Object.keys(N).length;if(K>0)return e.jsxs(J,{children:[e.jsx(ye,{children:e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:n.displayName})}),e.jsx(Z,{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:lt(K)})}),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"}),w&&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:w})})]})})]});if(g){const B=()=>{z(null),re(),T(null)};return e.jsxs(J,{children:[e.jsx(Z,{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&&ee>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:ee})," attempt",ee!==1?"s":""," remaining"]})}),!g.success&&ee<=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(xe,{children:e.jsx("div",{style:{display:"flex",justifyContent:"center",width:"100%",gap:"12px"},children:g.success?e.jsx(V,{type:"button",onClick:()=>r==null?void 0:r(),children:"Continue"}):e.jsxs(e.Fragment,{children:[ee>0&&K<=0&&e.jsx(V,{type:"button",onClick:B,children:"Retake Test"}),ee>0&&K>0&&e.jsx(V,{type:"button",onClick:B,children:"OK"}),ee<=0&&s&&e.jsx(V,{type:"button",variant:"outline",onClick:s,children:"Back"})]})})})]})}if(!P)return e.jsxs(J,{children:[e.jsxs(ye,{children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:n.displayName}),n.subtitle&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",marginTop:"4px"},children:n.subtitle})]}),e.jsxs(Z,{children:[n.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:n.description})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px",marginBottom:"20px"},children:[e.jsx(st,{icon:"questions",label:"Questions",value:String(n.totalQuestionCount)}),e.jsx(st,{icon:"time",label:"Time Limit",value:lt(n.testDurationSec)}),e.jsx(st,{icon:"target",label:"Pass Requirement",value:`${n.testCorrectAnswerPassLimit} correct`}),e.jsx(st,{icon:"retry",label:"Attempts Left",value:String(ee),variant:ee<=1?"warning":"default"})]}),w&&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:"})," ",w]})]}),ee<=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(xe,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:s?"space-between":"flex-end",width:"100%"},children:[s&&e.jsx(V,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(V,{type:"button",onClick:$,disabled:ee<=0,children:"Start Test"})]})})]});const A=n.appropriatenessQuestions[Y],U=Y===ue-1,X=oe===ue,le=f<=60;return e.jsxs(J,{children:[e.jsxs(ye,{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:n.displayName}),e.jsxs("p",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"2px"},children:["Question ",Y+1," of ",ue]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 14px",borderRadius:"999px",backgroundColor:le?"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:le?"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:le?"var(--metakyc-danger, #ef4444)":"var(--metakyc-text-primary, #111827)",transition:"color 0.3s ease"},children:lt(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:`${oe/ue*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:[oe," answered"]}),e.jsxs("span",{style:{fontSize:"11px",color:"var(--metakyc-text-muted, #9ca3af)"},children:[ee," attempt",ee!==1?"s":""," left"]})]})]})]}),e.jsxs(Z,{children:[A&&e.jsx(vs,{question:A,index:Y,selectedAnswer:N[A.id],onSelect:B=>D(A.id,B),disabled:y}),ue>1&&e.jsx("div",{style:{display:"flex",justifyContent:"center",gap:"6px",marginTop:"20px",flexWrap:"wrap"},children:n.appropriatenessQuestions.map((B,b)=>e.jsx("button",{type:"button",onClick:()=>I(b),style:{width:"28px",height:"28px",borderRadius:"8px",border:b===Y?"2px solid var(--metakyc-primary, #2563eb)":"1px solid var(--metakyc-border, #e5e7eb)",backgroundColor:N[B.id]?b===Y?"color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)":"color-mix(in srgb, var(--metakyc-primary, #2563eb) 8%, transparent)":b===Y?"var(--metakyc-surface, #f9fafb)":"var(--metakyc-background, #ffffff)",color:N[B.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:b+1},B.id))}),H&&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."})]}),w&&!H&&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:w})})]}),e.jsx(xe,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[e.jsx(V,{type:"button",variant:"outline",onClick:()=>{Y>0?I(B=>B-1):s==null||s()},disabled:y,children:Y>0?"Previous":"Cancel"}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[!U&&e.jsx(V,{type:"button",onClick:()=>I(B=>B+1),children:"Next"}),(U||X)&&e.jsx(V,{type:"button",isLoading:y,onClick:()=>te(),disabled:!X&&!H,style:{opacity:X||H?1:.5},children:H?"Submitting...":"Submit Test"})]})]})})]})},bs={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"})]})},st=({icon:t,label:r,value:s,variant:a="default"})=>{const n=a==="warning";return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px",padding:"14px",borderRadius:"10px",backgroundColor:n?"color-mix(in srgb, #f59e0b 8%, transparent)":"var(--metakyc-surface, #f9fafb)",border:n?"1px solid color-mix(in srgb, #f59e0b 20%, transparent)":"1px solid var(--metakyc-border, #e5e7eb)"},children:[e.jsx("div",{style:{color:n?"#f59e0b":"var(--metakyc-primary, #2563eb)",flexShrink:0},children:bs[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:n?"#b45309":"var(--metakyc-text-primary, #111827)",margin:0,marginTop:"1px"},children:s})]})]})},vs=({question:t,selectedAnswer:r,onSelect:s,disabled:a})=>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((n,l)=>{const c=r===n;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:a?"default":"pointer",transition:"all 0.15s ease",opacity:a?.6:1},onMouseEnter:u=>{!a&&!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:n,checked:c,onChange:()=>s(n),disabled:a,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:n})]},l)})})]}),Dr=({applicantId:t,onComplete:r,onBack:s})=>{var Te,Ve,Me,He;const{applicantService:a,baseInformationService:n,config:l,currentTheme:c}=we(),{identityData:u,provider:y,token:m,isLoading:w,error:T,requestIdentity:N,restartIdentity:F}=vr(t),[f,j]=o.useState(null),[P,_]=o.useState(null),[H,L]=o.useState([]),[K,W]=o.useState([]),[Y,I]=o.useState(!0),[g,z]=o.useState(!1),[$,D]=o.useState(null),[M,te]=o.useState(!1),re=o.useRef(!1),[ee,ue]=o.useState({}),[oe,A]=o.useState({}),U=c!=null&&c.reviewPageFields&&c.reviewPageFields.length>0?c.reviewPageFields[0]:null,X=!!(c!=null&&c.reviewPageDisabled),le=o.useRef(!1);le.current=X;const B=Oe.useForm({defaultValues:{street:"",streetNumber:"",city:"",zip:"",country:"",nationality:"",phonenumber:""}});o.useEffect(()=>{if(X){re.current||(re.current=!0,N().then(()=>z(!0)).catch(O=>console.error("[Identity] Auto-request failed:",O)).finally(()=>I(!1)));return}(async()=>{try{const[O,q,p]=await Promise.all([a.getApplicantData(t),n.getCountries("","en"),n.getCountries("","en",40)]);_(O);const k=new Set,R=q.map(x=>({value:x.abbreviation3||x.abbreviation,label:x.name})).filter(x=>!x.value||k.has(x.value)?!1:(k.add(x.value),!0));L(R);const v=new Set,i=p.filter(x=>x.countryCode).map(x=>({value:x.countryCode,label:`${x.countryCode} – ${x.name}`})).filter(x=>v.has(x.value)?!1:(v.add(x.value),!0));W(i);const d=O.applicantRequestData;if(ue({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)||""}),B.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)||""}),O.kycRecords&&O.kycRecords.length>0&&O.kycRecords[0].providerTokenObject!==null&&!re.current&&le.current){console.log("[Identity] Review page disabled + existing identity — auto-requesting..."),re.current=!0;try{await N(),z(!0)}catch(x){console.error("[Identity] Auto-request failed:",x)}}}catch(O){console.error("Error loading applicant data:",O)}finally{I(!1)}})()},[t]),o.useEffect(()=>{u&&!g&&le.current&&(console.log("[Identity] Review page disabled — showing cached provider"),z(!0))},[u,g]),o.useEffect(()=>{if(m){if(m.expiresAt){const h=new Date(m.expiresAt).getTime();if(Date.now()>=h){console.warn("[Identity] Token has expired (expiresAt)"),te(!0),D("Your verification session has expired. Please restart.");return}}if(m.url)try{const O=new URL(m.url).toString().toLowerCase();if(O.includes("expired")||O.includes("invalid")||O.includes("error")){console.warn("[Identity] Token URL indicates expiration"),te(!0),D("Your verification link has expired. Please restart.");return}}catch{console.error("[Identity] Invalid token URL")}if(m.status==="expired"||m.error==="expired"||m.expired===!0){console.warn("[Identity] Token object indicates expiration"),te(!0),D("Your verification session has expired. Please restart.");return}}},[m]),o.useEffect(()=>{if(y!==null&&m&&!f&&g&&!M){const h=y;if(m.url){console.log("[Identity] Loading provider URL for user verification:",m.url),D(null);try{if(new URL(m.url),h===Ne.SardinAI){console.log("[SardinAI] Initializing Risk SDK in background...");try{const O=Ke.parseProviderConfig(y,m,l);Ke.createProvider(y,O).initialize().then(()=>{console.log("[SardinAI] Risk SDK initialized successfully in background")}).catch(p=>{console.warn("[SardinAI] Risk SDK initialization failed (non-blocking):",p)})}catch(O){console.warn("[SardinAI] Risk SDK setup failed (non-blocking):",O)}}j({type:"url",url:m.url})}catch(O){console.error("[Identity] Invalid URL:",O),D("Invalid verification URL. Please restart."),te(!0)}return}if(h===Ne.SardinAI){console.log("[SardinAI] No URL provided - initializing Risk SDK only..."),D(null);try{const O=Ke.parseProviderConfig(y,m,l),q=Ke.createProvider(y,O);q.initialize().then(()=>{console.log("[SardinAI] Risk SDK initialized successfully"),j(q),setTimeout(()=>{r==null||r()},2e3)}).catch(p=>{var R;console.error("[SardinAI] Failed to initialize:",p);const k=((R=p.message)==null?void 0:R.toLowerCase())||"";k.includes("expired")||k.includes("invalid")||k.includes("401")||k.includes("400")?(te(!0),D("Session expired or invalid. Please restart verification.")):D(`Failed to initialize: ${p.message}`)})}catch(O){console.error("[SardinAI] Error creating provider:",O),D(`Configuration error: ${O.message}`)}return}try{D(null);const O=Ke.parseProviderConfig(y,m,l),q=Ke.createProvider(y,O);h===Ne.Sumsub?(q.initialize("identity-container").catch(p=>{var k;console.error("[Sumsub] Initialization error:",p),D(`Failed to initialize: ${p.message}`),(k=p.message)!=null&&k.toLowerCase().includes("expired")&&te(!0)}),q.onComplete&&q.onComplete(()=>{r==null||r()})):h===Ne.Onfido&&q.initialize("identity-container").catch(p=>{console.error("[Onfido] Initialization error:",p),D(`Failed to initialize: ${p.message}`)}),j(q)}catch(O){console.error("[Identity] Provider setup error:",O),D(`Setup error: ${O.message}`)}}return()=>{if(f&&f.destroy)try{f.destroy()}catch(h){console.error("[Identity] Error destroying provider:",h)}}},[y,m,f,g,r,M]);const b=async()=>{try{D(null),te(!1),await N(),z(!0)}catch(h){console.error("Error starting identity verification:",h)}},G=async()=>{try{D(null),te(!1),j(null),console.log("[Identity] Restarting verification..."),await F(),z(!0)}catch(h){console.error("Error restarting identity verification:",h),D(h.message||"Failed to restart verification")}};if(Y||w)return e.jsx(J,{children:e.jsxs(Z,{children:[e.jsx(Ce,{className:"my-8"}),e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-4",children:"Loading identity verification..."})]})});if(T)return e.jsx(J,{children:e.jsx(Z,{children:e.jsxs("p",{className:"text-danger-500",children:["Error: ",T.message]})})});if(g&&($||M))return e.jsxs(J,{children:[e.jsx(ye,{children:e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"Verification Session Issue"})}),e.jsxs(Z,{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:M?"Session Expired":"Verification Error"}),e.jsx("p",{className:"text-red-800 dark:text-red-200 text-sm",children:$||"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(xe,{className:"flex justify-between",children:[s&&e.jsx(V,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(V,{type:"button",onClick:G,disabled:w,children:w?"Restarting...":"Restart Verification"})]})]});if(g&&u){const h=y;return m!=null&&m.url?e.jsxs(J,{children:[e.jsx(ye,{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(V,{type:"button",variant:"outline",size:"sm",onClick:G,disabled:w,children:"Restart"})]})}),e.jsxs(Z,{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:m.url,className:"w-full h-full border-0 rounded-lg",allow:"camera; microphone; geolocation",title:"Identity Verification",onLoad:O=>{var q,p,k;console.log("[Identity] Iframe loaded");try{const R=O.target,v=R.contentDocument||((q=R.contentWindow)==null?void 0:q.document);if(v){const i=((k=(p=v.body)==null?void 0:p.textContent)==null?void 0:k.toLowerCase())||"";(i.includes("expired")||i.includes("invalid")||i.includes("error"))&&(console.warn("[Identity] Iframe shows expiration message"),te(!0),D("Your verification link has expired."))}}catch{console.log("[Identity] Cannot check iframe content (CORS)")}}})})]}),s&&e.jsx(xe,{children:e.jsx(V,{variant:"outline",onClick:s,children:"Back"})})]}):h===Ne.SardinAI?e.jsxs(J,{children:[e.jsxs(ye,{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(Z,{children:e.jsxs("div",{className:"text-center py-12",children:[e.jsx(Ce,{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(J,{children:[e.jsxs(ye,{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(Z,{children:e.jsx("div",{id:"identity-container",className:"min-h-[400px]"})}),s&&e.jsx(xe,{children:e.jsx(V,{variant:"outline",onClick:s,children:"Back"})})]})}const Q=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),ie=(h=4)=>({1:"col-span-1",2:"col-span-2",3:"col-span-3",4:"col-span-4"})[h]||"col-span-4",ke=(h,O)=>{if(!O&&O!==0)return"—";if(Q.has(h)&&h!=="mobileCountryCode"){const q=H.find(p=>p.value===O);return q?q.label:String(O)}return String(O)},Fe=({helpText:h})=>{const[O,q]=o.useState(!1),p=o.useRef(null),[,k]=o.useState({top:0,left:0}),R=()=>{if(p.current){const v=p.current.getBoundingClientRect();k({top:v.bottom+window.scrollY+6,left:v.left+window.scrollX})}q(!0)};return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"metakyc-help-btn",ref:p,onClick:R,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:"?"}),O&&it.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:()=>q(!1),children:e.jsxs("div",{onClick:v=>v.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:h},style:{fontSize:13,color:"var(--metakyc-text-primary, #111827)",lineHeight:1.6}}),e.jsx("button",{type:"button",onClick:()=>q(!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)]})},he=(h,O)=>O?e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:5,flexWrap:"nowrap"},children:[e.jsx("div",{style:{flex:1,minWidth:0},children:h}),e.jsx("div",{style:{paddingTop:24},children:e.jsx(Fe,{helpText:O})})]}):h,qe=(h,O)=>{const q=`cf-${O}`,p=h.paramName??"",k=oe[p];if(h.customType==="br")return e.jsx("div",{className:ie(h.colSpan),style:{minHeight:"0.5rem"}},q);if(h.customType==="paragraph")return e.jsx("div",{className:ie(h.colSpan),children:e.jsx("div",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:h.label||""}})},q);if(h.customType==="html")return e.jsx("div",{className:ie(h.colSpan),dangerouslySetInnerHTML:{__html:h.label||""}},q);if(h.customType==="link")return e.jsx("div",{className:ie(h.colSpan),children:he(e.jsx("a",{href:h.linkUrl??"#",target:"_blank",rel:"noopener noreferrer",className:"text-sm underline",style:{color:"var(--metakyc-primary, #6366f1)"},children:h.displayText||h.label||h.linkText||h.linkUrl}),h.helpText)},q);if(h.customType==="checkbox"||h.customType==="link_checkbox"){const R=k==="true"||k===!0;return e.jsx("div",{className:ie(h.colSpan),children:he(e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:!!R,onChange:v=>A(i=>({...i,[p]:String(v.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:h.customType==="link_checkbox"&&h.linkUrl?e.jsxs(e.Fragment,{children:[e.jsx("a",{href:h.linkUrl,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--metakyc-primary, #6366f1)",textDecoration:"underline"},children:h.linkText||h.label}),h.label&&h.linkText?` ${h.label}`:""]}):h.displayText||h.label})]}),h.helpText)},q)}if(h.customType==="group_checkbox"){const R=Array.isArray(k)?k:k?[k]:[],v=i=>{h.singleSelect?A(d=>({...d,[p]:R[0]===i?[]:[i]})):A(d=>({...d,[p]:R.includes(i)?R.filter(E=>E!==i):[...R,i]}))};return e.jsx("div",{className:ie(h.colSpan),children:he(e.jsxs("div",{className:"space-y-1.5",children:[h.label&&e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:h.displayText||h.label}),(h.options||[]).map(i=>e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:R.includes(i.value),onChange:()=>v(i.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:i.label})]},i.value))]}),h.helpText)},q)}return h.customType==="radio_group"?e.jsx("div",{className:ie(h.colSpan),children:he(e.jsxs("div",{className:"space-y-1.5",children:[h.label&&e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:h.displayText||h.label}),(h.options||[]).map(R=>e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"radio",name:`rg-${p}`,value:R.value,checked:k===R.value,onChange:()=>A(v=>({...v,[p]:R.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:R.label})]},R.value))]}),h.helpText)},q):e.jsx("div",{className:ie(h.colSpan),children:he(e.jsx(me,{label:h.displayText||h.label||p,value:String(k??""),onChange:R=>A(v=>({...v,[p]:R.target.value}))}),h.helpText)},q)},Ye=(h,O)=>{if(h.isCustom)return qe(h,O);const q=h.name??"",p=_e[q],k=h.displayText||(p==null?void 0:p.label)||q,R=ee[q]??"",v=q==="mobileCountryCode",i=!!(p!=null&&p.countriesType)&&!v;return h.editable?v?e.jsx("div",{className:ie(h.colSpan??2),children:he(e.jsx(Ae,{label:k,value:String(R),onChange:d=>ue(E=>({...E,[q]:d})),options:[{value:"",label:"Select country code…"},...K]}),h.helpText)},`epc-${O}`):i?e.jsx("div",{className:ie(h.colSpan??2),children:he(e.jsx(Ae,{label:k,value:String(R),onChange:d=>ue(E=>({...E,[q]:d})),options:[{value:"",label:`Select ${k.toLowerCase()}…`},...H]}),h.helpText)},`ec-${O}`):e.jsx("div",{className:ie(h.colSpan??2),children:he(e.jsx(me,{label:k,type:(p==null?void 0:p.type)==="date"?"date":(p==null?void 0:p.type)==="email"?"email":"text",value:String(R),onChange:d=>ue(E=>({...E,[q]:d.target.value}))}),h.helpText)},`ei-${O}`):e.jsx("div",{className:ie(h.colSpan??2),children:he(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:k}),e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)",minHeight:"1.5rem"},children:ke(q,R)})]}),h.helpText)},`ro-${O}`)};if(U){const h=U.title||"Review Your Information",O=U.subtitle||"Please review and confirm your information before starting identity verification";return e.jsx("form",{onSubmit:q=>{q.preventDefault(),b()},children:e.jsxs(J,{children:[e.jsxs(ye,{children:[e.jsx("h2",{className:"text-lg font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:h}),e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:O})]}),e.jsx(Z,{children:e.jsx("div",{className:"grid grid-cols-4 gap-4",children:U.fields.map((q,p)=>Ye(q,p))})}),e.jsxs(xe,{className:"flex justify-between",children:[s&&e.jsx(V,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(V,{type:"submit",isLoading:w,children:"Confirm and Start Verification"})]})]})})}return e.jsx("form",{onSubmit:B.handleSubmit(b),children:e.jsxs(J,{children:[e.jsxs(ye,{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(Z,{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:`${((Te=P==null?void 0:P.applicantRequestData)==null?void 0:Te.firstName)||""} ${((Ve=P==null?void 0:P.applicantRequestData)==null?void 0:Ve.lastName)||""}`.trim()},{label:"Email",value:(Me=P==null?void 0:P.applicantRequestData)==null?void 0:Me.email},{label:"Date of Birth",value:((He=P==null?void 0:P.applicantRequestData)==null?void 0:He.dateOfBirth)||"Not provided"}].map(({label:h,value:O})=>e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:h}),e.jsx("p",{className:"mt-1 text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:O})]},h))}),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(Oe.Controller,{control:B.control,name:"country",render:({field:h})=>e.jsx(Ae,{label:"Country",value:h.value,onChange:h.onChange,options:[{value:"",label:"Select country…"},...H]})}),e.jsx(Oe.Controller,{control:B.control,name:"nationality",render:({field:h})=>e.jsx(Ae,{label:"Nationality",value:h.value,onChange:h.onChange,options:[{value:"",label:"Select nationality…"},...H]})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Oe.Controller,{control:B.control,name:"street",render:({field:h})=>e.jsx(me,{...h,label:"Street"})}),e.jsx(Oe.Controller,{control:B.control,name:"streetNumber",render:({field:h})=>e.jsx(me,{...h,label:"Street Number"})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Oe.Controller,{control:B.control,name:"city",render:({field:h})=>e.jsx(me,{...h,label:"City"})}),e.jsx(Oe.Controller,{control:B.control,name:"zip",render:({field:h})=>e.jsx(me,{...h,label:"ZIP / Postal Code"})})]}),e.jsx(Oe.Controller,{control:B.control,name:"phonenumber",render:({field:h})=>e.jsx(me,{...h,label:"Phone Number",type:"tel"})})]})]}),e.jsxs(xe,{className:"flex justify-between",children:[s&&e.jsx(V,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(V,{type:"submit",isLoading:w,children:"Confirm and Start Verification"})]})]})})},ut=({kycStatus:t,reviewStatus:r,workflowResult:s,customMessage:a,onContinue:n,onContactSupport:l})=>{const u=t===Be.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===Be.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===Be.Pending||t===Be.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===$e.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===$e.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===$e.UnderReview||r===$e.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===tt.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===tt.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===tt.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(J,{children:[e.jsxs(Z,{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(xt,{variant:u.type==="success"?"success":u.type==="error"?"danger":u.type==="pending"?"warning":"info",children:t!=null?Be[t]:$e[r]})}),e.jsx("p",{className:"text-center mb-6 max-w-md mx-auto",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:a||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?Be[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:$e[r]})]})]})})]}),e.jsxs(xe,{className:"flex justify-center gap-4",children:[u.type==="success"&&n&&e.jsx(V,{onClick:n,size:"lg",children:"Continue"}),u.type==="error"&&e.jsxs(e.Fragment,{children:[l&&e.jsx(V,{variant:"outline",onClick:l,children:"Contact Support"}),n&&e.jsx(V,{onClick:n,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"})})]})]})},Mr=({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"}})}),Ze=({title:t,subtitle:r,className:s=""})=>{const{currentTheme:a}=we(),n=t||(a==null?void 0:a.title)||"",l=!!(a!=null&&a.logo&&a.logo.visible&&a.logo.url),c=!!n;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(Mr,{config:a.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:n})]}),r&&e.jsx("p",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:r})]})},at=["firstName","lastName","email","phonenumber","dateOfBirth"];function Qe(t){return t==null||t===""||Array.isArray(t)&&t.length===0}const et={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"},jt=({helpText:t,children:r})=>{const[s,a]=o.useState(!1);if(!t)return e.jsx(e.Fragment,{children:r});const n=s?e.jsx("div",{role:"dialog","aria-modal":"true",onClick:()=>a(!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:()=>a(!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:()=>a(!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"&&n?it.createPortal(n,document.body):null]})},ks=({workflowKey:t,externalRefId:r,onSuccess:s,onCancel:a})=>{var O,q,p,k,R,v;const{config:n,baseInformationService:l,currentTheme:c}=we(),{createApplicant:u,isLoading:y}=yt(),m=t||((O=n.applicantForm)==null?void 0:O.workflowKey);if(!m)throw new Error("workflowKey is required. Provide it either as a prop to CreateApplicantForm or set it in config.applicantForm.workflowKey");const w=r||((q=n.applicantForm)==null?void 0:q.externalRefId)||"",T=((p=n.applicantForm)==null?void 0:p.email)||"",N=((k=n.applicantForm)==null?void 0:k.hiddenValues)||{},f=(((R=n.applicantForm)==null?void 0:R.fieldLabelMode)||(c==null?void 0:c.fieldLabelMode)||"label")!=="placeholder",j=o.useMemo(()=>c!=null&&c.applicantFormPages&&c.applicantFormPages.length>0?c.applicantFormPages:null,[c==null?void 0:c.applicantFormPages]),P=o.useMemo(()=>{const i=new Set(at),d=c==null?void 0:c.applicantFormRequiredFields;if(d)for(const E of d)i.add(E);if(j)for(const E of j)for(const x of E.fields)!x.isCustom&&x.name&&x.required&&i.add(x.name);return Array.from(i)},[c==null?void 0:c.applicantFormRequiredFields,j]),_=o.useMemo(()=>{var E;if(j){const x=j.flatMap(S=>S.fields).filter(S=>!S.isCustom&&S.name).map(S=>S.name),C=new Set(x);for(const S of at)C.add(S);return Array.from(C)}let i;(E=n.applicantForm)!=null&&E.visibleFields?i=n.applicantForm.visibleFields:c!=null&&c.applicantFormVisibleFields&&c.applicantFormVisibleFields.length>0?i=c.applicantFormVisibleFields:i=Mt;const d=new Set(i);for(const x of at)d.add(x);return Array.from(d)},[(v=n.applicantForm)==null?void 0:v.visibleFields,c==null?void 0:c.applicantFormVisibleFields,j]),H=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),L=o.useMemo(()=>{var d,E;const i=new Set;if(j)for(const x of j)for(const C of x.fields)!C.isCustom&&C.name&&H.has(C.name)&&i.add(C.countriesType??((d=_e[C.name])==null?void 0:d.countriesType));else for(const x of _)H.has(x)&&i.add((E=_e[x])==null?void 0:E.countriesType);return i.size===0&&i.add(void 0),Array.from(i)},[_,j]),[K,W]=o.useState({}),[Y,I]=o.useState(!0),g=o.useRef(new Set),z=o.useRef(new Set);o.useEffect(()=>{if(!c)return;const i=L.filter(x=>{const C=x!=null?String(x):"all";return!z.current.has(C)&&!g.current.has(C)});if(i.length===0){L.every(C=>{const S=C!=null?String(C):"all";return z.current.has(S)})&&I(!1);return}I(!0);const d=i.map(x=>x!=null?String(x):"all");d.forEach(x=>g.current.add(x)),(async()=>{try{const x=await Promise.all(i.map(async C=>{const S=C!=null?String(C):"all",ne=await l.getCountries("",n.locale||"en",C),se=C===40,fe=new Set,pe=ne.map(ce=>se&&ce.countryCode?{value:ce.countryCode,label:`${ce.countryCode} – ${ce.name}`}:{value:ce.abbreviation3||ce.abbreviation,label:ce.name}).filter(ce=>!ce.value||fe.has(ce.value)?!1:(fe.add(ce.value),!0));return z.current.add(S),g.current.delete(S),[S,pe]}));W(C=>({...C,...Object.fromEntries(x)}))}catch(x){d.forEach(C=>g.current.delete(C)),console.error("Failed to load countries:",x)}finally{L.every(C=>{const S=C!=null?String(C):"all";return z.current.has(S)})&&I(!1)}})()},[L,c]);const $=(i,d)=>{var C;const E=d??((C=_e[i])==null?void 0:C.countriesType),x=E!=null?String(E):"all";return K[x]||[]},D=Object.fromEntries(Object.entries(N).filter(([i])=>i in{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})),[M,te]=o.useState({workflowKey:m,firstName:"",lastName:"",title:"",email:T,dateOfBirth:"",phonenumber:"",externalRefId:w,mobileCountryCode:"",street:"",streetNumber:"",zip:"",city:"",country:"",nationality:"",otherNationality:[],defaultLanguage:"EN",taxCountry:"",placeOfBirth:"",countryOfBirth:"",salutation:null,educationLevel:"",occupation:"",taxNumber:"",...D}),re=Object.fromEntries(Object.entries(N).filter(([i])=>!(i in D)&&i!=="externalRefId"&&i!=="workflowKey")),[ee,ue]=o.useState({...re}),[oe,A]=o.useState(0),[U,X]=o.useState({}),[le,B]=o.useState(null),[b,G]=o.useState(!1),Q=(i,d)=>te(E=>({...E,[i]:d})),ie=(i,d)=>ue(E=>({...E,[i]:d})),ke=i=>!i.conditionalOn||ee[i.conditionalOn]==="true",Fe=j&&oe<j.length-1?oe+1:-1,he=j&&oe>0?oe-1:-1,qe=i=>{var E;const d={};for(const x of i.fields)if(x.isCustom){if(x.customType==="paragraph"||x.customType==="html"||x.customType==="br"||x.customType==="link")continue;if(x.required&&x.paramName){const C=ee[x.paramName],S=x.displayText||x.label||x.paramName;x.customType==="checkbox"||x.customType==="link_checkbox"?C!=="true"&&(d[x.paramName]=`${S} is required.`):(!C||C.trim()==="")&&(d[x.paramName]=`${S} is required.`)}}else if(x.name){const C=x.name;if(P.includes(C)&&Qe(M[C])){const S=x.displayText||((E=_e[C])==null?void 0:E.label)||C;d[C]=`${S} is required.`}}return d},Ye=async()=>{if(!j)return;const i=j[oe];if(i.conditionalOn&&!ke(i)){X({}),Fe>=0?A(Fe):await Te();return}const d=qe(i);if(Object.keys(d).length>0){X(d);return}X({}),Fe>=0?A(Fe):await Te()},Te=async()=>{if(j){let i={};for(const d of j)ke(d)&&(i={...i,...qe(d)});if(Object.keys(i).length>0){X(i);return}}G(!0),B(null);try{if(!M.externalRefId||M.externalRefId.trim()===""){B("External Reference ID is required. Please pass it via config.applicantForm.externalRefId.");return}const i={workflowKey:M.workflowKey,externalRefId:M.externalRefId.trim()};if(j){for(const C of j)if(ke(C)){for(const S of C.fields)if(!S.isCustom&&S.name){const ne=S.name,se=M[ne];Qe(se)||(i[ne]=se)}}for(const C of at)if(i[C]===void 0){const S=M[C];Qe(S)||(i[C]=S)}}else _.forEach(C=>{if(C==="externalRefId")return;const S=M[C];Qe(S)||(i[C]=S)});const d=[];if(j){for(const C of j)if(ke(C))for(const S of C.fields){if(!S.isCustom||!S.paramName||S.customType==="paragraph"||S.customType==="html"||S.customType==="br"||S.customType==="link")continue;const ne=ee[S.paramName]??"";let se;if(S.customType==="checkbox"||S.customType==="link_checkbox")se=ne==="true"?"yes":"no";else if(se=ne,!se&&!S.required)continue;d.push({paramName:S.paramName,value:se})}}for(const[C,S]of Object.entries(D))i[C]===void 0&&!Qe(S)&&(i[C]=S);const E=new Set(d.map(C=>C.paramName));for(const[C,S]of Object.entries(re))!E.has(C)&&S&&d.push({paramName:C,value:S});d.length>0&&(i.applicantAdditionalDatas=d);const x=await u(i);s(x.applicantId)}catch(i){console.error("Error creating applicant:",i),B(i.message||"Failed to create applicant")}finally{G(!1)}},Ve=async i=>{var d;i.preventDefault();for(const E of P)if(Qe(M[E])){const x=((d=_e[E])==null?void 0:d.label)||E;B(`${x} is required.`);return}await Te()},Me=(i,d,E,x,C)=>{var ht;const S=_e[i];if(!S)return null;const ne=P.includes(i),se=U[i],fe=E||S.label,pe=d??i,ce={required:ne},Pe=C?C!=="placeholder":f,ze=Pe?fe:void 0,zr=Pe?"...":fe;switch(S.type){case"select":if(i==="country"||i==="nationality"||i==="taxCountry"||i==="countryOfBirth"||i==="mobileCountryCode"){const je=$(i,x);return e.jsx(Ae,{...ce,label:ze,value:M[i]||"",onChange:We=>Q(i,We),options:[{value:"",label:`Select ${zr.toLowerCase()}`},...je],disabled:Y,error:se},pe)}if(i==="salutation")return e.jsx(Ae,{...ce,label:ze,value:((ht=M[i])==null?void 0:ht.toString())||"",onChange:je=>Q(i,je?Number(je):null),options:[{value:"",label:Pe?"Select salutation...":fe},{value:rt.Male.toString(),label:"Male"},{value:rt.Female.toString(),label:"Female"},{value:rt.Other.toString(),label:"Other"}],error:se},pe);if(i==="defaultLanguage"){const je=c!=null&&c.allowedLanguages&&c.allowedLanguages.length>0?dt.filter(We=>c.allowedLanguages.includes(We.value)):dt;return e.jsx(Ae,{...ce,label:ze,value:M[i]||"",onChange:We=>Q(i,We),options:[{value:"",label:Pe?"Select language...":fe},...je],error:se},pe)}return null;case"multiselect":if(i==="otherNationality"){const je=$(i,x);return e.jsx(jr,{...ce,label:ze,value:M[i]||[],onChange:We=>Q(i,We),options:je,placeholder:Pe?"Select other nationalities...":fe,disabled:Y},pe)}return null;case"date":return e.jsx(me,{...ce,type:"date",label:ze,placeholder:Pe?void 0:fe,value:M[i]||"",onChange:je=>Q(i,je.target.value),error:se},pe);case"email":return e.jsx(me,{...ce,type:"email",label:ze,placeholder:Pe?void 0:fe,value:M[i]||"",onChange:je=>Q(i,je.target.value),error:se},pe);case"tel":return e.jsx(me,{...ce,type:"tel",label:ze,placeholder:Pe?void 0:fe,value:M[i]||"",onChange:je=>Q(i,je.target.value),error:se},pe);default:return e.jsx(me,{...ce,type:"text",label:ze,placeholder:Pe?void 0:fe,value:M[i]||"",onChange:je=>Q(i,je.target.value),error:se},pe)}},He=(i,d)=>{const E=i.labelMode?i.labelMode!=="placeholder":f;if(i.customType==="paragraph"){const S=i.displayText||i.label||"";return e.jsx("p",{className:"metakyc-paragraph",style:{fontSize:"14px",lineHeight:"1.7",margin:0,color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:S}},`custom-${d}`)}if(i.customType==="html")return e.jsx("div",{dangerouslySetInnerHTML:{__html:i.label||""}},`custom-${d}`);if(i.customType==="br")return e.jsx("div",{style:{height:"12px"}},`custom-${d}`);if(i.customType==="link"){const S=i.displayText||i.label||i.linkText||i.linkUrl||"";return e.jsx("div",{className:"metakyc-link-field",children:e.jsxs("a",{href:i.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:[S,e.jsx("span",{style:{fontSize:"10px",opacity:.7},children:"↗"})]})},`custom-${d}`)}if(!i.paramName)return null;const x=U[i.paramName],C=i.displayText||i.label||i.paramName;if(i.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:ee[i.paramName]==="true",onChange:S=>ie(i.paramName,S.target.checked?"true":"false"),className:"metakyc-option-input",style:et}),e.jsxs("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:[C,i.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),x&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:x})]},`custom-${d}`);if(i.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:ee[i.paramName]==="true",onChange:S=>ie(i.paramName,S.target.checked?"true":"false"),className:"metakyc-option-input",style:{...et,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," ",i.linkUrl&&e.jsx("a",{href:i.linkUrl,target:"_blank",rel:"noopener noreferrer",className:"underline",style:{color:"var(--metakyc-primary, #2563eb)"},onClick:S=>S.stopPropagation(),children:i.linkText||i.linkUrl}),i.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),x&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:x})]},`custom-${d}`);if(i.customType==="group_checkbox"){const S=(ee[i.paramName]||"").split(",").filter(Boolean);return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[E&&e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[C,i.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:(i.options||[]).map(ne=>{const se=i.singleSelect?ee[i.paramName]===ne.value:S.includes(ne.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:fe=>{if(i.singleSelect)ie(i.paramName,fe.target.checked?ne.value:"");else{const pe=fe.target.checked?[...S,ne.value]:S.filter(ce=>ce!==ne.value);ie(i.paramName,pe.join(","))}},className:"metakyc-option-input",style:et}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:ne.label})]},ne.value)})}),x&&e.jsx("p",{className:"text-red-500 text-xs",children:x})]},`custom-${d}`)}return i.customType==="radio_group"?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[E&&e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[C,i.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:(i.options||[]).map(S=>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:ee[i.paramName]===S.value,onChange:()=>ie(i.paramName,S.value),name:`radio-group-${i.paramName}-${d}`,className:"metakyc-option-input",style:et}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:S.label})]},S.value))}),x&&e.jsx("p",{className:"text-red-500 text-xs",children:x})]},`custom-${d}`):e.jsx(me,{type:"text",label:E?`${C}${i.required?" *":""}`:void 0,placeholder:E?void 0:C,value:ee[i.paramName]||"",onChange:S=>ie(i.paramName,S.target.value),required:i.required,error:x},`custom-${d}`)},h=(i,d)=>{const E=ke(i);return e.jsxs("div",{className:"space-y-4",children:[i.conditionalOn&&e.jsx(jt,{helpText:i.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:E,onChange:x=>ie(i.conditionalOn,x.target.checked?"true":"false"),className:"metakyc-option-input",style:et}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",fontWeight:500},children:i.conditionalOn})]})}),E&&e.jsx("div",{className:"grid grid-cols-4 gap-4",children:i.fields.map((x,C)=>{const S=x.colSpan===1?"col-span-1":x.colSpan===2?"col-span-2":x.colSpan===3?"col-span-3":"col-span-4",ne=x.isCustom?`custom-${C}-${x.paramName}`:`builtin-${x.name}-${C}`;return e.jsx("div",{className:S,children:e.jsx(jt,{helpText:x.helpText,children:x.isCustom?He(x,C):Me(x.name,ne,x.displayText,x.countriesType,x.labelMode)})},ne)})})]})};if(!c||Y)return e.jsx("div",{className:"metakyc-sdk",children:e.jsx(J,{children:e.jsxs(Z,{children:[e.jsx(Ce,{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 i=j[oe]??j[0],d=he===-1,E=Fe===-1,x=j.length,C=ke(i),S=Object.values(U);return e.jsx("div",{className:"metakyc-sdk",children:e.jsxs(J,{children:[e.jsx(ye,{children:e.jsx(Ze,{title:(c==null?void 0:c.title)||"Create Applicant"})}),e.jsxs(Z,{children:[(i.title||i.subtitle||i.description)&&e.jsxs("div",{className:"mb-4",children:[i.title&&e.jsx("h3",{className:"font-semibold text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:i.title}),i.subtitle&&e.jsx("p",{className:"text-sm mt-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:i.subtitle}),i.description&&i.description!==i.subtitle&&e.jsx("p",{className:"text-xs mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:i.description})]}),(le||S.length>0)&&e.jsxs("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-lg",children:[le&&e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",le]}),S.map((ne,se)=>e.jsx("p",{className:"text-red-600 text-sm",children:ne},se))]}),x>1&&e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[j.map((ne,se)=>e.jsx("div",{className:`h-1.5 rounded-full transition-all ${se===oe?"flex-1":"w-8"}`,style:se===oe?{backgroundColor:"var(--metakyc-primary, #2563eb)"}:se<oe?{backgroundColor:"var(--metakyc-primary-light, #93c5fd)",opacity:.7}:{backgroundColor:"#e5e7eb"}},se)),e.jsxs("span",{className:"text-xs text-gray-400 flex-shrink-0",children:[oe+1," / ",x]})]}),h(i)]}),e.jsxs(xe,{className:"flex justify-between",children:[e.jsxs("div",{children:[!d&&e.jsx(V,{type:"button",variant:"outline",onClick:()=>{A(he),X({})},disabled:b||y,children:"Previous"}),d&&a&&e.jsx(V,{type:"button",variant:"outline",onClick:a,disabled:b||y,children:"Cancel"})]}),e.jsx(V,{type:"button",isLoading:b||y,onClick:E?Te:Ye,children:E?i.conditionalOn&&!C?"Skip & Submit":"Submit":i.conditionalOn&&!C?"Skip":"Next"})]})]})})}return e.jsx("div",{className:"metakyc-sdk",children:e.jsx("form",{onSubmit:Ve,children:e.jsxs(J,{children:[e.jsx(ye,{children:e.jsx(Ze,{title:(c==null?void 0:c.title)||"Create Applicant"})}),e.jsxs(Z,{children:[le&&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:"})," ",le]})}),e.jsx("div",{className:"grid grid-cols-4 gap-4",children:_.map(i=>e.jsx("div",{className:"col-span-4",children:Me(i)},i))})]}),e.jsxs(xe,{className:"flex justify-between",children:[a&&e.jsx(V,{type:"button",variant:"outline",onClick:a,disabled:b||y,children:"Cancel"}),e.jsx(V,{type:"submit",isLoading:b||y,children:"Create Applicant"})]})]})})})},wt=["companyName","email"];function ct(t){return t==null||t===""||Array.isArray(t)&&t.length===0}const js=({workflowKey:t,externalRefId:r,onSuccess:s,onCancel:a})=>{var Me,He,h,O,q;const{config:n,baseInformationService:l,currentTheme:c}=we(),{createCompanyApplicant:u,isLoading:y}=yt(),m=t||((Me=n.applicantForm)==null?void 0:Me.workflowKey);if(!m)throw new Error("workflowKey is required. Provide it either as a prop to CreateCompanyApplicantForm or set it in config.applicantForm.workflowKey");const w=r||((He=n.applicantForm)==null?void 0:He.externalRefId)||"",T=((h=n.applicantForm)==null?void 0:h.email)||"",F=(((O=n.applicantForm)==null?void 0:O.fieldLabelMode)||(c==null?void 0:c.fieldLabelMode)||"label")!=="placeholder",f=o.useMemo(()=>c!=null&&c.companyFormPages&&c.companyFormPages.length>0?c.companyFormPages:null,[c==null?void 0:c.companyFormPages]),j=o.useMemo(()=>{const p=new Set(wt),k=c==null?void 0:c.companyFormRequiredFields;if(k)for(const R of k)p.add(R);if(f)for(const R of f)for(const v of R.fields)!v.isCustom&&v.name&&v.required&&p.add(v.name);return Array.from(p)},[c==null?void 0:c.companyFormRequiredFields,f]),P=o.useMemo(()=>{var p;if(f){const k=f.flatMap(v=>v.fields).filter(v=>!v.isCustom&&v.name).map(v=>v.name),R=new Set(k);for(const v of wt)R.add(v);return Array.from(R)}return(p=n.applicantForm)!=null&&p.visibleFields?n.applicantForm.visibleFields:c!=null&&c.companyFormVisibleFields&&c.companyFormVisibleFields.length>0?c.companyFormVisibleFields:Dt},[(q=n.applicantForm)==null?void 0:q.visibleFields,c==null?void 0:c.companyFormVisibleFields,f]),_=new Set(["countryResidence","addressCountry"]),H=o.useMemo(()=>{var k,R;const p=new Set;if(f)for(const v of f)for(const i of v.fields)!i.isCustom&&i.name&&_.has(i.name)&&p.add(i.countriesType??((k=Ue[i.name])==null?void 0:k.countriesType));else for(const v of P)_.has(v)&&p.add((R=Ue[v])==null?void 0:R.countriesType);return p.size===0&&p.add(void 0),Array.from(p)},[P,f]),[L,K]=o.useState({}),[W,Y]=o.useState(!0),I=o.useRef(new Set),g=o.useRef(new Set);o.useEffect(()=>{if(!c)return;const p=H.filter(v=>{const i=v!=null?String(v):"all";return!g.current.has(i)&&!I.current.has(i)});if(p.length===0){H.every(i=>g.current.has(i!=null?String(i):"all"))&&Y(!1);return}Y(!0);const k=p.map(v=>v!=null?String(v):"all");k.forEach(v=>I.current.add(v)),(async()=>{try{const v=await Promise.all(p.map(async i=>{const d=i!=null?String(i):"all",E=await l.getCountries("",n.locale||"en",i),x=new Set,C=E.map(S=>({value:S.abbreviation3||S.abbreviation,label:S.name})).filter(S=>!S.value||x.has(S.value)?!1:(x.add(S.value),!0));return g.current.add(d),I.current.delete(d),[d,C]}));K(i=>({...i,...Object.fromEntries(v)}))}catch(v){k.forEach(i=>I.current.delete(i)),console.error("Failed to load countries:",v)}finally{H.every(i=>g.current.has(i!=null?String(i):"all"))&&Y(!1)}})()},[H,c]);const z=(p,k)=>{var i;const R=k??((i=Ue[p])==null?void 0:i.countriesType),v=R!=null?String(R):"all";return L[v]||[]},[$,D]=o.useState({workflowKey:m,companyName:"",email:T,phone:"",registrationNumber:"",countryResidence:"",legalAddress:"",incorporatedOn:"",controlScheme:"",taxId:"",registrationLocation:"",website:"",postalAddress:"",street:"",streetNumber:"",city:"",state:"",postalCode:"",addressCountry:"",lei:"",externalRefId:w}),[M,te]=o.useState({}),[re,ee]=o.useState(0),[ue,oe]=o.useState({}),[A,U]=o.useState(null),[X,le]=o.useState(!1),B=(p,k)=>D(R=>({...R,[p]:k})),b=(p,k)=>te(R=>({...R,[p]:k})),G=p=>!p.conditionalOn||M[p.conditionalOn]==="true",Q=f&&re<f.length-1?re+1:-1,ie=f&&re>0?re-1:-1,ke=p=>{var R;const k={};for(const v of p.fields)if(v.isCustom){if(v.customType==="paragraph"||v.customType==="html"||v.customType==="br"||v.customType==="link")continue;if(v.required&&v.paramName){const i=M[v.paramName],d=v.displayText||v.label||v.paramName;v.customType==="checkbox"||v.customType==="link_checkbox"?i!=="true"&&(k[v.paramName]=`${d} is required.`):(!i||i.trim()==="")&&(k[v.paramName]=`${d} is required.`)}}else if(v.name){const i=v.name;if(j.includes(i)&&ct($[i])){const d=v.displayText||((R=Ue[i])==null?void 0:R.label)||i;k[i]=`${d} is required.`}}return k},Fe=async()=>{if(!f)return;const p=f[re];if(p.conditionalOn&&!G(p)){oe({}),Q>=0?ee(Q):await he();return}const k=ke(p);if(Object.keys(k).length>0){oe(k);return}oe({}),Q>=0?ee(Q):await he()},he=async()=>{var p;if(f){let k={};for(const R of f)G(R)&&(k={...k,...ke(R)});if(Object.keys(k).length>0){oe(k);return}}le(!0),U(null);try{const k={workflowKey:$.workflowKey,externalRefId:((p=$.externalRefId)==null?void 0:p.trim())||void 0},R=f?f.filter(d=>G(d)).flatMap(d=>d.fields).filter(d=>!d.isCustom&&d.name).map(d=>d.name):P;for(const d of R){const E=$[d];if(!ct(E))switch(d){case"companyName":k.companyName=E;break;case"email":k.companyEmail=E;break;case"phone":k.companyPhone=E;break;case"registrationNumber":k.companyRegistrationNumber=E;break;case"countryResidence":k.companyCountry=E;break;case"city":k.companyCity=E;break;case"street":k.companyStreet=E;break;case"postalCode":k.companyZip=E;break;default:k[d]=E;break}}const v=[];if(f){for(const d of f)if(G(d))for(const E of d.fields){if(!E.isCustom||!E.paramName||E.customType==="paragraph"||E.customType==="html"||E.customType==="br"||E.customType==="link")continue;const x=M[E.paramName]??"";let C;if(E.customType==="checkbox"||E.customType==="link_checkbox")C=x==="true"?"yes":"no";else if(C=x,!C&&!E.required)continue;v.push({paramName:E.paramName,value:C})}}v.length>0&&(k.applicantAdditionalDatas=v);const i=await u(k);s(i.applicantId)}catch(k){console.error("Error creating company applicant:",k),U(k.message||"Failed to create company applicant")}finally{le(!1)}},qe=async p=>{var k;p.preventDefault();for(const R of j)if(ct($[R])){const v=((k=Ue[R])==null?void 0:k.label)||R;U(`${v} is required.`);return}await he()},Ye=(p,k,R,v,i)=>{const d=Ue[p];if(!d)return null;const E=j.includes(p),x=ue[p],C=R||d.label,S=k??p,ne=i?i!=="placeholder":F,se=ne?C:void 0,fe=ne?"...":C;switch(d.type){case"select":if(p==="countryResidence"||p==="addressCountry"){const pe=z(p,v);return e.jsx(Ae,{required:E,label:se,value:$[p]||"",onChange:ce=>B(p,ce),options:[{value:"",label:`Select ${fe.toLowerCase()}`},...pe],disabled:W,error:x},S)}return null;case"date":return e.jsx(me,{required:E,type:"date",label:se,placeholder:ne?void 0:C,value:$[p]||"",onChange:pe=>B(p,pe.target.value),error:x},S);case"email":return e.jsx(me,{required:E,type:"email",label:se,placeholder:ne?void 0:C,value:$[p]||"",onChange:pe=>B(p,pe.target.value),error:x},S);case"tel":return e.jsx(me,{required:E,type:"tel",label:se,placeholder:ne?void 0:C,value:$[p]||"",onChange:pe=>B(p,pe.target.value),error:x},S);default:return e.jsx(me,{required:E,type:"text",label:se,placeholder:ne?void 0:C,value:$[p]||"",onChange:pe=>B(p,pe.target.value),error:x},S)}},Te=(p,k)=>{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-${k}`);if(p.customType==="html")return e.jsx("div",{dangerouslySetInnerHTML:{__html:p.label||""}},`custom-${k}`);if(p.customType==="br")return e.jsx("div",{style:{height:"12px"}},`custom-${k}`);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-${k}`);if(!p.paramName)return null;const R=ue[p.paramName],v=p.displayText||p.label||p.paramName,i=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:M[p.paramName]==="true",onChange:d=>b(p.paramName,d.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:[v,p.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),R&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:R})]},`custom-${k}`):e.jsx(me,{type:"text",label:i?`${v}${p.required?" *":""}`:void 0,placeholder:i?void 0:v,value:M[p.paramName]||"",onChange:d=>b(p.paramName,d.target.value),required:p.required,error:R},`custom-${k}`)},Ve=p=>{const k=G(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:k,onChange:R=>b(p.conditionalOn,R.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})]}),k&&e.jsx("div",{className:"grid grid-cols-4 gap-4",children:p.fields.map((R,v)=>{const i=R.colSpan===1?"col-span-1":R.colSpan===2?"col-span-2":R.colSpan===3?"col-span-3":"col-span-4",d=R.isCustom?`custom-${v}-${R.paramName}`:`builtin-${R.name}-${v}`;return e.jsx("div",{className:i,children:R.isCustom?Te(R,v):Ye(R.name,d,R.displayText,R.countriesType,R.labelMode)},d)})})]})};if(!c||W)return e.jsx("div",{className:"metakyc-sdk",children:e.jsx(J,{children:e.jsxs(Z,{children:[e.jsx(Ce,{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(f){const p=f[re]??f[0],k=ie===-1,R=Q===-1,v=f.length,i=G(p),d=Object.values(ue);return e.jsx("div",{className:"metakyc-sdk",children:e.jsxs(J,{children:[e.jsx(ye,{children:e.jsx(Ze,{title:(c==null?void 0:c.title)||"Company Registration"})}),e.jsxs(Z,{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})]}),(A||d.length>0)&&e.jsxs("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-lg",children:[A&&e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",A]}),d.map((E,x)=>e.jsx("p",{className:"text-red-600 text-sm",children:E},x))]}),v>1&&e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[f.map((E,x)=>e.jsx("div",{className:`h-1.5 rounded-full transition-all ${x===re?"flex-1":"w-8"}`,style:x===re?{backgroundColor:"var(--metakyc-primary, #2563eb)"}:x<re?{backgroundColor:"var(--metakyc-primary-light, #93c5fd)",opacity:.7}:{backgroundColor:"#e5e7eb"}},x)),e.jsxs("span",{className:"text-xs text-gray-400 flex-shrink-0",children:[re+1," / ",v]})]}),Ve(p)]}),e.jsxs(xe,{className:"flex justify-between",children:[e.jsxs("div",{children:[!k&&e.jsx(V,{type:"button",variant:"outline",onClick:()=>{ee(ie),oe({})},disabled:X||y,children:"Previous"}),k&&a&&e.jsx(V,{type:"button",variant:"outline",onClick:a,disabled:X||y,children:"Cancel"})]}),e.jsx(V,{type:"button",isLoading:X||y,onClick:R?he:Fe,children:R?p.conditionalOn&&!i?"Skip & Submit":"Submit":p.conditionalOn&&!i?"Skip":"Next"})]})]})})}return e.jsx("div",{className:"metakyc-sdk",children:e.jsx("form",{onSubmit:qe,children:e.jsxs(J,{children:[e.jsx(ye,{children:e.jsx(Ze,{title:(c==null?void 0:c.title)||"Company Registration"})}),e.jsxs(Z,{children:[A&&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:"})," ",A]})}),e.jsx("div",{className:"grid grid-cols-4 gap-4",children:P.map(p=>e.jsx("div",{className:"col-span-4",children:Ye(p)},p))})]}),e.jsxs(xe,{className:"flex justify-between",children:[a&&e.jsx(V,{type:"button",variant:"outline",onClick:a,disabled:X||y,children:"Cancel"}),e.jsx(V,{type:"submit",isLoading:X||y,children:"Register Company"})]})]})})})},ws=({applicantId:t,onComplete:r,onError:s,theme:a="light",className:n})=>{const{progress:l,currentStep:c,steps:u,workflowKey:y,nextWorkflowKey:m,hasWorkflowChanged:w,isLoading:T,error:N,moveBack:F,refreshProgress:f}=hr(t),[j,P]=o.useState(!1);if(o.useEffect(()=>{N&&s&&s(N)},[N,s]),o.useEffect(()=>{l!=null&&l.workflowResult&&r&&r(l.workflowResult)},[l==null?void 0:l.workflowResult,r]),o.useEffect(()=>{a==="dark"?document.documentElement.classList.add("dark"):document.documentElement.classList.remove("dark")},[a]),o.useEffect(()=>{w&&P(!1)},[w]),T||!l)return e.jsx("div",{className:`metakyc-sdk ${n||""}`,children:e.jsx(J,{children:e.jsxs(Z,{children:[e.jsx(Ce,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Loading workflow..."})]})})});if(N)return e.jsx("div",{className:`metakyc-sdk ${n||""}`,children:e.jsx(J,{children:e.jsx(Z,{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:N.message})]})})})});if(w&&!j)return e.jsx("div",{className:`metakyc-sdk ${n||""}`,children:e.jsx(J,{children:e.jsx(Z,{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:m})]})]}),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:()=>P(!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===Re.Finished||l.status===Re.OnHold)return e.jsx("div",{className:`metakyc-sdk ${n||""}`,children:e.jsx(ut,{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 ${n||""}`,children:e.jsx(J,{children:e.jsxs(Z,{children:[e.jsx(Ce,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:l.status===Re.IdentityPending?"Loading identity verification...":"Loading current step..."})]})})});const _=W=>{switch(W){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""}},H=o.useRef(null),L=()=>{const W=u.filter($=>$.visibility!==!1),Y=W.findIndex($=>$.order===c.order),I=Y>=0?Y+1:1,g=W.length,z=g>1?Y/(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(Ze,{}),e.jsxs(xt,{variant:l.status===1?"info":"success",children:["Step ",I," 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:`${z}%`,transition:"width 0.4s ease"}})})}),e.jsx(Ss,{ref:H,visibleSteps:W,currentVisibleStepIndex:Y,getStepFallbackName:_})]})},K=()=>{const W={applicantId:t,onComplete:async()=>{await f()},onBack:c.order>0?F:void 0};switch(c.action){case ae.Questionaries:return e.jsx(Er,{...W});case ae.UploadDocument:return e.jsx(Ar,{...W});case ae.Overview:return e.jsx(Fr,{...W});case ae.IdentitySdk:return e.jsx(Dr,{...W});case ae.RiskScoring:return e.jsx(Tr,{...W});case ae.AdditionalData:case ae.InvestorCategorization:return e.jsx(Pr,{...W});case ae.AppropriatenessTest:return e.jsx(Lr,{...W});case ae.ManualReview:return e.jsx(ut,{kycStatus:l.kycStatus,reviewStatus:l.reviewStatus,workflowResult:l.workflowResult,customMessage:l.customMessage});default:return e.jsx(J,{children:e.jsxs(Z,{className:"py-12 text-center",children:[e.jsx("div",{className:"mb-4",children:e.jsx(Ce,{})}),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 ${n||""}`,children:[L(),K()]})},Ss=o.forwardRef(({visibleSteps:t,currentVisibleStepIndex:r,getStepFallbackName:s},a)=>{const n=o.useRef(null),l=o.useRef(null);return o.useImperativeHandle(a,()=>n.current),o.useEffect(()=>{if(l.current&&n.current){const c=n.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:n,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,m=u===r,w=y||m,T=c.displayName||c.name||s(c.action)||`Step ${u+1}`;return e.jsxs(o.Fragment,{children:[e.jsxs("div",{ref:m?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",...w?{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:m?600:400,color:m?"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 Cs(t){return De.z.object({questionResults:De.z.any()}).passthrough()}function Ns(t){let r=De.z.array(De.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(a=>a.size<=t.maxEachFileSizeByte),{message:`File size must not exceed ${Math.round(t.maxEachFileSizeByte/1024/1024)}MB`})),t.allowedTypes){const s=t.allowedTypes.split(",").map(a=>a.trim());r=r.refine(a=>a?a.every(n=>s.some(l=>l.endsWith("/*")?n.type.startsWith(l.slice(0,-2)):n.type===l)):!0,{message:"Invalid file type"})}return r}function Rs(t){const r={};return t.uploadDocumentFiles.forEach(s=>{const a=`file_${s.id}`;r[a]=Ns(s)}),De.z.object(r)}function Is(t){return De.z.any()}function Es(t){return De.z.string().min(1,"This question is required")}function As(t){const r={};return t.appropriatenessQuestions.forEach(s=>{const a=`question_${s.id}`;r[a]=Es()}),De.z.object(r)}const Fs=De.z.any();exports.ALLOWED_LANGUAGES=dt;exports.ApplicantProgressOnHoldReason=St;exports.ApplicantProgressStatus=Re;exports.ApplicantService=$t;exports.ApplicantStatus=Nt;exports.AppropriatenessQuestionType=Ft;exports.AppropriatenessTestService=Wt;exports.AppropriatenessTestStep=Lr;exports.Badge=xt;exports.BaseInformationService=Yt;exports.Button=V;exports.COMPANY_FIELD_METADATA=Ue;exports.Card=J;exports.CardContent=Z;exports.CardFooter=xe;exports.CardHeader=ye;exports.CountriesType=Le;exports.CreateApplicantForm=ks;exports.CreateCompanyApplicantForm=js;exports.CriteriaBuiltInType=Pt;exports.DEFAULT_COMPANY_VISIBLE_FIELDS=Dt;exports.DEFAULT_VISIBLE_FIELDS=Mt;exports.DocumentReviewStatus=At;exports.EndpointBuilder=Ot;exports.ErrorHandler=Ge;exports.EventEmitter=rr;exports.FIELD_METADATA=_e;exports.FileType=Et;exports.FileUpload=wr;exports.GenderType=rt;exports.Header=Ze;exports.HttpClient=Bt;exports.IdentityProviderManager=Ke;exports.IdentityService=qt;exports.IdentityVerificationProvider=Ne;exports.IdentityVerificationStep=Dr;exports.Input=me;exports.InvestorCategorizationService=Vt;exports.InvestorCategorizationStep=Pr;exports.InvestorCategorizationType=ge;exports.InvestorCategoryType=Lt;exports.KycProcessStatus=Rt;exports.KycStatus=Be;exports.KycStatusDisplay=ut;exports.KycWorkflow=ws;exports.Logo=Mr;exports.MetaKYCContext=mt;exports.MetaKYCError=Ie;exports.MetaKYCProvider=Kr;exports.MultiSelect=jr;exports.OnfidoProvider=or;exports.OverviewService=Ut;exports.OverviewStep=Fr;exports.PhoneInput=Sr;exports.QuestionnaireService=_t;exports.QuestionnaireStep=Er;exports.ReviewStatus=$e;exports.RiskCriteriaType=Tt;exports.RiskLevel=Ct;exports.RiskScoringService=Kt;exports.RiskScoringStep=Tr;exports.SardinAIProvider=lr;exports.SearchableSelect=Ae;exports.Select=ot;exports.Spinner=Ce;exports.StepRouter=ar;exports.SumsubProvider=ir;exports.ThemeManager=cr;exports.ThemePreset=be;exports.ThemeService=tr;exports.UploadDocumentService=Ht;exports.UploadDocumentStep=Ar;exports.UserType=It;exports.ValueDataType=Ee;exports.WorkflowOrchestrator=nr;exports.WorkflowResultType=tt;exports.WorkflowState=sr;exports.WorkflowStepAction=ae;exports.appropriatenessTestSchema=Fs;exports.clearAllStorage=Gr;exports.clearApplicantId=mr;exports.clearWorkflowState=xr;exports.cn=ve;exports.corporateTheme=Qt;exports.defaultConfig=zt;exports.defaultTheme=Se;exports.fileToBase64=dr;exports.fintechTheme=Gt;exports.formatFileSize=nt;exports.generateAppropriatenessSchema=As;exports.generateQuestionnaireSchema=Cs;exports.generateRiskScoringSchema=Is;exports.generateUploadDocumentSchema=Rs;exports.getAcceptString=Vr;exports.getApplicantId=pr;exports.getThemePreset=Je;exports.getWorkflowState=Qr;exports.healthcareTheme=Jt;exports.isScriptLoaded=Hr;exports.loadScript=pt;exports.minimalTheme=Xt;exports.modernTheme=Zt;exports.removeScript=Wr;exports.saveApplicantId=ur;exports.saveWorkflowState=yr;exports.themePresets=er;exports.useApplicant=yt;exports.useAppropriatenessTest=Jr;exports.useIdentityVerification=vr;exports.useKycWorkflow=hr;exports.useMetaKYC=we;exports.useOverview=br;exports.useQuestionnaire=fr;exports.useRiskScoring=kr;exports.useUploadDocument=gr;exports.validateFileSize=qr;exports.validateFileType=Yr;
82
+ */const ps=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],Pr=Fr("chevron-right",ps);function ms(t,r){const s=!r||r.length===0||r.every(a=>!a||!a.trim());if(t.isRequired&&s)return t.errorMessage||"This field is required";if(!s){const a=r[0]??"";if(a&&t.regex)try{if(!new RegExp(t.regex).test(a))return t.errorMessage||"Invalid format"}catch{}if(a!==""){const n=Number(a);if(!isNaN(n)&&a.trim()!==""){if(t.min!==void 0&&t.min!==null&&n<t.min)return`Minimum value is ${t.min}`;if(t.max!==void 0&&t.max!==null&&n>t.max)return`Maximum value is ${t.max}`}else{if(t.min!==void 0&&t.min!==null&&a.length<t.min)return`Minimum length is ${t.min} characters`;if(t.max!==void 0&&t.max!==null&&a.length>t.max)return`Maximum length is ${t.max} characters`}}}return null}function ys(t){const r=t.flatMap((a,n)=>(a.questions??[]).map((o,c)=>({question:o,groupIndex:n,qIdx:c}))),s=new Map;for(const a of r){const n=a.question.pageNumber!=null&&a.question.pageNumber>0?a.question.pageNumber:1;s.has(n)||s.set(n,[]),s.get(n).push(a)}return Array.from(s.entries()).sort(([a],[n])=>a-n).map(([,a])=>a)}const Lr=({applicantId:t,onComplete:r,onBack:s})=>{const{questionnaire:a,initialAnswers:n,isLoading:o,isSubmitting:c,error:u,submit:m}=jr(t),[p,I]=i.useState({}),[P,g]=i.useState({}),[A,N]=i.useState(0);i.useEffect(()=>{n&&Object.keys(n).length>0&&Object.keys(p).length===0&&I(n)},[n]);const k=i.useMemo(()=>a?ys(a.questionGroups):[],[a]),b=A===k.length-1,_=k[A]??[],U=i.useCallback((C,h)=>{I(M=>({...M,[C]:h})),g(M=>{const Q={...M};return delete Q[C],Q})},[]),L=i.useCallback(()=>{const C={};for(const{question:h}of _){const M=ms(h,p[h.id]??[]);M&&(C[h.id]=M)}return g(h=>({...h,...C})),Object.keys(C).length===0},[_,p]),B=()=>{L()&&N(C=>C+1)},K=()=>{A>0?N(C=>C-1):s==null||s()},X=async()=>{if(!(!L()||!a))try{const C=a.questionGroups.flatMap(M=>(M.questions??[]).map(Q=>({questionId:Q.id,values:p[Q.id]??[]}))),h={applicantId:t,questionnarieId:a.id,questionResults:C};await m(h),r==null||r()}catch(C){console.error("Questionnaire submit error:",C)}};return o?e.jsx(ee,{children:e.jsx(te,{children:e.jsx(Ae,{className:"my-8"})})}):u?e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading questionnaire: ",u.message]})})}):a?e.jsxs(ee,{children:[e.jsxs(ve,{children:[e.jsx("h2",{className:"text-lg font-bold",children:a.displayName}),a.subtitle&&e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:a.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 ",A+1," of ",k.length]}),e.jsx("div",{className:"flex items-center gap-1.5",children:k.map((C,h)=>e.jsx("div",{className:"rounded-full transition-all duration-200",style:{height:"6px",width:h===A?"20px":"6px",backgroundColor:h<=A?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},h))})]})]}),e.jsx(te,{className:"space-y-6",children:_.map(({question:C})=>e.jsx(xs,{question:C,value:p[C.id]??[],error:P[C.id],onChange:h=>U(C.id,h)},C.id))}),e.jsxs(ke,{className:"flex items-center justify-between",children:[e.jsxs(Z,{type:"button",variant:"outline",onClick:K,style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(Tr,{size:14}),A>0?"Previous":"Back"]}),b?e.jsx(Z,{type:"button",isLoading:c,onClick:X,children:"Continue"}):e.jsxs(Z,{type:"button",onClick:B,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},xs=({question:t,value:r,error:s,onChange:a})=>{var c;const o=(((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}),o==="text"&&e.jsx(fe,{value:r[0]??"",onChange:u=>a([u.target.value]),placeholder:t.subtitle?void 0:"Enter your answer…",error:s,required:t.isRequired}),o==="single-select"&&e.jsx(pt,{value:r[0]??"",onChange:u=>a([u.target.value]),options:(t.defaultAnswers??[]).map(u=>({value:u,label:u})),placeholder:"Select an option…",error:s,required:t.isRequired}),o==="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:()=>a([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})]}),(o==="checkbox"||o==="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:m=>{m.target.checked?a([...r,u]):a(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&&o==="text"&&null]})};function hs(t){const r=new Map;for(const s of t){const a=s.pageNumber!=null&&s.pageNumber>0?s.pageNumber:1;r.has(a)||r.set(a,[]),r.get(a).push(s)}return Array.from(r.entries()).sort(([s],[a])=>s-a).map(([,s])=>s)}const Dr=({applicantId:t,onComplete:r,onBack:s})=>{const{uploadDocument:a,isLoading:n,isSubmitting:o,error:c,submit:u}=wr(t),[m,p]=i.useState({}),[I,P]=i.useState(null),[g,A]=i.useState(0),[N,k]=i.useState({}),b=i.useMemo(()=>a?hs(a.uploadDocumentFiles):[],[a]),_=b[g]??[],U=g===b.length-1,L=b.length,B=i.useCallback(()=>{const h={};for(const M of _)M.isRequired&&(m[M.id]||[]).length===0&&(h[M.id]=`${M.displayName} is required`);return k(h),Object.keys(h).length===0},[_,m]),K=()=>{B()&&(A(h=>h+1),k({}))},X=()=>{g>0?(A(h=>h-1),k({})):s==null||s()},C=async()=>{if(!(!B()||!a)){P(null);try{const h=await Promise.all(a.uploadDocumentFiles.map(async Q=>{const O=m[Q.id]||[],G=await Promise.all(O.map(async W=>({fileName:W.name,fileData:await xr(W)})));return{uploadDocumentFileId:Q.id,valueList:G}})),M={applicantId:t,uploadDocumentId:a.id,uploadDocumentResults:h};await u(M),r==null||r()}catch(h){P((h==null?void 0:h.message)||"Failed to submit documents. Please try again.")}}};return n?e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"48px 0",gap:"16px"},children:[e.jsx(Ae,{className:"my-8"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)"},children:"Loading document requirements..."})]})})}):c?e.jsx(ee,{children:e.jsx(te,{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})]})})}):a?e.jsxs(ee,{children:[e.jsxs(ve,{children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:a.displayName||"Upload Documents"}),a.subtitle&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",marginTop:"4px"},children:a.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 ",g+1," of ",L]}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:b.map((h,M)=>e.jsx("div",{style:{height:"6px",width:M===g?"20px":"6px",borderRadius:"999px",transition:"all 0.2s ease",backgroundColor:M<=g?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},M))})]})]}),a.description&&g===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:a.description})]}),e.jsx(te,{children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"24px"},children:_.map(h=>e.jsx(Ir,{label:h.displayName,subtitle:h.subtitle,accept:h.allowedTypes,multiple:h.multipleFile,maxSize:h.maxEachFileSizeByte,required:h.isRequired,error:N[h.id],value:m[h.id]||[],onChange:M=>{P(null),k(Q=>{const O={...Q};return delete O[h.id],O}),p(Q=>({...Q,[h.id]:M}))}},h.id))})}),I&&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:I})]}),e.jsx(ke,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[e.jsx(Z,{type:"button",variant:"outline",onClick:X,children:g>0?"Previous":"Back"}),U?e.jsx(Z,{type:"button",isLoading:o,onClick:C,children:o?"Uploading...":"Continue"}):e.jsx(Z,{type:"button",onClick:K,children:"Next"})]})})]}):null},Mr=({applicantId:t,onComplete:r,onBack:s})=>{const{overview:a,isLoading:n,isSubmitting:o,error:c,passOverview:u}=Sr(t),m=async()=>{await u(),r==null||r()};return n?e.jsx(ee,{children:e.jsx(te,{children:e.jsx(Ae,{className:"my-8"})})}):c?e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading overview: ",c.message]})})}):a?e.jsxs(ee,{children:[e.jsxs(ve,{children:[e.jsx("h2",{className:"text-lg font-bold",children:a.title||"Overview"}),a.description&&e.jsx("p",{className:"mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:a.description})]}),e.jsx(te,{className:"space-y-8",children:a.steps&&a.steps.length>0?a.steps.sort((p,I)=>p.order-I.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(ke,{className:"flex justify-between",children:[s&&e.jsx(Z,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(Z,{onClick:m,isLoading:o,children:"Continue"})]})]}):null};function fs(t){const r=(t??"en").toLowerCase().replace("_","-");try{return Intl.NumberFormat.supportedLocalesOf([r]),r}catch{return"en"}}function gs(t){return t.valueDataType===Oe.Money&&Array.isArray(t.defaultValues)&&t.defaultValues.length>0}function bs(t,r){const s=new Intl.NumberFormat(fs(r),{minimumFractionDigits:0,maximumFractionDigits:2});return t.replace(/([\d]+(?:\.\d+)?)/g,a=>{const n=parseFloat(a);return isNaN(n)?a:s.format(n)})}function vs(t,r){const s=!r||r.length===0||r.every(a=>!a||!a.trim());if(t.isRequired&&s)return t.errorMessage||`${t.displayName} is required`;if(!s){const a=r[0]??"";if(a&&t.regex)try{if(!new RegExp(t.regex).test(a))return t.errorMessage||"Invalid format"}catch{}const n=t.valueDataType===Oe.Integer||t.valueDataType===Oe.Money||t.valueDataType===Oe.DigitOnly;if(n&&a.trim()!==""){const o=Number(a);if(!isNaN(o)){if(t.min!==void 0&&t.min!==null&&o<t.min)return`Minimum value is ${t.min}`;if(t.max!==void 0&&t.max!==null&&o>t.max)return`Maximum value is ${t.max}`}}else if(!n&&a!==""){if(t.min!==void 0&&t.min!==null&&a.length<t.min)return`Minimum length is ${t.min} characters`;if(t.max!==void 0&&t.max!==null&&a.length>t.max)return`Maximum length is ${t.max} characters`}}return null}function ks(t){const r=new Map;return t.forEach((s,a)=>{const n=s.pageNumber!=null&&s.pageNumber>0?s.pageNumber:1;r.has(n)||r.set(n,[]),r.get(n).push({criterion:s,idx:a})}),Array.from(r.entries()).sort(([s],[a])=>s-a).map(([,s])=>s)}function js(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:a}=Re(),n=a.locale??"en",{criteria:o,initialAnswers:c,isLoading:u,isSubmitting:m,error:p,submit:I}=Nr(t),[P,g]=i.useState({}),[A,N]=i.useState({}),[k,b]=i.useState(0),[_,U]=i.useState(!1);i.useEffect(()=>{c&&Object.keys(c).length>0&&Object.keys(P).length===0&&g(c)},[c]);const L=i.useMemo(()=>o&&o.length>0?ks(o):[],[o]),B=k===L.length-1,K=L[k]??[];i.useEffect(()=>{!u&&o&&o.length===0&&!_&&!m&&(U(!0),I({applicantId:t,criteriaValueInputs:[]}).then(()=>r==null?void 0:r()).catch(console.error))},[u,o,_,m,I,t,r]);const X=i.useCallback((O,G)=>{g(W=>({...W,[O]:G})),N(W=>{const ue={...W};return delete ue[O],ue})},[]),C=i.useCallback(()=>{const O={};for(const{criterion:G}of K){const W=vs(G,P[G.id]??[]);W&&(O[G.id]=W)}return N(G=>({...G,...O})),Object.keys(O).length===0},[K,P]),h=()=>{C()&&b(O=>O+1)},M=()=>{k>0?b(O=>O-1):s==null||s()},Q=async()=>{if(!(!C()||!o))try{const O=o.map(W=>{const ue=(P[W.id]??[]).filter(J=>J&&J.trim());return ue.length>0?{riskCriteriaId:W.id,values:ue}:null}).filter(W=>W!==null);await I({applicantId:t,criteriaValueInputs:O}),r==null||r()}catch(O){console.error("Risk scoring submit error:",O)}};return u?e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ae,{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&&o&&o.length===0?e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ae,{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(ee,{children:e.jsx(te,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading criteria: ",p.message]})})}):o?e.jsxs(ee,{children:[e.jsxs(ve,{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((O,G)=>e.jsx("div",{className:"rounded-full transition-all duration-200",style:{height:"6px",width:G===k?"20px":"6px",backgroundColor:G<=k?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},G))})]})]}),e.jsx(te,{className:"space-y-6",children:K.map(({criterion:O})=>e.jsx(ws,{criterion:O,value:P[O.id]??[],error:A[O.id],locale:n,onChange:G=>X(O.id,G)},O.id))}),e.jsxs(ke,{className:"flex items-center justify-between",children:[e.jsxs(Z,{type:"button",variant:"outline",onClick:M,style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(Tr,{size:14}),k>0?"Previous":"Back"]}),B?e.jsx(Z,{type:"button",isLoading:m,onClick:Q,children:"Continue"}):e.jsxs(Z,{type:"button",onClick:h,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},ws=({criterion:t,value:r,error:s,locale:a,onChange:n})=>{const o=js(t),c=t.valueDataType===Oe.Integer||t.valueDataType===Oe.Money||t.valueDataType===Oe.DigitOnly,u=gs(t),m=p=>u?bs(p,a):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}`}),o==="text"&&e.jsx(fe,{value:r[0]??"",onChange:p=>n([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===Oe.DigitOnly&&["e","E","+","-","."].includes(p.key)&&p.preventDefault()}}),o==="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:()=>n([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:m(p)})]},p)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),o==="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:I=>{I.target.checked?n([...r,p]):n(r.filter(P=>P!==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:m(p)})]},p)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),o==="country"&&e.jsx(pt,{value:r[0]??"",onChange:p=>n([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:a}=Re(),[n,o]=i.useState(null),[c,u]=i.useState(!1),[m,p]=i.useState(null),I=async P=>{if(P.preventDefault(),n===null){p("Please select an investor type");return}u(!0),p(null);try{const g={applicantId:t,investorType:n};console.log("Submitting investor categorization:",g);const A=await a.setInvestorCategorization(g);console.log("Investor categorization result:",A),r==null||r()}catch(g){console.error("Error submitting investor categorization:",g),p(g.message||"Failed to submit investor categorization")}finally{u(!1)}};return e.jsx("form",{onSubmit:I,children:e.jsxs(ee,{children:[e.jsxs(ve,{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(te,{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:n===we.Individual?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:n===we.Individual?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:we.Individual,checked:n===we.Individual,onChange:()=>o(we.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:n===we.Sophisticated?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:n===we.Sophisticated?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:we.Sophisticated,checked:n===we.Sophisticated,onChange:()=>o(we.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:n===we.HighNetWorth?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:n===we.HighNetWorth?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:we.HighNetWorth,checked:n===we.HighNetWorth,onChange:()=>o(we.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(ke,{className:"flex justify-between",children:[s&&e.jsx(Z,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(Z,{type:"submit",isLoading:c,disabled:n===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:a}=Re(),[n,o]=i.useState(null),[c,u]=i.useState(!0),[m,p]=i.useState(!1),[I,P]=i.useState(null),[g,A]=i.useState({}),[N,k]=i.useState(0),[b,_]=i.useState(!1),[U,L]=i.useState(!1),[B,K]=i.useState(0),[X,C]=i.useState(0),[h,M]=i.useState(null);i.useEffect(()=>{(async()=>{try{u(!0),P(null);const T=await a.getAppropriatenessTest(t);if(o(T),T.waitTimeSpanForNextTry&&T.waitTimeSpanForNextTry!=="00:00:00"){const q=Nt(T.waitTimeSpanForNextTry);q>0&&K(q)}}catch(T){P(T.message||"Failed to load appropriateness test")}finally{u(!1)}})()},[t,a]),i.useEffect(()=>{if(!b||N<=0)return;const T=setInterval(()=>{k(q=>q<=1?(L(!0),0):q-1)},1e3);return()=>clearInterval(T)},[b,N]),i.useEffect(()=>{if(B<=0)return;const T=setInterval(()=>{K(q=>q<=1?0:q-1)},1e3);return()=>clearInterval(T)},[B]),i.useEffect(()=>{U&&!m&&W()},[U]);const Q=()=>{n&&(_(!0),k(n.testDurationSec),C(0),A({}),P(null))},O=(T,q)=>{A(xe=>({...xe,[T]:q}))},G=i.useCallback(async()=>{try{const T=await a.getAppropriatenessTest(t);if(o(T),T.waitTimeSpanForNextTry&&T.waitTimeSpanForNextTry!=="00:00:00"){const q=Nt(T.waitTimeSpanForNextTry);q>0&&K(q)}}catch{}},[t,a]),W=async T=>{if(n){if(!U){const q=n.appropriatenessQuestions.length-Object.keys(g).length;if(q>0){P(`Please answer all questions. ${q} remaining.`);return}}p(!0),P(null);try{const q=n.appropriatenessQuestions.map(R=>({appropriatenessQuestionId:R.id,value:g[R.id]||""})),xe={applicantId:t,appropriatenessTestId:n.id,appropriatenessQuestionResults:q};try{const R=await a.fillAppropriatenessTest(xe);R.isSuccess?M({success:!0,message:R.message||"Congratulations! You have passed the test."}):(M({success:!1,message:R.message||"You did not pass the test."}),setTimeout(()=>G(),1e3))}catch(R){if(R.code===400&&R.message)M({success:!1,message:R.message}),setTimeout(()=>G(),1500);else throw R}}catch(q){P(q.message||"Failed to submit test. Please try again."),ue()}finally{p(!1)}}},ue=()=>{_(!1),L(!1),A({}),C(0)};if(c)return e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"48px 0",gap:"16px"},children:[e.jsx(Ae,{className:"my-8"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)"},children:"Loading test..."})]})})});if(!n)return e.jsx(ee,{children:e.jsx(te,{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"}),I&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"8px"},children:I})]})})});const J=n.testAllowedMaxTry-n.totalFailedTries,he=n.appropriatenessQuestions.length,pe=Object.keys(g).length;if(B>0)return e.jsxs(ee,{children:[e.jsx(ve,{children:e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:n.displayName})}),e.jsx(te,{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(B)})}),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"}),I&&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:I})})]})})]});if(h){const T=()=>{M(null),ue(),P(null)};return e.jsxs(ee,{children:[e.jsx(te,{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:h.success?"color-mix(in srgb, var(--metakyc-success, #10b981) 12%, transparent)":"color-mix(in srgb, var(--metakyc-danger, #ef4444) 10%, transparent)"},children:h.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:h.success?"var(--metakyc-success, #10b981)":"var(--metakyc-danger, #ef4444)",margin:0},children:h.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:h.message}),!h.success&&J>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:J})," attempt",J!==1?"s":""," remaining"]})}),!h.success&&J<=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(ke,{children:e.jsx("div",{style:{display:"flex",justifyContent:"center",width:"100%",gap:"12px"},children:h.success?e.jsx(Z,{type:"button",onClick:()=>r==null?void 0:r(),children:"Continue"}):e.jsxs(e.Fragment,{children:[J>0&&B<=0&&e.jsx(Z,{type:"button",onClick:T,children:"Retake Test"}),J>0&&B>0&&e.jsx(Z,{type:"button",onClick:T,children:"OK"}),J<=0&&s&&e.jsx(Z,{type:"button",variant:"outline",onClick:s,children:"Back"})]})})})]})}if(!b)return e.jsxs(ee,{children:[e.jsxs(ve,{children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:n.displayName}),n.subtitle&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",marginTop:"4px"},children:n.subtitle})]}),e.jsxs(te,{children:[n.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:n.description})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px",marginBottom:"20px"},children:[e.jsx(lt,{icon:"questions",label:"Questions",value:String(n.totalQuestionCount)}),e.jsx(lt,{icon:"time",label:"Time Limit",value:mt(n.testDurationSec)}),e.jsx(lt,{icon:"target",label:"Pass Requirement",value:`${n.testCorrectAnswerPassLimit} correct`}),e.jsx(lt,{icon:"retry",label:"Attempts Left",value:String(J),variant:J<=1?"warning":"default"})]}),I&&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:"})," ",I]})]}),J<=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(ke,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:s?"space-between":"flex-end",width:"100%"},children:[s&&e.jsx(Z,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(Z,{type:"button",onClick:Q,disabled:J<=0,children:"Start Test"})]})})]});const oe=n.appropriatenessQuestions[X],je=X===he-1,E=pe===he,$=N<=60;return e.jsxs(ee,{children:[e.jsxs(ve,{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:n.displayName}),e.jsxs("p",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"2px"},children:["Question ",X+1," of ",he]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 14px",borderRadius:"999px",backgroundColor:$?"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:$?"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:$?"var(--metakyc-danger, #ef4444)":"var(--metakyc-text-primary, #111827)",transition:"color 0.3s ease"},children:mt(N)})]})]}),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:`${pe/he*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:[pe," answered"]}),e.jsxs("span",{style:{fontSize:"11px",color:"var(--metakyc-text-muted, #9ca3af)"},children:[J," attempt",J!==1?"s":""," left"]})]})]})]}),e.jsxs(te,{children:[oe&&e.jsx(Cs,{question:oe,index:X,selectedAnswer:g[oe.id],onSelect:T=>O(oe.id,T),disabled:m}),he>1&&e.jsx("div",{style:{display:"flex",justifyContent:"center",gap:"6px",marginTop:"20px",flexWrap:"wrap"},children:n.appropriatenessQuestions.map((T,q)=>e.jsx("button",{type:"button",onClick:()=>C(q),style:{width:"28px",height:"28px",borderRadius:"8px",border:q===X?"2px solid var(--metakyc-primary, #2563eb)":"1px solid var(--metakyc-border, #e5e7eb)",backgroundColor:g[T.id]?q===X?"color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)":"color-mix(in srgb, var(--metakyc-primary, #2563eb) 8%, transparent)":q===X?"var(--metakyc-surface, #f9fafb)":"var(--metakyc-background, #ffffff)",color:g[T.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:q+1},T.id))}),U&&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."})]}),I&&!U&&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:I})})]}),e.jsx(ke,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[e.jsx(Z,{type:"button",variant:"outline",onClick:()=>{X>0?C(T=>T-1):s==null||s()},disabled:m,children:X>0?"Previous":"Cancel"}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[!je&&e.jsx(Z,{type:"button",onClick:()=>C(T=>T+1),children:"Next"}),(je||E)&&e.jsx(Z,{type:"button",isLoading:m,onClick:()=>W(),disabled:!E&&!U,style:{opacity:E||U?1:.5},children:U?"Submitting...":"Submit Test"})]})]})})]})},Ss={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:a="default"})=>{const n=a==="warning";return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px",padding:"14px",borderRadius:"10px",backgroundColor:n?"color-mix(in srgb, #f59e0b 8%, transparent)":"var(--metakyc-surface, #f9fafb)",border:n?"1px solid color-mix(in srgb, #f59e0b 20%, transparent)":"1px solid var(--metakyc-border, #e5e7eb)"},children:[e.jsx("div",{style:{color:n?"#f59e0b":"var(--metakyc-primary, #2563eb)",flexShrink:0},children:Ss[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:n?"#b45309":"var(--metakyc-text-primary, #111827)",margin:0,marginTop:"1px"},children:s})]})]})},Cs=({question:t,selectedAnswer:r,onSelect:s,disabled:a})=>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((n,o)=>{const c=r===n;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:a?"default":"pointer",transition:"all 0.15s ease",opacity:a?.6:1},onMouseEnter:u=>{!a&&!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:n,checked:c,onChange:()=>s(n),disabled:a,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:n})]},o)})})]}),_r=({applicantId:t,onComplete:r,onBack:s})=>{var Le,Qe,Ge,_e;const{applicantService:a,baseInformationService:n,config:o,currentTheme:c}=Re(),{identityData:u,provider:m,token:p,isLoading:I,error:P,requestIdentity:g,restartIdentity:A}=Cr(t),[N,k]=i.useState(null),[b,_]=i.useState(null),[U,L]=i.useState([]),[B,K]=i.useState([]),[X,C]=i.useState(!0),[h,M]=i.useState(!1),[Q,O]=i.useState(null),[G,W]=i.useState(!1),ue=i.useRef(!1),[J,he]=i.useState({}),[pe,oe]=i.useState({}),je=c!=null&&c.reviewPageFields&&c.reviewPageFields.length>0?c.reviewPageFields[0]:null,E=!!(c!=null&&c.reviewPageDisabled),$=i.useRef(!1);$.current=E;const T=Ke.useForm({defaultValues:{street:"",streetNumber:"",city:"",zip:"",country:"",nationality:"",phonenumber:""}});i.useEffect(()=>{if(E){ue.current||(ue.current=!0,g().then(()=>M(!0)).catch(z=>console.error("[Identity] Auto-request failed:",z)).finally(()=>C(!1)));return}(async()=>{try{const[z,V,H]=await Promise.all([a.getApplicantData(t),n.getCountries("","en"),n.getCountries("","en",40)]);_(z);const se=new Set,re=V.map(v=>({value:v.abbreviation3||v.abbreviation,label:v.name})).filter(v=>!v.value||se.has(v.value)?!1:(se.add(v.value),!0));L(re);const de=new Set,y=H.filter(v=>v.countryCode).map(v=>({value:v.countryCode,label:`${v.countryCode} – ${v.name}`})).filter(v=>de.has(v.value)?!1:(de.add(v.value),!0));K(y);const d=z.applicantRequestData;if(he({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)||""}),T.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)||""}),z.kycRecords&&z.kycRecords.length>0&&z.kycRecords[0].providerTokenObject!==null&&!ue.current&&$.current){console.log("[Identity] Review page disabled + existing identity — auto-requesting..."),ue.current=!0;try{await g(),M(!0)}catch(v){console.error("[Identity] Auto-request failed:",v)}}}catch(z){console.error("Error loading applicant data:",z)}finally{C(!1)}})()},[t]),i.useEffect(()=>{u&&!h&&$.current&&(console.log("[Identity] Review page disabled — showing cached provider"),M(!0))},[u,h]),i.useEffect(()=>{if(p){if(p.expiresAt){const x=new Date(p.expiresAt).getTime();if(Date.now()>=x){console.warn("[Identity] Token has expired (expiresAt)"),W(!0),O("Your verification session has expired. Please restart.");return}}if(p.url)try{const z=new URL(p.url).toString().toLowerCase();if(z.includes("expired")||z.includes("invalid")||z.includes("error")){console.warn("[Identity] Token URL indicates expiration"),W(!0),O("Your verification link has expired. Please restart.");return}}catch{console.error("[Identity] Invalid token URL")}if(p.status==="expired"||p.error==="expired"||p.expired===!0){console.warn("[Identity] Token object indicates expiration"),W(!0),O("Your verification session has expired. Please restart.");return}}},[p]),i.useEffect(()=>{if(m!==null&&p&&!N&&h&&!G){const x=m;if(p.url){console.log("[Identity] Loading provider URL for user verification:",p.url),O(null);try{if(new URL(p.url),x===Fe.SardinAI){console.log("[SardinAI] Initializing Risk SDK in background...");try{const z=Xe.parseProviderConfig(m,p,o);Xe.createProvider(m,z).initialize().then(()=>{console.log("[SardinAI] Risk SDK initialized successfully in background")}).catch(H=>{console.warn("[SardinAI] Risk SDK initialization failed (non-blocking):",H)})}catch(z){console.warn("[SardinAI] Risk SDK setup failed (non-blocking):",z)}}k({type:"url",url:p.url})}catch(z){console.error("[Identity] Invalid URL:",z),O("Invalid verification URL. Please restart."),W(!0)}return}if(x===Fe.SardinAI){console.log("[SardinAI] No URL provided - initializing Risk SDK only..."),O(null);try{const z=Xe.parseProviderConfig(m,p,o),V=Xe.createProvider(m,z);V.initialize().then(()=>{console.log("[SardinAI] Risk SDK initialized successfully"),k(V),setTimeout(()=>{r==null||r()},2e3)}).catch(H=>{var re;console.error("[SardinAI] Failed to initialize:",H);const se=((re=H.message)==null?void 0:re.toLowerCase())||"";se.includes("expired")||se.includes("invalid")||se.includes("401")||se.includes("400")?(W(!0),O("Session expired or invalid. Please restart verification.")):O(`Failed to initialize: ${H.message}`)})}catch(z){console.error("[SardinAI] Error creating provider:",z),O(`Configuration error: ${z.message}`)}return}try{O(null);const z=Xe.parseProviderConfig(m,p,o),V=Xe.createProvider(m,z);x===Fe.Sumsub?(V.initialize("identity-container").catch(H=>{var se;console.error("[Sumsub] Initialization error:",H),O(`Failed to initialize: ${H.message}`),(se=H.message)!=null&&se.toLowerCase().includes("expired")&&W(!0)}),V.onComplete&&V.onComplete(()=>{r==null||r()})):x===Fe.Onfido&&V.initialize("identity-container").catch(H=>{console.error("[Onfido] Initialization error:",H),O(`Failed to initialize: ${H.message}`)}),k(V)}catch(z){console.error("[Identity] Provider setup error:",z),O(`Setup error: ${z.message}`)}}return()=>{if(N&&N.destroy)try{N.destroy()}catch(x){console.error("[Identity] Error destroying provider:",x)}}},[m,p,N,h,r,G]);const q=async()=>{try{O(null),W(!1),await g(),M(!0)}catch(x){console.error("Error starting identity verification:",x)}},xe=async()=>{try{O(null),W(!1),k(null),console.log("[Identity] Restarting verification..."),await A(),M(!0)}catch(x){console.error("Error restarting identity verification:",x),O(x.message||"Failed to restart verification")}};if(X||I)return e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ae,{className:"my-8"}),e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-4",children:"Loading identity verification..."})]})});if(P)return e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("p",{className:"text-danger-500",children:["Error: ",P.message]})})});if(h&&(Q||G))return e.jsxs(ee,{children:[e.jsx(ve,{children:e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"Verification Session Issue"})}),e.jsxs(te,{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:G?"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(ke,{className:"flex justify-between",children:[s&&e.jsx(Z,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(Z,{type:"button",onClick:xe,disabled:I,children:I?"Restarting...":"Restart Verification"})]})]});if(h&&u){const x=m;return p!=null&&p.url?e.jsxs(ee,{children:[e.jsx(ve,{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(Z,{type:"button",variant:"outline",size:"sm",onClick:xe,disabled:I,children:"Restart"})]})}),e.jsxs(te,{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:p.url,className:"w-full h-full border-0 rounded-lg",allow:"camera; microphone; geolocation",title:"Identity Verification",onLoad:z=>{var V,H,se;console.log("[Identity] Iframe loaded");try{const re=z.target,de=re.contentDocument||((V=re.contentWindow)==null?void 0:V.document);if(de){const y=((se=(H=de.body)==null?void 0:H.textContent)==null?void 0:se.toLowerCase())||"";(y.includes("expired")||y.includes("invalid")||y.includes("error"))&&(console.warn("[Identity] Iframe shows expiration message"),W(!0),O("Your verification link has expired."))}}catch{console.log("[Identity] Cannot check iframe content (CORS)")}}})})]}),s&&e.jsx(ke,{children:e.jsx(Z,{variant:"outline",onClick:s,children:"Back"})})]}):x===Fe.SardinAI?e.jsxs(ee,{children:[e.jsxs(ve,{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(te,{children:e.jsxs("div",{className:"text-center py-12",children:[e.jsx(Ae,{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(ee,{children:[e.jsxs(ve,{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(te,{children:e.jsx("div",{id:"identity-container",className:"min-h-[400px]"})}),s&&e.jsx(ke,{children:e.jsx(Z,{variant:"outline",onClick:s,children:"Back"})})]})}const R=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),Y=(x=4)=>({1:"col-span-1",2:"col-span-2",3:"col-span-3",4:"col-span-4"})[x]||"col-span-4",ce=(x,z)=>{if(!z&&z!==0)return"—";if(R.has(x)&&x!=="mobileCountryCode"){const V=U.find(H=>H.value===z);return V?V.label:String(z)}return String(z)},ge=({helpText:x})=>{const[z,V]=i.useState(!1),H=i.useRef(null),[,se]=i.useState({top:0,left:0}),re=()=>{if(H.current){const de=H.current.getBoundingClientRect();se({top:de.bottom+window.scrollY+6,left:de.left+window.scrollX})}V(!0)};return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"metakyc-help-btn",ref:H,onClick:re,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:"?"}),z&&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:()=>V(!1),children:e.jsxs("div",{onClick:de=>de.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:()=>V(!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)]})},me=(x,z)=>z?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(ge,{helpText:z})})]}):x,Pe=(x,z)=>{const V=`cf-${z}`,H=x.paramName??"",se=pe[H];if(x.customType==="br")return e.jsx("div",{className:Y(x.colSpan),style:{minHeight:"0.5rem"}},V);if(x.customType==="paragraph")return e.jsx("div",{className:Y(x.colSpan),children:e.jsx("div",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:x.label||""}})},V);if(x.customType==="html")return e.jsx("div",{className:Y(x.colSpan),dangerouslySetInnerHTML:{__html:x.label||""}},V);if(x.customType==="link")return e.jsx("div",{className:Y(x.colSpan),children:me(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)},V);if(x.customType==="checkbox"||x.customType==="link_checkbox"){const re=se==="true"||se===!0;return e.jsx("div",{className:Y(x.colSpan),children:me(e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:!!re,onChange:de=>oe(y=>({...y,[H]:String(de.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)},V)}if(x.customType==="group_checkbox"){const re=Array.isArray(se)?se:se?[se]:[],de=y=>{x.singleSelect?oe(d=>({...d,[H]:re[0]===y?[]:[y]})):oe(d=>({...d,[H]:re.includes(y)?re.filter(D=>D!==y):[...re,y]}))};return e.jsx("div",{className:Y(x.colSpan),children:me(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(y=>e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:re.includes(y.value),onChange:()=>de(y.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:y.label})]},y.value))]}),x.helpText)},V)}return x.customType==="radio_group"?e.jsx("div",{className:Y(x.colSpan),children:me(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(re=>e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"radio",name:`rg-${H}`,value:re.value,checked:se===re.value,onChange:()=>oe(de=>({...de,[H]:re.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:re.label})]},re.value))]}),x.helpText)},V):e.jsx("div",{className:Y(x.colSpan),children:me(e.jsx(fe,{label:x.displayText||x.label||H,value:String(se??""),onChange:re=>oe(de=>({...de,[H]:re.target.value}))}),x.helpText)},V)},Be=(x,z)=>{if(x.isCustom)return Pe(x,z);const V=x.name??"",H=Ve[V],se=x.displayText||(H==null?void 0:H.label)||V,re=J[V]??"",de=V==="mobileCountryCode",y=!!(H!=null&&H.countriesType)&&!de;return x.editable?de?e.jsx("div",{className:Y(x.colSpan??2),children:me(e.jsx(ze,{label:se,value:String(re),onChange:d=>he(D=>({...D,[V]:d})),options:[{value:"",label:"Select country code…"},...B]}),x.helpText)},`epc-${z}`):y?e.jsx("div",{className:Y(x.colSpan??2),children:me(e.jsx(ze,{label:se,value:String(re),onChange:d=>he(D=>({...D,[V]:d})),options:[{value:"",label:`Select ${se.toLowerCase()}…`},...U]}),x.helpText)},`ec-${z}`):e.jsx("div",{className:Y(x.colSpan??2),children:me(e.jsx(fe,{label:se,type:(H==null?void 0:H.type)==="date"?"date":(H==null?void 0:H.type)==="email"?"email":"text",value:String(re),onChange:d=>he(D=>({...D,[V]:d.target.value}))}),x.helpText)},`ei-${z}`):e.jsx("div",{className:Y(x.colSpan??2),children:me(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:se}),e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)",minHeight:"1.5rem"},children:ce(V,re)})]}),x.helpText)},`ro-${z}`)};if(je){const x=je.title||"Review Your Information",z=je.subtitle||"Please review and confirm your information before starting identity verification";return e.jsx("form",{onSubmit:V=>{V.preventDefault(),q()},children:e.jsxs(ee,{children:[e.jsxs(ve,{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:z})]}),e.jsx(te,{children:e.jsx("div",{className:"grid grid-cols-4 gap-4",children:je.fields.map((V,H)=>Be(V,H))})}),e.jsxs(ke,{className:"flex justify-between",children:[s&&e.jsx(Z,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(Z,{type:"submit",isLoading:I,children:"Confirm and Start Verification"})]})]})})}return e.jsx("form",{onSubmit:T.handleSubmit(q),children:e.jsxs(ee,{children:[e.jsxs(ve,{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(te,{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:`${((Le=b==null?void 0:b.applicantRequestData)==null?void 0:Le.firstName)||""} ${((Qe=b==null?void 0:b.applicantRequestData)==null?void 0:Qe.lastName)||""}`.trim()},{label:"Email",value:(Ge=b==null?void 0:b.applicantRequestData)==null?void 0:Ge.email},{label:"Date of Birth",value:((_e=b==null?void 0:b.applicantRequestData)==null?void 0:_e.dateOfBirth)||"Not provided"}].map(({label:x,value:z})=>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:z})]},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:T.control,name:"country",render:({field:x})=>e.jsx(ze,{label:"Country",value:x.value,onChange:x.onChange,options:[{value:"",label:"Select country…"},...U]})}),e.jsx(Ke.Controller,{control:T.control,name:"nationality",render:({field:x})=>e.jsx(ze,{label:"Nationality",value:x.value,onChange:x.onChange,options:[{value:"",label:"Select nationality…"},...U]})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Ke.Controller,{control:T.control,name:"street",render:({field:x})=>e.jsx(fe,{...x,label:"Street"})}),e.jsx(Ke.Controller,{control:T.control,name:"streetNumber",render:({field:x})=>e.jsx(fe,{...x,label:"Street Number"})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Ke.Controller,{control:T.control,name:"city",render:({field:x})=>e.jsx(fe,{...x,label:"City"})}),e.jsx(Ke.Controller,{control:T.control,name:"zip",render:({field:x})=>e.jsx(fe,{...x,label:"ZIP / Postal Code"})})]}),e.jsx(Ke.Controller,{control:T.control,name:"phonenumber",render:({field:x})=>e.jsx(fe,{...x,label:"Phone Number",type:"tel"})})]})]}),e.jsxs(ke,{className:"flex justify-between",children:[s&&e.jsx(Z,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(Z,{type:"submit",isLoading:I,children:"Confirm and Start Verification"})]})]})})},ht=({kycStatus:t,reviewStatus:r,workflowResult:s,customMessage:a,onContinue:n,onContactSupport:o})=>{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===Ye.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===Ye.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===Ye.UnderReview||r===Ye.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(ee,{children:[e.jsxs(te,{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]:Ye[r]})}),e.jsx("p",{className:"text-center mb-6 max-w-md mx-auto",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:a||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:Ye[r]})]})]})})]}),e.jsxs(ke,{className:"flex justify-center gap-4",children:[u.type==="success"&&n&&e.jsx(Z,{onClick:n,size:"lg",children:"Continue"}),u.type==="error"&&e.jsxs(e.Fragment,{children:[o&&e.jsx(Z,{variant:"outline",onClick:o,children:"Contact Support"}),n&&e.jsx(Z,{onClick:n,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:a}=Re(),n=t||(a==null?void 0:a.title)||"",o=!!(a!=null&&a.logo&&a.logo.visible&&a.logo.url),c=!!n;return!o&&!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:[o&&e.jsx($r,{config:a.logo}),o&&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:n})]}),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 nt={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,a]=i.useState(!1);if(!t)return e.jsx(e.Fragment,{children:r});const n=s?e.jsx("div",{role:"dialog","aria-modal":"true",onClick:()=>a(!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:o=>o.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:()=>a(!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:()=>a(!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:o=>{o.currentTarget.style.background="var(--metakyc-primary, #2563eb)",o.currentTarget.style.color="#ffffff"},onMouseLeave:o=>{o.currentTarget.style.background="transparent",o.currentTarget.style.color="var(--metakyc-primary, #2563eb)"},children:"?"}),typeof document<"u"&&n?ut.createPortal(n,document.body):null]})},Ns=({workflowKey:t,externalRefId:r,onSuccess:s,onCancel:a})=>{var se,re,de,y,d,D,v;const{config:n,baseInformationService:o,currentTheme:c}=Re(),{createApplicant:u,isLoading:m}=bt(),p=t||((se=n.applicantForm)==null?void 0:se.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 I=r||((re=n.applicantForm)==null?void 0:re.externalRefId)||"",P=((de=n.applicantForm)==null?void 0:de.email)||"",g=((y=n.applicantForm)==null?void 0:y.hiddenValues)||{},A=((d=n.applicantForm)==null?void 0:d.initialValues)||{},k=(((D=n.applicantForm)==null?void 0:D.fieldLabelMode)||(c==null?void 0:c.fieldLabelMode)||"label")!=="placeholder",b=i.useMemo(()=>c!=null&&c.applicantFormPages&&c.applicantFormPages.length>0?c.applicantFormPages:null,[c==null?void 0:c.applicantFormPages]),_=i.useMemo(()=>{const l=new Set(ct),j=c==null?void 0:c.applicantFormRequiredFields;if(j)for(const F of j)l.add(F);if(b)for(const F of b)for(const f of F.fields)!f.isCustom&&f.name&&f.required&&l.add(f.name);return Array.from(l)},[c==null?void 0:c.applicantFormRequiredFields,b]),U=i.useMemo(()=>{var F;if(b){const f=b.flatMap(w=>w.fields).filter(w=>!w.isCustom&&w.name).map(w=>w.name),S=new Set(f);for(const w of ct)S.add(w);return Array.from(S)}let l;(F=n.applicantForm)!=null&&F.visibleFields?l=n.applicantForm.visibleFields:c!=null&&c.applicantFormVisibleFields&&c.applicantFormVisibleFields.length>0?l=c.applicantFormVisibleFields:l=$t;const j=new Set(l);for(const f of ct)j.add(f);return Array.from(j)},[(v=n.applicantForm)==null?void 0:v.visibleFields,c==null?void 0:c.applicantFormVisibleFields,b]),L=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),B=i.useMemo(()=>{var j,F;const l=new Set;if(b)for(const f of b)for(const S of f.fields)!S.isCustom&&S.name&&L.has(S.name)&&l.add(S.countriesType??((j=Ve[S.name])==null?void 0:j.countriesType));else for(const f of U)L.has(f)&&l.add((F=Ve[f])==null?void 0:F.countriesType);return l.size===0&&l.add(void 0),Array.from(l)},[U,b]),[K,X]=i.useState({}),[C,h]=i.useState(!0),M=i.useRef(new Set),Q=i.useRef(new Set);i.useEffect(()=>{if(!c)return;const l=B.filter(f=>{const S=f!=null?String(f):"all";return!Q.current.has(S)&&!M.current.has(S)});if(l.length===0){B.every(S=>{const w=S!=null?String(S):"all";return Q.current.has(w)})&&h(!1);return}h(!0);const j=l.map(f=>f!=null?String(f):"all");j.forEach(f=>M.current.add(f)),(async()=>{try{const f=await Promise.all(l.map(async S=>{const w=S!=null?String(S):"all",le=await o.getCountries("",n.locale||"en",S),ae=S===40,be=new Set,Ee=le.map(ne=>ae&&ne.countryCode?{value:ne.countryCode,label:`${ne.countryCode} – ${ne.name}`}:{value:ne.abbreviation3||ne.abbreviation,label:ne.name}).filter(ne=>!ne.value||be.has(ne.value)?!1:(be.add(ne.value),!0));return Q.current.add(w),M.current.delete(w),[w,Ee]}));X(S=>({...S,...Object.fromEntries(f)}))}catch(f){j.forEach(S=>M.current.delete(S)),console.error("Failed to load countries:",f)}finally{B.every(S=>{const w=S!=null?String(S):"all";return Q.current.has(w)})&&h(!1)}})()},[B,c]);const O=(l,j)=>{var S;const F=j??((S=Ve[l])==null?void 0:S.countriesType),f=F!=null?String(F):"all";return K[f]||[]},G={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},W=Object.fromEntries(Object.entries(g).filter(([l])=>l in G)),ue=Object.fromEntries(Object.entries(A).filter(([l])=>l in G)),[J,he]=i.useState({workflowKey:p,firstName:"",lastName:"",title:"",email:P,dateOfBirth:"",phonenumber:"",externalRefId:I,mobileCountryCode:"",street:"",streetNumber:"",zip:"",city:"",country:"",nationality:"",otherNationality:[],defaultLanguage:"EN",taxCountry:"",placeOfBirth:"",countryOfBirth:"",salutation:null,educationLevel:"",occupation:"",taxNumber:"",...W,...ue}),pe=Object.fromEntries(Object.entries(g).filter(([l])=>!(l in W)&&l!=="externalRefId"&&l!=="workflowKey")),[oe,je]=i.useState({...pe}),[E,$]=i.useState(0),[T,q]=i.useState({}),[xe,R]=i.useState(null),[Y,ce]=i.useState(!1),ge=(l,j)=>he(F=>({...F,[l]:j})),me=(l,j)=>je(F=>({...F,[l]:j})),Pe=l=>!l.conditionalOn||oe[l.conditionalOn]==="true",Be=b&&E<b.length-1?E+1:-1,Le=b&&E>0?E-1:-1,Qe=l=>{var F;const j={};for(const f of l.fields)if(f.isCustom){if(f.customType==="paragraph"||f.customType==="html"||f.customType==="br"||f.customType==="link")continue;if(f.required&&f.paramName){const S=oe[f.paramName],w=f.displayText||f.label||f.paramName;f.customType==="checkbox"||f.customType==="link_checkbox"?S!=="true"&&(j[f.paramName]=`${w} is required.`):(!S||S.trim()==="")&&(j[f.paramName]=`${w} is required.`)}}else if(f.name){const S=f.name;if(_.includes(S)&&et(J[S])){const w=f.displayText||((F=Ve[S])==null?void 0:F.label)||S;j[S]=`${w} is required.`}}return j},Ge=async()=>{if(!b)return;const l=b[E];if(l.conditionalOn&&!Pe(l)){q({}),Be>=0?$(Be):await _e();return}const j=Qe(l);if(Object.keys(j).length>0){q(j);return}q({}),Be>=0?$(Be):await _e()},_e=async()=>{if(b){let l={};for(const j of b)Pe(j)&&(l={...l,...Qe(j)});if(Object.keys(l).length>0){q(l);return}}ce(!0),R(null);try{if(!J.externalRefId||J.externalRefId.trim()===""){R("External Reference ID is required. Please pass it via config.applicantForm.externalRefId.");return}const l={workflowKey:J.workflowKey,externalRefId:J.externalRefId.trim()};if(b){for(const S of b)if(Pe(S)){for(const w of S.fields)if(!w.isCustom&&w.name){const le=w.name,ae=J[le];et(ae)||(l[le]=ae)}}for(const S of ct)if(l[S]===void 0){const w=J[S];et(w)||(l[S]=w)}}else U.forEach(S=>{if(S==="externalRefId")return;const w=J[S];et(w)||(l[S]=w)});const j=[];if(b){for(const S of b)if(Pe(S))for(const w of S.fields){if(!w.isCustom||!w.paramName||w.customType==="paragraph"||w.customType==="html"||w.customType==="br"||w.customType==="link")continue;const le=oe[w.paramName]??"";let ae;if(w.customType==="checkbox"||w.customType==="link_checkbox")ae=le==="true"?"yes":"no";else if(ae=le,!ae&&!w.required)continue;j.push({paramName:w.paramName,value:ae})}}for(const[S,w]of Object.entries(W))l[S]===void 0&&!et(w)&&(l[S]=w);const F=new Set(j.map(S=>S.paramName));for(const[S,w]of Object.entries(pe))!F.has(S)&&w&&j.push({paramName:S,value:w});j.length>0&&(l.applicantAdditionalDatas=j);const f=await u(l);s(f.applicantId)}catch(l){console.error("Error creating applicant:",l),R(l.message||"Failed to create applicant")}finally{ce(!1)}},x=async l=>{var j;l.preventDefault();for(const F of _)if(et(J[F])){const f=((j=Ve[F])==null?void 0:j.label)||F;R(`${f} is required.`);return}await _e()},z=(l,j,F,f,S)=>{var kt;const w=Ve[l];if(!w)return null;const le=_.includes(l),ae=T[l],be=F||w.label,Ee=l in ue,ne=j??l,De={required:le},$e=S?S!=="placeholder":k,Ue=$e?be:void 0,Hr=$e?"...":be;switch(w.type){case"select":if(l==="country"||l==="nationality"||l==="taxCountry"||l==="countryOfBirth"||l==="mobileCountryCode"){const Ne=O(l,f);return e.jsx(ze,{...De,label:Ue,value:J[l]||"",onChange:Je=>ge(l,Je),options:[{value:"",label:`Select ${Hr.toLowerCase()}`},...Ne],disabled:C,readOnly:Ee,error:ae},ne)}if(l==="salutation")return e.jsx(ze,{...De,label:Ue,value:((kt=J[l])==null?void 0:kt.toString())||"",onChange:Ne=>ge(l,Ne?Number(Ne):null),options:[{value:"",label:$e?"Select salutation...":be},{value:ot.Male.toString(),label:"Male"},{value:ot.Female.toString(),label:"Female"},{value:ot.Other.toString(),label:"Other"}],readOnly:Ee,error:ae},ne);if(l==="defaultLanguage"){const Ne=c!=null&&c.allowedLanguages&&c.allowedLanguages.length>0?xt.filter(Je=>c.allowedLanguages.includes(Je.value)):xt;return e.jsx(ze,{...De,label:Ue,value:J[l]||"",onChange:Je=>ge(l,Je),options:[{value:"",label:$e?"Select language...":be},...Ne],readOnly:Ee,error:ae},ne)}return null;case"multiselect":if(l==="otherNationality"){const Ne=O(l,f);return e.jsx(Rr,{...De,label:Ue,value:J[l]||[],onChange:Je=>ge(l,Je),options:Ne,placeholder:$e?"Select other nationalities...":be,disabled:C,readOnly:Ee},ne)}return null;case"date":return e.jsx(fe,{...De,type:"date",label:Ue,placeholder:$e?void 0:be,value:J[l]||"",onChange:Ne=>ge(l,Ne.target.value),readOnly:Ee,error:ae},ne);case"email":return e.jsx(fe,{...De,type:"email",label:Ue,placeholder:$e?void 0:be,value:J[l]||"",onChange:Ne=>ge(l,Ne.target.value),readOnly:Ee,error:ae},ne);case"tel":return e.jsx(fe,{...De,type:"tel",label:Ue,placeholder:$e?void 0:be,value:J[l]||"",onChange:Ne=>ge(l,Ne.target.value),readOnly:Ee,error:ae},ne);default:return e.jsx(fe,{...De,type:"text",label:Ue,placeholder:$e?void 0:be,value:J[l]||"",onChange:Ne=>ge(l,Ne.target.value),readOnly:Ee,error:ae},ne)}},V=(l,j)=>{const F=l.labelMode?l.labelMode!=="placeholder":k;if(l.customType==="paragraph"){const w=l.displayText||l.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-${j}`)}if(l.customType==="html")return e.jsx("div",{dangerouslySetInnerHTML:{__html:l.label||""}},`custom-${j}`);if(l.customType==="br")return e.jsx("div",{style:{height:"12px"}},`custom-${j}`);if(l.customType==="link"){const w=l.displayText||l.label||l.linkText||l.linkUrl||"";return e.jsx("div",{className:"metakyc-link-field",children:e.jsxs("a",{href:l.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-${j}`)}if(!l.paramName)return null;const f=T[l.paramName],S=l.displayText||l.label||l.paramName;if(l.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:oe[l.paramName]==="true",onChange:w=>me(l.paramName,w.target.checked?"true":"false"),className:"metakyc-option-input",style:nt}),e.jsxs("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:[S,l.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-${j}`);if(l.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:oe[l.paramName]==="true",onChange:w=>me(l.paramName,w.target.checked?"true":"false"),className:"metakyc-option-input",style:{...nt,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:[S," ",l.linkUrl&&e.jsx("a",{href:l.linkUrl,target:"_blank",rel:"noopener noreferrer",className:"underline",style:{color:"var(--metakyc-primary, #2563eb)"},onClick:w=>w.stopPropagation(),children:l.linkText||l.linkUrl}),l.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-${j}`);if(l.customType==="group_checkbox"){const w=(oe[l.paramName]||"").split(",").filter(Boolean);return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[F&&e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[S,l.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:(l.options||[]).map(le=>{const ae=l.singleSelect?oe[l.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:ae,onChange:be=>{if(l.singleSelect)me(l.paramName,be.target.checked?le.value:"");else{const Ee=be.target.checked?[...w,le.value]:w.filter(ne=>ne!==le.value);me(l.paramName,Ee.join(","))}},className:"metakyc-option-input",style:nt}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:le.label})]},le.value)})}),f&&e.jsx("p",{className:"text-red-500 text-xs",children:f})]},`custom-${j}`)}return l.customType==="radio_group"?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[F&&e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[S,l.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:(l.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:oe[l.paramName]===w.value,onChange:()=>me(l.paramName,w.value),name:`radio-group-${l.paramName}-${j}`,className:"metakyc-option-input",style:nt}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:w.label})]},w.value))}),f&&e.jsx("p",{className:"text-red-500 text-xs",children:f})]},`custom-${j}`):e.jsx(fe,{type:"text",label:F?`${S}${l.required?" *":""}`:void 0,placeholder:F?void 0:S,value:oe[l.paramName]||"",onChange:w=>me(l.paramName,w.target.value),required:l.required,error:f},`custom-${j}`)},H=(l,j)=>{const F=Pe(l);return e.jsxs("div",{className:"space-y-4",children:[l.conditionalOn&&e.jsx(Rt,{helpText:l.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:F,onChange:f=>me(l.conditionalOn,f.target.checked?"true":"false"),className:"metakyc-option-input",style:nt}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",fontWeight:500},children:l.conditionalOn})]})}),F&&e.jsx("div",{className:"grid grid-cols-4 gap-4",children:l.fields.map((f,S)=>{const w=f.colSpan===1?"col-span-1":f.colSpan===2?"col-span-2":f.colSpan===3?"col-span-3":"col-span-4",le=f.isCustom?`custom-${S}-${f.paramName}`:`builtin-${f.name}-${S}`;return e.jsx("div",{className:w,children:e.jsx(Rt,{helpText:f.helpText,children:f.isCustom?V(f,S):z(f.name,le,f.displayText,f.countriesType,f.labelMode)})},le)})})]})};if(!c||C)return e.jsx("div",{className:"metakyc-sdk",children:e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ae,{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(b){const l=b[E]??b[0],j=Le===-1,F=Be===-1,f=b.length,S=Pe(l),w=Object.values(T);return e.jsx("div",{className:"metakyc-sdk",children:e.jsxs(ee,{children:[e.jsx(ve,{children:e.jsx(st,{title:(c==null?void 0:c.title)||"Create Applicant"})}),e.jsxs(te,{children:[(l.title||l.subtitle||l.description)&&e.jsxs("div",{className:"mb-4",children:[l.title&&e.jsx("h3",{className:"font-semibold text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:l.title}),l.subtitle&&e.jsx("p",{className:"text-sm mt-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:l.subtitle}),l.description&&l.description!==l.subtitle&&e.jsx("p",{className:"text-xs mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:l.description})]}),(xe||w.length>0)&&e.jsxs("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-lg",children:[xe&&e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",xe]}),w.map((le,ae)=>e.jsx("p",{className:"text-red-600 text-sm",children:le},ae))]}),f>1&&e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[b.map((le,ae)=>e.jsx("div",{className:`h-1.5 rounded-full transition-all ${ae===E?"flex-1":"w-8"}`,style:ae===E?{backgroundColor:"var(--metakyc-primary, #2563eb)"}:ae<E?{backgroundColor:"var(--metakyc-primary-light, #93c5fd)",opacity:.7}:{backgroundColor:"#e5e7eb"}},ae)),e.jsxs("span",{className:"text-xs text-gray-400 flex-shrink-0",children:[E+1," / ",f]})]}),H(l)]}),e.jsxs(ke,{className:"flex justify-between",children:[e.jsxs("div",{children:[!j&&e.jsx(Z,{type:"button",variant:"outline",onClick:()=>{$(Le),q({})},disabled:Y||m,children:"Previous"}),j&&a&&e.jsx(Z,{type:"button",variant:"outline",onClick:a,disabled:Y||m,children:"Cancel"})]}),e.jsx(Z,{type:"button",isLoading:Y||m,onClick:F?_e:Ge,children:F?l.conditionalOn&&!S?"Skip & Submit":"Submit":l.conditionalOn&&!S?"Skip":"Next"})]})]})})}return e.jsx("div",{className:"metakyc-sdk",children:e.jsx("form",{onSubmit:x,children:e.jsxs(ee,{children:[e.jsx(ve,{children:e.jsx(st,{title:(c==null?void 0:c.title)||"Create Applicant"})}),e.jsxs(te,{children:[xe&&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:"})," ",xe]})}),e.jsx("div",{className:"grid grid-cols-4 gap-4",children:U.map(l=>e.jsx("div",{className:"col-span-4",children:z(l)},l))})]}),e.jsxs(ke,{className:"flex justify-between",children:[a&&e.jsx(Z,{type:"button",variant:"outline",onClick:a,disabled:Y||m,children:"Cancel"}),e.jsx(Z,{type:"submit",isLoading:Y||m,children:"Create Applicant"})]})]})})})},It=["companyName","email"];function yt(t){return t==null||t===""||Array.isArray(t)&&t.length===0}const Rs=({workflowKey:t,externalRefId:r,onSuccess:s,onCancel:a})=>{var z,V,H,se,re,de;const{config:n,baseInformationService:o,currentTheme:c}=Re(),{createCompanyApplicant:u,isLoading:m}=bt(),p=t||((z=n.applicantForm)==null?void 0:z.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 I=r||((V=n.applicantForm)==null?void 0:V.externalRefId)||"",P=((H=n.applicantForm)==null?void 0:H.email)||"",g=((se=n.applicantForm)==null?void 0:se.initialValues)||{},N=(((re=n.applicantForm)==null?void 0:re.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]),b=i.useMemo(()=>{const y=new Set(It),d=c==null?void 0:c.companyFormRequiredFields;if(d)for(const D of d)y.add(D);if(k)for(const D of k)for(const v of D.fields)!v.isCustom&&v.name&&v.required&&y.add(v.name);return Array.from(y)},[c==null?void 0:c.companyFormRequiredFields,k]),_=i.useMemo(()=>{var y;if(k){const d=k.flatMap(v=>v.fields).filter(v=>!v.isCustom&&v.name).map(v=>v.name),D=new Set(d);for(const v of It)D.add(v);return Array.from(D)}return(y=n.applicantForm)!=null&&y.visibleFields?n.applicantForm.visibleFields:c!=null&&c.companyFormVisibleFields&&c.companyFormVisibleFields.length>0?c.companyFormVisibleFields:_t},[(de=n.applicantForm)==null?void 0:de.visibleFields,c==null?void 0:c.companyFormVisibleFields,k]),U=new Set(["countryResidence","addressCountry"]),L=i.useMemo(()=>{var d,D;const y=new Set;if(k)for(const v of k)for(const l of v.fields)!l.isCustom&&l.name&&U.has(l.name)&&y.add(l.countriesType??((d=Ze[l.name])==null?void 0:d.countriesType));else for(const v of _)U.has(v)&&y.add((D=Ze[v])==null?void 0:D.countriesType);return y.size===0&&y.add(void 0),Array.from(y)},[_,k]),[B,K]=i.useState({}),[X,C]=i.useState(!0),h=i.useRef(new Set),M=i.useRef(new Set);i.useEffect(()=>{if(!c)return;const y=L.filter(v=>{const l=v!=null?String(v):"all";return!M.current.has(l)&&!h.current.has(l)});if(y.length===0){L.every(l=>M.current.has(l!=null?String(l):"all"))&&C(!1);return}C(!0);const d=y.map(v=>v!=null?String(v):"all");d.forEach(v=>h.current.add(v)),(async()=>{try{const v=await Promise.all(y.map(async l=>{const j=l!=null?String(l):"all",F=await o.getCountries("",n.locale||"en",l),f=new Set,S=F.map(w=>({value:w.abbreviation3||w.abbreviation,label:w.name})).filter(w=>!w.value||f.has(w.value)?!1:(f.add(w.value),!0));return M.current.add(j),h.current.delete(j),[j,S]}));K(l=>({...l,...Object.fromEntries(v)}))}catch(v){d.forEach(l=>h.current.delete(l)),console.error("Failed to load countries:",v)}finally{L.every(l=>M.current.has(l!=null?String(l):"all"))&&C(!1)}})()},[L,c]);const Q=(y,d)=>{var l;const D=d??((l=Ze[y])==null?void 0:l.countriesType),v=D!=null?String(D):"all";return B[v]||[]},O={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},G=Object.fromEntries(Object.entries(g).filter(([y])=>y in O)),[W,ue]=i.useState({workflowKey:p,companyName:"",email:P,phone:"",registrationNumber:"",countryResidence:"",legalAddress:"",incorporatedOn:"",controlScheme:"",taxId:"",registrationLocation:"",website:"",postalAddress:"",street:"",streetNumber:"",city:"",state:"",postalCode:"",addressCountry:"",lei:"",externalRefId:I,...G}),[J,he]=i.useState({}),[pe,oe]=i.useState(0),[je,E]=i.useState({}),[$,T]=i.useState(null),[q,xe]=i.useState(!1),R=(y,d)=>ue(D=>({...D,[y]:d})),Y=(y,d)=>he(D=>({...D,[y]:d})),ce=y=>!y.conditionalOn||J[y.conditionalOn]==="true",ge=k&&pe<k.length-1?pe+1:-1,me=k&&pe>0?pe-1:-1,Pe=y=>{var D;const d={};for(const v of y.fields)if(v.isCustom){if(v.customType==="paragraph"||v.customType==="html"||v.customType==="br"||v.customType==="link")continue;if(v.required&&v.paramName){const l=J[v.paramName],j=v.displayText||v.label||v.paramName;v.customType==="checkbox"||v.customType==="link_checkbox"?l!=="true"&&(d[v.paramName]=`${j} is required.`):(!l||l.trim()==="")&&(d[v.paramName]=`${j} is required.`)}}else if(v.name){const l=v.name;if(b.includes(l)&&yt(W[l])){const j=v.displayText||((D=Ze[l])==null?void 0:D.label)||l;d[l]=`${j} is required.`}}return d},Be=async()=>{if(!k)return;const y=k[pe];if(y.conditionalOn&&!ce(y)){E({}),ge>=0?oe(ge):await Le();return}const d=Pe(y);if(Object.keys(d).length>0){E(d);return}E({}),ge>=0?oe(ge):await Le()},Le=async()=>{var y;if(k){let d={};for(const D of k)ce(D)&&(d={...d,...Pe(D)});if(Object.keys(d).length>0){E(d);return}}xe(!0),T(null);try{const d={workflowKey:W.workflowKey,externalRefId:((y=W.externalRefId)==null?void 0:y.trim())||void 0},D=k?k.filter(j=>ce(j)).flatMap(j=>j.fields).filter(j=>!j.isCustom&&j.name).map(j=>j.name):_;for(const j of D){const F=W[j];if(!yt(F))switch(j){case"companyName":d.companyName=F;break;case"email":d.companyEmail=F;break;case"phone":d.companyPhone=F;break;case"registrationNumber":d.companyRegistrationNumber=F;break;case"countryResidence":d.companyCountry=F;break;case"city":d.companyCity=F;break;case"street":d.companyStreet=F;break;case"postalCode":d.companyZip=F;break;default:d[j]=F;break}}const v=[];if(k){for(const j of k)if(ce(j))for(const F of j.fields){if(!F.isCustom||!F.paramName||F.customType==="paragraph"||F.customType==="html"||F.customType==="br"||F.customType==="link")continue;const f=J[F.paramName]??"";let S;if(F.customType==="checkbox"||F.customType==="link_checkbox")S=f==="true"?"yes":"no";else if(S=f,!S&&!F.required)continue;v.push({paramName:F.paramName,value:S})}}v.length>0&&(d.applicantAdditionalDatas=v);const l=await u(d);s(l.applicantId)}catch(d){console.error("Error creating company applicant:",d),T(d.message||"Failed to create company applicant")}finally{xe(!1)}},Qe=async y=>{var d;y.preventDefault();for(const D of b)if(yt(W[D])){const v=((d=Ze[D])==null?void 0:d.label)||D;T(`${v} is required.`);return}await Le()},Ge=(y,d,D,v,l)=>{const j=Ze[y];if(!j)return null;const F=b.includes(y),f=je[y],S=D||j.label,w=y in G,le=d??y,ae=l?l!=="placeholder":N,be=ae?S:void 0,Ee=ae?"...":S;switch(j.type){case"select":if(y==="countryResidence"||y==="addressCountry"){const ne=Q(y,v);return e.jsx(ze,{required:F,label:be,value:W[y]||"",onChange:De=>R(y,De),options:[{value:"",label:`Select ${Ee.toLowerCase()}`},...ne],disabled:X,readOnly:w,error:f},le)}return null;case"date":return e.jsx(fe,{required:F,type:"date",label:be,placeholder:ae?void 0:S,value:W[y]||"",onChange:ne=>R(y,ne.target.value),readOnly:w,error:f},le);case"email":return e.jsx(fe,{required:F,type:"email",label:be,placeholder:ae?void 0:S,value:W[y]||"",onChange:ne=>R(y,ne.target.value),readOnly:w,error:f},le);case"tel":return e.jsx(fe,{required:F,type:"tel",label:be,placeholder:ae?void 0:S,value:W[y]||"",onChange:ne=>R(y,ne.target.value),readOnly:w,error:f},le);default:return e.jsx(fe,{required:F,type:"text",label:be,placeholder:ae?void 0:S,value:W[y]||"",onChange:ne=>R(y,ne.target.value),readOnly:w,error:f},le)}},_e=(y,d)=>{if(y.customType==="paragraph")return e.jsx("p",{style:{fontSize:"14px",lineHeight:"1.7",margin:0,color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:y.displayText||y.label||""}},`custom-${d}`);if(y.customType==="html")return e.jsx("div",{dangerouslySetInnerHTML:{__html:y.label||""}},`custom-${d}`);if(y.customType==="br")return e.jsx("div",{style:{height:"12px"}},`custom-${d}`);if(y.customType==="link")return e.jsx("div",{children:e.jsx("a",{href:y.linkUrl||"#",target:"_blank",rel:"noopener noreferrer",style:{color:"var(--metakyc-primary, #2563eb)",fontSize:"14px",textDecoration:"underline"},children:y.displayText||y.label||y.linkText||y.linkUrl||""})},`custom-${d}`);if(!y.paramName)return null;const D=je[y.paramName],v=y.displayText||y.label||y.paramName,l=y.labelMode?y.labelMode!=="placeholder":N;return y.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:J[y.paramName]==="true",onChange:j=>Y(y.paramName,j.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:[v,y.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),D&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:D})]},`custom-${d}`):e.jsx(fe,{type:"text",label:l?`${v}${y.required?" *":""}`:void 0,placeholder:l?void 0:v,value:J[y.paramName]||"",onChange:j=>Y(y.paramName,j.target.value),required:y.required,error:D},`custom-${d}`)},x=y=>{const d=ce(y);return e.jsxs("div",{className:"space-y-4",children:[y.conditionalOn&&e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:d,onChange:D=>Y(y.conditionalOn,D.target.checked?"true":"false"),style:{width:"16px",height:"16px",accentColor:"var(--metakyc-primary, #2563eb)"}}),e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:y.conditionalOn})]}),d&&e.jsx("div",{className:"grid grid-cols-4 gap-4",children:y.fields.map((D,v)=>{const l=D.colSpan===1?"col-span-1":D.colSpan===2?"col-span-2":D.colSpan===3?"col-span-3":"col-span-4",j=D.isCustom?`custom-${v}-${D.paramName}`:`builtin-${D.name}-${v}`;return e.jsx("div",{className:l,children:D.isCustom?_e(D,v):Ge(D.name,j,D.displayText,D.countriesType,D.labelMode)},j)})})]})};if(!c||X)return e.jsx("div",{className:"metakyc-sdk",children:e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ae,{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 y=k[pe]??k[0],d=me===-1,D=ge===-1,v=k.length,l=ce(y),j=Object.values(je);return e.jsx("div",{className:"metakyc-sdk",children:e.jsxs(ee,{children:[e.jsx(ve,{children:e.jsx(st,{title:(c==null?void 0:c.title)||"Company Registration"})}),e.jsxs(te,{children:[(y.title||y.subtitle)&&e.jsxs("div",{className:"mb-4",children:[y.title&&e.jsx("h3",{className:"font-semibold text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:y.title}),y.subtitle&&e.jsx("p",{className:"text-sm mt-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:y.subtitle})]}),($||j.length>0)&&e.jsxs("div",{className:"mb-4 p-3 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:"})," ",$]}),j.map((F,f)=>e.jsx("p",{className:"text-red-600 text-sm",children:F},f))]}),v>1&&e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[k.map((F,f)=>e.jsx("div",{className:`h-1.5 rounded-full transition-all ${f===pe?"flex-1":"w-8"}`,style:f===pe?{backgroundColor:"var(--metakyc-primary, #2563eb)"}:f<pe?{backgroundColor:"var(--metakyc-primary-light, #93c5fd)",opacity:.7}:{backgroundColor:"#e5e7eb"}},f)),e.jsxs("span",{className:"text-xs text-gray-400 flex-shrink-0",children:[pe+1," / ",v]})]}),x(y)]}),e.jsxs(ke,{className:"flex justify-between",children:[e.jsxs("div",{children:[!d&&e.jsx(Z,{type:"button",variant:"outline",onClick:()=>{oe(me),E({})},disabled:q||m,children:"Previous"}),d&&a&&e.jsx(Z,{type:"button",variant:"outline",onClick:a,disabled:q||m,children:"Cancel"})]}),e.jsx(Z,{type:"button",isLoading:q||m,onClick:D?Le:Be,children:D?y.conditionalOn&&!l?"Skip & Submit":"Submit":y.conditionalOn&&!l?"Skip":"Next"})]})]})})}return e.jsx("div",{className:"metakyc-sdk",children:e.jsx("form",{onSubmit:Qe,children:e.jsxs(ee,{children:[e.jsx(ve,{children:e.jsx(st,{title:(c==null?void 0:c.title)||"Company Registration"})}),e.jsxs(te,{children:[$&&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:"})," ",$]})}),e.jsx("div",{className:"grid grid-cols-4 gap-4",children:_.map(y=>e.jsx("div",{className:"col-span-4",children:Ge(y)},y))})]}),e.jsxs(ke,{className:"flex justify-between",children:[a&&e.jsx(Z,{type:"button",variant:"outline",onClick:a,disabled:q||m,children:"Cancel"}),e.jsx(Z,{type:"submit",isLoading:q||m,children:"Register Company"})]})]})})})},Is=({applicantId:t,onComplete:r,onError:s,theme:a="light",className:n})=>{const{progress:o,currentStep:c,steps:u,workflowKey:m,nextWorkflowKey:p,hasWorkflowChanged:I,isLoading:P,error:g,moveBack:A,refreshProgress:N}=kr(t),[k,b]=i.useState(!1),_=i.useRef(null);if(i.useEffect(()=>{g&&s&&s(g)},[g,s]),i.useEffect(()=>{o!=null&&o.workflowResult&&r&&r(o.workflowResult)},[o==null?void 0:o.workflowResult,r]),i.useEffect(()=>{a==="dark"?document.documentElement.classList.add("dark"):document.documentElement.classList.remove("dark")},[a]),i.useEffect(()=>{I&&b(!1)},[I]),P||!o)return e.jsx("div",{className:`metakyc-sdk ${n||""}`,children:e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ae,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Loading workflow..."})]})})});if(g)return e.jsx("div",{className:`metakyc-sdk ${n||""}`,children:e.jsx(ee,{children:e.jsx(te,{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:g.message})]})})})});if(I&&!k)return e.jsx("div",{className:`metakyc-sdk ${n||""}`,children:e.jsx(ee,{children:e.jsx(te,{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:p})]})]}),o.nextWorkflowName&&e.jsx("p",{className:"text-center mt-2 text-xs",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:o.nextWorkflowName})]}),e.jsx("button",{onClick:()=>b(!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(o.status===Te.Finished||o.status===Te.OnHold)return e.jsx("div",{className:`metakyc-sdk ${n||""}`,children:e.jsx(ht,{kycStatus:o.kycStatus,reviewStatus:o.reviewStatus,workflowResult:o.workflowResult,customMessage:o.customMessage,onContinue:r&&o.workflowResult?()=>r(o.workflowResult):void 0,onContactSupport:()=>{typeof window<"u"&&(window.location.href="mailto:support@example.com")}})});if(!c)return e.jsx("div",{className:`metakyc-sdk ${n||""}`,children:e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ae,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:o.status===Te.IdentityPending?"Loading identity verification...":"Loading current step..."})]})})});const U=K=>{switch(K){case ie.Overview:return"Overview";case ie.Questionaries:return"Questionnaire";case ie.UploadDocument:return"Documents";case ie.IdentitySdk:return"Identity";case ie.RiskScoring:return"Risk Assessment";case ie.InvestorCategorization:return"Investor Categorization";case ie.AppropriatenessTest:return"Appropriateness Test";case ie.AdditionalData:return"Additional Data";case ie.ManualReview:return"Review";default:return""}},L=()=>{const K=u.filter(Q=>Q.visibility!==!1),X=K.findIndex(Q=>Q.order===c.order),C=X>=0?X+1:1,h=K.length,M=h>1?X/(h-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:o.status===1?"info":"success",children:["Step ",C," of ",h]})]}),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:`${M}%`,transition:"width 0.4s ease"}})})}),e.jsx(Es,{ref:_,visibleSteps:K,currentVisibleStepIndex:X,getStepFallbackName:U})]})},B=()=>{const K={applicantId:t,onComplete:async()=>{await N()},onBack:c.order>0?A:void 0};switch(c.action){case ie.Questionaries:return e.jsx(Lr,{...K});case ie.UploadDocument:return e.jsx(Dr,{...K});case ie.Overview:return e.jsx(Mr,{...K});case ie.IdentitySdk:return e.jsx(_r,{...K});case ie.RiskScoring:return e.jsx(Or,{...K});case ie.AdditionalData:case ie.InvestorCategorization:return e.jsx(zr,{...K});case ie.AppropriatenessTest:return e.jsx(Br,{...K});case ie.ManualReview:return e.jsx(ht,{kycStatus:o.kycStatus,reviewStatus:o.reviewStatus,workflowResult:o.workflowResult,customMessage:o.customMessage});default:return e.jsx(ee,{children:e.jsxs(te,{className:"py-12 text-center",children:[e.jsx("div",{className:"mb-4",children:e.jsx(Ae,{})}),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: ",ie[c.action]]})]})})}};return e.jsxs("div",{className:`metakyc-sdk ${n||""}`,children:[L(),B()]})},Es=i.forwardRef(({visibleSteps:t,currentVisibleStepIndex:r,getStepFallbackName:s},a)=>{const n=i.useRef(null),o=i.useRef(null);return i.useImperativeHandle(a,()=>n.current),i.useEffect(()=>{if(o.current&&n.current){const c=n.current,u=o.current,m=u.offsetLeft-c.offsetWidth/2+u.offsetWidth/2;c.scrollTo({left:Math.max(0,m),behavior:"smooth"})}},[r]),e.jsx("div",{ref:n,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 m=u<r,p=u===r,I=m||p,P=c.displayName||c.name||s(c.action)||`Step ${u+1}`;return e.jsxs(i.Fragment,{children:[e.jsxs("div",{ref:p?o: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",...I?{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"})}):u+1}),e.jsx("span",{style:{marginLeft:"6px",fontSize:"13px",whiteSpace:"nowrap",fontWeight:p?600:400,color:p?"var(--metakyc-text-primary, #111827)":m?"var(--metakyc-primary, #2563eb)":"var(--metakyc-text-muted, #9ca3af)",transition:"color 0.2s ease"},children:P})]}),u<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 As(t){return We.z.object({questionResults:We.z.any()}).passthrough()}function Fs(t){let r=We.z.array(We.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(a=>a.size<=t.maxEachFileSizeByte),{message:`File size must not exceed ${Math.round(t.maxEachFileSizeByte/1024/1024)}MB`})),t.allowedTypes){const s=t.allowedTypes.split(",").map(a=>a.trim());r=r.refine(a=>a?a.every(n=>s.some(o=>o.endsWith("/*")?n.type.startsWith(o.slice(0,-2)):n.type===o)):!0,{message:"Invalid file type"})}return r}function Ts(t){const r={};return t.uploadDocumentFiles.forEach(s=>{const a=`file_${s.id}`;r[a]=Fs(s)}),We.z.object(r)}function Ps(t){return We.z.any()}function Ls(t){return We.z.string().min(1,"This question is required")}function Ds(t){const r={};return t.appropriatenessQuestions.forEach(s=>{const a=`question_${s.id}`;r[a]=Ls()}),We.z.object(r)}const Ms=We.z.any();exports.ALLOWED_LANGUAGES=xt;exports.ApplicantProgressOnHoldReason=Et;exports.ApplicantProgressStatus=Te;exports.ApplicantService=Kt;exports.ApplicantStatus=Ft;exports.AppropriatenessQuestionType=Mt;exports.AppropriatenessTestService=Vt;exports.AppropriatenessTestStep=Br;exports.Badge=vt;exports.BaseInformationService=Zt;exports.Button=Z;exports.COMPANY_FIELD_METADATA=Ze;exports.Card=ee;exports.CardContent=te;exports.CardFooter=ke;exports.CardHeader=ve;exports.CountriesType=He;exports.CreateApplicantForm=Ns;exports.CreateCompanyApplicantForm=Rs;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=Xe;exports.IdentityService=Jt;exports.IdentityVerificationProvider=Fe;exports.IdentityVerificationStep=_r;exports.Input=fe;exports.InvestorCategorizationService=Xt;exports.InvestorCategorizationStep=zr;exports.InvestorCategorizationType=we;exports.InvestorCategoryType=Bt;exports.KycProcessStatus=Tt;exports.KycStatus=qe;exports.KycStatusDisplay=ht;exports.KycWorkflow=Is;exports.Logo=$r;exports.MetaKYCContext=gt;exports.MetaKYCError=Me;exports.MetaKYCProvider=Gr;exports.MultiSelect=Rr;exports.OnfidoProvider=pr;exports.OverviewService=Qt;exports.OverviewStep=Mr;exports.PhoneInput=Er;exports.QuestionnaireService=qt;exports.QuestionnaireStep=Lr;exports.ReviewStatus=Ye;exports.RiskCriteriaType=Ot;exports.RiskLevel=At;exports.RiskScoringService=Gt;exports.RiskScoringStep=Or;exports.SardinAIProvider=mr;exports.SearchableSelect=ze;exports.Select=pt;exports.Spinner=Ae;exports.StepRouter=cr;exports.SumsubProvider=ur;exports.ThemeManager=yr;exports.ThemePreset=Se;exports.ThemeService=ir;exports.UploadDocumentService=Yt;exports.UploadDocumentStep=Dr;exports.UserType=Pt;exports.ValueDataType=Oe;exports.WorkflowOrchestrator=dr;exports.WorkflowResultType=it;exports.WorkflowState=lr;exports.WorkflowStepAction=ie;exports.appropriatenessTestSchema=Ms;exports.clearAllStorage=ts;exports.clearApplicantId=gr;exports.clearWorkflowState=vr;exports.cn=Ce;exports.corporateTheme=er;exports.defaultConfig=Ht;exports.defaultTheme=Ie;exports.fileToBase64=xr;exports.fintechTheme=tr;exports.formatFileSize=dt;exports.generateAppropriatenessSchema=Ds;exports.generateQuestionnaireSchema=As;exports.generateRiskScoringSchema=Ps;exports.generateUploadDocumentSchema=Ts;exports.getAcceptString=Xr;exports.getApplicantId=fr;exports.getThemePreset=rt;exports.getWorkflowState=es;exports.healthcareTheme=rr;exports.isScriptLoaded=Yr;exports.loadScript=ft;exports.minimalTheme=ar;exports.modernTheme=sr;exports.removeScript=Vr;exports.saveApplicantId=hr;exports.saveWorkflowState=br;exports.themePresets=nr;exports.useApplicant=bt;exports.useAppropriatenessTest=rs;exports.useIdentityVerification=Cr;exports.useKycWorkflow=kr;exports.useMetaKYC=Re;exports.useOverview=Sr;exports.useQuestionnaire=jr;exports.useRiskScoring=Nr;exports.useUploadDocument=wr;exports.validateFileSize=Jr;exports.validateFileType=Zr;
83
83
  //# sourceMappingURL=index.cjs.map