@vpdev2/metakyc 1.0.3 → 1.0.4
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/client/config.d.ts +2 -0
- package/dist/client/config.d.ts.map +1 -1
- package/dist/context/MetaKYCProvider.d.ts.map +1 -1
- package/dist/index.cjs +13 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +288 -265
- package/dist/index.js.map +1 -1
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Ur=Object.defineProperty;var Kr=(t,r,s)=>r in t?Ur(t,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[r]=s;var pe=(t,r,s)=>Kr(t,typeof r!="symbol"?r+"":r,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const qr=require("axios"),i=require("react"),e=require("react/jsx-runtime"),pt=require("react-dom"),qe=require("react-hook-form"),We=require("zod");function Vr(t){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(r,s,n.get?n:{enumerable:!0,get:()=>t[s]})}}return r.default=t,Object.freeze(r)}const wt=Vr(i);var oe=(t=>(t[t.IdentitySdk=0]="IdentitySdk",t[t.RiskScoring=1]="RiskScoring",t[t.Questionaries=2]="Questionaries",t[t.AdditionalData=3]="AdditionalData",t[t.AppropriatenessTest=4]="AppropriatenessTest",t[t.UploadDocument=5]="UploadDocument",t[t.ManualReview=6]="ManualReview",t[t.Overview=7]="Overview",t[t.InvestorCategorization=8]="InvestorCategorization",t))(oe||{}),ot=(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))(ot||{}),Te=(t=>(t[t.None=0]="None",t[t.InProgress=1]="InProgress",t[t.Finished=2]="Finished",t[t.OnHold=3]="OnHold",t[t.IdentityPending=4]="IdentityPending",t))(Te||{}),At=(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))(At||{}),Tt=(t=>(t[t.LowRisk=0]="LowRisk",t[t.MediumRisk=1]="MediumRisk",t[t.HighRisk=2]="HighRisk",t[t.Alert=3]="Alert",t))(Tt||{}),Ve=(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))(Ve||{}),Ye=(t=>(t[t.Approved=0]="Approved",t[t.Reject=1]="Reject",t[t.UnderReview=2]="UnderReview",t[t.Closed=3]="Closed",t[t.AdminReview=4]="AdminReview",t[t.New=5]="New",t[t.InProgress=6]="InProgress",t))(Ye||{}),Ft=(t=>(t[t.ProviderResultPending=0]="ProviderResultPending",t[t.ProviderResultReceived=1]="ProviderResultReceived",t[t.Canceled=2]="Canceled",t[t.ExtendedToNewApplicant=3]="ExtendedToNewApplicant",t))(Ft||{}),Pt=(t=>(t[t.None=0]="None",t[t.ProviderResultPending=1]="ProviderResultPending",t[t.ProviderResultReceived=2]="ProviderResultReceived",t[t.Canceled=3]="Canceled",t))(Pt||{}),Ae=(t=>(t[t.Onfido=0]="Onfido",t[t.Sumsub=2]="Sumsub",t[t.SardinAI=3]="SardinAI",t))(Ae||{}),Lt=(t=>(t[t.Individual=0]="Individual",t[t.Company=1]="Company",t))(Lt||{}),lt=(t=>(t[t.Male=0]="Male",t[t.Female=1]="Female",t[t.Other=2]="Other",t))(lt||{}),Mt=(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))(Mt||{}),Dt=(t=>(t[t.Pending=0]="Pending",t[t.Approved=1]="Approved",t[t.Rejected=2]="Rejected",t[t.RequiresRevision=3]="RequiresRevision",t))(Dt||{}),Ot=(t=>(t[t.SingleChoice=0]="SingleChoice",t[t.MultipleChoice=1]="MultipleChoice",t[t.Text=2]="Text",t))(Ot||{}),Me=(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))(Me||{}),zt=(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))(zt||{}),$t=(t=>(t[t.None=0]="None",t[t.Country=1]="Country",t))($t||{}),je=(t=>(t[t.Individual=0]="Individual",t[t.Sophisticated=1]="Sophisticated",t[t.HighNetWorth=2]="HighNetWorth",t[t.Business=3]="Business",t))(je||{}),Bt=(t=>(t[t.Retail=0]="Retail",t[t.Professional=1]="Professional",t[t.EligibleCounterparty=2]="EligibleCounterparty",t))(Bt||{});const He={Nationality:10,Address:20,CountryOfBirth:30,PhoneNumber:40,UboAddress:50},Qe={firstName:{label:"First Name",type:"text"},lastName:{label:"Last Name",type:"text"},email:{label:"Email",type:"email"},phonenumber:{label:"Phone Number",type:"tel"},dateOfBirth:{label:"Date of Birth",type:"date"},salutation:{label:"Salutation",type:"select"},title:{label:"Title",type:"text"},mobileCountryCode:{label:"Mobile Country Code",type:"select",countriesType:He.PhoneNumber},street:{label:"Street",type:"text"},streetNumber:{label:"Street Number",type:"text"},zip:{label:"ZIP / Postal Code",type:"text"},city:{label:"City",type:"text"},country:{label:"Country",type:"select",countriesType:He.Address},nationality:{label:"Nationality",type:"select",countriesType:He.Nationality},otherNationality:{label:"Other Nationalities",type:"multiselect",countriesType:He.Nationality},countryOfBirth:{label:"Country of Birth",type:"select",countriesType:He.CountryOfBirth},placeOfBirth:{label:"Place of Birth",type:"text"},taxCountry:{label:"Tax Country",type:"select",countriesType:He.Address},taxNumber:{label:"Tax Number",type:"text"},defaultLanguage:{label:"Default Language",type:"select"},educationLevel:{label:"Education Level",type:"text"},occupation:{label:"Occupation",type:"text"}},Ze={companyName:{label:"Company Name",type:"text"},email:{label:"Email",type:"email"},phone:{label:"Phone",type:"tel"},registrationNumber:{label:"Registration Number",type:"text"},countryResidence:{label:"Country of Residence",type:"select",countriesType:He.Address},legalAddress:{label:"Legal Address",type:"text"},incorporatedOn:{label:"Incorporation Date",type:"date"},controlScheme:{label:"Control Scheme",type:"text"},taxId:{label:"Tax ID",type:"text"},registrationLocation:{label:"Registration Location",type:"text"},website:{label:"Website",type:"text"},postalAddress:{label:"Postal Address",type:"text"},street:{label:"Street",type:"text"},streetNumber:{label:"Street Number",type:"text"},city:{label:"City",type:"text"},state:{label:"State / Province",type:"text"},postalCode:{label:"Postal Code",type:"text"},addressCountry:{label:"Address Country",type:"select",countriesType:He.Address},lei:{label:"LEI",type:"text"}},_t=["companyName","email","phone","registrationNumber"],Ht=["firstName","lastName","email","phonenumber","dateOfBirth"],ht=[{value:"EN",label:"English"},{value:"DE",label:"German"},{value:"FR",label:"French"},{value:"ES",label:"Spanish"},{value:"IT",label:"Italian"},{value:"PT",label:"Portuguese"},{value:"NL",label:"Dutch"},{value:"PL",label:"Polish"},{value:"RU",label:"Russian"},{value:"ZH",label:"Chinese"},{value:"JA",label:"Japanese"},{value:"AR",label:"Arabic"},{value:"TR",label:"Turkish"},{value:"SV",label:"Swedish"},{value:"DA",label:"Danish"},{value:"FI",label:"Finnish"},{value:"NO",label:"Norwegian"}];var we=(t=>(t.Default="default",t.Corporate="corporate",t.Fintech="fintech",t.Healthcare="healthcare",t.Modern="modern",t.Minimal="minimal",t))(we||{});const Wt={timeout:3e4,retries:3,locale:"en",endpoints:{pattern:"host-controller"}};class Ut{constructor(r){this.config=r}build(r,s){const n=`${r}.${s}`;if(this.config.customPaths&&this.config.customPaths[n])return this.config.customPaths[n];switch(this.config.pattern){case"host-controller":return`/api/${r}/${s}`;case"application-service":return`/services/app/${this.getServiceName(r)}/${s}`;case"custom":throw new Error(`Custom endpoint path not found for ${n}. Please provide it in customPaths.`);default:throw new Error(`Unknown endpoint pattern: ${this.config.pattern}`)}}getServiceName(r){return{Applicant:"MetaKYCVerification",Questionnaire:"MetaKYCVerification",UploadDocument:"MetaKYCVerification",AppropriatenessTest:"MetaKYCVerification",BaseInformation:"MetaKYCVerification"}[r]||r}}class Le extends Error{constructor(s,n,a,o,c){super(s);pe(this,"response");this.code=n,this.details=a,this.validationErrors=o,this.name="MetaKYCError",this.response=c,Object.setPrototypeOf(this,Le.prototype)}}class rt{static handleApiError(r){return new Le(r.message||"An unknown error occurred",r.code,r.details||void 0,r.validationErrors||void 0)}static handleAxiosError(r){if(r.response){const s=r.response.data;return s&&s.error?new Le(s.error.message||"An unknown error occurred",s.error.code,s.error.details||void 0,s.error.validationErrors||void 0,r.response):s&&s.result&&s.result.message?new Le(s.result.message,r.response.status,`HTTP ${r.response.status}: ${r.response.statusText}`,void 0,r.response):new Le((s==null?void 0:s.message)||r.message||"Request failed",r.response.status,`HTTP ${r.response.status}: ${r.response.statusText}`,void 0,r.response)}else return r.request?new Le("No response from server",0,"The request was made but no response was received. Please check your network connection."):new Le(r.message||"An unexpected error occurred",0,r.toString())}static isMetaKYCError(r){return r instanceof Le}}class Kt{constructor(r){pe(this,"axiosInstance");pe(this,"endpointBuilder");pe(this,"config");this.config={...Wt,...r},this.endpointBuilder=new Ut(this.config.endpoints),this.axiosInstance=qr.create({baseURL:this.config.baseUrl,timeout:this.config.timeout,headers:{"Content-Type":"application/json"}}),this.axiosInstance.interceptors.request.use(s=>{if(s.headers["Abp-TenantId"]=this.config.tenantId.toString(),this.config.getAccessToken){const n=this.config.getAccessToken();n&&(s.headers.Authorization=`Bearer ${n}`)}else this.config.apiKey&&(s.headers.ApiKey=this.config.apiKey,s.headers["X-API-KEY"]=this.config.apiKey);return this.config.locale&&(s.headers["Accept-Language"]=this.config.locale),s},s=>Promise.reject(s)),this.axiosInstance.interceptors.response.use(s=>s,async s=>{var a;const n=s.config;return((a=s.response)==null?void 0:a.status)>=500&&!n._retry&&(n._retry=!0,n._retryCount=(n._retryCount||0)+1,n._retryCount<(this.config.retries||3))?(await new Promise(o=>setTimeout(o,1e3*n._retryCount)),this.axiosInstance(n)):Promise.reject(s)})}buildEndpoint(r,s){return this.endpointBuilder.build(r,s)}async get(r,s,n){try{const a=this.buildEndpoint(r,s),o=await this.axiosInstance.get(a,{params:n});return this.handleResponse(o)}catch(a){throw rt.handleAxiosError(a)}}async post(r,s,n){try{const a=this.buildEndpoint(r,s),o=await this.axiosInstance.post(a,n);return this.handleResponse(o)}catch(a){throw rt.handleAxiosError(a)}}async put(r,s,n){try{const a=this.buildEndpoint(r,s),o=await this.axiosInstance.put(a,n);return this.handleResponse(o)}catch(a){throw rt.handleAxiosError(a)}}async delete(r,s,n){try{const a=this.buildEndpoint(r,s),o=await this.axiosInstance.delete(a,{params:n});return this.handleResponse(o)}catch(a){throw rt.handleAxiosError(a)}}handleResponse(r){const s=r.data;if(!s.success&&s.error)throw rt.handleApiError(s.error);return s}getAxiosInstance(){return this.axiosInstance}}class qt{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 Vt{constructor(r){this.httpClient=r}async getQuestionnaire(r){return(await this.httpClient.get("Questionnaire","GetQuestionnaire",{applicantid:r})).result}async fillQuestionnaire(r){return(await this.httpClient.post("Applicant","FillQuestionnarie",r)).result}}class Yt{constructor(r){this.httpClient=r}async getUploadDocument(r){return(await this.httpClient.get("UploadDocument","GetUploadDocument",{applicantid:r})).result}async fillUploadDocument(r){await this.httpClient.post("Applicant","FillUploadDocument",r)}async reviewUploadDocument(r){await this.httpClient.post("UploadDocument","ReviewUploadDocument",r)}}class Qt{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 Gt{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 Jt{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 Zt{constructor(r){this.httpClient=r}async identityRequest(r){console.log("[IdentityService] Calling IdentityRequest with input:",r);const s=await this.httpClient.post("Applicant","IdentityRequest",r);return console.log("[IdentityService] IdentityRequest response:",s),s.result}async identityCompanyRequest(r){return(await this.httpClient.post("Applicant","IdentityCompanyRequest",r)).result}async restartIdentityRequest(r){const s={applicantId:r,restart:!0,redirectUrl:"",ttl:604800};return console.log("[IdentityService] Restarting identity with restart=true:",s),this.identityRequest(s)}async restartIdentityCompanyRequest(r){const s={applicantId:r,restart:!0,redirectUrl:"",ttl:604800};return this.identityCompanyRequest(s)}async refreshSumsubToken(r){console.log("[IdentityService] Refreshing Sumsub token for applicant:",r);const s=await this.httpClient.post("Applicant","RefreshSumsubToken",{applicantId:r});return console.log("[IdentityService] Sumsub token refresh result:",s),s.result.accessToken}}class Xt{constructor(r){this.httpClient=r}async getCountries(r,s,n){return(await this.httpClient.get("BaseInformation","GetAllCountries",{filter:r||"",lng:s||"en",type:n})).result}async getBranches(){return(await this.httpClient.get("BaseInformation","GetBranches")).result}async getLegalEntities(){return(await this.httpClient.get("BaseInformation","GetLegalEntities")).result}}class er{constructor(r){this.httpClient=r}async setInvestorCategorization(r){return(await this.httpClient.post("Applicant","SetInvestorCategorization",r)).result}async getInvestorCategorization(r){return(await this.httpClient.get("Applicant","GetInvestorCategorisation",{applicantId:r})).result}}const Re={name:"Default",title:"KYC Verification",logo:{url:"",height:"40px",visible:!0},colors:{primary:"#2563eb",primaryHover:"#1d4ed8",primaryLight:"#dbeafe",primaryDark:"#1e40af",secondary:"#64748b",secondaryHover:"#475569",success:"#10b981",warning:"#f59e0b",danger:"#ef4444",info:"#3b82f6",background:"#ffffff",surface:"#f9fafb",border:"#e5e7eb",textPrimary:"#111827",textSecondary:"#6b7280",textMuted:"#9ca3af"},typography:{fontFamily:"Inter, system-ui, -apple-system, sans-serif",fontSize:{xs:"0.75rem",sm:"0.875rem",base:"1rem",lg:"1.125rem",xl:"1.25rem","2xl":"1.5rem","3xl":"1.875rem"},fontWeight:{normal:400,medium:500,semibold:600,bold:700}},spacing:{borderRadius:"0.5rem",cardPadding:"1.5rem",inputHeight:"2.5rem"},darkMode:{colors:{background:"#111827",surface:"#1f2937",border:"#374151",textPrimary:"#f9fafb",textSecondary:"#d1d5db",textMuted:"#9ca3af"}}},tr={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"}},rr={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"}},sr={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"}}},nr={name:"Modern",logo:{url:"",height:"38px",visible:!0},colors:{primary:"#8B5CF6",primaryHover:"#7C3AED",primaryLight:"#EDE9FE",primaryDark:"#6D28D9",secondary:"#EC4899",secondaryHover:"#DB2777",success:"#10B981",warning:"#F59E0B",danger:"#EF4444",info:"#3B82F6",background:"#ffffff",surface:"#FAFAFA",border:"#E5E5E5",textPrimary:"#171717",textSecondary:"#737373",textMuted:"#A3A3A3"},typography:{fontFamily:"Poppins, system-ui, sans-serif"},spacing:{borderRadius:"1rem",cardPadding:"2rem",inputHeight:"3rem"}},ar={name:"Minimal",logo:{url:"",height:"32px",visible:!0},colors:{primary:"#000000",primaryHover:"#18181B",primaryLight:"#F4F4F5",primaryDark:"#000000",secondary:"#71717A",secondaryHover:"#52525B",success:"#22C55E",warning:"#EAB308",danger:"#EF4444",info:"#3B82F6",background:"#ffffff",surface:"#FAFAFA",border:"#E4E4E7",textPrimary:"#09090B",textSecondary:"#71717A",textMuted:"#A1A1AA"},typography:{fontFamily:"system-ui, -apple-system, sans-serif"},spacing:{borderRadius:"0.25rem",cardPadding:"1.25rem",inputHeight:"2.25rem"}},ir={[we.Default]:Re,[we.Corporate]:tr,[we.Fintech]:rr,[we.Healthcare]:sr,[we.Modern]:nr,[we.Minimal]:ar};function st(t){return ir[t]||Re}class or{constructor(r){this.httpClient=r}async getThemeConfiguration(){var r;try{const s=await this.httpClient.get("Tenant","GetThemeConfiguration");if(!s.result.isEnabled)return st(we.Default);let n=s.result.preset?st(s.result.preset):st(we.Default);if(s.result.title&&(n.title=s.result.title),s.result.logo&&(n.logo={...n.logo,...s.result.logo}),s.result.colors&&(n.colors={...n.colors,...s.result.colors}),s.result.typography&&(n.typography={...n.typography,...s.result.typography}),s.result.spacing&&(n.spacing={...n.spacing,...s.result.spacing}),s.result.customCSS&&(n.customCSS=s.result.customCSS),s.result.darkMode&&(n.darkMode={colors:{...(r=n.darkMode)==null?void 0:r.colors,...s.result.darkMode.colors}}),s.result.applicantFormVisibleFields&&s.result.applicantFormVisibleFields.length>0&&(n.applicantFormVisibleFields=s.result.applicantFormVisibleFields),s.result.applicantFormRequiredFields&&s.result.applicantFormRequiredFields.length>0&&(n.applicantFormRequiredFields=s.result.applicantFormRequiredFields),s.result.allowedLanguages&&s.result.allowedLanguages.length>0&&(n.allowedLanguages=s.result.allowedLanguages),s.result.applicantFormPages)try{const a=typeof s.result.applicantFormPages=="string"?JSON.parse(s.result.applicantFormPages):s.result.applicantFormPages;Array.isArray(a)&&a.length>0&&(n.applicantFormPages=a.map(o=>{const c=!o._v||o._v<4;return{...o,fields:(o.fields||[]).map(d=>({...d,colSpan:c?d.colSpan===1?2:4:Math.min(4,Math.max(1,d.colSpan??4))}))}}))}catch{}if(s.result.reviewPageFields)try{const a=typeof s.result.reviewPageFields=="string"?JSON.parse(s.result.reviewPageFields):s.result.reviewPageFields;Array.isArray(a)&&a.length>0&&(n.reviewPageFields=a)}catch{}if(s.result.reviewPageDisabled&&(n.reviewPageDisabled=!0),s.result.fieldLabelMode==="placeholder"&&(n.fieldLabelMode="placeholder"),s.result.companyFormVisibleFields&&s.result.companyFormVisibleFields.length>0&&(n.companyFormVisibleFields=s.result.companyFormVisibleFields),s.result.companyFormRequiredFields&&s.result.companyFormRequiredFields.length>0&&(n.companyFormRequiredFields=s.result.companyFormRequiredFields),s.result.companyFormPages)try{const a=typeof s.result.companyFormPages=="string"?JSON.parse(s.result.companyFormPages):s.result.companyFormPages;Array.isArray(a)&&a.length>0&&(n.companyFormPages=a.map(o=>{const c=!o._v||o._v<4;return{...o,fields:(o.fields||[]).map(d=>({...d,colSpan:c?d.colSpan===1?2:4:Math.min(4,Math.max(1,d.colSpan??4))}))}}))}catch{}if(s.result.companyReviewPageFields)try{const a=typeof s.result.companyReviewPageFields=="string"?JSON.parse(s.result.companyReviewPageFields):s.result.companyReviewPageFields;Array.isArray(a)&&a.length>0&&(n.companyReviewPageFields=a)}catch{}return n}catch(s){return console.warn("[ThemeService] Failed to fetch theme configuration:",s),st(we.Default)}}async saveThemeConfiguration(r){await this.httpClient.post("Tenant","SaveThemeConfiguration",r)}getAvailablePresets(){return[{id:we.Default,name:"Default"},{id:we.Corporate,name:"Corporate"},{id:we.Fintech,name:"Fintech"},{id:we.Healthcare,name:"Healthcare"},{id:we.Modern,name:"Modern"},{id:we.Minimal,name:"Minimal"}]}getPreviewTheme(r,s){const n=st(r);return s?{...n,...s,logo:{...n.logo,...s.logo},colors:{...n.colors,...s.colors},typography:s.typography?{...n.typography,...s.typography}:n.typography,spacing:s.spacing?{...n.spacing,...s.spacing}:n.spacing}:n}}class lr{constructor(){pe(this,"listeners",new Map)}on(r,s){return this.listeners.has(r)||this.listeners.set(r,new Set),this.listeners.get(r).add(s),()=>{this.off(r,s)}}off(r,s){const n=this.listeners.get(r);n&&n.delete(s)}emit(r,s){const n=this.listeners.get(r);n&&n.forEach(a=>{try{a(s)}catch(o){console.error(`Error in event listener for "${r}":`,o)}})}clear(){this.listeners.clear()}clearEvent(r){this.listeners.delete(r)}}class cr{constructor(){pe(this,"events",new lr);pe(this,"_applicantId",null);pe(this,"_progress",null);pe(this,"_error",null)}get applicantId(){return this._applicantId}get progress(){return this._progress}get currentStep(){var r;return((r=this._progress)==null?void 0:r.currentStep)||null}get steps(){var r;return((r=this._progress)==null?void 0:r.stepInfoList)||[]}get status(){var r;return((r=this._progress)==null?void 0:r.status)||Te.None}get workflowResult(){var r;return((r=this._progress)==null?void 0:r.workflowResult)||null}get error(){return this._error}get isComplete(){return this.status===Te.Finished}get isOnHold(){return this.status===Te.OnHold}get isInProgress(){return this.status===Te.InProgress}setApplicantId(r){this._applicantId=r}updateProgress(r){var n,a;const s=(n=this._progress)==null?void 0:n.currentStep;this._progress=r,this._applicantId=r.applicantId,this._error=null,this.events.emit("progressUpdated",r),(s==null?void 0:s.order)!==((a=r.currentStep)==null?void 0:a.order)&&this.events.emit("stepChanged",r.currentStep),this.events.emit("statusChanged",r.status),r.status===Te.Finished&&r.workflowResult&&this.events.emit("completed",r.workflowResult)}setError(r){this._error=r,this.events.emit("error",r)}clearError(){this._error=null}reset(){this._applicantId=null,this._progress=null,this._error=null}onProgressUpdated(r){return this.events.on("progressUpdated",r)}onStepChanged(r){return this.events.on("stepChanged",r)}onStatusChanged(r){return this.events.on("statusChanged",r)}onError(r){return this.events.on("error",r)}onCompleted(r){return this.events.on("completed",r)}clearListeners(){this.events.clear()}}class dr{constructor(){pe(this,"handlers",new Map)}registerHandler(r,s){this.handlers.set(r,s)}getHandler(r){return this.handlers.get(r)}hasHandler(r){return this.handlers.has(r)}async loadStepData(r,s){const n=this.getHandler(r);if(!n)throw new Error(`No handler registered for step action: ${oe[r]}`);return n.loadData(s)}async submitStepData(r,s){const n=this.getHandler(r);if(!n)throw new Error(`No handler registered for step action: ${oe[r]}`);return n.submitData(s)}}class ur{constructor(r,s,n,a,o,c,d,y){pe(this,"state");pe(this,"stepRouter");this.applicantService=r,this.questionnaireService=s,this.uploadDocumentService=n,this.appropriatenessTestService=a,this.overviewService=o,this.riskScoringService=c,this.investorCategorizationService=y,this.state=new cr,this.stepRouter=new dr,this.registerStepHandlers()}registerStepHandlers(){this.stepRouter.registerHandler(oe.Questionaries,{loadData:r=>this.questionnaireService.getQuestionnaire(r),submitData:async r=>{await this.questionnaireService.fillQuestionnaire(r)}}),this.stepRouter.registerHandler(oe.UploadDocument,{loadData:r=>this.uploadDocumentService.getUploadDocument(r),submitData:r=>this.uploadDocumentService.fillUploadDocument(r)}),this.stepRouter.registerHandler(oe.AppropriatenessTest,{loadData:r=>this.appropriatenessTestService.getAppropriatenessTest(r),submitData:async r=>{await this.appropriatenessTestService.fillAppropriatenessTest(r)}}),this.stepRouter.registerHandler(oe.Overview,{loadData:r=>this.overviewService.getOverviewData(r),submitData:r=>this.overviewService.passOverview(r.applicantId)}),this.stepRouter.registerHandler(oe.RiskScoring,{loadData:r=>this.riskScoringService.getRiskCriterias(r),submitData:async r=>{await this.riskScoringService.submitRiskScoring(r)}}),this.stepRouter.registerHandler(oe.IdentitySdk,{loadData:async r=>({applicantId:r,message:"Identity verification required"}),submitData:async()=>{}}),this.stepRouter.registerHandler(oe.InvestorCategorization,{loadData:r=>this.investorCategorizationService.getInvestorCategorization(r),submitData:async r=>{await this.investorCategorizationService.setInvestorCategorization(r)}}),this.stepRouter.registerHandler(oe.ManualReview,{loadData:async r=>({applicantId:r,message:"Your application is under manual review"}),submitData:async()=>{}}),this.stepRouter.registerHandler(oe.AdditionalData,{loadData:async r=>({applicantId:r,message:"Additional data required"}),submitData:async()=>{}})}async initialize(r){try{this.state.setApplicantId(r);const s=await this.applicantService.getProgress(r);return this.state.updateProgress(s),s}catch(s){throw this.state.setError(s),s}}async refreshProgress(){if(!this.state.applicantId)throw new Error("Workflow not initialized. Call initialize() first.");try{const r=await this.applicantService.getProgress(this.state.applicantId);return this.state.updateProgress(r),r}catch(r){throw this.state.setError(r),r}}async getCurrentStepData(){if(!this.state.currentStep)throw new Error("No current step available");if(!this.state.applicantId)throw new Error("Workflow not initialized");try{return await this.stepRouter.loadStepData(this.state.currentStep.action,this.state.applicantId)}catch(r){throw this.state.setError(r),r}}async submitCurrentStep(r){if(!this.state.currentStep)throw new Error("No current step available");try{await this.stepRouter.submitStepData(this.state.currentStep.action,r),await this.refreshProgress()}catch(s){throw this.state.setError(s),s}}async moveToNextStep(){return this.refreshProgress()}async moveToPreviousStep(){if(!this.state.applicantId)throw new Error("Workflow not initialized");try{return await this.applicantService.progressStepBack(this.state.applicantId),await this.refreshProgress()}catch(r){throw this.state.setError(r),r}}getState(){return this.state}getStepRouter(){return this.stepRouter}}function gt(t,r){return new Promise((s,n)=>{if(r&&document.getElementById(r)){s();return}const a=document.createElement("script");a.src=t,r&&(a.id=r),a.async=!0,a.onload=()=>s(),a.onerror=()=>n(new Error(`Failed to load script: ${t}`)),document.head.appendChild(a)})}function Yr(t){return!!document.getElementById(t)}function Qr(t){const r=document.getElementById(t);r&&r.remove()}const Gr="https://static.sumsub.com/idensic/static/sns-websdk-builder.js";function Be(t,r){try{return getComputedStyle(document.documentElement).getPropertyValue(t).trim()||r}catch{return r}}function Jr(){const t=Be("--metakyc-primary","#2563eb"),r=Be("--metakyc-primary-hover","#1d4ed8"),s=Be("--metakyc-background","#ffffff"),n=Be("--metakyc-surface","#f9fafb"),a=Be("--metakyc-text-primary","#111827"),o=Be("--metakyc-text-secondary","#6b7280"),c=Be("--metakyc-text-muted","#9ca3af"),d=Be("--metakyc-border","#e5e7eb");return`
|
|
1
|
+
"use strict";var Kr=Object.defineProperty;var qr=(t,r,s)=>r in t?Kr(t,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[r]=s;var pe=(t,r,s)=>qr(t,typeof r!="symbol"?r+"":r,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Vr=require("axios"),i=require("react"),e=require("react/jsx-runtime"),pt=require("react-dom"),qe=require("react-hook-form"),We=require("zod");function Yr(t){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(r,s,n.get?n:{enumerable:!0,get:()=>t[s]})}}return r.default=t,Object.freeze(r)}const wt=Yr(i);var oe=(t=>(t[t.IdentitySdk=0]="IdentitySdk",t[t.RiskScoring=1]="RiskScoring",t[t.Questionaries=2]="Questionaries",t[t.AdditionalData=3]="AdditionalData",t[t.AppropriatenessTest=4]="AppropriatenessTest",t[t.UploadDocument=5]="UploadDocument",t[t.ManualReview=6]="ManualReview",t[t.Overview=7]="Overview",t[t.InvestorCategorization=8]="InvestorCategorization",t))(oe||{}),ot=(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))(ot||{}),Te=(t=>(t[t.None=0]="None",t[t.InProgress=1]="InProgress",t[t.Finished=2]="Finished",t[t.OnHold=3]="OnHold",t[t.IdentityPending=4]="IdentityPending",t))(Te||{}),At=(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))(At||{}),Tt=(t=>(t[t.LowRisk=0]="LowRisk",t[t.MediumRisk=1]="MediumRisk",t[t.HighRisk=2]="HighRisk",t[t.Alert=3]="Alert",t))(Tt||{}),Ve=(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))(Ve||{}),Ye=(t=>(t[t.Approved=0]="Approved",t[t.Reject=1]="Reject",t[t.UnderReview=2]="UnderReview",t[t.Closed=3]="Closed",t[t.AdminReview=4]="AdminReview",t[t.New=5]="New",t[t.InProgress=6]="InProgress",t))(Ye||{}),Ft=(t=>(t[t.ProviderResultPending=0]="ProviderResultPending",t[t.ProviderResultReceived=1]="ProviderResultReceived",t[t.Canceled=2]="Canceled",t[t.ExtendedToNewApplicant=3]="ExtendedToNewApplicant",t))(Ft||{}),Pt=(t=>(t[t.None=0]="None",t[t.ProviderResultPending=1]="ProviderResultPending",t[t.ProviderResultReceived=2]="ProviderResultReceived",t[t.Canceled=3]="Canceled",t))(Pt||{}),Ae=(t=>(t[t.Onfido=0]="Onfido",t[t.Sumsub=2]="Sumsub",t[t.SardinAI=3]="SardinAI",t))(Ae||{}),Lt=(t=>(t[t.Individual=0]="Individual",t[t.Company=1]="Company",t))(Lt||{}),lt=(t=>(t[t.Male=0]="Male",t[t.Female=1]="Female",t[t.Other=2]="Other",t))(lt||{}),Dt=(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))(Dt||{}),Mt=(t=>(t[t.Pending=0]="Pending",t[t.Approved=1]="Approved",t[t.Rejected=2]="Rejected",t[t.RequiresRevision=3]="RequiresRevision",t))(Mt||{}),Ot=(t=>(t[t.SingleChoice=0]="SingleChoice",t[t.MultipleChoice=1]="MultipleChoice",t[t.Text=2]="Text",t))(Ot||{}),De=(t=>(t[t.String=0]="String",t[t.Integer=1]="Integer",t[t.Money=2]="Money",t[t.Boolean=3]="Boolean",t[t.Date=4]="Date",t[t.Country=5]="Country",t[t.DigitOnly=6]="DigitOnly",t))(De||{}),zt=(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))(zt||{}),$t=(t=>(t[t.None=0]="None",t[t.Country=1]="Country",t))($t||{}),je=(t=>(t[t.Individual=0]="Individual",t[t.Sophisticated=1]="Sophisticated",t[t.HighNetWorth=2]="HighNetWorth",t[t.Business=3]="Business",t))(je||{}),Bt=(t=>(t[t.Retail=0]="Retail",t[t.Professional=1]="Professional",t[t.EligibleCounterparty=2]="EligibleCounterparty",t))(Bt||{});const He={Nationality:10,Address:20,CountryOfBirth:30,PhoneNumber:40,UboAddress:50},Qe={firstName:{label:"First Name",type:"text"},lastName:{label:"Last Name",type:"text"},email:{label:"Email",type:"email"},phonenumber:{label:"Phone Number",type:"tel"},dateOfBirth:{label:"Date of Birth",type:"date"},salutation:{label:"Salutation",type:"select"},title:{label:"Title",type:"text"},mobileCountryCode:{label:"Mobile Country Code",type:"select",countriesType:He.PhoneNumber},street:{label:"Street",type:"text"},streetNumber:{label:"Street Number",type:"text"},zip:{label:"ZIP / Postal Code",type:"text"},city:{label:"City",type:"text"},country:{label:"Country",type:"select",countriesType:He.Address},nationality:{label:"Nationality",type:"select",countriesType:He.Nationality},otherNationality:{label:"Other Nationalities",type:"multiselect",countriesType:He.Nationality},countryOfBirth:{label:"Country of Birth",type:"select",countriesType:He.CountryOfBirth},placeOfBirth:{label:"Place of Birth",type:"text"},taxCountry:{label:"Tax Country",type:"select",countriesType:He.Address},taxNumber:{label:"Tax Number",type:"text"},defaultLanguage:{label:"Default Language",type:"select"},educationLevel:{label:"Education Level",type:"text"},occupation:{label:"Occupation",type:"text"}},Ze={companyName:{label:"Company Name",type:"text"},email:{label:"Email",type:"email"},phone:{label:"Phone",type:"tel"},registrationNumber:{label:"Registration Number",type:"text"},countryResidence:{label:"Country of Residence",type:"select",countriesType:He.Address},legalAddress:{label:"Legal Address",type:"text"},incorporatedOn:{label:"Incorporation Date",type:"date"},controlScheme:{label:"Control Scheme",type:"text"},taxId:{label:"Tax ID",type:"text"},registrationLocation:{label:"Registration Location",type:"text"},website:{label:"Website",type:"text"},postalAddress:{label:"Postal Address",type:"text"},street:{label:"Street",type:"text"},streetNumber:{label:"Street Number",type:"text"},city:{label:"City",type:"text"},state:{label:"State / Province",type:"text"},postalCode:{label:"Postal Code",type:"text"},addressCountry:{label:"Address Country",type:"select",countriesType:He.Address},lei:{label:"LEI",type:"text"}},_t=["companyName","email","phone","registrationNumber"],Ht=["firstName","lastName","email","phonenumber","dateOfBirth"],ht=[{value:"EN",label:"English"},{value:"DE",label:"German"},{value:"FR",label:"French"},{value:"ES",label:"Spanish"},{value:"IT",label:"Italian"},{value:"PT",label:"Portuguese"},{value:"NL",label:"Dutch"},{value:"PL",label:"Polish"},{value:"RU",label:"Russian"},{value:"ZH",label:"Chinese"},{value:"JA",label:"Japanese"},{value:"AR",label:"Arabic"},{value:"TR",label:"Turkish"},{value:"SV",label:"Swedish"},{value:"DA",label:"Danish"},{value:"FI",label:"Finnish"},{value:"NO",label:"Norwegian"}];var we=(t=>(t.Default="default",t.Corporate="corporate",t.Fintech="fintech",t.Healthcare="healthcare",t.Modern="modern",t.Minimal="minimal",t))(we||{});const Wt={timeout:3e4,retries:3,locale:"en",endpoints:{pattern:"host-controller"}};class Ut{constructor(r){this.config=r}build(r,s){const n=`${r}.${s}`;if(this.config.customPaths&&this.config.customPaths[n])return this.config.customPaths[n];switch(this.config.pattern){case"host-controller":return`/api/${r}/${s}`;case"application-service":return`/services/app/${this.getServiceName(r)}/${s}`;case"custom":throw new Error(`Custom endpoint path not found for ${n}. Please provide it in customPaths.`);default:throw new Error(`Unknown endpoint pattern: ${this.config.pattern}`)}}getServiceName(r){return{Applicant:"MetaKYCVerification",Questionnaire:"MetaKYCVerification",UploadDocument:"MetaKYCVerification",AppropriatenessTest:"MetaKYCVerification",BaseInformation:"MetaKYCVerification"}[r]||r}}class Le extends Error{constructor(s,n,a,o,c){super(s);pe(this,"response");this.code=n,this.details=a,this.validationErrors=o,this.name="MetaKYCError",this.response=c,Object.setPrototypeOf(this,Le.prototype)}}class rt{static handleApiError(r){return new Le(r.message||"An unknown error occurred",r.code,r.details||void 0,r.validationErrors||void 0)}static handleAxiosError(r){if(r.response){const s=r.response.data;return s&&s.error?new Le(s.error.message||"An unknown error occurred",s.error.code,s.error.details||void 0,s.error.validationErrors||void 0,r.response):s&&s.result&&s.result.message?new Le(s.result.message,r.response.status,`HTTP ${r.response.status}: ${r.response.statusText}`,void 0,r.response):new Le((s==null?void 0:s.message)||r.message||"Request failed",r.response.status,`HTTP ${r.response.status}: ${r.response.statusText}`,void 0,r.response)}else return r.request?new Le("No response from server",0,"The request was made but no response was received. Please check your network connection."):new Le(r.message||"An unexpected error occurred",0,r.toString())}static isMetaKYCError(r){return r instanceof Le}}class Kt{constructor(r){pe(this,"axiosInstance");pe(this,"endpointBuilder");pe(this,"config");this.config={...Wt,...r},this.endpointBuilder=new Ut(this.config.endpoints),this.axiosInstance=Vr.create({baseURL:this.config.baseUrl,timeout:this.config.timeout,headers:{"Content-Type":"application/json"}}),this.axiosInstance.interceptors.request.use(s=>{if(s.headers["Abp-TenantId"]=this.config.tenantId.toString(),this.config.getAccessToken){const n=this.config.getAccessToken();n&&(s.headers.Authorization=`Bearer ${n}`)}else this.config.apiKey&&(s.headers.ApiKey=this.config.apiKey,s.headers["X-API-KEY"]=this.config.apiKey);return this.config.locale&&(s.headers["Accept-Language"]=this.config.locale),s},s=>Promise.reject(s)),this.axiosInstance.interceptors.response.use(s=>s,async s=>{var a;const n=s.config;return((a=s.response)==null?void 0:a.status)>=500&&!n._retry&&(n._retry=!0,n._retryCount=(n._retryCount||0)+1,n._retryCount<(this.config.retries||3))?(await new Promise(o=>setTimeout(o,1e3*n._retryCount)),this.axiosInstance(n)):Promise.reject(s)})}buildEndpoint(r,s){return this.endpointBuilder.build(r,s)}async get(r,s,n){try{const a=this.buildEndpoint(r,s),o=await this.axiosInstance.get(a,{params:n});return this.handleResponse(o)}catch(a){throw rt.handleAxiosError(a)}}async post(r,s,n){try{const a=this.buildEndpoint(r,s),o=await this.axiosInstance.post(a,n);return this.handleResponse(o)}catch(a){throw rt.handleAxiosError(a)}}async put(r,s,n){try{const a=this.buildEndpoint(r,s),o=await this.axiosInstance.put(a,n);return this.handleResponse(o)}catch(a){throw rt.handleAxiosError(a)}}async delete(r,s,n){try{const a=this.buildEndpoint(r,s),o=await this.axiosInstance.delete(a,{params:n});return this.handleResponse(o)}catch(a){throw rt.handleAxiosError(a)}}handleResponse(r){const s=r.data;if(!s.success&&s.error)throw rt.handleApiError(s.error);return s}getAxiosInstance(){return this.axiosInstance}}class qt{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 Vt{constructor(r){this.httpClient=r}async getQuestionnaire(r){return(await this.httpClient.get("Questionnaire","GetQuestionnaire",{applicantid:r})).result}async fillQuestionnaire(r){return(await this.httpClient.post("Applicant","FillQuestionnarie",r)).result}}class Yt{constructor(r){this.httpClient=r}async getUploadDocument(r){return(await this.httpClient.get("UploadDocument","GetUploadDocument",{applicantid:r})).result}async fillUploadDocument(r){await this.httpClient.post("Applicant","FillUploadDocument",r)}async reviewUploadDocument(r){await this.httpClient.post("UploadDocument","ReviewUploadDocument",r)}}class Qt{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 Gt{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 Jt{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 Zt{constructor(r){this.httpClient=r}async identityRequest(r){console.log("[IdentityService] Calling IdentityRequest with input:",r);const s=await this.httpClient.post("Applicant","IdentityRequest",r);return console.log("[IdentityService] IdentityRequest response:",s),s.result}async identityCompanyRequest(r){return(await this.httpClient.post("Applicant","IdentityCompanyRequest",r)).result}async restartIdentityRequest(r){const s={applicantId:r,restart:!0,redirectUrl:"",ttl:604800};return console.log("[IdentityService] Restarting identity with restart=true:",s),this.identityRequest(s)}async restartIdentityCompanyRequest(r){const s={applicantId:r,restart:!0,redirectUrl:"",ttl:604800};return this.identityCompanyRequest(s)}async refreshSumsubToken(r){console.log("[IdentityService] Refreshing Sumsub token for applicant:",r);const s=await this.httpClient.post("Applicant","RefreshSumsubToken",{applicantId:r});return console.log("[IdentityService] Sumsub token refresh result:",s),s.result.accessToken}}class Xt{constructor(r){this.httpClient=r}async getCountries(r,s,n){return(await this.httpClient.get("BaseInformation","GetAllCountries",{filter:r||"",lng:s||"en",type:n})).result}async getBranches(){return(await this.httpClient.get("BaseInformation","GetBranches")).result}async getLegalEntities(){return(await this.httpClient.get("BaseInformation","GetLegalEntities")).result}}class er{constructor(r){this.httpClient=r}async setInvestorCategorization(r){return(await this.httpClient.post("Applicant","SetInvestorCategorization",r)).result}async getInvestorCategorization(r){return(await this.httpClient.get("Applicant","GetInvestorCategorisation",{applicantId:r})).result}}const Re={name:"Default",title:"KYC Verification",logo:{url:"",height:"40px",visible:!0},colors:{primary:"#2563eb",primaryHover:"#1d4ed8",primaryLight:"#dbeafe",primaryDark:"#1e40af",secondary:"#64748b",secondaryHover:"#475569",success:"#10b981",warning:"#f59e0b",danger:"#ef4444",info:"#3b82f6",background:"#ffffff",surface:"#f9fafb",border:"#e5e7eb",textPrimary:"#111827",textSecondary:"#6b7280",textMuted:"#9ca3af"},typography:{fontFamily:"Inter, system-ui, -apple-system, sans-serif",fontSize:{xs:"0.75rem",sm:"0.875rem",base:"1rem",lg:"1.125rem",xl:"1.25rem","2xl":"1.5rem","3xl":"1.875rem"},fontWeight:{normal:400,medium:500,semibold:600,bold:700}},spacing:{borderRadius:"0.5rem",cardPadding:"1.5rem",inputHeight:"2.5rem"},darkMode:{colors:{background:"#111827",surface:"#1f2937",border:"#374151",textPrimary:"#f9fafb",textSecondary:"#d1d5db",textMuted:"#9ca3af"}}},tr={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"}},rr={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"}},sr={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"}}},nr={name:"Modern",logo:{url:"",height:"38px",visible:!0},colors:{primary:"#8B5CF6",primaryHover:"#7C3AED",primaryLight:"#EDE9FE",primaryDark:"#6D28D9",secondary:"#EC4899",secondaryHover:"#DB2777",success:"#10B981",warning:"#F59E0B",danger:"#EF4444",info:"#3B82F6",background:"#ffffff",surface:"#FAFAFA",border:"#E5E5E5",textPrimary:"#171717",textSecondary:"#737373",textMuted:"#A3A3A3"},typography:{fontFamily:"Poppins, system-ui, sans-serif"},spacing:{borderRadius:"1rem",cardPadding:"2rem",inputHeight:"3rem"}},ar={name:"Minimal",logo:{url:"",height:"32px",visible:!0},colors:{primary:"#000000",primaryHover:"#18181B",primaryLight:"#F4F4F5",primaryDark:"#000000",secondary:"#71717A",secondaryHover:"#52525B",success:"#22C55E",warning:"#EAB308",danger:"#EF4444",info:"#3B82F6",background:"#ffffff",surface:"#FAFAFA",border:"#E4E4E7",textPrimary:"#09090B",textSecondary:"#71717A",textMuted:"#A1A1AA"},typography:{fontFamily:"system-ui, -apple-system, sans-serif"},spacing:{borderRadius:"0.25rem",cardPadding:"1.25rem",inputHeight:"2.25rem"}},ir={[we.Default]:Re,[we.Corporate]:tr,[we.Fintech]:rr,[we.Healthcare]:sr,[we.Modern]:nr,[we.Minimal]:ar};function st(t){return ir[t]||Re}class or{constructor(r){this.httpClient=r}async getThemeConfiguration(){var r;try{const s=await this.httpClient.get("Tenant","GetThemeConfiguration");if(!s.result.isEnabled)return st(we.Default);let n=s.result.preset?st(s.result.preset):st(we.Default);if(s.result.title&&(n.title=s.result.title),s.result.logo&&(n.logo={...n.logo,...s.result.logo}),s.result.colors&&(n.colors={...n.colors,...s.result.colors}),s.result.typography&&(n.typography={...n.typography,...s.result.typography}),s.result.spacing&&(n.spacing={...n.spacing,...s.result.spacing}),s.result.customCSS&&(n.customCSS=s.result.customCSS),s.result.darkMode&&(n.darkMode={colors:{...(r=n.darkMode)==null?void 0:r.colors,...s.result.darkMode.colors}}),s.result.applicantFormVisibleFields&&s.result.applicantFormVisibleFields.length>0&&(n.applicantFormVisibleFields=s.result.applicantFormVisibleFields),s.result.applicantFormRequiredFields&&s.result.applicantFormRequiredFields.length>0&&(n.applicantFormRequiredFields=s.result.applicantFormRequiredFields),s.result.allowedLanguages&&s.result.allowedLanguages.length>0&&(n.allowedLanguages=s.result.allowedLanguages),s.result.applicantFormPages)try{const a=typeof s.result.applicantFormPages=="string"?JSON.parse(s.result.applicantFormPages):s.result.applicantFormPages;Array.isArray(a)&&a.length>0&&(n.applicantFormPages=a.map(o=>{const c=!o._v||o._v<4;return{...o,fields:(o.fields||[]).map(d=>({...d,colSpan:c?d.colSpan===1?2:4:Math.min(4,Math.max(1,d.colSpan??4))}))}}))}catch{}if(s.result.reviewPageFields)try{const a=typeof s.result.reviewPageFields=="string"?JSON.parse(s.result.reviewPageFields):s.result.reviewPageFields;Array.isArray(a)&&a.length>0&&(n.reviewPageFields=a)}catch{}if(s.result.reviewPageDisabled&&(n.reviewPageDisabled=!0),s.result.fieldLabelMode==="placeholder"&&(n.fieldLabelMode="placeholder"),s.result.companyFormVisibleFields&&s.result.companyFormVisibleFields.length>0&&(n.companyFormVisibleFields=s.result.companyFormVisibleFields),s.result.companyFormRequiredFields&&s.result.companyFormRequiredFields.length>0&&(n.companyFormRequiredFields=s.result.companyFormRequiredFields),s.result.companyFormPages)try{const a=typeof s.result.companyFormPages=="string"?JSON.parse(s.result.companyFormPages):s.result.companyFormPages;Array.isArray(a)&&a.length>0&&(n.companyFormPages=a.map(o=>{const c=!o._v||o._v<4;return{...o,fields:(o.fields||[]).map(d=>({...d,colSpan:c?d.colSpan===1?2:4:Math.min(4,Math.max(1,d.colSpan??4))}))}}))}catch{}if(s.result.companyReviewPageFields)try{const a=typeof s.result.companyReviewPageFields=="string"?JSON.parse(s.result.companyReviewPageFields):s.result.companyReviewPageFields;Array.isArray(a)&&a.length>0&&(n.companyReviewPageFields=a)}catch{}return n}catch(s){return console.warn("[ThemeService] Failed to fetch theme configuration:",s),st(we.Default)}}async saveThemeConfiguration(r){await this.httpClient.post("Tenant","SaveThemeConfiguration",r)}getAvailablePresets(){return[{id:we.Default,name:"Default"},{id:we.Corporate,name:"Corporate"},{id:we.Fintech,name:"Fintech"},{id:we.Healthcare,name:"Healthcare"},{id:we.Modern,name:"Modern"},{id:we.Minimal,name:"Minimal"}]}getPreviewTheme(r,s){const n=st(r);return s?{...n,...s,logo:{...n.logo,...s.logo},colors:{...n.colors,...s.colors},typography:s.typography?{...n.typography,...s.typography}:n.typography,spacing:s.spacing?{...n.spacing,...s.spacing}:n.spacing}:n}}class lr{constructor(){pe(this,"listeners",new Map)}on(r,s){return this.listeners.has(r)||this.listeners.set(r,new Set),this.listeners.get(r).add(s),()=>{this.off(r,s)}}off(r,s){const n=this.listeners.get(r);n&&n.delete(s)}emit(r,s){const n=this.listeners.get(r);n&&n.forEach(a=>{try{a(s)}catch(o){console.error(`Error in event listener for "${r}":`,o)}})}clear(){this.listeners.clear()}clearEvent(r){this.listeners.delete(r)}}class cr{constructor(){pe(this,"events",new lr);pe(this,"_applicantId",null);pe(this,"_progress",null);pe(this,"_error",null)}get applicantId(){return this._applicantId}get progress(){return this._progress}get currentStep(){var r;return((r=this._progress)==null?void 0:r.currentStep)||null}get steps(){var r;return((r=this._progress)==null?void 0:r.stepInfoList)||[]}get status(){var r;return((r=this._progress)==null?void 0:r.status)||Te.None}get workflowResult(){var r;return((r=this._progress)==null?void 0:r.workflowResult)||null}get error(){return this._error}get isComplete(){return this.status===Te.Finished}get isOnHold(){return this.status===Te.OnHold}get isInProgress(){return this.status===Te.InProgress}setApplicantId(r){this._applicantId=r}updateProgress(r){var n,a;const s=(n=this._progress)==null?void 0:n.currentStep;this._progress=r,this._applicantId=r.applicantId,this._error=null,this.events.emit("progressUpdated",r),(s==null?void 0:s.order)!==((a=r.currentStep)==null?void 0:a.order)&&this.events.emit("stepChanged",r.currentStep),this.events.emit("statusChanged",r.status),r.status===Te.Finished&&r.workflowResult&&this.events.emit("completed",r.workflowResult)}setError(r){this._error=r,this.events.emit("error",r)}clearError(){this._error=null}reset(){this._applicantId=null,this._progress=null,this._error=null}onProgressUpdated(r){return this.events.on("progressUpdated",r)}onStepChanged(r){return this.events.on("stepChanged",r)}onStatusChanged(r){return this.events.on("statusChanged",r)}onError(r){return this.events.on("error",r)}onCompleted(r){return this.events.on("completed",r)}clearListeners(){this.events.clear()}}class dr{constructor(){pe(this,"handlers",new Map)}registerHandler(r,s){this.handlers.set(r,s)}getHandler(r){return this.handlers.get(r)}hasHandler(r){return this.handlers.has(r)}async loadStepData(r,s){const n=this.getHandler(r);if(!n)throw new Error(`No handler registered for step action: ${oe[r]}`);return n.loadData(s)}async submitStepData(r,s){const n=this.getHandler(r);if(!n)throw new Error(`No handler registered for step action: ${oe[r]}`);return n.submitData(s)}}class ur{constructor(r,s,n,a,o,c,d,y){pe(this,"state");pe(this,"stepRouter");this.applicantService=r,this.questionnaireService=s,this.uploadDocumentService=n,this.appropriatenessTestService=a,this.overviewService=o,this.riskScoringService=c,this.investorCategorizationService=y,this.state=new cr,this.stepRouter=new dr,this.registerStepHandlers()}registerStepHandlers(){this.stepRouter.registerHandler(oe.Questionaries,{loadData:r=>this.questionnaireService.getQuestionnaire(r),submitData:async r=>{await this.questionnaireService.fillQuestionnaire(r)}}),this.stepRouter.registerHandler(oe.UploadDocument,{loadData:r=>this.uploadDocumentService.getUploadDocument(r),submitData:r=>this.uploadDocumentService.fillUploadDocument(r)}),this.stepRouter.registerHandler(oe.AppropriatenessTest,{loadData:r=>this.appropriatenessTestService.getAppropriatenessTest(r),submitData:async r=>{await this.appropriatenessTestService.fillAppropriatenessTest(r)}}),this.stepRouter.registerHandler(oe.Overview,{loadData:r=>this.overviewService.getOverviewData(r),submitData:r=>this.overviewService.passOverview(r.applicantId)}),this.stepRouter.registerHandler(oe.RiskScoring,{loadData:r=>this.riskScoringService.getRiskCriterias(r),submitData:async r=>{await this.riskScoringService.submitRiskScoring(r)}}),this.stepRouter.registerHandler(oe.IdentitySdk,{loadData:async r=>({applicantId:r,message:"Identity verification required"}),submitData:async()=>{}}),this.stepRouter.registerHandler(oe.InvestorCategorization,{loadData:r=>this.investorCategorizationService.getInvestorCategorization(r),submitData:async r=>{await this.investorCategorizationService.setInvestorCategorization(r)}}),this.stepRouter.registerHandler(oe.ManualReview,{loadData:async r=>({applicantId:r,message:"Your application is under manual review"}),submitData:async()=>{}}),this.stepRouter.registerHandler(oe.AdditionalData,{loadData:async r=>({applicantId:r,message:"Additional data required"}),submitData:async()=>{}})}async initialize(r){try{this.state.setApplicantId(r);const s=await this.applicantService.getProgress(r);return this.state.updateProgress(s),s}catch(s){throw this.state.setError(s),s}}async refreshProgress(){if(!this.state.applicantId)throw new Error("Workflow not initialized. Call initialize() first.");try{const r=await this.applicantService.getProgress(this.state.applicantId);return this.state.updateProgress(r),r}catch(r){throw this.state.setError(r),r}}async getCurrentStepData(){if(!this.state.currentStep)throw new Error("No current step available");if(!this.state.applicantId)throw new Error("Workflow not initialized");try{return await this.stepRouter.loadStepData(this.state.currentStep.action,this.state.applicantId)}catch(r){throw this.state.setError(r),r}}async submitCurrentStep(r){if(!this.state.currentStep)throw new Error("No current step available");try{await this.stepRouter.submitStepData(this.state.currentStep.action,r),await this.refreshProgress()}catch(s){throw this.state.setError(s),s}}async moveToNextStep(){return this.refreshProgress()}async moveToPreviousStep(){if(!this.state.applicantId)throw new Error("Workflow not initialized");try{return await this.applicantService.progressStepBack(this.state.applicantId),await this.refreshProgress()}catch(r){throw this.state.setError(r),r}}getState(){return this.state}getStepRouter(){return this.stepRouter}}function gt(t,r){return new Promise((s,n)=>{if(r&&document.getElementById(r)){s();return}const a=document.createElement("script");a.src=t,r&&(a.id=r),a.async=!0,a.onload=()=>s(),a.onerror=()=>n(new Error(`Failed to load script: ${t}`)),document.head.appendChild(a)})}function Qr(t){return!!document.getElementById(t)}function Gr(t){const r=document.getElementById(t);r&&r.remove()}const Jr="https://static.sumsub.com/idensic/static/sns-websdk-builder.js";function Be(t,r){try{return getComputedStyle(document.documentElement).getPropertyValue(t).trim()||r}catch{return r}}function Zr(){const t=Be("--metakyc-primary","#2563eb"),r=Be("--metakyc-primary-hover","#1d4ed8"),s=Be("--metakyc-background","#ffffff"),n=Be("--metakyc-surface","#f9fafb"),a=Be("--metakyc-text-primary","#111827"),o=Be("--metakyc-text-secondary","#6b7280"),c=Be("--metakyc-text-muted","#9ca3af"),d=Be("--metakyc-border","#e5e7eb");return`
|
|
2
2
|
body, html { font-family: ${Be("--metakyc-font-family","-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif")} !important; background-color: ${s} !important; }
|
|
3
3
|
p, span, label, div { color: ${a}; }
|
|
4
4
|
h1, h2, h3, h4 { color: ${a}; }
|
|
@@ -18,7 +18,7 @@ select { background-color: ${s}; color: ${a}; border: 1px solid ${d}; border-rad
|
|
|
18
18
|
.subtitle { color: ${c}; }
|
|
19
19
|
a { color: ${t}; }
|
|
20
20
|
a:hover { color: ${r}; }
|
|
21
|
-
`.trim()}class pr{constructor(r){pe(this,"sdk",null);pe(this,"config");pe(this,"completeCallback",null);pe(this,"errorCallback",null);this.config=r}async loadSDK(){if(!window.snsWebSdk&&(await gt(
|
|
21
|
+
`.trim()}class pr{constructor(r){pe(this,"sdk",null);pe(this,"config");pe(this,"completeCallback",null);pe(this,"errorCallback",null);this.config=r}async loadSDK(){if(!window.snsWebSdk&&(await gt(Jr,"sumsub-websdk"),!window.snsWebSdk))throw new Error("Sumsub Web SDK failed to load from CDN")}async initialize(r){await this.loadSDK();const s={lang:this.config.lang||"en"};if(this.config.applicantEmail&&(s.email=this.config.applicantEmail),this.config.applicantPhone&&(s.phone=this.config.applicantPhone),this.config.theme&&(s.theme=this.config.theme),this.config.customizationName&&(s.customizationName=this.config.customizationName),!this.config.customizationName){const a={};this.config.customCss&&(a.customCss=this.config.customCss),this.config.customCssStr&&(a.customCssStr=this.config.customCssStr),a.customCssStr||(a.customCssStr=Zr()),s.uiConf=a}const n=window.snsWebSdk.init(this.config.accessToken,()=>this.config.onTokenRefresh()).withConf(s).withOptions({addViewportTag:!1,adaptIframeHeight:this.config.adaptIframeHeight!==!1}).on("idCheck.onStepCompleted",a=>{console.log("[Sumsub] Step completed:",a)}).on("idCheck.applicantStatus",a=>{var o,c;console.log("[Sumsub] Applicant status:",a),((a==null?void 0:a.reviewStatus)==="completed"||((o=a==null?void 0:a.reviewResult)==null?void 0:o.reviewAnswer)==="GREEN")&&((c=this.completeCallback)==null||c.call(this,a))}).on("idCheck.onError",a=>{var o;console.error("[Sumsub] Error:",a),(o=this.errorCallback)==null||o.call(this,a)}).onMessage((a,o)=>{var c;console.log("[Sumsub] Message:",a,o),a==="idCheck.onApplicantSubmitted"&&((c=this.completeCallback)==null||c.call(this,o))});this.sdk=n.build(),this.sdk.launch(`#${r}`)}destroy(){if(this.sdk){try{this.sdk.destroy()}catch{}this.sdk=null}}onComplete(r){this.completeCallback=r}onError(r){this.errorCallback=r}}class mr{constructor(r){pe(this,"sdk",null);pe(this,"config");this.config=r}async loadSDK(){await gt("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 yr{constructor(r){pe(this,"sardineContext",null);pe(this,"config");pe(this,"sessionKey");this.config=r,this.sessionKey=r.sessionKey||this.generateSessionKey()}generateSessionKey(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(r){const s=Math.random()*16|0;return(r==="x"?s:s&3|8).toString(16)})}getSardineHost(){const{environment:r,region:s}=this.config;if(r==="sandbox")return"api.sandbox.sardine.ai";switch(s){case"eu":return"api.eu.sardine.ai";case"ca":return"api.ca.sardine.ai";case"au":return"api.au.sardine.ai";default:return"api.sardine.ai"}}async loadSDK(){return new Promise((r,s)=>{if(window._Sardine){r();return}const n=this.getSardineHost(),a=document.createElement("script");a.type="text/javascript",a.async=!0,a.src=`https://${n}/assets/loader.min.js`,a.onload=()=>{console.log("[SardinAI] SDK loaded successfully"),r()},a.onerror=()=>{s(new Error("Failed to load SardinAI SDK"))};const o=document.getElementsByTagName("script")[0];o&&o.parentNode?o.parentNode.insertBefore(a,o):document.head.appendChild(a)})}async initialize(){try{if(await this.loadSDK(),!window._Sardine)throw new Error("SardinAI SDK not available after loading");const r=this.getSardineHost(),{clientId:s,environment:n,flow:a,enableBiometrics:o,enablePortScanning:c}=this.config;this.sardineContext=window._Sardine.createContext({clientId:s,sessionKey:this.sessionKey,userIdHash:void 0,flow:a||window.location.pathname,environment:n||"production",parentElement:document.body,enableBiometrics:o!==!1,enablePortScanning:c===!0,region:this.config.region,onDeviceResponse:d=>{console.log(`[SardinAI] Device ID: ${d.deviceId}`)},onConfigUpdate:(d,y,p)=>{switch(d){case"SESSION_UPDATE_FAILED":console.error("[SardinAI] Session update failed:",p);break;case"SESSION_UPDATED":console.log("[SardinAI] Session updated:",y);break;case"SESSION_NO_UPDATE":console.log("[SardinAI] No session update");break;default:console.warn("[SardinAI] Unknown event:",d)}}}),this.addNoScriptFallback(r),console.log("[SardinAI] SDK initialized with sessionKey:",this.sessionKey)}catch(r){throw console.error("[SardinAI] Initialization failed:",r),r}}addNoScriptFallback(r){const s=document.createElement("noscript"),n=document.createElement("img"),{clientId:a,flow:o}=this.config;n.src=`https://${r}/v1/a.png?clientId=${a}&sessionKey=${this.sessionKey}&flow=${o||"kyc"}&ns=1`,n.style.display="none",s.appendChild(n),document.body.appendChild(s)}updateConfig(r){if(!this.sardineContext){console.warn("[SardinAI] Cannot update config - SDK not initialized");return}r.sessionKey&&(this.sessionKey=r.sessionKey),this.sardineContext.updateConfig({...r,onConfigUpdate:(s,n,a)=>{switch(s){case"SESSION_UPDATE_FAILED":console.error("[SardinAI] Config update failed:",a);break;case"SESSION_UPDATED":console.log("[SardinAI] Config updated:",n);break;case"SESSION_NO_UPDATE":console.log("[SardinAI] No config update needed");break}}})}getSessionKey(){return this.sessionKey}destroy(){this.sardineContext&&(this.sardineContext=null)}}class _e{static createProvider(r,s){switch(r){case Ae.Sumsub:return new pr(s);case Ae.Onfido:return new mr(s);case Ae.SardinAI:return new yr(s);default:throw new Error(`Unsupported identity provider: ${r}`)}}static parseProviderConfig(r,s,n){var a,o;switch(r){case Ae.Sumsub:const c=((a=n==null?void 0:n.identityProviders)==null?void 0:a.sumsub)||{};return{accessToken:s.accessToken||s.token,applicantEmail:s.email,applicantPhone:s.phone,externalUserId:s.externalUserId,lang:c.lang||s.lang||"en",theme:c.theme,customizationName:c.customizationName,customCss:c.customCss,adaptIframeHeight:c.adaptIframeHeight};case Ae.Onfido:return{token:s.token||s.sdkToken};case Ae.SardinAI:const d=((o=n==null?void 0:n.identityProviders)==null?void 0:o.sardinai)||{};return{clientId:d.clientId||s.clientId,sessionKey:d.sessionKey||s.sessionKey,environment:d.environment||s.environment||"production",flow:d.flow||s.flow,region:d.region,enableBiometrics:d.enableBiometrics,enablePortScanning:d.enablePortScanning};default:throw new Error(`Unsupported identity provider: ${r}`)}}}function Xr(){return`
|
|
22
22
|
/* ── metakyc-input-colors (ThemeManager failsafe — same rules as globals.css) ── */
|
|
23
23
|
.metakyc-sdk input:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="range"]),
|
|
24
24
|
.metakyc-sdk select,
|
|
@@ -49,55 +49,55 @@ a:hover { color: ${r}; }
|
|
|
49
49
|
position: relative !important;
|
|
50
50
|
z-index: 2 !important;
|
|
51
51
|
}
|
|
52
|
-
`}class xr{constructor(r){pe(this,"currentTheme",Re);pe(this,"customStyleElement",null);pe(this,"inputStyleElement",null);pe(this,"container");this.container=r||document.documentElement}applyTheme(r){this.currentTheme=this.mergeWithDefault(r),this.applyColors(this.currentTheme.colors),this.currentTheme.typography&&this.applyTypography(this.currentTheme.typography),this.currentTheme.spacing&&this.applySpacing(this.currentTheme.spacing),this.currentTheme.customCSS&&this.injectCustomCSS(this.currentTheme.customCSS),console.log("[ThemeManager] Theme applied:",this.currentTheme.name||"Custom")}applyColors(r){var n;const s={primary:r.primary,"primary-hover":r.primaryHover,"primary-light":r.primaryLight,"primary-dark":r.primaryDark,secondary:r.secondary,"secondary-hover":r.secondaryHover,success:r.success,warning:r.warning,danger:r.danger,info:r.info,background:r.background,surface:r.surface,border:r.border,"text-primary":r.textPrimary,"text-secondary":r.textSecondary,"text-muted":r.textMuted,"input-bg":r.inputBg||r.background,"input-text":r.inputText||r.textPrimary,"input-border":r.inputBorder||r.border,"input-border-focus":r.inputBorderFocus||r.primary,"input-placeholder":r.inputPlaceholder||r.textMuted};Object.entries(s).forEach(([a,o])=>{o&&this.container.style.setProperty(`--metakyc-${a}`,o)}),this.injectInputColors(),(n=this.currentTheme.darkMode)!=null&&n.colors&&this.applyDarkModeColors(this.currentTheme.darkMode.colors)}applyDarkModeColors(r){Object.entries(r).forEach(([s,n])=>{if(n){const a=`--metakyc-dark-${this.kebabCase(s)}`;this.container.style.setProperty(a,n)}})}applyTypography(r){r&&(r.fontFamily&&this.container.style.setProperty("--metakyc-font-family",r.fontFamily),r.headingFont&&this.container.style.setProperty("--metakyc-heading-font",r.headingFont),r.fontSize&&Object.entries(r.fontSize).forEach(([s,n])=>{this.container.style.setProperty(`--metakyc-font-size-${s}`,n)}),r.fontWeight&&Object.entries(r.fontWeight).forEach(([s,n])=>{this.container.style.setProperty(`--metakyc-font-weight-${s}`,n.toString())}))}applySpacing(r){r&&Object.entries(r).forEach(([s,n])=>{const a=`--metakyc-${this.kebabCase(s)}`;this.container.style.setProperty(a,n)})}injectInputColors(){this.inputStyleElement&&this.inputStyleElement.remove(),this.inputStyleElement=document.createElement("style"),this.inputStyleElement.id="metakyc-input-colors",this.inputStyleElement.textContent=Zr(),this.customStyleElement&&this.customStyleElement.parentNode?document.head.insertBefore(this.inputStyleElement,this.customStyleElement):document.head.appendChild(this.inputStyleElement)}injectCustomCSS(r){this.customStyleElement&&this.customStyleElement.remove(),this.customStyleElement=document.createElement("style"),this.customStyleElement.id="metakyc-custom-css",this.customStyleElement.textContent=r,document.head.appendChild(this.customStyleElement)}mergeWithDefault(r){var s;return{name:r.name||Re.name,title:r.title||Re.title,logo:{...Re.logo,...r.logo},colors:{...Re.colors,...r.colors},typography:r.typography?{...Re.typography,...r.typography}:Re.typography,spacing:r.spacing?{...Re.spacing,...r.spacing}:Re.spacing,customCSS:r.customCSS,darkMode:r.darkMode?{colors:{...(s=Re.darkMode)==null?void 0:s.colors,...r.darkMode.colors}}:Re.darkMode,applicantFormVisibleFields:r.applicantFormVisibleFields,applicantFormRequiredFields:r.applicantFormRequiredFields,allowedLanguages:r.allowedLanguages,applicantFormPages:r.applicantFormPages,reviewPageFields:r.reviewPageFields,reviewPageDisabled:r.reviewPageDisabled,fieldLabelMode:r.fieldLabelMode,companyFormVisibleFields:r.companyFormVisibleFields,companyFormRequiredFields:r.companyFormRequiredFields,companyFormPages:r.companyFormPages,companyReviewPageFields:r.companyReviewPageFields}}getCurrentTheme(){return this.currentTheme}resetTheme(){this.applyTheme(Re)}cleanup(){this.inputStyleElement&&(this.inputStyleElement.remove(),this.inputStyleElement=null),this.customStyleElement&&(this.customStyleElement.remove(),this.customStyleElement=null)}kebabCase(r){return r.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}}const bt=i.createContext(null),Xr=({config:t,children:r})=>{const[s,n]=i.useState(null),a=i.useRef(!1),o=i.useRef(!1),c=i.useMemo(()=>{const y=new Kt(t),p=new qt(y),g=new Vt(y),T=new Yt(y),v=new Qt(y),E=new Gt(y),A=new Jt(y),k=new Zt(y),S=new Xt(y),D=new er(y),Y=new or(y),L=new xr;return{httpClient:y,applicantService:p,questionnaireService:g,uploadDocumentService:T,appropriatenessTestService:v,overviewService:E,riskScoringService:A,identityService:k,baseInformationService:S,investorCategorizationService:D,themeService:Y,themeManager:L}},[t]),d=i.useMemo(()=>({config:t,...c,currentTheme:s,createOrchestrator:()=>new ur(c.applicantService,c.questionnaireService,c.uploadDocumentService,c.appropriatenessTestService,c.overviewService,c.riskScoringService,c.identityService,c.investorCategorizationService)}),[t,c,s]);return i.useEffect(()=>((async()=>{if(a.current||o.current){console.log("[MetaKYC] Theme already loading or loaded, skipping...");return}a.current=!0;try{if(t.theme){console.log("[MetaKYC] Applying static theme from config"),c.themeManager.applyTheme(t.theme),n(c.themeManager.getCurrentTheme()),o.current=!0;return}console.log("[MetaKYC] Fetching theme from backend...");const p=await c.themeService.getThemeConfiguration();c.themeManager.applyTheme(p),n(c.themeManager.getCurrentTheme()),o.current=!0,console.log("[MetaKYC] Theme loaded and applied",p)}catch(p){console.warn("[MetaKYC] Failed to load theme, using default:",p),n(c.themeManager.getCurrentTheme()),o.current=!0}finally{a.current=!1}})(),()=>{c.themeManager.cleanup()}),[]),e.jsx(bt.Provider,{value:d,children:r})};function Ne(){const t=i.useContext(bt);if(!t)throw new Error("useMetaKYC must be used within a MetaKYCProvider");return t}async function hr(t){return new Promise((r,s)=>{const n=new FileReader;n.readAsDataURL(t),n.onload=()=>{const o=n.result.split(",")[1];r(o)},n.onerror=a=>s(a)})}function es(t,r){return t.size<=r}function ts(t,r){return r.split(",").map(n=>n.trim()).some(n=>{if(n.endsWith("/*")){const a=n.slice(0,-2);return t.type.startsWith(a)}return t.type===n})}function ut(t){if(t===0)return"0 Bytes";const r=1024,s=["Bytes","KB","MB","GB"],n=Math.floor(Math.log(t)/Math.log(r));return Math.round(t/Math.pow(r,n)*100)/100+" "+s[n]}function rs(t){return t}function Se(...t){return t.filter(Boolean).join(" ")}const at={APPLICANT_ID:"metakyc_applicant_id",WORKFLOW_STATE:"metakyc_workflow_state"};function fr(t){try{localStorage.setItem(at.APPLICANT_ID,t.toString())}catch(r){console.warn("Failed to save applicant ID to storage:",r)}}function gr(){try{const t=localStorage.getItem(at.APPLICANT_ID);return t?parseInt(t,10):null}catch(t){return console.warn("Failed to retrieve applicant ID from storage:",t),null}}function br(){try{localStorage.removeItem(at.APPLICANT_ID)}catch(t){console.warn("Failed to clear applicant ID from storage:",t)}}function vr(t){try{localStorage.setItem(at.WORKFLOW_STATE,JSON.stringify(t))}catch(r){console.warn("Failed to save workflow state to storage:",r)}}function ss(){try{const t=localStorage.getItem(at.WORKFLOW_STATE);return t?JSON.parse(t):null}catch(t){return console.warn("Failed to retrieve workflow state from storage:",t),null}}function kr(){try{localStorage.removeItem(at.WORKFLOW_STATE)}catch(t){console.warn("Failed to clear workflow state from storage:",t)}}function ns(){br(),kr()}function jr(t){const{createOrchestrator:r}=Ne(),[s,n]=i.useState(null),[a,o]=i.useState(!1),[c,d]=i.useState(null),y=i.useRef(null),p=t||gr();i.useEffect(()=>{y.current||(y.current=r())},[r]),i.useEffect(()=>{var L;s&&p&&(fr(p),vr({applicantId:p,currentStepOrder:(L=s.currentStep)==null?void 0:L.order,status:s.status,lastUpdated:new Date().toISOString(),workflowKey:s.workFlowKey,nextWorkflowKey:s.nextWorkflowKey}))},[s,p]);const g=i.useRef(!1),T=i.useRef(!1),v=i.useCallback(async()=>{if(!(!p||!y.current)){if(g.current){console.log("[Workflow] Load already in progress, skipping...");return}g.current=!0,o(!0),d(null);try{const L=await y.current.initialize(p);n(L),T.current=!0}catch(L){d(L)}finally{o(!1),g.current=!1}}},[p]);i.useEffect(()=>{p&&!T.current&&v()},[p,v]);const E=i.useCallback(async()=>{if(y.current){if(g.current){console.log("[Workflow] Refresh already in progress, skipping...");return}g.current=!0,o(!0),d(null);try{const L=await y.current.refreshProgress();n(L)}catch(L){d(L)}finally{o(!1),g.current=!1}}},[]),A=i.useCallback(async()=>{if(y.current){o(!0),d(null);try{const L=await y.current.moveToNextStep();n(L)}catch(L){d(L)}finally{o(!1)}}},[]),k=i.useCallback(async()=>{if(y.current){o(!0),d(null);try{const L=await y.current.moveToPreviousStep();n(L)}catch(L){d(L)}finally{o(!1)}}},[]),S=i.useCallback(async L=>{if(y.current){o(!0),d(null);try{await y.current.submitCurrentStep(L);const B=await y.current.refreshProgress();n(B)}catch(B){throw d(B),B}finally{o(!1)}}},[]),D=wt.useMemo(()=>s!=null&&s.stepInfoList?[...s.stepInfoList].sort((L,B)=>L.order-B.order):[],[s==null?void 0:s.stepInfoList]),Y=wt.useMemo(()=>s?s.nextWorkflowKey&&s.nextWorkflowKey!==s.workFlowKey:!1,[s]);return{progress:s,applicantId:p,currentStep:(s==null?void 0:s.currentStep)||null,steps:D,status:(s==null?void 0:s.status)||Te.None,workflowResult:(s==null?void 0:s.workflowResult)||null,workflowKey:s==null?void 0:s.workFlowKey,nextWorkflowKey:s==null?void 0:s.nextWorkflowKey,hasWorkflowChanged:Y,isLoading:a,error:c,isComplete:(s==null?void 0:s.status)===Te.Finished,isOnHold:(s==null?void 0:s.status)===Te.OnHold,refreshProgress:E,moveToNext:A,moveBack:k,submitCurrentStep:S,orchestrator:y.current}}function wr(t){const{questionnaireService:r,applicantService:s}=Ne(),[n,a]=i.useState(null),[o,c]=i.useState({}),[d,y]=i.useState(!1),[p,g]=i.useState(!1),[T,v]=i.useState(null),E=i.useRef(!1),A=i.useRef(null),k=i.useCallback(async()=>{var D,Y;if(t){if(E.current){console.log("[Questionnaire] Load already in progress, skipping...");return}E.current=!0,y(!0),v(null);try{const[L,B]=await Promise.all([r.getQuestionnaire(t),s.getApplicantData(t).catch(()=>null)]);if(a(L),(D=B==null?void 0:B.questionnaireResults)!=null&&D.length&&L){const U=new Map;for(const f of B.questionnaireResults)f.question&&((Y=f.answers)!=null&&Y.length)&&U.set(f.question.trim().toLowerCase(),f.answers);const X={},R=L.questionGroups.flatMap(f=>f.questions??[]);for(const f of R){const O=f.text.trim().toLowerCase();U.has(O)&&(X[f.id]=U.get(O))}c(X)}A.current=t}catch(L){v(L)}finally{y(!1),E.current=!1}}},[t,r,s]);i.useEffect(()=>{t&&A.current!==t&&k()},[t]);const S=i.useCallback(async D=>{g(!0),v(null);try{return await r.fillQuestionnaire(D)}catch(Y){throw v(Y),Y}finally{g(!1)}},[r]);return{questionnaire:n,initialAnswers:o,isLoading:d,isSubmitting:p,error:T,load:k,submit:S}}function Sr(t){const{uploadDocumentService:r}=Ne(),[s,n]=i.useState(null),[a,o]=i.useState(!1),[c,d]=i.useState(!1),[y,p]=i.useState(0),[g,T]=i.useState(null),v=i.useRef(!1),E=i.useRef(null),A=i.useCallback(async()=>{if(t){if(v.current){console.log("[UploadDocument] Load already in progress, skipping...");return}v.current=!0,o(!0),T(null);try{const S=await r.getUploadDocument(t);n(S),E.current=t}catch(S){T(S)}finally{o(!1),v.current=!1}}},[t,r]);i.useEffect(()=>{t&&E.current!==t&&A()},[t]);const k=i.useCallback(async S=>{d(!0),p(0),T(null);try{await r.fillUploadDocument(S),p(100)}catch(D){throw T(D),D}finally{d(!1)}},[r]);return{uploadDocument:s,isLoading:a,isSubmitting:c,uploadProgress:y,error:g,load:A,submit:k}}function as(t){const{appropriatenessTestService:r}=Ne(),[s,n]=i.useState(null),[a,o]=i.useState(!1),[c,d]=i.useState(!1),[y,p]=i.useState(null),[g,T]=i.useState(null),v=i.useRef(!1),E=i.useRef(null),A=i.useCallback(async()=>{if(t){if(v.current){console.log("[AppropriatenessTest] Load already in progress, skipping...");return}v.current=!0,o(!0),p(null);try{const S=await r.getAppropriatenessTest(t);n(S),E.current=t}catch(S){p(S)}finally{o(!1),v.current=!1}}},[t,r]);i.useEffect(()=>{t&&E.current!==t&&A()},[t]);const k=i.useCallback(async S=>{d(!0),p(null);try{const D=await r.fillAppropriatenessTest(S);return T(D),D}catch(D){throw p(D),D}finally{d(!1)}},[r]);return{test:s,result:g,isLoading:a,isSubmitting:c,error:y,load:A,submit:k}}function Cr(t){const{overviewService:r}=Ne(),[s,n]=i.useState(null),[a,o]=i.useState(!1),[c,d]=i.useState(!1),[y,p]=i.useState(null),g=i.useRef(!1),T=i.useRef(null),v=i.useCallback(async()=>{if(t){if(g.current){console.log("[Overview] Load already in progress, skipping...");return}g.current=!0,o(!0),p(null);try{const A=await r.getOverviewData(t);n(A),T.current=t}catch(A){p(A)}finally{o(!1),g.current=!1}}},[t,r]);i.useEffect(()=>{t&&T.current!==t&&v()},[t]);const E=i.useCallback(async()=>{if(t){d(!0),p(null);try{await r.passOverview(t)}catch(A){throw p(A),A}finally{d(!1)}}},[t,r]);return{overview:s,isLoading:a,isSubmitting:c,error:y,load:v,passOverview:E}}function Nr(t){const{identityService:r}=Ne(),[s,n]=i.useState(null),[a,o]=i.useState(!1),[c,d]=i.useState(null),y=i.useRef(!1),p=i.useCallback(async(v,E)=>{if(t){if(y.current){console.log("[Identity] Request already in progress, skipping...");return}y.current=!0,o(!0),d(null);try{const A={applicantId:t,restart:!1,redirectUrl:v||"",ttl:E||604800};console.log("Identity request input:",A);const k=await r.identityRequest(A);return console.log("Identity request result:",k),n(k),k}catch(A){throw d(A),A}finally{o(!1),y.current=!1}}},[t,r]),g=i.useCallback(async(v,E)=>{if(t){o(!0),d(null);try{const A={applicantId:t,restart:!1,redirectUrl:v,ttl:E},k=await r.identityCompanyRequest(A);return n(k),k}catch(A){throw d(A),A}finally{o(!1)}}},[t,r]),T=i.useCallback(async()=>{if(t){if(y.current){console.log("[Identity] Restart already in progress, skipping...");return}y.current=!0,o(!0),d(null);try{const v={applicantId:t,restart:!0,redirectUrl:"",ttl:604800};console.log("Restarting identity with input:",v);const E=await r.identityRequest(v);return console.log("Restart identity result:",E),n(E),E}catch(v){throw d(v),v}finally{o(!1),y.current=!1}}},[t,r]);return{identityData:s,provider:(s==null?void 0:s.provider)||null,token:(s==null?void 0:s.publicProviderTokenObject)||null,isLoading:a,error:c,requestIdentity:p,requestCompanyIdentity:g,restartIdentity:T}}function Rr(t){const{riskScoringService:r,applicantService:s}=Ne(),[n,a]=i.useState(null),[o,c]=i.useState({}),[d,y]=i.useState(!1),[p,g]=i.useState(!1),[T,v]=i.useState(null),[E,A]=i.useState(null),k=i.useRef(!1),S=i.useRef(null),D=i.useCallback(async()=>{var L;if(t){if(k.current){console.log("[RiskScoring] Load already in progress, skipping...");return}k.current=!0,y(!0),v(null);try{const[B,U]=await Promise.all([r.getRiskCriterias(t),s.getApplicantData(t).catch(()=>null)]);if(a(B),(L=U==null?void 0:U.riskScoringResults)!=null&&L.length){const X=U.riskScoringResults[0],R={};for(const f of X.riskCriteriaResults??[])if(f.riskCriteriaId!=null&&f.answer!=null&&f.answer!==""){const O=[...new Set(f.answer.split(",").map(q=>q.trim()).filter(q=>q!==""))];O.length>0&&(R[f.riskCriteriaId]=O)}c(R)}S.current=t}catch(B){v(B)}finally{y(!1),k.current=!1}}},[t,r,s]);i.useEffect(()=>{t&&S.current!==t&&D()},[t]);const Y=i.useCallback(async L=>{g(!0),v(null);try{const B=await r.submitRiskScoring(L);return A(B),B}catch(B){throw v(B),B}finally{g(!1)}},[r]);return{criteria:n,initialAnswers:o,result:E,isLoading:d,isSubmitting:p,error:T,load:D,submit:Y}}function vt(){const{applicantService:t,config:r}=Ne(),[s,n]=i.useState(!1),[a,o]=i.useState(null),c=i.useRef(!1),d=i.useRef(!1),y=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(E){const A=Math.random()*16|0;return(E==="x"?A:A&3|8).toString(16)}),p=i.useCallback(async E=>{var A;if(c.current)throw console.log("[Applicant] Create already in progress, skipping..."),new Error("Creation already in progress");c.current=!0,n(!0),o(null);try{if(E.applicantAdditionalDatas||(E.applicantAdditionalDatas=[]),(A=r.identityProviders)!=null&&A.sardinai){const S=y();console.log("[SardinAI] Generated session key:",S),E.applicantAdditionalDatas.push({paramName:"sessionKey",value:S})}return await t.createApplicant(E)}catch(k){throw o(k),k}finally{n(!1),c.current=!1}},[t,r]),g=i.useCallback(async E=>{n(!0),o(null);try{return await t.createCompanyApplicant(E)}catch(A){throw o(A),A}finally{n(!1)}},[t]),T=i.useCallback(async E=>{if(d.current)throw console.log("[Applicant] Data load already in progress, skipping..."),new Error("Data load already in progress");d.current=!0,n(!0),o(null);try{return await t.getApplicantData(E)}catch(A){throw o(A),A}finally{n(!1),d.current=!1}},[t]),v=i.useCallback(async E=>{n(!0),o(null);try{await t.stopProgress(E)}catch(A){throw o(A),A}finally{n(!1)}},[t]);return{isLoading:s,error:a,createApplicant:p,createCompanyApplicant:g,getApplicantData:T,stopProgress:v}}const is={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:n=!1,disabled:a,className:o,style:c,...d})=>{const y="inline-flex items-center justify-center rounded-lg font-medium transition-opacity border focus:outline-none focus:ring-2 focus:ring-offset-1 disabled:opacity-50 disabled:cursor-not-allowed",p={sm:"px-3 py-1.5 text-sm",md:"px-4 py-2 text-sm",lg:"px-6 py-3 text-base"},g={sm:{padding:"0.375rem 0.75rem",fontSize:"0.875rem"},md:{padding:"0.5rem 1rem",fontSize:"0.875rem"},lg:{padding:"0.75rem 1.5rem",fontSize:"1rem"}};return e.jsxs("button",{className:Se(y,p[s],o),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",borderRadius:"0.5rem",fontWeight:500,borderWidth:"1px",borderStyle:"solid",cursor:a||n?"not-allowed":"pointer",opacity:a||n?.5:1,lineHeight:"1.25rem",...g[s],...is[r],...c},disabled:a||n,...d,children:[n&&e.jsxs("svg",{className:"animate-spin -ml-1 mr-2 h-4 w-4",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),t]})},ye=i.forwardRef(({label:t,error:r,helperText:s,leftIcon:n,rightIcon:a,className:o,style:c,...d},y)=>e.jsxs("div",{className:"w-full",children:[t&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[t,d.required&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),e.jsxs("div",{className:"relative",children:[n&&e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:n}),e.jsx("input",{ref:y,className:Se("block w-full rounded-lg border px-3 py-2 text-sm transition-colors","focus:outline-none focus:ring-2 focus:ring-offset-0","disabled:opacity-60 disabled:cursor-not-allowed",n?"pl-10":"",a?"pr-10":"",o),style:{minHeight:"38px",backgroundColor:d.readOnly?"var(--metakyc-surface, #f3f4f6)":"var(--metakyc-input-bg, #ffffff)",color:"var(--metakyc-input-text, var(--metakyc-text-primary, #111827))",borderColor:r?"var(--metakyc-danger, #ef4444)":"var(--metakyc-input-border, var(--metakyc-border, #d1d5db))",cursor:d.readOnly?"default":void 0,...c},...d}),a&&e.jsx("div",{className:"absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none",children:a})]}),r&&e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-danger, #ef4444)"},children:r}),!r&&s&&e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:s})]}));ye.displayName="Input";const ee=({children:t,className:r,style:s,...n})=>e.jsx("div",{className:Se("metakyc-card rounded-xl shadow-sm border",r),style:{backgroundColor:"var(--metakyc-surface, #ffffff)",borderColor:"var(--metakyc-border, #e5e7eb)",borderWidth:"1px",borderStyle:"solid",borderRadius:"0.75rem",overflow:"hidden",...s},...n,children:t}),ge=({children:t,className:r,style:s,...n})=>e.jsx("div",{className:Se("px-6 py-4 border-b",r),style:{padding:"1rem 1.5rem",borderBottomWidth:"1px",borderBottomStyle:"solid",borderBottomColor:"var(--metakyc-border, #e5e7eb)",...s},...n,children:t}),te=({children:t,className:r,style:s,...n})=>e.jsx("div",{className:Se("px-6 py-4",r),style:{padding:"1rem 1.5rem",...s},...n,children:t}),be=({children:t,className:r,style:s,...n})=>e.jsx("div",{className:Se("px-6 py-4 border-t",r),style:{padding:"1rem 1.5rem",borderTopWidth:"1px",borderTopStyle:"solid",borderTopColor:"var(--metakyc-border, #e5e7eb)",...s},...n,children:t}),os={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"}},kt=({children:t,variant:r="default",className:s,style:n,...a})=>e.jsx("span",{className:Se("inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium",s),style:{...os[r],...n},...a,children:t}),Ee=({size:t="md",className:r,...s})=>{const n={sm:"h-4 w-4",md:"h-8 w-8",lg:"h-12 w-12"};return e.jsx("div",{className:Se("flex items-center justify-center",r),...s,children:e.jsxs("svg",{className:Se("animate-spin text-primary-500",n[t]),xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})})},mt=i.forwardRef(({label:t,error:r,helperText:s,options:n,placeholder:a,className:o,style:c,...d},y)=>e.jsxs("div",{className:"w-full",children:[t&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[t,d.required&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),e.jsxs("select",{ref:y,className:Se("block w-full rounded-lg border px-3 py-2 text-sm transition-colors","focus:outline-none focus:ring-2 focus:ring-offset-0","disabled:opacity-60 disabled:cursor-not-allowed",r?"border-danger-500":"",o),style:{minHeight:"38px",backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:"var(--metakyc-input-text, var(--metakyc-text-primary, #111827))",borderColor:r?"var(--metakyc-danger, #ef4444)":"var(--metakyc-input-border, var(--metakyc-border, #d1d5db))",...c},...d,children:[a&&e.jsx("option",{value:"",disabled:!0,style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:"var(--metakyc-text-secondary, #6b7280)"},children:a},"__placeholder__"),n.map((p,g)=>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-${g}`))]}),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})]}));mt.displayName="Select";const St=280,Ir=({label:t,value:r,onChange:s,options:n,placeholder:a="Select...",disabled:o=!1,readOnly:c=!1,required:d=!1})=>{const y=o||c,[p,g]=i.useState(!1),[T,v]=i.useState(""),[E,A]=i.useState(null),[k,S]=i.useState({bg:"#ffffff",borderColor:"#d1d5db",textPrimary:"#111827",textSecondary:"#6b7280",primaryColor:"#2563eb",primaryLight:"#eff6ff",hoverBg:"#f9fafb"}),D=i.useRef(null),Y=i.useRef(null),L=i.useRef(null),B=i.useCallback(()=>{if(!Y.current)return null;const I=Y.current.getBoundingClientRect(),z=window.innerHeight-I.bottom<St&&I.top>St;return{top:z?I.top:I.bottom+4,left:I.left,width:I.width,openUp:z}},[]),U=i.useCallback(()=>{const I=getComputedStyle(document.documentElement),W=(_,me)=>I.getPropertyValue(_).trim()||me,z=W("--metakyc-input-bg",W("--metakyc-background","#ffffff"));S({bg:z,borderColor:W("--metakyc-input-border",W("--metakyc-border","#d1d5db")),textPrimary:W("--metakyc-input-text",W("--metakyc-text-primary","#111827")),textSecondary:W("--metakyc-text-secondary","#6b7280"),primaryColor:W("--metakyc-primary","#2563eb"),primaryLight:W("--metakyc-primary-light","#eff6ff"),hoverBg:W("--metakyc-surface",z)})},[]),X=i.useCallback(()=>{if(y)return;U();const I=B();I&&A(I),g(!0)},[y,B,U]),R=i.useCallback(()=>{g(!1),v("")},[]);i.useEffect(()=>{if(!p)return;const I=W=>{var _,me;const z=W.target;!((_=D.current)!=null&&_.contains(z))&&!((me=L.current)!=null&&me.contains(z))&&R()};return document.addEventListener("mousedown",I),()=>document.removeEventListener("mousedown",I)},[p,R]),i.useEffect(()=>{if(!p)return;const I=()=>{const W=B();W&&A(W)};return window.addEventListener("scroll",I,!0),window.addEventListener("resize",I),()=>{window.removeEventListener("scroll",I,!0),window.removeEventListener("resize",I)}},[p,B]);const f=n.filter(I=>I.label.toLowerCase().includes(T.toLowerCase())),O=I=>{y||s(r.includes(I)?r.filter(W=>W!==I):[...r,I])},q=(I,W)=>{W.stopPropagation(),y||s(r.filter(z=>z!==I))},Q=I=>{var W;return((W=n.find(z=>z.value===I))==null?void 0:W.label)||I},{bg:$,borderColor:G,textPrimary:se,textSecondary:V,primaryColor:he,primaryLight:ce,hoverBg:de}=k,fe=p&&E&&e.jsxs("div",{ref:L,className:"metakyc-multiselect-dropdown",style:{position:"fixed",top:E.openUp?void 0:E.top,bottom:E.openUp?window.innerHeight-E.top+4:void 0,left:E.left,width:E.width,zIndex:99999,borderRadius:"8px",boxShadow:"0 4px 16px rgba(0,0,0,0.18)",border:`1px solid ${G}`,backgroundColor:$,overflow:"hidden"},children:[e.jsx("div",{style:{padding:"8px",borderBottom:`1px solid ${G}`},children:e.jsx("input",{type:"text",value:T,onChange:I=>v(I.target.value),placeholder:"Search...",autoFocus:!0,onClick:I=>I.stopPropagation(),className:"metakyc-multiselect-search w-full",style:{display:"block",width:"100%",padding:"6px 8px",fontSize:"13px",borderRadius:"6px",border:`1px solid ${G}`,backgroundColor:$,color:se,outline:"none",boxSizing:"border-box"},onFocus:I=>{const W=getComputedStyle(document.documentElement),z=W.getPropertyValue("--metakyc-input-border-focus").trim()||W.getPropertyValue("--metakyc-primary").trim()||"#2563eb";I.currentTarget.style.backgroundColor=$,I.currentTarget.style.color=se,I.currentTarget.style.borderColor=z,I.currentTarget.style.outline="none",I.currentTarget.style.boxShadow=`0 0 0 2px ${z}33`},onBlur:I=>{I.currentTarget.style.backgroundColor=$,I.currentTarget.style.color=se,I.currentTarget.style.borderColor=G,I.currentTarget.style.outline="none",I.currentTarget.style.boxShadow="none"}})}),e.jsx("ul",{style:{listStyle:"none",margin:0,padding:"4px 0",maxHeight:"192px",overflowY:"auto"},children:f.length===0?e.jsx("li",{style:{padding:"8px 12px",fontSize:"13px",color:V},children:"No results"}):f.map(I=>{const W=r.includes(I.value);return e.jsxs("li",{onClick:()=>O(I.value),className:"metakyc-multiselect-option",style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",fontSize:"13px",cursor:"pointer",backgroundColor:W?ce:"transparent",color:W?he:se,userSelect:"none"},onMouseEnter:z=>{W||(z.currentTarget.style.backgroundColor=de)},onMouseLeave:z=>{W||(z.currentTarget.style.backgroundColor="transparent")},children:[e.jsx("input",{type:"checkbox",checked:W,readOnly:!0,style:{accentColor:he,pointerEvents:"none",flexShrink:0}}),e.jsx("span",{children:I.label})]},I.value)})}),r.length>0&&e.jsx("div",{style:{padding:"6px 12px",borderTop:`1px solid ${G}`},children:e.jsxs("button",{type:"button",onClick:()=>{s([]),v("")},style:{fontSize:"12px",color:"#ef4444",background:"none",border:"none",cursor:"pointer",padding:0},children:["Clear all (",r.length," selected)"]})})]});return e.jsxs("div",{className:"w-full metakyc-multiselect",ref:D,children:[t&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[t,d&&e.jsx("span",{style:{color:"var(--metakyc-error, #ef4444)",marginLeft:"4px"},children:"*"})]}),e.jsxs("div",{ref:Y,onClick:()=>p?R():X(),className:Se("metakyc-multiselect-trigger","w-full px-3 py-2 rounded-lg border text-sm transition-colors relative",y?"opacity-50 cursor-not-allowed":"cursor-pointer"),style:{minHeight:"38px",backgroundColor:"var(--metakyc-input-bg, #ffffff)",borderColor:p?"var(--metakyc-input-border-focus, var(--metakyc-primary, #2563eb))":"var(--metakyc-input-border, var(--metakyc-border, #d1d5db))",outline:p?"2px solid var(--metakyc-input-border-focus, var(--metakyc-primary, #2563eb))":"none",outlineOffset:"-1px"},children:[r.length===0?e.jsx("span",{className:"metakyc-multiselect-placeholder leading-6",style:{color:"var(--metakyc-text-secondary, #9ca3af)"},children:a}):e.jsx("div",{className:"flex flex-wrap gap-1 pr-6",children:r.map(I=>e.jsxs("span",{className:"metakyc-multiselect-chip inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium",style:{backgroundColor:"var(--metakyc-primary-light, #eff6ff)",color:"var(--metakyc-primary, #2563eb)"},children:[Q(I),!y&&e.jsx("button",{type:"button",onClick:W=>q(I,W),className:"metakyc-multiselect-chip-remove",style:{background:"transparent",border:"none",padding:"0 0 0 2px",margin:0,cursor:"pointer",fontSize:"14px",lineHeight:1,fontWeight:"bold",display:"inline-flex",alignItems:"center",boxShadow:"none",transform:"none",minWidth:0,width:"auto",height:"auto",letterSpacing:"normal",textTransform:"none"},children:"×"})]},I))}),e.jsx("span",{className:"metakyc-multiselect-arrow absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none text-xs",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:p?"▲":"▼"})]}),typeof document<"u"&&fe?pt.createPortal(fe,document.body):null]})},Ct=260,De=({label:t,error:r,helperText:s,options:n,placeholder:a="Select...",value:o,onChange:c,disabled:d=!1,readOnly:y=!1,required:p=!1,className:g})=>{var me;const T=d||y,[v,E]=i.useState(!1),[A,k]=i.useState(""),[S,D]=i.useState(null),[Y,L]=i.useState({bg:"#ffffff",border:"#d1d5db",text:"#111827",textSecondary:"#6b7280",primary:"#2563eb",primaryLight:"#eff6ff",hoverBg:"#f9fafb"}),B=i.useCallback(()=>{const N=getComputedStyle(document.documentElement),re=(ne,ve)=>N.getPropertyValue(ne).trim()||ve,ue=re("--metakyc-input-bg",re("--metakyc-background","#ffffff"));L({bg:ue,border:re("--metakyc-input-border",re("--metakyc-border","#d1d5db")),text:re("--metakyc-input-text",re("--metakyc-text-primary","#111827")),textSecondary:re("--metakyc-text-secondary","#6b7280"),primary:re("--metakyc-primary","#2563eb"),primaryLight:re("--metakyc-primary-light","#eff6ff"),hoverBg:re("--metakyc-surface",ue)})},[]),U=i.useRef(null),X=i.useRef(null),R=i.useRef(null),f=i.useRef(null),O=i.useCallback(()=>{if(!X.current)return null;const N=X.current.getBoundingClientRect(),ue=window.innerHeight-N.bottom<Ct&&N.top>Ct;return{top:ue?N.top:N.bottom+4,left:N.left,width:N.width,openUp:ue}},[]),q=i.useCallback(()=>{if(T)return;B();const N=O();N&&D(N),E(!0)},[T,O,B]),Q=i.useCallback(()=>{E(!1),k("")},[]),$=()=>v?Q():q();i.useEffect(()=>{if(!v)return;const N=re=>{var ne,ve;const ue=re.target;!((ne=U.current)!=null&&ne.contains(ue))&&!((ve=R.current)!=null&&ve.contains(ue))&&Q()};return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},[v,Q]),i.useEffect(()=>{if(!v)return;const N=()=>{const re=O();re&&D(re)};return window.addEventListener("scroll",N,!0),window.addEventListener("resize",N),()=>{window.removeEventListener("scroll",N,!0),window.removeEventListener("resize",N)}},[v,O]),i.useEffect(()=>{v&&f.current&&setTimeout(()=>{var N;return(N=f.current)==null?void 0:N.focus()},0)},[v]);const G=n.filter(N=>N.label.toLowerCase().includes(A.toLowerCase())||N.value.toLowerCase().includes(A.toLowerCase())),se=(me=n.find(N=>N.value===o))==null?void 0:me.label,V=(N,re)=>{T||re||(c(N),Q())},{bg:he,border:ce,text:de,textSecondary:fe,primary:I,primaryLight:W,hoverBg:z}=Y,_=v&&S&&e.jsxs("div",{ref:R,className:"metakyc-searchable-select-dropdown",style:{position:"fixed",top:S.openUp?void 0:S.top,bottom:S.openUp?window.innerHeight-S.top+4:void 0,left:S.left,width:S.width,zIndex:99999,borderRadius:"8px",boxShadow:"0 4px 16px rgba(0,0,0,0.18)",border:`1px solid ${ce}`,backgroundColor:he,overflow:"hidden"},children:[e.jsx("div",{style:{padding:"8px",borderBottom:`1px solid ${ce}`},children:e.jsx("input",{ref:f,type:"text",value:A,onChange:N=>k(N.target.value),placeholder:"Search...",onClick:N=>N.stopPropagation(),className:"metakyc-searchable-select-search w-full",style:{display:"block",width:"100%",padding:"6px 8px",fontSize:"13px",borderRadius:"6px",border:`1px solid ${ce}`,backgroundColor:he,color:de,outline:"none",boxSizing:"border-box"},onFocus:N=>{const re=getComputedStyle(document.documentElement),ue=re.getPropertyValue("--metakyc-input-border-focus").trim()||re.getPropertyValue("--metakyc-primary").trim()||"#2563eb";N.currentTarget.style.backgroundColor=he,N.currentTarget.style.color=de,N.currentTarget.style.borderColor=ue,N.currentTarget.style.outline="none",N.currentTarget.style.boxShadow=`0 0 0 2px ${ue}33`},onBlur:N=>{N.currentTarget.style.backgroundColor=he,N.currentTarget.style.color=de,N.currentTarget.style.borderColor=ce,N.currentTarget.style.outline="none",N.currentTarget.style.boxShadow="none"}})}),e.jsx("ul",{style:{listStyle:"none",margin:0,padding:"4px 0",maxHeight:"208px",overflowY:"auto"},children:G.length===0?e.jsx("li",{style:{padding:"8px 12px",fontSize:"13px",color:fe},children:"No results"}):G.map(N=>{const re=N.value===o;return e.jsx("li",{className:"metakyc-searchable-select-option",onClick:()=>V(N.value,N.disabled),style:{padding:"8px 12px",fontSize:"13px",cursor:N.disabled?"not-allowed":"pointer",opacity:N.disabled?.4:1,backgroundColor:re?W:"transparent",color:re?I:de,userSelect:"none"},onMouseEnter:ue=>{!re&&!N.disabled&&(ue.currentTarget.style.backgroundColor=z)},onMouseLeave:ue=>{re||(ue.currentTarget.style.backgroundColor="transparent")},children:N.label},N.value)})})]});return e.jsxs("div",{className:Se("w-full metakyc-searchable-select",g),ref:U,children:[t&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[t,p&&e.jsx("span",{style:{color:"var(--metakyc-error, #ef4444)",marginLeft:"4px"},children:"*"})]}),e.jsxs("div",{ref:X,role:"button",tabIndex:T?-1:0,onClick:$,onKeyDown:N=>{(N.key==="Enter"||N.key===" ")&&(N.preventDefault(),$()),N.key==="Escape"&&Q()},className:Se("metakyc-searchable-select-trigger","w-full px-3 py-2 rounded-lg border text-sm transition-colors text-left","flex items-center justify-between gap-2","focus:outline-none",T?"opacity-60 cursor-not-allowed":"cursor-pointer"),style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:se?"var(--metakyc-input-text, var(--metakyc-text-primary, #111827))":"var(--metakyc-input-placeholder, var(--metakyc-text-muted, #9ca3af))",borderColor:r?"var(--metakyc-danger, #ef4444)":v?"var(--metakyc-input-border-focus, var(--metakyc-primary, #2563eb))":"var(--metakyc-input-border, var(--metakyc-border, #d1d5db))",minHeight:"38px",outline:v?"2px solid var(--metakyc-input-border-focus, var(--metakyc-primary, #2563eb))":"none",outlineOffset:"-1px"},children:[e.jsx("span",{className:"truncate flex-1",children:se||a}),e.jsx("span",{className:"flex-shrink-0 text-xs pointer-events-none",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:v?"▲":"▼"})]}),typeof document<"u"&&_?pt.createPortal(_,document.body):null,r&&e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-error, #ef4444)"},children:r}),!r&&s&&e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:s})]})};De.displayName="SearchableSelect";function ls(t){const r=t.type;return r.startsWith("image/")?"image":r==="application/pdf"?"pdf":"file"}const Er=({label:t,subtitle:r,error:s,accept:n,multiple:a=!1,maxSize:o,required:c,onChange:d,value:y=[],className:p})=>{const[g,T]=i.useState(!1),[v,E]=i.useState(null),A=i.useRef(null),k=i.useCallback(R=>{if(!R)return;E(null);const f=Array.from(R);if(o&&f.filter(q=>q.size>o).length>0){E(`File exceeds the maximum size of ${ut(o)}`);return}d==null||d(a?[...y,...f]:[f[0]])},[o,a,d,y]),S=i.useCallback(R=>{R.preventDefault(),R.stopPropagation(),T(!0)},[]),D=i.useCallback(R=>{R.preventDefault(),R.stopPropagation(),T(!1)},[]),Y=i.useCallback(R=>{R.preventDefault(),R.stopPropagation(),T(!1),k(R.dataTransfer.files)},[k]),L=()=>{var R;(R=A.current)==null||R.click()},B=R=>{E(null);const f=y.filter((O,q)=>q!==R);d==null||d(f)},U=s||v,X=y.length>0;return e.jsxs("div",{className:Se("metakyc-file-upload",p),style:{width:"100%"},children:[t&&e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"14px",fontWeight:600,color:"var(--metakyc-text-primary, #111827)"},children:[t,c&&e.jsx("span",{style:{color:"var(--metakyc-danger, #ef4444)",marginLeft:"2px"},children:"*"})]}),r&&e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"2px"},children:r})]}),e.jsxs("div",{className:"metakyc-file-dropzone",onClick:L,onDragOver:S,onDragLeave:D,onDrop:Y,style:{border:`2px dashed ${U?"var(--metakyc-danger, #ef4444)":g?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #d1d5db)"}`,borderRadius:"12px",padding:X?"20px":"32px 20px",textAlign:"center",cursor:"pointer",transition:"all 0.2s ease",backgroundColor:g?"color-mix(in srgb, var(--metakyc-primary, #2563eb) 5%, var(--metakyc-background, #ffffff))":"var(--metakyc-background, #ffffff)"},children:[e.jsx("input",{ref:A,type:"file",style:{display:"none"},accept:n,multiple:a,onChange:R=>{k(R.target.files),R.target.value=""}}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"12px"},children:[e.jsx("div",{style:{width:"48px",height:"48px",borderRadius:"12px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:g?"color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)":"var(--metakyc-surface, #f9fafb)",transition:"background-color 0.2s ease"},children:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:g?"var(--metakyc-primary, #2563eb)":"var(--metakyc-text-muted, #9ca3af)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{transition:"stroke 0.2s ease"},children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"17 8 12 3 7 8"}),e.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"15"})]})}),e.jsxs("div",{children:[e.jsxs("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",margin:0},children:[e.jsx("span",{style:{fontWeight:600,color:"var(--metakyc-primary, #2563eb)"},children:"Click to upload"})," ","or drag and drop"]}),(n||o)&&e.jsxs("p",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"4px"},children:[n&&e.jsx("span",{children:n}),n&&o&&e.jsx("span",{children:" · "}),o&&e.jsxs("span",{children:["Max ",ut(o)]})]})]})]})]}),X&&e.jsx("div",{style:{marginTop:"12px",display:"flex",flexDirection:"column",gap:"8px"},children:y.map((R,f)=>{const O=ls(R),q=O==="image",Q=q?URL.createObjectURL(R):null;return e.jsxs("div",{className:"metakyc-file-item",style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 12px",borderRadius:"10px",backgroundColor:"var(--metakyc-surface, #f9fafb)",border:"1px solid var(--metakyc-border, #e5e7eb)",transition:"background-color 0.15s ease"},children:[e.jsx("div",{style:{width:"40px",height:"40px",borderRadius:"8px",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden",backgroundColor:q?"transparent":"color-mix(in srgb, var(--metakyc-primary, #2563eb) 10%, transparent)"},children:q&&Q?e.jsx("img",{src:Q,alt:R.name,style:{width:"100%",height:"100%",objectFit:"cover",borderRadius:"8px"}}):O==="pdf"?e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"}),e.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),e.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"}),e.jsx("polyline",{points:"10 9 9 9 8 9"})]}):e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-primary, #2563eb)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("p",{style:{fontSize:"13px",fontWeight:500,color:"var(--metakyc-text-primary, #111827)",margin:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:R.name}),e.jsx("p",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)",margin:0,marginTop:"2px"},children:ut(R.size)})]}),e.jsx("button",{type:"button",onClick:$=>{$.stopPropagation(),B(f)},style:{display:"flex",alignItems:"center",justifyContent:"center",width:"28px",height:"28px",borderRadius:"6px",border:"none",backgroundColor:"transparent",color:"var(--metakyc-text-muted, #9ca3af)",cursor:"pointer",flexShrink:0,transition:"all 0.15s ease",padding:0},onMouseEnter:$=>{$.currentTarget.style.backgroundColor="color-mix(in srgb, var(--metakyc-danger, #ef4444) 10%, transparent)",$.currentTarget.style.color="var(--metakyc-danger, #ef4444)"},onMouseLeave:$=>{$.currentTarget.style.backgroundColor="transparent",$.currentTarget.style.color="var(--metakyc-text-muted, #9ca3af)"},children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},`${R.name}-${f}`)})}),U&&e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",marginTop:"6px"},children:U})]})},Ar=i.forwardRef(({countryCode:t="+1",onCountryCodeChange:r,className:s,...n},a)=>e.jsxs("div",{className:"w-full",children:[n.label&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[n.label,n.required&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:t,onChange:o=>r==null?void 0:r(o.target.value),className:Se("w-20 rounded-lg border px-3 py-2 text-sm","focus:outline-none focus:ring-2 focus:ring-offset-0"),style:{minHeight:"38px",backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:"var(--metakyc-text-primary, #111827)",borderColor:"var(--metakyc-border, #d1d5db)"},placeholder:"+1"}),e.jsx(ye,{ref:a,type:"tel",className:Se("flex-1",s),...n,label:""})]}),n.error&&e.jsx("p",{className:"mt-1 text-sm text-danger-500",children:n.error})]}));Ar.displayName="PhoneInput";/**
|
|
52
|
+
`}class xr{constructor(r){pe(this,"currentTheme",Re);pe(this,"customStyleElement",null);pe(this,"inputStyleElement",null);pe(this,"container");this.container=r||document.documentElement}applyTheme(r){this.currentTheme=this.mergeWithDefault(r),this.applyColors(this.currentTheme.colors),this.currentTheme.typography&&this.applyTypography(this.currentTheme.typography),this.currentTheme.spacing&&this.applySpacing(this.currentTheme.spacing),this.currentTheme.customCSS&&this.injectCustomCSS(this.currentTheme.customCSS),console.log("[ThemeManager] Theme applied:",this.currentTheme.name||"Custom")}applyColors(r){var n;const s={primary:r.primary,"primary-hover":r.primaryHover,"primary-light":r.primaryLight,"primary-dark":r.primaryDark,secondary:r.secondary,"secondary-hover":r.secondaryHover,success:r.success,warning:r.warning,danger:r.danger,info:r.info,background:r.background,surface:r.surface,border:r.border,"text-primary":r.textPrimary,"text-secondary":r.textSecondary,"text-muted":r.textMuted,"input-bg":r.inputBg||r.background,"input-text":r.inputText||r.textPrimary,"input-border":r.inputBorder||r.border,"input-border-focus":r.inputBorderFocus||r.primary,"input-placeholder":r.inputPlaceholder||r.textMuted};Object.entries(s).forEach(([a,o])=>{o&&this.container.style.setProperty(`--metakyc-${a}`,o)}),this.injectInputColors(),(n=this.currentTheme.darkMode)!=null&&n.colors&&this.applyDarkModeColors(this.currentTheme.darkMode.colors)}applyDarkModeColors(r){Object.entries(r).forEach(([s,n])=>{if(n){const a=`--metakyc-dark-${this.kebabCase(s)}`;this.container.style.setProperty(a,n)}})}applyTypography(r){r&&(r.fontFamily&&this.container.style.setProperty("--metakyc-font-family",r.fontFamily),r.headingFont&&this.container.style.setProperty("--metakyc-heading-font",r.headingFont),r.fontSize&&Object.entries(r.fontSize).forEach(([s,n])=>{this.container.style.setProperty(`--metakyc-font-size-${s}`,n)}),r.fontWeight&&Object.entries(r.fontWeight).forEach(([s,n])=>{this.container.style.setProperty(`--metakyc-font-weight-${s}`,n.toString())}))}applySpacing(r){r&&Object.entries(r).forEach(([s,n])=>{const a=`--metakyc-${this.kebabCase(s)}`;this.container.style.setProperty(a,n)})}injectInputColors(){this.inputStyleElement&&this.inputStyleElement.remove(),this.inputStyleElement=document.createElement("style"),this.inputStyleElement.id="metakyc-input-colors",this.inputStyleElement.textContent=Xr(),this.customStyleElement&&this.customStyleElement.parentNode?document.head.insertBefore(this.inputStyleElement,this.customStyleElement):document.head.appendChild(this.inputStyleElement)}injectCustomCSS(r){this.customStyleElement&&this.customStyleElement.remove(),this.customStyleElement=document.createElement("style"),this.customStyleElement.id="metakyc-custom-css",this.customStyleElement.textContent=r,document.head.appendChild(this.customStyleElement)}mergeWithDefault(r){var s;return{name:r.name||Re.name,title:r.title||Re.title,logo:{...Re.logo,...r.logo},colors:{...Re.colors,...r.colors},typography:r.typography?{...Re.typography,...r.typography}:Re.typography,spacing:r.spacing?{...Re.spacing,...r.spacing}:Re.spacing,customCSS:r.customCSS,darkMode:r.darkMode?{colors:{...(s=Re.darkMode)==null?void 0:s.colors,...r.darkMode.colors}}:Re.darkMode,applicantFormVisibleFields:r.applicantFormVisibleFields,applicantFormRequiredFields:r.applicantFormRequiredFields,allowedLanguages:r.allowedLanguages,applicantFormPages:r.applicantFormPages,reviewPageFields:r.reviewPageFields,reviewPageDisabled:r.reviewPageDisabled,fieldLabelMode:r.fieldLabelMode,companyFormVisibleFields:r.companyFormVisibleFields,companyFormRequiredFields:r.companyFormRequiredFields,companyFormPages:r.companyFormPages,companyReviewPageFields:r.companyReviewPageFields}}getCurrentTheme(){return this.currentTheme}resetTheme(){this.applyTheme(Re)}cleanup(){this.inputStyleElement&&(this.inputStyleElement.remove(),this.inputStyleElement=null),this.customStyleElement&&(this.customStyleElement.remove(),this.customStyleElement=null)}kebabCase(r){return r.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}}const bt=i.createContext(null),hr="1.0.4",es=({config:t,children:r})=>{const[s,n]=i.useState(null),a=i.useRef(!1),o=i.useRef(!1),c=i.useMemo(()=>{const y=new Kt(t),p=new qt(y),g=new Vt(y),T=new Yt(y),v=new Qt(y),E=new Gt(y),A=new Jt(y),k=new Zt(y),S=new Xt(y),M=new er(y),Y=new or(y),L=new xr;return{httpClient:y,applicantService:p,questionnaireService:g,uploadDocumentService:T,appropriatenessTestService:v,overviewService:E,riskScoringService:A,identityService:k,baseInformationService:S,investorCategorizationService:M,themeService:Y,themeManager:L}},[t]),d=i.useMemo(()=>({config:t,...c,currentTheme:s,createOrchestrator:()=>new ur(c.applicantService,c.questionnaireService,c.uploadDocumentService,c.appropriatenessTestService,c.overviewService,c.riskScoringService,c.identityService,c.investorCategorizationService)}),[t,c,s]);return i.useEffect(()=>((async()=>{if(a.current||o.current){console.log("[MetaKYC] Theme already loading or loaded, skipping...");return}a.current=!0;try{if(t.theme){console.log("[MetaKYC] Applying static theme from config"),c.themeManager.applyTheme(t.theme),n(c.themeManager.getCurrentTheme()),o.current=!0;return}console.log("[MetaKYC] Fetching theme from backend...");const p=await c.themeService.getThemeConfiguration();c.themeManager.applyTheme(p),n(c.themeManager.getCurrentTheme()),o.current=!0,console.log("[MetaKYC] Theme loaded and applied",p)}catch(p){console.warn("[MetaKYC] Failed to load theme, using default:",p),n(c.themeManager.getCurrentTheme()),o.current=!0}finally{a.current=!1}})(),()=>{c.themeManager.cleanup()}),[]),e.jsxs(bt.Provider,{value:d,children:[t.showVersion&&e.jsxs("div",{style:{fontSize:"0.625rem",color:"var(--metakyc-text-muted, #9ca3af)",opacity:.5,textAlign:"right",padding:"2px 8px",userSelect:"none",pointerEvents:"none",letterSpacing:"0.02em",lineHeight:1},children:["SDK v",hr]}),r]})};function Ne(){const t=i.useContext(bt);if(!t)throw new Error("useMetaKYC must be used within a MetaKYCProvider");return t}async function fr(t){return new Promise((r,s)=>{const n=new FileReader;n.readAsDataURL(t),n.onload=()=>{const o=n.result.split(",")[1];r(o)},n.onerror=a=>s(a)})}function ts(t,r){return t.size<=r}function rs(t,r){return r.split(",").map(n=>n.trim()).some(n=>{if(n.endsWith("/*")){const a=n.slice(0,-2);return t.type.startsWith(a)}return t.type===n})}function ut(t){if(t===0)return"0 Bytes";const r=1024,s=["Bytes","KB","MB","GB"],n=Math.floor(Math.log(t)/Math.log(r));return Math.round(t/Math.pow(r,n)*100)/100+" "+s[n]}function ss(t){return t}function Se(...t){return t.filter(Boolean).join(" ")}const at={APPLICANT_ID:"metakyc_applicant_id",WORKFLOW_STATE:"metakyc_workflow_state"};function gr(t){try{localStorage.setItem(at.APPLICANT_ID,t.toString())}catch(r){console.warn("Failed to save applicant ID to storage:",r)}}function br(){try{const t=localStorage.getItem(at.APPLICANT_ID);return t?parseInt(t,10):null}catch(t){return console.warn("Failed to retrieve applicant ID from storage:",t),null}}function vr(){try{localStorage.removeItem(at.APPLICANT_ID)}catch(t){console.warn("Failed to clear applicant ID from storage:",t)}}function kr(t){try{localStorage.setItem(at.WORKFLOW_STATE,JSON.stringify(t))}catch(r){console.warn("Failed to save workflow state to storage:",r)}}function ns(){try{const t=localStorage.getItem(at.WORKFLOW_STATE);return t?JSON.parse(t):null}catch(t){return console.warn("Failed to retrieve workflow state from storage:",t),null}}function jr(){try{localStorage.removeItem(at.WORKFLOW_STATE)}catch(t){console.warn("Failed to clear workflow state from storage:",t)}}function as(){vr(),jr()}function wr(t){const{createOrchestrator:r}=Ne(),[s,n]=i.useState(null),[a,o]=i.useState(!1),[c,d]=i.useState(null),y=i.useRef(null),p=t||br();i.useEffect(()=>{y.current||(y.current=r())},[r]),i.useEffect(()=>{var L;s&&p&&(gr(p),kr({applicantId:p,currentStepOrder:(L=s.currentStep)==null?void 0:L.order,status:s.status,lastUpdated:new Date().toISOString(),workflowKey:s.workFlowKey,nextWorkflowKey:s.nextWorkflowKey}))},[s,p]);const g=i.useRef(!1),T=i.useRef(!1),v=i.useCallback(async()=>{if(!(!p||!y.current)){if(g.current){console.log("[Workflow] Load already in progress, skipping...");return}g.current=!0,o(!0),d(null);try{const L=await y.current.initialize(p);n(L),T.current=!0}catch(L){d(L)}finally{o(!1),g.current=!1}}},[p]);i.useEffect(()=>{p&&!T.current&&v()},[p,v]);const E=i.useCallback(async()=>{if(y.current){if(g.current){console.log("[Workflow] Refresh already in progress, skipping...");return}g.current=!0,o(!0),d(null);try{const L=await y.current.refreshProgress();n(L)}catch(L){d(L)}finally{o(!1),g.current=!1}}},[]),A=i.useCallback(async()=>{if(y.current){o(!0),d(null);try{const L=await y.current.moveToNextStep();n(L)}catch(L){d(L)}finally{o(!1)}}},[]),k=i.useCallback(async()=>{if(y.current){o(!0),d(null);try{const L=await y.current.moveToPreviousStep();n(L)}catch(L){d(L)}finally{o(!1)}}},[]),S=i.useCallback(async L=>{if(y.current){o(!0),d(null);try{await y.current.submitCurrentStep(L);const B=await y.current.refreshProgress();n(B)}catch(B){throw d(B),B}finally{o(!1)}}},[]),M=wt.useMemo(()=>s!=null&&s.stepInfoList?[...s.stepInfoList].sort((L,B)=>L.order-B.order):[],[s==null?void 0:s.stepInfoList]),Y=wt.useMemo(()=>s?s.nextWorkflowKey&&s.nextWorkflowKey!==s.workFlowKey:!1,[s]);return{progress:s,applicantId:p,currentStep:(s==null?void 0:s.currentStep)||null,steps:M,status:(s==null?void 0:s.status)||Te.None,workflowResult:(s==null?void 0:s.workflowResult)||null,workflowKey:s==null?void 0:s.workFlowKey,nextWorkflowKey:s==null?void 0:s.nextWorkflowKey,hasWorkflowChanged:Y,isLoading:a,error:c,isComplete:(s==null?void 0:s.status)===Te.Finished,isOnHold:(s==null?void 0:s.status)===Te.OnHold,refreshProgress:E,moveToNext:A,moveBack:k,submitCurrentStep:S,orchestrator:y.current}}function Sr(t){const{questionnaireService:r,applicantService:s}=Ne(),[n,a]=i.useState(null),[o,c]=i.useState({}),[d,y]=i.useState(!1),[p,g]=i.useState(!1),[T,v]=i.useState(null),E=i.useRef(!1),A=i.useRef(null),k=i.useCallback(async()=>{var M,Y;if(t){if(E.current){console.log("[Questionnaire] Load already in progress, skipping...");return}E.current=!0,y(!0),v(null);try{const[L,B]=await Promise.all([r.getQuestionnaire(t),s.getApplicantData(t).catch(()=>null)]);if(a(L),(M=B==null?void 0:B.questionnaireResults)!=null&&M.length&&L){const U=new Map;for(const f of B.questionnaireResults)f.question&&((Y=f.answers)!=null&&Y.length)&&U.set(f.question.trim().toLowerCase(),f.answers);const X={},R=L.questionGroups.flatMap(f=>f.questions??[]);for(const f of R){const O=f.text.trim().toLowerCase();U.has(O)&&(X[f.id]=U.get(O))}c(X)}A.current=t}catch(L){v(L)}finally{y(!1),E.current=!1}}},[t,r,s]);i.useEffect(()=>{t&&A.current!==t&&k()},[t]);const S=i.useCallback(async M=>{g(!0),v(null);try{return await r.fillQuestionnaire(M)}catch(Y){throw v(Y),Y}finally{g(!1)}},[r]);return{questionnaire:n,initialAnswers:o,isLoading:d,isSubmitting:p,error:T,load:k,submit:S}}function Cr(t){const{uploadDocumentService:r}=Ne(),[s,n]=i.useState(null),[a,o]=i.useState(!1),[c,d]=i.useState(!1),[y,p]=i.useState(0),[g,T]=i.useState(null),v=i.useRef(!1),E=i.useRef(null),A=i.useCallback(async()=>{if(t){if(v.current){console.log("[UploadDocument] Load already in progress, skipping...");return}v.current=!0,o(!0),T(null);try{const S=await r.getUploadDocument(t);n(S),E.current=t}catch(S){T(S)}finally{o(!1),v.current=!1}}},[t,r]);i.useEffect(()=>{t&&E.current!==t&&A()},[t]);const k=i.useCallback(async S=>{d(!0),p(0),T(null);try{await r.fillUploadDocument(S),p(100)}catch(M){throw T(M),M}finally{d(!1)}},[r]);return{uploadDocument:s,isLoading:a,isSubmitting:c,uploadProgress:y,error:g,load:A,submit:k}}function is(t){const{appropriatenessTestService:r}=Ne(),[s,n]=i.useState(null),[a,o]=i.useState(!1),[c,d]=i.useState(!1),[y,p]=i.useState(null),[g,T]=i.useState(null),v=i.useRef(!1),E=i.useRef(null),A=i.useCallback(async()=>{if(t){if(v.current){console.log("[AppropriatenessTest] Load already in progress, skipping...");return}v.current=!0,o(!0),p(null);try{const S=await r.getAppropriatenessTest(t);n(S),E.current=t}catch(S){p(S)}finally{o(!1),v.current=!1}}},[t,r]);i.useEffect(()=>{t&&E.current!==t&&A()},[t]);const k=i.useCallback(async S=>{d(!0),p(null);try{const M=await r.fillAppropriatenessTest(S);return T(M),M}catch(M){throw p(M),M}finally{d(!1)}},[r]);return{test:s,result:g,isLoading:a,isSubmitting:c,error:y,load:A,submit:k}}function Nr(t){const{overviewService:r}=Ne(),[s,n]=i.useState(null),[a,o]=i.useState(!1),[c,d]=i.useState(!1),[y,p]=i.useState(null),g=i.useRef(!1),T=i.useRef(null),v=i.useCallback(async()=>{if(t){if(g.current){console.log("[Overview] Load already in progress, skipping...");return}g.current=!0,o(!0),p(null);try{const A=await r.getOverviewData(t);n(A),T.current=t}catch(A){p(A)}finally{o(!1),g.current=!1}}},[t,r]);i.useEffect(()=>{t&&T.current!==t&&v()},[t]);const E=i.useCallback(async()=>{if(t){d(!0),p(null);try{await r.passOverview(t)}catch(A){throw p(A),A}finally{d(!1)}}},[t,r]);return{overview:s,isLoading:a,isSubmitting:c,error:y,load:v,passOverview:E}}function Rr(t){const{identityService:r}=Ne(),[s,n]=i.useState(null),[a,o]=i.useState(!1),[c,d]=i.useState(null),y=i.useRef(!1),p=i.useCallback(async(v,E)=>{if(t){if(y.current){console.log("[Identity] Request already in progress, skipping...");return}y.current=!0,o(!0),d(null);try{const A={applicantId:t,restart:!1,redirectUrl:v||"",ttl:E||604800};console.log("Identity request input:",A);const k=await r.identityRequest(A);return console.log("Identity request result:",k),n(k),k}catch(A){throw d(A),A}finally{o(!1),y.current=!1}}},[t,r]),g=i.useCallback(async(v,E)=>{if(t){o(!0),d(null);try{const A={applicantId:t,restart:!1,redirectUrl:v,ttl:E},k=await r.identityCompanyRequest(A);return n(k),k}catch(A){throw d(A),A}finally{o(!1)}}},[t,r]),T=i.useCallback(async()=>{if(t){if(y.current){console.log("[Identity] Restart already in progress, skipping...");return}y.current=!0,o(!0),d(null);try{const v={applicantId:t,restart:!0,redirectUrl:"",ttl:604800};console.log("Restarting identity with input:",v);const E=await r.identityRequest(v);return console.log("Restart identity result:",E),n(E),E}catch(v){throw d(v),v}finally{o(!1),y.current=!1}}},[t,r]);return{identityData:s,provider:(s==null?void 0:s.provider)||null,token:(s==null?void 0:s.publicProviderTokenObject)||null,isLoading:a,error:c,requestIdentity:p,requestCompanyIdentity:g,restartIdentity:T}}function Ir(t){const{riskScoringService:r,applicantService:s}=Ne(),[n,a]=i.useState(null),[o,c]=i.useState({}),[d,y]=i.useState(!1),[p,g]=i.useState(!1),[T,v]=i.useState(null),[E,A]=i.useState(null),k=i.useRef(!1),S=i.useRef(null),M=i.useCallback(async()=>{var L;if(t){if(k.current){console.log("[RiskScoring] Load already in progress, skipping...");return}k.current=!0,y(!0),v(null);try{const[B,U]=await Promise.all([r.getRiskCriterias(t),s.getApplicantData(t).catch(()=>null)]);if(a(B),(L=U==null?void 0:U.riskScoringResults)!=null&&L.length){const X=U.riskScoringResults[0],R={};for(const f of X.riskCriteriaResults??[])if(f.riskCriteriaId!=null&&f.answer!=null&&f.answer!==""){const O=[...new Set(f.answer.split(",").map(q=>q.trim()).filter(q=>q!==""))];O.length>0&&(R[f.riskCriteriaId]=O)}c(R)}S.current=t}catch(B){v(B)}finally{y(!1),k.current=!1}}},[t,r,s]);i.useEffect(()=>{t&&S.current!==t&&M()},[t]);const Y=i.useCallback(async L=>{g(!0),v(null);try{const B=await r.submitRiskScoring(L);return A(B),B}catch(B){throw v(B),B}finally{g(!1)}},[r]);return{criteria:n,initialAnswers:o,result:E,isLoading:d,isSubmitting:p,error:T,load:M,submit:Y}}function vt(){const{applicantService:t,config:r}=Ne(),[s,n]=i.useState(!1),[a,o]=i.useState(null),c=i.useRef(!1),d=i.useRef(!1),y=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(E){const A=Math.random()*16|0;return(E==="x"?A:A&3|8).toString(16)}),p=i.useCallback(async E=>{var A;if(c.current)throw console.log("[Applicant] Create already in progress, skipping..."),new Error("Creation already in progress");c.current=!0,n(!0),o(null);try{if(E.applicantAdditionalDatas||(E.applicantAdditionalDatas=[]),(A=r.identityProviders)!=null&&A.sardinai){const S=y();console.log("[SardinAI] Generated session key:",S),E.applicantAdditionalDatas.push({paramName:"sessionKey",value:S})}return await t.createApplicant(E)}catch(k){throw o(k),k}finally{n(!1),c.current=!1}},[t,r]),g=i.useCallback(async E=>{n(!0),o(null);try{return await t.createCompanyApplicant(E)}catch(A){throw o(A),A}finally{n(!1)}},[t]),T=i.useCallback(async E=>{if(d.current)throw console.log("[Applicant] Data load already in progress, skipping..."),new Error("Data load already in progress");d.current=!0,n(!0),o(null);try{return await t.getApplicantData(E)}catch(A){throw o(A),A}finally{n(!1),d.current=!1}},[t]),v=i.useCallback(async E=>{n(!0),o(null);try{await t.stopProgress(E)}catch(A){throw o(A),A}finally{n(!1)}},[t]);return{isLoading:s,error:a,createApplicant:p,createCompanyApplicant:g,getApplicantData:T,stopProgress:v}}const os={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:n=!1,disabled:a,className:o,style:c,...d})=>{const y="inline-flex items-center justify-center rounded-lg font-medium transition-opacity border focus:outline-none focus:ring-2 focus:ring-offset-1 disabled:opacity-50 disabled:cursor-not-allowed",p={sm:"px-3 py-1.5 text-sm",md:"px-4 py-2 text-sm",lg:"px-6 py-3 text-base"},g={sm:{padding:"0.375rem 0.75rem",fontSize:"0.875rem"},md:{padding:"0.5rem 1rem",fontSize:"0.875rem"},lg:{padding:"0.75rem 1.5rem",fontSize:"1rem"}};return e.jsxs("button",{className:Se(y,p[s],o),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",borderRadius:"0.5rem",fontWeight:500,borderWidth:"1px",borderStyle:"solid",cursor:a||n?"not-allowed":"pointer",opacity:a||n?.5:1,lineHeight:"1.25rem",...g[s],...os[r],...c},disabled:a||n,...d,children:[n&&e.jsxs("svg",{className:"animate-spin -ml-1 mr-2 h-4 w-4",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),t]})},ye=i.forwardRef(({label:t,error:r,helperText:s,leftIcon:n,rightIcon:a,className:o,style:c,...d},y)=>e.jsxs("div",{className:"w-full",children:[t&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[t,d.required&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),e.jsxs("div",{className:"relative",children:[n&&e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:n}),e.jsx("input",{ref:y,className:Se("block w-full rounded-lg border px-3 py-2 text-sm transition-colors","focus:outline-none focus:ring-2 focus:ring-offset-0","disabled:opacity-60 disabled:cursor-not-allowed",n?"pl-10":"",a?"pr-10":"",o),style:{minHeight:"38px",backgroundColor:d.readOnly?"var(--metakyc-surface, #f3f4f6)":"var(--metakyc-input-bg, #ffffff)",color:"var(--metakyc-input-text, var(--metakyc-text-primary, #111827))",borderColor:r?"var(--metakyc-danger, #ef4444)":"var(--metakyc-input-border, var(--metakyc-border, #d1d5db))",cursor:d.readOnly?"default":void 0,...c},...d}),a&&e.jsx("div",{className:"absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none",children:a})]}),r&&e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-danger, #ef4444)"},children:r}),!r&&s&&e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:s})]}));ye.displayName="Input";const ee=({children:t,className:r,style:s,...n})=>e.jsx("div",{className:Se("metakyc-card rounded-xl shadow-sm border",r),style:{backgroundColor:"var(--metakyc-surface, #ffffff)",borderColor:"var(--metakyc-border, #e5e7eb)",borderWidth:"1px",borderStyle:"solid",borderRadius:"0.75rem",overflow:"hidden",...s},...n,children:t}),ge=({children:t,className:r,style:s,...n})=>e.jsx("div",{className:Se("px-6 py-4 border-b",r),style:{padding:"1rem 1.5rem",borderBottomWidth:"1px",borderBottomStyle:"solid",borderBottomColor:"var(--metakyc-border, #e5e7eb)",...s},...n,children:t}),te=({children:t,className:r,style:s,...n})=>e.jsx("div",{className:Se("px-6 py-4",r),style:{padding:"1rem 1.5rem",...s},...n,children:t}),be=({children:t,className:r,style:s,...n})=>e.jsx("div",{className:Se("px-6 py-4 border-t",r),style:{padding:"1rem 1.5rem",borderTopWidth:"1px",borderTopStyle:"solid",borderTopColor:"var(--metakyc-border, #e5e7eb)",...s},...n,children:t}),ls={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"}},kt=({children:t,variant:r="default",className:s,style:n,...a})=>e.jsx("span",{className:Se("inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium",s),style:{...ls[r],...n},...a,children:t}),Ee=({size:t="md",className:r,...s})=>{const n={sm:"h-4 w-4",md:"h-8 w-8",lg:"h-12 w-12"};return e.jsx("div",{className:Se("flex items-center justify-center",r),...s,children:e.jsxs("svg",{className:Se("animate-spin text-primary-500",n[t]),xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})})},mt=i.forwardRef(({label:t,error:r,helperText:s,options:n,placeholder:a,className:o,style:c,...d},y)=>e.jsxs("div",{className:"w-full",children:[t&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[t,d.required&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),e.jsxs("select",{ref:y,className:Se("block w-full rounded-lg border px-3 py-2 text-sm transition-colors","focus:outline-none focus:ring-2 focus:ring-offset-0","disabled:opacity-60 disabled:cursor-not-allowed",r?"border-danger-500":"",o),style:{minHeight:"38px",backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:"var(--metakyc-input-text, var(--metakyc-text-primary, #111827))",borderColor:r?"var(--metakyc-danger, #ef4444)":"var(--metakyc-input-border, var(--metakyc-border, #d1d5db))",...c},...d,children:[a&&e.jsx("option",{value:"",disabled:!0,style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:"var(--metakyc-text-secondary, #6b7280)"},children:a},"__placeholder__"),n.map((p,g)=>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-${g}`))]}),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})]}));mt.displayName="Select";const St=280,Er=({label:t,value:r,onChange:s,options:n,placeholder:a="Select...",disabled:o=!1,readOnly:c=!1,required:d=!1})=>{const y=o||c,[p,g]=i.useState(!1),[T,v]=i.useState(""),[E,A]=i.useState(null),[k,S]=i.useState({bg:"#ffffff",borderColor:"#d1d5db",textPrimary:"#111827",textSecondary:"#6b7280",primaryColor:"#2563eb",primaryLight:"#eff6ff",hoverBg:"#f9fafb"}),M=i.useRef(null),Y=i.useRef(null),L=i.useRef(null),B=i.useCallback(()=>{if(!Y.current)return null;const I=Y.current.getBoundingClientRect(),z=window.innerHeight-I.bottom<St&&I.top>St;return{top:z?I.top:I.bottom+4,left:I.left,width:I.width,openUp:z}},[]),U=i.useCallback(()=>{const I=getComputedStyle(document.documentElement),W=(_,me)=>I.getPropertyValue(_).trim()||me,z=W("--metakyc-input-bg",W("--metakyc-background","#ffffff"));S({bg:z,borderColor:W("--metakyc-input-border",W("--metakyc-border","#d1d5db")),textPrimary:W("--metakyc-input-text",W("--metakyc-text-primary","#111827")),textSecondary:W("--metakyc-text-secondary","#6b7280"),primaryColor:W("--metakyc-primary","#2563eb"),primaryLight:W("--metakyc-primary-light","#eff6ff"),hoverBg:W("--metakyc-surface",z)})},[]),X=i.useCallback(()=>{if(y)return;U();const I=B();I&&A(I),g(!0)},[y,B,U]),R=i.useCallback(()=>{g(!1),v("")},[]);i.useEffect(()=>{if(!p)return;const I=W=>{var _,me;const z=W.target;!((_=M.current)!=null&&_.contains(z))&&!((me=L.current)!=null&&me.contains(z))&&R()};return document.addEventListener("mousedown",I),()=>document.removeEventListener("mousedown",I)},[p,R]),i.useEffect(()=>{if(!p)return;const I=()=>{const W=B();W&&A(W)};return window.addEventListener("scroll",I,!0),window.addEventListener("resize",I),()=>{window.removeEventListener("scroll",I,!0),window.removeEventListener("resize",I)}},[p,B]);const f=n.filter(I=>I.label.toLowerCase().includes(T.toLowerCase())),O=I=>{y||s(r.includes(I)?r.filter(W=>W!==I):[...r,I])},q=(I,W)=>{W.stopPropagation(),y||s(r.filter(z=>z!==I))},Q=I=>{var W;return((W=n.find(z=>z.value===I))==null?void 0:W.label)||I},{bg:$,borderColor:G,textPrimary:se,textSecondary:V,primaryColor:he,primaryLight:ce,hoverBg:de}=k,fe=p&&E&&e.jsxs("div",{ref:L,className:"metakyc-multiselect-dropdown",style:{position:"fixed",top:E.openUp?void 0:E.top,bottom:E.openUp?window.innerHeight-E.top+4:void 0,left:E.left,width:E.width,zIndex:99999,borderRadius:"8px",boxShadow:"0 4px 16px rgba(0,0,0,0.18)",border:`1px solid ${G}`,backgroundColor:$,overflow:"hidden"},children:[e.jsx("div",{style:{padding:"8px",borderBottom:`1px solid ${G}`},children:e.jsx("input",{type:"text",value:T,onChange:I=>v(I.target.value),placeholder:"Search...",autoFocus:!0,onClick:I=>I.stopPropagation(),className:"metakyc-multiselect-search w-full",style:{display:"block",width:"100%",padding:"6px 8px",fontSize:"13px",borderRadius:"6px",border:`1px solid ${G}`,backgroundColor:$,color:se,outline:"none",boxSizing:"border-box"},onFocus:I=>{const W=getComputedStyle(document.documentElement),z=W.getPropertyValue("--metakyc-input-border-focus").trim()||W.getPropertyValue("--metakyc-primary").trim()||"#2563eb";I.currentTarget.style.backgroundColor=$,I.currentTarget.style.color=se,I.currentTarget.style.borderColor=z,I.currentTarget.style.outline="none",I.currentTarget.style.boxShadow=`0 0 0 2px ${z}33`},onBlur:I=>{I.currentTarget.style.backgroundColor=$,I.currentTarget.style.color=se,I.currentTarget.style.borderColor=G,I.currentTarget.style.outline="none",I.currentTarget.style.boxShadow="none"}})}),e.jsx("ul",{style:{listStyle:"none",margin:0,padding:"4px 0",maxHeight:"192px",overflowY:"auto"},children:f.length===0?e.jsx("li",{style:{padding:"8px 12px",fontSize:"13px",color:V},children:"No results"}):f.map(I=>{const W=r.includes(I.value);return e.jsxs("li",{onClick:()=>O(I.value),className:"metakyc-multiselect-option",style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",fontSize:"13px",cursor:"pointer",backgroundColor:W?ce:"transparent",color:W?he:se,userSelect:"none"},onMouseEnter:z=>{W||(z.currentTarget.style.backgroundColor=de)},onMouseLeave:z=>{W||(z.currentTarget.style.backgroundColor="transparent")},children:[e.jsx("input",{type:"checkbox",checked:W,readOnly:!0,style:{accentColor:he,pointerEvents:"none",flexShrink:0}}),e.jsx("span",{children:I.label})]},I.value)})}),r.length>0&&e.jsx("div",{style:{padding:"6px 12px",borderTop:`1px solid ${G}`},children:e.jsxs("button",{type:"button",onClick:()=>{s([]),v("")},style:{fontSize:"12px",color:"#ef4444",background:"none",border:"none",cursor:"pointer",padding:0},children:["Clear all (",r.length," selected)"]})})]});return e.jsxs("div",{className:"w-full metakyc-multiselect",ref:M,children:[t&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[t,d&&e.jsx("span",{style:{color:"var(--metakyc-error, #ef4444)",marginLeft:"4px"},children:"*"})]}),e.jsxs("div",{ref:Y,onClick:()=>p?R():X(),className:Se("metakyc-multiselect-trigger","w-full px-3 py-2 rounded-lg border text-sm transition-colors relative",y?"opacity-50 cursor-not-allowed":"cursor-pointer"),style:{minHeight:"38px",backgroundColor:"var(--metakyc-input-bg, #ffffff)",borderColor:p?"var(--metakyc-input-border-focus, var(--metakyc-primary, #2563eb))":"var(--metakyc-input-border, var(--metakyc-border, #d1d5db))",outline:p?"2px solid var(--metakyc-input-border-focus, var(--metakyc-primary, #2563eb))":"none",outlineOffset:"-1px"},children:[r.length===0?e.jsx("span",{className:"metakyc-multiselect-placeholder leading-6",style:{color:"var(--metakyc-text-secondary, #9ca3af)"},children:a}):e.jsx("div",{className:"flex flex-wrap gap-1 pr-6",children:r.map(I=>e.jsxs("span",{className:"metakyc-multiselect-chip inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium",style:{backgroundColor:"var(--metakyc-primary-light, #eff6ff)",color:"var(--metakyc-primary, #2563eb)"},children:[Q(I),!y&&e.jsx("button",{type:"button",onClick:W=>q(I,W),className:"metakyc-multiselect-chip-remove",style:{background:"transparent",border:"none",padding:"0 0 0 2px",margin:0,cursor:"pointer",fontSize:"14px",lineHeight:1,fontWeight:"bold",display:"inline-flex",alignItems:"center",boxShadow:"none",transform:"none",minWidth:0,width:"auto",height:"auto",letterSpacing:"normal",textTransform:"none"},children:"×"})]},I))}),e.jsx("span",{className:"metakyc-multiselect-arrow absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none text-xs",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:p?"▲":"▼"})]}),typeof document<"u"&&fe?pt.createPortal(fe,document.body):null]})},Ct=260,Me=({label:t,error:r,helperText:s,options:n,placeholder:a="Select...",value:o,onChange:c,disabled:d=!1,readOnly:y=!1,required:p=!1,className:g})=>{var me;const T=d||y,[v,E]=i.useState(!1),[A,k]=i.useState(""),[S,M]=i.useState(null),[Y,L]=i.useState({bg:"#ffffff",border:"#d1d5db",text:"#111827",textSecondary:"#6b7280",primary:"#2563eb",primaryLight:"#eff6ff",hoverBg:"#f9fafb"}),B=i.useCallback(()=>{const N=getComputedStyle(document.documentElement),re=(ne,ve)=>N.getPropertyValue(ne).trim()||ve,ue=re("--metakyc-input-bg",re("--metakyc-background","#ffffff"));L({bg:ue,border:re("--metakyc-input-border",re("--metakyc-border","#d1d5db")),text:re("--metakyc-input-text",re("--metakyc-text-primary","#111827")),textSecondary:re("--metakyc-text-secondary","#6b7280"),primary:re("--metakyc-primary","#2563eb"),primaryLight:re("--metakyc-primary-light","#eff6ff"),hoverBg:re("--metakyc-surface",ue)})},[]),U=i.useRef(null),X=i.useRef(null),R=i.useRef(null),f=i.useRef(null),O=i.useCallback(()=>{if(!X.current)return null;const N=X.current.getBoundingClientRect(),ue=window.innerHeight-N.bottom<Ct&&N.top>Ct;return{top:ue?N.top:N.bottom+4,left:N.left,width:N.width,openUp:ue}},[]),q=i.useCallback(()=>{if(T)return;B();const N=O();N&&M(N),E(!0)},[T,O,B]),Q=i.useCallback(()=>{E(!1),k("")},[]),$=()=>v?Q():q();i.useEffect(()=>{if(!v)return;const N=re=>{var ne,ve;const ue=re.target;!((ne=U.current)!=null&&ne.contains(ue))&&!((ve=R.current)!=null&&ve.contains(ue))&&Q()};return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},[v,Q]),i.useEffect(()=>{if(!v)return;const N=()=>{const re=O();re&&M(re)};return window.addEventListener("scroll",N,!0),window.addEventListener("resize",N),()=>{window.removeEventListener("scroll",N,!0),window.removeEventListener("resize",N)}},[v,O]),i.useEffect(()=>{v&&f.current&&setTimeout(()=>{var N;return(N=f.current)==null?void 0:N.focus()},0)},[v]);const G=n.filter(N=>N.label.toLowerCase().includes(A.toLowerCase())||N.value.toLowerCase().includes(A.toLowerCase())),se=(me=n.find(N=>N.value===o))==null?void 0:me.label,V=(N,re)=>{T||re||(c(N),Q())},{bg:he,border:ce,text:de,textSecondary:fe,primary:I,primaryLight:W,hoverBg:z}=Y,_=v&&S&&e.jsxs("div",{ref:R,className:"metakyc-searchable-select-dropdown",style:{position:"fixed",top:S.openUp?void 0:S.top,bottom:S.openUp?window.innerHeight-S.top+4:void 0,left:S.left,width:S.width,zIndex:99999,borderRadius:"8px",boxShadow:"0 4px 16px rgba(0,0,0,0.18)",border:`1px solid ${ce}`,backgroundColor:he,overflow:"hidden"},children:[e.jsx("div",{style:{padding:"8px",borderBottom:`1px solid ${ce}`},children:e.jsx("input",{ref:f,type:"text",value:A,onChange:N=>k(N.target.value),placeholder:"Search...",onClick:N=>N.stopPropagation(),className:"metakyc-searchable-select-search w-full",style:{display:"block",width:"100%",padding:"6px 8px",fontSize:"13px",borderRadius:"6px",border:`1px solid ${ce}`,backgroundColor:he,color:de,outline:"none",boxSizing:"border-box"},onFocus:N=>{const re=getComputedStyle(document.documentElement),ue=re.getPropertyValue("--metakyc-input-border-focus").trim()||re.getPropertyValue("--metakyc-primary").trim()||"#2563eb";N.currentTarget.style.backgroundColor=he,N.currentTarget.style.color=de,N.currentTarget.style.borderColor=ue,N.currentTarget.style.outline="none",N.currentTarget.style.boxShadow=`0 0 0 2px ${ue}33`},onBlur:N=>{N.currentTarget.style.backgroundColor=he,N.currentTarget.style.color=de,N.currentTarget.style.borderColor=ce,N.currentTarget.style.outline="none",N.currentTarget.style.boxShadow="none"}})}),e.jsx("ul",{style:{listStyle:"none",margin:0,padding:"4px 0",maxHeight:"208px",overflowY:"auto"},children:G.length===0?e.jsx("li",{style:{padding:"8px 12px",fontSize:"13px",color:fe},children:"No results"}):G.map(N=>{const re=N.value===o;return e.jsx("li",{className:"metakyc-searchable-select-option",onClick:()=>V(N.value,N.disabled),style:{padding:"8px 12px",fontSize:"13px",cursor:N.disabled?"not-allowed":"pointer",opacity:N.disabled?.4:1,backgroundColor:re?W:"transparent",color:re?I:de,userSelect:"none"},onMouseEnter:ue=>{!re&&!N.disabled&&(ue.currentTarget.style.backgroundColor=z)},onMouseLeave:ue=>{re||(ue.currentTarget.style.backgroundColor="transparent")},children:N.label},N.value)})})]});return e.jsxs("div",{className:Se("w-full metakyc-searchable-select",g),ref:U,children:[t&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[t,p&&e.jsx("span",{style:{color:"var(--metakyc-error, #ef4444)",marginLeft:"4px"},children:"*"})]}),e.jsxs("div",{ref:X,role:"button",tabIndex:T?-1:0,onClick:$,onKeyDown:N=>{(N.key==="Enter"||N.key===" ")&&(N.preventDefault(),$()),N.key==="Escape"&&Q()},className:Se("metakyc-searchable-select-trigger","w-full px-3 py-2 rounded-lg border text-sm transition-colors text-left","flex items-center justify-between gap-2","focus:outline-none",T?"opacity-60 cursor-not-allowed":"cursor-pointer"),style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:se?"var(--metakyc-input-text, var(--metakyc-text-primary, #111827))":"var(--metakyc-input-placeholder, var(--metakyc-text-muted, #9ca3af))",borderColor:r?"var(--metakyc-danger, #ef4444)":v?"var(--metakyc-input-border-focus, var(--metakyc-primary, #2563eb))":"var(--metakyc-input-border, var(--metakyc-border, #d1d5db))",minHeight:"38px",outline:v?"2px solid var(--metakyc-input-border-focus, var(--metakyc-primary, #2563eb))":"none",outlineOffset:"-1px"},children:[e.jsx("span",{className:"truncate flex-1",children:se||a}),e.jsx("span",{className:"flex-shrink-0 text-xs pointer-events-none",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:v?"▲":"▼"})]}),typeof document<"u"&&_?pt.createPortal(_,document.body):null,r&&e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-error, #ef4444)"},children:r}),!r&&s&&e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:s})]})};Me.displayName="SearchableSelect";function cs(t){const r=t.type;return r.startsWith("image/")?"image":r==="application/pdf"?"pdf":"file"}const Ar=({label:t,subtitle:r,error:s,accept:n,multiple:a=!1,maxSize:o,required:c,onChange:d,value:y=[],className:p})=>{const[g,T]=i.useState(!1),[v,E]=i.useState(null),A=i.useRef(null),k=i.useCallback(R=>{if(!R)return;E(null);const f=Array.from(R);if(o&&f.filter(q=>q.size>o).length>0){E(`File exceeds the maximum size of ${ut(o)}`);return}d==null||d(a?[...y,...f]:[f[0]])},[o,a,d,y]),S=i.useCallback(R=>{R.preventDefault(),R.stopPropagation(),T(!0)},[]),M=i.useCallback(R=>{R.preventDefault(),R.stopPropagation(),T(!1)},[]),Y=i.useCallback(R=>{R.preventDefault(),R.stopPropagation(),T(!1),k(R.dataTransfer.files)},[k]),L=()=>{var R;(R=A.current)==null||R.click()},B=R=>{E(null);const f=y.filter((O,q)=>q!==R);d==null||d(f)},U=s||v,X=y.length>0;return e.jsxs("div",{className:Se("metakyc-file-upload",p),style:{width:"100%"},children:[t&&e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"14px",fontWeight:600,color:"var(--metakyc-text-primary, #111827)"},children:[t,c&&e.jsx("span",{style:{color:"var(--metakyc-danger, #ef4444)",marginLeft:"2px"},children:"*"})]}),r&&e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"2px"},children:r})]}),e.jsxs("div",{className:"metakyc-file-dropzone",onClick:L,onDragOver:S,onDragLeave:M,onDrop:Y,style:{border:`2px dashed ${U?"var(--metakyc-danger, #ef4444)":g?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #d1d5db)"}`,borderRadius:"12px",padding:X?"20px":"32px 20px",textAlign:"center",cursor:"pointer",transition:"all 0.2s ease",backgroundColor:g?"color-mix(in srgb, var(--metakyc-primary, #2563eb) 5%, var(--metakyc-background, #ffffff))":"var(--metakyc-background, #ffffff)"},children:[e.jsx("input",{ref:A,type:"file",style:{display:"none"},accept:n,multiple:a,onChange:R=>{k(R.target.files),R.target.value=""}}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"12px"},children:[e.jsx("div",{style:{width:"48px",height:"48px",borderRadius:"12px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:g?"color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)":"var(--metakyc-surface, #f9fafb)",transition:"background-color 0.2s ease"},children:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:g?"var(--metakyc-primary, #2563eb)":"var(--metakyc-text-muted, #9ca3af)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{transition:"stroke 0.2s ease"},children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"17 8 12 3 7 8"}),e.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"15"})]})}),e.jsxs("div",{children:[e.jsxs("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",margin:0},children:[e.jsx("span",{style:{fontWeight:600,color:"var(--metakyc-primary, #2563eb)"},children:"Click to upload"})," ","or drag and drop"]}),(n||o)&&e.jsxs("p",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"4px"},children:[n&&e.jsx("span",{children:n}),n&&o&&e.jsx("span",{children:" · "}),o&&e.jsxs("span",{children:["Max ",ut(o)]})]})]})]})]}),X&&e.jsx("div",{style:{marginTop:"12px",display:"flex",flexDirection:"column",gap:"8px"},children:y.map((R,f)=>{const O=cs(R),q=O==="image",Q=q?URL.createObjectURL(R):null;return e.jsxs("div",{className:"metakyc-file-item",style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 12px",borderRadius:"10px",backgroundColor:"var(--metakyc-surface, #f9fafb)",border:"1px solid var(--metakyc-border, #e5e7eb)",transition:"background-color 0.15s ease"},children:[e.jsx("div",{style:{width:"40px",height:"40px",borderRadius:"8px",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden",backgroundColor:q?"transparent":"color-mix(in srgb, var(--metakyc-primary, #2563eb) 10%, transparent)"},children:q&&Q?e.jsx("img",{src:Q,alt:R.name,style:{width:"100%",height:"100%",objectFit:"cover",borderRadius:"8px"}}):O==="pdf"?e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"}),e.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),e.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"}),e.jsx("polyline",{points:"10 9 9 9 8 9"})]}):e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-primary, #2563eb)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("p",{style:{fontSize:"13px",fontWeight:500,color:"var(--metakyc-text-primary, #111827)",margin:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:R.name}),e.jsx("p",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)",margin:0,marginTop:"2px"},children:ut(R.size)})]}),e.jsx("button",{type:"button",onClick:$=>{$.stopPropagation(),B(f)},style:{display:"flex",alignItems:"center",justifyContent:"center",width:"28px",height:"28px",borderRadius:"6px",border:"none",backgroundColor:"transparent",color:"var(--metakyc-text-muted, #9ca3af)",cursor:"pointer",flexShrink:0,transition:"all 0.15s ease",padding:0},onMouseEnter:$=>{$.currentTarget.style.backgroundColor="color-mix(in srgb, var(--metakyc-danger, #ef4444) 10%, transparent)",$.currentTarget.style.color="var(--metakyc-danger, #ef4444)"},onMouseLeave:$=>{$.currentTarget.style.backgroundColor="transparent",$.currentTarget.style.color="var(--metakyc-text-muted, #9ca3af)"},children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},`${R.name}-${f}`)})}),U&&e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",marginTop:"6px"},children:U})]})},Tr=i.forwardRef(({countryCode:t="+1",onCountryCodeChange:r,className:s,...n},a)=>e.jsxs("div",{className:"w-full",children:[n.label&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[n.label,n.required&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:t,onChange:o=>r==null?void 0:r(o.target.value),className:Se("w-20 rounded-lg border px-3 py-2 text-sm","focus:outline-none focus:ring-2 focus:ring-offset-0"),style:{minHeight:"38px",backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:"var(--metakyc-text-primary, #111827)",borderColor:"var(--metakyc-border, #d1d5db)"},placeholder:"+1"}),e.jsx(ye,{ref:a,type:"tel",className:Se("flex-1",s),...n,label:""})]}),n.error&&e.jsx("p",{className:"mt-1 text-sm text-danger-500",children:n.error})]}));Tr.displayName="PhoneInput";/**
|
|
53
53
|
* @license lucide-react v0.574.0 - ISC
|
|
54
54
|
*
|
|
55
55
|
* This source code is licensed under the ISC license.
|
|
56
56
|
* See the LICENSE file in the root directory of this source tree.
|
|
57
|
-
*/const
|
|
57
|
+
*/const Fr=(...t)=>t.filter((r,s,n)=>!!r&&r.trim()!==""&&n.indexOf(r)===s).join(" ").trim();/**
|
|
58
58
|
* @license lucide-react v0.574.0 - ISC
|
|
59
59
|
*
|
|
60
60
|
* This source code is licensed under the ISC license.
|
|
61
61
|
* See the LICENSE file in the root directory of this source tree.
|
|
62
|
-
*/const
|
|
62
|
+
*/const ds=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();/**
|
|
63
63
|
* @license lucide-react v0.574.0 - ISC
|
|
64
64
|
*
|
|
65
65
|
* This source code is licensed under the ISC license.
|
|
66
66
|
* See the LICENSE file in the root directory of this source tree.
|
|
67
|
-
*/const
|
|
67
|
+
*/const us=t=>t.replace(/^([A-Z])|[\s-_]+(\w)/g,(r,s,n)=>n?n.toUpperCase():s.toLowerCase());/**
|
|
68
68
|
* @license lucide-react v0.574.0 - ISC
|
|
69
69
|
*
|
|
70
70
|
* This source code is licensed under the ISC license.
|
|
71
71
|
* See the LICENSE file in the root directory of this source tree.
|
|
72
|
-
*/const Nt=t=>{const r=
|
|
72
|
+
*/const Nt=t=>{const r=us(t);return r.charAt(0).toUpperCase()+r.slice(1)};/**
|
|
73
73
|
* @license lucide-react v0.574.0 - ISC
|
|
74
74
|
*
|
|
75
75
|
* This source code is licensed under the ISC license.
|
|
76
76
|
* See the LICENSE file in the root directory of this source tree.
|
|
77
|
-
*/var
|
|
77
|
+
*/var ps={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
|
|
78
78
|
* @license lucide-react v0.574.0 - ISC
|
|
79
79
|
*
|
|
80
80
|
* This source code is licensed under the ISC license.
|
|
81
81
|
* See the LICENSE file in the root directory of this source tree.
|
|
82
|
-
*/const
|
|
82
|
+
*/const ms=t=>{for(const r in t)if(r.startsWith("aria-")||r==="role"||r==="title")return!0;return!1};/**
|
|
83
83
|
* @license lucide-react v0.574.0 - ISC
|
|
84
84
|
*
|
|
85
85
|
* This source code is licensed under the ISC license.
|
|
86
86
|
* See the LICENSE file in the root directory of this source tree.
|
|
87
|
-
*/const
|
|
87
|
+
*/const ys=i.forwardRef(({color:t="currentColor",size:r=24,strokeWidth:s=2,absoluteStrokeWidth:n,className:a="",children:o,iconNode:c,...d},y)=>i.createElement("svg",{ref:y,...ps,width:r,height:r,stroke:t,strokeWidth:n?Number(s)*24/Number(r):s,className:Fr("lucide",a),...!o&&!ms(d)&&{"aria-hidden":"true"},...d},[...c.map(([p,g])=>i.createElement(p,g)),...Array.isArray(o)?o:[o]]));/**
|
|
88
88
|
* @license lucide-react v0.574.0 - ISC
|
|
89
89
|
*
|
|
90
90
|
* This source code is licensed under the ISC license.
|
|
91
91
|
* See the LICENSE file in the root directory of this source tree.
|
|
92
|
-
*/const
|
|
92
|
+
*/const Pr=(t,r)=>{const s=i.forwardRef(({className:n,...a},o)=>i.createElement(ys,{ref:o,iconNode:r,className:Fr(`lucide-${ds(Nt(t))}`,`lucide-${t}`,n),...a}));return s.displayName=Nt(t),s};/**
|
|
93
93
|
* @license lucide-react v0.574.0 - ISC
|
|
94
94
|
*
|
|
95
95
|
* This source code is licensed under the ISC license.
|
|
96
96
|
* See the LICENSE file in the root directory of this source tree.
|
|
97
|
-
*/const
|
|
97
|
+
*/const xs=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],Lr=Pr("chevron-left",xs);/**
|
|
98
98
|
* @license lucide-react v0.574.0 - ISC
|
|
99
99
|
*
|
|
100
100
|
* This source code is licensed under the ISC license.
|
|
101
101
|
* See the LICENSE file in the root directory of this source tree.
|
|
102
|
-
*/const xs=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],Lr=Fr("chevron-right",xs);function hs(t,r){const s=!r||r.length===0||r.every(n=>!n||!n.trim());if(t.isRequired&&s)return t.errorMessage||"This field is required";if(!s){const n=r[0]??"";if(n&&t.regex)try{if(!new RegExp(t.regex).test(n))return t.errorMessage||"Invalid format"}catch{}if(n!==""){const a=Number(n);if(!isNaN(a)&&n.trim()!==""){if(t.min!==void 0&&t.min!==null&&a<t.min)return`Minimum value is ${t.min}`;if(t.max!==void 0&&t.max!==null&&a>t.max)return`Maximum value is ${t.max}`}else{if(t.min!==void 0&&t.min!==null&&n.length<t.min)return`Minimum length is ${t.min} characters`;if(t.max!==void 0&&t.max!==null&&n.length>t.max)return`Maximum length is ${t.max} characters`}}}return null}function fs(t){const r=t.flatMap((n,a)=>(n.questions??[]).map((o,c)=>({question:o,groupIndex:a,qIdx:c}))),s=new Map;for(const n of r){const a=n.question.pageNumber!=null&&n.question.pageNumber>0?n.question.pageNumber:1;s.has(a)||s.set(a,[]),s.get(a).push(n)}return Array.from(s.entries()).sort(([n],[a])=>n-a).map(([,n])=>n)}const Mr=({applicantId:t,onComplete:r,onBack:s})=>{const{questionnaire:n,initialAnswers:a,isLoading:o,isSubmitting:c,error:d,submit:y}=wr(t),[p,g]=i.useState({}),[T,v]=i.useState({}),[E,A]=i.useState(0);i.useEffect(()=>{a&&Object.keys(a).length>0&&Object.keys(p).length===0&&g(a)},[a]);const k=i.useMemo(()=>n?fs(n.questionGroups):[],[n]),S=E===k.length-1,D=k[E]??[],Y=i.useCallback((R,f)=>{g(O=>({...O,[R]:f})),v(O=>{const q={...O};return delete q[R],q})},[]),L=i.useCallback(()=>{const R={};for(const{question:f}of D){const O=hs(f,p[f.id]??[]);O&&(R[f.id]=O)}return v(f=>({...f,...R})),Object.keys(R).length===0},[D,p]),B=()=>{L()&&A(R=>R+1)},U=()=>{E>0?A(R=>R-1):s==null||s()},X=async()=>{if(!(!L()||!n))try{const R=n.questionGroups.flatMap(O=>(O.questions??[]).map(q=>({questionId:q.id,values:p[q.id]??[]}))),f={applicantId:t,questionnarieId:n.id,questionResults:R};await y(f),r==null||r()}catch(R){console.error("Questionnaire submit error:",R)}};return o?e.jsx(ee,{children:e.jsx(te,{children:e.jsx(Ee,{className:"my-8"})})}):d?e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading questionnaire: ",d.message]})})}):n?e.jsxs(ee,{children:[e.jsxs(ge,{children:[e.jsx("h2",{className:"text-lg font-bold",children:n.displayName}),n.subtitle&&e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:n.subtitle}),k.length>1&&e.jsxs("div",{className:"flex items-center justify-between mt-3",children:[e.jsxs("span",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:["Page ",E+1," of ",k.length]}),e.jsx("div",{className:"flex items-center gap-1.5",children:k.map((R,f)=>e.jsx("div",{className:"rounded-full transition-all duration-200",style:{height:"6px",width:f===E?"20px":"6px",backgroundColor:f<=E?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},f))})]})]}),e.jsx(te,{className:"space-y-6",children:D.map(({question:R})=>e.jsx(gs,{question:R,value:p[R.id]??[],error:T[R.id],onChange:f=>Y(R.id,f)},R.id))}),e.jsxs(be,{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs(J,{type:"button",variant:"outline",onClick:U,style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(Pr,{size:14}),E>0?"Previous":"Back"]}),S?e.jsx(J,{type:"button",isLoading:c,onClick:X,children:"Continue"}):e.jsxs(J,{type:"button",onClick:B,style:{display:"flex",alignItems:"center",gap:"4px"},children:["Next",e.jsx(Lr,{size:14})]})]}),d&&e.jsx("div",{className:"mx-6 mb-4 p-3 bg-red-50 border border-red-200 rounded",children:e.jsx("p",{className:"text-red-600 text-sm",children:d.message})})]}):null},gs=({question:t,value:r,error:s,onChange:n})=>{var c;const o=(((c=t.defaultAnswers)==null?void 0:c.length)??0)>0?t.showAsDropdown?t.canMultipleAnswer?"multi-select":"single-select":t.canMultipleAnswer?"checkbox":"radio":"text";return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[t.text,t.isRequired&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),t.subtitle&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:t.subtitle}),t.description&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:t.description}),o==="text"&&e.jsx(ye,{value:r[0]??"",onChange:d=>n([d.target.value]),placeholder:t.subtitle?void 0:"Enter your answer…",error:s,required:t.isRequired}),o==="single-select"&&e.jsx(mt,{value:r[0]??"",onChange:d=>n([d.target.value]),options:(t.defaultAnswers??[]).map(d=>({value:d,label:d})),placeholder:"Select an option…",error:s,required:t.isRequired}),o==="radio"&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultAnswers??[]).map(d=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"radio",checked:r[0]===d,onChange:()=>n([d]),className:"metakyc-option-input",style:{width:"16px",height:"16px",minWidth:"16px",flexShrink:0,flexGrow:0,accentColor:"var(--metakyc-primary, #2563eb)",cursor:"pointer",margin:0,padding:0,display:"inline-block",verticalAlign:"middle"}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:d})]},d)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),(o==="checkbox"||o==="multi-select")&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultAnswers??[]).map(d=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"checkbox",checked:r.includes(d),onChange:y=>{y.target.checked?n([...r,d]):n(r.filter(p=>p!==d))},className:"metakyc-option-input",style:{width:"16px",height:"16px",minWidth:"16px",flexShrink:0,flexGrow:0,accentColor:"var(--metakyc-primary, #2563eb)",cursor:"pointer",margin:0,padding:0,display:"inline-block",verticalAlign:"middle"}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:d})]},d)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),s&&o==="text"&&null]})};function bs(t){const r=new Map;for(const s of t){const n=s.pageNumber!=null&&s.pageNumber>0?s.pageNumber:1;r.has(n)||r.set(n,[]),r.get(n).push(s)}return Array.from(r.entries()).sort(([s],[n])=>s-n).map(([,s])=>s)}const Dr=({applicantId:t,onComplete:r,onBack:s})=>{const{uploadDocument:n,isLoading:a,isSubmitting:o,error:c,submit:d}=Sr(t),[y,p]=i.useState({}),[g,T]=i.useState(null),[v,E]=i.useState(0),[A,k]=i.useState({}),S=i.useMemo(()=>n?bs(n.uploadDocumentFiles):[],[n]),D=S[v]??[],Y=v===S.length-1,L=S.length,B=i.useCallback(()=>{const f={};for(const O of D)O.isRequired&&(y[O.id]||[]).length===0&&(f[O.id]=`${O.displayName} is required`);return k(f),Object.keys(f).length===0},[D,y]),U=()=>{B()&&(E(f=>f+1),k({}))},X=()=>{v>0?(E(f=>f-1),k({})):s==null||s()},R=async()=>{if(!(!B()||!n)){T(null);try{const f=await Promise.all(n.uploadDocumentFiles.map(async q=>{const Q=y[q.id]||[],$=await Promise.all(Q.map(async G=>({fileName:G.name,fileData:await hr(G)})));return{uploadDocumentFileId:q.id,valueList:$}})),O={applicantId:t,uploadDocumentId:n.id,uploadDocumentResults:f};await d(O),r==null||r()}catch(f){T((f==null?void 0:f.message)||"Failed to submit documents. Please try again.")}}};return a?e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"48px 0",gap:"16px"},children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)"},children:"Loading document requirements..."})]})})}):c?e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"32px 0",gap:"12px",textAlign:"center"},children:[e.jsx("div",{style:{width:"48px",height:"48px",borderRadius:"50%",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 10%, transparent)",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),e.jsx("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]})}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-danger, #ef4444)",fontWeight:500},children:"Error loading document requirements"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-muted, #9ca3af)"},children:c.message})]})})}):n?e.jsxs(ee,{children:[e.jsxs(ge,{children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:n.displayName||"Upload Documents"}),n.subtitle&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",marginTop:"4px"},children:n.subtitle}),L>1&&e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginTop:"12px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)"},children:["Page ",v+1," of ",L]}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:S.map((f,O)=>e.jsx("div",{style:{height:"6px",width:O===v?"20px":"6px",borderRadius:"999px",transition:"all 0.2s ease",backgroundColor:O<=v?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},O))})]})]}),n.description&&v===0&&e.jsxs("div",{style:{margin:"0 24px",marginTop:"4px",display:"flex",gap:"10px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-primary, #2563eb) 5%, var(--metakyc-background, #ffffff))",border:"1px solid color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-primary, #2563eb)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:"1px"},children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-secondary, #374151)",margin:0,lineHeight:1.5},children:n.description})]}),e.jsx(te,{children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"24px"},children:D.map(f=>e.jsx(Er,{label:f.displayName,subtitle:f.subtitle,accept:f.allowedTypes,multiple:f.multipleFile,maxSize:f.maxEachFileSizeByte,required:f.isRequired,error:A[f.id],value:y[f.id]||[],onChange:O=>{T(null),k(q=>{const Q={...q};return delete Q[f.id],Q}),p(q=>({...q,[f.id]:O}))}},f.id))})}),g&&e.jsxs("div",{style:{margin:"0 24px",padding:"10px 14px",borderRadius:"8px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:g})]}),e.jsx(be,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[e.jsx(J,{type:"button",variant:"outline",onClick:X,children:v>0?"Previous":"Back"}),Y?e.jsx(J,{type:"button",isLoading:o,onClick:R,children:o?"Uploading...":"Continue"}):e.jsx(J,{type:"button",onClick:U,children:"Next"})]})})]}):null},Or=({applicantId:t,onComplete:r,onBack:s})=>{const{overview:n,isLoading:a,isSubmitting:o,error:c,passOverview:d}=Cr(t),y=async()=>{await d(),r==null||r()};return a?e.jsx(ee,{children:e.jsx(te,{children:e.jsx(Ee,{className:"my-8"})})}):c?e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading overview: ",c.message]})})}):n?e.jsxs(ee,{children:[e.jsxs(ge,{children:[e.jsx("h2",{className:"text-lg font-bold",children:n.title||"Overview"}),n.description&&e.jsx("p",{className:"mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:n.description})]}),e.jsx(te,{className:"space-y-8",children:n.steps&&n.steps.length>0?n.steps.sort((p,g)=>p.order-g.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(be,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{onClick:y,isLoading:o,children:"Continue"})]})]}):null};function vs(t){const r=(t??"en").toLowerCase().replace("_","-");try{return Intl.NumberFormat.supportedLocalesOf([r]),r}catch{return"en"}}function ks(t){return t.valueDataType===Me.Money&&Array.isArray(t.defaultValues)&&t.defaultValues.length>0}function js(t,r){const s=new Intl.NumberFormat(vs(r),{minimumFractionDigits:0,maximumFractionDigits:2});return t.replace(/([\d]+(?:\.\d+)?)/g,n=>{const a=parseFloat(n);return isNaN(a)?n:s.format(a)})}function ws(t,r){const s=!r||r.length===0||r.every(n=>!n||!n.trim());if(t.isRequired&&s)return t.errorMessage||`${t.displayName} is required`;if(!s){const n=r[0]??"";if(n&&t.regex)try{if(!new RegExp(t.regex).test(n))return t.errorMessage||"Invalid format"}catch{}const a=t.valueDataType===Me.Integer||t.valueDataType===Me.Money||t.valueDataType===Me.DigitOnly;if(a&&n.trim()!==""){const o=Number(n);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(!a&&n!==""){if(t.min!==void 0&&t.min!==null&&n.length<t.min)return`Minimum length is ${t.min} characters`;if(t.max!==void 0&&t.max!==null&&n.length>t.max)return`Maximum length is ${t.max} characters`}}return null}function Ss(t){const r=new Map;return t.forEach((s,n)=>{const a=s.pageNumber!=null&&s.pageNumber>0?s.pageNumber:1;r.has(a)||r.set(a,[]),r.get(a).push({criterion:s,idx:n})}),Array.from(r.entries()).sort(([s],[n])=>s-n).map(([,s])=>s)}function Cs(t){return t.builtInType===1?"country":!t.defaultValues||t.defaultValues.length===0?"text":t.multipleValue?"checkbox":"radio"}const zr=({applicantId:t,onComplete:r,onBack:s})=>{const{config:n}=Ne(),a=n.locale??"en",{criteria:o,initialAnswers:c,isLoading:d,isSubmitting:y,error:p,submit:g}=Rr(t),[T,v]=i.useState({}),[E,A]=i.useState({}),[k,S]=i.useState(0),[D,Y]=i.useState(!1);i.useEffect(()=>{c&&Object.keys(c).length>0&&Object.keys(T).length===0&&v(c)},[c]);const L=i.useMemo(()=>o&&o.length>0?Ss(o):[],[o]),B=k===L.length-1,U=L[k]??[];i.useEffect(()=>{!d&&o&&o.length===0&&!D&&!y&&(Y(!0),g({applicantId:t,criteriaValueInputs:[]}).then(()=>r==null?void 0:r()).catch(console.error))},[d,o,D,y,g,t,r]);const X=i.useCallback((Q,$)=>{v(G=>({...G,[Q]:$})),A(G=>{const se={...G};return delete se[Q],se})},[]),R=i.useCallback(()=>{const Q={};for(const{criterion:$}of U){const G=ws($,T[$.id]??[]);G&&(Q[$.id]=G)}return A($=>({...$,...Q})),Object.keys(Q).length===0},[U,T]),f=()=>{R()&&S(Q=>Q+1)},O=()=>{k>0?S(Q=>Q-1):s==null||s()},q=async()=>{if(!(!R()||!o))try{const Q=o.map(G=>{const se=(T[G.id]??[]).filter(V=>V&&V.trim());return se.length>0?{riskCriteriaId:G.id,values:se}:null}).filter(G=>G!==null);await g({applicantId:t,criteriaValueInputs:Q}),r==null||r()}catch(Q){console.error("Risk scoring submit error:",Q)}};return d?e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center text-sm mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Loading risk scoring criteria…"})]})}):!d&&o&&o.length===0?e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center text-sm mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"No criteria required. Moving to next step…"})]})}):p?e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading criteria: ",p.message]})})}):o?e.jsxs(ee,{children:[e.jsxs(ge,{children:[e.jsx("h2",{className:"text-lg font-bold",children:"Risk Assessment"}),e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Please answer the following questions for risk evaluation"}),L.length>1&&e.jsxs("div",{className:"flex items-center justify-between mt-3",children:[e.jsxs("span",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:["Page ",k+1," of ",L.length]}),e.jsx("div",{className:"flex items-center gap-1.5",children:L.map((Q,$)=>e.jsx("div",{className:"rounded-full transition-all duration-200",style:{height:"6px",width:$===k?"20px":"6px",backgroundColor:$<=k?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},$))})]})]}),e.jsx(te,{className:"space-y-6",children:U.map(({criterion:Q})=>e.jsx(Ns,{criterion:Q,value:T[Q.id]??[],error:E[Q.id],locale:a,onChange:$=>X(Q.id,$)},Q.id))}),e.jsxs(be,{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs(J,{type:"button",variant:"outline",onClick:O,style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(Pr,{size:14}),k>0?"Previous":"Back"]}),B?e.jsx(J,{type:"button",isLoading:y,onClick:q,children:"Continue"}):e.jsxs(J,{type:"button",onClick:f,style:{display:"flex",alignItems:"center",gap:"4px"},children:["Next",e.jsx(Lr,{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},Ns=({criterion:t,value:r,error:s,locale:n,onChange:a})=>{const o=Cs(t),c=t.valueDataType===Me.Integer||t.valueDataType===Me.Money||t.valueDataType===Me.DigitOnly,d=ks(t),y=p=>d?js(p,n):p;return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[t.displayName,t.isRequired&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),t.description&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:t.description}),c&&(t.min!==void 0||t.max!==void 0)&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:t.min!==void 0&&t.max!==void 0?`Range: ${t.min} – ${t.max}`:t.min!==void 0?`Minimum: ${t.min}`:`Maximum: ${t.max}`}),o==="text"&&e.jsx(ye,{value:r[0]??"",onChange:p=>a([p.target.value]),type:c?"number":"text",placeholder:"Enter your answer…",error:s,required:t.isRequired,min:t.min,max:t.max,onKeyDown:p=>{t.valueDataType===Me.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:()=>a([p]),className:"metakyc-option-input",style:{width:"16px",height:"16px",minWidth:"16px",flexShrink:0,flexGrow:0,accentColor:"var(--metakyc-primary, #2563eb)",cursor:"pointer",margin:0,padding:0,display:"inline-block",verticalAlign:"middle"}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:y(p)})]},p)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),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:g=>{g.target.checked?a([...r,p]):a(r.filter(T=>T!==p))},className:"metakyc-option-input",style:{width:"16px",height:"16px",minWidth:"16px",flexShrink:0,flexGrow:0,accentColor:"var(--metakyc-primary, #2563eb)",cursor:"pointer",margin:0,padding:0,display:"inline-block",verticalAlign:"middle"}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:y(p)})]},p)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),o==="country"&&e.jsx(mt,{value:r[0]??"",onChange:p=>a([p.target.value]),options:[{value:"US",label:"United States"},{value:"GB",label:"United Kingdom"},{value:"DE",label:"Germany"},{value:"FR",label:"France"},{value:"AE",label:"United Arab Emirates"}],placeholder:"Select a country…",error:s,required:t.isRequired})]})},$r=({applicantId:t,onComplete:r,onBack:s})=>{const{investorCategorizationService:n}=Ne(),[a,o]=i.useState(null),[c,d]=i.useState(!1),[y,p]=i.useState(null),g=async T=>{if(T.preventDefault(),a===null){p("Please select an investor type");return}d(!0),p(null);try{const v={applicantId:t,investorType:a};console.log("Submitting investor categorization:",v);const E=await n.setInvestorCategorization(v);console.log("Investor categorization result:",E),r==null||r()}catch(v){console.error("Error submitting investor categorization:",v),p(v.message||"Failed to submit investor categorization")}finally{d(!1)}};return e.jsx("form",{onSubmit:g,children:e.jsxs(ee,{children:[e.jsxs(ge,{children:[e.jsx("h2",{className:"text-lg font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Which statement best describes you?"}),e.jsx("p",{className:"mt-2",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"All Tokenise clients are treated as Retail Investors under EU regulation, which gives you the highest level of investor protection. For our internal purposes, we ask you to select the description that best matches your situation"})]}),e.jsxs(te,{className:"space-y-4",children:[e.jsx("p",{className:"text-sm font-medium mb-3",style:{color:"var(--metakyc-text-secondary, #374151)"},children:"Choose one"}),e.jsx("label",{className:"block p-4 border-2 rounded-lg cursor-pointer transition-all",style:{borderColor:a===je.Individual?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:a===je.Individual?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:je.Individual,checked:a===je.Individual,onChange:()=>o(je.Individual),className:"mt-1"}),e.jsxs("div",{className:"ml-3",children:[e.jsx("div",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Individual investor"}),e.jsx("div",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"(Recommended) Most of our clients choose this option. Provides the strongest protection and aligns with our mission to make investing accessible to everyone."})]})]})}),e.jsx("label",{className:"block p-4 border-2 rounded-lg cursor-pointer transition-all",style:{borderColor:a===je.Sophisticated?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:a===je.Sophisticated?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:je.Sophisticated,checked:a===je.Sophisticated,onChange:()=>o(je.Sophisticated),className:"mt-1"}),e.jsxs("div",{className:"ml-3",children:[e.jsx("div",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Sophisticated investor"}),e.jsx("div",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"In the last 2 years, I have done one or more of the following:"}),e.jsxs("ul",{className:"text-sm mt-2 space-y-1 list-none",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:[e.jsx("li",{children:"Worked in private equity or provided capital to small and medium enterprises, and/or"}),e.jsx("li",{children:"Been the director of a company with an annual turnover of at least (USD) $2m million, and/or"}),e.jsx("li",{children:"Invested directly in at least 2 private (not listed) companies."})]})]})]})}),e.jsx("label",{className:"block p-4 border-2 rounded-lg cursor-pointer transition-all",style:{borderColor:a===je.HighNetWorth?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:a===je.HighNetWorth?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:je.HighNetWorth,checked:a===je.HighNetWorth,onChange:()=>o(je.HighNetWorth),className:"mt-1"}),e.jsxs("div",{className:"ml-3",children:[e.jsx("div",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"High networth investor"}),e.jsxs("div",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:["I earn more than (USD/EUR) $150,000 per year, and/or",e.jsx("br",{}),"I have net assets (excluding my main property) of at least $/EUR 300,000"]})]})]})}),y&&e.jsx("div",{className:"p-4 rounded-lg",style:{backgroundColor:"#fee2e2",border:"1px solid #fca5a5"},children:e.jsxs("p",{className:"text-sm",style:{color:"#991b1b"},children:[e.jsx("strong",{children:"Error:"})," ",y]})})]}),e.jsxs(be,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"submit",isLoading:c,disabled:a===null,children:"Submit"})]})]})})};function Rt(t){const r=t.split(":").map(Number);return r.length===3?r[0]*3600+r[1]*60+r[2]:0}function yt(t){const r=Math.floor(t/60),s=t%60;return`${r.toString().padStart(2,"0")}:${s.toString().padStart(2,"0")}`}const Br=({applicantId:t,onComplete:r,onBack:s})=>{const{appropriatenessTestService:n}=Ne(),[a,o]=i.useState(null),[c,d]=i.useState(!0),[y,p]=i.useState(!1),[g,T]=i.useState(null),[v,E]=i.useState({}),[A,k]=i.useState(0),[S,D]=i.useState(!1),[Y,L]=i.useState(!1),[B,U]=i.useState(0),[X,R]=i.useState(0),[f,O]=i.useState(null);i.useEffect(()=>{(async()=>{try{d(!0),T(null);const z=await n.getAppropriatenessTest(t);if(o(z),z.waitTimeSpanForNextTry&&z.waitTimeSpanForNextTry!=="00:00:00"){const _=Rt(z.waitTimeSpanForNextTry);_>0&&U(_)}}catch(z){T(z.message||"Failed to load appropriateness test")}finally{d(!1)}})()},[t,n]),i.useEffect(()=>{if(!S||A<=0)return;const z=setInterval(()=>{k(_=>_<=1?(L(!0),0):_-1)},1e3);return()=>clearInterval(z)},[S,A]),i.useEffect(()=>{if(B<=0)return;const z=setInterval(()=>{U(_=>_<=1?0:_-1)},1e3);return()=>clearInterval(z)},[B]),i.useEffect(()=>{Y&&!y&&G()},[Y]);const q=()=>{a&&(D(!0),k(a.testDurationSec),R(0),E({}),T(null))},Q=(z,_)=>{E(me=>({...me,[z]:_}))},$=i.useCallback(async()=>{try{const z=await n.getAppropriatenessTest(t);if(o(z),z.waitTimeSpanForNextTry&&z.waitTimeSpanForNextTry!=="00:00:00"){const _=Rt(z.waitTimeSpanForNextTry);_>0&&U(_)}}catch{}},[t,n]),G=async z=>{if(a){if(!Y){const _=a.appropriatenessQuestions.length-Object.keys(v).length;if(_>0){T(`Please answer all questions. ${_} remaining.`);return}}p(!0),T(null);try{const _=a.appropriatenessQuestions.map(N=>({appropriatenessQuestionId:N.id,value:v[N.id]||""})),me={applicantId:t,appropriatenessTestId:a.id,appropriatenessQuestionResults:_};try{const N=await n.fillAppropriatenessTest(me);N.isSuccess?O({success:!0,message:N.message||"Congratulations! You have passed the test."}):(O({success:!1,message:N.message||"You did not pass the test."}),setTimeout(()=>$(),1e3))}catch(N){if(N.code===400&&N.message)O({success:!1,message:N.message}),setTimeout(()=>$(),1500);else throw N}}catch(_){T(_.message||"Failed to submit test. Please try again."),se()}finally{p(!1)}}},se=()=>{D(!1),L(!1),E({}),R(0)};if(c)return e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"48px 0",gap:"16px"},children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)"},children:"Loading test..."})]})})});if(!a)return e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("div",{style:{textAlign:"center",padding:"48px 0"},children:[e.jsx("p",{style:{fontSize:"16px",fontWeight:600,color:"var(--metakyc-danger, #ef4444)"},children:"No test data available"}),g&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"8px"},children:g})]})})});const V=a.testAllowedMaxTry-a.totalFailedTries,he=a.appropriatenessQuestions.length,ce=Object.keys(v).length;if(B>0)return e.jsxs(ee,{children:[e.jsx(ge,{children:e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:a.displayName})}),e.jsx(te,{children:e.jsxs("div",{style:{textAlign:"center",padding:"32px 0"},children:[e.jsx("div",{style:{width:"100px",height:"100px",borderRadius:"50%",margin:"0 auto 20px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"color-mix(in srgb, var(--metakyc-primary, #2563eb) 8%, transparent)"},children:e.jsx("span",{style:{fontSize:"28px",fontWeight:700,color:"var(--metakyc-primary, #2563eb)",fontVariantNumeric:"tabular-nums"},children:yt(B)})}),e.jsx("p",{style:{fontSize:"15px",fontWeight:500,color:"var(--metakyc-text-primary, #111827)"},children:"Please wait before retrying"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"4px"},children:"You can attempt the test again once the timer expires"}),g&&e.jsx("div",{style:{marginTop:"20px",padding:"12px 16px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:g})})]})})]});if(f){const z=()=>{O(null),se(),T(null)};return e.jsxs(ee,{children:[e.jsx(te,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",textAlign:"center",padding:"40px 16px",gap:"16px"},children:[e.jsx("div",{style:{width:"72px",height:"72px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:f.success?"color-mix(in srgb, var(--metakyc-success, #10b981) 12%, transparent)":"color-mix(in srgb, var(--metakyc-danger, #ef4444) 10%, transparent)"},children:f.success?e.jsxs("svg",{width:"36",height:"36",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-success, #10b981)",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),e.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]}):e.jsxs("svg",{width:"36",height:"36",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),e.jsx("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]})}),e.jsx("h2",{style:{fontSize:"20px",fontWeight:700,color:f.success?"var(--metakyc-success, #10b981)":"var(--metakyc-danger, #ef4444)",margin:0},children:f.success?"Test Passed":"Test Failed"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",margin:0,lineHeight:1.6,maxWidth:"400px",whiteSpace:"pre-line"},children:f.message}),!f.success&&V>0&&e.jsx("div",{style:{marginTop:"4px",padding:"10px 20px",borderRadius:"10px",backgroundColor:"var(--metakyc-surface, #f9fafb)",border:"1px solid var(--metakyc-border, #e5e7eb)"},children:e.jsxs("p",{style:{fontSize:"13px",color:"var(--metakyc-text-muted, #9ca3af)",margin:0},children:["You have ",e.jsx("strong",{style:{color:"var(--metakyc-text-primary, #111827)"},children:V})," attempt",V!==1?"s":""," remaining"]})}),!f.success&&V<=0&&e.jsx("div",{style:{marginTop:"4px",padding:"10px 20px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:"No attempts remaining. Please contact support for assistance."})})]})}),e.jsx(be,{children:e.jsx("div",{style:{display:"flex",justifyContent:"center",width:"100%",gap:"12px"},children:f.success?e.jsx(J,{type:"button",onClick:()=>r==null?void 0:r(),children:"Continue"}):e.jsxs(e.Fragment,{children:[V>0&&B<=0&&e.jsx(J,{type:"button",onClick:z,children:"Retake Test"}),V>0&&B>0&&e.jsx(J,{type:"button",onClick:z,children:"OK"}),V<=0&&s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"})]})})})]})}if(!S)return e.jsxs(ee,{children:[e.jsxs(ge,{children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:a.displayName}),a.subtitle&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",marginTop:"4px"},children:a.subtitle})]}),e.jsxs(te,{children:[a.description&&e.jsxs("div",{style:{marginBottom:"20px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-primary, #2563eb) 5%, var(--metakyc-background, #ffffff))",border:"1px solid color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)",display:"flex",gap:"10px"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-primary, #2563eb)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:"1px"},children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-secondary, #374151)",margin:0,lineHeight:1.5},children:a.description})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px",marginBottom:"20px"},children:[e.jsx(ct,{icon:"questions",label:"Questions",value:String(a.totalQuestionCount)}),e.jsx(ct,{icon:"time",label:"Time Limit",value:yt(a.testDurationSec)}),e.jsx(ct,{icon:"target",label:"Pass Requirement",value:`${a.testCorrectAnswerPassLimit} correct`}),e.jsx(ct,{icon:"retry",label:"Attempts Left",value:String(V),variant:V<=1?"warning":"default"})]}),g&&e.jsxs("div",{style:{marginBottom:"16px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)",display:"flex",gap:"10px"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:"1px"},children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),e.jsxs("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0,lineHeight:1.5},children:[e.jsx("strong",{children:"Previous attempt:"})," ",g]})]}),V<=0&&e.jsx("div",{style:{padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:"You have used all your attempts. Please contact support for assistance."})})]}),e.jsx(be,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:s?"space-between":"flex-end",width:"100%"},children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"button",onClick:q,disabled:V<=0,children:"Start Test"})]})})]});const de=a.appropriatenessQuestions[X],fe=X===he-1,I=ce===he,W=A<=60;return e.jsxs(ee,{children:[e.jsxs(ge,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:a.displayName}),e.jsxs("p",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"2px"},children:["Question ",X+1," of ",he]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 14px",borderRadius:"999px",backgroundColor:W?"color-mix(in srgb, var(--metakyc-danger, #ef4444) 10%, transparent)":"var(--metakyc-surface, #f3f4f6)",transition:"all 0.3s ease"},children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:W?"var(--metakyc-danger, #ef4444)":"var(--metakyc-text-muted, #9ca3af)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),e.jsx("span",{style:{fontSize:"16px",fontWeight:700,fontVariantNumeric:"tabular-nums",color:W?"var(--metakyc-danger, #ef4444)":"var(--metakyc-text-primary, #111827)",transition:"color 0.3s ease"},children:yt(A)})]})]}),e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsx("div",{style:{height:"4px",borderRadius:"999px",backgroundColor:"var(--metakyc-border, #e5e7eb)",overflow:"hidden"},children:e.jsx("div",{style:{height:"100%",borderRadius:"999px",backgroundColor:"var(--metakyc-primary, #2563eb)",width:`${ce/he*100}%`,transition:"width 0.3s ease"}})}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:"4px"},children:[e.jsxs("span",{style:{fontSize:"11px",color:"var(--metakyc-text-muted, #9ca3af)"},children:[ce," answered"]}),e.jsxs("span",{style:{fontSize:"11px",color:"var(--metakyc-text-muted, #9ca3af)"},children:[V," attempt",V!==1?"s":""," left"]})]})]})]}),e.jsxs(te,{children:[de&&e.jsx(Is,{question:de,index:X,selectedAnswer:v[de.id],onSelect:z=>Q(de.id,z),disabled:y}),he>1&&e.jsx("div",{style:{display:"flex",justifyContent:"center",gap:"6px",marginTop:"20px",flexWrap:"wrap"},children:a.appropriatenessQuestions.map((z,_)=>e.jsx("button",{type:"button",onClick:()=>R(_),style:{width:"28px",height:"28px",borderRadius:"8px",border:_===X?"2px solid var(--metakyc-primary, #2563eb)":"1px solid var(--metakyc-border, #e5e7eb)",backgroundColor:v[z.id]?_===X?"color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)":"color-mix(in srgb, var(--metakyc-primary, #2563eb) 8%, transparent)":_===X?"var(--metakyc-surface, #f9fafb)":"var(--metakyc-background, #ffffff)",color:v[z.id]?"var(--metakyc-primary, #2563eb)":"var(--metakyc-text-muted, #9ca3af)",fontSize:"12px",fontWeight:600,cursor:"pointer",transition:"all 0.15s ease",padding:0,display:"flex",alignItems:"center",justifyContent:"center"},children:_+1},z.id))}),Y&&e.jsxs("div",{style:{marginTop:"16px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, #f59e0b 10%, transparent)",border:"1px solid color-mix(in srgb, #f59e0b 25%, transparent)",display:"flex",alignItems:"center",gap:"10px"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"#f59e0b",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),e.jsx("p",{style:{fontSize:"13px",color:"#b45309",margin:0,fontWeight:500},children:"Time's up! Your answers are being submitted."})]}),g&&!Y&&e.jsx("div",{style:{marginTop:"16px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:g})})]}),e.jsx(be,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[e.jsx(J,{type:"button",variant:"outline",onClick:()=>{X>0?R(z=>z-1):s==null||s()},disabled:y,children:X>0?"Previous":"Cancel"}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[!fe&&e.jsx(J,{type:"button",onClick:()=>R(z=>z+1),children:"Next"}),(fe||I)&&e.jsx(J,{type:"button",isLoading:y,onClick:()=>G(),disabled:!I&&!Y,style:{opacity:I||Y?1:.5},children:Y?"Submitting...":"Submit Test"})]})]})})]})},Rs={questions:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M9 11l3 3L22 4"}),e.jsx("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),time:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),target:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("circle",{cx:"12",cy:"12",r:"6"}),e.jsx("circle",{cx:"12",cy:"12",r:"2"})]}),retry:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})},ct=({icon:t,label:r,value:s,variant:n="default"})=>{const a=n==="warning";return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px",padding:"14px",borderRadius:"10px",backgroundColor:a?"color-mix(in srgb, #f59e0b 8%, transparent)":"var(--metakyc-surface, #f9fafb)",border:a?"1px solid color-mix(in srgb, #f59e0b 20%, transparent)":"1px solid var(--metakyc-border, #e5e7eb)"},children:[e.jsx("div",{style:{color:a?"#f59e0b":"var(--metakyc-primary, #2563eb)",flexShrink:0},children:Rs[t]}),e.jsxs("div",{children:[e.jsx("p",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)",margin:0},children:r}),e.jsx("p",{style:{fontSize:"15px",fontWeight:600,color:a?"#b45309":"var(--metakyc-text-primary, #111827)",margin:0,marginTop:"1px"},children:s})]})]})},Is=({question:t,selectedAnswer:r,onSelect:s,disabled:n})=>e.jsxs("div",{children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[t.groupName&&e.jsx("span",{style:{display:"inline-block",fontSize:"11px",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em",color:"var(--metakyc-primary, #2563eb)",marginBottom:"8px"},children:t.groupName}),e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--metakyc-text-primary, #111827)",margin:0,lineHeight:1.5},children:t.question})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.answers.map((a,o)=>{const c=r===a;return e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"12px",padding:"14px 16px",borderRadius:"10px",border:`2px solid ${c?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}`,backgroundColor:c?"color-mix(in srgb, var(--metakyc-primary, #2563eb) 5%, var(--metakyc-background, #ffffff))":"var(--metakyc-background, #ffffff)",cursor:n?"default":"pointer",transition:"all 0.15s ease",opacity:n?.6:1},onMouseEnter:d=>{!n&&!c&&(d.currentTarget.style.borderColor="color-mix(in srgb, var(--metakyc-primary, #2563eb) 50%, var(--metakyc-border, #e5e7eb))")},onMouseLeave:d=>{c||(d.currentTarget.style.borderColor="var(--metakyc-border, #e5e7eb)")},children:[e.jsx("div",{style:{width:"20px",height:"20px",borderRadius:"50%",border:`2px solid ${c?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #d1d5db)"}`,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,transition:"border-color 0.15s ease"},children:c&&e.jsx("div",{style:{width:"10px",height:"10px",borderRadius:"50%",backgroundColor:"var(--metakyc-primary, #2563eb)"}})}),e.jsx("input",{type:"radio",name:`q-${t.id}`,value:a,checked:c,onChange:()=>s(a),disabled:n,style:{position:"absolute",opacity:0,width:0,height:0}}),e.jsx("span",{style:{fontSize:"14px",color:c?"var(--metakyc-text-primary, #111827)":"var(--metakyc-text-secondary, #6b7280)",fontWeight:c?500:400,transition:"color 0.15s ease"},children:a})]},o)})})]}),_r=({applicantId:t,onComplete:r,onBack:s})=>{var Ge,ze,et,Ue;const{applicantService:n,baseInformationService:a,identityService:o,config:c,currentTheme:d}=Ne(),{identityData:y,provider:p,token:g,isLoading:T,error:v,requestIdentity:E,restartIdentity:A}=Nr(t),[k,S]=i.useState(null),[D,Y]=i.useState(null),[L,B]=i.useState([]),[U,X]=i.useState([]),[R,f]=i.useState(!0),[O,q]=i.useState(!1),[Q,$]=i.useState(null),[G,se]=i.useState(!1),V=i.useRef(!1),[he,ce]=i.useState({}),[de,fe]=i.useState({}),I=d!=null&&d.reviewPageFields&&d.reviewPageFields.length>0?d.reviewPageFields[0]:null,W=!!(d!=null&&d.reviewPageDisabled),z=i.useRef(!1);z.current=W;const _=qe.useForm({defaultValues:{street:"",streetNumber:"",city:"",zip:"",country:"",nationality:"",phonenumber:""}});i.useEffect(()=>{if(W){V.current||(V.current=!0,E().then(()=>q(!0)).catch(M=>console.error("[Identity] Auto-request failed:",M)).finally(()=>f(!1)));return}(async()=>{try{const[M,K,H]=await Promise.all([n.getApplicantData(t),a.getCountries("","en"),a.getCountries("","en",40)]);Y(M);const Z=new Set,m=K.map(h=>({value:h.abbreviation3||h.abbreviation,label:h.name})).filter(h=>!h.value||Z.has(h.value)?!1:(Z.add(h.value),!0));B(m);const C=new Set,F=H.filter(h=>h.countryCode).map(h=>({value:h.countryCode,label:`${h.countryCode} – ${h.name}`})).filter(h=>C.has(h.value)?!1:(C.add(h.value),!0));X(F);const u=M.applicantRequestData;if(ce({firstName:(u==null?void 0:u.firstName)||"",lastName:(u==null?void 0:u.lastName)||"",email:(u==null?void 0:u.email)||"",dateOfBirth:(u==null?void 0:u.dateOfBirth)||"",title:(u==null?void 0:u.title)||"",salutation:(u==null?void 0:u.salutation)||"",phonenumber:(u==null?void 0:u.phonenumber)||"",mobileCountryCode:(u==null?void 0:u.mobileCountryCode)||"",street:(u==null?void 0:u.street)||"",streetNumber:(u==null?void 0:u.streetNumber)||"",city:(u==null?void 0:u.city)||"",zip:(u==null?void 0:u.zip)||"",country:(u==null?void 0:u.country)||"",nationality:(u==null?void 0:u.nationality)||"",taxCountry:(u==null?void 0:u.taxCountry)||"",countryOfBirth:(u==null?void 0:u.countryOfBirth)||"",placeOfBirth:(u==null?void 0:u.placeOfBirth)||"",educationLevel:(u==null?void 0:u.educationLevel)||"",occupation:(u==null?void 0:u.occupation)||"",taxNumber:(u==null?void 0:u.taxNumber)||"",defaultLanguage:(u==null?void 0:u.defaultLanguage)||""}),_.reset({street:(u==null?void 0:u.street)||"",streetNumber:(u==null?void 0:u.streetNumber)||"",city:(u==null?void 0:u.city)||"",zip:(u==null?void 0:u.zip)||"",country:(u==null?void 0:u.country)||"",nationality:(u==null?void 0:u.nationality)||"",phonenumber:(u==null?void 0:u.phonenumber)||""}),M.kycRecords&&M.kycRecords.length>0&&M.kycRecords[0].providerTokenObject!==null&&!V.current&&z.current){console.log("[Identity] Review page disabled + existing identity — auto-requesting..."),V.current=!0;try{await E(),q(!0)}catch(h){console.error("[Identity] Auto-request failed:",h)}}}catch(M){console.error("Error loading applicant data:",M)}finally{f(!1)}})()},[t]),i.useEffect(()=>{y&&!O&&z.current&&(console.log("[Identity] Review page disabled — showing cached provider"),q(!0))},[y,O]),i.useEffect(()=>{if(g){if(g.expiresAt){const x=new Date(g.expiresAt).getTime();if(Date.now()>=x){console.warn("[Identity] Token has expired (expiresAt)"),se(!0),$("Your verification session has expired. Please restart.");return}}if(g.url)try{const M=new URL(g.url).toString().toLowerCase();if(M.includes("expired")||M.includes("invalid")||M.includes("error")){console.warn("[Identity] Token URL indicates expiration"),se(!0),$("Your verification link has expired. Please restart.");return}}catch{console.error("[Identity] Invalid token URL")}if(g.status==="expired"||g.error==="expired"||g.expired===!0){console.warn("[Identity] Token object indicates expiration"),se(!0),$("Your verification session has expired. Please restart.");return}}},[g]);const me=p!==null&&p===Ae.Sumsub;i.useEffect(()=>{if(p!==null&&g&&!k&&O&&!G){const x=p;if(me){console.log("[Sumsub] Fetching access token for Web SDK…"),$(null),(async()=>{try{const M=await o.refreshSumsubToken(t),K=_e.parseProviderConfig(p,g,c);K.accessToken=M,K.onTokenRefresh=()=>o.refreshSumsubToken(t);const H=_e.createProvider(p,K);H.onComplete(Z=>{console.log("[Sumsub] Verification complete:",Z),r==null||r()}),H.onError(Z=>{console.error("[Sumsub] SDK error:",Z),(typeof Z=="string"?Z:(Z==null?void 0:Z.message)||"Unknown error").toLowerCase().includes("expired")&&(se(!0),$("Session expired. Please restart."))}),await H.initialize("sumsub-websdk-container"),console.log("[Sumsub] Web SDK launched"),S(H)}catch(M){console.error("[Sumsub] Initialization error:",M),$(`Failed to initialize: ${M.message||M}`),String(M.message||M).toLowerCase().includes("expired")&&se(!0)}})();return}if(g.url){console.log("[Identity] Loading provider URL for user verification:",g.url),$(null);try{if(new URL(g.url),x===Ae.SardinAI){console.log("[SardinAI] Initializing Risk SDK in background...");try{const M=_e.parseProviderConfig(p,g,c);_e.createProvider(p,M).initialize().then(()=>console.log("[SardinAI] Risk SDK initialized in background")).catch(H=>console.warn("[SardinAI] Risk SDK init failed (non-blocking):",H))}catch(M){console.warn("[SardinAI] Risk SDK setup failed (non-blocking):",M)}}S({type:"url",url:g.url})}catch(M){console.error("[Identity] Invalid URL:",M),$("Invalid verification URL. Please restart."),se(!0)}return}if(x===Ae.SardinAI){console.log("[SardinAI] No URL provided - initializing Risk SDK only..."),$(null);try{const M=_e.parseProviderConfig(p,g,c),K=_e.createProvider(p,M);K.initialize().then(()=>{console.log("[SardinAI] Risk SDK initialized successfully"),S(K),setTimeout(()=>r==null?void 0:r(),2e3)}).catch(H=>{var m;console.error("[SardinAI] Failed to initialize:",H);const Z=((m=H.message)==null?void 0:m.toLowerCase())||"";Z.includes("expired")||Z.includes("invalid")||Z.includes("401")||Z.includes("400")?(se(!0),$("Session expired or invalid. Please restart verification.")):$(`Failed to initialize: ${H.message}`)})}catch(M){console.error("[SardinAI] Error creating provider:",M),$(`Configuration error: ${M.message}`)}return}try{$(null);const M=_e.parseProviderConfig(p,g,c),K=_e.createProvider(p,M);x===Ae.Onfido&&K.initialize("identity-container").catch(H=>{console.error("[Onfido] Initialization error:",H),$(`Failed to initialize: ${H.message}`)}),S(K)}catch(M){console.error("[Identity] Provider setup error:",M),$(`Setup error: ${M.message}`)}}return()=>{if(k&&k.destroy)try{k.destroy()}catch(x){console.error("[Identity] Error destroying provider:",x)}}},[p,g,k,O,r,G,me,t,c,o]);const N=async()=>{try{$(null),se(!1),await E(),q(!0)}catch(x){console.error("Error starting identity verification:",x)}},re=async()=>{try{$(null),se(!1),S(null),console.log("[Identity] Restarting verification..."),await A(),q(!0)}catch(x){console.error("Error restarting identity verification:",x),$(x.message||"Failed to restart verification")}};if(R||T)return e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-4",children:"Loading identity verification..."})]})});if(v)return e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("p",{className:"text-danger-500",children:["Error: ",v.message]})})});if(O&&(Q||G))return e.jsxs(ee,{children:[e.jsx(ge,{children:e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"Verification Session Issue"})}),e.jsxs(te,{children:[e.jsx("div",{className:"p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg mb-6",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("svg",{className:"h-6 w-6 text-red-600 dark:text-red-400 mr-3 mt-0.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-red-900 dark:text-red-100 mb-1",children:G?"Session Expired":"Verification Error"}),e.jsx("p",{className:"text-red-800 dark:text-red-200 text-sm",children:Q||"Your verification session has expired and needs to be restarted."})]})]})}),e.jsxs("div",{className:"bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-4",children:[e.jsx("h3",{className:"font-semibold text-blue-900 dark:text-blue-100 mb-2",children:"What to do next:"}),e.jsxs("ul",{className:"text-blue-800 dark:text-blue-200 text-sm space-y-1 list-disc list-inside",children:[e.jsx("li",{children:'Click "Restart Verification" below to generate a new session'}),e.jsx("li",{children:"Complete the verification process without delays"}),e.jsx("li",{children:"If issues persist, contact support"})]})]})]}),e.jsxs(be,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"button",onClick:re,disabled:T,children:T?"Restarting...":"Restart Verification"})]})]});if(O&&y){const x=p;return me?e.jsxs("div",{style:{background:"var(--metakyc-background, #ffffff)",borderRadius:"12px",border:"1px solid var(--metakyc-border, #e5e7eb)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"20px 24px",borderBottom:"1px solid var(--metakyc-border, #e5e7eb)"},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{margin:0,fontSize:"20px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)"},children:"Identity Verification"}),e.jsx("p",{style:{margin:"4px 0 0",fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)"},children:"Please complete the identity verification process"})]}),e.jsx("button",{type:"button",onClick:re,disabled:T,style:{padding:"6px 14px",fontSize:"13px",fontWeight:500,borderRadius:"8px",border:"1px solid var(--metakyc-border, #d1d5db)",background:"var(--metakyc-background, #ffffff)",color:"var(--metakyc-text-primary, #111827)",cursor:T?"not-allowed":"pointer",opacity:T?.5:1},children:T?"Restarting…":"Restart"})]}),e.jsx("div",{id:"sumsub-websdk-container",style:{minHeight:"520px",width:"100%",padding:"16px 24px",background:"var(--metakyc-background, #ffffff)"}}),s&&e.jsx("div",{style:{padding:"16px 24px",borderTop:"1px solid var(--metakyc-border, #e5e7eb)"},children:e.jsx(J,{variant:"outline",onClick:s,children:"Back"})})]}):g!=null&&g.url?e.jsxs(ee,{children:[e.jsx(ge,{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:re,disabled:T,children:"Restart"})]})}),e.jsxs(te,{children:[e.jsx("div",{className:"mb-4 p-3 bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg",children:e.jsxs("p",{className:"text-yellow-800 dark:text-yellow-200 text-sm",children:[e.jsx("strong",{children:"Important:"}),' If you see an "expired" or "invalid link" message below, click the "Restart" button above to generate a new verification session.']})}),e.jsx("div",{className:"w-full",style:{height:"600px"},children:e.jsx("iframe",{src:g.url,className:"w-full h-full border-0 rounded-lg",allow:"camera; microphone; geolocation",title:"Identity Verification",onLoad:M=>{var K,H,Z;console.log("[Identity] Iframe loaded");try{const m=M.target,C=m.contentDocument||((K=m.contentWindow)==null?void 0:K.document);if(C){const F=((Z=(H=C.body)==null?void 0:H.textContent)==null?void 0:Z.toLowerCase())||"";(F.includes("expired")||F.includes("invalid")||F.includes("error"))&&(console.warn("[Identity] Iframe shows expiration message"),se(!0),$("Your verification link has expired."))}}catch{console.log("[Identity] Cannot check iframe content (CORS)")}}})})]}),s&&e.jsx(be,{children:e.jsx(J,{variant:"outline",onClick:s,children:"Back"})})]}):x===Ae.SardinAI?e.jsxs(ee,{children:[e.jsxs(ge,{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Device Risk Assessment"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:"Analyzing device security and behavioral patterns..."})]}),e.jsx(te,{children:e.jsxs("div",{className:"text-center py-12",children:[e.jsx(Ee,{className:"mb-4"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Please wait while we verify your device security"}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-500 mt-2",children:"This process is automatic and will complete in a few seconds"})]})})]}):e.jsxs(ee,{children:[e.jsxs(ge,{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Identity Verification"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:"Please complete the identity verification process"})]}),e.jsx(te,{children:e.jsx("div",{id:"identity-container",className:"min-h-[400px]"})}),s&&e.jsx(be,{children:e.jsx(J,{variant:"outline",onClick:s,children:"Back"})})]})}const ue=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),ne=(x=4)=>{const M=Math.min(4,Math.max(1,Number(x)||4));return{gridColumn:`span ${M} / span ${M}`}},ve=(x,M)=>{if(!M&&M!==0)return"—";if(ue.has(x)&&x!=="mobileCountryCode"){const K=L.find(H=>H.value===M);return K?K.label:String(M)}return String(M)},Fe=({helpText:x})=>{const[M,K]=i.useState(!1),H=i.useRef(null),[,Z]=i.useState({top:0,left:0}),m=()=>{if(H.current){const C=H.current.getBoundingClientRect();Z({top:C.bottom+window.scrollY+6,left:C.left+window.scrollX})}K(!0)};return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"metakyc-help-btn",ref:H,onClick:m,style:{width:18,height:18,borderRadius:"50%",border:"1.5px solid var(--metakyc-primary, #2563eb)",background:"transparent",color:"var(--metakyc-primary, #2563eb)",fontSize:11,fontWeight:700,cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,lineHeight:1,position:"relative",zIndex:2},children:"?"}),M&&pt.createPortal(e.jsx("div",{style:{position:"fixed",inset:0,zIndex:99999,background:"rgba(0,0,0,0.55)",backdropFilter:"blur(6px)",WebkitBackdropFilter:"blur(6px)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:()=>K(!1),children:e.jsxs("div",{onClick:C=>C.stopPropagation(),style:{background:"var(--metakyc-surface, var(--metakyc-background, #ffffff))",border:"1px solid var(--metakyc-border, #e5e7eb)",borderRadius:"var(--metakyc-border-radius, 8px)",padding:"20px 24px",maxWidth:400,width:"90%",boxShadow:"0 24px 64px rgba(0,0,0,0.4)"},children:[e.jsx("div",{dangerouslySetInnerHTML:{__html:x},style:{fontSize:13,color:"var(--metakyc-text-primary, #111827)",lineHeight:1.6}}),e.jsx("button",{type:"button",onClick:()=>K(!1),style:{marginTop:12,padding:"4px 12px",fontSize:12,border:"1px solid var(--metakyc-border, #e5e7eb)",borderRadius:"var(--metakyc-border-radius, 6px)",background:"transparent",cursor:"pointer",color:"var(--metakyc-text-secondary, #6b7280)"},children:"Close"})]})}),document.body)]})},ke=(x,M)=>M?e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:5,flexWrap:"nowrap"},children:[e.jsx("div",{style:{flex:1,minWidth:0},children:x}),e.jsx("div",{style:{paddingTop:24},children:e.jsx(Fe,{helpText:M})})]}):x,Oe=(x,M)=>{const K=`cf-${M}`,H=x.paramName??"",Z=de[H];if(x.customType==="br")return e.jsx("div",{style:{...ne(x.colSpan),minHeight:"0.5rem"}},K);if(x.customType==="paragraph")return e.jsx("div",{style:ne(x.colSpan),children:e.jsx("div",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:x.label||""}})},K);if(x.customType==="html")return e.jsx("div",{style:ne(x.colSpan),dangerouslySetInnerHTML:{__html:x.label||""}},K);if(x.customType==="link")return e.jsx("div",{style:ne(x.colSpan),children:ke(e.jsx("a",{href:x.linkUrl??"#",target:"_blank",rel:"noopener noreferrer",className:"text-sm underline",style:{color:"var(--metakyc-primary, #6366f1)"},children:x.displayText||x.label||x.linkText||x.linkUrl}),x.helpText)},K);if(x.customType==="checkbox"||x.customType==="link_checkbox"){const m=Z==="true"||Z===!0;return e.jsx("div",{style:ne(x.colSpan),children:ke(e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:!!m,onChange:C=>fe(F=>({...F,[H]:String(C.target.checked)})),style:{width:16,height:16,flexShrink:0,marginTop:2,accentColor:"var(--metakyc-primary, #6366f1)"}}),e.jsx("span",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)"},children:x.customType==="link_checkbox"&&x.linkUrl?e.jsxs(e.Fragment,{children:[e.jsx("a",{href:x.linkUrl,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--metakyc-primary, #6366f1)",textDecoration:"underline"},children:x.linkText||x.label}),x.label&&x.linkText?` ${x.label}`:""]}):x.displayText||x.label})]}),x.helpText)},K)}if(x.customType==="group_checkbox"){const m=Array.isArray(Z)?Z:Z?[Z]:[],C=F=>{x.singleSelect?fe(u=>({...u,[H]:m[0]===F?[]:[F]})):fe(u=>({...u,[H]:m.includes(F)?m.filter(l=>l!==F):[...m,F]}))};return e.jsx("div",{style:ne(x.colSpan),children:ke(e.jsxs("div",{className:"space-y-1.5",children:[x.label&&e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:x.displayText||x.label}),(x.options||[]).map(F=>e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:m.includes(F.value),onChange:()=>C(F.value),style:{width:16,height:16,flexShrink:0,marginTop:2,accentColor:"var(--metakyc-primary, #6366f1)"}}),e.jsx("span",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)"},children:F.label})]},F.value))]}),x.helpText)},K)}return x.customType==="radio_group"?e.jsx("div",{style:ne(x.colSpan),children:ke(e.jsxs("div",{className:"space-y-1.5",children:[x.label&&e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:x.displayText||x.label}),(x.options||[]).map(m=>e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"radio",name:`rg-${H}`,value:m.value,checked:Z===m.value,onChange:()=>fe(C=>({...C,[H]:m.value})),style:{width:16,height:16,flexShrink:0,marginTop:2,accentColor:"var(--metakyc-primary, #6366f1)"}}),e.jsx("span",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)"},children:m.label})]},m.value))]}),x.helpText)},K):e.jsx("div",{style:ne(x.colSpan),children:ke(e.jsx(ye,{label:x.displayText||x.label||H,value:String(Z??""),onChange:m=>fe(C=>({...C,[H]:m.target.value}))}),x.helpText)},K)},Xe=(x,M)=>{if(x.isCustom)return Oe(x,M);const K=x.name??"",H=Qe[K],Z=x.displayText||(H==null?void 0:H.label)||K,m=he[K]??"",C=K==="mobileCountryCode",F=!!(H!=null&&H.countriesType)&&!C;return x.editable?C?e.jsx("div",{style:ne(x.colSpan??2),children:ke(e.jsx(De,{label:Z,value:String(m),onChange:u=>ce(l=>({...l,[K]:u})),options:[{value:"",label:"Select country code…"},...U]}),x.helpText)},`epc-${M}`):F?e.jsx("div",{style:ne(x.colSpan??2),children:ke(e.jsx(De,{label:Z,value:String(m),onChange:u=>ce(l=>({...l,[K]:u})),options:[{value:"",label:`Select ${Z.toLowerCase()}…`},...L]}),x.helpText)},`ec-${M}`):e.jsx("div",{style:ne(x.colSpan??2),children:ke(e.jsx(ye,{label:Z,type:(H==null?void 0:H.type)==="date"?"date":(H==null?void 0:H.type)==="email"?"email":"text",value:String(m),onChange:u=>ce(l=>({...l,[K]:u.target.value}))}),x.helpText)},`ei-${M}`):e.jsx("div",{style:ne(x.colSpan??2),children:ke(e.jsxs(e.Fragment,{children:[e.jsx("label",{className:"block text-sm font-medium mb-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:Z}),e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)",minHeight:"1.5rem"},children:ve(K,m)})]}),x.helpText)},`ro-${M}`)};if(I){const x=I.title||"Review Your Information",M=I.subtitle||"Please review and confirm your information before starting identity verification";return e.jsx("form",{onSubmit:K=>{K.preventDefault(),N()},children:e.jsxs(ee,{children:[e.jsxs(ge,{children:[e.jsx("h2",{className:"text-lg font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:x}),e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:M})]}),e.jsx(te,{children:e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:I.fields.map((K,H)=>Xe(K,H))})}),e.jsxs(be,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"submit",isLoading:T,children:"Confirm and Start Verification"})]})]})})}return e.jsx("form",{onSubmit:_.handleSubmit(N),children:e.jsxs(ee,{children:[e.jsxs(ge,{children:[e.jsx("h2",{className:"text-lg font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Review Your Information"}),e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Please review and confirm your information before starting identity verification"})]}),e.jsxs(te,{className:"space-y-6",children:[e.jsx("div",{className:"space-y-4 pb-4",style:{borderBottom:"1px solid var(--metakyc-border, #e5e7eb)"},children:[{label:"Name",value:`${((Ge=D==null?void 0:D.applicantRequestData)==null?void 0:Ge.firstName)||""} ${((ze=D==null?void 0:D.applicantRequestData)==null?void 0:ze.lastName)||""}`.trim()},{label:"Email",value:(et=D==null?void 0:D.applicantRequestData)==null?void 0:et.email},{label:"Date of Birth",value:((Ue=D==null?void 0:D.applicantRequestData)==null?void 0:Ue.dateOfBirth)||"Not provided"}].map(({label:x,value:M})=>e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:x}),e.jsx("p",{className:"mt-1 text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:M})]},x))}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Address Information"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(qe.Controller,{control:_.control,name:"country",render:({field:x})=>e.jsx(De,{label:"Country",value:x.value,onChange:x.onChange,options:[{value:"",label:"Select country…"},...L]})}),e.jsx(qe.Controller,{control:_.control,name:"nationality",render:({field:x})=>e.jsx(De,{label:"Nationality",value:x.value,onChange:x.onChange,options:[{value:"",label:"Select nationality…"},...L]})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(qe.Controller,{control:_.control,name:"street",render:({field:x})=>e.jsx(ye,{...x,label:"Street"})}),e.jsx(qe.Controller,{control:_.control,name:"streetNumber",render:({field:x})=>e.jsx(ye,{...x,label:"Street Number"})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(qe.Controller,{control:_.control,name:"city",render:({field:x})=>e.jsx(ye,{...x,label:"City"})}),e.jsx(qe.Controller,{control:_.control,name:"zip",render:({field:x})=>e.jsx(ye,{...x,label:"ZIP / Postal Code"})})]}),e.jsx(qe.Controller,{control:_.control,name:"phonenumber",render:({field:x})=>e.jsx(ye,{...x,label:"Phone Number",type:"tel"})})]})]}),e.jsxs(be,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"submit",isLoading:T,children:"Confirm and Start Verification"})]})]})})},ft=({kycStatus:t,reviewStatus:r,workflowResult:s,customMessage:n,onContinue:a,onContactSupport:o})=>{const d=t===Ve.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===Ve.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===Ve.Pending||t===Ve.InProgress?{type:"pending",title:"Verification Pending",icon:"⏱",iconBg:"bg-blue-100 dark:bg-blue-900/30",iconColor:"text-blue-600 dark:text-blue-400",message:"Your identity verification is currently being processed."}:r===Ye.Approved?{type:"success",title:"Application Approved",icon:"✓",iconBg:"bg-green-100 dark:bg-green-900/30",iconColor:"text-green-600 dark:text-green-400",message:"Your application has been approved."}:r===Ye.Reject?{type:"error",title:"Application Rejected",icon:"✕",iconBg:"bg-red-100 dark:bg-red-900/30",iconColor:"text-red-600 dark:text-red-400",message:"Your application has been rejected."}:r===Ye.UnderReview||r===Ye.AdminReview?{type:"pending",title:"Under Review",icon:"📋",iconBg:"bg-yellow-100 dark:bg-yellow-900/30",iconColor:"text-yellow-700 dark:text-yellow-400",message:"Your application is currently under manual review."}:s===ot.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===ot.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===ot.AdminReview?{type:"pending",title:"Admin Review Required",icon:"📋",iconBg:"bg-yellow-100 dark:bg-yellow-900/30",iconColor:"text-yellow-700 dark:text-yellow-400",message:"Your application requires administrator review."}:{type:"pending",title:"Processing",icon:"⏱",iconBg:"bg-blue-100 dark:bg-blue-900/30",iconColor:"text-blue-600 dark:text-blue-400",message:"Your application is being reviewed."};return e.jsxs(ee,{children:[e.jsxs(te,{className:"py-12",children:[e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx("div",{className:`w-24 h-24 rounded-full flex items-center justify-center ${d.iconBg}`,children:e.jsx("span",{className:`text-5xl ${d.iconColor}`,children:d.icon})})}),e.jsx("h2",{className:"text-3xl font-bold text-center mb-4",style:{color:"var(--metakyc-text-primary, #111827)"},children:d.title}),e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx(kt,{variant:d.type==="success"?"success":d.type==="error"?"danger":d.type==="pending"?"warning":"info",children:t!=null?Ve[t]:Ye[r]})}),e.jsx("p",{className:"text-center mb-6 max-w-md mx-auto",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:n||d.message}),d.type==="success"&&e.jsxs("div",{className:"bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg p-4 mb-6",children:[e.jsx("h3",{className:"font-semibold text-green-900 dark:text-green-100 mb-2",children:"What's Next?"}),e.jsxs("ul",{className:"text-sm text-green-800 dark:text-green-200 space-y-1",children:[e.jsx("li",{children:"✓ Your identity has been verified"}),e.jsx("li",{children:"✓ You can now proceed with your application"}),e.jsx("li",{children:"✓ All features are now accessible"})]})]}),d.type==="error"&&e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 mb-6",children:[e.jsx("h3",{className:"font-semibold text-red-900 dark:text-red-100 mb-2",children:"What Can You Do?"}),e.jsxs("ul",{className:"text-sm text-red-800 dark:text-red-200 space-y-2",children:[e.jsx("li",{children:"• Review the requirements and ensure all information is correct"}),e.jsx("li",{children:"• Contact our support team for assistance"}),e.jsx("li",{children:"• You may be able to resubmit your application"})]})]}),d.type==="pending"&&e.jsxs("div",{className:"bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-4 mb-6",children:[e.jsx("h3",{className:"font-semibold text-blue-900 dark:text-blue-100 mb-2",children:"What Happens Next?"}),e.jsxs("ul",{className:"text-sm text-blue-800 dark:text-blue-200 space-y-2",children:[e.jsx("li",{children:"• Our team is reviewing your information"}),e.jsx("li",{children:"• You will be notified via email once the review is complete"}),e.jsx("li",{children:"• This typically takes 24-48 hours"}),e.jsx("li",{children:"• No action is required from you at this time"})]})]}),e.jsx("div",{className:"mt-6 pt-6",style:{borderTop:"1px solid var(--metakyc-border, #e5e7eb)"},children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"KYC Status:"}),e.jsx("div",{className:"font-medium mt-1",style:{color:"var(--metakyc-text-primary, #111827)"},children:t!=null?Ve[t]:"Not Available"})]}),e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"Review Status:"}),e.jsx("div",{className:"font-medium mt-1",style:{color:"var(--metakyc-text-primary, #111827)"},children:Ye[r]})]})]})})]}),e.jsxs(be,{style:{display:"flex",justifyContent:"center",gap:"1rem"},children:[d.type==="success"&&a&&e.jsx(J,{onClick:a,size:"lg",children:"Continue"}),d.type==="error"&&e.jsxs(e.Fragment,{children:[o&&e.jsx(J,{variant:"outline",onClick:o,children:"Contact Support"}),a&&e.jsx(J,{onClick:a,children:"Try Again"})]}),d.type==="pending"&&e.jsx("div",{className:"text-center",children:e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Please check back later or wait for our email notification"})})]})]})},Hr=({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"}})}),nt=({title:t,subtitle:r,className:s=""})=>{const{currentTheme:n}=Ne(),a=t||(n==null?void 0:n.title)||"",o=!!(n!=null&&n.logo&&n.logo.visible&&n.logo.url),c=!!a;return!o&&!c?null:e.jsxs("div",{className:`metakyc-header ${s}`,children:[e.jsxs("div",{className:"metakyc-header-title flex items-center text-xl font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:[o&&e.jsx(Hr,{config:n.logo}),o&&c&&e.jsx("span",{style:{fontSize:"1.5rem",fontWeight:300,color:"var(--metakyc-text-muted, #9ca3af)",margin:"0 12px"},children:"|"}),c&&e.jsx("span",{style:{color:"var(--metakyc-text-primary, #111827)"},children:a})]}),r&&e.jsx("p",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:r})]})},dt=["firstName","lastName","email","phonenumber","dateOfBirth"];function tt(t){return t==null||t===""||Array.isArray(t)&&t.length===0}const it={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"},It=({helpText:t,children:r})=>{const[s,n]=i.useState(!1);if(!t)return e.jsx(e.Fragment,{children:r});const a=s?e.jsx("div",{role:"dialog","aria-modal":"true",onClick:()=>n(!1),style:{position:"fixed",inset:0,zIndex:999999,background:"rgba(0, 0, 0, 0.55)",backdropFilter:"blur(6px)",WebkitBackdropFilter:"blur(6px)",display:"flex",alignItems:"center",justifyContent:"center",padding:"16px"},children:e.jsxs("div",{onClick: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:()=>n(!1),"aria-label":"Close",style:{position:"absolute",top:"12px",right:"12px",width:"28px",height:"28px",borderRadius:"50%",border:"1px solid var(--metakyc-border, #e5e7eb)",background:"var(--metakyc-input-bg, #f3f4f6)",color:"var(--metakyc-text-secondary, #6b7280)",fontSize:"16px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:"×"}),e.jsx("div",{style:{color:"var(--metakyc-text-primary, #111827)",fontSize:"14px",lineHeight:1.75},dangerouslySetInnerHTML:{__html:t}})]})}):null;return e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"5px",flexWrap:"nowrap"},children:[r,e.jsx("button",{type:"button",className:"metakyc-help-btn",onClick:()=>n(!0),"aria-label":"Help",style:{flexShrink:0,marginTop:"2px",width:"18px",height:"18px",borderRadius:"50%",border:"1.5px solid var(--metakyc-primary, #2563eb)",background:"transparent",color:"var(--metakyc-primary, #2563eb)",fontSize:"10px",fontWeight:"700",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,padding:0,position:"relative",zIndex:2,transition:"background 0.15s, color 0.15s"},onMouseEnter: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"&&a?pt.createPortal(a,document.body):null]})},Es=({workflowKey:t,externalRefId:r,onSuccess:s,onCancel:n})=>{var K,H,Z,m,C,F,u;const{config:a,baseInformationService:o,currentTheme:c}=Ne(),{createApplicant:d,isLoading:y}=vt(),p=t||((K=a.applicantForm)==null?void 0:K.workflowKey);if(!p)throw new Error("workflowKey is required. Provide it either as a prop to CreateApplicantForm or set it in config.applicantForm.workflowKey");const g=r||((H=a.applicantForm)==null?void 0:H.externalRefId)||"",T=((Z=a.applicantForm)==null?void 0:Z.email)||"",v=((m=a.applicantForm)==null?void 0:m.hiddenValues)||{},E=((C=a.applicantForm)==null?void 0:C.initialValues)||{},k=(((F=a.applicantForm)==null?void 0:F.fieldLabelMode)||(c==null?void 0:c.fieldLabelMode)||"label")!=="placeholder",S=i.useMemo(()=>c!=null&&c.applicantFormPages&&c.applicantFormPages.length>0?c.applicantFormPages:null,[c==null?void 0:c.applicantFormPages]),D=i.useMemo(()=>{const l=new Set(dt),h=c==null?void 0:c.applicantFormRequiredFields;if(h)for(const P of h)l.add(P);if(S)for(const P of S)for(const b of P.fields)!b.isCustom&&b.name&&b.required&&l.add(b.name);return Array.from(l)},[c==null?void 0:c.applicantFormRequiredFields,S]),Y=i.useMemo(()=>{var P;if(S){const b=S.flatMap(j=>j.fields).filter(j=>!j.isCustom&&j.name).map(j=>j.name),w=new Set(b);for(const j of dt)w.add(j);return Array.from(w)}let l;(P=a.applicantForm)!=null&&P.visibleFields?l=a.applicantForm.visibleFields:c!=null&&c.applicantFormVisibleFields&&c.applicantFormVisibleFields.length>0?l=c.applicantFormVisibleFields:l=Ht;const h=new Set(l);for(const b of dt)h.add(b);return Array.from(h)},[(u=a.applicantForm)==null?void 0:u.visibleFields,c==null?void 0:c.applicantFormVisibleFields,S]),L=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),B=i.useMemo(()=>{var h,P;const l=new Set;if(S)for(const b of S)for(const w of b.fields)!w.isCustom&&w.name&&L.has(w.name)&&l.add(w.countriesType??((h=Qe[w.name])==null?void 0:h.countriesType));else for(const b of Y)L.has(b)&&l.add((P=Qe[b])==null?void 0:P.countriesType);return l.size===0&&l.add(void 0),Array.from(l)},[Y,S]),[U,X]=i.useState({}),[R,f]=i.useState(!0),O=i.useRef(new Set),q=i.useRef(new Set);i.useEffect(()=>{if(!c)return;const l=B.filter(b=>{const w=b!=null?String(b):"all";return!q.current.has(w)&&!O.current.has(w)});if(l.length===0){B.every(w=>{const j=w!=null?String(w):"all";return q.current.has(j)})&&f(!1);return}f(!0);const h=l.map(b=>b!=null?String(b):"all");h.forEach(b=>O.current.add(b)),(async()=>{try{const b=await Promise.all(l.map(async w=>{const j=w!=null?String(w):"all",le=await o.getCountries("",a.locale||"en",w),ae=w===40,xe=new Set,Ie=le.map(ie=>ae&&ie.countryCode?{value:ie.countryCode,label:`${ie.countryCode} – ${ie.name}`}:{value:ie.abbreviation3||ie.abbreviation,label:ie.name}).filter(ie=>!ie.value||xe.has(ie.value)?!1:(xe.add(ie.value),!0));return q.current.add(j),O.current.delete(j),[j,Ie]}));X(w=>({...w,...Object.fromEntries(b)}))}catch(b){h.forEach(w=>O.current.delete(w)),console.error("Failed to load countries:",b)}finally{B.every(w=>{const j=w!=null?String(w):"all";return q.current.has(j)})&&f(!1)}})()},[B,c]);const Q=(l,h)=>{var w;const P=h??((w=Qe[l])==null?void 0:w.countriesType),b=P!=null?String(P):"all";return U[b]||[]},$={firstName:1,lastName:1,title:1,email:1,dateOfBirth:1,phonenumber:1,mobileCountryCode:1,street:1,streetNumber:1,zip:1,city:1,country:1,nationality:1,otherNationality:1,defaultLanguage:1,taxCountry:1,placeOfBirth:1,countryOfBirth:1,salutation:1,educationLevel:1,occupation:1,taxNumber:1},G=Object.fromEntries(Object.entries(v).filter(([l])=>l in $)),se=Object.fromEntries(Object.entries(E).filter(([l])=>l in $)),[V,he]=i.useState({workflowKey:p,firstName:"",lastName:"",title:"",email:T,dateOfBirth:"",phonenumber:"",externalRefId:g,mobileCountryCode:"",street:"",streetNumber:"",zip:"",city:"",country:"",nationality:"",otherNationality:[],defaultLanguage:"EN",taxCountry:"",placeOfBirth:"",countryOfBirth:"",salutation:null,educationLevel:"",occupation:"",taxNumber:"",...G,...se}),ce=Object.fromEntries(Object.entries(v).filter(([l])=>!(l in G)&&l!=="externalRefId"&&l!=="workflowKey")),[de,fe]=i.useState({...ce}),[I,W]=i.useState(0),[z,_]=i.useState({}),[me,N]=i.useState(null),[re,ue]=i.useState(!1),ne=(l,h)=>he(P=>({...P,[l]:h})),ve=(l,h)=>fe(P=>({...P,[l]:h})),Fe=l=>!l.conditionalOn||de[l.conditionalOn]==="true",ke=S&&I<S.length-1?I+1:-1,Oe=S&&I>0?I-1:-1,Xe=l=>{var P;const h={};for(const b of l.fields)if(b.isCustom){if(b.customType==="paragraph"||b.customType==="html"||b.customType==="br"||b.customType==="link")continue;if(b.required&&b.paramName){const w=de[b.paramName],j=b.displayText||b.label||b.paramName;b.customType==="checkbox"||b.customType==="link_checkbox"?w!=="true"&&(h[b.paramName]=`${j} is required.`):(!w||w.trim()==="")&&(h[b.paramName]=`${j} is required.`)}}else if(b.name){const w=b.name;if(D.includes(w)&&tt(V[w])){const j=b.displayText||((P=Qe[w])==null?void 0:P.label)||w;h[w]=`${j} is required.`}}return h},Ge=async()=>{if(!S)return;const l=S[I];if(l.conditionalOn&&!Fe(l)){_({}),ke>=0?W(ke):await ze();return}const h=Xe(l);if(Object.keys(h).length>0){_(h);return}_({}),ke>=0?W(ke):await ze()},ze=async()=>{if(S){let l={};for(const h of S)Fe(h)&&(l={...l,...Xe(h)});if(Object.keys(l).length>0){_(l);return}}ue(!0),N(null);try{if(!V.externalRefId||V.externalRefId.trim()===""){N("External Reference ID is required. Please pass it via config.applicantForm.externalRefId.");return}const l={workflowKey:V.workflowKey,externalRefId:V.externalRefId.trim()};if(S){for(const w of S)if(Fe(w)){for(const j of w.fields)if(!j.isCustom&&j.name){const le=j.name,ae=V[le];tt(ae)||(l[le]=ae)}}for(const w of dt)if(l[w]===void 0){const j=V[w];tt(j)||(l[w]=j)}}else Y.forEach(w=>{if(w==="externalRefId")return;const j=V[w];tt(j)||(l[w]=j)});const h=[];if(S){for(const w of S)if(Fe(w))for(const j of w.fields){if(!j.isCustom||!j.paramName||j.customType==="paragraph"||j.customType==="html"||j.customType==="br"||j.customType==="link")continue;const le=de[j.paramName]??"";let ae;if(j.customType==="checkbox"||j.customType==="link_checkbox")ae=le==="true"?"yes":"no";else if(ae=le,!ae&&!j.required)continue;h.push({paramName:j.paramName,value:ae})}}for(const[w,j]of Object.entries(G))l[w]===void 0&&!tt(j)&&(l[w]=j);const P=new Set(h.map(w=>w.paramName));for(const[w,j]of Object.entries(ce))!P.has(w)&&j&&h.push({paramName:w,value:j});h.length>0&&(l.applicantAdditionalDatas=h);const b=await d(l);s(b.applicantId)}catch(l){console.error("Error creating applicant:",l),N(l.message||"Failed to create applicant")}finally{ue(!1)}},et=async l=>{var h;l.preventDefault();for(const P of D)if(tt(V[P])){const b=((h=Qe[P])==null?void 0:h.label)||P;N(`${b} is required.`);return}await ze()},Ue=(l,h,P,b,w)=>{var jt;const j=Qe[l];if(!j)return null;const le=D.includes(l),ae=z[l],xe=P||j.label,Ie=l in se,ie=h??l,Pe={required:le},$e=w?w!=="placeholder":k,Ke=$e?xe:void 0,Wr=$e?"...":xe;switch(j.type){case"select":if(l==="country"||l==="nationality"||l==="taxCountry"||l==="countryOfBirth"||l==="mobileCountryCode"){const Ce=Q(l,b);return e.jsx(De,{...Pe,label:Ke,value:V[l]||"",onChange:Je=>ne(l,Je),options:[{value:"",label:`Select ${Wr.toLowerCase()}`},...Ce],disabled:R,readOnly:Ie,error:ae},ie)}if(l==="salutation")return e.jsx(De,{...Pe,label:Ke,value:((jt=V[l])==null?void 0:jt.toString())||"",onChange:Ce=>ne(l,Ce?Number(Ce):null),options:[{value:"",label:$e?"Select salutation...":xe},{value:lt.Male.toString(),label:"Male"},{value:lt.Female.toString(),label:"Female"},{value:lt.Other.toString(),label:"Other"}],readOnly:Ie,error:ae},ie);if(l==="defaultLanguage"){const Ce=c!=null&&c.allowedLanguages&&c.allowedLanguages.length>0?ht.filter(Je=>c.allowedLanguages.includes(Je.value)):ht;return e.jsx(De,{...Pe,label:Ke,value:V[l]||"",onChange:Je=>ne(l,Je),options:[{value:"",label:$e?"Select language...":xe},...Ce],readOnly:Ie,error:ae},ie)}return null;case"multiselect":if(l==="otherNationality"){const Ce=Q(l,b);return e.jsx(Ir,{...Pe,label:Ke,value:V[l]||[],onChange:Je=>ne(l,Je),options:Ce,placeholder:$e?"Select other nationalities...":xe,disabled:R,readOnly:Ie},ie)}return null;case"date":return e.jsx(ye,{...Pe,type:"date",label:Ke,placeholder:$e?void 0:xe,value:V[l]||"",onChange:Ce=>ne(l,Ce.target.value),readOnly:Ie,error:ae},ie);case"email":return e.jsx(ye,{...Pe,type:"email",label:Ke,placeholder:$e?void 0:xe,value:V[l]||"",onChange:Ce=>ne(l,Ce.target.value),readOnly:Ie,error:ae},ie);case"tel":return e.jsx(ye,{...Pe,type:"tel",label:Ke,placeholder:$e?void 0:xe,value:V[l]||"",onChange:Ce=>ne(l,Ce.target.value),readOnly:Ie,error:ae},ie);default:return e.jsx(ye,{...Pe,type:"text",label:Ke,placeholder:$e?void 0:xe,value:V[l]||"",onChange:Ce=>ne(l,Ce.target.value),readOnly:Ie,error:ae},ie)}},x=(l,h)=>{const P=l.labelMode?l.labelMode!=="placeholder":k;if(l.customType==="paragraph"){const j=l.displayText||l.label||"";return e.jsx("p",{className:"metakyc-paragraph",style:{fontSize:"14px",lineHeight:"1.7",margin:0,color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:j}},`custom-${h}`)}if(l.customType==="html")return e.jsx("div",{dangerouslySetInnerHTML:{__html:l.label||""}},`custom-${h}`);if(l.customType==="br")return e.jsx("div",{style:{height:"12px"}},`custom-${h}`);if(l.customType==="link"){const j=l.displayText||l.label||l.linkText||l.linkUrl||"";return e.jsx("div",{className:"metakyc-link-field",children:e.jsxs("a",{href:l.linkUrl||"#",target:"_blank",rel:"noopener noreferrer",style:{display:"inline-flex",alignItems:"center",gap:"4px",color:"var(--metakyc-primary, #2563eb)",fontSize:"14px",textDecoration:"underline",cursor:"pointer"},children:[j,e.jsx("span",{style:{fontSize:"10px",opacity:.7},children:"↗"})]})},`custom-${h}`)}if(!l.paramName)return null;const b=z[l.paramName],w=l.displayText||l.label||l.paramName;if(l.customType==="checkbox")return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"checkbox",checked:de[l.paramName]==="true",onChange:j=>ve(l.paramName,j.target.checked?"true":"false"),className:"metakyc-option-input",style:it}),e.jsxs("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:[w,l.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),b&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:b})]},`custom-${h}`);if(l.customType==="link_checkbox")return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"checkbox",checked:de[l.paramName]==="true",onChange:j=>ve(l.paramName,j.target.checked?"true":"false"),className:"metakyc-option-input",style:{...it,alignSelf:"flex-start",marginTop:"2px"}}),e.jsxs("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:[w," ",l.linkUrl&&e.jsx("a",{href:l.linkUrl,target:"_blank",rel:"noopener noreferrer",className:"underline",style:{color:"var(--metakyc-primary, #2563eb)"},onClick:j=>j.stopPropagation(),children:l.linkText||l.linkUrl}),l.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),b&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:b})]},`custom-${h}`);if(l.customType==="group_checkbox"){const j=(de[l.paramName]||"").split(",").filter(Boolean);return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[P&&e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[w,l.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]}),e.jsx("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:(l.options||[]).map(le=>{const ae=l.singleSelect?de[l.paramName]===le.value:j.includes(le.value);return e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"checkbox",checked:ae,onChange:xe=>{if(l.singleSelect)ve(l.paramName,xe.target.checked?le.value:"");else{const Ie=xe.target.checked?[...j,le.value]:j.filter(ie=>ie!==le.value);ve(l.paramName,Ie.join(","))}},className:"metakyc-option-input",style:it}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:le.label})]},le.value)})}),b&&e.jsx("p",{className:"text-red-500 text-xs",children:b})]},`custom-${h}`)}return l.customType==="radio_group"?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[P&&e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[w,l.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]}),e.jsx("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:(l.options||[]).map(j=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"radio",checked:de[l.paramName]===j.value,onChange:()=>ve(l.paramName,j.value),name:`radio-group-${l.paramName}-${h}`,className:"metakyc-option-input",style:it}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:j.label})]},j.value))}),b&&e.jsx("p",{className:"text-red-500 text-xs",children:b})]},`custom-${h}`):e.jsx(ye,{type:"text",label:P?`${w}${l.required?" *":""}`:void 0,placeholder:P?void 0:w,value:de[l.paramName]||"",onChange:j=>ve(l.paramName,j.target.value),required:l.required,error:b},`custom-${h}`)},M=(l,h)=>{const P=Fe(l);return e.jsxs("div",{className:"space-y-4",children:[l.conditionalOn&&e.jsx(It,{helpText:l.conditionalHelpText,children:e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"checkbox",checked:P,onChange:b=>ve(l.conditionalOn,b.target.checked?"true":"false"),className:"metakyc-option-input",style:it}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",fontWeight:500},children:l.conditionalOn})]})}),P&&e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:l.fields.map((b,w)=>{const j=Math.min(4,Math.max(1,Number(b.colSpan)||4)),le=b.isCustom?`custom-${w}-${b.paramName}`:`builtin-${b.name}-${w}`;return e.jsx("div",{style:{gridColumn:`span ${j} / span ${j}`},children:e.jsx(It,{helpText:b.helpText,children:b.isCustom?x(b,w):Ue(b.name,le,b.displayText,b.countriesType,b.labelMode)})},le)})})]})};if(!c||R)return e.jsx("div",{className:"metakyc-sdk",children:e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)",fontSize:"0.875rem"},children:"Loading form…"})]})})});if(S){const l=S[I]??S[0],h=Oe===-1,P=ke===-1,b=S.length,w=Fe(l),j=Object.values(z);return e.jsx("div",{className:"metakyc-sdk",children:e.jsxs(ee,{children:[e.jsx(ge,{children:e.jsx(nt,{title:(c==null?void 0:c.title)||"Create Applicant"})}),e.jsxs(te,{children:[(l.title||l.subtitle||l.description)&&e.jsxs("div",{className:"mb-4",children:[l.title&&e.jsx("h3",{className:"font-semibold text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:l.title}),l.subtitle&&e.jsx("p",{className:"text-sm mt-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:l.subtitle}),l.description&&l.description!==l.subtitle&&e.jsx("p",{className:"text-xs mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:l.description})]}),(me||j.length>0)&&e.jsxs("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-lg",children:[me&&e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",me]}),j.map((le,ae)=>e.jsx("p",{className:"text-red-600 text-sm",children:le},ae))]}),b>1&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem",marginBottom:"1rem"},children:[S.map((le,ae)=>e.jsx("div",{style:{height:"0.375rem",borderRadius:"9999px",transition:"all 150ms",...ae===I?{flex:"1 1 0%",backgroundColor:"var(--metakyc-primary, #2563eb)"}:ae<I?{width:"2rem",backgroundColor:"var(--metakyc-primary-light, #93c5fd)",opacity:.7}:{width:"2rem",backgroundColor:"#e5e7eb"}}},ae)),e.jsxs("span",{style:{fontSize:"0.75rem",color:"var(--metakyc-text-muted, #9ca3af)",flexShrink:0},children:[I+1," / ",b]})]}),M(l)]}),e.jsxs(be,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{children:[!h&&e.jsx(J,{type:"button",variant:"outline",onClick:()=>{W(Oe),_({})},disabled:re||y,children:"Previous"}),h&&n&&e.jsx(J,{type:"button",variant:"outline",onClick:n,disabled:re||y,children:"Cancel"})]}),e.jsx(J,{type:"button",isLoading:re||y,onClick:P?ze:Ge,children:P?l.conditionalOn&&!w?"Skip & Submit":"Submit":l.conditionalOn&&!w?"Skip":"Next"})]})]})})}return e.jsx("div",{className:"metakyc-sdk",children:e.jsx("form",{onSubmit:et,children:e.jsxs(ee,{children:[e.jsx(ge,{children:e.jsx(nt,{title:(c==null?void 0:c.title)||"Create Applicant"})}),e.jsxs(te,{children:[me&&e.jsx("div",{className:"mb-6 p-4 bg-red-50 border border-red-200 rounded-lg",children:e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",me]})}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:Y.map(l=>e.jsx("div",{style:{gridColumn:"span 4 / span 4"},children:Ue(l)},l))})]}),e.jsxs(be,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[n&&e.jsx(J,{type:"button",variant:"outline",onClick:n,disabled:re||y,children:"Cancel"}),e.jsx(J,{type:"submit",isLoading:re||y,children:"Create Applicant"})]})]})})})},Et=["companyName","email"];function xt(t){return t==null||t===""||Array.isArray(t)&&t.length===0}const As=({workflowKey:t,externalRefId:r,onSuccess:s,onCancel:n})=>{var Ue,x,M,K,H,Z;const{config:a,baseInformationService:o,currentTheme:c}=Ne(),{createCompanyApplicant:d,isLoading:y}=vt(),p=t||((Ue=a.applicantForm)==null?void 0:Ue.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 g=r||((x=a.applicantForm)==null?void 0:x.externalRefId)||"",T=((M=a.applicantForm)==null?void 0:M.email)||"",v=((K=a.applicantForm)==null?void 0:K.initialValues)||{},A=(((H=a.applicantForm)==null?void 0:H.fieldLabelMode)||(c==null?void 0:c.fieldLabelMode)||"label")!=="placeholder",k=i.useMemo(()=>c!=null&&c.companyFormPages&&c.companyFormPages.length>0?c.companyFormPages:null,[c==null?void 0:c.companyFormPages]),S=i.useMemo(()=>{const m=new Set(Et),C=c==null?void 0:c.companyFormRequiredFields;if(C)for(const F of C)m.add(F);if(k)for(const F of k)for(const u of F.fields)!u.isCustom&&u.name&&u.required&&m.add(u.name);return Array.from(m)},[c==null?void 0:c.companyFormRequiredFields,k]),D=i.useMemo(()=>{var m;if(k){const C=k.flatMap(u=>u.fields).filter(u=>!u.isCustom&&u.name).map(u=>u.name),F=new Set(C);for(const u of Et)F.add(u);return Array.from(F)}return(m=a.applicantForm)!=null&&m.visibleFields?a.applicantForm.visibleFields:c!=null&&c.companyFormVisibleFields&&c.companyFormVisibleFields.length>0?c.companyFormVisibleFields:_t},[(Z=a.applicantForm)==null?void 0:Z.visibleFields,c==null?void 0:c.companyFormVisibleFields,k]),Y=new Set(["countryResidence","addressCountry"]),L=i.useMemo(()=>{var C,F;const m=new Set;if(k)for(const u of k)for(const l of u.fields)!l.isCustom&&l.name&&Y.has(l.name)&&m.add(l.countriesType??((C=Ze[l.name])==null?void 0:C.countriesType));else for(const u of D)Y.has(u)&&m.add((F=Ze[u])==null?void 0:F.countriesType);return m.size===0&&m.add(void 0),Array.from(m)},[D,k]),[B,U]=i.useState({}),[X,R]=i.useState(!0),f=i.useRef(new Set),O=i.useRef(new Set);i.useEffect(()=>{if(!c)return;const m=L.filter(u=>{const l=u!=null?String(u):"all";return!O.current.has(l)&&!f.current.has(l)});if(m.length===0){L.every(l=>O.current.has(l!=null?String(l):"all"))&&R(!1);return}R(!0);const C=m.map(u=>u!=null?String(u):"all");C.forEach(u=>f.current.add(u)),(async()=>{try{const u=await Promise.all(m.map(async l=>{const h=l!=null?String(l):"all",P=await o.getCountries("",a.locale||"en",l),b=new Set,w=P.map(j=>({value:j.abbreviation3||j.abbreviation,label:j.name})).filter(j=>!j.value||b.has(j.value)?!1:(b.add(j.value),!0));return O.current.add(h),f.current.delete(h),[h,w]}));U(l=>({...l,...Object.fromEntries(u)}))}catch(u){C.forEach(l=>f.current.delete(l)),console.error("Failed to load countries:",u)}finally{L.every(l=>O.current.has(l!=null?String(l):"all"))&&R(!1)}})()},[L,c]);const q=(m,C)=>{var l;const F=C??((l=Ze[m])==null?void 0:l.countriesType),u=F!=null?String(F):"all";return B[u]||[]},Q={companyName:1,registrationNumber:1,email:1,phone:1,countryResidence:1,legalAddress:1,incorporatedOn:1,controlScheme:1,taxId:1,registrationLocation:1,website:1,postalAddress:1,street:1,streetNumber:1,city:1,state:1,postalCode:1,addressCountry:1,lei:1},$=Object.fromEntries(Object.entries(v).filter(([m])=>m in Q)),[G,se]=i.useState({workflowKey:p,companyName:"",email:T,phone:"",registrationNumber:"",countryResidence:"",legalAddress:"",incorporatedOn:"",controlScheme:"",taxId:"",registrationLocation:"",website:"",postalAddress:"",street:"",streetNumber:"",city:"",state:"",postalCode:"",addressCountry:"",lei:"",externalRefId:g,...$}),[V,he]=i.useState({}),[ce,de]=i.useState(0),[fe,I]=i.useState({}),[W,z]=i.useState(null),[_,me]=i.useState(!1),N=(m,C)=>se(F=>({...F,[m]:C})),re=(m,C)=>he(F=>({...F,[m]:C})),ue=m=>!m.conditionalOn||V[m.conditionalOn]==="true",ne=k&&ce<k.length-1?ce+1:-1,ve=k&&ce>0?ce-1:-1,Fe=m=>{var F;const C={};for(const u of m.fields)if(u.isCustom){if(u.customType==="paragraph"||u.customType==="html"||u.customType==="br"||u.customType==="link")continue;if(u.required&&u.paramName){const l=V[u.paramName],h=u.displayText||u.label||u.paramName;u.customType==="checkbox"||u.customType==="link_checkbox"?l!=="true"&&(C[u.paramName]=`${h} is required.`):(!l||l.trim()==="")&&(C[u.paramName]=`${h} is required.`)}}else if(u.name){const l=u.name;if(S.includes(l)&&xt(G[l])){const h=u.displayText||((F=Ze[l])==null?void 0:F.label)||l;C[l]=`${h} is required.`}}return C},ke=async()=>{if(!k)return;const m=k[ce];if(m.conditionalOn&&!ue(m)){I({}),ne>=0?de(ne):await Oe();return}const C=Fe(m);if(Object.keys(C).length>0){I(C);return}I({}),ne>=0?de(ne):await Oe()},Oe=async()=>{var m;if(k){let C={};for(const F of k)ue(F)&&(C={...C,...Fe(F)});if(Object.keys(C).length>0){I(C);return}}me(!0),z(null);try{const C={workflowKey:G.workflowKey,externalRefId:((m=G.externalRefId)==null?void 0:m.trim())||void 0},F=k?k.filter(h=>ue(h)).flatMap(h=>h.fields).filter(h=>!h.isCustom&&h.name).map(h=>h.name):D;for(const h of F){const P=G[h];if(!xt(P))switch(h){case"companyName":C.companyName=P;break;case"email":C.companyEmail=P;break;case"phone":C.companyPhone=P;break;case"registrationNumber":C.companyRegistrationNumber=P;break;case"countryResidence":C.companyCountry=P;break;case"city":C.companyCity=P;break;case"street":C.companyStreet=P;break;case"postalCode":C.companyZip=P;break;default:C[h]=P;break}}const u=[];if(k){for(const h of k)if(ue(h))for(const P of h.fields){if(!P.isCustom||!P.paramName||P.customType==="paragraph"||P.customType==="html"||P.customType==="br"||P.customType==="link")continue;const b=V[P.paramName]??"";let w;if(P.customType==="checkbox"||P.customType==="link_checkbox")w=b==="true"?"yes":"no";else if(w=b,!w&&!P.required)continue;u.push({paramName:P.paramName,value:w})}}u.length>0&&(C.applicantAdditionalDatas=u);const l=await d(C);s(l.applicantId)}catch(C){console.error("Error creating company applicant:",C),z(C.message||"Failed to create company applicant")}finally{me(!1)}},Xe=async m=>{var C;m.preventDefault();for(const F of S)if(xt(G[F])){const u=((C=Ze[F])==null?void 0:C.label)||F;z(`${u} is required.`);return}await Oe()},Ge=(m,C,F,u,l)=>{const h=Ze[m];if(!h)return null;const P=S.includes(m),b=fe[m],w=F||h.label,j=m in $,le=C??m,ae=l?l!=="placeholder":A,xe=ae?w:void 0,Ie=ae?"...":w;switch(h.type){case"select":if(m==="countryResidence"||m==="addressCountry"){const ie=q(m,u);return e.jsx(De,{required:P,label:xe,value:G[m]||"",onChange:Pe=>N(m,Pe),options:[{value:"",label:`Select ${Ie.toLowerCase()}`},...ie],disabled:X,readOnly:j,error:b},le)}return null;case"date":return e.jsx(ye,{required:P,type:"date",label:xe,placeholder:ae?void 0:w,value:G[m]||"",onChange:ie=>N(m,ie.target.value),readOnly:j,error:b},le);case"email":return e.jsx(ye,{required:P,type:"email",label:xe,placeholder:ae?void 0:w,value:G[m]||"",onChange:ie=>N(m,ie.target.value),readOnly:j,error:b},le);case"tel":return e.jsx(ye,{required:P,type:"tel",label:xe,placeholder:ae?void 0:w,value:G[m]||"",onChange:ie=>N(m,ie.target.value),readOnly:j,error:b},le);default:return e.jsx(ye,{required:P,type:"text",label:xe,placeholder:ae?void 0:w,value:G[m]||"",onChange:ie=>N(m,ie.target.value),readOnly:j,error:b},le)}},ze=(m,C)=>{if(m.customType==="paragraph")return e.jsx("p",{style:{fontSize:"14px",lineHeight:"1.7",margin:0,color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:m.displayText||m.label||""}},`custom-${C}`);if(m.customType==="html")return e.jsx("div",{dangerouslySetInnerHTML:{__html:m.label||""}},`custom-${C}`);if(m.customType==="br")return e.jsx("div",{style:{height:"12px"}},`custom-${C}`);if(m.customType==="link")return e.jsx("div",{children:e.jsx("a",{href:m.linkUrl||"#",target:"_blank",rel:"noopener noreferrer",style:{color:"var(--metakyc-primary, #2563eb)",fontSize:"14px",textDecoration:"underline"},children:m.displayText||m.label||m.linkText||m.linkUrl||""})},`custom-${C}`);if(!m.paramName)return null;const F=fe[m.paramName],u=m.displayText||m.label||m.paramName,l=m.labelMode?m.labelMode!=="placeholder":A;return m.customType==="checkbox"?e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:V[m.paramName]==="true",onChange:h=>re(m.paramName,h.target.checked?"true":"false"),style:{width:"16px",height:"16px",accentColor:"var(--metakyc-primary, #2563eb)"}}),e.jsxs("span",{style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)"},children:[u,m.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),F&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:F})]},`custom-${C}`):e.jsx(ye,{type:"text",label:l?`${u}${m.required?" *":""}`:void 0,placeholder:l?void 0:u,value:V[m.paramName]||"",onChange:h=>re(m.paramName,h.target.value),required:m.required,error:F},`custom-${C}`)},et=m=>{const C=ue(m);return e.jsxs("div",{className:"space-y-4",children:[m.conditionalOn&&e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:C,onChange:F=>re(m.conditionalOn,F.target.checked?"true":"false"),style:{width:"16px",height:"16px",accentColor:"var(--metakyc-primary, #2563eb)"}}),e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:m.conditionalOn})]}),C&&e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:m.fields.map((F,u)=>{const l=Math.min(4,Math.max(1,Number(F.colSpan)||4)),h=F.isCustom?`custom-${u}-${F.paramName}`:`builtin-${F.name}-${u}`;return e.jsx("div",{style:{gridColumn:`span ${l} / span ${l}`},children:F.isCustom?ze(F,u):Ge(F.name,h,F.displayText,F.countriesType,F.labelMode)},h)})})]})};if(!c||X)return e.jsx("div",{className:"metakyc-sdk",children:e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)",fontSize:"0.875rem"},children:"Loading form…"})]})})});if(k){const m=k[ce]??k[0],C=ve===-1,F=ne===-1,u=k.length,l=ue(m),h=Object.values(fe);return e.jsx("div",{className:"metakyc-sdk",children:e.jsxs(ee,{children:[e.jsx(ge,{children:e.jsx(nt,{title:(c==null?void 0:c.title)||"Company Registration"})}),e.jsxs(te,{children:[(m.title||m.subtitle)&&e.jsxs("div",{className:"mb-4",children:[m.title&&e.jsx("h3",{className:"font-semibold text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:m.title}),m.subtitle&&e.jsx("p",{className:"text-sm mt-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:m.subtitle})]}),(W||h.length>0)&&e.jsxs("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-lg",children:[W&&e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",W]}),h.map((P,b)=>e.jsx("p",{className:"text-red-600 text-sm",children:P},b))]}),u>1&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem",marginBottom:"1rem"},children:[k.map((P,b)=>e.jsx("div",{style:{height:"0.375rem",borderRadius:"9999px",transition:"all 150ms",...b===ce?{flex:"1 1 0%",backgroundColor:"var(--metakyc-primary, #2563eb)"}:b<ce?{width:"2rem",backgroundColor:"var(--metakyc-primary-light, #93c5fd)",opacity:.7}:{width:"2rem",backgroundColor:"#e5e7eb"}}},b)),e.jsxs("span",{style:{fontSize:"0.75rem",color:"var(--metakyc-text-muted, #9ca3af)",flexShrink:0},children:[ce+1," / ",u]})]}),et(m)]}),e.jsxs(be,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{children:[!C&&e.jsx(J,{type:"button",variant:"outline",onClick:()=>{de(ve),I({})},disabled:_||y,children:"Previous"}),C&&n&&e.jsx(J,{type:"button",variant:"outline",onClick:n,disabled:_||y,children:"Cancel"})]}),e.jsx(J,{type:"button",isLoading:_||y,onClick:F?Oe:ke,children:F?m.conditionalOn&&!l?"Skip & Submit":"Submit":m.conditionalOn&&!l?"Skip":"Next"})]})]})})}return e.jsx("div",{className:"metakyc-sdk",children:e.jsx("form",{onSubmit:Xe,children:e.jsxs(ee,{children:[e.jsx(ge,{children:e.jsx(nt,{title:(c==null?void 0:c.title)||"Company Registration"})}),e.jsxs(te,{children:[W&&e.jsx("div",{className:"mb-6 p-4 bg-red-50 border border-red-200 rounded-lg",children:e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",W]})}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:D.map(m=>e.jsx("div",{style:{gridColumn:"span 4 / span 4"},children:Ge(m)},m))})]}),e.jsxs(be,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[n&&e.jsx(J,{type:"button",variant:"outline",onClick:n,disabled:_||y,children:"Cancel"}),e.jsx(J,{type:"submit",isLoading:_||y,children:"Register Company"})]})]})})})},Ts=({applicantId:t,onComplete:r,onError:s,theme:n="light",className:a})=>{const{progress:o,currentStep:c,steps:d,workflowKey:y,nextWorkflowKey:p,hasWorkflowChanged:g,isLoading:T,error:v,moveBack:E,refreshProgress:A}=jr(t),[k,S]=i.useState(!1),D=i.useRef(null);if(i.useEffect(()=>{v&&s&&s(v)},[v,s]),i.useEffect(()=>{o!=null&&o.workflowResult&&r&&r(o.workflowResult)},[o==null?void 0:o.workflowResult,r]),i.useEffect(()=>{n==="dark"?document.documentElement.classList.add("dark"):document.documentElement.classList.remove("dark")},[n]),i.useEffect(()=>{g&&S(!1)},[g]),T||!o)return e.jsx("div",{className:`metakyc-sdk ${a||""}`,children:e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Loading workflow..."})]})})});if(v)return e.jsx("div",{className:`metakyc-sdk ${a||""}`,children:e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-lg mb-4",style:{color:"var(--metakyc-danger, #ef4444)"},children:"An error occurred"}),e.jsx("p",{style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:v.message})]})})})});if(g&&!k)return e.jsx("div",{className:`metakyc-sdk ${a||""}`,children:e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("div",{className:"text-center py-8",children:[e.jsx("div",{className:"mb-6",children:e.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-full mb-4",style:{backgroundColor:"var(--metakyc-primary-light, #dbeafe)"},children:e.jsx("svg",{className:"w-8 h-8",style:{color:"var(--metakyc-primary, #2563eb)"},fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})})}),e.jsx("h3",{className:"text-xl font-semibold mb-2",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Workflow Transition"}),e.jsx("p",{className:"mb-6",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Your application workflow has been updated based on your progress."}),e.jsxs("div",{className:"rounded-lg p-4 mb-6 max-w-md mx-auto",style:{backgroundColor:"var(--metakyc-surface, #f9fafb)"},children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"mb-1",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"Previous Workflow"}),e.jsx("p",{className:"font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:y})]}),e.jsx("svg",{className:"w-6 h-6 mx-4",style:{color:"var(--metakyc-text-muted, #9ca3af)"},fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 7l5 5m0 0l-5 5m5-5H6"})}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"mb-1",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"New Workflow"}),e.jsx("p",{className:"font-medium",style:{color:"var(--metakyc-primary, #2563eb)"},children:p})]})]}),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:()=>S(!0),className:"px-6 py-3 font-medium rounded-lg transition-opacity hover:opacity-90",style:{backgroundColor:"var(--metakyc-primary, #2563eb)",color:"#ffffff"},children:"Continue with New Workflow"})]})})})});if(o.status===Te.Finished||o.status===Te.OnHold)return e.jsx("div",{className:`metakyc-sdk ${a||""}`,children:e.jsx(ft,{kycStatus:o.kycStatus,reviewStatus:o.reviewStatus,workflowResult:o.workflowResult,customMessage:o.customMessage,onContinue:r&&o.workflowResult?()=>r(o.workflowResult):void 0,onContactSupport:()=>{typeof window<"u"&&(window.location.href="mailto:support@example.com")}})});if(!c)return e.jsx("div",{className:`metakyc-sdk ${a||""}`,children:e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:o.status===Te.IdentityPending?"Loading identity verification...":"Loading current step..."})]})})});const Y=U=>{switch(U){case oe.Overview:return"Overview";case oe.Questionaries:return"Questionnaire";case oe.UploadDocument:return"Documents";case oe.IdentitySdk:return"Identity";case oe.RiskScoring:return"Risk Assessment";case oe.InvestorCategorization:return"Investor Categorization";case oe.AppropriatenessTest:return"Appropriateness Test";case oe.AdditionalData:return"Additional Data";case oe.ManualReview:return"Review";default:return""}},L=()=>{const U=d.filter(q=>q.visibility!==!1),X=U.findIndex(q=>q.order===c.order),R=X>=0?X+1:1,f=U.length,O=f>1?X/(f-1)*100:100;return e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",marginBottom:"16px"},children:[e.jsx(nt,{}),e.jsxs(kt,{variant:o.status===1?"info":"success",children:["Step ",R," of ",f]})]}),e.jsx("div",{style:{marginBottom:"16px"},children:e.jsx("div",{style:{height:"4px",borderRadius:"999px",backgroundColor:"var(--metakyc-border, #e5e7eb)",overflow:"hidden"},children:e.jsx("div",{style:{height:"100%",borderRadius:"999px",backgroundColor:"var(--metakyc-primary, #2563eb)",width:`${O}%`,transition:"width 0.4s ease"}})})}),e.jsx(Fs,{ref:D,visibleSteps:U,currentVisibleStepIndex:X,getStepFallbackName:Y})]})},B=()=>{const U={applicantId:t,onComplete:async()=>{await A()},onBack:c.order>0?E:void 0};switch(c.action){case oe.Questionaries:return e.jsx(Mr,{...U});case oe.UploadDocument:return e.jsx(Dr,{...U});case oe.Overview:return e.jsx(Or,{...U});case oe.IdentitySdk:return e.jsx(_r,{...U});case oe.RiskScoring:return e.jsx(zr,{...U});case oe.AdditionalData:case oe.InvestorCategorization:return e.jsx($r,{...U});case oe.AppropriatenessTest:return e.jsx(Br,{...U});case oe.ManualReview:return e.jsx(ft,{kycStatus:o.kycStatus,reviewStatus:o.reviewStatus,workflowResult:o.workflowResult,customMessage:o.customMessage});default:return e.jsx(ee,{children:e.jsxs(te,{className:"py-12 text-center",children:[e.jsx("div",{className:"mb-4",children:e.jsx(Ee,{})}),e.jsxs("p",{className:"text-gray-600 dark:text-gray-400 mb-2",children:["Processing step: ",c.title||c.name]}),e.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:["Action type: ",oe[c.action]]})]})})}};return e.jsxs("div",{className:`metakyc-sdk ${a||""}`,children:[L(),B()]})},Fs=i.forwardRef(({visibleSteps:t,currentVisibleStepIndex:r,getStepFallbackName:s},n)=>{const a=i.useRef(null),o=i.useRef(null);return i.useImperativeHandle(n,()=>a.current),i.useEffect(()=>{if(o.current&&a.current){const c=a.current,d=o.current,y=d.offsetLeft-c.offsetWidth/2+d.offsetWidth/2;c.scrollTo({left:Math.max(0,y),behavior:"smooth"})}},[r]),e.jsx("div",{ref:a,className:"metakyc-stepper-scroll",style:{display:"flex",alignItems:"center",overflowX:"auto",overflowY:"hidden",scrollbarWidth:"none",msOverflowStyle:"none",WebkitOverflowScrolling:"touch",padding:"4px 0",gap:"0"},children:t.map((c,d)=>{const y=d<r,p=d===r,g=y||p,T=c.displayName||c.name||s(c.action)||`Step ${d+1}`;return e.jsxs(i.Fragment,{children:[e.jsxs("div",{ref:p?o:void 0,style:{display:"flex",alignItems:"center",flexShrink:0},children:[e.jsx("div",{style:{width:"28px",height:"28px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"12px",fontWeight:600,flexShrink:0,transition:"all 0.2s ease",...g?{backgroundColor:"var(--metakyc-primary, #2563eb)",color:"#ffffff",border:"none"}:{backgroundColor:"transparent",color:"var(--metakyc-text-muted, #9ca3af)",border:"2px solid var(--metakyc-border, #e5e7eb)"}},children:y?e.jsx("svg",{width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:2.5,viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}):d+1}),e.jsx("span",{style:{marginLeft:"6px",fontSize:"13px",whiteSpace:"nowrap",fontWeight:p?600:400,color:p?"var(--metakyc-text-primary, #111827)":y?"var(--metakyc-primary, #2563eb)":"var(--metakyc-text-muted, #9ca3af)",transition:"color 0.2s ease"},children:T})]}),d<t.length-1&&e.jsx("div",{style:{width:"32px",minWidth:"16px",height:"2px",margin:"0 8px",flexShrink:0,borderRadius:"999px",backgroundColor:y?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",transition:"background-color 0.2s ease"}})]},c.order)})})});function Ps(t){return We.z.object({questionResults:We.z.any()}).passthrough()}function Ls(t){let r=We.z.array(We.z.instanceof(File));if(t.isRequired?r=r.min(1,`${t.displayName} is required`):r=r.optional(),t.multipleFile||(r=r.refine(s=>!s||s.length<=1,{message:"Only one file is allowed"})),t.maxEachFileSizeByte>0&&(r=r.refine(s=>!s||s.every(n=>n.size<=t.maxEachFileSizeByte),{message:`File size must not exceed ${Math.round(t.maxEachFileSizeByte/1024/1024)}MB`})),t.allowedTypes){const s=t.allowedTypes.split(",").map(n=>n.trim());r=r.refine(n=>n?n.every(a=>s.some(o=>o.endsWith("/*")?a.type.startsWith(o.slice(0,-2)):a.type===o)):!0,{message:"Invalid file type"})}return r}function Ms(t){const r={};return t.uploadDocumentFiles.forEach(s=>{const n=`file_${s.id}`;r[n]=Ls(s)}),We.z.object(r)}function Ds(t){return We.z.any()}function Os(t){return We.z.string().min(1,"This question is required")}function zs(t){const r={};return t.appropriatenessQuestions.forEach(s=>{const n=`question_${s.id}`;r[n]=Os()}),We.z.object(r)}const $s=We.z.any();exports.ALLOWED_LANGUAGES=ht;exports.ApplicantProgressOnHoldReason=At;exports.ApplicantProgressStatus=Te;exports.ApplicantService=qt;exports.ApplicantStatus=Ft;exports.AppropriatenessQuestionType=Ot;exports.AppropriatenessTestService=Qt;exports.AppropriatenessTestStep=Br;exports.Badge=kt;exports.BaseInformationService=Xt;exports.Button=J;exports.COMPANY_FIELD_METADATA=Ze;exports.Card=ee;exports.CardContent=te;exports.CardFooter=be;exports.CardHeader=ge;exports.CountriesType=He;exports.CreateApplicantForm=Es;exports.CreateCompanyApplicantForm=As;exports.CriteriaBuiltInType=$t;exports.DEFAULT_COMPANY_VISIBLE_FIELDS=_t;exports.DEFAULT_VISIBLE_FIELDS=Ht;exports.DocumentReviewStatus=Dt;exports.EndpointBuilder=Ut;exports.ErrorHandler=rt;exports.EventEmitter=lr;exports.FIELD_METADATA=Qe;exports.FileType=Mt;exports.FileUpload=Er;exports.GenderType=lt;exports.Header=nt;exports.HttpClient=Kt;exports.IdentityProviderManager=_e;exports.IdentityService=Zt;exports.IdentityVerificationProvider=Ae;exports.IdentityVerificationStep=_r;exports.Input=ye;exports.InvestorCategorizationService=er;exports.InvestorCategorizationStep=$r;exports.InvestorCategorizationType=je;exports.InvestorCategoryType=Bt;exports.KycProcessStatus=Pt;exports.KycStatus=Ve;exports.KycStatusDisplay=ft;exports.KycWorkflow=Ts;exports.Logo=Hr;exports.MetaKYCContext=bt;exports.MetaKYCError=Le;exports.MetaKYCProvider=Xr;exports.MultiSelect=Ir;exports.OnfidoProvider=mr;exports.OverviewService=Gt;exports.OverviewStep=Or;exports.PhoneInput=Ar;exports.QuestionnaireService=Vt;exports.QuestionnaireStep=Mr;exports.ReviewStatus=Ye;exports.RiskCriteriaType=zt;exports.RiskLevel=Tt;exports.RiskScoringService=Jt;exports.RiskScoringStep=zr;exports.SardinAIProvider=yr;exports.SearchableSelect=De;exports.Select=mt;exports.Spinner=Ee;exports.StepRouter=dr;exports.SumsubProvider=pr;exports.ThemeManager=xr;exports.ThemePreset=we;exports.ThemeService=or;exports.UploadDocumentService=Yt;exports.UploadDocumentStep=Dr;exports.UserType=Lt;exports.ValueDataType=Me;exports.WorkflowOrchestrator=ur;exports.WorkflowResultType=ot;exports.WorkflowState=cr;exports.WorkflowStepAction=oe;exports.appropriatenessTestSchema=$s;exports.clearAllStorage=ns;exports.clearApplicantId=br;exports.clearWorkflowState=kr;exports.cn=Se;exports.corporateTheme=tr;exports.defaultConfig=Wt;exports.defaultTheme=Re;exports.fileToBase64=hr;exports.fintechTheme=rr;exports.formatFileSize=ut;exports.generateAppropriatenessSchema=zs;exports.generateQuestionnaireSchema=Ps;exports.generateRiskScoringSchema=Ds;exports.generateUploadDocumentSchema=Ms;exports.getAcceptString=rs;exports.getApplicantId=gr;exports.getThemePreset=st;exports.getWorkflowState=ss;exports.healthcareTheme=sr;exports.isScriptLoaded=Yr;exports.loadScript=gt;exports.minimalTheme=ar;exports.modernTheme=nr;exports.removeScript=Qr;exports.saveApplicantId=fr;exports.saveWorkflowState=vr;exports.themePresets=ir;exports.useApplicant=vt;exports.useAppropriatenessTest=as;exports.useIdentityVerification=Nr;exports.useKycWorkflow=jr;exports.useMetaKYC=Ne;exports.useOverview=Cr;exports.useQuestionnaire=wr;exports.useRiskScoring=Rr;exports.useUploadDocument=Sr;exports.validateFileSize=es;exports.validateFileType=ts;
|
|
102
|
+
*/const hs=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],Dr=Pr("chevron-right",hs);function fs(t,r){const s=!r||r.length===0||r.every(n=>!n||!n.trim());if(t.isRequired&&s)return t.errorMessage||"This field is required";if(!s){const n=r[0]??"";if(n&&t.regex)try{if(!new RegExp(t.regex).test(n))return t.errorMessage||"Invalid format"}catch{}if(n!==""){const a=Number(n);if(!isNaN(a)&&n.trim()!==""){if(t.min!==void 0&&t.min!==null&&a<t.min)return`Minimum value is ${t.min}`;if(t.max!==void 0&&t.max!==null&&a>t.max)return`Maximum value is ${t.max}`}else{if(t.min!==void 0&&t.min!==null&&n.length<t.min)return`Minimum length is ${t.min} characters`;if(t.max!==void 0&&t.max!==null&&n.length>t.max)return`Maximum length is ${t.max} characters`}}}return null}function gs(t){const r=t.flatMap((n,a)=>(n.questions??[]).map((o,c)=>({question:o,groupIndex:a,qIdx:c}))),s=new Map;for(const n of r){const a=n.question.pageNumber!=null&&n.question.pageNumber>0?n.question.pageNumber:1;s.has(a)||s.set(a,[]),s.get(a).push(n)}return Array.from(s.entries()).sort(([n],[a])=>n-a).map(([,n])=>n)}const Mr=({applicantId:t,onComplete:r,onBack:s})=>{const{questionnaire:n,initialAnswers:a,isLoading:o,isSubmitting:c,error:d,submit:y}=Sr(t),[p,g]=i.useState({}),[T,v]=i.useState({}),[E,A]=i.useState(0);i.useEffect(()=>{a&&Object.keys(a).length>0&&Object.keys(p).length===0&&g(a)},[a]);const k=i.useMemo(()=>n?gs(n.questionGroups):[],[n]),S=E===k.length-1,M=k[E]??[],Y=i.useCallback((R,f)=>{g(O=>({...O,[R]:f})),v(O=>{const q={...O};return delete q[R],q})},[]),L=i.useCallback(()=>{const R={};for(const{question:f}of M){const O=fs(f,p[f.id]??[]);O&&(R[f.id]=O)}return v(f=>({...f,...R})),Object.keys(R).length===0},[M,p]),B=()=>{L()&&A(R=>R+1)},U=()=>{E>0?A(R=>R-1):s==null||s()},X=async()=>{if(!(!L()||!n))try{const R=n.questionGroups.flatMap(O=>(O.questions??[]).map(q=>({questionId:q.id,values:p[q.id]??[]}))),f={applicantId:t,questionnarieId:n.id,questionResults:R};await y(f),r==null||r()}catch(R){console.error("Questionnaire submit error:",R)}};return o?e.jsx(ee,{children:e.jsx(te,{children:e.jsx(Ee,{className:"my-8"})})}):d?e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading questionnaire: ",d.message]})})}):n?e.jsxs(ee,{children:[e.jsxs(ge,{children:[e.jsx("h2",{className:"text-lg font-bold",children:n.displayName}),n.subtitle&&e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:n.subtitle}),k.length>1&&e.jsxs("div",{className:"flex items-center justify-between mt-3",children:[e.jsxs("span",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:["Page ",E+1," of ",k.length]}),e.jsx("div",{className:"flex items-center gap-1.5",children:k.map((R,f)=>e.jsx("div",{className:"rounded-full transition-all duration-200",style:{height:"6px",width:f===E?"20px":"6px",backgroundColor:f<=E?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},f))})]})]}),e.jsx(te,{className:"space-y-6",children:M.map(({question:R})=>e.jsx(bs,{question:R,value:p[R.id]??[],error:T[R.id],onChange:f=>Y(R.id,f)},R.id))}),e.jsxs(be,{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs(J,{type:"button",variant:"outline",onClick:U,style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(Lr,{size:14}),E>0?"Previous":"Back"]}),S?e.jsx(J,{type:"button",isLoading:c,onClick:X,children:"Continue"}):e.jsxs(J,{type:"button",onClick:B,style:{display:"flex",alignItems:"center",gap:"4px"},children:["Next",e.jsx(Dr,{size:14})]})]}),d&&e.jsx("div",{className:"mx-6 mb-4 p-3 bg-red-50 border border-red-200 rounded",children:e.jsx("p",{className:"text-red-600 text-sm",children:d.message})})]}):null},bs=({question:t,value:r,error:s,onChange:n})=>{var c;const o=(((c=t.defaultAnswers)==null?void 0:c.length)??0)>0?t.showAsDropdown?t.canMultipleAnswer?"multi-select":"single-select":t.canMultipleAnswer?"checkbox":"radio":"text";return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[t.text,t.isRequired&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),t.subtitle&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:t.subtitle}),t.description&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:t.description}),o==="text"&&e.jsx(ye,{value:r[0]??"",onChange:d=>n([d.target.value]),placeholder:t.subtitle?void 0:"Enter your answer…",error:s,required:t.isRequired}),o==="single-select"&&e.jsx(mt,{value:r[0]??"",onChange:d=>n([d.target.value]),options:(t.defaultAnswers??[]).map(d=>({value:d,label:d})),placeholder:"Select an option…",error:s,required:t.isRequired}),o==="radio"&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultAnswers??[]).map(d=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"radio",checked:r[0]===d,onChange:()=>n([d]),className:"metakyc-option-input",style:{width:"16px",height:"16px",minWidth:"16px",flexShrink:0,flexGrow:0,accentColor:"var(--metakyc-primary, #2563eb)",cursor:"pointer",margin:0,padding:0,display:"inline-block",verticalAlign:"middle"}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:d})]},d)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),(o==="checkbox"||o==="multi-select")&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultAnswers??[]).map(d=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"checkbox",checked:r.includes(d),onChange:y=>{y.target.checked?n([...r,d]):n(r.filter(p=>p!==d))},className:"metakyc-option-input",style:{width:"16px",height:"16px",minWidth:"16px",flexShrink:0,flexGrow:0,accentColor:"var(--metakyc-primary, #2563eb)",cursor:"pointer",margin:0,padding:0,display:"inline-block",verticalAlign:"middle"}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:d})]},d)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),s&&o==="text"&&null]})};function vs(t){const r=new Map;for(const s of t){const n=s.pageNumber!=null&&s.pageNumber>0?s.pageNumber:1;r.has(n)||r.set(n,[]),r.get(n).push(s)}return Array.from(r.entries()).sort(([s],[n])=>s-n).map(([,s])=>s)}const Or=({applicantId:t,onComplete:r,onBack:s})=>{const{uploadDocument:n,isLoading:a,isSubmitting:o,error:c,submit:d}=Cr(t),[y,p]=i.useState({}),[g,T]=i.useState(null),[v,E]=i.useState(0),[A,k]=i.useState({}),S=i.useMemo(()=>n?vs(n.uploadDocumentFiles):[],[n]),M=S[v]??[],Y=v===S.length-1,L=S.length,B=i.useCallback(()=>{const f={};for(const O of M)O.isRequired&&(y[O.id]||[]).length===0&&(f[O.id]=`${O.displayName} is required`);return k(f),Object.keys(f).length===0},[M,y]),U=()=>{B()&&(E(f=>f+1),k({}))},X=()=>{v>0?(E(f=>f-1),k({})):s==null||s()},R=async()=>{if(!(!B()||!n)){T(null);try{const f=await Promise.all(n.uploadDocumentFiles.map(async q=>{const Q=y[q.id]||[],$=await Promise.all(Q.map(async G=>({fileName:G.name,fileData:await fr(G)})));return{uploadDocumentFileId:q.id,valueList:$}})),O={applicantId:t,uploadDocumentId:n.id,uploadDocumentResults:f};await d(O),r==null||r()}catch(f){T((f==null?void 0:f.message)||"Failed to submit documents. Please try again.")}}};return a?e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"48px 0",gap:"16px"},children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)"},children:"Loading document requirements..."})]})})}):c?e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"32px 0",gap:"12px",textAlign:"center"},children:[e.jsx("div",{style:{width:"48px",height:"48px",borderRadius:"50%",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 10%, transparent)",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),e.jsx("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]})}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-danger, #ef4444)",fontWeight:500},children:"Error loading document requirements"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-muted, #9ca3af)"},children:c.message})]})})}):n?e.jsxs(ee,{children:[e.jsxs(ge,{children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:n.displayName||"Upload Documents"}),n.subtitle&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",marginTop:"4px"},children:n.subtitle}),L>1&&e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginTop:"12px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)"},children:["Page ",v+1," of ",L]}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:S.map((f,O)=>e.jsx("div",{style:{height:"6px",width:O===v?"20px":"6px",borderRadius:"999px",transition:"all 0.2s ease",backgroundColor:O<=v?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},O))})]})]}),n.description&&v===0&&e.jsxs("div",{style:{margin:"0 24px",marginTop:"4px",display:"flex",gap:"10px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-primary, #2563eb) 5%, var(--metakyc-background, #ffffff))",border:"1px solid color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-primary, #2563eb)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:"1px"},children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-secondary, #374151)",margin:0,lineHeight:1.5},children:n.description})]}),e.jsx(te,{children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"24px"},children:M.map(f=>e.jsx(Ar,{label:f.displayName,subtitle:f.subtitle,accept:f.allowedTypes,multiple:f.multipleFile,maxSize:f.maxEachFileSizeByte,required:f.isRequired,error:A[f.id],value:y[f.id]||[],onChange:O=>{T(null),k(q=>{const Q={...q};return delete Q[f.id],Q}),p(q=>({...q,[f.id]:O}))}},f.id))})}),g&&e.jsxs("div",{style:{margin:"0 24px",padding:"10px 14px",borderRadius:"8px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:g})]}),e.jsx(be,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[e.jsx(J,{type:"button",variant:"outline",onClick:X,children:v>0?"Previous":"Back"}),Y?e.jsx(J,{type:"button",isLoading:o,onClick:R,children:o?"Uploading...":"Continue"}):e.jsx(J,{type:"button",onClick:U,children:"Next"})]})})]}):null},zr=({applicantId:t,onComplete:r,onBack:s})=>{const{overview:n,isLoading:a,isSubmitting:o,error:c,passOverview:d}=Nr(t),y=async()=>{await d(),r==null||r()};return a?e.jsx(ee,{children:e.jsx(te,{children:e.jsx(Ee,{className:"my-8"})})}):c?e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading overview: ",c.message]})})}):n?e.jsxs(ee,{children:[e.jsxs(ge,{children:[e.jsx("h2",{className:"text-lg font-bold",children:n.title||"Overview"}),n.description&&e.jsx("p",{className:"mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:n.description})]}),e.jsx(te,{className:"space-y-8",children:n.steps&&n.steps.length>0?n.steps.sort((p,g)=>p.order-g.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(be,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{onClick:y,isLoading:o,children:"Continue"})]})]}):null};function ks(t){const r=(t??"en").toLowerCase().replace("_","-");try{return Intl.NumberFormat.supportedLocalesOf([r]),r}catch{return"en"}}function js(t){return t.valueDataType===De.Money&&Array.isArray(t.defaultValues)&&t.defaultValues.length>0}function ws(t,r){const s=new Intl.NumberFormat(ks(r),{minimumFractionDigits:0,maximumFractionDigits:2});return t.replace(/([\d]+(?:\.\d+)?)/g,n=>{const a=parseFloat(n);return isNaN(a)?n:s.format(a)})}function Ss(t,r){const s=!r||r.length===0||r.every(n=>!n||!n.trim());if(t.isRequired&&s)return t.errorMessage||`${t.displayName} is required`;if(!s){const n=r[0]??"";if(n&&t.regex)try{if(!new RegExp(t.regex).test(n))return t.errorMessage||"Invalid format"}catch{}const a=t.valueDataType===De.Integer||t.valueDataType===De.Money||t.valueDataType===De.DigitOnly;if(a&&n.trim()!==""){const o=Number(n);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(!a&&n!==""){if(t.min!==void 0&&t.min!==null&&n.length<t.min)return`Minimum length is ${t.min} characters`;if(t.max!==void 0&&t.max!==null&&n.length>t.max)return`Maximum length is ${t.max} characters`}}return null}function Cs(t){const r=new Map;return t.forEach((s,n)=>{const a=s.pageNumber!=null&&s.pageNumber>0?s.pageNumber:1;r.has(a)||r.set(a,[]),r.get(a).push({criterion:s,idx:n})}),Array.from(r.entries()).sort(([s],[n])=>s-n).map(([,s])=>s)}function Ns(t){return t.builtInType===1?"country":!t.defaultValues||t.defaultValues.length===0?"text":t.multipleValue?"checkbox":"radio"}const $r=({applicantId:t,onComplete:r,onBack:s})=>{const{config:n}=Ne(),a=n.locale??"en",{criteria:o,initialAnswers:c,isLoading:d,isSubmitting:y,error:p,submit:g}=Ir(t),[T,v]=i.useState({}),[E,A]=i.useState({}),[k,S]=i.useState(0),[M,Y]=i.useState(!1);i.useEffect(()=>{c&&Object.keys(c).length>0&&Object.keys(T).length===0&&v(c)},[c]);const L=i.useMemo(()=>o&&o.length>0?Cs(o):[],[o]),B=k===L.length-1,U=L[k]??[];i.useEffect(()=>{!d&&o&&o.length===0&&!M&&!y&&(Y(!0),g({applicantId:t,criteriaValueInputs:[]}).then(()=>r==null?void 0:r()).catch(console.error))},[d,o,M,y,g,t,r]);const X=i.useCallback((Q,$)=>{v(G=>({...G,[Q]:$})),A(G=>{const se={...G};return delete se[Q],se})},[]),R=i.useCallback(()=>{const Q={};for(const{criterion:$}of U){const G=Ss($,T[$.id]??[]);G&&(Q[$.id]=G)}return A($=>({...$,...Q})),Object.keys(Q).length===0},[U,T]),f=()=>{R()&&S(Q=>Q+1)},O=()=>{k>0?S(Q=>Q-1):s==null||s()},q=async()=>{if(!(!R()||!o))try{const Q=o.map(G=>{const se=(T[G.id]??[]).filter(V=>V&&V.trim());return se.length>0?{riskCriteriaId:G.id,values:se}:null}).filter(G=>G!==null);await g({applicantId:t,criteriaValueInputs:Q}),r==null||r()}catch(Q){console.error("Risk scoring submit error:",Q)}};return d?e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center text-sm mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Loading risk scoring criteria…"})]})}):!d&&o&&o.length===0?e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center text-sm mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"No criteria required. Moving to next step…"})]})}):p?e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading criteria: ",p.message]})})}):o?e.jsxs(ee,{children:[e.jsxs(ge,{children:[e.jsx("h2",{className:"text-lg font-bold",children:"Risk Assessment"}),e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Please answer the following questions for risk evaluation"}),L.length>1&&e.jsxs("div",{className:"flex items-center justify-between mt-3",children:[e.jsxs("span",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:["Page ",k+1," of ",L.length]}),e.jsx("div",{className:"flex items-center gap-1.5",children:L.map((Q,$)=>e.jsx("div",{className:"rounded-full transition-all duration-200",style:{height:"6px",width:$===k?"20px":"6px",backgroundColor:$<=k?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},$))})]})]}),e.jsx(te,{className:"space-y-6",children:U.map(({criterion:Q})=>e.jsx(Rs,{criterion:Q,value:T[Q.id]??[],error:E[Q.id],locale:a,onChange:$=>X(Q.id,$)},Q.id))}),e.jsxs(be,{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs(J,{type:"button",variant:"outline",onClick:O,style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(Lr,{size:14}),k>0?"Previous":"Back"]}),B?e.jsx(J,{type:"button",isLoading:y,onClick:q,children:"Continue"}):e.jsxs(J,{type:"button",onClick:f,style:{display:"flex",alignItems:"center",gap:"4px"},children:["Next",e.jsx(Dr,{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},Rs=({criterion:t,value:r,error:s,locale:n,onChange:a})=>{const o=Ns(t),c=t.valueDataType===De.Integer||t.valueDataType===De.Money||t.valueDataType===De.DigitOnly,d=js(t),y=p=>d?ws(p,n):p;return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[t.displayName,t.isRequired&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),t.description&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:t.description}),c&&(t.min!==void 0||t.max!==void 0)&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:t.min!==void 0&&t.max!==void 0?`Range: ${t.min} – ${t.max}`:t.min!==void 0?`Minimum: ${t.min}`:`Maximum: ${t.max}`}),o==="text"&&e.jsx(ye,{value:r[0]??"",onChange:p=>a([p.target.value]),type:c?"number":"text",placeholder:"Enter your answer…",error:s,required:t.isRequired,min:t.min,max:t.max,onKeyDown:p=>{t.valueDataType===De.DigitOnly&&["e","E","+","-","."].includes(p.key)&&p.preventDefault()}}),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:()=>a([p]),className:"metakyc-option-input",style:{width:"16px",height:"16px",minWidth:"16px",flexShrink:0,flexGrow:0,accentColor:"var(--metakyc-primary, #2563eb)",cursor:"pointer",margin:0,padding:0,display:"inline-block",verticalAlign:"middle"}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:y(p)})]},p)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),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:g=>{g.target.checked?a([...r,p]):a(r.filter(T=>T!==p))},className:"metakyc-option-input",style:{width:"16px",height:"16px",minWidth:"16px",flexShrink:0,flexGrow:0,accentColor:"var(--metakyc-primary, #2563eb)",cursor:"pointer",margin:0,padding:0,display:"inline-block",verticalAlign:"middle"}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:y(p)})]},p)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),o==="country"&&e.jsx(mt,{value:r[0]??"",onChange:p=>a([p.target.value]),options:[{value:"US",label:"United States"},{value:"GB",label:"United Kingdom"},{value:"DE",label:"Germany"},{value:"FR",label:"France"},{value:"AE",label:"United Arab Emirates"}],placeholder:"Select a country…",error:s,required:t.isRequired})]})},Br=({applicantId:t,onComplete:r,onBack:s})=>{const{investorCategorizationService:n}=Ne(),[a,o]=i.useState(null),[c,d]=i.useState(!1),[y,p]=i.useState(null),g=async T=>{if(T.preventDefault(),a===null){p("Please select an investor type");return}d(!0),p(null);try{const v={applicantId:t,investorType:a};console.log("Submitting investor categorization:",v);const E=await n.setInvestorCategorization(v);console.log("Investor categorization result:",E),r==null||r()}catch(v){console.error("Error submitting investor categorization:",v),p(v.message||"Failed to submit investor categorization")}finally{d(!1)}};return e.jsx("form",{onSubmit:g,children:e.jsxs(ee,{children:[e.jsxs(ge,{children:[e.jsx("h2",{className:"text-lg font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Which statement best describes you?"}),e.jsx("p",{className:"mt-2",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"All Tokenise clients are treated as Retail Investors under EU regulation, which gives you the highest level of investor protection. For our internal purposes, we ask you to select the description that best matches your situation"})]}),e.jsxs(te,{className:"space-y-4",children:[e.jsx("p",{className:"text-sm font-medium mb-3",style:{color:"var(--metakyc-text-secondary, #374151)"},children:"Choose one"}),e.jsx("label",{className:"block p-4 border-2 rounded-lg cursor-pointer transition-all",style:{borderColor:a===je.Individual?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:a===je.Individual?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:je.Individual,checked:a===je.Individual,onChange:()=>o(je.Individual),className:"mt-1"}),e.jsxs("div",{className:"ml-3",children:[e.jsx("div",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Individual investor"}),e.jsx("div",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"(Recommended) Most of our clients choose this option. Provides the strongest protection and aligns with our mission to make investing accessible to everyone."})]})]})}),e.jsx("label",{className:"block p-4 border-2 rounded-lg cursor-pointer transition-all",style:{borderColor:a===je.Sophisticated?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:a===je.Sophisticated?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:je.Sophisticated,checked:a===je.Sophisticated,onChange:()=>o(je.Sophisticated),className:"mt-1"}),e.jsxs("div",{className:"ml-3",children:[e.jsx("div",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Sophisticated investor"}),e.jsx("div",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"In the last 2 years, I have done one or more of the following:"}),e.jsxs("ul",{className:"text-sm mt-2 space-y-1 list-none",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:[e.jsx("li",{children:"Worked in private equity or provided capital to small and medium enterprises, and/or"}),e.jsx("li",{children:"Been the director of a company with an annual turnover of at least (USD) $2m million, and/or"}),e.jsx("li",{children:"Invested directly in at least 2 private (not listed) companies."})]})]})]})}),e.jsx("label",{className:"block p-4 border-2 rounded-lg cursor-pointer transition-all",style:{borderColor:a===je.HighNetWorth?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:a===je.HighNetWorth?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:je.HighNetWorth,checked:a===je.HighNetWorth,onChange:()=>o(je.HighNetWorth),className:"mt-1"}),e.jsxs("div",{className:"ml-3",children:[e.jsx("div",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"High networth investor"}),e.jsxs("div",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:["I earn more than (USD/EUR) $150,000 per year, and/or",e.jsx("br",{}),"I have net assets (excluding my main property) of at least $/EUR 300,000"]})]})]})}),y&&e.jsx("div",{className:"p-4 rounded-lg",style:{backgroundColor:"#fee2e2",border:"1px solid #fca5a5"},children:e.jsxs("p",{className:"text-sm",style:{color:"#991b1b"},children:[e.jsx("strong",{children:"Error:"})," ",y]})})]}),e.jsxs(be,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"submit",isLoading:c,disabled:a===null,children:"Submit"})]})]})})};function Rt(t){const r=t.split(":").map(Number);return r.length===3?r[0]*3600+r[1]*60+r[2]:0}function yt(t){const r=Math.floor(t/60),s=t%60;return`${r.toString().padStart(2,"0")}:${s.toString().padStart(2,"0")}`}const _r=({applicantId:t,onComplete:r,onBack:s})=>{const{appropriatenessTestService:n}=Ne(),[a,o]=i.useState(null),[c,d]=i.useState(!0),[y,p]=i.useState(!1),[g,T]=i.useState(null),[v,E]=i.useState({}),[A,k]=i.useState(0),[S,M]=i.useState(!1),[Y,L]=i.useState(!1),[B,U]=i.useState(0),[X,R]=i.useState(0),[f,O]=i.useState(null);i.useEffect(()=>{(async()=>{try{d(!0),T(null);const z=await n.getAppropriatenessTest(t);if(o(z),z.waitTimeSpanForNextTry&&z.waitTimeSpanForNextTry!=="00:00:00"){const _=Rt(z.waitTimeSpanForNextTry);_>0&&U(_)}}catch(z){T(z.message||"Failed to load appropriateness test")}finally{d(!1)}})()},[t,n]),i.useEffect(()=>{if(!S||A<=0)return;const z=setInterval(()=>{k(_=>_<=1?(L(!0),0):_-1)},1e3);return()=>clearInterval(z)},[S,A]),i.useEffect(()=>{if(B<=0)return;const z=setInterval(()=>{U(_=>_<=1?0:_-1)},1e3);return()=>clearInterval(z)},[B]),i.useEffect(()=>{Y&&!y&&G()},[Y]);const q=()=>{a&&(M(!0),k(a.testDurationSec),R(0),E({}),T(null))},Q=(z,_)=>{E(me=>({...me,[z]:_}))},$=i.useCallback(async()=>{try{const z=await n.getAppropriatenessTest(t);if(o(z),z.waitTimeSpanForNextTry&&z.waitTimeSpanForNextTry!=="00:00:00"){const _=Rt(z.waitTimeSpanForNextTry);_>0&&U(_)}}catch{}},[t,n]),G=async z=>{if(a){if(!Y){const _=a.appropriatenessQuestions.length-Object.keys(v).length;if(_>0){T(`Please answer all questions. ${_} remaining.`);return}}p(!0),T(null);try{const _=a.appropriatenessQuestions.map(N=>({appropriatenessQuestionId:N.id,value:v[N.id]||""})),me={applicantId:t,appropriatenessTestId:a.id,appropriatenessQuestionResults:_};try{const N=await n.fillAppropriatenessTest(me);N.isSuccess?O({success:!0,message:N.message||"Congratulations! You have passed the test."}):(O({success:!1,message:N.message||"You did not pass the test."}),setTimeout(()=>$(),1e3))}catch(N){if(N.code===400&&N.message)O({success:!1,message:N.message}),setTimeout(()=>$(),1500);else throw N}}catch(_){T(_.message||"Failed to submit test. Please try again."),se()}finally{p(!1)}}},se=()=>{M(!1),L(!1),E({}),R(0)};if(c)return e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"48px 0",gap:"16px"},children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)"},children:"Loading test..."})]})})});if(!a)return e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("div",{style:{textAlign:"center",padding:"48px 0"},children:[e.jsx("p",{style:{fontSize:"16px",fontWeight:600,color:"var(--metakyc-danger, #ef4444)"},children:"No test data available"}),g&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"8px"},children:g})]})})});const V=a.testAllowedMaxTry-a.totalFailedTries,he=a.appropriatenessQuestions.length,ce=Object.keys(v).length;if(B>0)return e.jsxs(ee,{children:[e.jsx(ge,{children:e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:a.displayName})}),e.jsx(te,{children:e.jsxs("div",{style:{textAlign:"center",padding:"32px 0"},children:[e.jsx("div",{style:{width:"100px",height:"100px",borderRadius:"50%",margin:"0 auto 20px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"color-mix(in srgb, var(--metakyc-primary, #2563eb) 8%, transparent)"},children:e.jsx("span",{style:{fontSize:"28px",fontWeight:700,color:"var(--metakyc-primary, #2563eb)",fontVariantNumeric:"tabular-nums"},children:yt(B)})}),e.jsx("p",{style:{fontSize:"15px",fontWeight:500,color:"var(--metakyc-text-primary, #111827)"},children:"Please wait before retrying"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"4px"},children:"You can attempt the test again once the timer expires"}),g&&e.jsx("div",{style:{marginTop:"20px",padding:"12px 16px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:g})})]})})]});if(f){const z=()=>{O(null),se(),T(null)};return e.jsxs(ee,{children:[e.jsx(te,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",textAlign:"center",padding:"40px 16px",gap:"16px"},children:[e.jsx("div",{style:{width:"72px",height:"72px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:f.success?"color-mix(in srgb, var(--metakyc-success, #10b981) 12%, transparent)":"color-mix(in srgb, var(--metakyc-danger, #ef4444) 10%, transparent)"},children:f.success?e.jsxs("svg",{width:"36",height:"36",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-success, #10b981)",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),e.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]}):e.jsxs("svg",{width:"36",height:"36",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),e.jsx("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]})}),e.jsx("h2",{style:{fontSize:"20px",fontWeight:700,color:f.success?"var(--metakyc-success, #10b981)":"var(--metakyc-danger, #ef4444)",margin:0},children:f.success?"Test Passed":"Test Failed"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",margin:0,lineHeight:1.6,maxWidth:"400px",whiteSpace:"pre-line"},children:f.message}),!f.success&&V>0&&e.jsx("div",{style:{marginTop:"4px",padding:"10px 20px",borderRadius:"10px",backgroundColor:"var(--metakyc-surface, #f9fafb)",border:"1px solid var(--metakyc-border, #e5e7eb)"},children:e.jsxs("p",{style:{fontSize:"13px",color:"var(--metakyc-text-muted, #9ca3af)",margin:0},children:["You have ",e.jsx("strong",{style:{color:"var(--metakyc-text-primary, #111827)"},children:V})," attempt",V!==1?"s":""," remaining"]})}),!f.success&&V<=0&&e.jsx("div",{style:{marginTop:"4px",padding:"10px 20px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:"No attempts remaining. Please contact support for assistance."})})]})}),e.jsx(be,{children:e.jsx("div",{style:{display:"flex",justifyContent:"center",width:"100%",gap:"12px"},children:f.success?e.jsx(J,{type:"button",onClick:()=>r==null?void 0:r(),children:"Continue"}):e.jsxs(e.Fragment,{children:[V>0&&B<=0&&e.jsx(J,{type:"button",onClick:z,children:"Retake Test"}),V>0&&B>0&&e.jsx(J,{type:"button",onClick:z,children:"OK"}),V<=0&&s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"})]})})})]})}if(!S)return e.jsxs(ee,{children:[e.jsxs(ge,{children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:a.displayName}),a.subtitle&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",marginTop:"4px"},children:a.subtitle})]}),e.jsxs(te,{children:[a.description&&e.jsxs("div",{style:{marginBottom:"20px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-primary, #2563eb) 5%, var(--metakyc-background, #ffffff))",border:"1px solid color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)",display:"flex",gap:"10px"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-primary, #2563eb)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:"1px"},children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-secondary, #374151)",margin:0,lineHeight:1.5},children:a.description})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px",marginBottom:"20px"},children:[e.jsx(ct,{icon:"questions",label:"Questions",value:String(a.totalQuestionCount)}),e.jsx(ct,{icon:"time",label:"Time Limit",value:yt(a.testDurationSec)}),e.jsx(ct,{icon:"target",label:"Pass Requirement",value:`${a.testCorrectAnswerPassLimit} correct`}),e.jsx(ct,{icon:"retry",label:"Attempts Left",value:String(V),variant:V<=1?"warning":"default"})]}),g&&e.jsxs("div",{style:{marginBottom:"16px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)",display:"flex",gap:"10px"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:"1px"},children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),e.jsxs("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0,lineHeight:1.5},children:[e.jsx("strong",{children:"Previous attempt:"})," ",g]})]}),V<=0&&e.jsx("div",{style:{padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:"You have used all your attempts. Please contact support for assistance."})})]}),e.jsx(be,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:s?"space-between":"flex-end",width:"100%"},children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"button",onClick:q,disabled:V<=0,children:"Start Test"})]})})]});const de=a.appropriatenessQuestions[X],fe=X===he-1,I=ce===he,W=A<=60;return e.jsxs(ee,{children:[e.jsxs(ge,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:a.displayName}),e.jsxs("p",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"2px"},children:["Question ",X+1," of ",he]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 14px",borderRadius:"999px",backgroundColor:W?"color-mix(in srgb, var(--metakyc-danger, #ef4444) 10%, transparent)":"var(--metakyc-surface, #f3f4f6)",transition:"all 0.3s ease"},children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:W?"var(--metakyc-danger, #ef4444)":"var(--metakyc-text-muted, #9ca3af)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),e.jsx("span",{style:{fontSize:"16px",fontWeight:700,fontVariantNumeric:"tabular-nums",color:W?"var(--metakyc-danger, #ef4444)":"var(--metakyc-text-primary, #111827)",transition:"color 0.3s ease"},children:yt(A)})]})]}),e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsx("div",{style:{height:"4px",borderRadius:"999px",backgroundColor:"var(--metakyc-border, #e5e7eb)",overflow:"hidden"},children:e.jsx("div",{style:{height:"100%",borderRadius:"999px",backgroundColor:"var(--metakyc-primary, #2563eb)",width:`${ce/he*100}%`,transition:"width 0.3s ease"}})}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:"4px"},children:[e.jsxs("span",{style:{fontSize:"11px",color:"var(--metakyc-text-muted, #9ca3af)"},children:[ce," answered"]}),e.jsxs("span",{style:{fontSize:"11px",color:"var(--metakyc-text-muted, #9ca3af)"},children:[V," attempt",V!==1?"s":""," left"]})]})]})]}),e.jsxs(te,{children:[de&&e.jsx(Es,{question:de,index:X,selectedAnswer:v[de.id],onSelect:z=>Q(de.id,z),disabled:y}),he>1&&e.jsx("div",{style:{display:"flex",justifyContent:"center",gap:"6px",marginTop:"20px",flexWrap:"wrap"},children:a.appropriatenessQuestions.map((z,_)=>e.jsx("button",{type:"button",onClick:()=>R(_),style:{width:"28px",height:"28px",borderRadius:"8px",border:_===X?"2px solid var(--metakyc-primary, #2563eb)":"1px solid var(--metakyc-border, #e5e7eb)",backgroundColor:v[z.id]?_===X?"color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)":"color-mix(in srgb, var(--metakyc-primary, #2563eb) 8%, transparent)":_===X?"var(--metakyc-surface, #f9fafb)":"var(--metakyc-background, #ffffff)",color:v[z.id]?"var(--metakyc-primary, #2563eb)":"var(--metakyc-text-muted, #9ca3af)",fontSize:"12px",fontWeight:600,cursor:"pointer",transition:"all 0.15s ease",padding:0,display:"flex",alignItems:"center",justifyContent:"center"},children:_+1},z.id))}),Y&&e.jsxs("div",{style:{marginTop:"16px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, #f59e0b 10%, transparent)",border:"1px solid color-mix(in srgb, #f59e0b 25%, transparent)",display:"flex",alignItems:"center",gap:"10px"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"#f59e0b",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),e.jsx("p",{style:{fontSize:"13px",color:"#b45309",margin:0,fontWeight:500},children:"Time's up! Your answers are being submitted."})]}),g&&!Y&&e.jsx("div",{style:{marginTop:"16px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:g})})]}),e.jsx(be,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[e.jsx(J,{type:"button",variant:"outline",onClick:()=>{X>0?R(z=>z-1):s==null||s()},disabled:y,children:X>0?"Previous":"Cancel"}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[!fe&&e.jsx(J,{type:"button",onClick:()=>R(z=>z+1),children:"Next"}),(fe||I)&&e.jsx(J,{type:"button",isLoading:y,onClick:()=>G(),disabled:!I&&!Y,style:{opacity:I||Y?1:.5},children:Y?"Submitting...":"Submit Test"})]})]})})]})},Is={questions:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M9 11l3 3L22 4"}),e.jsx("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),time:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),target:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("circle",{cx:"12",cy:"12",r:"6"}),e.jsx("circle",{cx:"12",cy:"12",r:"2"})]}),retry:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})},ct=({icon:t,label:r,value:s,variant:n="default"})=>{const a=n==="warning";return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px",padding:"14px",borderRadius:"10px",backgroundColor:a?"color-mix(in srgb, #f59e0b 8%, transparent)":"var(--metakyc-surface, #f9fafb)",border:a?"1px solid color-mix(in srgb, #f59e0b 20%, transparent)":"1px solid var(--metakyc-border, #e5e7eb)"},children:[e.jsx("div",{style:{color:a?"#f59e0b":"var(--metakyc-primary, #2563eb)",flexShrink:0},children:Is[t]}),e.jsxs("div",{children:[e.jsx("p",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)",margin:0},children:r}),e.jsx("p",{style:{fontSize:"15px",fontWeight:600,color:a?"#b45309":"var(--metakyc-text-primary, #111827)",margin:0,marginTop:"1px"},children:s})]})]})},Es=({question:t,selectedAnswer:r,onSelect:s,disabled:n})=>e.jsxs("div",{children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[t.groupName&&e.jsx("span",{style:{display:"inline-block",fontSize:"11px",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em",color:"var(--metakyc-primary, #2563eb)",marginBottom:"8px"},children:t.groupName}),e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--metakyc-text-primary, #111827)",margin:0,lineHeight:1.5},children:t.question})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.answers.map((a,o)=>{const c=r===a;return e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"12px",padding:"14px 16px",borderRadius:"10px",border:`2px solid ${c?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}`,backgroundColor:c?"color-mix(in srgb, var(--metakyc-primary, #2563eb) 5%, var(--metakyc-background, #ffffff))":"var(--metakyc-background, #ffffff)",cursor:n?"default":"pointer",transition:"all 0.15s ease",opacity:n?.6:1},onMouseEnter:d=>{!n&&!c&&(d.currentTarget.style.borderColor="color-mix(in srgb, var(--metakyc-primary, #2563eb) 50%, var(--metakyc-border, #e5e7eb))")},onMouseLeave:d=>{c||(d.currentTarget.style.borderColor="var(--metakyc-border, #e5e7eb)")},children:[e.jsx("div",{style:{width:"20px",height:"20px",borderRadius:"50%",border:`2px solid ${c?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #d1d5db)"}`,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,transition:"border-color 0.15s ease"},children:c&&e.jsx("div",{style:{width:"10px",height:"10px",borderRadius:"50%",backgroundColor:"var(--metakyc-primary, #2563eb)"}})}),e.jsx("input",{type:"radio",name:`q-${t.id}`,value:a,checked:c,onChange:()=>s(a),disabled:n,style:{position:"absolute",opacity:0,width:0,height:0}}),e.jsx("span",{style:{fontSize:"14px",color:c?"var(--metakyc-text-primary, #111827)":"var(--metakyc-text-secondary, #6b7280)",fontWeight:c?500:400,transition:"color 0.15s ease"},children:a})]},o)})})]}),Hr=({applicantId:t,onComplete:r,onBack:s})=>{var Ge,ze,et,Ue;const{applicantService:n,baseInformationService:a,identityService:o,config:c,currentTheme:d}=Ne(),{identityData:y,provider:p,token:g,isLoading:T,error:v,requestIdentity:E,restartIdentity:A}=Rr(t),[k,S]=i.useState(null),[M,Y]=i.useState(null),[L,B]=i.useState([]),[U,X]=i.useState([]),[R,f]=i.useState(!0),[O,q]=i.useState(!1),[Q,$]=i.useState(null),[G,se]=i.useState(!1),V=i.useRef(!1),[he,ce]=i.useState({}),[de,fe]=i.useState({}),I=d!=null&&d.reviewPageFields&&d.reviewPageFields.length>0?d.reviewPageFields[0]:null,W=!!(d!=null&&d.reviewPageDisabled),z=i.useRef(!1);z.current=W;const _=qe.useForm({defaultValues:{street:"",streetNumber:"",city:"",zip:"",country:"",nationality:"",phonenumber:""}});i.useEffect(()=>{if(W){V.current||(V.current=!0,E().then(()=>q(!0)).catch(D=>console.error("[Identity] Auto-request failed:",D)).finally(()=>f(!1)));return}(async()=>{try{const[D,K,H]=await Promise.all([n.getApplicantData(t),a.getCountries("","en"),a.getCountries("","en",40)]);Y(D);const Z=new Set,m=K.map(h=>({value:h.abbreviation3||h.abbreviation,label:h.name})).filter(h=>!h.value||Z.has(h.value)?!1:(Z.add(h.value),!0));B(m);const C=new Set,F=H.filter(h=>h.countryCode).map(h=>({value:h.countryCode,label:`${h.countryCode} – ${h.name}`})).filter(h=>C.has(h.value)?!1:(C.add(h.value),!0));X(F);const u=D.applicantRequestData;if(ce({firstName:(u==null?void 0:u.firstName)||"",lastName:(u==null?void 0:u.lastName)||"",email:(u==null?void 0:u.email)||"",dateOfBirth:(u==null?void 0:u.dateOfBirth)||"",title:(u==null?void 0:u.title)||"",salutation:(u==null?void 0:u.salutation)||"",phonenumber:(u==null?void 0:u.phonenumber)||"",mobileCountryCode:(u==null?void 0:u.mobileCountryCode)||"",street:(u==null?void 0:u.street)||"",streetNumber:(u==null?void 0:u.streetNumber)||"",city:(u==null?void 0:u.city)||"",zip:(u==null?void 0:u.zip)||"",country:(u==null?void 0:u.country)||"",nationality:(u==null?void 0:u.nationality)||"",taxCountry:(u==null?void 0:u.taxCountry)||"",countryOfBirth:(u==null?void 0:u.countryOfBirth)||"",placeOfBirth:(u==null?void 0:u.placeOfBirth)||"",educationLevel:(u==null?void 0:u.educationLevel)||"",occupation:(u==null?void 0:u.occupation)||"",taxNumber:(u==null?void 0:u.taxNumber)||"",defaultLanguage:(u==null?void 0:u.defaultLanguage)||""}),_.reset({street:(u==null?void 0:u.street)||"",streetNumber:(u==null?void 0:u.streetNumber)||"",city:(u==null?void 0:u.city)||"",zip:(u==null?void 0:u.zip)||"",country:(u==null?void 0:u.country)||"",nationality:(u==null?void 0:u.nationality)||"",phonenumber:(u==null?void 0:u.phonenumber)||""}),D.kycRecords&&D.kycRecords.length>0&&D.kycRecords[0].providerTokenObject!==null&&!V.current&&z.current){console.log("[Identity] Review page disabled + existing identity — auto-requesting..."),V.current=!0;try{await E(),q(!0)}catch(h){console.error("[Identity] Auto-request failed:",h)}}}catch(D){console.error("Error loading applicant data:",D)}finally{f(!1)}})()},[t]),i.useEffect(()=>{y&&!O&&z.current&&(console.log("[Identity] Review page disabled — showing cached provider"),q(!0))},[y,O]),i.useEffect(()=>{if(g){if(g.expiresAt){const x=new Date(g.expiresAt).getTime();if(Date.now()>=x){console.warn("[Identity] Token has expired (expiresAt)"),se(!0),$("Your verification session has expired. Please restart.");return}}if(g.url)try{const D=new URL(g.url).toString().toLowerCase();if(D.includes("expired")||D.includes("invalid")||D.includes("error")){console.warn("[Identity] Token URL indicates expiration"),se(!0),$("Your verification link has expired. Please restart.");return}}catch{console.error("[Identity] Invalid token URL")}if(g.status==="expired"||g.error==="expired"||g.expired===!0){console.warn("[Identity] Token object indicates expiration"),se(!0),$("Your verification session has expired. Please restart.");return}}},[g]);const me=p!==null&&p===Ae.Sumsub;i.useEffect(()=>{if(p!==null&&g&&!k&&O&&!G){const x=p;if(me){console.log("[Sumsub] Fetching access token for Web SDK…"),$(null),(async()=>{try{const D=await o.refreshSumsubToken(t),K=_e.parseProviderConfig(p,g,c);K.accessToken=D,K.onTokenRefresh=()=>o.refreshSumsubToken(t);const H=_e.createProvider(p,K);H.onComplete(Z=>{console.log("[Sumsub] Verification complete:",Z),r==null||r()}),H.onError(Z=>{console.error("[Sumsub] SDK error:",Z),(typeof Z=="string"?Z:(Z==null?void 0:Z.message)||"Unknown error").toLowerCase().includes("expired")&&(se(!0),$("Session expired. Please restart."))}),await H.initialize("sumsub-websdk-container"),console.log("[Sumsub] Web SDK launched"),S(H)}catch(D){console.error("[Sumsub] Initialization error:",D),$(`Failed to initialize: ${D.message||D}`),String(D.message||D).toLowerCase().includes("expired")&&se(!0)}})();return}if(g.url){console.log("[Identity] Loading provider URL for user verification:",g.url),$(null);try{if(new URL(g.url),x===Ae.SardinAI){console.log("[SardinAI] Initializing Risk SDK in background...");try{const D=_e.parseProviderConfig(p,g,c);_e.createProvider(p,D).initialize().then(()=>console.log("[SardinAI] Risk SDK initialized in background")).catch(H=>console.warn("[SardinAI] Risk SDK init failed (non-blocking):",H))}catch(D){console.warn("[SardinAI] Risk SDK setup failed (non-blocking):",D)}}S({type:"url",url:g.url})}catch(D){console.error("[Identity] Invalid URL:",D),$("Invalid verification URL. Please restart."),se(!0)}return}if(x===Ae.SardinAI){console.log("[SardinAI] No URL provided - initializing Risk SDK only..."),$(null);try{const D=_e.parseProviderConfig(p,g,c),K=_e.createProvider(p,D);K.initialize().then(()=>{console.log("[SardinAI] Risk SDK initialized successfully"),S(K),setTimeout(()=>r==null?void 0:r(),2e3)}).catch(H=>{var m;console.error("[SardinAI] Failed to initialize:",H);const Z=((m=H.message)==null?void 0:m.toLowerCase())||"";Z.includes("expired")||Z.includes("invalid")||Z.includes("401")||Z.includes("400")?(se(!0),$("Session expired or invalid. Please restart verification.")):$(`Failed to initialize: ${H.message}`)})}catch(D){console.error("[SardinAI] Error creating provider:",D),$(`Configuration error: ${D.message}`)}return}try{$(null);const D=_e.parseProviderConfig(p,g,c),K=_e.createProvider(p,D);x===Ae.Onfido&&K.initialize("identity-container").catch(H=>{console.error("[Onfido] Initialization error:",H),$(`Failed to initialize: ${H.message}`)}),S(K)}catch(D){console.error("[Identity] Provider setup error:",D),$(`Setup error: ${D.message}`)}}return()=>{if(k&&k.destroy)try{k.destroy()}catch(x){console.error("[Identity] Error destroying provider:",x)}}},[p,g,k,O,r,G,me,t,c,o]);const N=async()=>{try{$(null),se(!1),await E(),q(!0)}catch(x){console.error("Error starting identity verification:",x)}},re=async()=>{try{$(null),se(!1),S(null),console.log("[Identity] Restarting verification..."),await A(),q(!0)}catch(x){console.error("Error restarting identity verification:",x),$(x.message||"Failed to restart verification")}};if(R||T)return e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-4",children:"Loading identity verification..."})]})});if(v)return e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("p",{className:"text-danger-500",children:["Error: ",v.message]})})});if(O&&(Q||G))return e.jsxs(ee,{children:[e.jsx(ge,{children:e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"Verification Session Issue"})}),e.jsxs(te,{children:[e.jsx("div",{className:"p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg mb-6",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("svg",{className:"h-6 w-6 text-red-600 dark:text-red-400 mr-3 mt-0.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-red-900 dark:text-red-100 mb-1",children:G?"Session Expired":"Verification Error"}),e.jsx("p",{className:"text-red-800 dark:text-red-200 text-sm",children:Q||"Your verification session has expired and needs to be restarted."})]})]})}),e.jsxs("div",{className:"bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-4",children:[e.jsx("h3",{className:"font-semibold text-blue-900 dark:text-blue-100 mb-2",children:"What to do next:"}),e.jsxs("ul",{className:"text-blue-800 dark:text-blue-200 text-sm space-y-1 list-disc list-inside",children:[e.jsx("li",{children:'Click "Restart Verification" below to generate a new session'}),e.jsx("li",{children:"Complete the verification process without delays"}),e.jsx("li",{children:"If issues persist, contact support"})]})]})]}),e.jsxs(be,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"button",onClick:re,disabled:T,children:T?"Restarting...":"Restart Verification"})]})]});if(O&&y){const x=p;return me?e.jsxs("div",{style:{background:"var(--metakyc-background, #ffffff)",borderRadius:"12px",border:"1px solid var(--metakyc-border, #e5e7eb)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"20px 24px",borderBottom:"1px solid var(--metakyc-border, #e5e7eb)"},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{margin:0,fontSize:"20px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)"},children:"Identity Verification"}),e.jsx("p",{style:{margin:"4px 0 0",fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)"},children:"Please complete the identity verification process"})]}),e.jsx("button",{type:"button",onClick:re,disabled:T,style:{padding:"6px 14px",fontSize:"13px",fontWeight:500,borderRadius:"8px",border:"1px solid var(--metakyc-border, #d1d5db)",background:"var(--metakyc-background, #ffffff)",color:"var(--metakyc-text-primary, #111827)",cursor:T?"not-allowed":"pointer",opacity:T?.5:1},children:T?"Restarting…":"Restart"})]}),e.jsx("div",{id:"sumsub-websdk-container",style:{minHeight:"520px",width:"100%",padding:"16px 24px",background:"var(--metakyc-background, #ffffff)"}}),s&&e.jsx("div",{style:{padding:"16px 24px",borderTop:"1px solid var(--metakyc-border, #e5e7eb)"},children:e.jsx(J,{variant:"outline",onClick:s,children:"Back"})})]}):g!=null&&g.url?e.jsxs(ee,{children:[e.jsx(ge,{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:re,disabled:T,children:"Restart"})]})}),e.jsxs(te,{children:[e.jsx("div",{className:"mb-4 p-3 bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg",children:e.jsxs("p",{className:"text-yellow-800 dark:text-yellow-200 text-sm",children:[e.jsx("strong",{children:"Important:"}),' If you see an "expired" or "invalid link" message below, click the "Restart" button above to generate a new verification session.']})}),e.jsx("div",{className:"w-full",style:{height:"600px"},children:e.jsx("iframe",{src:g.url,className:"w-full h-full border-0 rounded-lg",allow:"camera; microphone; geolocation",title:"Identity Verification",onLoad:D=>{var K,H,Z;console.log("[Identity] Iframe loaded");try{const m=D.target,C=m.contentDocument||((K=m.contentWindow)==null?void 0:K.document);if(C){const F=((Z=(H=C.body)==null?void 0:H.textContent)==null?void 0:Z.toLowerCase())||"";(F.includes("expired")||F.includes("invalid")||F.includes("error"))&&(console.warn("[Identity] Iframe shows expiration message"),se(!0),$("Your verification link has expired."))}}catch{console.log("[Identity] Cannot check iframe content (CORS)")}}})})]}),s&&e.jsx(be,{children:e.jsx(J,{variant:"outline",onClick:s,children:"Back"})})]}):x===Ae.SardinAI?e.jsxs(ee,{children:[e.jsxs(ge,{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Device Risk Assessment"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:"Analyzing device security and behavioral patterns..."})]}),e.jsx(te,{children:e.jsxs("div",{className:"text-center py-12",children:[e.jsx(Ee,{className:"mb-4"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Please wait while we verify your device security"}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-500 mt-2",children:"This process is automatic and will complete in a few seconds"})]})})]}):e.jsxs(ee,{children:[e.jsxs(ge,{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Identity Verification"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:"Please complete the identity verification process"})]}),e.jsx(te,{children:e.jsx("div",{id:"identity-container",className:"min-h-[400px]"})}),s&&e.jsx(be,{children:e.jsx(J,{variant:"outline",onClick:s,children:"Back"})})]})}const ue=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),ne=(x=4)=>{const D=Math.min(4,Math.max(1,Number(x)||4));return{gridColumn:`span ${D} / span ${D}`}},ve=(x,D)=>{if(!D&&D!==0)return"—";if(ue.has(x)&&x!=="mobileCountryCode"){const K=L.find(H=>H.value===D);return K?K.label:String(D)}return String(D)},Fe=({helpText:x})=>{const[D,K]=i.useState(!1),H=i.useRef(null),[,Z]=i.useState({top:0,left:0}),m=()=>{if(H.current){const C=H.current.getBoundingClientRect();Z({top:C.bottom+window.scrollY+6,left:C.left+window.scrollX})}K(!0)};return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"metakyc-help-btn",ref:H,onClick:m,style:{width:18,height:18,borderRadius:"50%",border:"1.5px solid var(--metakyc-primary, #2563eb)",background:"transparent",color:"var(--metakyc-primary, #2563eb)",fontSize:11,fontWeight:700,cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,lineHeight:1,position:"relative",zIndex:2},children:"?"}),D&&pt.createPortal(e.jsx("div",{style:{position:"fixed",inset:0,zIndex:99999,background:"rgba(0,0,0,0.55)",backdropFilter:"blur(6px)",WebkitBackdropFilter:"blur(6px)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:()=>K(!1),children:e.jsxs("div",{onClick:C=>C.stopPropagation(),style:{background:"var(--metakyc-surface, var(--metakyc-background, #ffffff))",border:"1px solid var(--metakyc-border, #e5e7eb)",borderRadius:"var(--metakyc-border-radius, 8px)",padding:"20px 24px",maxWidth:400,width:"90%",boxShadow:"0 24px 64px rgba(0,0,0,0.4)"},children:[e.jsx("div",{dangerouslySetInnerHTML:{__html:x},style:{fontSize:13,color:"var(--metakyc-text-primary, #111827)",lineHeight:1.6}}),e.jsx("button",{type:"button",onClick:()=>K(!1),style:{marginTop:12,padding:"4px 12px",fontSize:12,border:"1px solid var(--metakyc-border, #e5e7eb)",borderRadius:"var(--metakyc-border-radius, 6px)",background:"transparent",cursor:"pointer",color:"var(--metakyc-text-secondary, #6b7280)"},children:"Close"})]})}),document.body)]})},ke=(x,D)=>D?e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:5,flexWrap:"nowrap"},children:[e.jsx("div",{style:{flex:1,minWidth:0},children:x}),e.jsx("div",{style:{paddingTop:24},children:e.jsx(Fe,{helpText:D})})]}):x,Oe=(x,D)=>{const K=`cf-${D}`,H=x.paramName??"",Z=de[H];if(x.customType==="br")return e.jsx("div",{style:{...ne(x.colSpan),minHeight:"0.5rem"}},K);if(x.customType==="paragraph")return e.jsx("div",{style:ne(x.colSpan),children:e.jsx("div",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:x.label||""}})},K);if(x.customType==="html")return e.jsx("div",{style:ne(x.colSpan),dangerouslySetInnerHTML:{__html:x.label||""}},K);if(x.customType==="link")return e.jsx("div",{style:ne(x.colSpan),children:ke(e.jsx("a",{href:x.linkUrl??"#",target:"_blank",rel:"noopener noreferrer",className:"text-sm underline",style:{color:"var(--metakyc-primary, #6366f1)"},children:x.displayText||x.label||x.linkText||x.linkUrl}),x.helpText)},K);if(x.customType==="checkbox"||x.customType==="link_checkbox"){const m=Z==="true"||Z===!0;return e.jsx("div",{style:ne(x.colSpan),children:ke(e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:!!m,onChange:C=>fe(F=>({...F,[H]:String(C.target.checked)})),style:{width:16,height:16,flexShrink:0,marginTop:2,accentColor:"var(--metakyc-primary, #6366f1)"}}),e.jsx("span",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)"},children:x.customType==="link_checkbox"&&x.linkUrl?e.jsxs(e.Fragment,{children:[e.jsx("a",{href:x.linkUrl,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--metakyc-primary, #6366f1)",textDecoration:"underline"},children:x.linkText||x.label}),x.label&&x.linkText?` ${x.label}`:""]}):x.displayText||x.label})]}),x.helpText)},K)}if(x.customType==="group_checkbox"){const m=Array.isArray(Z)?Z:Z?[Z]:[],C=F=>{x.singleSelect?fe(u=>({...u,[H]:m[0]===F?[]:[F]})):fe(u=>({...u,[H]:m.includes(F)?m.filter(l=>l!==F):[...m,F]}))};return e.jsx("div",{style:ne(x.colSpan),children:ke(e.jsxs("div",{className:"space-y-1.5",children:[x.label&&e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:x.displayText||x.label}),(x.options||[]).map(F=>e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:m.includes(F.value),onChange:()=>C(F.value),style:{width:16,height:16,flexShrink:0,marginTop:2,accentColor:"var(--metakyc-primary, #6366f1)"}}),e.jsx("span",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)"},children:F.label})]},F.value))]}),x.helpText)},K)}return x.customType==="radio_group"?e.jsx("div",{style:ne(x.colSpan),children:ke(e.jsxs("div",{className:"space-y-1.5",children:[x.label&&e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:x.displayText||x.label}),(x.options||[]).map(m=>e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"radio",name:`rg-${H}`,value:m.value,checked:Z===m.value,onChange:()=>fe(C=>({...C,[H]:m.value})),style:{width:16,height:16,flexShrink:0,marginTop:2,accentColor:"var(--metakyc-primary, #6366f1)"}}),e.jsx("span",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)"},children:m.label})]},m.value))]}),x.helpText)},K):e.jsx("div",{style:ne(x.colSpan),children:ke(e.jsx(ye,{label:x.displayText||x.label||H,value:String(Z??""),onChange:m=>fe(C=>({...C,[H]:m.target.value}))}),x.helpText)},K)},Xe=(x,D)=>{if(x.isCustom)return Oe(x,D);const K=x.name??"",H=Qe[K],Z=x.displayText||(H==null?void 0:H.label)||K,m=he[K]??"",C=K==="mobileCountryCode",F=!!(H!=null&&H.countriesType)&&!C;return x.editable?C?e.jsx("div",{style:ne(x.colSpan??2),children:ke(e.jsx(Me,{label:Z,value:String(m),onChange:u=>ce(l=>({...l,[K]:u})),options:[{value:"",label:"Select country code…"},...U]}),x.helpText)},`epc-${D}`):F?e.jsx("div",{style:ne(x.colSpan??2),children:ke(e.jsx(Me,{label:Z,value:String(m),onChange:u=>ce(l=>({...l,[K]:u})),options:[{value:"",label:`Select ${Z.toLowerCase()}…`},...L]}),x.helpText)},`ec-${D}`):e.jsx("div",{style:ne(x.colSpan??2),children:ke(e.jsx(ye,{label:Z,type:(H==null?void 0:H.type)==="date"?"date":(H==null?void 0:H.type)==="email"?"email":"text",value:String(m),onChange:u=>ce(l=>({...l,[K]:u.target.value}))}),x.helpText)},`ei-${D}`):e.jsx("div",{style:ne(x.colSpan??2),children:ke(e.jsxs(e.Fragment,{children:[e.jsx("label",{className:"block text-sm font-medium mb-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:Z}),e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)",minHeight:"1.5rem"},children:ve(K,m)})]}),x.helpText)},`ro-${D}`)};if(I){const x=I.title||"Review Your Information",D=I.subtitle||"Please review and confirm your information before starting identity verification";return e.jsx("form",{onSubmit:K=>{K.preventDefault(),N()},children:e.jsxs(ee,{children:[e.jsxs(ge,{children:[e.jsx("h2",{className:"text-lg font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:x}),e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:D})]}),e.jsx(te,{children:e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:I.fields.map((K,H)=>Xe(K,H))})}),e.jsxs(be,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"submit",isLoading:T,children:"Confirm and Start Verification"})]})]})})}return e.jsx("form",{onSubmit:_.handleSubmit(N),children:e.jsxs(ee,{children:[e.jsxs(ge,{children:[e.jsx("h2",{className:"text-lg font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Review Your Information"}),e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Please review and confirm your information before starting identity verification"})]}),e.jsxs(te,{className:"space-y-6",children:[e.jsx("div",{className:"space-y-4 pb-4",style:{borderBottom:"1px solid var(--metakyc-border, #e5e7eb)"},children:[{label:"Name",value:`${((Ge=M==null?void 0:M.applicantRequestData)==null?void 0:Ge.firstName)||""} ${((ze=M==null?void 0:M.applicantRequestData)==null?void 0:ze.lastName)||""}`.trim()},{label:"Email",value:(et=M==null?void 0:M.applicantRequestData)==null?void 0:et.email},{label:"Date of Birth",value:((Ue=M==null?void 0:M.applicantRequestData)==null?void 0:Ue.dateOfBirth)||"Not provided"}].map(({label:x,value:D})=>e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:x}),e.jsx("p",{className:"mt-1 text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:D})]},x))}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Address Information"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(qe.Controller,{control:_.control,name:"country",render:({field:x})=>e.jsx(Me,{label:"Country",value:x.value,onChange:x.onChange,options:[{value:"",label:"Select country…"},...L]})}),e.jsx(qe.Controller,{control:_.control,name:"nationality",render:({field:x})=>e.jsx(Me,{label:"Nationality",value:x.value,onChange:x.onChange,options:[{value:"",label:"Select nationality…"},...L]})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(qe.Controller,{control:_.control,name:"street",render:({field:x})=>e.jsx(ye,{...x,label:"Street"})}),e.jsx(qe.Controller,{control:_.control,name:"streetNumber",render:({field:x})=>e.jsx(ye,{...x,label:"Street Number"})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(qe.Controller,{control:_.control,name:"city",render:({field:x})=>e.jsx(ye,{...x,label:"City"})}),e.jsx(qe.Controller,{control:_.control,name:"zip",render:({field:x})=>e.jsx(ye,{...x,label:"ZIP / Postal Code"})})]}),e.jsx(qe.Controller,{control:_.control,name:"phonenumber",render:({field:x})=>e.jsx(ye,{...x,label:"Phone Number",type:"tel"})})]})]}),e.jsxs(be,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"submit",isLoading:T,children:"Confirm and Start Verification"})]})]})})},ft=({kycStatus:t,reviewStatus:r,workflowResult:s,customMessage:n,onContinue:a,onContactSupport:o})=>{const d=t===Ve.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===Ve.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===Ve.Pending||t===Ve.InProgress?{type:"pending",title:"Verification Pending",icon:"⏱",iconBg:"bg-blue-100 dark:bg-blue-900/30",iconColor:"text-blue-600 dark:text-blue-400",message:"Your identity verification is currently being processed."}:r===Ye.Approved?{type:"success",title:"Application Approved",icon:"✓",iconBg:"bg-green-100 dark:bg-green-900/30",iconColor:"text-green-600 dark:text-green-400",message:"Your application has been approved."}:r===Ye.Reject?{type:"error",title:"Application Rejected",icon:"✕",iconBg:"bg-red-100 dark:bg-red-900/30",iconColor:"text-red-600 dark:text-red-400",message:"Your application has been rejected."}:r===Ye.UnderReview||r===Ye.AdminReview?{type:"pending",title:"Under Review",icon:"📋",iconBg:"bg-yellow-100 dark:bg-yellow-900/30",iconColor:"text-yellow-700 dark:text-yellow-400",message:"Your application is currently under manual review."}:s===ot.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===ot.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===ot.AdminReview?{type:"pending",title:"Admin Review Required",icon:"📋",iconBg:"bg-yellow-100 dark:bg-yellow-900/30",iconColor:"text-yellow-700 dark:text-yellow-400",message:"Your application requires administrator review."}:{type:"pending",title:"Processing",icon:"⏱",iconBg:"bg-blue-100 dark:bg-blue-900/30",iconColor:"text-blue-600 dark:text-blue-400",message:"Your application is being reviewed."};return e.jsxs(ee,{children:[e.jsxs(te,{className:"py-12",children:[e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx("div",{className:`w-24 h-24 rounded-full flex items-center justify-center ${d.iconBg}`,children:e.jsx("span",{className:`text-5xl ${d.iconColor}`,children:d.icon})})}),e.jsx("h2",{className:"text-3xl font-bold text-center mb-4",style:{color:"var(--metakyc-text-primary, #111827)"},children:d.title}),e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx(kt,{variant:d.type==="success"?"success":d.type==="error"?"danger":d.type==="pending"?"warning":"info",children:t!=null?Ve[t]:Ye[r]})}),e.jsx("p",{className:"text-center mb-6 max-w-md mx-auto",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:n||d.message}),d.type==="success"&&e.jsxs("div",{className:"bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg p-4 mb-6",children:[e.jsx("h3",{className:"font-semibold text-green-900 dark:text-green-100 mb-2",children:"What's Next?"}),e.jsxs("ul",{className:"text-sm text-green-800 dark:text-green-200 space-y-1",children:[e.jsx("li",{children:"✓ Your identity has been verified"}),e.jsx("li",{children:"✓ You can now proceed with your application"}),e.jsx("li",{children:"✓ All features are now accessible"})]})]}),d.type==="error"&&e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 mb-6",children:[e.jsx("h3",{className:"font-semibold text-red-900 dark:text-red-100 mb-2",children:"What Can You Do?"}),e.jsxs("ul",{className:"text-sm text-red-800 dark:text-red-200 space-y-2",children:[e.jsx("li",{children:"• Review the requirements and ensure all information is correct"}),e.jsx("li",{children:"• Contact our support team for assistance"}),e.jsx("li",{children:"• You may be able to resubmit your application"})]})]}),d.type==="pending"&&e.jsxs("div",{className:"bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-4 mb-6",children:[e.jsx("h3",{className:"font-semibold text-blue-900 dark:text-blue-100 mb-2",children:"What Happens Next?"}),e.jsxs("ul",{className:"text-sm text-blue-800 dark:text-blue-200 space-y-2",children:[e.jsx("li",{children:"• Our team is reviewing your information"}),e.jsx("li",{children:"• You will be notified via email once the review is complete"}),e.jsx("li",{children:"• This typically takes 24-48 hours"}),e.jsx("li",{children:"• No action is required from you at this time"})]})]}),e.jsx("div",{className:"mt-6 pt-6",style:{borderTop:"1px solid var(--metakyc-border, #e5e7eb)"},children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"KYC Status:"}),e.jsx("div",{className:"font-medium mt-1",style:{color:"var(--metakyc-text-primary, #111827)"},children:t!=null?Ve[t]:"Not Available"})]}),e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"Review Status:"}),e.jsx("div",{className:"font-medium mt-1",style:{color:"var(--metakyc-text-primary, #111827)"},children:Ye[r]})]})]})})]}),e.jsxs(be,{style:{display:"flex",justifyContent:"center",gap:"1rem"},children:[d.type==="success"&&a&&e.jsx(J,{onClick:a,size:"lg",children:"Continue"}),d.type==="error"&&e.jsxs(e.Fragment,{children:[o&&e.jsx(J,{variant:"outline",onClick:o,children:"Contact Support"}),a&&e.jsx(J,{onClick:a,children:"Try Again"})]}),d.type==="pending"&&e.jsx("div",{className:"text-center",children:e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Please check back later or wait for our email notification"})})]})]})},Wr=({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"}})}),nt=({title:t,subtitle:r,className:s=""})=>{const{currentTheme:n}=Ne(),a=t||(n==null?void 0:n.title)||"",o=!!(n!=null&&n.logo&&n.logo.visible&&n.logo.url),c=!!a;return!o&&!c?null:e.jsxs("div",{className:`metakyc-header ${s}`,children:[e.jsxs("div",{className:"metakyc-header-title flex items-center text-xl font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:[o&&e.jsx(Wr,{config:n.logo}),o&&c&&e.jsx("span",{style:{fontSize:"1.5rem",fontWeight:300,color:"var(--metakyc-text-muted, #9ca3af)",margin:"0 12px"},children:"|"}),c&&e.jsx("span",{style:{color:"var(--metakyc-text-primary, #111827)"},children:a})]}),r&&e.jsx("p",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:r})]})},dt=["firstName","lastName","email","phonenumber","dateOfBirth"];function tt(t){return t==null||t===""||Array.isArray(t)&&t.length===0}const it={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"},It=({helpText:t,children:r})=>{const[s,n]=i.useState(!1);if(!t)return e.jsx(e.Fragment,{children:r});const a=s?e.jsx("div",{role:"dialog","aria-modal":"true",onClick:()=>n(!1),style:{position:"fixed",inset:0,zIndex:999999,background:"rgba(0, 0, 0, 0.55)",backdropFilter:"blur(6px)",WebkitBackdropFilter:"blur(6px)",display:"flex",alignItems:"center",justifyContent:"center",padding:"16px"},children:e.jsxs("div",{onClick: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:()=>n(!1),"aria-label":"Close",style:{position:"absolute",top:"12px",right:"12px",width:"28px",height:"28px",borderRadius:"50%",border:"1px solid var(--metakyc-border, #e5e7eb)",background:"var(--metakyc-input-bg, #f3f4f6)",color:"var(--metakyc-text-secondary, #6b7280)",fontSize:"16px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:"×"}),e.jsx("div",{style:{color:"var(--metakyc-text-primary, #111827)",fontSize:"14px",lineHeight:1.75},dangerouslySetInnerHTML:{__html:t}})]})}):null;return e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"5px",flexWrap:"nowrap"},children:[r,e.jsx("button",{type:"button",className:"metakyc-help-btn",onClick:()=>n(!0),"aria-label":"Help",style:{flexShrink:0,marginTop:"2px",width:"18px",height:"18px",borderRadius:"50%",border:"1.5px solid var(--metakyc-primary, #2563eb)",background:"transparent",color:"var(--metakyc-primary, #2563eb)",fontSize:"10px",fontWeight:"700",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,padding:0,position:"relative",zIndex:2,transition:"background 0.15s, color 0.15s"},onMouseEnter: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"&&a?pt.createPortal(a,document.body):null]})},As=({workflowKey:t,externalRefId:r,onSuccess:s,onCancel:n})=>{var K,H,Z,m,C,F,u;const{config:a,baseInformationService:o,currentTheme:c}=Ne(),{createApplicant:d,isLoading:y}=vt(),p=t||((K=a.applicantForm)==null?void 0:K.workflowKey);if(!p)throw new Error("workflowKey is required. Provide it either as a prop to CreateApplicantForm or set it in config.applicantForm.workflowKey");const g=r||((H=a.applicantForm)==null?void 0:H.externalRefId)||"",T=((Z=a.applicantForm)==null?void 0:Z.email)||"",v=((m=a.applicantForm)==null?void 0:m.hiddenValues)||{},E=((C=a.applicantForm)==null?void 0:C.initialValues)||{},k=(((F=a.applicantForm)==null?void 0:F.fieldLabelMode)||(c==null?void 0:c.fieldLabelMode)||"label")!=="placeholder",S=i.useMemo(()=>c!=null&&c.applicantFormPages&&c.applicantFormPages.length>0?c.applicantFormPages:null,[c==null?void 0:c.applicantFormPages]),M=i.useMemo(()=>{const l=new Set(dt),h=c==null?void 0:c.applicantFormRequiredFields;if(h)for(const P of h)l.add(P);if(S)for(const P of S)for(const b of P.fields)!b.isCustom&&b.name&&b.required&&l.add(b.name);return Array.from(l)},[c==null?void 0:c.applicantFormRequiredFields,S]),Y=i.useMemo(()=>{var P;if(S){const b=S.flatMap(j=>j.fields).filter(j=>!j.isCustom&&j.name).map(j=>j.name),w=new Set(b);for(const j of dt)w.add(j);return Array.from(w)}let l;(P=a.applicantForm)!=null&&P.visibleFields?l=a.applicantForm.visibleFields:c!=null&&c.applicantFormVisibleFields&&c.applicantFormVisibleFields.length>0?l=c.applicantFormVisibleFields:l=Ht;const h=new Set(l);for(const b of dt)h.add(b);return Array.from(h)},[(u=a.applicantForm)==null?void 0:u.visibleFields,c==null?void 0:c.applicantFormVisibleFields,S]),L=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),B=i.useMemo(()=>{var h,P;const l=new Set;if(S)for(const b of S)for(const w of b.fields)!w.isCustom&&w.name&&L.has(w.name)&&l.add(w.countriesType??((h=Qe[w.name])==null?void 0:h.countriesType));else for(const b of Y)L.has(b)&&l.add((P=Qe[b])==null?void 0:P.countriesType);return l.size===0&&l.add(void 0),Array.from(l)},[Y,S]),[U,X]=i.useState({}),[R,f]=i.useState(!0),O=i.useRef(new Set),q=i.useRef(new Set);i.useEffect(()=>{if(!c)return;const l=B.filter(b=>{const w=b!=null?String(b):"all";return!q.current.has(w)&&!O.current.has(w)});if(l.length===0){B.every(w=>{const j=w!=null?String(w):"all";return q.current.has(j)})&&f(!1);return}f(!0);const h=l.map(b=>b!=null?String(b):"all");h.forEach(b=>O.current.add(b)),(async()=>{try{const b=await Promise.all(l.map(async w=>{const j=w!=null?String(w):"all",le=await o.getCountries("",a.locale||"en",w),ae=w===40,xe=new Set,Ie=le.map(ie=>ae&&ie.countryCode?{value:ie.countryCode,label:`${ie.countryCode} – ${ie.name}`}:{value:ie.abbreviation3||ie.abbreviation,label:ie.name}).filter(ie=>!ie.value||xe.has(ie.value)?!1:(xe.add(ie.value),!0));return q.current.add(j),O.current.delete(j),[j,Ie]}));X(w=>({...w,...Object.fromEntries(b)}))}catch(b){h.forEach(w=>O.current.delete(w)),console.error("Failed to load countries:",b)}finally{B.every(w=>{const j=w!=null?String(w):"all";return q.current.has(j)})&&f(!1)}})()},[B,c]);const Q=(l,h)=>{var w;const P=h??((w=Qe[l])==null?void 0:w.countriesType),b=P!=null?String(P):"all";return U[b]||[]},$={firstName:1,lastName:1,title:1,email:1,dateOfBirth:1,phonenumber:1,mobileCountryCode:1,street:1,streetNumber:1,zip:1,city:1,country:1,nationality:1,otherNationality:1,defaultLanguage:1,taxCountry:1,placeOfBirth:1,countryOfBirth:1,salutation:1,educationLevel:1,occupation:1,taxNumber:1},G=Object.fromEntries(Object.entries(v).filter(([l])=>l in $)),se=Object.fromEntries(Object.entries(E).filter(([l])=>l in $)),[V,he]=i.useState({workflowKey:p,firstName:"",lastName:"",title:"",email:T,dateOfBirth:"",phonenumber:"",externalRefId:g,mobileCountryCode:"",street:"",streetNumber:"",zip:"",city:"",country:"",nationality:"",otherNationality:[],defaultLanguage:"EN",taxCountry:"",placeOfBirth:"",countryOfBirth:"",salutation:null,educationLevel:"",occupation:"",taxNumber:"",...G,...se}),ce=Object.fromEntries(Object.entries(v).filter(([l])=>!(l in G)&&l!=="externalRefId"&&l!=="workflowKey")),[de,fe]=i.useState({...ce}),[I,W]=i.useState(0),[z,_]=i.useState({}),[me,N]=i.useState(null),[re,ue]=i.useState(!1),ne=(l,h)=>he(P=>({...P,[l]:h})),ve=(l,h)=>fe(P=>({...P,[l]:h})),Fe=l=>!l.conditionalOn||de[l.conditionalOn]==="true",ke=S&&I<S.length-1?I+1:-1,Oe=S&&I>0?I-1:-1,Xe=l=>{var P;const h={};for(const b of l.fields)if(b.isCustom){if(b.customType==="paragraph"||b.customType==="html"||b.customType==="br"||b.customType==="link")continue;if(b.required&&b.paramName){const w=de[b.paramName],j=b.displayText||b.label||b.paramName;b.customType==="checkbox"||b.customType==="link_checkbox"?w!=="true"&&(h[b.paramName]=`${j} is required.`):(!w||w.trim()==="")&&(h[b.paramName]=`${j} is required.`)}}else if(b.name){const w=b.name;if(M.includes(w)&&tt(V[w])){const j=b.displayText||((P=Qe[w])==null?void 0:P.label)||w;h[w]=`${j} is required.`}}return h},Ge=async()=>{if(!S)return;const l=S[I];if(l.conditionalOn&&!Fe(l)){_({}),ke>=0?W(ke):await ze();return}const h=Xe(l);if(Object.keys(h).length>0){_(h);return}_({}),ke>=0?W(ke):await ze()},ze=async()=>{if(S){let l={};for(const h of S)Fe(h)&&(l={...l,...Xe(h)});if(Object.keys(l).length>0){_(l);return}}ue(!0),N(null);try{if(!V.externalRefId||V.externalRefId.trim()===""){N("External Reference ID is required. Please pass it via config.applicantForm.externalRefId.");return}const l={workflowKey:V.workflowKey,externalRefId:V.externalRefId.trim()};if(S){for(const w of S)if(Fe(w)){for(const j of w.fields)if(!j.isCustom&&j.name){const le=j.name,ae=V[le];tt(ae)||(l[le]=ae)}}for(const w of dt)if(l[w]===void 0){const j=V[w];tt(j)||(l[w]=j)}}else Y.forEach(w=>{if(w==="externalRefId")return;const j=V[w];tt(j)||(l[w]=j)});const h=[];if(S){for(const w of S)if(Fe(w))for(const j of w.fields){if(!j.isCustom||!j.paramName||j.customType==="paragraph"||j.customType==="html"||j.customType==="br"||j.customType==="link")continue;const le=de[j.paramName]??"";let ae;if(j.customType==="checkbox"||j.customType==="link_checkbox")ae=le==="true"?"yes":"no";else if(ae=le,!ae&&!j.required)continue;h.push({paramName:j.paramName,value:ae})}}for(const[w,j]of Object.entries(G))l[w]===void 0&&!tt(j)&&(l[w]=j);const P=new Set(h.map(w=>w.paramName));for(const[w,j]of Object.entries(ce))!P.has(w)&&j&&h.push({paramName:w,value:j});h.length>0&&(l.applicantAdditionalDatas=h);const b=await d(l);s(b.applicantId)}catch(l){console.error("Error creating applicant:",l),N(l.message||"Failed to create applicant")}finally{ue(!1)}},et=async l=>{var h;l.preventDefault();for(const P of M)if(tt(V[P])){const b=((h=Qe[P])==null?void 0:h.label)||P;N(`${b} is required.`);return}await ze()},Ue=(l,h,P,b,w)=>{var jt;const j=Qe[l];if(!j)return null;const le=M.includes(l),ae=z[l],xe=P||j.label,Ie=l in se,ie=h??l,Pe={required:le},$e=w?w!=="placeholder":k,Ke=$e?xe:void 0,Ur=$e?"...":xe;switch(j.type){case"select":if(l==="country"||l==="nationality"||l==="taxCountry"||l==="countryOfBirth"||l==="mobileCountryCode"){const Ce=Q(l,b);return e.jsx(Me,{...Pe,label:Ke,value:V[l]||"",onChange:Je=>ne(l,Je),options:[{value:"",label:`Select ${Ur.toLowerCase()}`},...Ce],disabled:R,readOnly:Ie,error:ae},ie)}if(l==="salutation")return e.jsx(Me,{...Pe,label:Ke,value:((jt=V[l])==null?void 0:jt.toString())||"",onChange:Ce=>ne(l,Ce?Number(Ce):null),options:[{value:"",label:$e?"Select salutation...":xe},{value:lt.Male.toString(),label:"Male"},{value:lt.Female.toString(),label:"Female"},{value:lt.Other.toString(),label:"Other"}],readOnly:Ie,error:ae},ie);if(l==="defaultLanguage"){const Ce=c!=null&&c.allowedLanguages&&c.allowedLanguages.length>0?ht.filter(Je=>c.allowedLanguages.includes(Je.value)):ht;return e.jsx(Me,{...Pe,label:Ke,value:V[l]||"",onChange:Je=>ne(l,Je),options:[{value:"",label:$e?"Select language...":xe},...Ce],readOnly:Ie,error:ae},ie)}return null;case"multiselect":if(l==="otherNationality"){const Ce=Q(l,b);return e.jsx(Er,{...Pe,label:Ke,value:V[l]||[],onChange:Je=>ne(l,Je),options:Ce,placeholder:$e?"Select other nationalities...":xe,disabled:R,readOnly:Ie},ie)}return null;case"date":return e.jsx(ye,{...Pe,type:"date",label:Ke,placeholder:$e?void 0:xe,value:V[l]||"",onChange:Ce=>ne(l,Ce.target.value),readOnly:Ie,error:ae},ie);case"email":return e.jsx(ye,{...Pe,type:"email",label:Ke,placeholder:$e?void 0:xe,value:V[l]||"",onChange:Ce=>ne(l,Ce.target.value),readOnly:Ie,error:ae},ie);case"tel":return e.jsx(ye,{...Pe,type:"tel",label:Ke,placeholder:$e?void 0:xe,value:V[l]||"",onChange:Ce=>ne(l,Ce.target.value),readOnly:Ie,error:ae},ie);default:return e.jsx(ye,{...Pe,type:"text",label:Ke,placeholder:$e?void 0:xe,value:V[l]||"",onChange:Ce=>ne(l,Ce.target.value),readOnly:Ie,error:ae},ie)}},x=(l,h)=>{const P=l.labelMode?l.labelMode!=="placeholder":k;if(l.customType==="paragraph"){const j=l.displayText||l.label||"";return e.jsx("p",{className:"metakyc-paragraph",style:{fontSize:"14px",lineHeight:"1.7",margin:0,color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:j}},`custom-${h}`)}if(l.customType==="html")return e.jsx("div",{dangerouslySetInnerHTML:{__html:l.label||""}},`custom-${h}`);if(l.customType==="br")return e.jsx("div",{style:{height:"12px"}},`custom-${h}`);if(l.customType==="link"){const j=l.displayText||l.label||l.linkText||l.linkUrl||"";return e.jsx("div",{className:"metakyc-link-field",children:e.jsxs("a",{href:l.linkUrl||"#",target:"_blank",rel:"noopener noreferrer",style:{display:"inline-flex",alignItems:"center",gap:"4px",color:"var(--metakyc-primary, #2563eb)",fontSize:"14px",textDecoration:"underline",cursor:"pointer"},children:[j,e.jsx("span",{style:{fontSize:"10px",opacity:.7},children:"↗"})]})},`custom-${h}`)}if(!l.paramName)return null;const b=z[l.paramName],w=l.displayText||l.label||l.paramName;if(l.customType==="checkbox")return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"checkbox",checked:de[l.paramName]==="true",onChange:j=>ve(l.paramName,j.target.checked?"true":"false"),className:"metakyc-option-input",style:it}),e.jsxs("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:[w,l.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),b&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:b})]},`custom-${h}`);if(l.customType==="link_checkbox")return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"checkbox",checked:de[l.paramName]==="true",onChange:j=>ve(l.paramName,j.target.checked?"true":"false"),className:"metakyc-option-input",style:{...it,alignSelf:"flex-start",marginTop:"2px"}}),e.jsxs("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:[w," ",l.linkUrl&&e.jsx("a",{href:l.linkUrl,target:"_blank",rel:"noopener noreferrer",className:"underline",style:{color:"var(--metakyc-primary, #2563eb)"},onClick:j=>j.stopPropagation(),children:l.linkText||l.linkUrl}),l.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),b&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:b})]},`custom-${h}`);if(l.customType==="group_checkbox"){const j=(de[l.paramName]||"").split(",").filter(Boolean);return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[P&&e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[w,l.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]}),e.jsx("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:(l.options||[]).map(le=>{const ae=l.singleSelect?de[l.paramName]===le.value:j.includes(le.value);return e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"checkbox",checked:ae,onChange:xe=>{if(l.singleSelect)ve(l.paramName,xe.target.checked?le.value:"");else{const Ie=xe.target.checked?[...j,le.value]:j.filter(ie=>ie!==le.value);ve(l.paramName,Ie.join(","))}},className:"metakyc-option-input",style:it}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:le.label})]},le.value)})}),b&&e.jsx("p",{className:"text-red-500 text-xs",children:b})]},`custom-${h}`)}return l.customType==="radio_group"?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[P&&e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[w,l.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]}),e.jsx("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:(l.options||[]).map(j=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"radio",checked:de[l.paramName]===j.value,onChange:()=>ve(l.paramName,j.value),name:`radio-group-${l.paramName}-${h}`,className:"metakyc-option-input",style:it}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:j.label})]},j.value))}),b&&e.jsx("p",{className:"text-red-500 text-xs",children:b})]},`custom-${h}`):e.jsx(ye,{type:"text",label:P?`${w}${l.required?" *":""}`:void 0,placeholder:P?void 0:w,value:de[l.paramName]||"",onChange:j=>ve(l.paramName,j.target.value),required:l.required,error:b},`custom-${h}`)},D=(l,h)=>{const P=Fe(l);return e.jsxs("div",{className:"space-y-4",children:[l.conditionalOn&&e.jsx(It,{helpText:l.conditionalHelpText,children:e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"checkbox",checked:P,onChange:b=>ve(l.conditionalOn,b.target.checked?"true":"false"),className:"metakyc-option-input",style:it}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",fontWeight:500},children:l.conditionalOn})]})}),P&&e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:l.fields.map((b,w)=>{const j=Math.min(4,Math.max(1,Number(b.colSpan)||4)),le=b.isCustom?`custom-${w}-${b.paramName}`:`builtin-${b.name}-${w}`;return e.jsx("div",{style:{gridColumn:`span ${j} / span ${j}`},children:e.jsx(It,{helpText:b.helpText,children:b.isCustom?x(b,w):Ue(b.name,le,b.displayText,b.countriesType,b.labelMode)})},le)})})]})};if(!c||R)return e.jsx("div",{className:"metakyc-sdk",children:e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)",fontSize:"0.875rem"},children:"Loading form…"})]})})});if(S){const l=S[I]??S[0],h=Oe===-1,P=ke===-1,b=S.length,w=Fe(l),j=Object.values(z);return e.jsx("div",{className:"metakyc-sdk",children:e.jsxs(ee,{children:[e.jsx(ge,{children:e.jsx(nt,{title:(c==null?void 0:c.title)||"Create Applicant"})}),e.jsxs(te,{children:[(l.title||l.subtitle||l.description)&&e.jsxs("div",{className:"mb-4",children:[l.title&&e.jsx("h3",{className:"font-semibold text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:l.title}),l.subtitle&&e.jsx("p",{className:"text-sm mt-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:l.subtitle}),l.description&&l.description!==l.subtitle&&e.jsx("p",{className:"text-xs mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:l.description})]}),(me||j.length>0)&&e.jsxs("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-lg",children:[me&&e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",me]}),j.map((le,ae)=>e.jsx("p",{className:"text-red-600 text-sm",children:le},ae))]}),b>1&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem",marginBottom:"1rem"},children:[S.map((le,ae)=>e.jsx("div",{style:{height:"0.375rem",borderRadius:"9999px",transition:"all 150ms",...ae===I?{flex:"1 1 0%",backgroundColor:"var(--metakyc-primary, #2563eb)"}:ae<I?{width:"2rem",backgroundColor:"var(--metakyc-primary-light, #93c5fd)",opacity:.7}:{width:"2rem",backgroundColor:"#e5e7eb"}}},ae)),e.jsxs("span",{style:{fontSize:"0.75rem",color:"var(--metakyc-text-muted, #9ca3af)",flexShrink:0},children:[I+1," / ",b]})]}),D(l)]}),e.jsxs(be,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{children:[!h&&e.jsx(J,{type:"button",variant:"outline",onClick:()=>{W(Oe),_({})},disabled:re||y,children:"Previous"}),h&&n&&e.jsx(J,{type:"button",variant:"outline",onClick:n,disabled:re||y,children:"Cancel"})]}),e.jsx(J,{type:"button",isLoading:re||y,onClick:P?ze:Ge,children:P?l.conditionalOn&&!w?"Skip & Submit":"Submit":l.conditionalOn&&!w?"Skip":"Next"})]})]})})}return e.jsx("div",{className:"metakyc-sdk",children:e.jsx("form",{onSubmit:et,children:e.jsxs(ee,{children:[e.jsx(ge,{children:e.jsx(nt,{title:(c==null?void 0:c.title)||"Create Applicant"})}),e.jsxs(te,{children:[me&&e.jsx("div",{className:"mb-6 p-4 bg-red-50 border border-red-200 rounded-lg",children:e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",me]})}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:Y.map(l=>e.jsx("div",{style:{gridColumn:"span 4 / span 4"},children:Ue(l)},l))})]}),e.jsxs(be,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[n&&e.jsx(J,{type:"button",variant:"outline",onClick:n,disabled:re||y,children:"Cancel"}),e.jsx(J,{type:"submit",isLoading:re||y,children:"Create Applicant"})]})]})})})},Et=["companyName","email"];function xt(t){return t==null||t===""||Array.isArray(t)&&t.length===0}const Ts=({workflowKey:t,externalRefId:r,onSuccess:s,onCancel:n})=>{var Ue,x,D,K,H,Z;const{config:a,baseInformationService:o,currentTheme:c}=Ne(),{createCompanyApplicant:d,isLoading:y}=vt(),p=t||((Ue=a.applicantForm)==null?void 0:Ue.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 g=r||((x=a.applicantForm)==null?void 0:x.externalRefId)||"",T=((D=a.applicantForm)==null?void 0:D.email)||"",v=((K=a.applicantForm)==null?void 0:K.initialValues)||{},A=(((H=a.applicantForm)==null?void 0:H.fieldLabelMode)||(c==null?void 0:c.fieldLabelMode)||"label")!=="placeholder",k=i.useMemo(()=>c!=null&&c.companyFormPages&&c.companyFormPages.length>0?c.companyFormPages:null,[c==null?void 0:c.companyFormPages]),S=i.useMemo(()=>{const m=new Set(Et),C=c==null?void 0:c.companyFormRequiredFields;if(C)for(const F of C)m.add(F);if(k)for(const F of k)for(const u of F.fields)!u.isCustom&&u.name&&u.required&&m.add(u.name);return Array.from(m)},[c==null?void 0:c.companyFormRequiredFields,k]),M=i.useMemo(()=>{var m;if(k){const C=k.flatMap(u=>u.fields).filter(u=>!u.isCustom&&u.name).map(u=>u.name),F=new Set(C);for(const u of Et)F.add(u);return Array.from(F)}return(m=a.applicantForm)!=null&&m.visibleFields?a.applicantForm.visibleFields:c!=null&&c.companyFormVisibleFields&&c.companyFormVisibleFields.length>0?c.companyFormVisibleFields:_t},[(Z=a.applicantForm)==null?void 0:Z.visibleFields,c==null?void 0:c.companyFormVisibleFields,k]),Y=new Set(["countryResidence","addressCountry"]),L=i.useMemo(()=>{var C,F;const m=new Set;if(k)for(const u of k)for(const l of u.fields)!l.isCustom&&l.name&&Y.has(l.name)&&m.add(l.countriesType??((C=Ze[l.name])==null?void 0:C.countriesType));else for(const u of M)Y.has(u)&&m.add((F=Ze[u])==null?void 0:F.countriesType);return m.size===0&&m.add(void 0),Array.from(m)},[M,k]),[B,U]=i.useState({}),[X,R]=i.useState(!0),f=i.useRef(new Set),O=i.useRef(new Set);i.useEffect(()=>{if(!c)return;const m=L.filter(u=>{const l=u!=null?String(u):"all";return!O.current.has(l)&&!f.current.has(l)});if(m.length===0){L.every(l=>O.current.has(l!=null?String(l):"all"))&&R(!1);return}R(!0);const C=m.map(u=>u!=null?String(u):"all");C.forEach(u=>f.current.add(u)),(async()=>{try{const u=await Promise.all(m.map(async l=>{const h=l!=null?String(l):"all",P=await o.getCountries("",a.locale||"en",l),b=new Set,w=P.map(j=>({value:j.abbreviation3||j.abbreviation,label:j.name})).filter(j=>!j.value||b.has(j.value)?!1:(b.add(j.value),!0));return O.current.add(h),f.current.delete(h),[h,w]}));U(l=>({...l,...Object.fromEntries(u)}))}catch(u){C.forEach(l=>f.current.delete(l)),console.error("Failed to load countries:",u)}finally{L.every(l=>O.current.has(l!=null?String(l):"all"))&&R(!1)}})()},[L,c]);const q=(m,C)=>{var l;const F=C??((l=Ze[m])==null?void 0:l.countriesType),u=F!=null?String(F):"all";return B[u]||[]},Q={companyName:1,registrationNumber:1,email:1,phone:1,countryResidence:1,legalAddress:1,incorporatedOn:1,controlScheme:1,taxId:1,registrationLocation:1,website:1,postalAddress:1,street:1,streetNumber:1,city:1,state:1,postalCode:1,addressCountry:1,lei:1},$=Object.fromEntries(Object.entries(v).filter(([m])=>m in Q)),[G,se]=i.useState({workflowKey:p,companyName:"",email:T,phone:"",registrationNumber:"",countryResidence:"",legalAddress:"",incorporatedOn:"",controlScheme:"",taxId:"",registrationLocation:"",website:"",postalAddress:"",street:"",streetNumber:"",city:"",state:"",postalCode:"",addressCountry:"",lei:"",externalRefId:g,...$}),[V,he]=i.useState({}),[ce,de]=i.useState(0),[fe,I]=i.useState({}),[W,z]=i.useState(null),[_,me]=i.useState(!1),N=(m,C)=>se(F=>({...F,[m]:C})),re=(m,C)=>he(F=>({...F,[m]:C})),ue=m=>!m.conditionalOn||V[m.conditionalOn]==="true",ne=k&&ce<k.length-1?ce+1:-1,ve=k&&ce>0?ce-1:-1,Fe=m=>{var F;const C={};for(const u of m.fields)if(u.isCustom){if(u.customType==="paragraph"||u.customType==="html"||u.customType==="br"||u.customType==="link")continue;if(u.required&&u.paramName){const l=V[u.paramName],h=u.displayText||u.label||u.paramName;u.customType==="checkbox"||u.customType==="link_checkbox"?l!=="true"&&(C[u.paramName]=`${h} is required.`):(!l||l.trim()==="")&&(C[u.paramName]=`${h} is required.`)}}else if(u.name){const l=u.name;if(S.includes(l)&&xt(G[l])){const h=u.displayText||((F=Ze[l])==null?void 0:F.label)||l;C[l]=`${h} is required.`}}return C},ke=async()=>{if(!k)return;const m=k[ce];if(m.conditionalOn&&!ue(m)){I({}),ne>=0?de(ne):await Oe();return}const C=Fe(m);if(Object.keys(C).length>0){I(C);return}I({}),ne>=0?de(ne):await Oe()},Oe=async()=>{var m;if(k){let C={};for(const F of k)ue(F)&&(C={...C,...Fe(F)});if(Object.keys(C).length>0){I(C);return}}me(!0),z(null);try{const C={workflowKey:G.workflowKey,externalRefId:((m=G.externalRefId)==null?void 0:m.trim())||void 0},F=k?k.filter(h=>ue(h)).flatMap(h=>h.fields).filter(h=>!h.isCustom&&h.name).map(h=>h.name):M;for(const h of F){const P=G[h];if(!xt(P))switch(h){case"companyName":C.companyName=P;break;case"email":C.companyEmail=P;break;case"phone":C.companyPhone=P;break;case"registrationNumber":C.companyRegistrationNumber=P;break;case"countryResidence":C.companyCountry=P;break;case"city":C.companyCity=P;break;case"street":C.companyStreet=P;break;case"postalCode":C.companyZip=P;break;default:C[h]=P;break}}const u=[];if(k){for(const h of k)if(ue(h))for(const P of h.fields){if(!P.isCustom||!P.paramName||P.customType==="paragraph"||P.customType==="html"||P.customType==="br"||P.customType==="link")continue;const b=V[P.paramName]??"";let w;if(P.customType==="checkbox"||P.customType==="link_checkbox")w=b==="true"?"yes":"no";else if(w=b,!w&&!P.required)continue;u.push({paramName:P.paramName,value:w})}}u.length>0&&(C.applicantAdditionalDatas=u);const l=await d(C);s(l.applicantId)}catch(C){console.error("Error creating company applicant:",C),z(C.message||"Failed to create company applicant")}finally{me(!1)}},Xe=async m=>{var C;m.preventDefault();for(const F of S)if(xt(G[F])){const u=((C=Ze[F])==null?void 0:C.label)||F;z(`${u} is required.`);return}await Oe()},Ge=(m,C,F,u,l)=>{const h=Ze[m];if(!h)return null;const P=S.includes(m),b=fe[m],w=F||h.label,j=m in $,le=C??m,ae=l?l!=="placeholder":A,xe=ae?w:void 0,Ie=ae?"...":w;switch(h.type){case"select":if(m==="countryResidence"||m==="addressCountry"){const ie=q(m,u);return e.jsx(Me,{required:P,label:xe,value:G[m]||"",onChange:Pe=>N(m,Pe),options:[{value:"",label:`Select ${Ie.toLowerCase()}`},...ie],disabled:X,readOnly:j,error:b},le)}return null;case"date":return e.jsx(ye,{required:P,type:"date",label:xe,placeholder:ae?void 0:w,value:G[m]||"",onChange:ie=>N(m,ie.target.value),readOnly:j,error:b},le);case"email":return e.jsx(ye,{required:P,type:"email",label:xe,placeholder:ae?void 0:w,value:G[m]||"",onChange:ie=>N(m,ie.target.value),readOnly:j,error:b},le);case"tel":return e.jsx(ye,{required:P,type:"tel",label:xe,placeholder:ae?void 0:w,value:G[m]||"",onChange:ie=>N(m,ie.target.value),readOnly:j,error:b},le);default:return e.jsx(ye,{required:P,type:"text",label:xe,placeholder:ae?void 0:w,value:G[m]||"",onChange:ie=>N(m,ie.target.value),readOnly:j,error:b},le)}},ze=(m,C)=>{if(m.customType==="paragraph")return e.jsx("p",{style:{fontSize:"14px",lineHeight:"1.7",margin:0,color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:m.displayText||m.label||""}},`custom-${C}`);if(m.customType==="html")return e.jsx("div",{dangerouslySetInnerHTML:{__html:m.label||""}},`custom-${C}`);if(m.customType==="br")return e.jsx("div",{style:{height:"12px"}},`custom-${C}`);if(m.customType==="link")return e.jsx("div",{children:e.jsx("a",{href:m.linkUrl||"#",target:"_blank",rel:"noopener noreferrer",style:{color:"var(--metakyc-primary, #2563eb)",fontSize:"14px",textDecoration:"underline"},children:m.displayText||m.label||m.linkText||m.linkUrl||""})},`custom-${C}`);if(!m.paramName)return null;const F=fe[m.paramName],u=m.displayText||m.label||m.paramName,l=m.labelMode?m.labelMode!=="placeholder":A;return m.customType==="checkbox"?e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:V[m.paramName]==="true",onChange:h=>re(m.paramName,h.target.checked?"true":"false"),style:{width:"16px",height:"16px",accentColor:"var(--metakyc-primary, #2563eb)"}}),e.jsxs("span",{style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)"},children:[u,m.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),F&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:F})]},`custom-${C}`):e.jsx(ye,{type:"text",label:l?`${u}${m.required?" *":""}`:void 0,placeholder:l?void 0:u,value:V[m.paramName]||"",onChange:h=>re(m.paramName,h.target.value),required:m.required,error:F},`custom-${C}`)},et=m=>{const C=ue(m);return e.jsxs("div",{className:"space-y-4",children:[m.conditionalOn&&e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:C,onChange:F=>re(m.conditionalOn,F.target.checked?"true":"false"),style:{width:"16px",height:"16px",accentColor:"var(--metakyc-primary, #2563eb)"}}),e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:m.conditionalOn})]}),C&&e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:m.fields.map((F,u)=>{const l=Math.min(4,Math.max(1,Number(F.colSpan)||4)),h=F.isCustom?`custom-${u}-${F.paramName}`:`builtin-${F.name}-${u}`;return e.jsx("div",{style:{gridColumn:`span ${l} / span ${l}`},children:F.isCustom?ze(F,u):Ge(F.name,h,F.displayText,F.countriesType,F.labelMode)},h)})})]})};if(!c||X)return e.jsx("div",{className:"metakyc-sdk",children:e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)",fontSize:"0.875rem"},children:"Loading form…"})]})})});if(k){const m=k[ce]??k[0],C=ve===-1,F=ne===-1,u=k.length,l=ue(m),h=Object.values(fe);return e.jsx("div",{className:"metakyc-sdk",children:e.jsxs(ee,{children:[e.jsx(ge,{children:e.jsx(nt,{title:(c==null?void 0:c.title)||"Company Registration"})}),e.jsxs(te,{children:[(m.title||m.subtitle)&&e.jsxs("div",{className:"mb-4",children:[m.title&&e.jsx("h3",{className:"font-semibold text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:m.title}),m.subtitle&&e.jsx("p",{className:"text-sm mt-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:m.subtitle})]}),(W||h.length>0)&&e.jsxs("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-lg",children:[W&&e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",W]}),h.map((P,b)=>e.jsx("p",{className:"text-red-600 text-sm",children:P},b))]}),u>1&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem",marginBottom:"1rem"},children:[k.map((P,b)=>e.jsx("div",{style:{height:"0.375rem",borderRadius:"9999px",transition:"all 150ms",...b===ce?{flex:"1 1 0%",backgroundColor:"var(--metakyc-primary, #2563eb)"}:b<ce?{width:"2rem",backgroundColor:"var(--metakyc-primary-light, #93c5fd)",opacity:.7}:{width:"2rem",backgroundColor:"#e5e7eb"}}},b)),e.jsxs("span",{style:{fontSize:"0.75rem",color:"var(--metakyc-text-muted, #9ca3af)",flexShrink:0},children:[ce+1," / ",u]})]}),et(m)]}),e.jsxs(be,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{children:[!C&&e.jsx(J,{type:"button",variant:"outline",onClick:()=>{de(ve),I({})},disabled:_||y,children:"Previous"}),C&&n&&e.jsx(J,{type:"button",variant:"outline",onClick:n,disabled:_||y,children:"Cancel"})]}),e.jsx(J,{type:"button",isLoading:_||y,onClick:F?Oe:ke,children:F?m.conditionalOn&&!l?"Skip & Submit":"Submit":m.conditionalOn&&!l?"Skip":"Next"})]})]})})}return e.jsx("div",{className:"metakyc-sdk",children:e.jsx("form",{onSubmit:Xe,children:e.jsxs(ee,{children:[e.jsx(ge,{children:e.jsx(nt,{title:(c==null?void 0:c.title)||"Company Registration"})}),e.jsxs(te,{children:[W&&e.jsx("div",{className:"mb-6 p-4 bg-red-50 border border-red-200 rounded-lg",children:e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",W]})}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:M.map(m=>e.jsx("div",{style:{gridColumn:"span 4 / span 4"},children:Ge(m)},m))})]}),e.jsxs(be,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[n&&e.jsx(J,{type:"button",variant:"outline",onClick:n,disabled:_||y,children:"Cancel"}),e.jsx(J,{type:"submit",isLoading:_||y,children:"Register Company"})]})]})})})},Fs=({applicantId:t,onComplete:r,onError:s,theme:n="light",className:a})=>{const{progress:o,currentStep:c,steps:d,workflowKey:y,nextWorkflowKey:p,hasWorkflowChanged:g,isLoading:T,error:v,moveBack:E,refreshProgress:A}=wr(t),[k,S]=i.useState(!1),M=i.useRef(null);if(i.useEffect(()=>{v&&s&&s(v)},[v,s]),i.useEffect(()=>{o!=null&&o.workflowResult&&r&&r(o.workflowResult)},[o==null?void 0:o.workflowResult,r]),i.useEffect(()=>{n==="dark"?document.documentElement.classList.add("dark"):document.documentElement.classList.remove("dark")},[n]),i.useEffect(()=>{g&&S(!1)},[g]),T||!o)return e.jsx("div",{className:`metakyc-sdk ${a||""}`,children:e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Loading workflow..."})]})})});if(v)return e.jsx("div",{className:`metakyc-sdk ${a||""}`,children:e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-lg mb-4",style:{color:"var(--metakyc-danger, #ef4444)"},children:"An error occurred"}),e.jsx("p",{style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:v.message})]})})})});if(g&&!k)return e.jsx("div",{className:`metakyc-sdk ${a||""}`,children:e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("div",{className:"text-center py-8",children:[e.jsx("div",{className:"mb-6",children:e.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-full mb-4",style:{backgroundColor:"var(--metakyc-primary-light, #dbeafe)"},children:e.jsx("svg",{className:"w-8 h-8",style:{color:"var(--metakyc-primary, #2563eb)"},fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})})}),e.jsx("h3",{className:"text-xl font-semibold mb-2",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Workflow Transition"}),e.jsx("p",{className:"mb-6",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Your application workflow has been updated based on your progress."}),e.jsxs("div",{className:"rounded-lg p-4 mb-6 max-w-md mx-auto",style:{backgroundColor:"var(--metakyc-surface, #f9fafb)"},children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"mb-1",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"Previous Workflow"}),e.jsx("p",{className:"font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:y})]}),e.jsx("svg",{className:"w-6 h-6 mx-4",style:{color:"var(--metakyc-text-muted, #9ca3af)"},fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 7l5 5m0 0l-5 5m5-5H6"})}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"mb-1",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"New Workflow"}),e.jsx("p",{className:"font-medium",style:{color:"var(--metakyc-primary, #2563eb)"},children:p})]})]}),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:()=>S(!0),className:"px-6 py-3 font-medium rounded-lg transition-opacity hover:opacity-90",style:{backgroundColor:"var(--metakyc-primary, #2563eb)",color:"#ffffff"},children:"Continue with New Workflow"})]})})})});if(o.status===Te.Finished||o.status===Te.OnHold)return e.jsx("div",{className:`metakyc-sdk ${a||""}`,children:e.jsx(ft,{kycStatus:o.kycStatus,reviewStatus:o.reviewStatus,workflowResult:o.workflowResult,customMessage:o.customMessage,onContinue:r&&o.workflowResult?()=>r(o.workflowResult):void 0,onContactSupport:()=>{typeof window<"u"&&(window.location.href="mailto:support@example.com")}})});if(!c)return e.jsx("div",{className:`metakyc-sdk ${a||""}`,children:e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:o.status===Te.IdentityPending?"Loading identity verification...":"Loading current step..."})]})})});const Y=U=>{switch(U){case oe.Overview:return"Overview";case oe.Questionaries:return"Questionnaire";case oe.UploadDocument:return"Documents";case oe.IdentitySdk:return"Identity";case oe.RiskScoring:return"Risk Assessment";case oe.InvestorCategorization:return"Investor Categorization";case oe.AppropriatenessTest:return"Appropriateness Test";case oe.AdditionalData:return"Additional Data";case oe.ManualReview:return"Review";default:return""}},L=()=>{const U=d.filter(q=>q.visibility!==!1),X=U.findIndex(q=>q.order===c.order),R=X>=0?X+1:1,f=U.length,O=f>1?X/(f-1)*100:100;return e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",marginBottom:"16px"},children:[e.jsx(nt,{}),e.jsxs(kt,{variant:o.status===1?"info":"success",children:["Step ",R," of ",f]})]}),e.jsx("div",{style:{marginBottom:"16px"},children:e.jsx("div",{style:{height:"4px",borderRadius:"999px",backgroundColor:"var(--metakyc-border, #e5e7eb)",overflow:"hidden"},children:e.jsx("div",{style:{height:"100%",borderRadius:"999px",backgroundColor:"var(--metakyc-primary, #2563eb)",width:`${O}%`,transition:"width 0.4s ease"}})})}),e.jsx(Ps,{ref:M,visibleSteps:U,currentVisibleStepIndex:X,getStepFallbackName:Y})]})},B=()=>{const U={applicantId:t,onComplete:async()=>{await A()},onBack:c.order>0?E:void 0};switch(c.action){case oe.Questionaries:return e.jsx(Mr,{...U});case oe.UploadDocument:return e.jsx(Or,{...U});case oe.Overview:return e.jsx(zr,{...U});case oe.IdentitySdk:return e.jsx(Hr,{...U});case oe.RiskScoring:return e.jsx($r,{...U});case oe.AdditionalData:case oe.InvestorCategorization:return e.jsx(Br,{...U});case oe.AppropriatenessTest:return e.jsx(_r,{...U});case oe.ManualReview:return e.jsx(ft,{kycStatus:o.kycStatus,reviewStatus:o.reviewStatus,workflowResult:o.workflowResult,customMessage:o.customMessage});default:return e.jsx(ee,{children:e.jsxs(te,{className:"py-12 text-center",children:[e.jsx("div",{className:"mb-4",children:e.jsx(Ee,{})}),e.jsxs("p",{className:"text-gray-600 dark:text-gray-400 mb-2",children:["Processing step: ",c.title||c.name]}),e.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:["Action type: ",oe[c.action]]})]})})}};return e.jsxs("div",{className:`metakyc-sdk ${a||""}`,children:[L(),B()]})},Ps=i.forwardRef(({visibleSteps:t,currentVisibleStepIndex:r,getStepFallbackName:s},n)=>{const a=i.useRef(null),o=i.useRef(null);return i.useImperativeHandle(n,()=>a.current),i.useEffect(()=>{if(o.current&&a.current){const c=a.current,d=o.current,y=d.offsetLeft-c.offsetWidth/2+d.offsetWidth/2;c.scrollTo({left:Math.max(0,y),behavior:"smooth"})}},[r]),e.jsx("div",{ref:a,className:"metakyc-stepper-scroll",style:{display:"flex",alignItems:"center",overflowX:"auto",overflowY:"hidden",scrollbarWidth:"none",msOverflowStyle:"none",WebkitOverflowScrolling:"touch",padding:"4px 0",gap:"0"},children:t.map((c,d)=>{const y=d<r,p=d===r,g=y||p,T=c.displayName||c.name||s(c.action)||`Step ${d+1}`;return e.jsxs(i.Fragment,{children:[e.jsxs("div",{ref:p?o:void 0,style:{display:"flex",alignItems:"center",flexShrink:0},children:[e.jsx("div",{style:{width:"28px",height:"28px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"12px",fontWeight:600,flexShrink:0,transition:"all 0.2s ease",...g?{backgroundColor:"var(--metakyc-primary, #2563eb)",color:"#ffffff",border:"none"}:{backgroundColor:"transparent",color:"var(--metakyc-text-muted, #9ca3af)",border:"2px solid var(--metakyc-border, #e5e7eb)"}},children:y?e.jsx("svg",{width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:2.5,viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}):d+1}),e.jsx("span",{style:{marginLeft:"6px",fontSize:"13px",whiteSpace:"nowrap",fontWeight:p?600:400,color:p?"var(--metakyc-text-primary, #111827)":y?"var(--metakyc-primary, #2563eb)":"var(--metakyc-text-muted, #9ca3af)",transition:"color 0.2s ease"},children:T})]}),d<t.length-1&&e.jsx("div",{style:{width:"32px",minWidth:"16px",height:"2px",margin:"0 8px",flexShrink:0,borderRadius:"999px",backgroundColor:y?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",transition:"background-color 0.2s ease"}})]},c.order)})})});function Ls(t){return We.z.object({questionResults:We.z.any()}).passthrough()}function Ds(t){let r=We.z.array(We.z.instanceof(File));if(t.isRequired?r=r.min(1,`${t.displayName} is required`):r=r.optional(),t.multipleFile||(r=r.refine(s=>!s||s.length<=1,{message:"Only one file is allowed"})),t.maxEachFileSizeByte>0&&(r=r.refine(s=>!s||s.every(n=>n.size<=t.maxEachFileSizeByte),{message:`File size must not exceed ${Math.round(t.maxEachFileSizeByte/1024/1024)}MB`})),t.allowedTypes){const s=t.allowedTypes.split(",").map(n=>n.trim());r=r.refine(n=>n?n.every(a=>s.some(o=>o.endsWith("/*")?a.type.startsWith(o.slice(0,-2)):a.type===o)):!0,{message:"Invalid file type"})}return r}function Ms(t){const r={};return t.uploadDocumentFiles.forEach(s=>{const n=`file_${s.id}`;r[n]=Ds(s)}),We.z.object(r)}function Os(t){return We.z.any()}function zs(t){return We.z.string().min(1,"This question is required")}function $s(t){const r={};return t.appropriatenessQuestions.forEach(s=>{const n=`question_${s.id}`;r[n]=zs()}),We.z.object(r)}const Bs=We.z.any();exports.ALLOWED_LANGUAGES=ht;exports.ApplicantProgressOnHoldReason=At;exports.ApplicantProgressStatus=Te;exports.ApplicantService=qt;exports.ApplicantStatus=Ft;exports.AppropriatenessQuestionType=Ot;exports.AppropriatenessTestService=Qt;exports.AppropriatenessTestStep=_r;exports.Badge=kt;exports.BaseInformationService=Xt;exports.Button=J;exports.COMPANY_FIELD_METADATA=Ze;exports.Card=ee;exports.CardContent=te;exports.CardFooter=be;exports.CardHeader=ge;exports.CountriesType=He;exports.CreateApplicantForm=As;exports.CreateCompanyApplicantForm=Ts;exports.CriteriaBuiltInType=$t;exports.DEFAULT_COMPANY_VISIBLE_FIELDS=_t;exports.DEFAULT_VISIBLE_FIELDS=Ht;exports.DocumentReviewStatus=Mt;exports.EndpointBuilder=Ut;exports.ErrorHandler=rt;exports.EventEmitter=lr;exports.FIELD_METADATA=Qe;exports.FileType=Dt;exports.FileUpload=Ar;exports.GenderType=lt;exports.Header=nt;exports.HttpClient=Kt;exports.IdentityProviderManager=_e;exports.IdentityService=Zt;exports.IdentityVerificationProvider=Ae;exports.IdentityVerificationStep=Hr;exports.Input=ye;exports.InvestorCategorizationService=er;exports.InvestorCategorizationStep=Br;exports.InvestorCategorizationType=je;exports.InvestorCategoryType=Bt;exports.KycProcessStatus=Pt;exports.KycStatus=Ve;exports.KycStatusDisplay=ft;exports.KycWorkflow=Fs;exports.Logo=Wr;exports.MetaKYCContext=bt;exports.MetaKYCError=Le;exports.MetaKYCProvider=es;exports.MultiSelect=Er;exports.OnfidoProvider=mr;exports.OverviewService=Gt;exports.OverviewStep=zr;exports.PhoneInput=Tr;exports.QuestionnaireService=Vt;exports.QuestionnaireStep=Mr;exports.ReviewStatus=Ye;exports.RiskCriteriaType=zt;exports.RiskLevel=Tt;exports.RiskScoringService=Jt;exports.RiskScoringStep=$r;exports.SDK_VERSION=hr;exports.SardinAIProvider=yr;exports.SearchableSelect=Me;exports.Select=mt;exports.Spinner=Ee;exports.StepRouter=dr;exports.SumsubProvider=pr;exports.ThemeManager=xr;exports.ThemePreset=we;exports.ThemeService=or;exports.UploadDocumentService=Yt;exports.UploadDocumentStep=Or;exports.UserType=Lt;exports.ValueDataType=De;exports.WorkflowOrchestrator=ur;exports.WorkflowResultType=ot;exports.WorkflowState=cr;exports.WorkflowStepAction=oe;exports.appropriatenessTestSchema=Bs;exports.clearAllStorage=as;exports.clearApplicantId=vr;exports.clearWorkflowState=jr;exports.cn=Se;exports.corporateTheme=tr;exports.defaultConfig=Wt;exports.defaultTheme=Re;exports.fileToBase64=fr;exports.fintechTheme=rr;exports.formatFileSize=ut;exports.generateAppropriatenessSchema=$s;exports.generateQuestionnaireSchema=Ls;exports.generateRiskScoringSchema=Os;exports.generateUploadDocumentSchema=Ms;exports.getAcceptString=ss;exports.getApplicantId=br;exports.getThemePreset=st;exports.getWorkflowState=ns;exports.healthcareTheme=sr;exports.isScriptLoaded=Qr;exports.loadScript=gt;exports.minimalTheme=ar;exports.modernTheme=nr;exports.removeScript=Gr;exports.saveApplicantId=gr;exports.saveWorkflowState=kr;exports.themePresets=ir;exports.useApplicant=vt;exports.useAppropriatenessTest=is;exports.useIdentityVerification=Rr;exports.useKycWorkflow=wr;exports.useMetaKYC=Ne;exports.useOverview=Nr;exports.useQuestionnaire=Sr;exports.useRiskScoring=Ir;exports.useUploadDocument=Cr;exports.validateFileSize=ts;exports.validateFileType=rs;
|
|
103
103
|
//# sourceMappingURL=index.cjs.map
|