@vpdev2/metakyc-sdk 1.0.92 → 1.0.94

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 Dr=Object.defineProperty;var Mr=(t,r,s)=>r in t?Dr(t,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[r]=s;var de=(t,r,s)=>Mr(t,typeof r!="symbol"?r+"":r,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Or=require("axios"),l=require("react"),e=require("react/jsx-runtime"),it=require("react-dom"),Be=require("react-hook-form"),Me=require("zod");function zr(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 ht=zr(l);var se=(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))(se||{}),rt=(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))(rt||{}),Ee=(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))(Ee||{}),kt=(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))(kt||{}),jt=(t=>(t[t.LowRisk=0]="LowRisk",t[t.MediumRisk=1]="MediumRisk",t[t.HighRisk=2]="HighRisk",t[t.Alert=3]="Alert",t))(jt||{}),_e=(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))(_e||{}),$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||{}),wt=(t=>(t[t.ProviderResultPending=0]="ProviderResultPending",t[t.ProviderResultReceived=1]="ProviderResultReceived",t[t.Canceled=2]="Canceled",t[t.ExtendedToNewApplicant=3]="ExtendedToNewApplicant",t))(wt||{}),St=(t=>(t[t.None=0]="None",t[t.ProviderResultPending=1]="ProviderResultPending",t[t.ProviderResultReceived=2]="ProviderResultReceived",t[t.Canceled=3]="Canceled",t))(St||{}),Ce=(t=>(t[t.Onfido=0]="Onfido",t[t.Sumsub=2]="Sumsub",t[t.SardinAI=3]="SardinAI",t))(Ce||{}),Nt=(t=>(t[t.Individual=0]="Individual",t[t.Company=1]="Company",t))(Nt||{}),st=(t=>(t[t.Male=0]="Male",t[t.Female=1]="Female",t[t.Other=2]="Other",t))(st||{}),Ct=(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))(Ct||{}),Et=(t=>(t[t.Pending=0]="Pending",t[t.Approved=1]="Approved",t[t.Rejected=2]="Rejected",t[t.RequiresRevision=3]="RequiresRevision",t))(Et||{}),Rt=(t=>(t[t.SingleChoice=0]="SingleChoice",t[t.MultipleChoice=1]="MultipleChoice",t[t.Text=2]="Text",t))(Rt||{}),Ae=(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))(Ae||{}),At=(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))(At||{}),It=(t=>(t[t.None=0]="None",t[t.Country=1]="Country",t))(It||{}),be=(t=>(t[t.Individual=0]="Individual",t[t.Sophisticated=1]="Sophisticated",t[t.HighNetWorth=2]="HighNetWorth",t[t.Business=3]="Business",t))(be||{}),Ft=(t=>(t[t.Retail=0]="Retail",t[t.Professional=1]="Professional",t[t.EligibleCounterparty=2]="EligibleCounterparty",t))(Ft||{});const Le={Nationality:10,Address:20,CountryOfBirth:30,PhoneNumber:40,UboAddress:50},He={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"}},We={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"}},Pt=["companyName","email","phone","registrationNumber"],Tt=["firstName","lastName","email","phonenumber","dateOfBirth"],ct=[{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 ve=(t=>(t.Default="default",t.Corporate="corporate",t.Fintech="fintech",t.Healthcare="healthcare",t.Modern="modern",t.Minimal="minimal",t))(ve||{});const Lt={timeout:3e4,retries:3,locale:"en",endpoints:{pattern:"host-controller"}};class Dt{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 Re extends Error{constructor(s,a,n,o,d){super(s);de(this,"response");this.code=a,this.details=n,this.validationErrors=o,this.name="MetaKYCError",this.response=d,Object.setPrototypeOf(this,Re.prototype)}}class Je{static handleApiError(r){return new Re(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 Re(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 Re(s.result.message,r.response.status,`HTTP ${r.response.status}: ${r.response.statusText}`,void 0,r.response):new Re((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 Re("No response from server",0,"The request was made but no response was received. Please check your network connection."):new Re(r.message||"An unexpected error occurred",0,r.toString())}static isMetaKYCError(r){return r instanceof Re}}class Mt{constructor(r){de(this,"axiosInstance");de(this,"endpointBuilder");de(this,"config");this.config={...Lt,...r},this.endpointBuilder=new Dt(this.config.endpoints),this.axiosInstance=Or.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 Je.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 Je.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 Je.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 Je.handleAxiosError(n)}}handleResponse(r){const s=r.data;if(!s.success&&s.error)throw Je.handleApiError(s.error);return s}getAxiosInstance(){return this.axiosInstance}}class Ot{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 zt{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 Bt{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 _t{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 $t{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 Ht{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 Ut{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 Kt{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 Wt{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"}},Yt={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"}},Vt={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"}}},Qt={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"}},Gt={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"}},Jt={[ve.Default]:Se,[ve.Corporate]:qt,[ve.Fintech]:Yt,[ve.Healthcare]:Vt,[ve.Modern]:Qt,[ve.Minimal]:Gt};function Ze(t){return Jt[t]||Se}class Zt{constructor(r){this.httpClient=r}async getThemeConfiguration(){var r;try{const s=await this.httpClient.get("Tenant","GetThemeConfiguration");if(!s.result.isEnabled)return Ze(ve.Default);let a=s.result.preset?Ze(s.result.preset):Ze(ve.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 d=!o._v||o._v<4;return{...o,fields:(o.fields||[]).map(m=>({...m,colSpan:d?m.colSpan===1?2:4:Math.min(4,Math.max(1,m.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 d=!o._v||o._v<4;return{...o,fields:(o.fields||[]).map(m=>({...m,colSpan:d?m.colSpan===1?2:4:Math.min(4,Math.max(1,m.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),Ze(ve.Default)}}async saveThemeConfiguration(r){await this.httpClient.post("Tenant","SaveThemeConfiguration",r)}getAvailablePresets(){return[{id:ve.Default,name:"Default"},{id:ve.Corporate,name:"Corporate"},{id:ve.Fintech,name:"Fintech"},{id:ve.Healthcare,name:"Healthcare"},{id:ve.Modern,name:"Modern"},{id:ve.Minimal,name:"Minimal"}]}getPreviewTheme(r,s){const a=Ze(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 Xt{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(o){console.error(`Error in event listener for "${r}":`,o)}})}clear(){this.listeners.clear()}clearEvent(r){this.listeners.delete(r)}}class er{constructor(){de(this,"events",new Xt);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)||Ee.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===Ee.Finished}get isOnHold(){return this.status===Ee.OnHold}get isInProgress(){return this.status===Ee.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===Ee.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 tr{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: ${se[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: ${se[r]}`);return a.submitData(s)}}class rr{constructor(r,s,a,n,o,d,m,x){de(this,"state");de(this,"stepRouter");this.applicantService=r,this.questionnaireService=s,this.uploadDocumentService=a,this.appropriatenessTestService=n,this.overviewService=o,this.riskScoringService=d,this.investorCategorizationService=x,this.state=new er,this.stepRouter=new tr,this.registerStepHandlers()}registerStepHandlers(){this.stepRouter.registerHandler(se.Questionaries,{loadData:r=>this.questionnaireService.getQuestionnaire(r),submitData:async r=>{await this.questionnaireService.fillQuestionnaire(r)}}),this.stepRouter.registerHandler(se.UploadDocument,{loadData:r=>this.uploadDocumentService.getUploadDocument(r),submitData:r=>this.uploadDocumentService.fillUploadDocument(r)}),this.stepRouter.registerHandler(se.AppropriatenessTest,{loadData:r=>this.appropriatenessTestService.getAppropriatenessTest(r),submitData:async r=>{await this.appropriatenessTestService.fillAppropriatenessTest(r)}}),this.stepRouter.registerHandler(se.Overview,{loadData:r=>this.overviewService.getOverviewData(r),submitData:r=>this.overviewService.passOverview(r.applicantId)}),this.stepRouter.registerHandler(se.RiskScoring,{loadData:r=>this.riskScoringService.getRiskCriterias(r),submitData:async r=>{await this.riskScoringService.submitRiskScoring(r)}}),this.stepRouter.registerHandler(se.IdentitySdk,{loadData:async r=>({applicantId:r,message:"Identity verification required"}),submitData:async()=>{}}),this.stepRouter.registerHandler(se.InvestorCategorization,{loadData:r=>this.investorCategorizationService.getInvestorCategorization(r),submitData:async r=>{await this.investorCategorizationService.setInvestorCategorization(r)}}),this.stepRouter.registerHandler(se.ManualReview,{loadData:async r=>({applicantId:r,message:"Your application is under manual review"}),submitData:async()=>{}}),this.stepRouter.registerHandler(se.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 ut(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 Br(t){return!!document.getElementById(t)}function _r(t){const r=document.getElementById(t);r&&r.remove()}class sr{constructor(r){de(this,"sdk",null);de(this,"config");this.config=r}async loadSDK(){await ut("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 ar{constructor(r){de(this,"sdk",null);de(this,"config");this.config=r}async loadSDK(){await ut("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 nr{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 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:d}=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:d===!0,region:this.config.region,onDeviceResponse:m=>{console.log(`[SardinAI] Device ID: ${m.deviceId}`)},onConfigUpdate:(m,x,p)=>{switch(m){case"SESSION_UPDATE_FAILED":console.error("[SardinAI] Session update failed:",p);break;case"SESSION_UPDATED":console.log("[SardinAI] Session updated:",x);break;case"SESSION_NO_UPDATE":console.log("[SardinAI] No session update");break;default:console.warn("[SardinAI] Unknown event:",m)}}}),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 qe{static createProvider(r,s){switch(r){case Ce.Sumsub:return new sr(s);case Ce.Onfido:return new ar(s);case Ce.SardinAI:return new nr(s);default:throw new Error(`Unsupported identity provider: ${r}`)}}static parseProviderConfig(r,s,a){var n;switch(r){case Ce.Sumsub:return{accessToken:s.accessToken||s.token,applicantEmail:s.email,applicantPhone:s.phone,externalUserId:s.externalUserId,lang:s.lang||"en"};case Ce.Onfido:return{token:s.token||s.sdkToken};case Ce.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 $r(){return`
1
+ "use strict";var Dr=Object.defineProperty;var Mr=(t,r,s)=>r in t?Dr(t,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[r]=s;var de=(t,r,s)=>Mr(t,typeof r!="symbol"?r+"":r,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Or=require("axios"),l=require("react"),e=require("react/jsx-runtime"),it=require("react-dom"),Be=require("react-hook-form"),Me=require("zod");function zr(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 ht=zr(l);var se=(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))(se||{}),rt=(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))(rt||{}),Ee=(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))(Ee||{}),kt=(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))(kt||{}),jt=(t=>(t[t.LowRisk=0]="LowRisk",t[t.MediumRisk=1]="MediumRisk",t[t.HighRisk=2]="HighRisk",t[t.Alert=3]="Alert",t))(jt||{}),_e=(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))(_e||{}),$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||{}),wt=(t=>(t[t.ProviderResultPending=0]="ProviderResultPending",t[t.ProviderResultReceived=1]="ProviderResultReceived",t[t.Canceled=2]="Canceled",t[t.ExtendedToNewApplicant=3]="ExtendedToNewApplicant",t))(wt||{}),St=(t=>(t[t.None=0]="None",t[t.ProviderResultPending=1]="ProviderResultPending",t[t.ProviderResultReceived=2]="ProviderResultReceived",t[t.Canceled=3]="Canceled",t))(St||{}),Ce=(t=>(t[t.Onfido=0]="Onfido",t[t.Sumsub=2]="Sumsub",t[t.SardinAI=3]="SardinAI",t))(Ce||{}),Nt=(t=>(t[t.Individual=0]="Individual",t[t.Company=1]="Company",t))(Nt||{}),st=(t=>(t[t.Male=0]="Male",t[t.Female=1]="Female",t[t.Other=2]="Other",t))(st||{}),Ct=(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))(Ct||{}),Et=(t=>(t[t.Pending=0]="Pending",t[t.Approved=1]="Approved",t[t.Rejected=2]="Rejected",t[t.RequiresRevision=3]="RequiresRevision",t))(Et||{}),Rt=(t=>(t[t.SingleChoice=0]="SingleChoice",t[t.MultipleChoice=1]="MultipleChoice",t[t.Text=2]="Text",t))(Rt||{}),Ae=(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))(Ae||{}),At=(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))(At||{}),Ft=(t=>(t[t.None=0]="None",t[t.Country=1]="Country",t))(Ft||{}),be=(t=>(t[t.Individual=0]="Individual",t[t.Sophisticated=1]="Sophisticated",t[t.HighNetWorth=2]="HighNetWorth",t[t.Business=3]="Business",t))(be||{}),It=(t=>(t[t.Retail=0]="Retail",t[t.Professional=1]="Professional",t[t.EligibleCounterparty=2]="EligibleCounterparty",t))(It||{});const Le={Nationality:10,Address:20,CountryOfBirth:30,PhoneNumber:40,UboAddress:50},He={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"}},We={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"}},Pt=["companyName","email","phone","registrationNumber"],Tt=["firstName","lastName","email","phonenumber","dateOfBirth"],ct=[{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 ve=(t=>(t.Default="default",t.Corporate="corporate",t.Fintech="fintech",t.Healthcare="healthcare",t.Modern="modern",t.Minimal="minimal",t))(ve||{});const Lt={timeout:3e4,retries:3,locale:"en",endpoints:{pattern:"host-controller"}};class Dt{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 Re extends Error{constructor(s,a,n,o,d){super(s);de(this,"response");this.code=a,this.details=n,this.validationErrors=o,this.name="MetaKYCError",this.response=d,Object.setPrototypeOf(this,Re.prototype)}}class Je{static handleApiError(r){return new Re(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 Re(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 Re(s.result.message,r.response.status,`HTTP ${r.response.status}: ${r.response.statusText}`,void 0,r.response):new Re((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 Re("No response from server",0,"The request was made but no response was received. Please check your network connection."):new Re(r.message||"An unexpected error occurred",0,r.toString())}static isMetaKYCError(r){return r instanceof Re}}class Mt{constructor(r){de(this,"axiosInstance");de(this,"endpointBuilder");de(this,"config");this.config={...Lt,...r},this.endpointBuilder=new Dt(this.config.endpoints),this.axiosInstance=Or.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 Je.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 Je.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 Je.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 Je.handleAxiosError(n)}}handleResponse(r){const s=r.data;if(!s.success&&s.error)throw Je.handleApiError(s.error);return s}getAxiosInstance(){return this.axiosInstance}}class Ot{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 zt{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 Bt{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 _t{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 $t{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 Ht{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 Ut{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 Kt{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 Wt{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"}},Yt={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"}},Vt={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"}}},Qt={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"}},Gt={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"}},Jt={[ve.Default]:Se,[ve.Corporate]:qt,[ve.Fintech]:Yt,[ve.Healthcare]:Vt,[ve.Modern]:Qt,[ve.Minimal]:Gt};function Ze(t){return Jt[t]||Se}class Zt{constructor(r){this.httpClient=r}async getThemeConfiguration(){var r;try{const s=await this.httpClient.get("Tenant","GetThemeConfiguration");if(!s.result.isEnabled)return Ze(ve.Default);let a=s.result.preset?Ze(s.result.preset):Ze(ve.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 d=!o._v||o._v<4;return{...o,fields:(o.fields||[]).map(m=>({...m,colSpan:d?m.colSpan===1?2:4:Math.min(4,Math.max(1,m.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 d=!o._v||o._v<4;return{...o,fields:(o.fields||[]).map(m=>({...m,colSpan:d?m.colSpan===1?2:4:Math.min(4,Math.max(1,m.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),Ze(ve.Default)}}async saveThemeConfiguration(r){await this.httpClient.post("Tenant","SaveThemeConfiguration",r)}getAvailablePresets(){return[{id:ve.Default,name:"Default"},{id:ve.Corporate,name:"Corporate"},{id:ve.Fintech,name:"Fintech"},{id:ve.Healthcare,name:"Healthcare"},{id:ve.Modern,name:"Modern"},{id:ve.Minimal,name:"Minimal"}]}getPreviewTheme(r,s){const a=Ze(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 Xt{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(o){console.error(`Error in event listener for "${r}":`,o)}})}clear(){this.listeners.clear()}clearEvent(r){this.listeners.delete(r)}}class er{constructor(){de(this,"events",new Xt);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)||Ee.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===Ee.Finished}get isOnHold(){return this.status===Ee.OnHold}get isInProgress(){return this.status===Ee.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===Ee.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 tr{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: ${se[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: ${se[r]}`);return a.submitData(s)}}class rr{constructor(r,s,a,n,o,d,m,x){de(this,"state");de(this,"stepRouter");this.applicantService=r,this.questionnaireService=s,this.uploadDocumentService=a,this.appropriatenessTestService=n,this.overviewService=o,this.riskScoringService=d,this.investorCategorizationService=x,this.state=new er,this.stepRouter=new tr,this.registerStepHandlers()}registerStepHandlers(){this.stepRouter.registerHandler(se.Questionaries,{loadData:r=>this.questionnaireService.getQuestionnaire(r),submitData:async r=>{await this.questionnaireService.fillQuestionnaire(r)}}),this.stepRouter.registerHandler(se.UploadDocument,{loadData:r=>this.uploadDocumentService.getUploadDocument(r),submitData:r=>this.uploadDocumentService.fillUploadDocument(r)}),this.stepRouter.registerHandler(se.AppropriatenessTest,{loadData:r=>this.appropriatenessTestService.getAppropriatenessTest(r),submitData:async r=>{await this.appropriatenessTestService.fillAppropriatenessTest(r)}}),this.stepRouter.registerHandler(se.Overview,{loadData:r=>this.overviewService.getOverviewData(r),submitData:r=>this.overviewService.passOverview(r.applicantId)}),this.stepRouter.registerHandler(se.RiskScoring,{loadData:r=>this.riskScoringService.getRiskCriterias(r),submitData:async r=>{await this.riskScoringService.submitRiskScoring(r)}}),this.stepRouter.registerHandler(se.IdentitySdk,{loadData:async r=>({applicantId:r,message:"Identity verification required"}),submitData:async()=>{}}),this.stepRouter.registerHandler(se.InvestorCategorization,{loadData:r=>this.investorCategorizationService.getInvestorCategorization(r),submitData:async r=>{await this.investorCategorizationService.setInvestorCategorization(r)}}),this.stepRouter.registerHandler(se.ManualReview,{loadData:async r=>({applicantId:r,message:"Your application is under manual review"}),submitData:async()=>{}}),this.stepRouter.registerHandler(se.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 ut(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 Br(t){return!!document.getElementById(t)}function _r(t){const r=document.getElementById(t);r&&r.remove()}class sr{constructor(r){de(this,"sdk",null);de(this,"config");this.config=r}async loadSDK(){await ut("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 ar{constructor(r){de(this,"sdk",null);de(this,"config");this.config=r}async loadSDK(){await ut("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 nr{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 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:d}=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:d===!0,region:this.config.region,onDeviceResponse:m=>{console.log(`[SardinAI] Device ID: ${m.deviceId}`)},onConfigUpdate:(m,x,p)=>{switch(m){case"SESSION_UPDATE_FAILED":console.error("[SardinAI] Session update failed:",p);break;case"SESSION_UPDATED":console.log("[SardinAI] Session updated:",x);break;case"SESSION_NO_UPDATE":console.log("[SardinAI] No session update");break;default:console.warn("[SardinAI] Unknown event:",m)}}}),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 qe{static createProvider(r,s){switch(r){case Ce.Sumsub:return new sr(s);case Ce.Onfido:return new ar(s);case Ce.SardinAI:return new nr(s);default:throw new Error(`Unsupported identity provider: ${r}`)}}static parseProviderConfig(r,s,a){var n;switch(r){case Ce.Sumsub:return{accessToken:s.accessToken||s.token,applicantEmail:s.email,applicantPhone:s.phone,externalUserId:s.externalUserId,lang:s.lang||"en"};case Ce.Onfido:return{token:s.token||s.sdkToken};case Ce.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 $r(){return`
2
2
  /* ── metakyc-input-colors (ThemeManager failsafe — same rules as globals.css) ── */
3
3
  .metakyc-sdk input:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="range"]),
4
4
  .metakyc-sdk select,
@@ -29,7 +29,7 @@
29
29
  position: relative !important;
30
30
  z-index: 2 !important;
31
31
  }
32
- `}class ir{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,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=$r(),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}}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=l.createContext(null),Hr=({config:t,children:r})=>{const[s,a]=l.useState(null),n=l.useRef(!1),o=l.useRef(!1),d=l.useMemo(()=>{const x=new Mt(t),p=new Ot(x),w=new zt(x),E=new Bt(x),N=new _t(x),R=new $t(x),f=new Ht(x),j=new Ut(x),L=new Kt(x),F=new Wt(x),$=new Zt(x),P=new ir;return{httpClient:x,applicantService:p,questionnaireService:w,uploadDocumentService:E,appropriatenessTestService:N,overviewService:R,riskScoringService:f,identityService:j,baseInformationService:L,investorCategorizationService:F,themeService:$,themeManager:P}},[t]),m=l.useMemo(()=>({config:t,...d,currentTheme:s,createOrchestrator:()=>new rr(d.applicantService,d.questionnaireService,d.uploadDocumentService,d.appropriatenessTestService,d.overviewService,d.riskScoringService,d.identityService,d.investorCategorizationService)}),[t,d,s]);return l.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"),d.themeManager.applyTheme(t.theme),a(d.themeManager.getCurrentTheme()),o.current=!0;return}console.log("[MetaKYC] Fetching theme from backend...");const p=await d.themeService.getThemeConfiguration();d.themeManager.applyTheme(p),a(d.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(d.themeManager.getCurrentTheme()),o.current=!0}finally{n.current=!1}})(),()=>{d.themeManager.cleanup()}),[]),e.jsx(mt.Provider,{value:m,children:r})};function we(){const t=l.useContext(mt);if(!t)throw new Error("useMetaKYC must be used within a MetaKYCProvider");return t}async function or(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 Ur(t,r){return t.size<=r}function Kr(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 Wr(t){return t}function xe(...t){return t.filter(Boolean).join(" ")}const et={APPLICANT_ID:"metakyc_applicant_id",WORKFLOW_STATE:"metakyc_workflow_state"};function lr(t){try{localStorage.setItem(et.APPLICANT_ID,t.toString())}catch(r){console.warn("Failed to save applicant ID to storage:",r)}}function cr(){try{const t=localStorage.getItem(et.APPLICANT_ID);return t?parseInt(t,10):null}catch(t){return console.warn("Failed to retrieve applicant ID from storage:",t),null}}function dr(){try{localStorage.removeItem(et.APPLICANT_ID)}catch(t){console.warn("Failed to clear applicant ID from storage:",t)}}function ur(t){try{localStorage.setItem(et.WORKFLOW_STATE,JSON.stringify(t))}catch(r){console.warn("Failed to save workflow state to storage:",r)}}function qr(){try{const t=localStorage.getItem(et.WORKFLOW_STATE);return t?JSON.parse(t):null}catch(t){return console.warn("Failed to retrieve workflow state from storage:",t),null}}function mr(){try{localStorage.removeItem(et.WORKFLOW_STATE)}catch(t){console.warn("Failed to clear workflow state from storage:",t)}}function Yr(){dr(),mr()}function pr(t){const{createOrchestrator:r}=we(),[s,a]=l.useState(null),[n,o]=l.useState(!1),[d,m]=l.useState(null),x=l.useRef(null),p=t||cr();l.useEffect(()=>{x.current||(x.current=r())},[r]),l.useEffect(()=>{var P;s&&p&&(lr(p),ur({applicantId:p,currentStepOrder:(P=s.currentStep)==null?void 0:P.order,status:s.status,lastUpdated:new Date().toISOString(),workflowKey:s.workFlowKey,nextWorkflowKey:s.nextWorkflowKey}))},[s,p]);const w=l.useRef(!1),E=l.useRef(!1),N=l.useCallback(async()=>{if(!(!p||!x.current)){if(w.current){console.log("[Workflow] Load already in progress, skipping...");return}w.current=!0,o(!0),m(null);try{const P=await x.current.initialize(p);a(P),E.current=!0}catch(P){m(P)}finally{o(!1),w.current=!1}}},[p]);l.useEffect(()=>{p&&!E.current&&N()},[p,N]);const R=l.useCallback(async()=>{if(x.current){if(w.current){console.log("[Workflow] Refresh already in progress, skipping...");return}w.current=!0,o(!0),m(null);try{const P=await x.current.refreshProgress();a(P)}catch(P){m(P)}finally{o(!1),w.current=!1}}},[]),f=l.useCallback(async()=>{if(x.current){o(!0),m(null);try{const P=await x.current.moveToNextStep();a(P)}catch(P){m(P)}finally{o(!1)}}},[]),j=l.useCallback(async()=>{if(x.current){o(!0),m(null);try{const P=await x.current.moveToPreviousStep();a(P)}catch(P){m(P)}finally{o(!1)}}},[]),L=l.useCallback(async P=>{if(x.current){o(!0),m(null);try{await x.current.submitCurrentStep(P);const M=await x.current.refreshProgress();a(M)}catch(M){throw m(M),M}finally{o(!1)}}},[]),F=ht.useMemo(()=>s!=null&&s.stepInfoList?[...s.stepInfoList].sort((P,M)=>P.order-M.order):[],[s==null?void 0:s.stepInfoList]),$=ht.useMemo(()=>s?s.nextWorkflowKey&&s.nextWorkflowKey!==s.workFlowKey:!1,[s]);return{progress:s,applicantId:p,currentStep:(s==null?void 0:s.currentStep)||null,steps:F,status:(s==null?void 0:s.status)||Ee.None,workflowResult:(s==null?void 0:s.workflowResult)||null,workflowKey:s==null?void 0:s.workFlowKey,nextWorkflowKey:s==null?void 0:s.nextWorkflowKey,hasWorkflowChanged:$,isLoading:n,error:d,isComplete:(s==null?void 0:s.status)===Ee.Finished,isOnHold:(s==null?void 0:s.status)===Ee.OnHold,refreshProgress:R,moveToNext:f,moveBack:j,submitCurrentStep:L,orchestrator:x.current}}function yr(t){const{questionnaireService:r,applicantService:s}=we(),[a,n]=l.useState(null),[o,d]=l.useState({}),[m,x]=l.useState(!1),[p,w]=l.useState(!1),[E,N]=l.useState(null),R=l.useRef(!1),f=l.useRef(null),j=l.useCallback(async()=>{var F,$;if(t){if(R.current){console.log("[Questionnaire] Load already in progress, skipping...");return}R.current=!0,x(!0),N(null);try{const[P,M]=await Promise.all([r.getQuestionnaire(t),s.getApplicantData(t).catch(()=>null)]);if(n(P),(F=M==null?void 0:M.questionnaireResults)!=null&&F.length&&P){const Z=new Map;for(const D of M.questionnaireResults)D.question&&(($=D.answers)!=null&&$.length)&&Z.set(D.question.trim().toLowerCase(),D.answers);const ae={},H=P.questionGroups.flatMap(D=>D.questions??[]);for(const D of H){const W=D.text.trim().toLowerCase();Z.has(W)&&(ae[D.id]=Z.get(W))}d(ae)}f.current=t}catch(P){N(P)}finally{x(!1),R.current=!1}}},[t,r,s]);l.useEffect(()=>{t&&f.current!==t&&j()},[t]);const L=l.useCallback(async F=>{w(!0),N(null);try{return await r.fillQuestionnaire(F)}catch($){throw N($),$}finally{w(!1)}},[r]);return{questionnaire:a,initialAnswers:o,isLoading:m,isSubmitting:p,error:E,load:j,submit:L}}function hr(t){const{uploadDocumentService:r}=we(),[s,a]=l.useState(null),[n,o]=l.useState(!1),[d,m]=l.useState(!1),[x,p]=l.useState(0),[w,E]=l.useState(null),N=l.useRef(!1),R=l.useRef(null),f=l.useCallback(async()=>{if(t){if(N.current){console.log("[UploadDocument] Load already in progress, skipping...");return}N.current=!0,o(!0),E(null);try{const L=await r.getUploadDocument(t);a(L),R.current=t}catch(L){E(L)}finally{o(!1),N.current=!1}}},[t,r]);l.useEffect(()=>{t&&R.current!==t&&f()},[t]);const j=l.useCallback(async L=>{m(!0),p(0),E(null);try{await r.fillUploadDocument(L),p(100)}catch(F){throw E(F),F}finally{m(!1)}},[r]);return{uploadDocument:s,isLoading:n,isSubmitting:d,uploadProgress:x,error:w,load:f,submit:j}}function Vr(t){const{appropriatenessTestService:r}=we(),[s,a]=l.useState(null),[n,o]=l.useState(!1),[d,m]=l.useState(!1),[x,p]=l.useState(null),[w,E]=l.useState(null),N=l.useRef(!1),R=l.useRef(null),f=l.useCallback(async()=>{if(t){if(N.current){console.log("[AppropriatenessTest] Load already in progress, skipping...");return}N.current=!0,o(!0),p(null);try{const L=await r.getAppropriatenessTest(t);a(L),R.current=t}catch(L){p(L)}finally{o(!1),N.current=!1}}},[t,r]);l.useEffect(()=>{t&&R.current!==t&&f()},[t]);const j=l.useCallback(async L=>{m(!0),p(null);try{const F=await r.fillAppropriatenessTest(L);return E(F),F}catch(F){throw p(F),F}finally{m(!1)}},[r]);return{test:s,result:w,isLoading:n,isSubmitting:d,error:x,load:f,submit:j}}function xr(t){const{overviewService:r}=we(),[s,a]=l.useState(null),[n,o]=l.useState(!1),[d,m]=l.useState(!1),[x,p]=l.useState(null),w=l.useRef(!1),E=l.useRef(null),N=l.useCallback(async()=>{if(t){if(w.current){console.log("[Overview] Load already in progress, skipping...");return}w.current=!0,o(!0),p(null);try{const f=await r.getOverviewData(t);a(f),E.current=t}catch(f){p(f)}finally{o(!1),w.current=!1}}},[t,r]);l.useEffect(()=>{t&&E.current!==t&&N()},[t]);const R=l.useCallback(async()=>{if(t){m(!0),p(null);try{await r.passOverview(t)}catch(f){throw p(f),f}finally{m(!1)}}},[t,r]);return{overview:s,isLoading:n,isSubmitting:d,error:x,load:N,passOverview:R}}function fr(t){const{identityService:r}=we(),[s,a]=l.useState(null),[n,o]=l.useState(!1),[d,m]=l.useState(null),x=l.useRef(!1),p=l.useCallback(async(N,R)=>{if(t){if(x.current){console.log("[Identity] Request already in progress, skipping...");return}x.current=!0,o(!0),m(null);try{const f={applicantId:t,restart:!1,redirectUrl:N||"",ttl:R||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 m(f),f}finally{o(!1),x.current=!1}}},[t,r]),w=l.useCallback(async(N,R)=>{if(t){o(!0),m(null);try{const f={applicantId:t,restart:!1,redirectUrl:N,ttl:R},j=await r.identityCompanyRequest(f);return a(j),j}catch(f){throw m(f),f}finally{o(!1)}}},[t,r]),E=l.useCallback(async()=>{if(t){if(x.current){console.log("[Identity] Restart already in progress, skipping...");return}x.current=!0,o(!0),m(null);try{const N={applicantId:t,restart:!0,redirectUrl:"",ttl:604800};console.log("Restarting identity with input:",N);const R=await r.identityRequest(N);return console.log("Restart identity result:",R),a(R),R}catch(N){throw m(N),N}finally{o(!1),x.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:d,requestIdentity:p,requestCompanyIdentity:w,restartIdentity:E}}function gr(t){const{riskScoringService:r,applicantService:s}=we(),[a,n]=l.useState(null),[o,d]=l.useState({}),[m,x]=l.useState(!1),[p,w]=l.useState(!1),[E,N]=l.useState(null),[R,f]=l.useState(null),j=l.useRef(!1),L=l.useRef(null),F=l.useCallback(async()=>{var P;if(t){if(j.current){console.log("[RiskScoring] Load already in progress, skipping...");return}j.current=!0,x(!0),N(null);try{const[M,Z]=await Promise.all([r.getRiskCriterias(t),s.getApplicantData(t).catch(()=>null)]);if(n(M),(P=Z==null?void 0:Z.riskScoringResults)!=null&&P.length){const ae=Z.riskScoringResults[0],H={};for(const D of ae.riskCriteriaResults??[])if(D.riskCriteriaId!=null&&D.answer!=null&&D.answer!==""){const W=[...new Set(D.answer.split(",").map(q=>q.trim()).filter(q=>q!==""))];W.length>0&&(H[D.riskCriteriaId]=W)}d(H)}L.current=t}catch(M){N(M)}finally{x(!1),j.current=!1}}},[t,r,s]);l.useEffect(()=>{t&&L.current!==t&&F()},[t]);const $=l.useCallback(async P=>{w(!0),N(null);try{const M=await r.submitRiskScoring(P);return f(M),M}catch(M){throw N(M),M}finally{w(!1)}},[r]);return{criteria:a,initialAnswers:o,result:R,isLoading:m,isSubmitting:p,error:E,load:F,submit:$}}function pt(){const{applicantService:t,config:r}=we(),[s,a]=l.useState(!1),[n,o]=l.useState(null),d=l.useRef(!1),m=l.useRef(!1),x=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(R){const f=Math.random()*16|0;return(R==="x"?f:f&3|8).toString(16)}),p=l.useCallback(async R=>{var f;if(d.current)throw console.log("[Applicant] Create already in progress, skipping..."),new Error("Creation already in progress");d.current=!0,a(!0),o(null);try{if(R.applicantAdditionalDatas||(R.applicantAdditionalDatas=[]),(f=r.identityProviders)!=null&&f.sardinai){const L=x();console.log("[SardinAI] Generated session key:",L),R.applicantAdditionalDatas.push({paramName:"sessionKey",value:L})}return await t.createApplicant(R)}catch(j){throw o(j),j}finally{a(!1),d.current=!1}},[t,r]),w=l.useCallback(async R=>{a(!0),o(null);try{return await t.createCompanyApplicant(R)}catch(f){throw o(f),f}finally{a(!1)}},[t]),E=l.useCallback(async R=>{if(m.current)throw console.log("[Applicant] Data load already in progress, skipping..."),new Error("Data load already in progress");m.current=!0,a(!0),o(null);try{return await t.getApplicantData(R)}catch(f){throw o(f),f}finally{a(!1),m.current=!1}},[t]),N=l.useCallback(async R=>{a(!0),o(null);try{await t.stopProgress(R)}catch(f){throw o(f),f}finally{a(!1)}},[t]);return{isLoading:s,error:n,createApplicant:p,createCompanyApplicant:w,getApplicantData:E,stopProgress:N}}const Qr={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"}},J=({children:t,variant:r="primary",size:s="md",isLoading:a=!1,disabled:n,className:o,style:d,...m})=>{const x="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:xe(x,p[s],o),style:{...Qr[r],...d},disabled:n||a,...m,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=l.forwardRef(({label:t,error:r,helperText:s,leftIcon:a,rightIcon:n,className:o,style:d,...m},x)=>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,m.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:x,className:xe("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:"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))",...d},...m}),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 V=({children:t,className:r,...s})=>e.jsx("div",{className:xe("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:xe("px-6 py-4 border-b",r),style:{borderColor:"var(--metakyc-border, #e5e7eb)"},...s,children:t}),Q=({children:t,className:r,...s})=>e.jsx("div",{className:xe("px-6 py-4",r),...s,children:t}),he=({children:t,className:r,...s})=>e.jsx("div",{className:xe("px-6 py-4 border-t",r),style:{borderColor:"var(--metakyc-border, #e5e7eb)"},...s,children:t}),Gr={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"}},De=({children:t,variant:r="default",className:s,style:a,...n})=>e.jsx("span",{className:xe("inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium",s),style:{...Gr[r],...a},...n,children:t}),Ne=({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:xe("flex items-center justify-center",r),...s,children:e.jsxs("svg",{className:xe("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=l.forwardRef(({label:t,error:r,helperText:s,options:a,placeholder:n,className:o,style:d,...m},x)=>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,m.required&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),e.jsxs("select",{ref:x,className:xe("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))",...d},...m,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,w)=>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-${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 xt=280,br=({label:t,value:r,onChange:s,options:a,placeholder:n="Select...",disabled:o=!1,required:d=!1})=>{const[m,x]=l.useState(!1),[p,w]=l.useState(""),[E,N]=l.useState(null),[R,f]=l.useState({bg:"#ffffff",borderColor:"#d1d5db",textPrimary:"#111827",textSecondary:"#6b7280",primaryColor:"#2563eb",primaryLight:"#eff6ff",hoverBg:"#f9fafb"}),j=l.useRef(null),L=l.useRef(null),F=l.useRef(null),$=l.useCallback(()=>{if(!L.current)return null;const A=L.current.getBoundingClientRect(),ee=window.innerHeight-A.bottom<xt&&A.top>xt;return{top:ee?A.top:A.bottom+4,left:A.left,width:A.width,openUp:ee}},[]),P=l.useCallback(()=>{const A=getComputedStyle(document.documentElement),U=(pe,oe)=>A.getPropertyValue(pe).trim()||oe,ee=U("--metakyc-input-bg",U("--metakyc-background","#ffffff"));f({bg:ee,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",ee)})},[]),M=l.useCallback(()=>{if(o)return;P();const A=$();A&&N(A),x(!0)},[o,$,P]),Z=l.useCallback(()=>{x(!1),w("")},[]);l.useEffect(()=>{if(!m)return;const A=U=>{var pe,oe;const ee=U.target;!((pe=j.current)!=null&&pe.contains(ee))&&!((oe=F.current)!=null&&oe.contains(ee))&&Z()};return document.addEventListener("mousedown",A),()=>document.removeEventListener("mousedown",A)},[m,Z]),l.useEffect(()=>{if(!m)return;const A=()=>{const U=$();U&&N(U)};return window.addEventListener("scroll",A,!0),window.addEventListener("resize",A),()=>{window.removeEventListener("scroll",A,!0),window.removeEventListener("resize",A)}},[m,$]);const ae=a.filter(A=>A.label.toLowerCase().includes(p.toLowerCase())),H=A=>{o||s(r.includes(A)?r.filter(U=>U!==A):[...r,A])},D=(A,U)=>{U.stopPropagation(),o||s(r.filter(ee=>ee!==A))},W=A=>{var U;return((U=a.find(ee=>ee.value===A))==null?void 0:U.label)||A},{bg:q,borderColor:B,textPrimary:_,textSecondary:O,primaryColor:T,primaryLight:Y,hoverBg:X}=R,ne=m&&E&&e.jsxs("div",{ref:F,className:"metakyc-multiselect-dropdown",style:{position:"fixed",top:E.openUp?void 0:E.top,bottom:E.openUp?window.innerHeight-E.top+4:void 0,left:E.left,width:E.width,zIndex:99999,borderRadius:"8px",boxShadow:"0 4px 16px rgba(0,0,0,0.18)",border:`1px solid ${B}`,backgroundColor:q,overflow:"hidden"},children:[e.jsx("div",{style:{padding:"8px",borderBottom:`1px solid ${B}`},children:e.jsx("input",{type:"text",value:p,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 ${B}`,backgroundColor:q,color:_,outline:"none",boxSizing:"border-box"},onFocus:A=>{const U=getComputedStyle(document.documentElement),ee=U.getPropertyValue("--metakyc-input-border-focus").trim()||U.getPropertyValue("--metakyc-primary").trim()||"#2563eb";A.currentTarget.style.backgroundColor=q,A.currentTarget.style.color=_,A.currentTarget.style.borderColor=ee,A.currentTarget.style.outline="none",A.currentTarget.style.boxShadow=`0 0 0 2px ${ee}33`},onBlur:A=>{A.currentTarget.style.backgroundColor=q,A.currentTarget.style.color=_,A.currentTarget.style.borderColor=B,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:ae.length===0?e.jsx("li",{style:{padding:"8px 12px",fontSize:"13px",color:O},children:"No results"}):ae.map(A=>{const U=r.includes(A.value);return e.jsxs("li",{onClick:()=>H(A.value),className:"metakyc-multiselect-option",style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",fontSize:"13px",cursor:"pointer",backgroundColor:U?Y:"transparent",color:U?T:_,userSelect:"none"},onMouseEnter:ee=>{U||(ee.currentTarget.style.backgroundColor=X)},onMouseLeave:ee=>{U||(ee.currentTarget.style.backgroundColor="transparent")},children:[e.jsx("input",{type:"checkbox",checked:U,readOnly:!0,style:{accentColor:T,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 ${B}`},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,d&&e.jsx("span",{style:{color:"var(--metakyc-error, #ef4444)",marginLeft:"4px"},children:"*"})]}),e.jsxs("div",{ref:L,onClick:()=>m?Z():M(),className:xe("metakyc-multiselect-trigger","min-h-[42px] w-full px-3 py-2 rounded-lg border text-sm transition-colors relative",o?"opacity-50 cursor-not-allowed":"cursor-pointer"),style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",borderColor:m?"var(--metakyc-input-border-focus, var(--metakyc-primary, #2563eb))":"var(--metakyc-input-border, var(--metakyc-border, #d1d5db))",outline:m?"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:[W(A),!o&&e.jsx("button",{type:"button",onClick:U=>D(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:m?"▲":"▼"})]}),typeof document<"u"&&ne?it.createPortal(ne,document.body):null]})},ft=260,Ie=({label:t,error:r,helperText:s,options:a,placeholder:n="Select...",value:o,onChange:d,disabled:m=!1,required:x=!1,className:p})=>{var oe;const[w,E]=l.useState(!1),[N,R]=l.useState(""),[f,j]=l.useState(null),[L,F]=l.useState({bg:"#ffffff",border:"#d1d5db",text:"#111827",textSecondary:"#6b7280",primary:"#2563eb",primaryLight:"#eff6ff",hoverBg:"#f9fafb"}),$=l.useCallback(()=>{const I=getComputedStyle(document.documentElement),G=(le,ke)=>I.getPropertyValue(le).trim()||ke,te=G("--metakyc-input-bg",G("--metakyc-background","#ffffff"));F({bg:te,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",te)})},[]),P=l.useRef(null),M=l.useRef(null),Z=l.useRef(null),ae=l.useRef(null),H=l.useCallback(()=>{if(!M.current)return null;const I=M.current.getBoundingClientRect(),te=window.innerHeight-I.bottom<ft&&I.top>ft;return{top:te?I.top:I.bottom+4,left:I.left,width:I.width,openUp:te}},[]),D=l.useCallback(()=>{if(m)return;$();const I=H();I&&j(I),E(!0)},[m,H,$]),W=l.useCallback(()=>{E(!1),R("")},[]),q=()=>w?W():D();l.useEffect(()=>{if(!w)return;const I=G=>{var le,ke;const te=G.target;!((le=P.current)!=null&&le.contains(te))&&!((ke=Z.current)!=null&&ke.contains(te))&&W()};return document.addEventListener("mousedown",I),()=>document.removeEventListener("mousedown",I)},[w,W]),l.useEffect(()=>{if(!w)return;const I=()=>{const G=H();G&&j(G)};return window.addEventListener("scroll",I,!0),window.addEventListener("resize",I),()=>{window.removeEventListener("scroll",I,!0),window.removeEventListener("resize",I)}},[w,H]),l.useEffect(()=>{w&&ae.current&&setTimeout(()=>{var I;return(I=ae.current)==null?void 0:I.focus()},0)},[w]);const B=a.filter(I=>I.label.toLowerCase().includes(N.toLowerCase())||I.value.toLowerCase().includes(N.toLowerCase())),_=(oe=a.find(I=>I.value===o))==null?void 0:oe.label,O=(I,G)=>{m||G||(d(I),W())},{bg:T,border:Y,text:X,textSecondary:ne,primary:A,primaryLight:U,hoverBg:ee}=L,pe=w&&f&&e.jsxs("div",{ref:Z,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 ${Y}`,backgroundColor:T,overflow:"hidden"},children:[e.jsx("div",{style:{padding:"8px",borderBottom:`1px solid ${Y}`},children:e.jsx("input",{ref:ae,type:"text",value:N,onChange:I=>R(I.target.value),placeholder:"Search...",onClick:I=>I.stopPropagation(),className:"metakyc-searchable-select-search w-full",style:{display:"block",width:"100%",padding:"6px 8px",fontSize:"13px",borderRadius:"6px",border:`1px solid ${Y}`,backgroundColor:T,color:X,outline:"none",boxSizing:"border-box"},onFocus:I=>{const G=getComputedStyle(document.documentElement),te=G.getPropertyValue("--metakyc-input-border-focus").trim()||G.getPropertyValue("--metakyc-primary").trim()||"#2563eb";I.currentTarget.style.backgroundColor=T,I.currentTarget.style.color=X,I.currentTarget.style.borderColor=te,I.currentTarget.style.outline="none",I.currentTarget.style.boxShadow=`0 0 0 2px ${te}33`},onBlur:I=>{I.currentTarget.style.backgroundColor=T,I.currentTarget.style.color=X,I.currentTarget.style.borderColor=Y,I.currentTarget.style.outline="none",I.currentTarget.style.boxShadow="none"}})}),e.jsx("ul",{style:{listStyle:"none",margin:0,padding:"4px 0",maxHeight:"208px",overflowY:"auto"},children:B.length===0?e.jsx("li",{style:{padding:"8px 12px",fontSize:"13px",color:ne},children:"No results"}):B.map(I=>{const G=I.value===o;return e.jsx("li",{className:"metakyc-searchable-select-option",onClick:()=>O(I.value,I.disabled),style:{padding:"8px 12px",fontSize:"13px",cursor:I.disabled?"not-allowed":"pointer",opacity:I.disabled?.4:1,backgroundColor:G?U:"transparent",color:G?A:X,userSelect:"none"},onMouseEnter:te=>{!G&&!I.disabled&&(te.currentTarget.style.backgroundColor=ee)},onMouseLeave:te=>{G||(te.currentTarget.style.backgroundColor="transparent")},children:I.label},I.value)})})]});return e.jsxs("div",{className:xe("w-full metakyc-searchable-select",p),ref:P,children:[t&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[t,x&&e.jsx("span",{style:{color:"var(--metakyc-error, #ef4444)",marginLeft:"4px"},children:"*"})]}),e.jsxs("div",{ref:M,role:"button",tabIndex:m?-1:0,onClick:q,onKeyDown:I=>{(I.key==="Enter"||I.key===" ")&&(I.preventDefault(),q()),I.key==="Escape"&&W()},className:xe("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",m?"opacity-60 cursor-not-allowed":"cursor-pointer"),style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:_?"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:_||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"&&pe?it.createPortal(pe,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})]})};Ie.displayName="SearchableSelect";const vr=({label:t,error:r,accept:s,multiple:a=!1,maxSize:n,onChange:o,value:d=[],className:m})=>{const[x,p]=l.useState(!1),w=l.useRef(null),E=F=>{if(!F)return;const $=Array.from(F);if(n&&$.filter(M=>M.size>n).length>0){const M=nt(n);alert(`Some files exceed the maximum size of ${M}`);return}o==null||o(a?[...d,...$]:[$[0]])},N=F=>{F.preventDefault(),p(!0)},R=()=>{p(!1)},f=F=>{F.preventDefault(),p(!1),E(F.dataTransfer.files)},j=()=>{var F;(F=w.current)==null||F.click()},L=F=>{const $=d.filter((P,M)=>M!==F);o==null||o($)};return e.jsxs("div",{className:xe("w-full",m),children:[t&&e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:t}),e.jsxs("div",{className:xe("border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors",x?"border-primary-500 bg-primary-50 dark:bg-primary-900/20":"border-gray-300 dark:border-gray-600 hover:border-primary-500",r&&"border-danger-500"),onDragOver:N,onDragLeave:R,onDrop:f,onClick:j,children:[e.jsx("input",{ref:w,type:"file",className:"hidden",accept:s,multiple:a,onChange:F=>E(F.target.files)}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("svg",{className:"mx-auto h-12 w-12 text-gray-400",stroke:"currentColor",fill:"none",viewBox:"0 0 48 48",children:e.jsx("path",{d:"M28 8H12a4 4 0 00-4 4v20m32-12v8m0 0v8a4 4 0 01-4 4H12a4 4 0 01-4-4v-4m32-4l-3.172-3.172a4 4 0 00-5.656 0L28 28M8 32l9.172-9.172a4 4 0 015.656 0L28 28m0 0l4 4m4-24h8m-4-4v8m-12 4h.02",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"})}),e.jsxs("div",{className:"text-sm text-gray-600 dark:text-gray-400",children:[e.jsx("span",{className:"font-medium text-primary-500",children:"Click to upload"})," or drag and drop"]}),n&&e.jsxs("p",{className:"text-xs text-gray-500",children:["Maximum file size: ",nt(n)]})]})]}),d.length>0&&e.jsx("div",{className:"mt-3 space-y-2",children:d.map((F,$)=>e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 bg-gray-50 dark:bg-gray-700 rounded-lg",children:[e.jsxs("div",{className:"flex items-center space-x-2 flex-1 min-w-0",children:[e.jsx("svg",{className:"h-5 w-5 text-gray-400 flex-shrink-0",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M4 4a2 2 0 012-2h4.586A2 2 0 0112 2.586L15.414 6A2 2 0 0116 7.414V16a2 2 0 01-2 2H6a2 2 0 01-2-2V4z",clipRule:"evenodd"})}),e.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300 truncate",children:F.name}),e.jsxs("span",{className:"text-xs text-gray-500",children:["(",nt(F.size),")"]})]}),e.jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),L($)},className:"ml-2 text-danger-500 hover:text-danger-700 focus:outline-none",children:e.jsx("svg",{className:"h-5 w-5",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",clipRule:"evenodd"})})})]},$))}),r&&e.jsx("p",{className:"mt-1 text-sm text-danger-500",children:r})]})},kr=l.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:xe("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:xe("flex-1",s),...a,label:""})]}),a.error&&e.jsx("p",{className:"mt-1 text-sm text-danger-500",children:a.error})]}));kr.displayName="PhoneInput";/**
32
+ `}class ir{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,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=$r(),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=l.createContext(null),Hr=({config:t,children:r})=>{const[s,a]=l.useState(null),n=l.useRef(!1),o=l.useRef(!1),d=l.useMemo(()=>{const x=new Mt(t),p=new Ot(x),w=new zt(x),E=new Bt(x),N=new _t(x),R=new $t(x),f=new Ht(x),j=new Ut(x),L=new Kt(x),I=new Wt(x),$=new Zt(x),P=new ir;return{httpClient:x,applicantService:p,questionnaireService:w,uploadDocumentService:E,appropriatenessTestService:N,overviewService:R,riskScoringService:f,identityService:j,baseInformationService:L,investorCategorizationService:I,themeService:$,themeManager:P}},[t]),m=l.useMemo(()=>({config:t,...d,currentTheme:s,createOrchestrator:()=>new rr(d.applicantService,d.questionnaireService,d.uploadDocumentService,d.appropriatenessTestService,d.overviewService,d.riskScoringService,d.identityService,d.investorCategorizationService)}),[t,d,s]);return l.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"),d.themeManager.applyTheme(t.theme),a(d.themeManager.getCurrentTheme()),o.current=!0;return}console.log("[MetaKYC] Fetching theme from backend...");const p=await d.themeService.getThemeConfiguration();d.themeManager.applyTheme(p),a(d.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(d.themeManager.getCurrentTheme()),o.current=!0}finally{n.current=!1}})(),()=>{d.themeManager.cleanup()}),[]),e.jsx(mt.Provider,{value:m,children:r})};function we(){const t=l.useContext(mt);if(!t)throw new Error("useMetaKYC must be used within a MetaKYCProvider");return t}async function or(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 Ur(t,r){return t.size<=r}function Kr(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 Wr(t){return t}function xe(...t){return t.filter(Boolean).join(" ")}const et={APPLICANT_ID:"metakyc_applicant_id",WORKFLOW_STATE:"metakyc_workflow_state"};function lr(t){try{localStorage.setItem(et.APPLICANT_ID,t.toString())}catch(r){console.warn("Failed to save applicant ID to storage:",r)}}function cr(){try{const t=localStorage.getItem(et.APPLICANT_ID);return t?parseInt(t,10):null}catch(t){return console.warn("Failed to retrieve applicant ID from storage:",t),null}}function dr(){try{localStorage.removeItem(et.APPLICANT_ID)}catch(t){console.warn("Failed to clear applicant ID from storage:",t)}}function ur(t){try{localStorage.setItem(et.WORKFLOW_STATE,JSON.stringify(t))}catch(r){console.warn("Failed to save workflow state to storage:",r)}}function qr(){try{const t=localStorage.getItem(et.WORKFLOW_STATE);return t?JSON.parse(t):null}catch(t){return console.warn("Failed to retrieve workflow state from storage:",t),null}}function mr(){try{localStorage.removeItem(et.WORKFLOW_STATE)}catch(t){console.warn("Failed to clear workflow state from storage:",t)}}function Yr(){dr(),mr()}function pr(t){const{createOrchestrator:r}=we(),[s,a]=l.useState(null),[n,o]=l.useState(!1),[d,m]=l.useState(null),x=l.useRef(null),p=t||cr();l.useEffect(()=>{x.current||(x.current=r())},[r]),l.useEffect(()=>{var P;s&&p&&(lr(p),ur({applicantId:p,currentStepOrder:(P=s.currentStep)==null?void 0:P.order,status:s.status,lastUpdated:new Date().toISOString(),workflowKey:s.workFlowKey,nextWorkflowKey:s.nextWorkflowKey}))},[s,p]);const w=l.useRef(!1),E=l.useRef(!1),N=l.useCallback(async()=>{if(!(!p||!x.current)){if(w.current){console.log("[Workflow] Load already in progress, skipping...");return}w.current=!0,o(!0),m(null);try{const P=await x.current.initialize(p);a(P),E.current=!0}catch(P){m(P)}finally{o(!1),w.current=!1}}},[p]);l.useEffect(()=>{p&&!E.current&&N()},[p,N]);const R=l.useCallback(async()=>{if(x.current){if(w.current){console.log("[Workflow] Refresh already in progress, skipping...");return}w.current=!0,o(!0),m(null);try{const P=await x.current.refreshProgress();a(P)}catch(P){m(P)}finally{o(!1),w.current=!1}}},[]),f=l.useCallback(async()=>{if(x.current){o(!0),m(null);try{const P=await x.current.moveToNextStep();a(P)}catch(P){m(P)}finally{o(!1)}}},[]),j=l.useCallback(async()=>{if(x.current){o(!0),m(null);try{const P=await x.current.moveToPreviousStep();a(P)}catch(P){m(P)}finally{o(!1)}}},[]),L=l.useCallback(async P=>{if(x.current){o(!0),m(null);try{await x.current.submitCurrentStep(P);const M=await x.current.refreshProgress();a(M)}catch(M){throw m(M),M}finally{o(!1)}}},[]),I=ht.useMemo(()=>s!=null&&s.stepInfoList?[...s.stepInfoList].sort((P,M)=>P.order-M.order):[],[s==null?void 0:s.stepInfoList]),$=ht.useMemo(()=>s?s.nextWorkflowKey&&s.nextWorkflowKey!==s.workFlowKey:!1,[s]);return{progress:s,applicantId:p,currentStep:(s==null?void 0:s.currentStep)||null,steps:I,status:(s==null?void 0:s.status)||Ee.None,workflowResult:(s==null?void 0:s.workflowResult)||null,workflowKey:s==null?void 0:s.workFlowKey,nextWorkflowKey:s==null?void 0:s.nextWorkflowKey,hasWorkflowChanged:$,isLoading:n,error:d,isComplete:(s==null?void 0:s.status)===Ee.Finished,isOnHold:(s==null?void 0:s.status)===Ee.OnHold,refreshProgress:R,moveToNext:f,moveBack:j,submitCurrentStep:L,orchestrator:x.current}}function yr(t){const{questionnaireService:r,applicantService:s}=we(),[a,n]=l.useState(null),[o,d]=l.useState({}),[m,x]=l.useState(!1),[p,w]=l.useState(!1),[E,N]=l.useState(null),R=l.useRef(!1),f=l.useRef(null),j=l.useCallback(async()=>{var I,$;if(t){if(R.current){console.log("[Questionnaire] Load already in progress, skipping...");return}R.current=!0,x(!0),N(null);try{const[P,M]=await Promise.all([r.getQuestionnaire(t),s.getApplicantData(t).catch(()=>null)]);if(n(P),(I=M==null?void 0:M.questionnaireResults)!=null&&I.length&&P){const Z=new Map;for(const D of M.questionnaireResults)D.question&&(($=D.answers)!=null&&$.length)&&Z.set(D.question.trim().toLowerCase(),D.answers);const ae={},H=P.questionGroups.flatMap(D=>D.questions??[]);for(const D of H){const W=D.text.trim().toLowerCase();Z.has(W)&&(ae[D.id]=Z.get(W))}d(ae)}f.current=t}catch(P){N(P)}finally{x(!1),R.current=!1}}},[t,r,s]);l.useEffect(()=>{t&&f.current!==t&&j()},[t]);const L=l.useCallback(async I=>{w(!0),N(null);try{return await r.fillQuestionnaire(I)}catch($){throw N($),$}finally{w(!1)}},[r]);return{questionnaire:a,initialAnswers:o,isLoading:m,isSubmitting:p,error:E,load:j,submit:L}}function hr(t){const{uploadDocumentService:r}=we(),[s,a]=l.useState(null),[n,o]=l.useState(!1),[d,m]=l.useState(!1),[x,p]=l.useState(0),[w,E]=l.useState(null),N=l.useRef(!1),R=l.useRef(null),f=l.useCallback(async()=>{if(t){if(N.current){console.log("[UploadDocument] Load already in progress, skipping...");return}N.current=!0,o(!0),E(null);try{const L=await r.getUploadDocument(t);a(L),R.current=t}catch(L){E(L)}finally{o(!1),N.current=!1}}},[t,r]);l.useEffect(()=>{t&&R.current!==t&&f()},[t]);const j=l.useCallback(async L=>{m(!0),p(0),E(null);try{await r.fillUploadDocument(L),p(100)}catch(I){throw E(I),I}finally{m(!1)}},[r]);return{uploadDocument:s,isLoading:n,isSubmitting:d,uploadProgress:x,error:w,load:f,submit:j}}function Vr(t){const{appropriatenessTestService:r}=we(),[s,a]=l.useState(null),[n,o]=l.useState(!1),[d,m]=l.useState(!1),[x,p]=l.useState(null),[w,E]=l.useState(null),N=l.useRef(!1),R=l.useRef(null),f=l.useCallback(async()=>{if(t){if(N.current){console.log("[AppropriatenessTest] Load already in progress, skipping...");return}N.current=!0,o(!0),p(null);try{const L=await r.getAppropriatenessTest(t);a(L),R.current=t}catch(L){p(L)}finally{o(!1),N.current=!1}}},[t,r]);l.useEffect(()=>{t&&R.current!==t&&f()},[t]);const j=l.useCallback(async L=>{m(!0),p(null);try{const I=await r.fillAppropriatenessTest(L);return E(I),I}catch(I){throw p(I),I}finally{m(!1)}},[r]);return{test:s,result:w,isLoading:n,isSubmitting:d,error:x,load:f,submit:j}}function xr(t){const{overviewService:r}=we(),[s,a]=l.useState(null),[n,o]=l.useState(!1),[d,m]=l.useState(!1),[x,p]=l.useState(null),w=l.useRef(!1),E=l.useRef(null),N=l.useCallback(async()=>{if(t){if(w.current){console.log("[Overview] Load already in progress, skipping...");return}w.current=!0,o(!0),p(null);try{const f=await r.getOverviewData(t);a(f),E.current=t}catch(f){p(f)}finally{o(!1),w.current=!1}}},[t,r]);l.useEffect(()=>{t&&E.current!==t&&N()},[t]);const R=l.useCallback(async()=>{if(t){m(!0),p(null);try{await r.passOverview(t)}catch(f){throw p(f),f}finally{m(!1)}}},[t,r]);return{overview:s,isLoading:n,isSubmitting:d,error:x,load:N,passOverview:R}}function fr(t){const{identityService:r}=we(),[s,a]=l.useState(null),[n,o]=l.useState(!1),[d,m]=l.useState(null),x=l.useRef(!1),p=l.useCallback(async(N,R)=>{if(t){if(x.current){console.log("[Identity] Request already in progress, skipping...");return}x.current=!0,o(!0),m(null);try{const f={applicantId:t,restart:!1,redirectUrl:N||"",ttl:R||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 m(f),f}finally{o(!1),x.current=!1}}},[t,r]),w=l.useCallback(async(N,R)=>{if(t){o(!0),m(null);try{const f={applicantId:t,restart:!1,redirectUrl:N,ttl:R},j=await r.identityCompanyRequest(f);return a(j),j}catch(f){throw m(f),f}finally{o(!1)}}},[t,r]),E=l.useCallback(async()=>{if(t){if(x.current){console.log("[Identity] Restart already in progress, skipping...");return}x.current=!0,o(!0),m(null);try{const N={applicantId:t,restart:!0,redirectUrl:"",ttl:604800};console.log("Restarting identity with input:",N);const R=await r.identityRequest(N);return console.log("Restart identity result:",R),a(R),R}catch(N){throw m(N),N}finally{o(!1),x.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:d,requestIdentity:p,requestCompanyIdentity:w,restartIdentity:E}}function gr(t){const{riskScoringService:r,applicantService:s}=we(),[a,n]=l.useState(null),[o,d]=l.useState({}),[m,x]=l.useState(!1),[p,w]=l.useState(!1),[E,N]=l.useState(null),[R,f]=l.useState(null),j=l.useRef(!1),L=l.useRef(null),I=l.useCallback(async()=>{var P;if(t){if(j.current){console.log("[RiskScoring] Load already in progress, skipping...");return}j.current=!0,x(!0),N(null);try{const[M,Z]=await Promise.all([r.getRiskCriterias(t),s.getApplicantData(t).catch(()=>null)]);if(n(M),(P=Z==null?void 0:Z.riskScoringResults)!=null&&P.length){const ae=Z.riskScoringResults[0],H={};for(const D of ae.riskCriteriaResults??[])if(D.riskCriteriaId!=null&&D.answer!=null&&D.answer!==""){const W=[...new Set(D.answer.split(",").map(q=>q.trim()).filter(q=>q!==""))];W.length>0&&(H[D.riskCriteriaId]=W)}d(H)}L.current=t}catch(M){N(M)}finally{x(!1),j.current=!1}}},[t,r,s]);l.useEffect(()=>{t&&L.current!==t&&I()},[t]);const $=l.useCallback(async P=>{w(!0),N(null);try{const M=await r.submitRiskScoring(P);return f(M),M}catch(M){throw N(M),M}finally{w(!1)}},[r]);return{criteria:a,initialAnswers:o,result:R,isLoading:m,isSubmitting:p,error:E,load:I,submit:$}}function pt(){const{applicantService:t,config:r}=we(),[s,a]=l.useState(!1),[n,o]=l.useState(null),d=l.useRef(!1),m=l.useRef(!1),x=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(R){const f=Math.random()*16|0;return(R==="x"?f:f&3|8).toString(16)}),p=l.useCallback(async R=>{var f;if(d.current)throw console.log("[Applicant] Create already in progress, skipping..."),new Error("Creation already in progress");d.current=!0,a(!0),o(null);try{if(R.applicantAdditionalDatas||(R.applicantAdditionalDatas=[]),(f=r.identityProviders)!=null&&f.sardinai){const L=x();console.log("[SardinAI] Generated session key:",L),R.applicantAdditionalDatas.push({paramName:"sessionKey",value:L})}return await t.createApplicant(R)}catch(j){throw o(j),j}finally{a(!1),d.current=!1}},[t,r]),w=l.useCallback(async R=>{a(!0),o(null);try{return await t.createCompanyApplicant(R)}catch(f){throw o(f),f}finally{a(!1)}},[t]),E=l.useCallback(async R=>{if(m.current)throw console.log("[Applicant] Data load already in progress, skipping..."),new Error("Data load already in progress");m.current=!0,a(!0),o(null);try{return await t.getApplicantData(R)}catch(f){throw o(f),f}finally{a(!1),m.current=!1}},[t]),N=l.useCallback(async R=>{a(!0),o(null);try{await t.stopProgress(R)}catch(f){throw o(f),f}finally{a(!1)}},[t]);return{isLoading:s,error:n,createApplicant:p,createCompanyApplicant:w,getApplicantData:E,stopProgress:N}}const Qr={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"}},J=({children:t,variant:r="primary",size:s="md",isLoading:a=!1,disabled:n,className:o,style:d,...m})=>{const x="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:xe(x,p[s],o),style:{...Qr[r],...d},disabled:n||a,...m,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=l.forwardRef(({label:t,error:r,helperText:s,leftIcon:a,rightIcon:n,className:o,style:d,...m},x)=>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,m.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:x,className:xe("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:"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))",...d},...m}),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 V=({children:t,className:r,...s})=>e.jsx("div",{className:xe("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:xe("px-6 py-4 border-b",r),style:{borderColor:"var(--metakyc-border, #e5e7eb)"},...s,children:t}),Q=({children:t,className:r,...s})=>e.jsx("div",{className:xe("px-6 py-4",r),...s,children:t}),he=({children:t,className:r,...s})=>e.jsx("div",{className:xe("px-6 py-4 border-t",r),style:{borderColor:"var(--metakyc-border, #e5e7eb)"},...s,children:t}),Gr={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"}},De=({children:t,variant:r="default",className:s,style:a,...n})=>e.jsx("span",{className:xe("inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium",s),style:{...Gr[r],...a},...n,children:t}),Ne=({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:xe("flex items-center justify-center",r),...s,children:e.jsxs("svg",{className:xe("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=l.forwardRef(({label:t,error:r,helperText:s,options:a,placeholder:n,className:o,style:d,...m},x)=>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,m.required&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),e.jsxs("select",{ref:x,className:xe("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))",...d},...m,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,w)=>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-${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 xt=280,br=({label:t,value:r,onChange:s,options:a,placeholder:n="Select...",disabled:o=!1,required:d=!1})=>{const[m,x]=l.useState(!1),[p,w]=l.useState(""),[E,N]=l.useState(null),[R,f]=l.useState({bg:"#ffffff",borderColor:"#d1d5db",textPrimary:"#111827",textSecondary:"#6b7280",primaryColor:"#2563eb",primaryLight:"#eff6ff",hoverBg:"#f9fafb"}),j=l.useRef(null),L=l.useRef(null),I=l.useRef(null),$=l.useCallback(()=>{if(!L.current)return null;const A=L.current.getBoundingClientRect(),ee=window.innerHeight-A.bottom<xt&&A.top>xt;return{top:ee?A.top:A.bottom+4,left:A.left,width:A.width,openUp:ee}},[]),P=l.useCallback(()=>{const A=getComputedStyle(document.documentElement),U=(pe,oe)=>A.getPropertyValue(pe).trim()||oe,ee=U("--metakyc-input-bg",U("--metakyc-background","#ffffff"));f({bg:ee,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",ee)})},[]),M=l.useCallback(()=>{if(o)return;P();const A=$();A&&N(A),x(!0)},[o,$,P]),Z=l.useCallback(()=>{x(!1),w("")},[]);l.useEffect(()=>{if(!m)return;const A=U=>{var pe,oe;const ee=U.target;!((pe=j.current)!=null&&pe.contains(ee))&&!((oe=I.current)!=null&&oe.contains(ee))&&Z()};return document.addEventListener("mousedown",A),()=>document.removeEventListener("mousedown",A)},[m,Z]),l.useEffect(()=>{if(!m)return;const A=()=>{const U=$();U&&N(U)};return window.addEventListener("scroll",A,!0),window.addEventListener("resize",A),()=>{window.removeEventListener("scroll",A,!0),window.removeEventListener("resize",A)}},[m,$]);const ae=a.filter(A=>A.label.toLowerCase().includes(p.toLowerCase())),H=A=>{o||s(r.includes(A)?r.filter(U=>U!==A):[...r,A])},D=(A,U)=>{U.stopPropagation(),o||s(r.filter(ee=>ee!==A))},W=A=>{var U;return((U=a.find(ee=>ee.value===A))==null?void 0:U.label)||A},{bg:q,borderColor:B,textPrimary:_,textSecondary:O,primaryColor:T,primaryLight:Y,hoverBg:X}=R,ne=m&&E&&e.jsxs("div",{ref:I,className:"metakyc-multiselect-dropdown",style:{position:"fixed",top:E.openUp?void 0:E.top,bottom:E.openUp?window.innerHeight-E.top+4:void 0,left:E.left,width:E.width,zIndex:99999,borderRadius:"8px",boxShadow:"0 4px 16px rgba(0,0,0,0.18)",border:`1px solid ${B}`,backgroundColor:q,overflow:"hidden"},children:[e.jsx("div",{style:{padding:"8px",borderBottom:`1px solid ${B}`},children:e.jsx("input",{type:"text",value:p,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 ${B}`,backgroundColor:q,color:_,outline:"none",boxSizing:"border-box"},onFocus:A=>{const U=getComputedStyle(document.documentElement),ee=U.getPropertyValue("--metakyc-input-border-focus").trim()||U.getPropertyValue("--metakyc-primary").trim()||"#2563eb";A.currentTarget.style.backgroundColor=q,A.currentTarget.style.color=_,A.currentTarget.style.borderColor=ee,A.currentTarget.style.outline="none",A.currentTarget.style.boxShadow=`0 0 0 2px ${ee}33`},onBlur:A=>{A.currentTarget.style.backgroundColor=q,A.currentTarget.style.color=_,A.currentTarget.style.borderColor=B,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:ae.length===0?e.jsx("li",{style:{padding:"8px 12px",fontSize:"13px",color:O},children:"No results"}):ae.map(A=>{const U=r.includes(A.value);return e.jsxs("li",{onClick:()=>H(A.value),className:"metakyc-multiselect-option",style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",fontSize:"13px",cursor:"pointer",backgroundColor:U?Y:"transparent",color:U?T:_,userSelect:"none"},onMouseEnter:ee=>{U||(ee.currentTarget.style.backgroundColor=X)},onMouseLeave:ee=>{U||(ee.currentTarget.style.backgroundColor="transparent")},children:[e.jsx("input",{type:"checkbox",checked:U,readOnly:!0,style:{accentColor:T,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 ${B}`},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,d&&e.jsx("span",{style:{color:"var(--metakyc-error, #ef4444)",marginLeft:"4px"},children:"*"})]}),e.jsxs("div",{ref:L,onClick:()=>m?Z():M(),className:xe("metakyc-multiselect-trigger","min-h-[42px] w-full px-3 py-2 rounded-lg border text-sm transition-colors relative",o?"opacity-50 cursor-not-allowed":"cursor-pointer"),style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",borderColor:m?"var(--metakyc-input-border-focus, var(--metakyc-primary, #2563eb))":"var(--metakyc-input-border, var(--metakyc-border, #d1d5db))",outline:m?"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:[W(A),!o&&e.jsx("button",{type:"button",onClick:U=>D(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:m?"▲":"▼"})]}),typeof document<"u"&&ne?it.createPortal(ne,document.body):null]})},ft=260,Fe=({label:t,error:r,helperText:s,options:a,placeholder:n="Select...",value:o,onChange:d,disabled:m=!1,required:x=!1,className:p})=>{var oe;const[w,E]=l.useState(!1),[N,R]=l.useState(""),[f,j]=l.useState(null),[L,I]=l.useState({bg:"#ffffff",border:"#d1d5db",text:"#111827",textSecondary:"#6b7280",primary:"#2563eb",primaryLight:"#eff6ff",hoverBg:"#f9fafb"}),$=l.useCallback(()=>{const F=getComputedStyle(document.documentElement),G=(le,ke)=>F.getPropertyValue(le).trim()||ke,te=G("--metakyc-input-bg",G("--metakyc-background","#ffffff"));I({bg:te,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",te)})},[]),P=l.useRef(null),M=l.useRef(null),Z=l.useRef(null),ae=l.useRef(null),H=l.useCallback(()=>{if(!M.current)return null;const F=M.current.getBoundingClientRect(),te=window.innerHeight-F.bottom<ft&&F.top>ft;return{top:te?F.top:F.bottom+4,left:F.left,width:F.width,openUp:te}},[]),D=l.useCallback(()=>{if(m)return;$();const F=H();F&&j(F),E(!0)},[m,H,$]),W=l.useCallback(()=>{E(!1),R("")},[]),q=()=>w?W():D();l.useEffect(()=>{if(!w)return;const F=G=>{var le,ke;const te=G.target;!((le=P.current)!=null&&le.contains(te))&&!((ke=Z.current)!=null&&ke.contains(te))&&W()};return document.addEventListener("mousedown",F),()=>document.removeEventListener("mousedown",F)},[w,W]),l.useEffect(()=>{if(!w)return;const F=()=>{const G=H();G&&j(G)};return window.addEventListener("scroll",F,!0),window.addEventListener("resize",F),()=>{window.removeEventListener("scroll",F,!0),window.removeEventListener("resize",F)}},[w,H]),l.useEffect(()=>{w&&ae.current&&setTimeout(()=>{var F;return(F=ae.current)==null?void 0:F.focus()},0)},[w]);const B=a.filter(F=>F.label.toLowerCase().includes(N.toLowerCase())||F.value.toLowerCase().includes(N.toLowerCase())),_=(oe=a.find(F=>F.value===o))==null?void 0:oe.label,O=(F,G)=>{m||G||(d(F),W())},{bg:T,border:Y,text:X,textSecondary:ne,primary:A,primaryLight:U,hoverBg:ee}=L,pe=w&&f&&e.jsxs("div",{ref:Z,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 ${Y}`,backgroundColor:T,overflow:"hidden"},children:[e.jsx("div",{style:{padding:"8px",borderBottom:`1px solid ${Y}`},children:e.jsx("input",{ref:ae,type:"text",value:N,onChange:F=>R(F.target.value),placeholder:"Search...",onClick:F=>F.stopPropagation(),className:"metakyc-searchable-select-search w-full",style:{display:"block",width:"100%",padding:"6px 8px",fontSize:"13px",borderRadius:"6px",border:`1px solid ${Y}`,backgroundColor:T,color:X,outline:"none",boxSizing:"border-box"},onFocus:F=>{const G=getComputedStyle(document.documentElement),te=G.getPropertyValue("--metakyc-input-border-focus").trim()||G.getPropertyValue("--metakyc-primary").trim()||"#2563eb";F.currentTarget.style.backgroundColor=T,F.currentTarget.style.color=X,F.currentTarget.style.borderColor=te,F.currentTarget.style.outline="none",F.currentTarget.style.boxShadow=`0 0 0 2px ${te}33`},onBlur:F=>{F.currentTarget.style.backgroundColor=T,F.currentTarget.style.color=X,F.currentTarget.style.borderColor=Y,F.currentTarget.style.outline="none",F.currentTarget.style.boxShadow="none"}})}),e.jsx("ul",{style:{listStyle:"none",margin:0,padding:"4px 0",maxHeight:"208px",overflowY:"auto"},children:B.length===0?e.jsx("li",{style:{padding:"8px 12px",fontSize:"13px",color:ne},children:"No results"}):B.map(F=>{const G=F.value===o;return e.jsx("li",{className:"metakyc-searchable-select-option",onClick:()=>O(F.value,F.disabled),style:{padding:"8px 12px",fontSize:"13px",cursor:F.disabled?"not-allowed":"pointer",opacity:F.disabled?.4:1,backgroundColor:G?U:"transparent",color:G?A:X,userSelect:"none"},onMouseEnter:te=>{!G&&!F.disabled&&(te.currentTarget.style.backgroundColor=ee)},onMouseLeave:te=>{G||(te.currentTarget.style.backgroundColor="transparent")},children:F.label},F.value)})})]});return e.jsxs("div",{className:xe("w-full metakyc-searchable-select",p),ref:P,children:[t&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[t,x&&e.jsx("span",{style:{color:"var(--metakyc-error, #ef4444)",marginLeft:"4px"},children:"*"})]}),e.jsxs("div",{ref:M,role:"button",tabIndex:m?-1:0,onClick:q,onKeyDown:F=>{(F.key==="Enter"||F.key===" ")&&(F.preventDefault(),q()),F.key==="Escape"&&W()},className:xe("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",m?"opacity-60 cursor-not-allowed":"cursor-pointer"),style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:_?"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:_||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"&&pe?it.createPortal(pe,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})]})};Fe.displayName="SearchableSelect";const vr=({label:t,error:r,accept:s,multiple:a=!1,maxSize:n,onChange:o,value:d=[],className:m})=>{const[x,p]=l.useState(!1),w=l.useRef(null),E=I=>{if(!I)return;const $=Array.from(I);if(n&&$.filter(M=>M.size>n).length>0){const M=nt(n);alert(`Some files exceed the maximum size of ${M}`);return}o==null||o(a?[...d,...$]:[$[0]])},N=I=>{I.preventDefault(),p(!0)},R=()=>{p(!1)},f=I=>{I.preventDefault(),p(!1),E(I.dataTransfer.files)},j=()=>{var I;(I=w.current)==null||I.click()},L=I=>{const $=d.filter((P,M)=>M!==I);o==null||o($)};return e.jsxs("div",{className:xe("w-full",m),children:[t&&e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:t}),e.jsxs("div",{className:xe("border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors",x?"border-primary-500 bg-primary-50 dark:bg-primary-900/20":"border-gray-300 dark:border-gray-600 hover:border-primary-500",r&&"border-danger-500"),onDragOver:N,onDragLeave:R,onDrop:f,onClick:j,children:[e.jsx("input",{ref:w,type:"file",className:"hidden",accept:s,multiple:a,onChange:I=>E(I.target.files)}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("svg",{className:"mx-auto h-12 w-12 text-gray-400",stroke:"currentColor",fill:"none",viewBox:"0 0 48 48",children:e.jsx("path",{d:"M28 8H12a4 4 0 00-4 4v20m32-12v8m0 0v8a4 4 0 01-4 4H12a4 4 0 01-4-4v-4m32-4l-3.172-3.172a4 4 0 00-5.656 0L28 28M8 32l9.172-9.172a4 4 0 015.656 0L28 28m0 0l4 4m4-24h8m-4-4v8m-12 4h.02",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"})}),e.jsxs("div",{className:"text-sm text-gray-600 dark:text-gray-400",children:[e.jsx("span",{className:"font-medium text-primary-500",children:"Click to upload"})," or drag and drop"]}),n&&e.jsxs("p",{className:"text-xs text-gray-500",children:["Maximum file size: ",nt(n)]})]})]}),d.length>0&&e.jsx("div",{className:"mt-3 space-y-2",children:d.map((I,$)=>e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 bg-gray-50 dark:bg-gray-700 rounded-lg",children:[e.jsxs("div",{className:"flex items-center space-x-2 flex-1 min-w-0",children:[e.jsx("svg",{className:"h-5 w-5 text-gray-400 flex-shrink-0",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M4 4a2 2 0 012-2h4.586A2 2 0 0112 2.586L15.414 6A2 2 0 0116 7.414V16a2 2 0 01-2 2H6a2 2 0 01-2-2V4z",clipRule:"evenodd"})}),e.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300 truncate",children:I.name}),e.jsxs("span",{className:"text-xs text-gray-500",children:["(",nt(I.size),")"]})]}),e.jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),L($)},className:"ml-2 text-danger-500 hover:text-danger-700 focus:outline-none",children:e.jsx("svg",{className:"h-5 w-5",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",clipRule:"evenodd"})})})]},$))}),r&&e.jsx("p",{className:"mt-1 text-sm text-danger-500",children:r})]})},kr=l.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:xe("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:xe("flex-1",s),...a,label:""})]}),a.error&&e.jsx("p",{className:"mt-1 text-sm text-danger-500",children:a.error})]}));kr.displayName="PhoneInput";/**
33
33
  * @license lucide-react v0.574.0 - ISC
34
34
  *
35
35
  * This source code is licensed under the ISC license.
@@ -79,10 +79,10 @@
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 ss=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],Nr=wr("chevron-right",ss);function as(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 ns(t){const r=t.flatMap((a,n)=>(a.questions??[]).map((o,d)=>({question:o,groupIndex:n,qIdx:d}))),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 Cr=({applicantId:t,onComplete:r,onBack:s})=>{const{questionnaire:a,initialAnswers:n,isLoading:o,isSubmitting:d,error:m,submit:x}=yr(t),[p,w]=l.useState({}),[E,N]=l.useState({}),[R,f]=l.useState(0);l.useEffect(()=>{n&&Object.keys(n).length>0&&Object.keys(p).length===0&&w(n)},[n]);const j=l.useMemo(()=>a?ns(a.questionGroups):[],[a]),L=R===j.length-1,F=j[R]??[],$=l.useCallback((H,D)=>{w(W=>({...W,[H]:D})),N(W=>{const q={...W};return delete q[H],q})},[]),P=l.useCallback(()=>{const H={};for(const{question:D}of F){const W=as(D,p[D.id]??[]);W&&(H[D.id]=W)}return N(D=>({...D,...H})),Object.keys(H).length===0},[F,p]),M=()=>{P()&&f(H=>H+1)},Z=()=>{R>0?f(H=>H-1):s==null||s()},ae=async()=>{if(!(!P()||!a))try{const H=a.questionGroups.flatMap(W=>(W.questions??[]).map(q=>({questionId:q.id,values:p[q.id]??[]}))),D={applicantId:t,questionnarieId:a.id,questionResults:H};await x(D),r==null||r()}catch(H){console.error("Questionnaire submit error:",H)}};return o?e.jsx(V,{children:e.jsx(Q,{children:e.jsx(Ne,{className:"my-8"})})}):m?e.jsx(V,{children:e.jsx(Q,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading questionnaire: ",m.message]})})}):a?e.jsxs(V,{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 ",R+1," of ",j.length]}),e.jsx("div",{className:"flex items-center gap-1.5",children:j.map((H,D)=>e.jsx("div",{className:"rounded-full transition-all duration-200",style:{height:"6px",width:D===R?"20px":"6px",backgroundColor:D<=R?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},D))})]})]}),e.jsx(Q,{className:"space-y-6",children:F.map(({question:H})=>e.jsx(is,{question:H,value:p[H.id]??[],error:E[H.id],onChange:D=>$(H.id,D)},H.id))}),e.jsxs(he,{className:"flex items-center justify-between",children:[e.jsxs(J,{type:"button",variant:"outline",onClick:Z,style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(Sr,{size:14}),R>0?"Previous":"Back"]}),L?e.jsx(J,{type:"button",isLoading:d,onClick:ae,children:"Continue"}):e.jsxs(J,{type:"button",onClick:M,style:{display:"flex",alignItems:"center",gap:"4px"},children:["Next",e.jsx(Nr,{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},is=({question:t,value:r,error:s,onChange:a})=>{var d;const o=(((d=t.defaultAnswers)==null?void 0:d.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(me,{value:r[0]??"",onChange:m=>a([m.target.value]),placeholder:t.subtitle?void 0:"Enter your answer…",error:s,required:t.isRequired}),o==="single-select"&&e.jsx(ot,{value:r[0]??"",onChange:m=>a([m.target.value]),options:(t.defaultAnswers??[]).map(m=>({value:m,label:m})),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(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:()=>a([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:m})]},m)),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(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:x=>{x.target.checked?a([...r,m]):a(r.filter(p=>p!==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:m})]},m)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),s&&o==="text"&&null]})},Er=({applicantId:t,onComplete:r,onBack:s})=>{const{uploadDocument:a,isLoading:n,isSubmitting:o,error:d,submit:m}=hr(t),[x,p]=l.useState({}),w=async E=>{if(E.preventDefault(),!a)return;const N=await Promise.all(a.uploadDocumentFiles.map(async f=>{const j=x[f.id]||[],L=await Promise.all(j.map(async F=>({fileName:F.name,fileData:await or(F)})));return{uploadDocumentFileId:f.id,valueList:L}})),R={applicantId:t,uploadDocumentId:a.id,uploadDocumentResults:N};await m(R),r==null||r()};return n?e.jsx(V,{children:e.jsx(Q,{children:e.jsx(Ne,{className:"my-8"})})}):d?e.jsx(V,{children:e.jsx(Q,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading document requirements: ",d.message]})})}):a?e.jsx("form",{onSubmit:w,children:e.jsxs(V,{children:[e.jsxs(ye,{children:[e.jsx("h2",{className:"text-lg font-bold",children:a.displayName}),a.subtitle&&e.jsx("p",{className:"mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:a.subtitle})]}),e.jsx(Q,{className:"space-y-6",children:a.uploadDocumentFiles.map(E=>e.jsx(vr,{label:E.displayName,accept:E.allowedTypes,multiple:E.multipleFile,maxSize:E.maxEachFileSizeByte,value:x[E.id]||[],onChange:N=>{p(R=>({...R,[E.id]:N}))}},E.id))}),e.jsxs(he,{className:"flex justify-between",children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"submit",isLoading:o,children:"Continue"})]})]})}):null},Rr=({applicantId:t,onComplete:r,onBack:s})=>{const{overview:a,isLoading:n,isSubmitting:o,error:d,passOverview:m}=xr(t),x=async()=>{await m(),r==null||r()};return n?e.jsx(V,{children:e.jsx(Q,{children:e.jsx(Ne,{className:"my-8"})})}):d?e.jsx(V,{children:e.jsx(Q,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading overview: ",d.message]})})}):a?e.jsxs(V,{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(Q,{className:"space-y-8",children:a.steps&&a.steps.length>0?a.steps.sort((p,w)=>p.order-w.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(he,{className:"flex justify-between",children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{onClick:x,isLoading:o,children:"Continue"})]})]}):null};function os(t){const r=(t??"en").toLowerCase().replace("_","-");try{return Intl.NumberFormat.supportedLocalesOf([r]),r}catch{return"en"}}function ls(t){return t.valueDataType===Ae.Money&&Array.isArray(t.defaultValues)&&t.defaultValues.length>0}function cs(t,r){const s=new Intl.NumberFormat(os(r),{minimumFractionDigits:0,maximumFractionDigits:2});return t.replace(/([\d]+(?:\.\d+)?)/g,a=>{const n=parseFloat(a);return isNaN(n)?a:s.format(n)})}function ds(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===Ae.Integer||t.valueDataType===Ae.Money||t.valueDataType===Ae.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 us(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 ms(t){return t.builtInType===1?"country":!t.defaultValues||t.defaultValues.length===0?"text":t.multipleValue?"checkbox":"radio"}const Ar=({applicantId:t,onComplete:r,onBack:s})=>{const{config:a}=we(),n=a.locale??"en",{criteria:o,initialAnswers:d,isLoading:m,isSubmitting:x,error:p,submit:w}=gr(t),[E,N]=l.useState({}),[R,f]=l.useState({}),[j,L]=l.useState(0),[F,$]=l.useState(!1);l.useEffect(()=>{d&&Object.keys(d).length>0&&Object.keys(E).length===0&&N(d)},[d]);const P=l.useMemo(()=>o&&o.length>0?us(o):[],[o]),M=j===P.length-1,Z=P[j]??[];l.useEffect(()=>{!m&&o&&o.length===0&&!F&&!x&&($(!0),w({applicantId:t,criteriaValueInputs:[]}).then(()=>r==null?void 0:r()).catch(console.error))},[m,o,F,x,w,t,r]);const ae=l.useCallback((B,_)=>{N(O=>({...O,[B]:_})),f(O=>{const T={...O};return delete T[B],T})},[]),H=l.useCallback(()=>{const B={};for(const{criterion:_}of Z){const O=ds(_,E[_.id]??[]);O&&(B[_.id]=O)}return f(_=>({..._,...B})),Object.keys(B).length===0},[Z,E]),D=()=>{H()&&L(B=>B+1)},W=()=>{j>0?L(B=>B-1):s==null||s()},q=async()=>{if(!(!H()||!o))try{const B=o.map(O=>{const T=(E[O.id]??[]).filter(Y=>Y&&Y.trim());return T.length>0?{riskCriteriaId:O.id,values:T}:null}).filter(O=>O!==null);await w({applicantId:t,criteriaValueInputs:B}),r==null||r()}catch(B){console.error("Risk scoring submit error:",B)}};return m?e.jsx(V,{children:e.jsxs(Q,{children:[e.jsx(Ne,{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…"})]})}):!m&&o&&o.length===0?e.jsx(V,{children:e.jsxs(Q,{children:[e.jsx(Ne,{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(V,{children:e.jsx(Q,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading criteria: ",p.message]})})}):o?e.jsxs(V,{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"}),P.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 ",P.length]}),e.jsx("div",{className:"flex items-center gap-1.5",children:P.map((B,_)=>e.jsx("div",{className:"rounded-full transition-all duration-200",style:{height:"6px",width:_===j?"20px":"6px",backgroundColor:_<=j?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},_))})]})]}),e.jsx(Q,{className:"space-y-6",children:Z.map(({criterion:B})=>e.jsx(ps,{criterion:B,value:E[B.id]??[],error:R[B.id],locale:n,onChange:_=>ae(B.id,_)},B.id))}),e.jsxs(he,{className:"flex items-center justify-between",children:[e.jsxs(J,{type:"button",variant:"outline",onClick:W,style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(Sr,{size:14}),j>0?"Previous":"Back"]}),M?e.jsx(J,{type:"button",isLoading:x,onClick:q,children:"Continue"}):e.jsxs(J,{type:"button",onClick:D,style:{display:"flex",alignItems:"center",gap:"4px"},children:["Next",e.jsx(Nr,{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},ps=({criterion:t,value:r,error:s,locale:a,onChange:n})=>{const o=ms(t),d=t.valueDataType===Ae.Integer||t.valueDataType===Ae.Money||t.valueDataType===Ae.DigitOnly,m=ls(t),x=p=>m?cs(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}),d&&(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(me,{value:r[0]??"",onChange:p=>n([p.target.value]),type:d?"number":"text",placeholder:"Enter your answer…",error:s,required:t.isRequired,min:t.min,max:t.max,onKeyDown:p=>{t.valueDataType===Ae.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:x(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:w=>{w.target.checked?n([...r,p]):n(r.filter(E=>E!==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:x(p)})]},p)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),o==="country"&&e.jsx(ot,{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})]})},Ir=({applicantId:t,onComplete:r,onBack:s})=>{const{investorCategorizationService:a}=we(),[n,o]=l.useState(null),[d,m]=l.useState(!1),[x,p]=l.useState(null),w=async E=>{if(E.preventDefault(),n===null){p("Please select an investor type");return}m(!0),p(null);try{const N={applicantId:t,investorType:n};console.log("Submitting investor categorization:",N);const R=await a.setInvestorCategorization(N);console.log("Investor categorization result:",R),r==null||r()}catch(N){console.error("Error submitting investor categorization:",N),p(N.message||"Failed to submit investor categorization")}finally{m(!1)}};return e.jsx("form",{onSubmit:w,children:e.jsxs(V,{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(Q,{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===be.Individual?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:n===be.Individual?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:be.Individual,checked:n===be.Individual,onChange:()=>o(be.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===be.Sophisticated?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:n===be.Sophisticated?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:be.Sophisticated,checked:n===be.Sophisticated,onChange:()=>o(be.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===be.HighNetWorth?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:n===be.HighNetWorth?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:be.HighNetWorth,checked:n===be.HighNetWorth,onChange:()=>o(be.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"]})]})]})}),x&&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:"})," ",x]})})]}),e.jsxs(he,{className:"flex justify-between",children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"submit",isLoading:d,disabled:n===null,children:"Submit"})]})]})})},Fr=({applicantId:t,onComplete:r,onBack:s})=>{const{appropriatenessTestService:a}=we(),[n,o]=l.useState(null),[d,m]=l.useState(!0),[x,p]=l.useState(!1),[w,E]=l.useState(null),[N,R]=l.useState({}),[f,j]=l.useState(0),[L,F]=l.useState(!1),[$,P]=l.useState(!1),[M,Z]=l.useState(0);l.useEffect(()=>{(async()=>{try{m(!0),E(null),console.log("Loading appropriateness test for applicant:",t);const T=await a.getAppropriatenessTest(t);if(console.log("Appropriateness test data:",T),o(T),T.waitTimeSpanForNextTry&&T.waitTimeSpanForNextTry!=="00:00:00"){const Y=ae(T.waitTimeSpanForNextTry);Y>0&&Z(Y)}}catch(T){console.error("Error loading appropriateness test:",T),E(T.message||"Failed to load appropriateness test")}finally{m(!1)}})()},[t,a]);const ae=O=>{const T=O.split(":").map(Number);if(T.length===3){const[Y,X,ne]=T;return Y*3600+X*60+ne}return 0},H=O=>{const T=Math.floor(O/60),Y=O%60;return`${T.toString().padStart(2,"0")}:${Y.toString().padStart(2,"0")}`};l.useEffect(()=>{if(!L||f<=0)return;const O=setInterval(()=>{j(T=>T<=1?(P(!0),0):T-1)},1e3);return()=>clearInterval(O)},[L,f]),l.useEffect(()=>{if(M<=0)return;const O=setInterval(()=>{Z(T=>T<=1?0:T-1)},1e3);return()=>clearInterval(O)},[M]),l.useEffect(()=>{$&&!x&&q()},[$]);const D=()=>{n&&(F(!0),j(n.testDurationSec))},W=(O,T)=>{R(Y=>({...Y,[O]:T}))},q=async O=>{if(O&&O.preventDefault(),!!n){if(!$){const T=n.appropriatenessQuestions.length-Object.keys(N).length;if(T>0){E(`Please answer all questions. ${T} question(s) remaining.`);return}}p(!0),E(null);try{const T=n.appropriatenessQuestions.map(X=>({appropriatenessQuestionId:X.id,value:N[X.id]||""})),Y={applicantId:t,appropriatenessTestId:n.id,appropriatenessQuestionResults:T};console.log("Submitting appropriateness test:",Y);try{const X=await a.fillAppropriatenessTest(Y);console.log("Appropriateness test result:",X),X.message&&(X.message.toLowerCase().includes("pass")||X.message.toLowerCase().includes("success")||X.message.toLowerCase().includes("congratulations"))?r==null||r():(E(X.message||"Test completed. Please check the result."),F(!1),P(!1),R({}),setTimeout(()=>B(),1e3))}catch(X){if(X.code===400&&X.message){const ne=X.message;console.log("Test failed:",ne),E(ne),F(!1),P(!1),R({}),setTimeout(()=>B(),1500)}else throw X}}catch(T){console.error("Error submitting appropriateness test:",T),E(T.message||"Failed to submit test. Please try again."),F(!1),P(!1),R({})}finally{p(!1)}}},B=async()=>{try{const O=await a.getAppropriatenessTest(t);if(console.log("Reloaded test data:",O),o(O),O.waitTimeSpanForNextTry&&O.waitTimeSpanForNextTry!=="00:00:00"){const T=ae(O.waitTimeSpanForNextTry);T>0&&Z(T)}}catch(O){console.error("Error reloading test data:",O),E(T=>T+`
82
+ */const ss=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],Nr=wr("chevron-right",ss);function as(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 ns(t){const r=t.flatMap((a,n)=>(a.questions??[]).map((o,d)=>({question:o,groupIndex:n,qIdx:d}))),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 Cr=({applicantId:t,onComplete:r,onBack:s})=>{const{questionnaire:a,initialAnswers:n,isLoading:o,isSubmitting:d,error:m,submit:x}=yr(t),[p,w]=l.useState({}),[E,N]=l.useState({}),[R,f]=l.useState(0);l.useEffect(()=>{n&&Object.keys(n).length>0&&Object.keys(p).length===0&&w(n)},[n]);const j=l.useMemo(()=>a?ns(a.questionGroups):[],[a]),L=R===j.length-1,I=j[R]??[],$=l.useCallback((H,D)=>{w(W=>({...W,[H]:D})),N(W=>{const q={...W};return delete q[H],q})},[]),P=l.useCallback(()=>{const H={};for(const{question:D}of I){const W=as(D,p[D.id]??[]);W&&(H[D.id]=W)}return N(D=>({...D,...H})),Object.keys(H).length===0},[I,p]),M=()=>{P()&&f(H=>H+1)},Z=()=>{R>0?f(H=>H-1):s==null||s()},ae=async()=>{if(!(!P()||!a))try{const H=a.questionGroups.flatMap(W=>(W.questions??[]).map(q=>({questionId:q.id,values:p[q.id]??[]}))),D={applicantId:t,questionnarieId:a.id,questionResults:H};await x(D),r==null||r()}catch(H){console.error("Questionnaire submit error:",H)}};return o?e.jsx(V,{children:e.jsx(Q,{children:e.jsx(Ne,{className:"my-8"})})}):m?e.jsx(V,{children:e.jsx(Q,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading questionnaire: ",m.message]})})}):a?e.jsxs(V,{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 ",R+1," of ",j.length]}),e.jsx("div",{className:"flex items-center gap-1.5",children:j.map((H,D)=>e.jsx("div",{className:"rounded-full transition-all duration-200",style:{height:"6px",width:D===R?"20px":"6px",backgroundColor:D<=R?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},D))})]})]}),e.jsx(Q,{className:"space-y-6",children:I.map(({question:H})=>e.jsx(is,{question:H,value:p[H.id]??[],error:E[H.id],onChange:D=>$(H.id,D)},H.id))}),e.jsxs(he,{className:"flex items-center justify-between",children:[e.jsxs(J,{type:"button",variant:"outline",onClick:Z,style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(Sr,{size:14}),R>0?"Previous":"Back"]}),L?e.jsx(J,{type:"button",isLoading:d,onClick:ae,children:"Continue"}):e.jsxs(J,{type:"button",onClick:M,style:{display:"flex",alignItems:"center",gap:"4px"},children:["Next",e.jsx(Nr,{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},is=({question:t,value:r,error:s,onChange:a})=>{var d;const o=(((d=t.defaultAnswers)==null?void 0:d.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(me,{value:r[0]??"",onChange:m=>a([m.target.value]),placeholder:t.subtitle?void 0:"Enter your answer…",error:s,required:t.isRequired}),o==="single-select"&&e.jsx(ot,{value:r[0]??"",onChange:m=>a([m.target.value]),options:(t.defaultAnswers??[]).map(m=>({value:m,label:m})),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(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:()=>a([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:m})]},m)),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(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:x=>{x.target.checked?a([...r,m]):a(r.filter(p=>p!==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:m})]},m)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),s&&o==="text"&&null]})},Er=({applicantId:t,onComplete:r,onBack:s})=>{const{uploadDocument:a,isLoading:n,isSubmitting:o,error:d,submit:m}=hr(t),[x,p]=l.useState({}),w=async E=>{if(E.preventDefault(),!a)return;const N=await Promise.all(a.uploadDocumentFiles.map(async f=>{const j=x[f.id]||[],L=await Promise.all(j.map(async I=>({fileName:I.name,fileData:await or(I)})));return{uploadDocumentFileId:f.id,valueList:L}})),R={applicantId:t,uploadDocumentId:a.id,uploadDocumentResults:N};await m(R),r==null||r()};return n?e.jsx(V,{children:e.jsx(Q,{children:e.jsx(Ne,{className:"my-8"})})}):d?e.jsx(V,{children:e.jsx(Q,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading document requirements: ",d.message]})})}):a?e.jsx("form",{onSubmit:w,children:e.jsxs(V,{children:[e.jsxs(ye,{children:[e.jsx("h2",{className:"text-lg font-bold",children:a.displayName}),a.subtitle&&e.jsx("p",{className:"mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:a.subtitle})]}),e.jsx(Q,{className:"space-y-6",children:a.uploadDocumentFiles.map(E=>e.jsx(vr,{label:E.displayName,accept:E.allowedTypes,multiple:E.multipleFile,maxSize:E.maxEachFileSizeByte,value:x[E.id]||[],onChange:N=>{p(R=>({...R,[E.id]:N}))}},E.id))}),e.jsxs(he,{className:"flex justify-between",children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"submit",isLoading:o,children:"Continue"})]})]})}):null},Rr=({applicantId:t,onComplete:r,onBack:s})=>{const{overview:a,isLoading:n,isSubmitting:o,error:d,passOverview:m}=xr(t),x=async()=>{await m(),r==null||r()};return n?e.jsx(V,{children:e.jsx(Q,{children:e.jsx(Ne,{className:"my-8"})})}):d?e.jsx(V,{children:e.jsx(Q,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading overview: ",d.message]})})}):a?e.jsxs(V,{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(Q,{className:"space-y-8",children:a.steps&&a.steps.length>0?a.steps.sort((p,w)=>p.order-w.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(he,{className:"flex justify-between",children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{onClick:x,isLoading:o,children:"Continue"})]})]}):null};function os(t){const r=(t??"en").toLowerCase().replace("_","-");try{return Intl.NumberFormat.supportedLocalesOf([r]),r}catch{return"en"}}function ls(t){return t.valueDataType===Ae.Money&&Array.isArray(t.defaultValues)&&t.defaultValues.length>0}function cs(t,r){const s=new Intl.NumberFormat(os(r),{minimumFractionDigits:0,maximumFractionDigits:2});return t.replace(/([\d]+(?:\.\d+)?)/g,a=>{const n=parseFloat(a);return isNaN(n)?a:s.format(n)})}function ds(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===Ae.Integer||t.valueDataType===Ae.Money||t.valueDataType===Ae.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 us(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 ms(t){return t.builtInType===1?"country":!t.defaultValues||t.defaultValues.length===0?"text":t.multipleValue?"checkbox":"radio"}const Ar=({applicantId:t,onComplete:r,onBack:s})=>{const{config:a}=we(),n=a.locale??"en",{criteria:o,initialAnswers:d,isLoading:m,isSubmitting:x,error:p,submit:w}=gr(t),[E,N]=l.useState({}),[R,f]=l.useState({}),[j,L]=l.useState(0),[I,$]=l.useState(!1);l.useEffect(()=>{d&&Object.keys(d).length>0&&Object.keys(E).length===0&&N(d)},[d]);const P=l.useMemo(()=>o&&o.length>0?us(o):[],[o]),M=j===P.length-1,Z=P[j]??[];l.useEffect(()=>{!m&&o&&o.length===0&&!I&&!x&&($(!0),w({applicantId:t,criteriaValueInputs:[]}).then(()=>r==null?void 0:r()).catch(console.error))},[m,o,I,x,w,t,r]);const ae=l.useCallback((B,_)=>{N(O=>({...O,[B]:_})),f(O=>{const T={...O};return delete T[B],T})},[]),H=l.useCallback(()=>{const B={};for(const{criterion:_}of Z){const O=ds(_,E[_.id]??[]);O&&(B[_.id]=O)}return f(_=>({..._,...B})),Object.keys(B).length===0},[Z,E]),D=()=>{H()&&L(B=>B+1)},W=()=>{j>0?L(B=>B-1):s==null||s()},q=async()=>{if(!(!H()||!o))try{const B=o.map(O=>{const T=(E[O.id]??[]).filter(Y=>Y&&Y.trim());return T.length>0?{riskCriteriaId:O.id,values:T}:null}).filter(O=>O!==null);await w({applicantId:t,criteriaValueInputs:B}),r==null||r()}catch(B){console.error("Risk scoring submit error:",B)}};return m?e.jsx(V,{children:e.jsxs(Q,{children:[e.jsx(Ne,{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…"})]})}):!m&&o&&o.length===0?e.jsx(V,{children:e.jsxs(Q,{children:[e.jsx(Ne,{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(V,{children:e.jsx(Q,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading criteria: ",p.message]})})}):o?e.jsxs(V,{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"}),P.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 ",P.length]}),e.jsx("div",{className:"flex items-center gap-1.5",children:P.map((B,_)=>e.jsx("div",{className:"rounded-full transition-all duration-200",style:{height:"6px",width:_===j?"20px":"6px",backgroundColor:_<=j?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},_))})]})]}),e.jsx(Q,{className:"space-y-6",children:Z.map(({criterion:B})=>e.jsx(ps,{criterion:B,value:E[B.id]??[],error:R[B.id],locale:n,onChange:_=>ae(B.id,_)},B.id))}),e.jsxs(he,{className:"flex items-center justify-between",children:[e.jsxs(J,{type:"button",variant:"outline",onClick:W,style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(Sr,{size:14}),j>0?"Previous":"Back"]}),M?e.jsx(J,{type:"button",isLoading:x,onClick:q,children:"Continue"}):e.jsxs(J,{type:"button",onClick:D,style:{display:"flex",alignItems:"center",gap:"4px"},children:["Next",e.jsx(Nr,{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},ps=({criterion:t,value:r,error:s,locale:a,onChange:n})=>{const o=ms(t),d=t.valueDataType===Ae.Integer||t.valueDataType===Ae.Money||t.valueDataType===Ae.DigitOnly,m=ls(t),x=p=>m?cs(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}),d&&(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(me,{value:r[0]??"",onChange:p=>n([p.target.value]),type:d?"number":"text",placeholder:"Enter your answer…",error:s,required:t.isRequired,min:t.min,max:t.max,onKeyDown:p=>{t.valueDataType===Ae.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:x(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:w=>{w.target.checked?n([...r,p]):n(r.filter(E=>E!==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:x(p)})]},p)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),o==="country"&&e.jsx(ot,{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})]})},Fr=({applicantId:t,onComplete:r,onBack:s})=>{const{investorCategorizationService:a}=we(),[n,o]=l.useState(null),[d,m]=l.useState(!1),[x,p]=l.useState(null),w=async E=>{if(E.preventDefault(),n===null){p("Please select an investor type");return}m(!0),p(null);try{const N={applicantId:t,investorType:n};console.log("Submitting investor categorization:",N);const R=await a.setInvestorCategorization(N);console.log("Investor categorization result:",R),r==null||r()}catch(N){console.error("Error submitting investor categorization:",N),p(N.message||"Failed to submit investor categorization")}finally{m(!1)}};return e.jsx("form",{onSubmit:w,children:e.jsxs(V,{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(Q,{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===be.Individual?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:n===be.Individual?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:be.Individual,checked:n===be.Individual,onChange:()=>o(be.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===be.Sophisticated?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:n===be.Sophisticated?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:be.Sophisticated,checked:n===be.Sophisticated,onChange:()=>o(be.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===be.HighNetWorth?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:n===be.HighNetWorth?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:be.HighNetWorth,checked:n===be.HighNetWorth,onChange:()=>o(be.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"]})]})]})}),x&&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:"})," ",x]})})]}),e.jsxs(he,{className:"flex justify-between",children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"submit",isLoading:d,disabled:n===null,children:"Submit"})]})]})})},Ir=({applicantId:t,onComplete:r,onBack:s})=>{const{appropriatenessTestService:a}=we(),[n,o]=l.useState(null),[d,m]=l.useState(!0),[x,p]=l.useState(!1),[w,E]=l.useState(null),[N,R]=l.useState({}),[f,j]=l.useState(0),[L,I]=l.useState(!1),[$,P]=l.useState(!1),[M,Z]=l.useState(0);l.useEffect(()=>{(async()=>{try{m(!0),E(null),console.log("Loading appropriateness test for applicant:",t);const T=await a.getAppropriatenessTest(t);if(console.log("Appropriateness test data:",T),o(T),T.waitTimeSpanForNextTry&&T.waitTimeSpanForNextTry!=="00:00:00"){const Y=ae(T.waitTimeSpanForNextTry);Y>0&&Z(Y)}}catch(T){console.error("Error loading appropriateness test:",T),E(T.message||"Failed to load appropriateness test")}finally{m(!1)}})()},[t,a]);const ae=O=>{const T=O.split(":").map(Number);if(T.length===3){const[Y,X,ne]=T;return Y*3600+X*60+ne}return 0},H=O=>{const T=Math.floor(O/60),Y=O%60;return`${T.toString().padStart(2,"0")}:${Y.toString().padStart(2,"0")}`};l.useEffect(()=>{if(!L||f<=0)return;const O=setInterval(()=>{j(T=>T<=1?(P(!0),0):T-1)},1e3);return()=>clearInterval(O)},[L,f]),l.useEffect(()=>{if(M<=0)return;const O=setInterval(()=>{Z(T=>T<=1?0:T-1)},1e3);return()=>clearInterval(O)},[M]),l.useEffect(()=>{$&&!x&&q()},[$]);const D=()=>{n&&(I(!0),j(n.testDurationSec))},W=(O,T)=>{R(Y=>({...Y,[O]:T}))},q=async O=>{if(O&&O.preventDefault(),!!n){if(!$){const T=n.appropriatenessQuestions.length-Object.keys(N).length;if(T>0){E(`Please answer all questions. ${T} question(s) remaining.`);return}}p(!0),E(null);try{const T=n.appropriatenessQuestions.map(X=>({appropriatenessQuestionId:X.id,value:N[X.id]||""})),Y={applicantId:t,appropriatenessTestId:n.id,appropriatenessQuestionResults:T};console.log("Submitting appropriateness test:",Y);try{const X=await a.fillAppropriatenessTest(Y);console.log("Appropriateness test result:",X),X.message&&(X.message.toLowerCase().includes("pass")||X.message.toLowerCase().includes("success")||X.message.toLowerCase().includes("congratulations"))?r==null||r():(E(X.message||"Test completed. Please check the result."),I(!1),P(!1),R({}),setTimeout(()=>B(),1e3))}catch(X){if(X.code===400&&X.message){const ne=X.message;console.log("Test failed:",ne),E(ne),I(!1),P(!1),R({}),setTimeout(()=>B(),1500)}else throw X}}catch(T){console.error("Error submitting appropriateness test:",T),E(T.message||"Failed to submit test. Please try again."),I(!1),P(!1),R({})}finally{p(!1)}}},B=async()=>{try{const O=await a.getAppropriatenessTest(t);if(console.log("Reloaded test data:",O),o(O),O.waitTimeSpanForNextTry&&O.waitTimeSpanForNextTry!=="00:00:00"){const T=ae(O.waitTimeSpanForNextTry);T>0&&Z(T)}}catch(O){console.error("Error reloading test data:",O),E(T=>T+`
83
83
 
84
84
  Failed to reload test data. Please refresh the page.`)}};if(d)return e.jsx(V,{children:e.jsxs(Q,{children:[e.jsx(Ne,{className:"my-8"}),e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-4",children:"Loading appropriateness test..."})]})});if(!n)return e.jsx(V,{children:e.jsxs(Q,{className:"py-12 text-center",children:[e.jsx("p",{className:"text-danger-500 text-lg mb-4",children:"No test data available"}),w&&e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:w})]})});if(M>0)return e.jsxs(V,{children:[e.jsxs(ye,{children:[e.jsx("h2",{className:"text-lg font-bold text-gray-900 dark:text-white",children:n.displayName}),n.subtitle&&e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-2",children:n.subtitle})]}),e.jsxs(Q,{className:"py-12 text-center",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("div",{className:"text-6xl font-bold text-primary-500 mb-2",children:H(M)}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Please wait before attempting the test again"})]}),w&&e.jsx("div",{className:"mt-4 p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg",children:e.jsx("p",{className:"text-red-600 dark:text-red-400 text-sm",children:w})})]})]});const _=n.testAllowedMaxTry-n.totalFailedTries;return L?e.jsx("form",{onSubmit:q,children:e.jsxs(V,{children:[e.jsx(ye,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-gray-900 dark:text-white",children:n.displayName}),n.subtitle&&e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:n.subtitle})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:`text-3xl font-bold ${f<=60?"text-danger-500":"text-primary-500"}`,children:H(f)}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Time Remaining"})]})]})}),e.jsxs(Q,{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs(De,{variant:"info",children:["Question ",Object.keys(N).length," of ",n.totalQuestionCount]}),e.jsxs(De,{variant:_>1?"success":"warning",children:[_," attempt",_!==1?"s":""," remaining"]})]}),n.appropriatenessQuestions.map((O,T)=>e.jsxs("div",{className:"p-4 border border-gray-200 dark:border-gray-700 rounded-lg",children:[e.jsxs("div",{className:"mb-4",children:[e.jsxs("span",{className:"inline-block px-2 py-1 text-xs font-semibold text-primary-700 bg-primary-100 dark:text-primary-300 dark:bg-primary-900/30 rounded mb-2",children:["Question ",T+1]}),O.groupName&&e.jsx("span",{className:"ml-2 text-xs text-gray-500 dark:text-gray-400",children:O.groupName}),e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white mt-2",children:O.question})]}),e.jsx("div",{className:"space-y-2",children:O.answers.map((Y,X)=>e.jsxs("label",{className:`
85
85
  flex items-center p-3 border-2 rounded-lg cursor-pointer transition-all
86
86
  ${N[O.id]===Y?"border-primary-500 bg-primary-50 dark:bg-primary-900/20":"border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600"}
87
- `,children:[e.jsx("input",{type:"radio",name:`question-${O.id}`,value:Y,checked:N[O.id]===Y,onChange:ne=>W(O.id,ne.target.value),className:"h-4 w-4 text-primary-500 border-gray-300 focus:ring-primary-500",disabled:x}),e.jsx("span",{className:"ml-3 text-gray-700 dark:text-gray-300",children:Y})]},X))})]},O.id)),w&&!$&&e.jsx("div",{className:"p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg",children:e.jsxs("p",{className:"text-red-600 dark:text-red-400 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",w]})}),$&&e.jsx("div",{className:"p-4 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-700 dark:text-yellow-400 text-sm",children:[e.jsx("strong",{children:"Time's up!"})," Your answers are being submitted automatically."]})})]}),e.jsxs(he,{className:"flex justify-between",children:[e.jsx(J,{type:"button",variant:"outline",onClick:s,disabled:x,children:"Cancel"}),e.jsx(J,{type:"submit",isLoading:x,disabled:Object.keys(N).length<n.totalQuestionCount,children:$?"Submitting...":"Submit Test"})]})]})}):e.jsxs(V,{children:[e.jsxs(ye,{children:[e.jsx("h2",{className:"text-lg font-bold text-gray-900 dark:text-white",children:n.displayName}),n.subtitle&&e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-2",children:n.subtitle})]}),e.jsxs(Q,{children:[n.description&&e.jsx("div",{className:"mb-6 p-4 bg-gray-50 dark:bg-gray-800 rounded-lg",children:e.jsx("p",{className:"text-gray-700 dark:text-gray-300",children:n.description})}),e.jsxs("div",{className:"space-y-4 mb-6",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg",children:[e.jsx("span",{className:"text-gray-700 dark:text-gray-300 font-medium",children:"Total Questions:"}),e.jsx(De,{variant:"info",children:n.totalQuestionCount})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg",children:[e.jsx("span",{className:"text-gray-700 dark:text-gray-300 font-medium",children:"Time Limit:"}),e.jsx(De,{variant:"info",children:H(n.testDurationSec)})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg",children:[e.jsx("span",{className:"text-gray-700 dark:text-gray-300 font-medium",children:"Correct Answers Required:"}),e.jsx(De,{variant:"info",children:n.testCorrectAnswerPassLimit})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg",children:[e.jsx("span",{className:"text-gray-700 dark:text-gray-300 font-medium",children:"Attempts Remaining:"}),e.jsx(De,{variant:_>1?"success":"warning",children:_})]})]}),w&&e.jsx("div",{className:"mb-4 p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg",children:e.jsxs("p",{className:"text-red-600 dark:text-red-400 text-sm",children:[e.jsx("strong",{children:"Previous Attempt:"})," ",w]})}),_<=0&&e.jsx("div",{className:"p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg",children:e.jsx("p",{className:"text-red-600 dark:text-red-400",children:"You have used all your attempts. Please contact support for assistance."})})]}),e.jsxs(he,{className:"flex justify-between",children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"button",onClick:D,disabled:_<=0,children:"Start Test"})]})]})},Pr=({applicantId:t,onComplete:r,onBack:s})=>{var Pe,Qe,Oe,Ue;const{applicantService:a,baseInformationService:n,config:o,currentTheme:d}=we(),{identityData:m,provider:x,token:p,isLoading:w,error:E,requestIdentity:N,restartIdentity:R}=fr(t),[f,j]=l.useState(null),[L,F]=l.useState(null),[$,P]=l.useState([]),[M,Z]=l.useState([]),[ae,H]=l.useState(!0),[D,W]=l.useState(!1),[q,B]=l.useState(null),[_,O]=l.useState(!1),T=l.useRef(!1),[Y,X]=l.useState({}),[ne,A]=l.useState({}),U=d!=null&&d.reviewPageFields&&d.reviewPageFields.length>0?d.reviewPageFields[0]:null,ee=!!(d!=null&&d.reviewPageDisabled),pe=l.useRef(!1);pe.current=ee;const oe=Be.useForm({defaultValues:{street:"",streetNumber:"",city:"",zip:"",country:"",nationality:"",phonenumber:""}});l.useEffect(()=>{if(ee){T.current||(T.current=!0,N().then(()=>W(!0)).catch(z=>console.error("[Identity] Auto-request failed:",z)).finally(()=>H(!1)));return}(async()=>{try{const[z,K,u]=await Promise.all([a.getApplicantData(t),n.getCountries("","en"),n.getCountries("","en",40)]);F(z);const b=new Set,S=K.map(y=>({value:y.abbreviation3||y.abbreviation,label:y.name})).filter(y=>!y.value||b.has(y.value)?!1:(b.add(y.value),!0));P(S);const g=new Set,i=u.filter(y=>y.countryCode).map(y=>({value:y.countryCode,label:`${y.countryCode} – ${y.name}`})).filter(y=>g.has(y.value)?!1:(g.add(y.value),!0));Z(i);const c=z.applicantRequestData;if(X({firstName:(c==null?void 0:c.firstName)||"",lastName:(c==null?void 0:c.lastName)||"",email:(c==null?void 0:c.email)||"",dateOfBirth:(c==null?void 0:c.dateOfBirth)||"",title:(c==null?void 0:c.title)||"",salutation:(c==null?void 0:c.salutation)||"",phonenumber:(c==null?void 0:c.phonenumber)||"",mobileCountryCode:(c==null?void 0:c.mobileCountryCode)||"",street:(c==null?void 0:c.street)||"",streetNumber:(c==null?void 0:c.streetNumber)||"",city:(c==null?void 0:c.city)||"",zip:(c==null?void 0:c.zip)||"",country:(c==null?void 0:c.country)||"",nationality:(c==null?void 0:c.nationality)||"",taxCountry:(c==null?void 0:c.taxCountry)||"",countryOfBirth:(c==null?void 0:c.countryOfBirth)||"",placeOfBirth:(c==null?void 0:c.placeOfBirth)||"",educationLevel:(c==null?void 0:c.educationLevel)||"",occupation:(c==null?void 0:c.occupation)||"",taxNumber:(c==null?void 0:c.taxNumber)||"",defaultLanguage:(c==null?void 0:c.defaultLanguage)||""}),oe.reset({street:(c==null?void 0:c.street)||"",streetNumber:(c==null?void 0:c.streetNumber)||"",city:(c==null?void 0:c.city)||"",zip:(c==null?void 0:c.zip)||"",country:(c==null?void 0:c.country)||"",nationality:(c==null?void 0:c.nationality)||"",phonenumber:(c==null?void 0:c.phonenumber)||""}),z.kycRecords&&z.kycRecords.length>0&&z.kycRecords[0].providerTokenObject!==null&&!T.current&&pe.current){console.log("[Identity] Review page disabled + existing identity — auto-requesting..."),T.current=!0;try{await N(),W(!0)}catch(y){console.error("[Identity] Auto-request failed:",y)}}}catch(z){console.error("Error loading applicant data:",z)}finally{H(!1)}})()},[t]),l.useEffect(()=>{m&&!D&&pe.current&&(console.log("[Identity] Review page disabled — showing cached provider"),W(!0))},[m,D]),l.useEffect(()=>{if(p){if(p.expiresAt){const h=new Date(p.expiresAt).getTime();if(Date.now()>=h){console.warn("[Identity] Token has expired (expiresAt)"),O(!0),B("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"),O(!0),B("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"),O(!0),B("Your verification session has expired. Please restart.");return}}},[p]),l.useEffect(()=>{if(x!==null&&p&&!f&&D&&!_){const h=x;if(p.url){console.log("[Identity] Loading provider URL for user verification:",p.url),B(null);try{if(new URL(p.url),h===Ce.SardinAI){console.log("[SardinAI] Initializing Risk SDK in background...");try{const z=qe.parseProviderConfig(x,p,o);qe.createProvider(x,z).initialize().then(()=>{console.log("[SardinAI] Risk SDK initialized successfully in background")}).catch(u=>{console.warn("[SardinAI] Risk SDK initialization failed (non-blocking):",u)})}catch(z){console.warn("[SardinAI] Risk SDK setup failed (non-blocking):",z)}}j({type:"url",url:p.url})}catch(z){console.error("[Identity] Invalid URL:",z),B("Invalid verification URL. Please restart."),O(!0)}return}if(h===Ce.SardinAI){console.log("[SardinAI] No URL provided - initializing Risk SDK only..."),B(null);try{const z=qe.parseProviderConfig(x,p,o),K=qe.createProvider(x,z);K.initialize().then(()=>{console.log("[SardinAI] Risk SDK initialized successfully"),j(K),setTimeout(()=>{r==null||r()},2e3)}).catch(u=>{var S;console.error("[SardinAI] Failed to initialize:",u);const b=((S=u.message)==null?void 0:S.toLowerCase())||"";b.includes("expired")||b.includes("invalid")||b.includes("401")||b.includes("400")?(O(!0),B("Session expired or invalid. Please restart verification.")):B(`Failed to initialize: ${u.message}`)})}catch(z){console.error("[SardinAI] Error creating provider:",z),B(`Configuration error: ${z.message}`)}return}try{B(null);const z=qe.parseProviderConfig(x,p,o),K=qe.createProvider(x,z);h===Ce.Sumsub?(K.initialize("identity-container").catch(u=>{var b;console.error("[Sumsub] Initialization error:",u),B(`Failed to initialize: ${u.message}`),(b=u.message)!=null&&b.toLowerCase().includes("expired")&&O(!0)}),K.onComplete&&K.onComplete(()=>{r==null||r()})):h===Ce.Onfido&&K.initialize("identity-container").catch(u=>{console.error("[Onfido] Initialization error:",u),B(`Failed to initialize: ${u.message}`)}),j(K)}catch(z){console.error("[Identity] Provider setup error:",z),B(`Setup error: ${z.message}`)}}return()=>{if(f&&f.destroy)try{f.destroy()}catch(h){console.error("[Identity] Error destroying provider:",h)}}},[x,p,f,D,r,_]);const I=async()=>{try{B(null),O(!1),await N(),W(!0)}catch(h){console.error("Error starting identity verification:",h)}},G=async()=>{try{B(null),O(!1),j(null),console.log("[Identity] Restarting verification..."),await R(),W(!0)}catch(h){console.error("Error restarting identity verification:",h),B(h.message||"Failed to restart verification")}};if(ae||w)return e.jsx(V,{children:e.jsxs(Q,{children:[e.jsx(Ne,{className:"my-8"}),e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-4",children:"Loading identity verification..."})]})});if(E)return e.jsx(V,{children:e.jsx(Q,{children:e.jsxs("p",{className:"text-danger-500",children:["Error: ",E.message]})})});if(D&&(q||_))return e.jsxs(V,{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(Q,{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:_?"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(he,{className:"flex justify-between",children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"button",onClick:G,disabled:w,children:w?"Restarting...":"Restart Verification"})]})]});if(D&&m){const h=x;return p!=null&&p.url?e.jsxs(V,{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(J,{type:"button",variant:"outline",size:"sm",onClick:G,disabled:w,children:"Restart"})]})}),e.jsxs(Q,{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 K,u,b;console.log("[Identity] Iframe loaded");try{const S=z.target,g=S.contentDocument||((K=S.contentWindow)==null?void 0:K.document);if(g){const i=((b=(u=g.body)==null?void 0:u.textContent)==null?void 0:b.toLowerCase())||"";(i.includes("expired")||i.includes("invalid")||i.includes("error"))&&(console.warn("[Identity] Iframe shows expiration message"),O(!0),B("Your verification link has expired."))}}catch{console.log("[Identity] Cannot check iframe content (CORS)")}}})})]}),s&&e.jsx(he,{children:e.jsx(J,{variant:"outline",onClick:s,children:"Back"})})]}):h===Ce.SardinAI?e.jsxs(V,{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(Q,{children:e.jsxs("div",{className:"text-center py-12",children:[e.jsx(Ne,{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(V,{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(Q,{children:e.jsx("div",{id:"identity-container",className:"min-h-[400px]"})}),s&&e.jsx(he,{children:e.jsx(J,{variant:"outline",onClick:s,children:"Back"})})]})}const te=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),le=(h=4)=>({1:"col-span-1",2:"col-span-2",3:"col-span-3",4:"col-span-4"})[h]||"col-span-4",ke=(h,z)=>{if(!z&&z!==0)return"—";if(te.has(h)&&h!=="mobileCountryCode"){const K=$.find(u=>u.value===z);return K?K.label:String(z)}return String(z)},Fe=({helpText:h})=>{const[z,K]=l.useState(!1),u=l.useRef(null),[,b]=l.useState({top:0,left:0}),S=()=>{if(u.current){const g=u.current.getBoundingClientRect();b({top:g.bottom+window.scrollY+6,left:g.left+window.scrollX})}K(!0)};return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"metakyc-help-btn",ref:u,onClick:S,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&&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:()=>K(!1),children:e.jsxs("div",{onClick:g=>g.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:()=>K(!1),style:{marginTop:12,padding:"4px 12px",fontSize:12,border:"1px solid var(--metakyc-border, #e5e7eb)",borderRadius:"var(--metakyc-border-radius, 6px)",background:"transparent",cursor:"pointer",color:"var(--metakyc-text-secondary, #6b7280)"},children:"Close"})]})}),document.body)]})},fe=(h,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:h}),e.jsx("div",{style:{paddingTop:24},children:e.jsx(Fe,{helpText:z})})]}):h,Ye=(h,z)=>{const K=`cf-${z}`,u=h.paramName??"",b=ne[u];if(h.customType==="br")return e.jsx("div",{className:le(h.colSpan),style:{minHeight:"0.5rem"}},K);if(h.customType==="paragraph")return e.jsx("div",{className:le(h.colSpan),children:e.jsx("div",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:h.label||""}})},K);if(h.customType==="html")return e.jsx("div",{className:le(h.colSpan),dangerouslySetInnerHTML:{__html:h.label||""}},K);if(h.customType==="link")return e.jsx("div",{className:le(h.colSpan),children:fe(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)},K);if(h.customType==="checkbox"||h.customType==="link_checkbox"){const S=b==="true"||b===!0;return e.jsx("div",{className:le(h.colSpan),children:fe(e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:!!S,onChange:g=>A(i=>({...i,[u]:String(g.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)},K)}if(h.customType==="group_checkbox"){const S=Array.isArray(b)?b:b?[b]:[],g=i=>{h.singleSelect?A(c=>({...c,[u]:S[0]===i?[]:[i]})):A(c=>({...c,[u]:S.includes(i)?S.filter(C=>C!==i):[...S,i]}))};return e.jsx("div",{className:le(h.colSpan),children:fe(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:S.includes(i.value),onChange:()=>g(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)},K)}return h.customType==="radio_group"?e.jsx("div",{className:le(h.colSpan),children:fe(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(S=>e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"radio",name:`rg-${u}`,value:S.value,checked:b===S.value,onChange:()=>A(g=>({...g,[u]:S.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:S.label})]},S.value))]}),h.helpText)},K):e.jsx("div",{className:le(h.colSpan),children:fe(e.jsx(me,{label:h.displayText||h.label||u,value:String(b??""),onChange:S=>A(g=>({...g,[u]:S.target.value}))}),h.helpText)},K)},Ve=(h,z)=>{if(h.isCustom)return Ye(h,z);const K=h.name??"",u=He[K],b=h.displayText||(u==null?void 0:u.label)||K,S=Y[K]??"",g=K==="mobileCountryCode",i=!!(u!=null&&u.countriesType)&&!g;return h.editable?g?e.jsx("div",{className:le(h.colSpan??2),children:fe(e.jsx(Ie,{label:b,value:String(S),onChange:c=>X(C=>({...C,[K]:c})),options:[{value:"",label:"Select country code…"},...M]}),h.helpText)},`epc-${z}`):i?e.jsx("div",{className:le(h.colSpan??2),children:fe(e.jsx(Ie,{label:b,value:String(S),onChange:c=>X(C=>({...C,[K]:c})),options:[{value:"",label:`Select ${b.toLowerCase()}…`},...$]}),h.helpText)},`ec-${z}`):e.jsx("div",{className:le(h.colSpan??2),children:fe(e.jsx(me,{label:b,type:(u==null?void 0:u.type)==="date"?"date":(u==null?void 0:u.type)==="email"?"email":"text",value:String(S),onChange:c=>X(C=>({...C,[K]:c.target.value}))}),h.helpText)},`ei-${z}`):e.jsx("div",{className:le(h.colSpan??2),children:fe(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:b}),e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)",minHeight:"1.5rem"},children:ke(K,S)})]}),h.helpText)},`ro-${z}`)};if(U){const h=U.title||"Review Your Information",z=U.subtitle||"Please review and confirm your information before starting identity verification";return e.jsx("form",{onSubmit:K=>{K.preventDefault(),I()},children:e.jsxs(V,{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:z})]}),e.jsx(Q,{children:e.jsx("div",{className:"grid grid-cols-4 gap-4",children:U.fields.map((K,u)=>Ve(K,u))})}),e.jsxs(he,{className:"flex justify-between",children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"submit",isLoading:w,children:"Confirm and Start Verification"})]})]})})}return e.jsx("form",{onSubmit:oe.handleSubmit(I),children:e.jsxs(V,{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(Q,{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:`${((Pe=L==null?void 0:L.applicantRequestData)==null?void 0:Pe.firstName)||""} ${((Qe=L==null?void 0:L.applicantRequestData)==null?void 0:Qe.lastName)||""}`.trim()},{label:"Email",value:(Oe=L==null?void 0:L.applicantRequestData)==null?void 0:Oe.email},{label:"Date of Birth",value:((Ue=L==null?void 0:L.applicantRequestData)==null?void 0:Ue.dateOfBirth)||"Not provided"}].map(({label:h,value:z})=>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:z})]},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(Be.Controller,{control:oe.control,name:"country",render:({field:h})=>e.jsx(Ie,{label:"Country",value:h.value,onChange:h.onChange,options:[{value:"",label:"Select country…"},...$]})}),e.jsx(Be.Controller,{control:oe.control,name:"nationality",render:({field:h})=>e.jsx(Ie,{label:"Nationality",value:h.value,onChange:h.onChange,options:[{value:"",label:"Select nationality…"},...$]})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Be.Controller,{control:oe.control,name:"street",render:({field:h})=>e.jsx(me,{...h,label:"Street"})}),e.jsx(Be.Controller,{control:oe.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(Be.Controller,{control:oe.control,name:"city",render:({field:h})=>e.jsx(me,{...h,label:"City"})}),e.jsx(Be.Controller,{control:oe.control,name:"zip",render:({field:h})=>e.jsx(me,{...h,label:"ZIP / Postal Code"})})]}),e.jsx(Be.Controller,{control:oe.control,name:"phonenumber",render:({field:h})=>e.jsx(me,{...h,label:"Phone Number",type:"tel"})})]})]}),e.jsxs(he,{className:"flex justify-between",children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"submit",isLoading:w,children:"Confirm and Start Verification"})]})]})})},dt=({kycStatus:t,reviewStatus:r,workflowResult:s,customMessage:a,onContinue:n,onContactSupport:o})=>{const m=t===_e.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===_e.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===_e.Pending||t===_e.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===rt.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===rt.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===rt.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(V,{children:[e.jsxs(Q,{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 ${m.iconBg}`,children:e.jsx("span",{className:`text-5xl ${m.iconColor}`,children:m.icon})})}),e.jsx("h2",{className:"text-3xl font-bold text-center mb-4",style:{color:"var(--metakyc-text-primary, #111827)"},children:m.title}),e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx(De,{variant:m.type==="success"?"success":m.type==="error"?"danger":m.type==="pending"?"warning":"info",children:t!=null?_e[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||m.message}),m.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"})]})]}),m.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"})]})]}),m.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?_e[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(he,{className:"flex justify-center gap-4",children:[m.type==="success"&&n&&e.jsx(J,{onClick:n,size:"lg",children:"Continue"}),m.type==="error"&&e.jsxs(e.Fragment,{children:[o&&e.jsx(J,{variant:"outline",onClick:o,children:"Contact Support"}),n&&e.jsx(J,{onClick:n,children:"Try Again"})]}),m.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"})})]})]})},Tr=({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"}})}),Xe=({title:t,subtitle:r,className:s=""})=>{const{currentTheme:a}=we(),n=t||(a==null?void 0:a.title)||"",o=!!(a!=null&&a.logo&&a.logo.visible&&a.logo.url),d=!!n;return!o&&!d?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(Tr,{config:a.logo}),o&&d&&e.jsx("span",{style:{fontSize:"1.5rem",fontWeight:300,color:"var(--metakyc-text-muted, #9ca3af)",margin:"0 12px"},children:"|"}),d&&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 Ge(t){return t==null||t===""||Array.isArray(t)&&t.length===0}const tt={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"},bt=({helpText:t,children:r})=>{const[s,a]=l.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?it.createPortal(n,document.body):null]})},ys=({workflowKey:t,externalRefId:r,onSuccess:s,onCancel:a})=>{var z,K,u,b,S,g;const{config:n,baseInformationService:o,currentTheme:d}=we(),{createApplicant:m,isLoading:x}=pt(),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 CreateApplicantForm or set it in config.applicantForm.workflowKey");const w=r||((K=n.applicantForm)==null?void 0:K.externalRefId)||"",E=((u=n.applicantForm)==null?void 0:u.email)||"",N=((b=n.applicantForm)==null?void 0:b.hiddenValues)||{},f=(((S=n.applicantForm)==null?void 0:S.fieldLabelMode)||(d==null?void 0:d.fieldLabelMode)||"label")!=="placeholder",j=l.useMemo(()=>d!=null&&d.applicantFormPages&&d.applicantFormPages.length>0?d.applicantFormPages:null,[d==null?void 0:d.applicantFormPages]),L=l.useMemo(()=>{const i=new Set(at),c=d==null?void 0:d.applicantFormRequiredFields;if(c)for(const C of c)i.add(C);if(j)for(const C of j)for(const y of C.fields)!y.isCustom&&y.name&&y.required&&i.add(y.name);return Array.from(i)},[d==null?void 0:d.applicantFormRequiredFields,j]),F=l.useMemo(()=>{var C;if(j){const y=j.flatMap(v=>v.fields).filter(v=>!v.isCustom&&v.name).map(v=>v.name),k=new Set(y);for(const v of at)k.add(v);return Array.from(k)}let i;(C=n.applicantForm)!=null&&C.visibleFields?i=n.applicantForm.visibleFields:d!=null&&d.applicantFormVisibleFields&&d.applicantFormVisibleFields.length>0?i=d.applicantFormVisibleFields:i=Tt;const c=new Set(i);for(const y of at)c.add(y);return Array.from(c)},[(g=n.applicantForm)==null?void 0:g.visibleFields,d==null?void 0:d.applicantFormVisibleFields,j]),$=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),P=l.useMemo(()=>{var c,C;const i=new Set;if(j)for(const y of j)for(const k of y.fields)!k.isCustom&&k.name&&$.has(k.name)&&i.add(k.countriesType??((c=He[k.name])==null?void 0:c.countriesType));else for(const y of F)$.has(y)&&i.add((C=He[y])==null?void 0:C.countriesType);return i.size===0&&i.add(void 0),Array.from(i)},[F,j]),[M,Z]=l.useState({}),[ae,H]=l.useState(!0),D=l.useRef(new Set),W=l.useRef(new Set);l.useEffect(()=>{if(!d)return;const i=P.filter(y=>{const k=y!=null?String(y):"all";return!W.current.has(k)&&!D.current.has(k)});if(i.length===0){P.every(k=>{const v=k!=null?String(k):"all";return W.current.has(v)})&&H(!1);return}H(!0);const c=i.map(y=>y!=null?String(y):"all");c.forEach(y=>D.current.add(y)),(async()=>{try{const y=await Promise.all(i.map(async k=>{const v=k!=null?String(k):"all",ie=await o.getCountries("",n.locale||"en",k),re=k===40,ge=new Set,ue=ie.map(ce=>re&&ce.countryCode?{value:ce.countryCode,label:`${ce.countryCode} – ${ce.name}`}:{value:ce.abbreviation3||ce.abbreviation,label:ce.name}).filter(ce=>!ce.value||ge.has(ce.value)?!1:(ge.add(ce.value),!0));return W.current.add(v),D.current.delete(v),[v,ue]}));Z(k=>({...k,...Object.fromEntries(y)}))}catch(y){c.forEach(k=>D.current.delete(k)),console.error("Failed to load countries:",y)}finally{P.every(k=>{const v=k!=null?String(k):"all";return W.current.has(v)})&&H(!1)}})()},[P,d]);const q=(i,c)=>{var k;const C=c??((k=He[i])==null?void 0:k.countriesType),y=C!=null?String(C):"all";return M[y]||[]},B=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})),[_,O]=l.useState({workflowKey:p,firstName:"",lastName:"",title:"",email:E,dateOfBirth:"",phonenumber:"",externalRefId:w,mobileCountryCode:"",street:"",streetNumber:"",zip:"",city:"",country:"",nationality:"",otherNationality:[],defaultLanguage:"EN",taxCountry:"",placeOfBirth:"",countryOfBirth:"",salutation:null,educationLevel:"",occupation:"",taxNumber:"",...B}),T=Object.fromEntries(Object.entries(N).filter(([i])=>!(i in B)&&i!=="externalRefId"&&i!=="workflowKey")),[Y,X]=l.useState({...T}),[ne,A]=l.useState(0),[U,ee]=l.useState({}),[pe,oe]=l.useState(null),[I,G]=l.useState(!1),te=(i,c)=>O(C=>({...C,[i]:c})),le=(i,c)=>X(C=>({...C,[i]:c})),ke=i=>!i.conditionalOn||Y[i.conditionalOn]==="true",Fe=j&&ne<j.length-1?ne+1:-1,fe=j&&ne>0?ne-1:-1,Ye=i=>{var C;const c={};for(const y of i.fields)if(y.isCustom){if(y.customType==="paragraph"||y.customType==="html"||y.customType==="br"||y.customType==="link")continue;if(y.required&&y.paramName){const k=Y[y.paramName],v=y.displayText||y.label||y.paramName;y.customType==="checkbox"||y.customType==="link_checkbox"?k!=="true"&&(c[y.paramName]=`${v} is required.`):(!k||k.trim()==="")&&(c[y.paramName]=`${v} is required.`)}}else if(y.name){const k=y.name;if(L.includes(k)&&Ge(_[k])){const v=y.displayText||((C=He[k])==null?void 0:C.label)||k;c[k]=`${v} is required.`}}return c},Ve=async()=>{if(!j)return;const i=j[ne];if(i.conditionalOn&&!ke(i)){ee({}),Fe>=0?A(Fe):await Pe();return}const c=Ye(i);if(Object.keys(c).length>0){ee(c);return}ee({}),Fe>=0?A(Fe):await Pe()},Pe=async()=>{if(j){let i={};for(const c of j)ke(c)&&(i={...i,...Ye(c)});if(Object.keys(i).length>0){ee(i);return}}G(!0),oe(null);try{if(!_.externalRefId||_.externalRefId.trim()===""){oe("External Reference ID is required. Please pass it via config.applicantForm.externalRefId.");return}const i={workflowKey:_.workflowKey,externalRefId:_.externalRefId.trim()};if(j){for(const k of j)if(ke(k)){for(const v of k.fields)if(!v.isCustom&&v.name){const ie=v.name,re=_[ie];Ge(re)||(i[ie]=re)}}for(const k of at)if(i[k]===void 0){const v=_[k];Ge(v)||(i[k]=v)}}else F.forEach(k=>{if(k==="externalRefId")return;const v=_[k];Ge(v)||(i[k]=v)});const c=[];if(j){for(const k of j)if(ke(k))for(const v of k.fields){if(!v.isCustom||!v.paramName||v.customType==="paragraph"||v.customType==="html"||v.customType==="br"||v.customType==="link")continue;const ie=Y[v.paramName]??"";let re;if(v.customType==="checkbox"||v.customType==="link_checkbox")re=ie==="true"?"yes":"no";else if(re=ie,!re&&!v.required)continue;c.push({paramName:v.paramName,value:re})}}for(const[k,v]of Object.entries(B))i[k]===void 0&&!Ge(v)&&(i[k]=v);const C=new Set(c.map(k=>k.paramName));for(const[k,v]of Object.entries(T))!C.has(k)&&v&&c.push({paramName:k,value:v});c.length>0&&(i.applicantAdditionalDatas=c);const y=await m(i);s(y.applicantId)}catch(i){console.error("Error creating applicant:",i),oe(i.message||"Failed to create applicant")}finally{G(!1)}},Qe=async i=>{var c;i.preventDefault();for(const C of L)if(Ge(_[C])){const y=((c=He[C])==null?void 0:c.label)||C;oe(`${y} is required.`);return}await Pe()},Oe=(i,c,C,y,k)=>{var yt;const v=He[i];if(!v)return null;const ie=L.includes(i),re=U[i],ge=C||v.label,ue=c??i,ce={required:ie},Te=k?k!=="placeholder":f,ze=Te?ge:void 0,Lr=Te?"...":ge;switch(v.type){case"select":if(i==="country"||i==="nationality"||i==="taxCountry"||i==="countryOfBirth"||i==="mobileCountryCode"){const je=q(i,y);return e.jsx(Ie,{...ce,label:ze,value:_[i]||"",onChange:Ke=>te(i,Ke),options:[{value:"",label:`Select ${Lr.toLowerCase()}`},...je],disabled:ae,error:re},ue)}if(i==="salutation")return e.jsx(Ie,{...ce,label:ze,value:((yt=_[i])==null?void 0:yt.toString())||"",onChange:je=>te(i,je?Number(je):null),options:[{value:"",label:Te?"Select salutation...":ge},{value:st.Male.toString(),label:"Male"},{value:st.Female.toString(),label:"Female"},{value:st.Other.toString(),label:"Other"}],error:re},ue);if(i==="defaultLanguage"){const je=d!=null&&d.allowedLanguages&&d.allowedLanguages.length>0?ct.filter(Ke=>d.allowedLanguages.includes(Ke.value)):ct;return e.jsx(Ie,{...ce,label:ze,value:_[i]||"",onChange:Ke=>te(i,Ke),options:[{value:"",label:Te?"Select language...":ge},...je],error:re},ue)}return null;case"multiselect":if(i==="otherNationality"){const je=q(i,y);return e.jsx(br,{...ce,label:ze,value:_[i]||[],onChange:Ke=>te(i,Ke),options:je,placeholder:Te?"Select other nationalities...":ge,disabled:ae},ue)}return null;case"date":return e.jsx(me,{...ce,type:"date",label:ze,placeholder:Te?void 0:ge,value:_[i]||"",onChange:je=>te(i,je.target.value),error:re},ue);case"email":return e.jsx(me,{...ce,type:"email",label:ze,placeholder:Te?void 0:ge,value:_[i]||"",onChange:je=>te(i,je.target.value),error:re},ue);case"tel":return e.jsx(me,{...ce,type:"tel",label:ze,placeholder:Te?void 0:ge,value:_[i]||"",onChange:je=>te(i,je.target.value),error:re},ue);default:return e.jsx(me,{...ce,type:"text",label:ze,placeholder:Te?void 0:ge,value:_[i]||"",onChange:je=>te(i,je.target.value),error:re},ue)}},Ue=(i,c)=>{const C=i.labelMode?i.labelMode!=="placeholder":f;if(i.customType==="paragraph"){const v=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:v}},`custom-${c}`)}if(i.customType==="html")return e.jsx("div",{dangerouslySetInnerHTML:{__html:i.label||""}},`custom-${c}`);if(i.customType==="br")return e.jsx("div",{style:{height:"12px"}},`custom-${c}`);if(i.customType==="link"){const v=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:[v,e.jsx("span",{style:{fontSize:"10px",opacity:.7},children:"↗"})]})},`custom-${c}`)}if(!i.paramName)return null;const y=U[i.paramName],k=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:Y[i.paramName]==="true",onChange:v=>le(i.paramName,v.target.checked?"true":"false"),className:"metakyc-option-input",style:tt}),e.jsxs("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:[k,i.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),y&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:y})]},`custom-${c}`);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:Y[i.paramName]==="true",onChange:v=>le(i.paramName,v.target.checked?"true":"false"),className:"metakyc-option-input",style:{...tt,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:[k," ",i.linkUrl&&e.jsx("a",{href:i.linkUrl,target:"_blank",rel:"noopener noreferrer",className:"underline",style:{color:"var(--metakyc-primary, #2563eb)"},onClick:v=>v.stopPropagation(),children:i.linkText||i.linkUrl}),i.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),y&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:y})]},`custom-${c}`);if(i.customType==="group_checkbox"){const v=(Y[i.paramName]||"").split(",").filter(Boolean);return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[C&&e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[k,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(ie=>{const re=i.singleSelect?Y[i.paramName]===ie.value:v.includes(ie.value);return e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"checkbox",checked:re,onChange:ge=>{if(i.singleSelect)le(i.paramName,ge.target.checked?ie.value:"");else{const ue=ge.target.checked?[...v,ie.value]:v.filter(ce=>ce!==ie.value);le(i.paramName,ue.join(","))}},className:"metakyc-option-input",style:tt}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:ie.label})]},ie.value)})}),y&&e.jsx("p",{className:"text-red-500 text-xs",children:y})]},`custom-${c}`)}return i.customType==="radio_group"?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[C&&e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[k,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(v=>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:Y[i.paramName]===v.value,onChange:()=>le(i.paramName,v.value),name:`radio-group-${i.paramName}-${c}`,className:"metakyc-option-input",style:tt}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:v.label})]},v.value))}),y&&e.jsx("p",{className:"text-red-500 text-xs",children:y})]},`custom-${c}`):e.jsx(me,{type:"text",label:C?`${k}${i.required?" *":""}`:void 0,placeholder:C?void 0:k,value:Y[i.paramName]||"",onChange:v=>le(i.paramName,v.target.value),required:i.required,error:y},`custom-${c}`)},h=(i,c)=>{const C=ke(i);return e.jsxs("div",{className:"space-y-4",children:[i.conditionalOn&&e.jsx(bt,{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:C,onChange:y=>le(i.conditionalOn,y.target.checked?"true":"false"),className:"metakyc-option-input",style:tt}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",fontWeight:500},children:i.conditionalOn})]})}),C&&e.jsx("div",{className:"grid grid-cols-4 gap-4",children:i.fields.map((y,k)=>{const v=y.colSpan===1?"col-span-1":y.colSpan===2?"col-span-2":y.colSpan===3?"col-span-3":"col-span-4",ie=y.isCustom?`custom-${k}-${y.paramName}`:`builtin-${y.name}-${k}`;return e.jsx("div",{className:v,children:e.jsx(bt,{helpText:y.helpText,children:y.isCustom?Ue(y,k):Oe(y.name,ie,y.displayText,y.countriesType,y.labelMode)})},ie)})})]})};if(!d||ae)return e.jsx("div",{className:"metakyc-sdk",children:e.jsx(V,{children:e.jsxs(Q,{children:[e.jsx(Ne,{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[ne]??j[0],c=fe===-1,C=Fe===-1,y=j.length,k=ke(i),v=Object.values(U);return e.jsx("div",{className:"metakyc-sdk",children:e.jsxs(V,{children:[e.jsx(ye,{children:e.jsx(Xe,{title:(d==null?void 0:d.title)||"Create Applicant"})}),e.jsxs(Q,{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})]}),(pe||v.length>0)&&e.jsxs("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-lg",children:[pe&&e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",pe]}),v.map((ie,re)=>e.jsx("p",{className:"text-red-600 text-sm",children:ie},re))]}),y>1&&e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[j.map((ie,re)=>e.jsx("div",{className:`h-1.5 rounded-full transition-all ${re===ne?"flex-1":"w-8"}`,style:re===ne?{backgroundColor:"var(--metakyc-primary, #2563eb)"}:re<ne?{backgroundColor:"var(--metakyc-primary-light, #93c5fd)",opacity:.7}:{backgroundColor:"#e5e7eb"}},re)),e.jsxs("span",{className:"text-xs text-gray-400 flex-shrink-0",children:[ne+1," / ",y]})]}),h(i)]}),e.jsxs(he,{className:"flex justify-between",children:[e.jsxs("div",{children:[!c&&e.jsx(J,{type:"button",variant:"outline",onClick:()=>{A(fe),ee({})},disabled:I||x,children:"Previous"}),c&&a&&e.jsx(J,{type:"button",variant:"outline",onClick:a,disabled:I||x,children:"Cancel"})]}),e.jsx(J,{type:"button",isLoading:I||x,onClick:C?Pe:Ve,children:C?i.conditionalOn&&!k?"Skip & Submit":"Submit":i.conditionalOn&&!k?"Skip":"Next"})]})]})})}return e.jsx("div",{className:"metakyc-sdk",children:e.jsx("form",{onSubmit:Qe,children:e.jsxs(V,{children:[e.jsx(ye,{children:e.jsx(Xe,{title:(d==null?void 0:d.title)||"Create Applicant"})}),e.jsxs(Q,{children:[pe&&e.jsx("div",{className:"mb-6 p-4 bg-red-50 border border-red-200 rounded-lg",children:e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",pe]})}),e.jsx("div",{className:"grid grid-cols-4 gap-4",children:F.map(i=>e.jsx("div",{className:"col-span-4",children:Oe(i)},i))})]}),e.jsxs(he,{className:"flex justify-between",children:[a&&e.jsx(J,{type:"button",variant:"outline",onClick:a,disabled:I||x,children:"Cancel"}),e.jsx(J,{type:"submit",isLoading:I||x,children:"Create Applicant"})]})]})})})},vt=["companyName","email"];function lt(t){return t==null||t===""||Array.isArray(t)&&t.length===0}const hs=({workflowKey:t,externalRefId:r,onSuccess:s,onCancel:a})=>{var Oe,Ue,h,z,K;const{config:n,baseInformationService:o,currentTheme:d}=we(),{createCompanyApplicant:m,isLoading:x}=pt(),p=t||((Oe=n.applicantForm)==null?void 0:Oe.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 w=r||((Ue=n.applicantForm)==null?void 0:Ue.externalRefId)||"",E=((h=n.applicantForm)==null?void 0:h.email)||"",R=(((z=n.applicantForm)==null?void 0:z.fieldLabelMode)||(d==null?void 0:d.fieldLabelMode)||"label")!=="placeholder",f=l.useMemo(()=>d!=null&&d.companyFormPages&&d.companyFormPages.length>0?d.companyFormPages:null,[d==null?void 0:d.companyFormPages]),j=l.useMemo(()=>{const u=new Set(vt),b=d==null?void 0:d.companyFormRequiredFields;if(b)for(const S of b)u.add(S);if(f)for(const S of f)for(const g of S.fields)!g.isCustom&&g.name&&g.required&&u.add(g.name);return Array.from(u)},[d==null?void 0:d.companyFormRequiredFields,f]),L=l.useMemo(()=>{var u;if(f){const b=f.flatMap(g=>g.fields).filter(g=>!g.isCustom&&g.name).map(g=>g.name),S=new Set(b);for(const g of vt)S.add(g);return Array.from(S)}return(u=n.applicantForm)!=null&&u.visibleFields?n.applicantForm.visibleFields:d!=null&&d.companyFormVisibleFields&&d.companyFormVisibleFields.length>0?d.companyFormVisibleFields:Pt},[(K=n.applicantForm)==null?void 0:K.visibleFields,d==null?void 0:d.companyFormVisibleFields,f]),F=new Set(["countryResidence","addressCountry"]),$=l.useMemo(()=>{var b,S;const u=new Set;if(f)for(const g of f)for(const i of g.fields)!i.isCustom&&i.name&&F.has(i.name)&&u.add(i.countriesType??((b=We[i.name])==null?void 0:b.countriesType));else for(const g of L)F.has(g)&&u.add((S=We[g])==null?void 0:S.countriesType);return u.size===0&&u.add(void 0),Array.from(u)},[L,f]),[P,M]=l.useState({}),[Z,ae]=l.useState(!0),H=l.useRef(new Set),D=l.useRef(new Set);l.useEffect(()=>{if(!d)return;const u=$.filter(g=>{const i=g!=null?String(g):"all";return!D.current.has(i)&&!H.current.has(i)});if(u.length===0){$.every(i=>D.current.has(i!=null?String(i):"all"))&&ae(!1);return}ae(!0);const b=u.map(g=>g!=null?String(g):"all");b.forEach(g=>H.current.add(g)),(async()=>{try{const g=await Promise.all(u.map(async i=>{const c=i!=null?String(i):"all",C=await o.getCountries("",n.locale||"en",i),y=new Set,k=C.map(v=>({value:v.abbreviation3||v.abbreviation,label:v.name})).filter(v=>!v.value||y.has(v.value)?!1:(y.add(v.value),!0));return D.current.add(c),H.current.delete(c),[c,k]}));M(i=>({...i,...Object.fromEntries(g)}))}catch(g){b.forEach(i=>H.current.delete(i)),console.error("Failed to load countries:",g)}finally{$.every(i=>D.current.has(i!=null?String(i):"all"))&&ae(!1)}})()},[$,d]);const W=(u,b)=>{var i;const S=b??((i=We[u])==null?void 0:i.countriesType),g=S!=null?String(S):"all";return P[g]||[]},[q,B]=l.useState({workflowKey:p,companyName:"",email:E,phone:"",registrationNumber:"",countryResidence:"",legalAddress:"",incorporatedOn:"",controlScheme:"",taxId:"",registrationLocation:"",website:"",postalAddress:"",street:"",streetNumber:"",city:"",state:"",postalCode:"",addressCountry:"",lei:"",externalRefId:w}),[_,O]=l.useState({}),[T,Y]=l.useState(0),[X,ne]=l.useState({}),[A,U]=l.useState(null),[ee,pe]=l.useState(!1),oe=(u,b)=>B(S=>({...S,[u]:b})),I=(u,b)=>O(S=>({...S,[u]:b})),G=u=>!u.conditionalOn||_[u.conditionalOn]==="true",te=f&&T<f.length-1?T+1:-1,le=f&&T>0?T-1:-1,ke=u=>{var S;const b={};for(const g of u.fields)if(g.isCustom){if(g.customType==="paragraph"||g.customType==="html"||g.customType==="br"||g.customType==="link")continue;if(g.required&&g.paramName){const i=_[g.paramName],c=g.displayText||g.label||g.paramName;g.customType==="checkbox"||g.customType==="link_checkbox"?i!=="true"&&(b[g.paramName]=`${c} is required.`):(!i||i.trim()==="")&&(b[g.paramName]=`${c} is required.`)}}else if(g.name){const i=g.name;if(j.includes(i)&&lt(q[i])){const c=g.displayText||((S=We[i])==null?void 0:S.label)||i;b[i]=`${c} is required.`}}return b},Fe=async()=>{if(!f)return;const u=f[T];if(u.conditionalOn&&!G(u)){ne({}),te>=0?Y(te):await fe();return}const b=ke(u);if(Object.keys(b).length>0){ne(b);return}ne({}),te>=0?Y(te):await fe()},fe=async()=>{var u;if(f){let b={};for(const S of f)G(S)&&(b={...b,...ke(S)});if(Object.keys(b).length>0){ne(b);return}}pe(!0),U(null);try{const b={workflowKey:q.workflowKey,externalRefId:((u=q.externalRefId)==null?void 0:u.trim())||void 0},S=f?f.filter(c=>G(c)).flatMap(c=>c.fields).filter(c=>!c.isCustom&&c.name).map(c=>c.name):L;for(const c of S){const C=q[c];if(!lt(C))switch(c){case"companyName":b.companyName=C;break;case"email":b.companyEmail=C;break;case"phone":b.companyPhone=C;break;case"registrationNumber":b.companyRegistrationNumber=C;break;case"countryResidence":b.companyCountry=C;break;case"city":b.companyCity=C;break;case"street":b.companyStreet=C;break;case"postalCode":b.companyZip=C;break;default:b[c]=C;break}}const g=[];if(f){for(const c of f)if(G(c))for(const C of c.fields){if(!C.isCustom||!C.paramName||C.customType==="paragraph"||C.customType==="html"||C.customType==="br"||C.customType==="link")continue;const y=_[C.paramName]??"";let k;if(C.customType==="checkbox"||C.customType==="link_checkbox")k=y==="true"?"yes":"no";else if(k=y,!k&&!C.required)continue;g.push({paramName:C.paramName,value:k})}}g.length>0&&(b.applicantAdditionalDatas=g);const i=await m(b);s(i.applicantId)}catch(b){console.error("Error creating company applicant:",b),U(b.message||"Failed to create company applicant")}finally{pe(!1)}},Ye=async u=>{var b;u.preventDefault();for(const S of j)if(lt(q[S])){const g=((b=We[S])==null?void 0:b.label)||S;U(`${g} is required.`);return}await fe()},Ve=(u,b,S,g,i)=>{const c=We[u];if(!c)return null;const C=j.includes(u),y=X[u],k=S||c.label,v=b??u,ie=i?i!=="placeholder":R,re=ie?k:void 0,ge=ie?"...":k;switch(c.type){case"select":if(u==="countryResidence"||u==="addressCountry"){const ue=W(u,g);return e.jsx(Ie,{required:C,label:re,value:q[u]||"",onChange:ce=>oe(u,ce),options:[{value:"",label:`Select ${ge.toLowerCase()}`},...ue],disabled:Z,error:y},v)}return null;case"date":return e.jsx(me,{required:C,type:"date",label:re,placeholder:ie?void 0:k,value:q[u]||"",onChange:ue=>oe(u,ue.target.value),error:y},v);case"email":return e.jsx(me,{required:C,type:"email",label:re,placeholder:ie?void 0:k,value:q[u]||"",onChange:ue=>oe(u,ue.target.value),error:y},v);case"tel":return e.jsx(me,{required:C,type:"tel",label:re,placeholder:ie?void 0:k,value:q[u]||"",onChange:ue=>oe(u,ue.target.value),error:y},v);default:return e.jsx(me,{required:C,type:"text",label:re,placeholder:ie?void 0:k,value:q[u]||"",onChange:ue=>oe(u,ue.target.value),error:y},v)}},Pe=(u,b)=>{if(u.customType==="paragraph")return e.jsx("p",{style:{fontSize:"14px",lineHeight:"1.7",margin:0,color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:u.displayText||u.label||""}},`custom-${b}`);if(u.customType==="html")return e.jsx("div",{dangerouslySetInnerHTML:{__html:u.label||""}},`custom-${b}`);if(u.customType==="br")return e.jsx("div",{style:{height:"12px"}},`custom-${b}`);if(u.customType==="link")return e.jsx("div",{children:e.jsx("a",{href:u.linkUrl||"#",target:"_blank",rel:"noopener noreferrer",style:{color:"var(--metakyc-primary, #2563eb)",fontSize:"14px",textDecoration:"underline"},children:u.displayText||u.label||u.linkText||u.linkUrl||""})},`custom-${b}`);if(!u.paramName)return null;const S=X[u.paramName],g=u.displayText||u.label||u.paramName,i=u.labelMode?u.labelMode!=="placeholder":R;return u.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:_[u.paramName]==="true",onChange:c=>I(u.paramName,c.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:[g,u.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),S&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:S})]},`custom-${b}`):e.jsx(me,{type:"text",label:i?`${g}${u.required?" *":""}`:void 0,placeholder:i?void 0:g,value:_[u.paramName]||"",onChange:c=>I(u.paramName,c.target.value),required:u.required,error:S},`custom-${b}`)},Qe=u=>{const b=G(u);return e.jsxs("div",{className:"space-y-4",children:[u.conditionalOn&&e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:b,onChange:S=>I(u.conditionalOn,S.target.checked?"true":"false"),style:{width:"16px",height:"16px",accentColor:"var(--metakyc-primary, #2563eb)"}}),e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:u.conditionalOn})]}),b&&e.jsx("div",{className:"grid grid-cols-4 gap-4",children:u.fields.map((S,g)=>{const i=S.colSpan===1?"col-span-1":S.colSpan===2?"col-span-2":S.colSpan===3?"col-span-3":"col-span-4",c=S.isCustom?`custom-${g}-${S.paramName}`:`builtin-${S.name}-${g}`;return e.jsx("div",{className:i,children:S.isCustom?Pe(S,g):Ve(S.name,c,S.displayText,S.countriesType,S.labelMode)},c)})})]})};if(!d||Z)return e.jsx("div",{className:"metakyc-sdk",children:e.jsx(V,{children:e.jsxs(Q,{children:[e.jsx(Ne,{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 u=f[T]??f[0],b=le===-1,S=te===-1,g=f.length,i=G(u),c=Object.values(X);return e.jsx("div",{className:"metakyc-sdk",children:e.jsxs(V,{children:[e.jsx(ye,{children:e.jsx(Xe,{title:(d==null?void 0:d.title)||"Company Registration"})}),e.jsxs(Q,{children:[(u.title||u.subtitle)&&e.jsxs("div",{className:"mb-4",children:[u.title&&e.jsx("h3",{className:"font-semibold text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:u.title}),u.subtitle&&e.jsx("p",{className:"text-sm mt-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:u.subtitle})]}),(A||c.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]}),c.map((C,y)=>e.jsx("p",{className:"text-red-600 text-sm",children:C},y))]}),g>1&&e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[f.map((C,y)=>e.jsx("div",{className:`h-1.5 rounded-full transition-all ${y===T?"flex-1":"w-8"}`,style:y===T?{backgroundColor:"var(--metakyc-primary, #2563eb)"}:y<T?{backgroundColor:"var(--metakyc-primary-light, #93c5fd)",opacity:.7}:{backgroundColor:"#e5e7eb"}},y)),e.jsxs("span",{className:"text-xs text-gray-400 flex-shrink-0",children:[T+1," / ",g]})]}),Qe(u)]}),e.jsxs(he,{className:"flex justify-between",children:[e.jsxs("div",{children:[!b&&e.jsx(J,{type:"button",variant:"outline",onClick:()=>{Y(le),ne({})},disabled:ee||x,children:"Previous"}),b&&a&&e.jsx(J,{type:"button",variant:"outline",onClick:a,disabled:ee||x,children:"Cancel"})]}),e.jsx(J,{type:"button",isLoading:ee||x,onClick:S?fe:Fe,children:S?u.conditionalOn&&!i?"Skip & Submit":"Submit":u.conditionalOn&&!i?"Skip":"Next"})]})]})})}return e.jsx("div",{className:"metakyc-sdk",children:e.jsx("form",{onSubmit:Ye,children:e.jsxs(V,{children:[e.jsx(ye,{children:e.jsx(Xe,{title:(d==null?void 0:d.title)||"Company Registration"})}),e.jsxs(Q,{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:L.map(u=>e.jsx("div",{className:"col-span-4",children:Ve(u)},u))})]}),e.jsxs(he,{className:"flex justify-between",children:[a&&e.jsx(J,{type:"button",variant:"outline",onClick:a,disabled:ee||x,children:"Cancel"}),e.jsx(J,{type:"submit",isLoading:ee||x,children:"Register Company"})]})]})})})},xs=({applicantId:t,onComplete:r,onError:s,theme:a="light",className:n})=>{const{progress:o,currentStep:d,steps:m,workflowKey:x,nextWorkflowKey:p,hasWorkflowChanged:w,isLoading:E,error:N,moveBack:R,refreshProgress:f}=pr(t),[j,L]=l.useState(!1);if(l.useEffect(()=>{N&&s&&s(N)},[N,s]),l.useEffect(()=>{o!=null&&o.workflowResult&&r&&r(o.workflowResult)},[o==null?void 0:o.workflowResult,r]),l.useEffect(()=>{a==="dark"?document.documentElement.classList.add("dark"):document.documentElement.classList.remove("dark")},[a]),l.useEffect(()=>{w&&L(!1)},[w]),E||!o)return e.jsx("div",{className:`metakyc-sdk ${n||""}`,children:e.jsx(V,{children:e.jsxs(Q,{children:[e.jsx(Ne,{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(V,{children:e.jsx(Q,{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(V,{children:e.jsx(Q,{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:x})]}),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:()=>L(!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===Ee.Finished||o.status===Ee.OnHold)return e.jsx("div",{className:`metakyc-sdk ${n||""}`,children:e.jsx(dt,{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(!d)return e.jsx("div",{className:`metakyc-sdk ${n||""}`,children:e.jsx(V,{children:e.jsxs(Q,{children:[e.jsx(Ne,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:o.status===Ee.IdentityPending?"Loading identity verification...":"Loading current step..."})]})})});const F=M=>{switch(M){case se.Overview:return"Overview";case se.Questionaries:return"Questionnaire";case se.UploadDocument:return"Documents";case se.IdentitySdk:return"Identity";case se.RiskScoring:return"Risk Assessment";case se.InvestorCategorization:return"Investor Categorization";case se.AppropriatenessTest:return"Appropriateness Test";case se.AdditionalData:return"Additional Data";case se.ManualReview:return"Review";default:return""}},$=()=>{const M=m.filter(D=>D.visibility!==!1),Z=M.findIndex(D=>D.order===d.order),ae=Z>=0?Z+1:1,H=M.length;return e.jsxs("div",{className:"mb-6",children:[e.jsxs("div",{className:"flex items-start justify-between mb-4",children:[e.jsx(Xe,{}),e.jsxs(De,{variant:o.status===1?"info":"success",children:["Step ",ae," of ",H]})]}),e.jsx("div",{className:"flex items-center",children:M.map((D,W)=>{const q=W<Z,B=D.order===d.order,_=q||B;return e.jsxs(l.Fragment,{children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center text-sm font-medium flex-shrink-0",style:_?{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:q?e.jsx("svg",{className:"w-4 h-4",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"})}):W+1}),e.jsx("span",{className:"ml-2 text-sm whitespace-nowrap",style:{fontWeight:B?600:400,color:B?"var(--metakyc-text-primary, #111827)":"var(--metakyc-text-muted, #9ca3af)"},children:D.displayName||D.name||F(D.action)||`Step ${W+1}`})]}),W<M.length-1&&e.jsx("div",{className:"flex-1 h-0.5 mx-3",style:{backgroundColor:q?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}})]},D.order)})})]})},P=()=>{const M={applicantId:t,onComplete:async()=>{await f()},onBack:d.order>0?R:void 0};switch(d.action){case se.Questionaries:return e.jsx(Cr,{...M});case se.UploadDocument:return e.jsx(Er,{...M});case se.Overview:return e.jsx(Rr,{...M});case se.IdentitySdk:return e.jsx(Pr,{...M});case se.RiskScoring:return e.jsx(Ar,{...M});case se.AdditionalData:case se.InvestorCategorization:return e.jsx(Ir,{...M});case se.AppropriatenessTest:return e.jsx(Fr,{...M});case se.ManualReview:return e.jsx(dt,{kycStatus:o.kycStatus,reviewStatus:o.reviewStatus,workflowResult:o.workflowResult,customMessage:o.customMessage});default:return e.jsx(V,{children:e.jsxs(Q,{className:"py-12 text-center",children:[e.jsx("div",{className:"mb-4",children:e.jsx(Ne,{})}),e.jsxs("p",{className:"text-gray-600 dark:text-gray-400 mb-2",children:["Processing step: ",d.title||d.name]}),e.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:["Action type: ",se[d.action]]})]})})}};return e.jsxs("div",{className:`metakyc-sdk ${n||""}`,children:[$(),P()]})};function fs(t){return Me.z.object({questionResults:Me.z.any()}).passthrough()}function gs(t){let r=Me.z.array(Me.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 bs(t){const r={};return t.uploadDocumentFiles.forEach(s=>{const a=`file_${s.id}`;r[a]=gs(s)}),Me.z.object(r)}function vs(t){return Me.z.any()}function ks(t){return Me.z.string().min(1,"This question is required")}function js(t){const r={};return t.appropriatenessQuestions.forEach(s=>{const a=`question_${s.id}`;r[a]=ks()}),Me.z.object(r)}const ws=Me.z.any();exports.ALLOWED_LANGUAGES=ct;exports.ApplicantProgressOnHoldReason=kt;exports.ApplicantProgressStatus=Ee;exports.ApplicantService=Ot;exports.ApplicantStatus=wt;exports.AppropriatenessQuestionType=Rt;exports.AppropriatenessTestService=_t;exports.AppropriatenessTestStep=Fr;exports.Badge=De;exports.BaseInformationService=Kt;exports.Button=J;exports.COMPANY_FIELD_METADATA=We;exports.Card=V;exports.CardContent=Q;exports.CardFooter=he;exports.CardHeader=ye;exports.CountriesType=Le;exports.CreateApplicantForm=ys;exports.CreateCompanyApplicantForm=hs;exports.CriteriaBuiltInType=It;exports.DEFAULT_COMPANY_VISIBLE_FIELDS=Pt;exports.DEFAULT_VISIBLE_FIELDS=Tt;exports.DocumentReviewStatus=Et;exports.EndpointBuilder=Dt;exports.ErrorHandler=Je;exports.EventEmitter=Xt;exports.FIELD_METADATA=He;exports.FileType=Ct;exports.FileUpload=vr;exports.GenderType=st;exports.Header=Xe;exports.HttpClient=Mt;exports.IdentityProviderManager=qe;exports.IdentityService=Ut;exports.IdentityVerificationProvider=Ce;exports.IdentityVerificationStep=Pr;exports.Input=me;exports.InvestorCategorizationService=Wt;exports.InvestorCategorizationStep=Ir;exports.InvestorCategorizationType=be;exports.InvestorCategoryType=Ft;exports.KycProcessStatus=St;exports.KycStatus=_e;exports.KycStatusDisplay=dt;exports.KycWorkflow=xs;exports.Logo=Tr;exports.MetaKYCContext=mt;exports.MetaKYCError=Re;exports.MetaKYCProvider=Hr;exports.MultiSelect=br;exports.OnfidoProvider=ar;exports.OverviewService=$t;exports.OverviewStep=Rr;exports.PhoneInput=kr;exports.QuestionnaireService=zt;exports.QuestionnaireStep=Cr;exports.ReviewStatus=$e;exports.RiskCriteriaType=At;exports.RiskLevel=jt;exports.RiskScoringService=Ht;exports.RiskScoringStep=Ar;exports.SardinAIProvider=nr;exports.SearchableSelect=Ie;exports.Select=ot;exports.Spinner=Ne;exports.StepRouter=tr;exports.SumsubProvider=sr;exports.ThemeManager=ir;exports.ThemePreset=ve;exports.ThemeService=Zt;exports.UploadDocumentService=Bt;exports.UploadDocumentStep=Er;exports.UserType=Nt;exports.ValueDataType=Ae;exports.WorkflowOrchestrator=rr;exports.WorkflowResultType=rt;exports.WorkflowState=er;exports.WorkflowStepAction=se;exports.appropriatenessTestSchema=ws;exports.clearAllStorage=Yr;exports.clearApplicantId=dr;exports.clearWorkflowState=mr;exports.cn=xe;exports.corporateTheme=qt;exports.defaultConfig=Lt;exports.defaultTheme=Se;exports.fileToBase64=or;exports.fintechTheme=Yt;exports.formatFileSize=nt;exports.generateAppropriatenessSchema=js;exports.generateQuestionnaireSchema=fs;exports.generateRiskScoringSchema=vs;exports.generateUploadDocumentSchema=bs;exports.getAcceptString=Wr;exports.getApplicantId=cr;exports.getThemePreset=Ze;exports.getWorkflowState=qr;exports.healthcareTheme=Vt;exports.isScriptLoaded=Br;exports.loadScript=ut;exports.minimalTheme=Gt;exports.modernTheme=Qt;exports.removeScript=_r;exports.saveApplicantId=lr;exports.saveWorkflowState=ur;exports.themePresets=Jt;exports.useApplicant=pt;exports.useAppropriatenessTest=Vr;exports.useIdentityVerification=fr;exports.useKycWorkflow=pr;exports.useMetaKYC=we;exports.useOverview=xr;exports.useQuestionnaire=yr;exports.useRiskScoring=gr;exports.useUploadDocument=hr;exports.validateFileSize=Ur;exports.validateFileType=Kr;
87
+ `,children:[e.jsx("input",{type:"radio",name:`question-${O.id}`,value:Y,checked:N[O.id]===Y,onChange:ne=>W(O.id,ne.target.value),className:"h-4 w-4 text-primary-500 border-gray-300 focus:ring-primary-500",disabled:x}),e.jsx("span",{className:"ml-3 text-gray-700 dark:text-gray-300",children:Y})]},X))})]},O.id)),w&&!$&&e.jsx("div",{className:"p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg",children:e.jsxs("p",{className:"text-red-600 dark:text-red-400 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",w]})}),$&&e.jsx("div",{className:"p-4 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-700 dark:text-yellow-400 text-sm",children:[e.jsx("strong",{children:"Time's up!"})," Your answers are being submitted automatically."]})})]}),e.jsxs(he,{className:"flex justify-between",children:[e.jsx(J,{type:"button",variant:"outline",onClick:s,disabled:x,children:"Cancel"}),e.jsx(J,{type:"submit",isLoading:x,disabled:Object.keys(N).length<n.totalQuestionCount,children:$?"Submitting...":"Submit Test"})]})]})}):e.jsxs(V,{children:[e.jsxs(ye,{children:[e.jsx("h2",{className:"text-lg font-bold text-gray-900 dark:text-white",children:n.displayName}),n.subtitle&&e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-2",children:n.subtitle})]}),e.jsxs(Q,{children:[n.description&&e.jsx("div",{className:"mb-6 p-4 bg-gray-50 dark:bg-gray-800 rounded-lg",children:e.jsx("p",{className:"text-gray-700 dark:text-gray-300",children:n.description})}),e.jsxs("div",{className:"space-y-4 mb-6",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg",children:[e.jsx("span",{className:"text-gray-700 dark:text-gray-300 font-medium",children:"Total Questions:"}),e.jsx(De,{variant:"info",children:n.totalQuestionCount})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg",children:[e.jsx("span",{className:"text-gray-700 dark:text-gray-300 font-medium",children:"Time Limit:"}),e.jsx(De,{variant:"info",children:H(n.testDurationSec)})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg",children:[e.jsx("span",{className:"text-gray-700 dark:text-gray-300 font-medium",children:"Correct Answers Required:"}),e.jsx(De,{variant:"info",children:n.testCorrectAnswerPassLimit})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg",children:[e.jsx("span",{className:"text-gray-700 dark:text-gray-300 font-medium",children:"Attempts Remaining:"}),e.jsx(De,{variant:_>1?"success":"warning",children:_})]})]}),w&&e.jsx("div",{className:"mb-4 p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg",children:e.jsxs("p",{className:"text-red-600 dark:text-red-400 text-sm",children:[e.jsx("strong",{children:"Previous Attempt:"})," ",w]})}),_<=0&&e.jsx("div",{className:"p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg",children:e.jsx("p",{className:"text-red-600 dark:text-red-400",children:"You have used all your attempts. Please contact support for assistance."})})]}),e.jsxs(he,{className:"flex justify-between",children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"button",onClick:D,disabled:_<=0,children:"Start Test"})]})]})},Pr=({applicantId:t,onComplete:r,onBack:s})=>{var Pe,Qe,Oe,Ue;const{applicantService:a,baseInformationService:n,config:o,currentTheme:d}=we(),{identityData:m,provider:x,token:p,isLoading:w,error:E,requestIdentity:N,restartIdentity:R}=fr(t),[f,j]=l.useState(null),[L,I]=l.useState(null),[$,P]=l.useState([]),[M,Z]=l.useState([]),[ae,H]=l.useState(!0),[D,W]=l.useState(!1),[q,B]=l.useState(null),[_,O]=l.useState(!1),T=l.useRef(!1),[Y,X]=l.useState({}),[ne,A]=l.useState({}),U=d!=null&&d.reviewPageFields&&d.reviewPageFields.length>0?d.reviewPageFields[0]:null,ee=!!(d!=null&&d.reviewPageDisabled),pe=l.useRef(!1);pe.current=ee;const oe=Be.useForm({defaultValues:{street:"",streetNumber:"",city:"",zip:"",country:"",nationality:"",phonenumber:""}});l.useEffect(()=>{if(ee){T.current||(T.current=!0,N().then(()=>W(!0)).catch(z=>console.error("[Identity] Auto-request failed:",z)).finally(()=>H(!1)));return}(async()=>{try{const[z,K,u]=await Promise.all([a.getApplicantData(t),n.getCountries("","en"),n.getCountries("","en",40)]);I(z);const b=new Set,S=K.map(y=>({value:y.abbreviation3||y.abbreviation,label:y.name})).filter(y=>!y.value||b.has(y.value)?!1:(b.add(y.value),!0));P(S);const g=new Set,i=u.filter(y=>y.countryCode).map(y=>({value:y.countryCode,label:`${y.countryCode} – ${y.name}`})).filter(y=>g.has(y.value)?!1:(g.add(y.value),!0));Z(i);const c=z.applicantRequestData;if(X({firstName:(c==null?void 0:c.firstName)||"",lastName:(c==null?void 0:c.lastName)||"",email:(c==null?void 0:c.email)||"",dateOfBirth:(c==null?void 0:c.dateOfBirth)||"",title:(c==null?void 0:c.title)||"",salutation:(c==null?void 0:c.salutation)||"",phonenumber:(c==null?void 0:c.phonenumber)||"",mobileCountryCode:(c==null?void 0:c.mobileCountryCode)||"",street:(c==null?void 0:c.street)||"",streetNumber:(c==null?void 0:c.streetNumber)||"",city:(c==null?void 0:c.city)||"",zip:(c==null?void 0:c.zip)||"",country:(c==null?void 0:c.country)||"",nationality:(c==null?void 0:c.nationality)||"",taxCountry:(c==null?void 0:c.taxCountry)||"",countryOfBirth:(c==null?void 0:c.countryOfBirth)||"",placeOfBirth:(c==null?void 0:c.placeOfBirth)||"",educationLevel:(c==null?void 0:c.educationLevel)||"",occupation:(c==null?void 0:c.occupation)||"",taxNumber:(c==null?void 0:c.taxNumber)||"",defaultLanguage:(c==null?void 0:c.defaultLanguage)||""}),oe.reset({street:(c==null?void 0:c.street)||"",streetNumber:(c==null?void 0:c.streetNumber)||"",city:(c==null?void 0:c.city)||"",zip:(c==null?void 0:c.zip)||"",country:(c==null?void 0:c.country)||"",nationality:(c==null?void 0:c.nationality)||"",phonenumber:(c==null?void 0:c.phonenumber)||""}),z.kycRecords&&z.kycRecords.length>0&&z.kycRecords[0].providerTokenObject!==null&&!T.current&&pe.current){console.log("[Identity] Review page disabled + existing identity — auto-requesting..."),T.current=!0;try{await N(),W(!0)}catch(y){console.error("[Identity] Auto-request failed:",y)}}}catch(z){console.error("Error loading applicant data:",z)}finally{H(!1)}})()},[t]),l.useEffect(()=>{m&&!D&&pe.current&&(console.log("[Identity] Review page disabled — showing cached provider"),W(!0))},[m,D]),l.useEffect(()=>{if(p){if(p.expiresAt){const h=new Date(p.expiresAt).getTime();if(Date.now()>=h){console.warn("[Identity] Token has expired (expiresAt)"),O(!0),B("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"),O(!0),B("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"),O(!0),B("Your verification session has expired. Please restart.");return}}},[p]),l.useEffect(()=>{if(x!==null&&p&&!f&&D&&!_){const h=x;if(p.url){console.log("[Identity] Loading provider URL for user verification:",p.url),B(null);try{if(new URL(p.url),h===Ce.SardinAI){console.log("[SardinAI] Initializing Risk SDK in background...");try{const z=qe.parseProviderConfig(x,p,o);qe.createProvider(x,z).initialize().then(()=>{console.log("[SardinAI] Risk SDK initialized successfully in background")}).catch(u=>{console.warn("[SardinAI] Risk SDK initialization failed (non-blocking):",u)})}catch(z){console.warn("[SardinAI] Risk SDK setup failed (non-blocking):",z)}}j({type:"url",url:p.url})}catch(z){console.error("[Identity] Invalid URL:",z),B("Invalid verification URL. Please restart."),O(!0)}return}if(h===Ce.SardinAI){console.log("[SardinAI] No URL provided - initializing Risk SDK only..."),B(null);try{const z=qe.parseProviderConfig(x,p,o),K=qe.createProvider(x,z);K.initialize().then(()=>{console.log("[SardinAI] Risk SDK initialized successfully"),j(K),setTimeout(()=>{r==null||r()},2e3)}).catch(u=>{var S;console.error("[SardinAI] Failed to initialize:",u);const b=((S=u.message)==null?void 0:S.toLowerCase())||"";b.includes("expired")||b.includes("invalid")||b.includes("401")||b.includes("400")?(O(!0),B("Session expired or invalid. Please restart verification.")):B(`Failed to initialize: ${u.message}`)})}catch(z){console.error("[SardinAI] Error creating provider:",z),B(`Configuration error: ${z.message}`)}return}try{B(null);const z=qe.parseProviderConfig(x,p,o),K=qe.createProvider(x,z);h===Ce.Sumsub?(K.initialize("identity-container").catch(u=>{var b;console.error("[Sumsub] Initialization error:",u),B(`Failed to initialize: ${u.message}`),(b=u.message)!=null&&b.toLowerCase().includes("expired")&&O(!0)}),K.onComplete&&K.onComplete(()=>{r==null||r()})):h===Ce.Onfido&&K.initialize("identity-container").catch(u=>{console.error("[Onfido] Initialization error:",u),B(`Failed to initialize: ${u.message}`)}),j(K)}catch(z){console.error("[Identity] Provider setup error:",z),B(`Setup error: ${z.message}`)}}return()=>{if(f&&f.destroy)try{f.destroy()}catch(h){console.error("[Identity] Error destroying provider:",h)}}},[x,p,f,D,r,_]);const F=async()=>{try{B(null),O(!1),await N(),W(!0)}catch(h){console.error("Error starting identity verification:",h)}},G=async()=>{try{B(null),O(!1),j(null),console.log("[Identity] Restarting verification..."),await R(),W(!0)}catch(h){console.error("Error restarting identity verification:",h),B(h.message||"Failed to restart verification")}};if(ae||w)return e.jsx(V,{children:e.jsxs(Q,{children:[e.jsx(Ne,{className:"my-8"}),e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-4",children:"Loading identity verification..."})]})});if(E)return e.jsx(V,{children:e.jsx(Q,{children:e.jsxs("p",{className:"text-danger-500",children:["Error: ",E.message]})})});if(D&&(q||_))return e.jsxs(V,{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(Q,{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:_?"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(he,{className:"flex justify-between",children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"button",onClick:G,disabled:w,children:w?"Restarting...":"Restart Verification"})]})]});if(D&&m){const h=x;return p!=null&&p.url?e.jsxs(V,{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(J,{type:"button",variant:"outline",size:"sm",onClick:G,disabled:w,children:"Restart"})]})}),e.jsxs(Q,{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 K,u,b;console.log("[Identity] Iframe loaded");try{const S=z.target,g=S.contentDocument||((K=S.contentWindow)==null?void 0:K.document);if(g){const i=((b=(u=g.body)==null?void 0:u.textContent)==null?void 0:b.toLowerCase())||"";(i.includes("expired")||i.includes("invalid")||i.includes("error"))&&(console.warn("[Identity] Iframe shows expiration message"),O(!0),B("Your verification link has expired."))}}catch{console.log("[Identity] Cannot check iframe content (CORS)")}}})})]}),s&&e.jsx(he,{children:e.jsx(J,{variant:"outline",onClick:s,children:"Back"})})]}):h===Ce.SardinAI?e.jsxs(V,{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(Q,{children:e.jsxs("div",{className:"text-center py-12",children:[e.jsx(Ne,{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(V,{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(Q,{children:e.jsx("div",{id:"identity-container",className:"min-h-[400px]"})}),s&&e.jsx(he,{children:e.jsx(J,{variant:"outline",onClick:s,children:"Back"})})]})}const te=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),le=(h=4)=>({1:"col-span-1",2:"col-span-2",3:"col-span-3",4:"col-span-4"})[h]||"col-span-4",ke=(h,z)=>{if(!z&&z!==0)return"—";if(te.has(h)&&h!=="mobileCountryCode"){const K=$.find(u=>u.value===z);return K?K.label:String(z)}return String(z)},Ie=({helpText:h})=>{const[z,K]=l.useState(!1),u=l.useRef(null),[,b]=l.useState({top:0,left:0}),S=()=>{if(u.current){const g=u.current.getBoundingClientRect();b({top:g.bottom+window.scrollY+6,left:g.left+window.scrollX})}K(!0)};return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"metakyc-help-btn",ref:u,onClick:S,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&&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:()=>K(!1),children:e.jsxs("div",{onClick:g=>g.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:()=>K(!1),style:{marginTop:12,padding:"4px 12px",fontSize:12,border:"1px solid var(--metakyc-border, #e5e7eb)",borderRadius:"var(--metakyc-border-radius, 6px)",background:"transparent",cursor:"pointer",color:"var(--metakyc-text-secondary, #6b7280)"},children:"Close"})]})}),document.body)]})},fe=(h,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:h}),e.jsx("div",{style:{paddingTop:24},children:e.jsx(Ie,{helpText:z})})]}):h,Ye=(h,z)=>{const K=`cf-${z}`,u=h.paramName??"",b=ne[u];if(h.customType==="br")return e.jsx("div",{className:le(h.colSpan),style:{minHeight:"0.5rem"}},K);if(h.customType==="paragraph")return e.jsx("div",{className:le(h.colSpan),children:e.jsx("div",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:h.label||""}})},K);if(h.customType==="html")return e.jsx("div",{className:le(h.colSpan),dangerouslySetInnerHTML:{__html:h.label||""}},K);if(h.customType==="link")return e.jsx("div",{className:le(h.colSpan),children:fe(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)},K);if(h.customType==="checkbox"||h.customType==="link_checkbox"){const S=b==="true"||b===!0;return e.jsx("div",{className:le(h.colSpan),children:fe(e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:!!S,onChange:g=>A(i=>({...i,[u]:String(g.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)},K)}if(h.customType==="group_checkbox"){const S=Array.isArray(b)?b:b?[b]:[],g=i=>{h.singleSelect?A(c=>({...c,[u]:S[0]===i?[]:[i]})):A(c=>({...c,[u]:S.includes(i)?S.filter(C=>C!==i):[...S,i]}))};return e.jsx("div",{className:le(h.colSpan),children:fe(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:S.includes(i.value),onChange:()=>g(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)},K)}return h.customType==="radio_group"?e.jsx("div",{className:le(h.colSpan),children:fe(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(S=>e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"radio",name:`rg-${u}`,value:S.value,checked:b===S.value,onChange:()=>A(g=>({...g,[u]:S.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:S.label})]},S.value))]}),h.helpText)},K):e.jsx("div",{className:le(h.colSpan),children:fe(e.jsx(me,{label:h.displayText||h.label||u,value:String(b??""),onChange:S=>A(g=>({...g,[u]:S.target.value}))}),h.helpText)},K)},Ve=(h,z)=>{if(h.isCustom)return Ye(h,z);const K=h.name??"",u=He[K],b=h.displayText||(u==null?void 0:u.label)||K,S=Y[K]??"",g=K==="mobileCountryCode",i=!!(u!=null&&u.countriesType)&&!g;return h.editable?g?e.jsx("div",{className:le(h.colSpan??2),children:fe(e.jsx(Fe,{label:b,value:String(S),onChange:c=>X(C=>({...C,[K]:c})),options:[{value:"",label:"Select country code…"},...M]}),h.helpText)},`epc-${z}`):i?e.jsx("div",{className:le(h.colSpan??2),children:fe(e.jsx(Fe,{label:b,value:String(S),onChange:c=>X(C=>({...C,[K]:c})),options:[{value:"",label:`Select ${b.toLowerCase()}…`},...$]}),h.helpText)},`ec-${z}`):e.jsx("div",{className:le(h.colSpan??2),children:fe(e.jsx(me,{label:b,type:(u==null?void 0:u.type)==="date"?"date":(u==null?void 0:u.type)==="email"?"email":"text",value:String(S),onChange:c=>X(C=>({...C,[K]:c.target.value}))}),h.helpText)},`ei-${z}`):e.jsx("div",{className:le(h.colSpan??2),children:fe(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:b}),e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)",minHeight:"1.5rem"},children:ke(K,S)})]}),h.helpText)},`ro-${z}`)};if(U){const h=U.title||"Review Your Information",z=U.subtitle||"Please review and confirm your information before starting identity verification";return e.jsx("form",{onSubmit:K=>{K.preventDefault(),F()},children:e.jsxs(V,{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:z})]}),e.jsx(Q,{children:e.jsx("div",{className:"grid grid-cols-4 gap-4",children:U.fields.map((K,u)=>Ve(K,u))})}),e.jsxs(he,{className:"flex justify-between",children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"submit",isLoading:w,children:"Confirm and Start Verification"})]})]})})}return e.jsx("form",{onSubmit:oe.handleSubmit(F),children:e.jsxs(V,{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(Q,{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:`${((Pe=L==null?void 0:L.applicantRequestData)==null?void 0:Pe.firstName)||""} ${((Qe=L==null?void 0:L.applicantRequestData)==null?void 0:Qe.lastName)||""}`.trim()},{label:"Email",value:(Oe=L==null?void 0:L.applicantRequestData)==null?void 0:Oe.email},{label:"Date of Birth",value:((Ue=L==null?void 0:L.applicantRequestData)==null?void 0:Ue.dateOfBirth)||"Not provided"}].map(({label:h,value:z})=>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:z})]},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(Be.Controller,{control:oe.control,name:"country",render:({field:h})=>e.jsx(Fe,{label:"Country",value:h.value,onChange:h.onChange,options:[{value:"",label:"Select country…"},...$]})}),e.jsx(Be.Controller,{control:oe.control,name:"nationality",render:({field:h})=>e.jsx(Fe,{label:"Nationality",value:h.value,onChange:h.onChange,options:[{value:"",label:"Select nationality…"},...$]})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Be.Controller,{control:oe.control,name:"street",render:({field:h})=>e.jsx(me,{...h,label:"Street"})}),e.jsx(Be.Controller,{control:oe.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(Be.Controller,{control:oe.control,name:"city",render:({field:h})=>e.jsx(me,{...h,label:"City"})}),e.jsx(Be.Controller,{control:oe.control,name:"zip",render:({field:h})=>e.jsx(me,{...h,label:"ZIP / Postal Code"})})]}),e.jsx(Be.Controller,{control:oe.control,name:"phonenumber",render:({field:h})=>e.jsx(me,{...h,label:"Phone Number",type:"tel"})})]})]}),e.jsxs(he,{className:"flex justify-between",children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"submit",isLoading:w,children:"Confirm and Start Verification"})]})]})})},dt=({kycStatus:t,reviewStatus:r,workflowResult:s,customMessage:a,onContinue:n,onContactSupport:o})=>{const m=t===_e.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===_e.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===_e.Pending||t===_e.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===rt.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===rt.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===rt.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(V,{children:[e.jsxs(Q,{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 ${m.iconBg}`,children:e.jsx("span",{className:`text-5xl ${m.iconColor}`,children:m.icon})})}),e.jsx("h2",{className:"text-3xl font-bold text-center mb-4",style:{color:"var(--metakyc-text-primary, #111827)"},children:m.title}),e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx(De,{variant:m.type==="success"?"success":m.type==="error"?"danger":m.type==="pending"?"warning":"info",children:t!=null?_e[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||m.message}),m.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"})]})]}),m.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"})]})]}),m.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?_e[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(he,{className:"flex justify-center gap-4",children:[m.type==="success"&&n&&e.jsx(J,{onClick:n,size:"lg",children:"Continue"}),m.type==="error"&&e.jsxs(e.Fragment,{children:[o&&e.jsx(J,{variant:"outline",onClick:o,children:"Contact Support"}),n&&e.jsx(J,{onClick:n,children:"Try Again"})]}),m.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"})})]})]})},Tr=({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"}})}),Xe=({title:t,subtitle:r,className:s=""})=>{const{currentTheme:a}=we(),n=t||(a==null?void 0:a.title)||"",o=!!(a!=null&&a.logo&&a.logo.visible&&a.logo.url),d=!!n;return!o&&!d?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(Tr,{config:a.logo}),o&&d&&e.jsx("span",{style:{fontSize:"1.5rem",fontWeight:300,color:"var(--metakyc-text-muted, #9ca3af)",margin:"0 12px"},children:"|"}),d&&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 Ge(t){return t==null||t===""||Array.isArray(t)&&t.length===0}const tt={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"},bt=({helpText:t,children:r})=>{const[s,a]=l.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?it.createPortal(n,document.body):null]})},ys=({workflowKey:t,externalRefId:r,onSuccess:s,onCancel:a})=>{var z,K,u,b,S,g;const{config:n,baseInformationService:o,currentTheme:d}=we(),{createApplicant:m,isLoading:x}=pt(),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 CreateApplicantForm or set it in config.applicantForm.workflowKey");const w=r||((K=n.applicantForm)==null?void 0:K.externalRefId)||"",E=((u=n.applicantForm)==null?void 0:u.email)||"",N=((b=n.applicantForm)==null?void 0:b.hiddenValues)||{},f=(((S=n.applicantForm)==null?void 0:S.fieldLabelMode)||(d==null?void 0:d.fieldLabelMode)||"label")!=="placeholder",j=l.useMemo(()=>d!=null&&d.applicantFormPages&&d.applicantFormPages.length>0?d.applicantFormPages:null,[d==null?void 0:d.applicantFormPages]),L=l.useMemo(()=>{const i=new Set(at),c=d==null?void 0:d.applicantFormRequiredFields;if(c)for(const C of c)i.add(C);if(j)for(const C of j)for(const y of C.fields)!y.isCustom&&y.name&&y.required&&i.add(y.name);return Array.from(i)},[d==null?void 0:d.applicantFormRequiredFields,j]),I=l.useMemo(()=>{var C;if(j){const y=j.flatMap(v=>v.fields).filter(v=>!v.isCustom&&v.name).map(v=>v.name),k=new Set(y);for(const v of at)k.add(v);return Array.from(k)}let i;(C=n.applicantForm)!=null&&C.visibleFields?i=n.applicantForm.visibleFields:d!=null&&d.applicantFormVisibleFields&&d.applicantFormVisibleFields.length>0?i=d.applicantFormVisibleFields:i=Tt;const c=new Set(i);for(const y of at)c.add(y);return Array.from(c)},[(g=n.applicantForm)==null?void 0:g.visibleFields,d==null?void 0:d.applicantFormVisibleFields,j]),$=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),P=l.useMemo(()=>{var c,C;const i=new Set;if(j)for(const y of j)for(const k of y.fields)!k.isCustom&&k.name&&$.has(k.name)&&i.add(k.countriesType??((c=He[k.name])==null?void 0:c.countriesType));else for(const y of I)$.has(y)&&i.add((C=He[y])==null?void 0:C.countriesType);return i.size===0&&i.add(void 0),Array.from(i)},[I,j]),[M,Z]=l.useState({}),[ae,H]=l.useState(!0),D=l.useRef(new Set),W=l.useRef(new Set);l.useEffect(()=>{if(!d)return;const i=P.filter(y=>{const k=y!=null?String(y):"all";return!W.current.has(k)&&!D.current.has(k)});if(i.length===0){P.every(k=>{const v=k!=null?String(k):"all";return W.current.has(v)})&&H(!1);return}H(!0);const c=i.map(y=>y!=null?String(y):"all");c.forEach(y=>D.current.add(y)),(async()=>{try{const y=await Promise.all(i.map(async k=>{const v=k!=null?String(k):"all",ie=await o.getCountries("",n.locale||"en",k),re=k===40,ge=new Set,ue=ie.map(ce=>re&&ce.countryCode?{value:ce.countryCode,label:`${ce.countryCode} – ${ce.name}`}:{value:ce.abbreviation3||ce.abbreviation,label:ce.name}).filter(ce=>!ce.value||ge.has(ce.value)?!1:(ge.add(ce.value),!0));return W.current.add(v),D.current.delete(v),[v,ue]}));Z(k=>({...k,...Object.fromEntries(y)}))}catch(y){c.forEach(k=>D.current.delete(k)),console.error("Failed to load countries:",y)}finally{P.every(k=>{const v=k!=null?String(k):"all";return W.current.has(v)})&&H(!1)}})()},[P,d]);const q=(i,c)=>{var k;const C=c??((k=He[i])==null?void 0:k.countriesType),y=C!=null?String(C):"all";return M[y]||[]},B=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})),[_,O]=l.useState({workflowKey:p,firstName:"",lastName:"",title:"",email:E,dateOfBirth:"",phonenumber:"",externalRefId:w,mobileCountryCode:"",street:"",streetNumber:"",zip:"",city:"",country:"",nationality:"",otherNationality:[],defaultLanguage:"EN",taxCountry:"",placeOfBirth:"",countryOfBirth:"",salutation:null,educationLevel:"",occupation:"",taxNumber:"",...B}),T=Object.fromEntries(Object.entries(N).filter(([i])=>!(i in B)&&i!=="externalRefId"&&i!=="workflowKey")),[Y,X]=l.useState({...T}),[ne,A]=l.useState(0),[U,ee]=l.useState({}),[pe,oe]=l.useState(null),[F,G]=l.useState(!1),te=(i,c)=>O(C=>({...C,[i]:c})),le=(i,c)=>X(C=>({...C,[i]:c})),ke=i=>!i.conditionalOn||Y[i.conditionalOn]==="true",Ie=j&&ne<j.length-1?ne+1:-1,fe=j&&ne>0?ne-1:-1,Ye=i=>{var C;const c={};for(const y of i.fields)if(y.isCustom){if(y.customType==="paragraph"||y.customType==="html"||y.customType==="br"||y.customType==="link")continue;if(y.required&&y.paramName){const k=Y[y.paramName],v=y.displayText||y.label||y.paramName;y.customType==="checkbox"||y.customType==="link_checkbox"?k!=="true"&&(c[y.paramName]=`${v} is required.`):(!k||k.trim()==="")&&(c[y.paramName]=`${v} is required.`)}}else if(y.name){const k=y.name;if(L.includes(k)&&Ge(_[k])){const v=y.displayText||((C=He[k])==null?void 0:C.label)||k;c[k]=`${v} is required.`}}return c},Ve=async()=>{if(!j)return;const i=j[ne];if(i.conditionalOn&&!ke(i)){ee({}),Ie>=0?A(Ie):await Pe();return}const c=Ye(i);if(Object.keys(c).length>0){ee(c);return}ee({}),Ie>=0?A(Ie):await Pe()},Pe=async()=>{if(j){let i={};for(const c of j)ke(c)&&(i={...i,...Ye(c)});if(Object.keys(i).length>0){ee(i);return}}G(!0),oe(null);try{if(!_.externalRefId||_.externalRefId.trim()===""){oe("External Reference ID is required. Please pass it via config.applicantForm.externalRefId.");return}const i={workflowKey:_.workflowKey,externalRefId:_.externalRefId.trim()};if(j){for(const k of j)if(ke(k)){for(const v of k.fields)if(!v.isCustom&&v.name){const ie=v.name,re=_[ie];Ge(re)||(i[ie]=re)}}for(const k of at)if(i[k]===void 0){const v=_[k];Ge(v)||(i[k]=v)}}else I.forEach(k=>{if(k==="externalRefId")return;const v=_[k];Ge(v)||(i[k]=v)});const c=[];if(j){for(const k of j)if(ke(k))for(const v of k.fields){if(!v.isCustom||!v.paramName||v.customType==="paragraph"||v.customType==="html"||v.customType==="br"||v.customType==="link")continue;const ie=Y[v.paramName]??"";let re;if(v.customType==="checkbox"||v.customType==="link_checkbox")re=ie==="true"?"yes":"no";else if(re=ie,!re&&!v.required)continue;c.push({paramName:v.paramName,value:re})}}for(const[k,v]of Object.entries(B))i[k]===void 0&&!Ge(v)&&(i[k]=v);const C=new Set(c.map(k=>k.paramName));for(const[k,v]of Object.entries(T))!C.has(k)&&v&&c.push({paramName:k,value:v});c.length>0&&(i.applicantAdditionalDatas=c);const y=await m(i);s(y.applicantId)}catch(i){console.error("Error creating applicant:",i),oe(i.message||"Failed to create applicant")}finally{G(!1)}},Qe=async i=>{var c;i.preventDefault();for(const C of L)if(Ge(_[C])){const y=((c=He[C])==null?void 0:c.label)||C;oe(`${y} is required.`);return}await Pe()},Oe=(i,c,C,y,k)=>{var yt;const v=He[i];if(!v)return null;const ie=L.includes(i),re=U[i],ge=C||v.label,ue=c??i,ce={required:ie},Te=k?k!=="placeholder":f,ze=Te?ge:void 0,Lr=Te?"...":ge;switch(v.type){case"select":if(i==="country"||i==="nationality"||i==="taxCountry"||i==="countryOfBirth"||i==="mobileCountryCode"){const je=q(i,y);return e.jsx(Fe,{...ce,label:ze,value:_[i]||"",onChange:Ke=>te(i,Ke),options:[{value:"",label:`Select ${Lr.toLowerCase()}`},...je],disabled:ae,error:re},ue)}if(i==="salutation")return e.jsx(Fe,{...ce,label:ze,value:((yt=_[i])==null?void 0:yt.toString())||"",onChange:je=>te(i,je?Number(je):null),options:[{value:"",label:Te?"Select salutation...":ge},{value:st.Male.toString(),label:"Male"},{value:st.Female.toString(),label:"Female"},{value:st.Other.toString(),label:"Other"}],error:re},ue);if(i==="defaultLanguage"){const je=d!=null&&d.allowedLanguages&&d.allowedLanguages.length>0?ct.filter(Ke=>d.allowedLanguages.includes(Ke.value)):ct;return e.jsx(Fe,{...ce,label:ze,value:_[i]||"",onChange:Ke=>te(i,Ke),options:[{value:"",label:Te?"Select language...":ge},...je],error:re},ue)}return null;case"multiselect":if(i==="otherNationality"){const je=q(i,y);return e.jsx(br,{...ce,label:ze,value:_[i]||[],onChange:Ke=>te(i,Ke),options:je,placeholder:Te?"Select other nationalities...":ge,disabled:ae},ue)}return null;case"date":return e.jsx(me,{...ce,type:"date",label:ze,placeholder:Te?void 0:ge,value:_[i]||"",onChange:je=>te(i,je.target.value),error:re},ue);case"email":return e.jsx(me,{...ce,type:"email",label:ze,placeholder:Te?void 0:ge,value:_[i]||"",onChange:je=>te(i,je.target.value),error:re},ue);case"tel":return e.jsx(me,{...ce,type:"tel",label:ze,placeholder:Te?void 0:ge,value:_[i]||"",onChange:je=>te(i,je.target.value),error:re},ue);default:return e.jsx(me,{...ce,type:"text",label:ze,placeholder:Te?void 0:ge,value:_[i]||"",onChange:je=>te(i,je.target.value),error:re},ue)}},Ue=(i,c)=>{const C=i.labelMode?i.labelMode!=="placeholder":f;if(i.customType==="paragraph"){const v=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:v}},`custom-${c}`)}if(i.customType==="html")return e.jsx("div",{dangerouslySetInnerHTML:{__html:i.label||""}},`custom-${c}`);if(i.customType==="br")return e.jsx("div",{style:{height:"12px"}},`custom-${c}`);if(i.customType==="link"){const v=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:[v,e.jsx("span",{style:{fontSize:"10px",opacity:.7},children:"↗"})]})},`custom-${c}`)}if(!i.paramName)return null;const y=U[i.paramName],k=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:Y[i.paramName]==="true",onChange:v=>le(i.paramName,v.target.checked?"true":"false"),className:"metakyc-option-input",style:tt}),e.jsxs("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:[k,i.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),y&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:y})]},`custom-${c}`);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:Y[i.paramName]==="true",onChange:v=>le(i.paramName,v.target.checked?"true":"false"),className:"metakyc-option-input",style:{...tt,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:[k," ",i.linkUrl&&e.jsx("a",{href:i.linkUrl,target:"_blank",rel:"noopener noreferrer",className:"underline",style:{color:"var(--metakyc-primary, #2563eb)"},onClick:v=>v.stopPropagation(),children:i.linkText||i.linkUrl}),i.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),y&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:y})]},`custom-${c}`);if(i.customType==="group_checkbox"){const v=(Y[i.paramName]||"").split(",").filter(Boolean);return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[C&&e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[k,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(ie=>{const re=i.singleSelect?Y[i.paramName]===ie.value:v.includes(ie.value);return e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"checkbox",checked:re,onChange:ge=>{if(i.singleSelect)le(i.paramName,ge.target.checked?ie.value:"");else{const ue=ge.target.checked?[...v,ie.value]:v.filter(ce=>ce!==ie.value);le(i.paramName,ue.join(","))}},className:"metakyc-option-input",style:tt}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:ie.label})]},ie.value)})}),y&&e.jsx("p",{className:"text-red-500 text-xs",children:y})]},`custom-${c}`)}return i.customType==="radio_group"?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[C&&e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[k,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(v=>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:Y[i.paramName]===v.value,onChange:()=>le(i.paramName,v.value),name:`radio-group-${i.paramName}-${c}`,className:"metakyc-option-input",style:tt}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:v.label})]},v.value))}),y&&e.jsx("p",{className:"text-red-500 text-xs",children:y})]},`custom-${c}`):e.jsx(me,{type:"text",label:C?`${k}${i.required?" *":""}`:void 0,placeholder:C?void 0:k,value:Y[i.paramName]||"",onChange:v=>le(i.paramName,v.target.value),required:i.required,error:y},`custom-${c}`)},h=(i,c)=>{const C=ke(i);return e.jsxs("div",{className:"space-y-4",children:[i.conditionalOn&&e.jsx(bt,{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:C,onChange:y=>le(i.conditionalOn,y.target.checked?"true":"false"),className:"metakyc-option-input",style:tt}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",fontWeight:500},children:i.conditionalOn})]})}),C&&e.jsx("div",{className:"grid grid-cols-4 gap-4",children:i.fields.map((y,k)=>{const v=y.colSpan===1?"col-span-1":y.colSpan===2?"col-span-2":y.colSpan===3?"col-span-3":"col-span-4",ie=y.isCustom?`custom-${k}-${y.paramName}`:`builtin-${y.name}-${k}`;return e.jsx("div",{className:v,children:e.jsx(bt,{helpText:y.helpText,children:y.isCustom?Ue(y,k):Oe(y.name,ie,y.displayText,y.countriesType,y.labelMode)})},ie)})})]})};if(!d||ae)return e.jsx("div",{className:"metakyc-sdk",children:e.jsx(V,{children:e.jsxs(Q,{children:[e.jsx(Ne,{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[ne]??j[0],c=fe===-1,C=Ie===-1,y=j.length,k=ke(i),v=Object.values(U);return e.jsx("div",{className:"metakyc-sdk",children:e.jsxs(V,{children:[e.jsx(ye,{children:e.jsx(Xe,{title:(d==null?void 0:d.title)||"Create Applicant"})}),e.jsxs(Q,{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})]}),(pe||v.length>0)&&e.jsxs("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-lg",children:[pe&&e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",pe]}),v.map((ie,re)=>e.jsx("p",{className:"text-red-600 text-sm",children:ie},re))]}),y>1&&e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[j.map((ie,re)=>e.jsx("div",{className:`h-1.5 rounded-full transition-all ${re===ne?"flex-1":"w-8"}`,style:re===ne?{backgroundColor:"var(--metakyc-primary, #2563eb)"}:re<ne?{backgroundColor:"var(--metakyc-primary-light, #93c5fd)",opacity:.7}:{backgroundColor:"#e5e7eb"}},re)),e.jsxs("span",{className:"text-xs text-gray-400 flex-shrink-0",children:[ne+1," / ",y]})]}),h(i)]}),e.jsxs(he,{className:"flex justify-between",children:[e.jsxs("div",{children:[!c&&e.jsx(J,{type:"button",variant:"outline",onClick:()=>{A(fe),ee({})},disabled:F||x,children:"Previous"}),c&&a&&e.jsx(J,{type:"button",variant:"outline",onClick:a,disabled:F||x,children:"Cancel"})]}),e.jsx(J,{type:"button",isLoading:F||x,onClick:C?Pe:Ve,children:C?i.conditionalOn&&!k?"Skip & Submit":"Submit":i.conditionalOn&&!k?"Skip":"Next"})]})]})})}return e.jsx("div",{className:"metakyc-sdk",children:e.jsx("form",{onSubmit:Qe,children:e.jsxs(V,{children:[e.jsx(ye,{children:e.jsx(Xe,{title:(d==null?void 0:d.title)||"Create Applicant"})}),e.jsxs(Q,{children:[pe&&e.jsx("div",{className:"mb-6 p-4 bg-red-50 border border-red-200 rounded-lg",children:e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",pe]})}),e.jsx("div",{className:"grid grid-cols-4 gap-4",children:I.map(i=>e.jsx("div",{className:"col-span-4",children:Oe(i)},i))})]}),e.jsxs(he,{className:"flex justify-between",children:[a&&e.jsx(J,{type:"button",variant:"outline",onClick:a,disabled:F||x,children:"Cancel"}),e.jsx(J,{type:"submit",isLoading:F||x,children:"Create Applicant"})]})]})})})},vt=["companyName","email"];function lt(t){return t==null||t===""||Array.isArray(t)&&t.length===0}const hs=({workflowKey:t,externalRefId:r,onSuccess:s,onCancel:a})=>{var Oe,Ue,h,z,K;const{config:n,baseInformationService:o,currentTheme:d}=we(),{createCompanyApplicant:m,isLoading:x}=pt(),p=t||((Oe=n.applicantForm)==null?void 0:Oe.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 w=r||((Ue=n.applicantForm)==null?void 0:Ue.externalRefId)||"",E=((h=n.applicantForm)==null?void 0:h.email)||"",R=(((z=n.applicantForm)==null?void 0:z.fieldLabelMode)||(d==null?void 0:d.fieldLabelMode)||"label")!=="placeholder",f=l.useMemo(()=>d!=null&&d.companyFormPages&&d.companyFormPages.length>0?d.companyFormPages:null,[d==null?void 0:d.companyFormPages]),j=l.useMemo(()=>{const u=new Set(vt),b=d==null?void 0:d.companyFormRequiredFields;if(b)for(const S of b)u.add(S);if(f)for(const S of f)for(const g of S.fields)!g.isCustom&&g.name&&g.required&&u.add(g.name);return Array.from(u)},[d==null?void 0:d.companyFormRequiredFields,f]),L=l.useMemo(()=>{var u;if(f){const b=f.flatMap(g=>g.fields).filter(g=>!g.isCustom&&g.name).map(g=>g.name),S=new Set(b);for(const g of vt)S.add(g);return Array.from(S)}return(u=n.applicantForm)!=null&&u.visibleFields?n.applicantForm.visibleFields:d!=null&&d.companyFormVisibleFields&&d.companyFormVisibleFields.length>0?d.companyFormVisibleFields:Pt},[(K=n.applicantForm)==null?void 0:K.visibleFields,d==null?void 0:d.companyFormVisibleFields,f]),I=new Set(["countryResidence","addressCountry"]),$=l.useMemo(()=>{var b,S;const u=new Set;if(f)for(const g of f)for(const i of g.fields)!i.isCustom&&i.name&&I.has(i.name)&&u.add(i.countriesType??((b=We[i.name])==null?void 0:b.countriesType));else for(const g of L)I.has(g)&&u.add((S=We[g])==null?void 0:S.countriesType);return u.size===0&&u.add(void 0),Array.from(u)},[L,f]),[P,M]=l.useState({}),[Z,ae]=l.useState(!0),H=l.useRef(new Set),D=l.useRef(new Set);l.useEffect(()=>{if(!d)return;const u=$.filter(g=>{const i=g!=null?String(g):"all";return!D.current.has(i)&&!H.current.has(i)});if(u.length===0){$.every(i=>D.current.has(i!=null?String(i):"all"))&&ae(!1);return}ae(!0);const b=u.map(g=>g!=null?String(g):"all");b.forEach(g=>H.current.add(g)),(async()=>{try{const g=await Promise.all(u.map(async i=>{const c=i!=null?String(i):"all",C=await o.getCountries("",n.locale||"en",i),y=new Set,k=C.map(v=>({value:v.abbreviation3||v.abbreviation,label:v.name})).filter(v=>!v.value||y.has(v.value)?!1:(y.add(v.value),!0));return D.current.add(c),H.current.delete(c),[c,k]}));M(i=>({...i,...Object.fromEntries(g)}))}catch(g){b.forEach(i=>H.current.delete(i)),console.error("Failed to load countries:",g)}finally{$.every(i=>D.current.has(i!=null?String(i):"all"))&&ae(!1)}})()},[$,d]);const W=(u,b)=>{var i;const S=b??((i=We[u])==null?void 0:i.countriesType),g=S!=null?String(S):"all";return P[g]||[]},[q,B]=l.useState({workflowKey:p,companyName:"",email:E,phone:"",registrationNumber:"",countryResidence:"",legalAddress:"",incorporatedOn:"",controlScheme:"",taxId:"",registrationLocation:"",website:"",postalAddress:"",street:"",streetNumber:"",city:"",state:"",postalCode:"",addressCountry:"",lei:"",externalRefId:w}),[_,O]=l.useState({}),[T,Y]=l.useState(0),[X,ne]=l.useState({}),[A,U]=l.useState(null),[ee,pe]=l.useState(!1),oe=(u,b)=>B(S=>({...S,[u]:b})),F=(u,b)=>O(S=>({...S,[u]:b})),G=u=>!u.conditionalOn||_[u.conditionalOn]==="true",te=f&&T<f.length-1?T+1:-1,le=f&&T>0?T-1:-1,ke=u=>{var S;const b={};for(const g of u.fields)if(g.isCustom){if(g.customType==="paragraph"||g.customType==="html"||g.customType==="br"||g.customType==="link")continue;if(g.required&&g.paramName){const i=_[g.paramName],c=g.displayText||g.label||g.paramName;g.customType==="checkbox"||g.customType==="link_checkbox"?i!=="true"&&(b[g.paramName]=`${c} is required.`):(!i||i.trim()==="")&&(b[g.paramName]=`${c} is required.`)}}else if(g.name){const i=g.name;if(j.includes(i)&&lt(q[i])){const c=g.displayText||((S=We[i])==null?void 0:S.label)||i;b[i]=`${c} is required.`}}return b},Ie=async()=>{if(!f)return;const u=f[T];if(u.conditionalOn&&!G(u)){ne({}),te>=0?Y(te):await fe();return}const b=ke(u);if(Object.keys(b).length>0){ne(b);return}ne({}),te>=0?Y(te):await fe()},fe=async()=>{var u;if(f){let b={};for(const S of f)G(S)&&(b={...b,...ke(S)});if(Object.keys(b).length>0){ne(b);return}}pe(!0),U(null);try{const b={workflowKey:q.workflowKey,externalRefId:((u=q.externalRefId)==null?void 0:u.trim())||void 0},S=f?f.filter(c=>G(c)).flatMap(c=>c.fields).filter(c=>!c.isCustom&&c.name).map(c=>c.name):L;for(const c of S){const C=q[c];if(!lt(C))switch(c){case"companyName":b.companyName=C;break;case"email":b.companyEmail=C;break;case"phone":b.companyPhone=C;break;case"registrationNumber":b.companyRegistrationNumber=C;break;case"countryResidence":b.companyCountry=C;break;case"city":b.companyCity=C;break;case"street":b.companyStreet=C;break;case"postalCode":b.companyZip=C;break;default:b[c]=C;break}}const g=[];if(f){for(const c of f)if(G(c))for(const C of c.fields){if(!C.isCustom||!C.paramName||C.customType==="paragraph"||C.customType==="html"||C.customType==="br"||C.customType==="link")continue;const y=_[C.paramName]??"";let k;if(C.customType==="checkbox"||C.customType==="link_checkbox")k=y==="true"?"yes":"no";else if(k=y,!k&&!C.required)continue;g.push({paramName:C.paramName,value:k})}}g.length>0&&(b.applicantAdditionalDatas=g);const i=await m(b);s(i.applicantId)}catch(b){console.error("Error creating company applicant:",b),U(b.message||"Failed to create company applicant")}finally{pe(!1)}},Ye=async u=>{var b;u.preventDefault();for(const S of j)if(lt(q[S])){const g=((b=We[S])==null?void 0:b.label)||S;U(`${g} is required.`);return}await fe()},Ve=(u,b,S,g,i)=>{const c=We[u];if(!c)return null;const C=j.includes(u),y=X[u],k=S||c.label,v=b??u,ie=i?i!=="placeholder":R,re=ie?k:void 0,ge=ie?"...":k;switch(c.type){case"select":if(u==="countryResidence"||u==="addressCountry"){const ue=W(u,g);return e.jsx(Fe,{required:C,label:re,value:q[u]||"",onChange:ce=>oe(u,ce),options:[{value:"",label:`Select ${ge.toLowerCase()}`},...ue],disabled:Z,error:y},v)}return null;case"date":return e.jsx(me,{required:C,type:"date",label:re,placeholder:ie?void 0:k,value:q[u]||"",onChange:ue=>oe(u,ue.target.value),error:y},v);case"email":return e.jsx(me,{required:C,type:"email",label:re,placeholder:ie?void 0:k,value:q[u]||"",onChange:ue=>oe(u,ue.target.value),error:y},v);case"tel":return e.jsx(me,{required:C,type:"tel",label:re,placeholder:ie?void 0:k,value:q[u]||"",onChange:ue=>oe(u,ue.target.value),error:y},v);default:return e.jsx(me,{required:C,type:"text",label:re,placeholder:ie?void 0:k,value:q[u]||"",onChange:ue=>oe(u,ue.target.value),error:y},v)}},Pe=(u,b)=>{if(u.customType==="paragraph")return e.jsx("p",{style:{fontSize:"14px",lineHeight:"1.7",margin:0,color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:u.displayText||u.label||""}},`custom-${b}`);if(u.customType==="html")return e.jsx("div",{dangerouslySetInnerHTML:{__html:u.label||""}},`custom-${b}`);if(u.customType==="br")return e.jsx("div",{style:{height:"12px"}},`custom-${b}`);if(u.customType==="link")return e.jsx("div",{children:e.jsx("a",{href:u.linkUrl||"#",target:"_blank",rel:"noopener noreferrer",style:{color:"var(--metakyc-primary, #2563eb)",fontSize:"14px",textDecoration:"underline"},children:u.displayText||u.label||u.linkText||u.linkUrl||""})},`custom-${b}`);if(!u.paramName)return null;const S=X[u.paramName],g=u.displayText||u.label||u.paramName,i=u.labelMode?u.labelMode!=="placeholder":R;return u.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:_[u.paramName]==="true",onChange:c=>F(u.paramName,c.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:[g,u.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),S&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:S})]},`custom-${b}`):e.jsx(me,{type:"text",label:i?`${g}${u.required?" *":""}`:void 0,placeholder:i?void 0:g,value:_[u.paramName]||"",onChange:c=>F(u.paramName,c.target.value),required:u.required,error:S},`custom-${b}`)},Qe=u=>{const b=G(u);return e.jsxs("div",{className:"space-y-4",children:[u.conditionalOn&&e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:b,onChange:S=>F(u.conditionalOn,S.target.checked?"true":"false"),style:{width:"16px",height:"16px",accentColor:"var(--metakyc-primary, #2563eb)"}}),e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:u.conditionalOn})]}),b&&e.jsx("div",{className:"grid grid-cols-4 gap-4",children:u.fields.map((S,g)=>{const i=S.colSpan===1?"col-span-1":S.colSpan===2?"col-span-2":S.colSpan===3?"col-span-3":"col-span-4",c=S.isCustom?`custom-${g}-${S.paramName}`:`builtin-${S.name}-${g}`;return e.jsx("div",{className:i,children:S.isCustom?Pe(S,g):Ve(S.name,c,S.displayText,S.countriesType,S.labelMode)},c)})})]})};if(!d||Z)return e.jsx("div",{className:"metakyc-sdk",children:e.jsx(V,{children:e.jsxs(Q,{children:[e.jsx(Ne,{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 u=f[T]??f[0],b=le===-1,S=te===-1,g=f.length,i=G(u),c=Object.values(X);return e.jsx("div",{className:"metakyc-sdk",children:e.jsxs(V,{children:[e.jsx(ye,{children:e.jsx(Xe,{title:(d==null?void 0:d.title)||"Company Registration"})}),e.jsxs(Q,{children:[(u.title||u.subtitle)&&e.jsxs("div",{className:"mb-4",children:[u.title&&e.jsx("h3",{className:"font-semibold text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:u.title}),u.subtitle&&e.jsx("p",{className:"text-sm mt-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:u.subtitle})]}),(A||c.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]}),c.map((C,y)=>e.jsx("p",{className:"text-red-600 text-sm",children:C},y))]}),g>1&&e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[f.map((C,y)=>e.jsx("div",{className:`h-1.5 rounded-full transition-all ${y===T?"flex-1":"w-8"}`,style:y===T?{backgroundColor:"var(--metakyc-primary, #2563eb)"}:y<T?{backgroundColor:"var(--metakyc-primary-light, #93c5fd)",opacity:.7}:{backgroundColor:"#e5e7eb"}},y)),e.jsxs("span",{className:"text-xs text-gray-400 flex-shrink-0",children:[T+1," / ",g]})]}),Qe(u)]}),e.jsxs(he,{className:"flex justify-between",children:[e.jsxs("div",{children:[!b&&e.jsx(J,{type:"button",variant:"outline",onClick:()=>{Y(le),ne({})},disabled:ee||x,children:"Previous"}),b&&a&&e.jsx(J,{type:"button",variant:"outline",onClick:a,disabled:ee||x,children:"Cancel"})]}),e.jsx(J,{type:"button",isLoading:ee||x,onClick:S?fe:Ie,children:S?u.conditionalOn&&!i?"Skip & Submit":"Submit":u.conditionalOn&&!i?"Skip":"Next"})]})]})})}return e.jsx("div",{className:"metakyc-sdk",children:e.jsx("form",{onSubmit:Ye,children:e.jsxs(V,{children:[e.jsx(ye,{children:e.jsx(Xe,{title:(d==null?void 0:d.title)||"Company Registration"})}),e.jsxs(Q,{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:L.map(u=>e.jsx("div",{className:"col-span-4",children:Ve(u)},u))})]}),e.jsxs(he,{className:"flex justify-between",children:[a&&e.jsx(J,{type:"button",variant:"outline",onClick:a,disabled:ee||x,children:"Cancel"}),e.jsx(J,{type:"submit",isLoading:ee||x,children:"Register Company"})]})]})})})},xs=({applicantId:t,onComplete:r,onError:s,theme:a="light",className:n})=>{const{progress:o,currentStep:d,steps:m,workflowKey:x,nextWorkflowKey:p,hasWorkflowChanged:w,isLoading:E,error:N,moveBack:R,refreshProgress:f}=pr(t),[j,L]=l.useState(!1);if(l.useEffect(()=>{N&&s&&s(N)},[N,s]),l.useEffect(()=>{o!=null&&o.workflowResult&&r&&r(o.workflowResult)},[o==null?void 0:o.workflowResult,r]),l.useEffect(()=>{a==="dark"?document.documentElement.classList.add("dark"):document.documentElement.classList.remove("dark")},[a]),l.useEffect(()=>{w&&L(!1)},[w]),E||!o)return e.jsx("div",{className:`metakyc-sdk ${n||""}`,children:e.jsx(V,{children:e.jsxs(Q,{children:[e.jsx(Ne,{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(V,{children:e.jsx(Q,{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(V,{children:e.jsx(Q,{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:x})]}),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:()=>L(!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===Ee.Finished||o.status===Ee.OnHold)return e.jsx("div",{className:`metakyc-sdk ${n||""}`,children:e.jsx(dt,{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(!d)return e.jsx("div",{className:`metakyc-sdk ${n||""}`,children:e.jsx(V,{children:e.jsxs(Q,{children:[e.jsx(Ne,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:o.status===Ee.IdentityPending?"Loading identity verification...":"Loading current step..."})]})})});const I=M=>{switch(M){case se.Overview:return"Overview";case se.Questionaries:return"Questionnaire";case se.UploadDocument:return"Documents";case se.IdentitySdk:return"Identity";case se.RiskScoring:return"Risk Assessment";case se.InvestorCategorization:return"Investor Categorization";case se.AppropriatenessTest:return"Appropriateness Test";case se.AdditionalData:return"Additional Data";case se.ManualReview:return"Review";default:return""}},$=()=>{const M=m.filter(D=>D.visibility!==!1),Z=M.findIndex(D=>D.order===d.order),ae=Z>=0?Z+1:1,H=M.length;return e.jsxs("div",{className:"mb-6",children:[e.jsxs("div",{className:"flex items-start justify-between mb-4",children:[e.jsx(Xe,{}),e.jsxs(De,{variant:o.status===1?"info":"success",children:["Step ",ae," of ",H]})]}),e.jsx("div",{className:"flex items-center",children:M.map((D,W)=>{const q=W<Z,B=D.order===d.order,_=q||B;return e.jsxs(l.Fragment,{children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center text-sm font-medium flex-shrink-0",style:_?{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:q?e.jsx("svg",{className:"w-4 h-4",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"})}):W+1}),e.jsx("span",{className:"ml-2 text-sm whitespace-nowrap",style:{fontWeight:B?600:400,color:B?"var(--metakyc-text-primary, #111827)":"var(--metakyc-text-muted, #9ca3af)"},children:D.displayName||D.name||I(D.action)||`Step ${W+1}`})]}),W<M.length-1&&e.jsx("div",{className:"flex-1 h-0.5 mx-3",style:{backgroundColor:q?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}})]},D.order)})})]})},P=()=>{const M={applicantId:t,onComplete:async()=>{await f()},onBack:d.order>0?R:void 0};switch(d.action){case se.Questionaries:return e.jsx(Cr,{...M});case se.UploadDocument:return e.jsx(Er,{...M});case se.Overview:return e.jsx(Rr,{...M});case se.IdentitySdk:return e.jsx(Pr,{...M});case se.RiskScoring:return e.jsx(Ar,{...M});case se.AdditionalData:case se.InvestorCategorization:return e.jsx(Fr,{...M});case se.AppropriatenessTest:return e.jsx(Ir,{...M});case se.ManualReview:return e.jsx(dt,{kycStatus:o.kycStatus,reviewStatus:o.reviewStatus,workflowResult:o.workflowResult,customMessage:o.customMessage});default:return e.jsx(V,{children:e.jsxs(Q,{className:"py-12 text-center",children:[e.jsx("div",{className:"mb-4",children:e.jsx(Ne,{})}),e.jsxs("p",{className:"text-gray-600 dark:text-gray-400 mb-2",children:["Processing step: ",d.title||d.name]}),e.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:["Action type: ",se[d.action]]})]})})}};return e.jsxs("div",{className:`metakyc-sdk ${n||""}`,children:[$(),P()]})};function fs(t){return Me.z.object({questionResults:Me.z.any()}).passthrough()}function gs(t){let r=Me.z.array(Me.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 bs(t){const r={};return t.uploadDocumentFiles.forEach(s=>{const a=`file_${s.id}`;r[a]=gs(s)}),Me.z.object(r)}function vs(t){return Me.z.any()}function ks(t){return Me.z.string().min(1,"This question is required")}function js(t){const r={};return t.appropriatenessQuestions.forEach(s=>{const a=`question_${s.id}`;r[a]=ks()}),Me.z.object(r)}const ws=Me.z.any();exports.ALLOWED_LANGUAGES=ct;exports.ApplicantProgressOnHoldReason=kt;exports.ApplicantProgressStatus=Ee;exports.ApplicantService=Ot;exports.ApplicantStatus=wt;exports.AppropriatenessQuestionType=Rt;exports.AppropriatenessTestService=_t;exports.AppropriatenessTestStep=Ir;exports.Badge=De;exports.BaseInformationService=Kt;exports.Button=J;exports.COMPANY_FIELD_METADATA=We;exports.Card=V;exports.CardContent=Q;exports.CardFooter=he;exports.CardHeader=ye;exports.CountriesType=Le;exports.CreateApplicantForm=ys;exports.CreateCompanyApplicantForm=hs;exports.CriteriaBuiltInType=Ft;exports.DEFAULT_COMPANY_VISIBLE_FIELDS=Pt;exports.DEFAULT_VISIBLE_FIELDS=Tt;exports.DocumentReviewStatus=Et;exports.EndpointBuilder=Dt;exports.ErrorHandler=Je;exports.EventEmitter=Xt;exports.FIELD_METADATA=He;exports.FileType=Ct;exports.FileUpload=vr;exports.GenderType=st;exports.Header=Xe;exports.HttpClient=Mt;exports.IdentityProviderManager=qe;exports.IdentityService=Ut;exports.IdentityVerificationProvider=Ce;exports.IdentityVerificationStep=Pr;exports.Input=me;exports.InvestorCategorizationService=Wt;exports.InvestorCategorizationStep=Fr;exports.InvestorCategorizationType=be;exports.InvestorCategoryType=It;exports.KycProcessStatus=St;exports.KycStatus=_e;exports.KycStatusDisplay=dt;exports.KycWorkflow=xs;exports.Logo=Tr;exports.MetaKYCContext=mt;exports.MetaKYCError=Re;exports.MetaKYCProvider=Hr;exports.MultiSelect=br;exports.OnfidoProvider=ar;exports.OverviewService=$t;exports.OverviewStep=Rr;exports.PhoneInput=kr;exports.QuestionnaireService=zt;exports.QuestionnaireStep=Cr;exports.ReviewStatus=$e;exports.RiskCriteriaType=At;exports.RiskLevel=jt;exports.RiskScoringService=Ht;exports.RiskScoringStep=Ar;exports.SardinAIProvider=nr;exports.SearchableSelect=Fe;exports.Select=ot;exports.Spinner=Ne;exports.StepRouter=tr;exports.SumsubProvider=sr;exports.ThemeManager=ir;exports.ThemePreset=ve;exports.ThemeService=Zt;exports.UploadDocumentService=Bt;exports.UploadDocumentStep=Er;exports.UserType=Nt;exports.ValueDataType=Ae;exports.WorkflowOrchestrator=rr;exports.WorkflowResultType=rt;exports.WorkflowState=er;exports.WorkflowStepAction=se;exports.appropriatenessTestSchema=ws;exports.clearAllStorage=Yr;exports.clearApplicantId=dr;exports.clearWorkflowState=mr;exports.cn=xe;exports.corporateTheme=qt;exports.defaultConfig=Lt;exports.defaultTheme=Se;exports.fileToBase64=or;exports.fintechTheme=Yt;exports.formatFileSize=nt;exports.generateAppropriatenessSchema=js;exports.generateQuestionnaireSchema=fs;exports.generateRiskScoringSchema=vs;exports.generateUploadDocumentSchema=bs;exports.getAcceptString=Wr;exports.getApplicantId=cr;exports.getThemePreset=Ze;exports.getWorkflowState=qr;exports.healthcareTheme=Vt;exports.isScriptLoaded=Br;exports.loadScript=ut;exports.minimalTheme=Gt;exports.modernTheme=Qt;exports.removeScript=_r;exports.saveApplicantId=lr;exports.saveWorkflowState=ur;exports.themePresets=Jt;exports.useApplicant=pt;exports.useAppropriatenessTest=Vr;exports.useIdentityVerification=fr;exports.useKycWorkflow=pr;exports.useMetaKYC=we;exports.useOverview=xr;exports.useQuestionnaire=yr;exports.useRiskScoring=gr;exports.useUploadDocument=hr;exports.validateFileSize=Ur;exports.validateFileType=Kr;
88
88
  //# sourceMappingURL=index.cjs.map