@vpdev2/metakyc-sdk 1.0.67 → 1.0.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/identity/IdentityVerificationStep.d.ts.map +1 -1
- package/dist/index.cjs +18 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2117 -1914
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/types/form-config.d.ts +5 -0
- package/dist/types/form-config.d.ts.map +1 -1
- package/dist/types/theme.d.ts +3 -3
- package/dist/types/theme.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var vr=Object.defineProperty;var kr=(t,r,s)=>r in t?vr(t,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[r]=s;var ee=(t,r,s)=>kr(t,typeof r!="symbol"?r+"":r,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const wr=require("axios"),o=require("react"),e=require("react/jsx-runtime"),Ze=require("react-dom"),Ie=require("react-hook-form"),Ee=require("zod");function jr(t){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const a=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(r,s,a.get?a:{enumerable:!0,get:()=>t[s]})}}return r.default=t,Object.freeze(r)}const rt=jr(o);var Q=(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))(Q||{}),Ue=(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))(Ue||{}),be=(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))(be||{}),ot=(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))(ot||{}),lt=(t=>(t[t.LowRisk=0]="LowRisk",t[t.MediumRisk=1]="MediumRisk",t[t.HighRisk=2]="HighRisk",t[t.Alert=3]="Alert",t))(lt||{}),Pe=(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))(Pe||{}),Fe=(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))(Fe||{}),ct=(t=>(t[t.ProviderResultPending=0]="ProviderResultPending",t[t.ProviderResultReceived=1]="ProviderResultReceived",t[t.Canceled=2]="Canceled",t[t.ExtendedToNewApplicant=3]="ExtendedToNewApplicant",t))(ct||{}),dt=(t=>(t[t.None=0]="None",t[t.ProviderResultPending=1]="ProviderResultPending",t[t.ProviderResultReceived=2]="ProviderResultReceived",t[t.Canceled=3]="Canceled",t))(dt||{}),fe=(t=>(t[t.Onfido=0]="Onfido",t[t.Sumsub=2]="Sumsub",t[t.SardinAI=3]="SardinAI",t))(fe||{}),ut=(t=>(t[t.Individual=0]="Individual",t[t.Company=1]="Company",t))(ut||{}),Ke=(t=>(t[t.Male=0]="Male",t[t.Female=1]="Female",t[t.Other=2]="Other",t))(Ke||{}),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||{}),pt=(t=>(t[t.Pending=0]="Pending",t[t.Approved=1]="Approved",t[t.Rejected=2]="Rejected",t[t.RequiresRevision=3]="RequiresRevision",t))(pt||{}),ht=(t=>(t[t.SingleChoice=0]="SingleChoice",t[t.MultipleChoice=1]="MultipleChoice",t[t.Text=2]="Text",t))(ht||{}),Ce=(t=>(t[t.String=0]="String",t[t.Integer=1]="Integer",t[t.Decimal=2]="Decimal",t[t.Boolean=3]="Boolean",t[t.Date=4]="Date",t[t.Country=5]="Country",t[t.DigitOnly=6]="DigitOnly",t))(Ce||{}),gt=(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))(gt||{}),xt=(t=>(t[t.None=0]="None",t[t.Country=1]="Country",t))(xt||{}),ge=(t=>(t[t.Individual=0]="Individual",t[t.Sophisticated=1]="Sophisticated",t[t.HighNetWorth=2]="HighNetWorth",t[t.Business=3]="Business",t))(ge||{}),yt=(t=>(t[t.Retail=0]="Retail",t[t.Professional=1]="Professional",t[t.EligibleCounterparty=2]="EligibleCounterparty",t))(yt||{});const Me={Nationality:10,Address:20,CountryOfBirth:30,PhoneNumber:40,UboAddress:50},Le={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:Me.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:Me.Address},nationality:{label:"Nationality",type:"select",countriesType:Me.Nationality},otherNationality:{label:"Other Nationalities",type:"multiselect",countriesType:Me.Nationality},countryOfBirth:{label:"Country of Birth",type:"select",countriesType:Me.CountryOfBirth},placeOfBirth:{label:"Place of Birth",type:"text"},taxCountry:{label:"Tax Country",type:"select",countriesType:Me.Address},taxNumber:{label:"Tax Number",type:"text"},defaultLanguage:{label:"Default Language",type:"select"},educationLevel:{label:"Education Level",type:"text"},occupation:{label:"Occupation",type:"text"}},ft=["firstName","lastName","email","phonenumber","dateOfBirth"],Ve=[{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 oe=(t=>(t.Default="default",t.Corporate="corporate",t.Fintech="fintech",t.Healthcare="healthcare",t.Modern="modern",t.Minimal="minimal",t))(oe||{});const bt={timeout:3e4,retries:3,locale:"en",endpoints:{pattern:"host-controller"}};class vt{constructor(r){this.config=r}build(r,s){const a=`${r}.${s}`;if(this.config.customPaths&&this.config.customPaths[a])return this.config.customPaths[a];switch(this.config.pattern){case"host-controller":return`/api/${r}/${s}`;case"application-service":return`/services/app/${this.getServiceName(r)}/${s}`;case"custom":throw new Error(`Custom endpoint path not found for ${a}. Please provide it in customPaths.`);default:throw new Error(`Unknown endpoint pattern: ${this.config.pattern}`)}}getServiceName(r){return{Applicant:"MetaKYCVerification",Questionnaire:"MetaKYCVerification",UploadDocument:"MetaKYCVerification",AppropriatenessTest:"MetaKYCVerification",BaseInformation:"MetaKYCVerification"}[r]||r}}class Se extends Error{constructor(s,a,n,i,l){super(s);ee(this,"response");this.code=a,this.details=n,this.validationErrors=i,this.name="MetaKYCError",this.response=l,Object.setPrototypeOf(this,Se.prototype)}}class ze{static handleApiError(r){return new Se(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 Se(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 Se(s.result.message,r.response.status,`HTTP ${r.response.status}: ${r.response.statusText}`,void 0,r.response):new Se((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 Se("No response from server",0,"The request was made but no response was received. Please check your network connection."):new Se(r.message||"An unexpected error occurred",0,r.toString())}static isMetaKYCError(r){return r instanceof Se}}class kt{constructor(r){ee(this,"axiosInstance");ee(this,"endpointBuilder");ee(this,"config");this.config={...bt,...r},this.endpointBuilder=new vt(this.config.endpoints),this.axiosInstance=wr.create({baseURL:this.config.baseUrl,timeout:this.config.timeout,headers:{"Content-Type":"application/json"}}),this.axiosInstance.interceptors.request.use(s=>(s.headers["Abp-TenantId"]=this.config.tenantId.toString(),s.headers.ApiKey=this.config.apiKey,s.headers["X-API-KEY"]=this.config.apiKey,this.config.locale&&(s.headers["Accept-Language"]=this.config.locale),s),s=>Promise.reject(s)),this.axiosInstance.interceptors.response.use(s=>s,async s=>{var n;const a=s.config;return((n=s.response)==null?void 0:n.status)>=500&&!a._retry&&(a._retry=!0,a._retryCount=(a._retryCount||0)+1,a._retryCount<(this.config.retries||3))?(await new Promise(i=>setTimeout(i,1e3*a._retryCount)),this.axiosInstance(a)):Promise.reject(s)})}buildEndpoint(r,s){return this.endpointBuilder.build(r,s)}async get(r,s,a){try{const n=this.buildEndpoint(r,s),i=await this.axiosInstance.get(n,{params:a});return this.handleResponse(i)}catch(n){throw ze.handleAxiosError(n)}}async post(r,s,a){try{const n=this.buildEndpoint(r,s),i=await this.axiosInstance.post(n,a);return this.handleResponse(i)}catch(n){throw ze.handleAxiosError(n)}}async put(r,s,a){try{const n=this.buildEndpoint(r,s),i=await this.axiosInstance.put(n,a);return this.handleResponse(i)}catch(n){throw ze.handleAxiosError(n)}}async delete(r,s,a){try{const n=this.buildEndpoint(r,s),i=await this.axiosInstance.delete(n,{params:a});return this.handleResponse(i)}catch(n){throw ze.handleAxiosError(n)}}handleResponse(r){const s=r.data;if(!s.success&&s.error)throw ze.handleApiError(s.error);return s}getAxiosInstance(){return this.axiosInstance}}class wt{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 jt{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 St{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 Nt{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 Ct{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 Et{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 At{constructor(r){this.httpClient=r}async identityRequest(r){console.log("[IdentityService] Calling IdentityRequest with input:",r);const s=await this.httpClient.post("Applicant","IdentityRequest",r);return console.log("[IdentityService] IdentityRequest response:",s),s.result}async identityCompanyRequest(r){return(await this.httpClient.post("Applicant","IdentityCompanyRequest",r)).result}async restartIdentityRequest(r){const s={applicantId:r,restart:!0,redirectUrl:"",ttl:604800};return console.log("[IdentityService] Restarting identity with restart=true:",s),this.identityRequest(s)}async restartIdentityCompanyRequest(r){const s={applicantId:r,restart:!0,redirectUrl:"",ttl:604800};return this.identityCompanyRequest(s)}}class Rt{constructor(r){this.httpClient=r}async getCountries(r,s,a){return(await this.httpClient.get("BaseInformation","GetAllCountries",{filter:r||"",lng:s||"en",type:a})).result}async getBranches(){return(await this.httpClient.get("BaseInformation","GetBranches")).result}async getLegalEntities(){return(await this.httpClient.get("BaseInformation","GetLegalEntities")).result}}class It{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 pe={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"}}},Pt={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"}},Ft={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"}},Lt={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"}}},Tt={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"}},Dt={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"}},Mt={[oe.Default]:pe,[oe.Corporate]:Pt,[oe.Fintech]:Ft,[oe.Healthcare]:Lt,[oe.Modern]:Tt,[oe.Minimal]:Dt};function Be(t){return Mt[t]||pe}class Ot{constructor(r){this.httpClient=r}async getThemeConfiguration(){var r;try{const s=await this.httpClient.get("Tenant","GetThemeConfiguration");if(!s.result.isEnabled)return Be(oe.Default);let a=s.result.preset?Be(s.result.preset):Be(oe.Default);if(s.result.title&&(a.title=s.result.title),s.result.logo&&(a.logo={...a.logo,...s.result.logo}),s.result.colors&&(a.colors={...a.colors,...s.result.colors}),s.result.typography&&(a.typography={...a.typography,...s.result.typography}),s.result.spacing&&(a.spacing={...a.spacing,...s.result.spacing}),s.result.customCSS&&(a.customCSS=s.result.customCSS),s.result.darkMode&&(a.darkMode={colors:{...(r=a.darkMode)==null?void 0:r.colors,...s.result.darkMode.colors}}),s.result.applicantFormVisibleFields&&s.result.applicantFormVisibleFields.length>0&&(a.applicantFormVisibleFields=s.result.applicantFormVisibleFields),s.result.applicantFormRequiredFields&&s.result.applicantFormRequiredFields.length>0&&(a.applicantFormRequiredFields=s.result.applicantFormRequiredFields),s.result.allowedLanguages&&s.result.allowedLanguages.length>0&&(a.allowedLanguages=s.result.allowedLanguages),s.result.applicantFormPages)try{const n=typeof s.result.applicantFormPages=="string"?JSON.parse(s.result.applicantFormPages):s.result.applicantFormPages;Array.isArray(n)&&n.length>0&&(a.applicantFormPages=n.map(i=>{const l=!i._v||i._v<4;return{...i,fields:(i.fields||[]).map(d=>({...d,colSpan:l?d.colSpan===1?2:4:Math.min(4,Math.max(1,d.colSpan??4))}))}}))}catch{}if(s.result.reviewPageFields)try{const n=typeof s.result.reviewPageFields=="string"?JSON.parse(s.result.reviewPageFields):s.result.reviewPageFields;Array.isArray(n)&&n.length>0&&(a.reviewPageFields=n)}catch{}return a}catch(s){return console.warn("[ThemeService] Failed to fetch theme configuration:",s),Be(oe.Default)}}async saveThemeConfiguration(r){await this.httpClient.post("Tenant","SaveThemeConfiguration",r)}getAvailablePresets(){return[{id:oe.Default,name:"Default"},{id:oe.Corporate,name:"Corporate"},{id:oe.Fintech,name:"Fintech"},{id:oe.Healthcare,name:"Healthcare"},{id:oe.Modern,name:"Modern"},{id:oe.Minimal,name:"Minimal"}]}getPreviewTheme(r,s){const a=Be(r);return s?{...a,...s,logo:{...a.logo,...s.logo},colors:{...a.colors,...s.colors},typography:s.typography?{...a.typography,...s.typography}:a.typography,spacing:s.spacing?{...a.spacing,...s.spacing}:a.spacing}:a}}class zt{constructor(){ee(this,"listeners",new Map)}on(r,s){return this.listeners.has(r)||this.listeners.set(r,new Set),this.listeners.get(r).add(s),()=>{this.off(r,s)}}off(r,s){const a=this.listeners.get(r);a&&a.delete(s)}emit(r,s){const a=this.listeners.get(r);a&&a.forEach(n=>{try{n(s)}catch(i){console.error(`Error in event listener for "${r}":`,i)}})}clear(){this.listeners.clear()}clearEvent(r){this.listeners.delete(r)}}class Bt{constructor(){ee(this,"events",new zt);ee(this,"_applicantId",null);ee(this,"_progress",null);ee(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)||be.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===be.Finished}get isOnHold(){return this.status===be.OnHold}get isInProgress(){return this.status===be.InProgress}setApplicantId(r){this._applicantId=r}updateProgress(r){var a,n;const s=(a=this._progress)==null?void 0:a.currentStep;this._progress=r,this._applicantId=r.applicantId,this._error=null,this.events.emit("progressUpdated",r),(s==null?void 0:s.order)!==((n=r.currentStep)==null?void 0:n.order)&&this.events.emit("stepChanged",r.currentStep),this.events.emit("statusChanged",r.status),r.status===be.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 $t{constructor(){ee(this,"handlers",new Map)}registerHandler(r,s){this.handlers.set(r,s)}getHandler(r){return this.handlers.get(r)}hasHandler(r){return this.handlers.has(r)}async loadStepData(r,s){const a=this.getHandler(r);if(!a)throw new Error(`No handler registered for step action: ${Q[r]}`);return a.loadData(s)}async submitStepData(r,s){const a=this.getHandler(r);if(!a)throw new Error(`No handler registered for step action: ${Q[r]}`);return a.submitData(s)}}class _t{constructor(r,s,a,n,i,l,d,m){ee(this,"state");ee(this,"stepRouter");this.applicantService=r,this.questionnaireService=s,this.uploadDocumentService=a,this.appropriatenessTestService=n,this.overviewService=i,this.riskScoringService=l,this.investorCategorizationService=m,this.state=new Bt,this.stepRouter=new $t,this.registerStepHandlers()}registerStepHandlers(){this.stepRouter.registerHandler(Q.Questionaries,{loadData:r=>this.questionnaireService.getQuestionnaire(r),submitData:async r=>{await this.questionnaireService.fillQuestionnaire(r)}}),this.stepRouter.registerHandler(Q.UploadDocument,{loadData:r=>this.uploadDocumentService.getUploadDocument(r),submitData:r=>this.uploadDocumentService.fillUploadDocument(r)}),this.stepRouter.registerHandler(Q.AppropriatenessTest,{loadData:r=>this.appropriatenessTestService.getAppropriatenessTest(r),submitData:async r=>{await this.appropriatenessTestService.fillAppropriatenessTest(r)}}),this.stepRouter.registerHandler(Q.Overview,{loadData:r=>this.overviewService.getOverviewData(r),submitData:r=>this.overviewService.passOverview(r.applicantId)}),this.stepRouter.registerHandler(Q.RiskScoring,{loadData:r=>this.riskScoringService.getRiskCriterias(r),submitData:async r=>{await this.riskScoringService.submitRiskScoring(r)}}),this.stepRouter.registerHandler(Q.IdentitySdk,{loadData:async r=>({applicantId:r,message:"Identity verification required"}),submitData:async()=>{}}),this.stepRouter.registerHandler(Q.InvestorCategorization,{loadData:r=>this.investorCategorizationService.getInvestorCategorization(r),submitData:async r=>{await this.investorCategorizationService.setInvestorCategorization(r)}}),this.stepRouter.registerHandler(Q.ManualReview,{loadData:async r=>({applicantId:r,message:"Your application is under manual review"}),submitData:async()=>{}}),this.stepRouter.registerHandler(Q.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 Xe(t,r){return new Promise((s,a)=>{if(r&&document.getElementById(r)){s();return}const n=document.createElement("script");n.src=t,r&&(n.id=r),n.async=!0,n.onload=()=>s(),n.onerror=()=>a(new Error(`Failed to load script: ${t}`)),document.head.appendChild(n)})}function Sr(t){return!!document.getElementById(t)}function Nr(t){const r=document.getElementById(t);r&&r.remove()}class Ht{constructor(r){ee(this,"sdk",null);ee(this,"config");this.config=r}async loadSDK(){await Xe("https://cdn.sumsub.com/websdk/v2/production/websdk.js","sumsub-sdk")}async initialize(r){if(window.snsWebSdk||await this.loadSDK(),!window.snsWebSdk)throw new Error("Sumsub SDK failed to load");this.sdk=window.snsWebSdk.init(this.config.accessToken,()=>this.config.accessToken).withConf({lang:this.config.lang||"en",email:this.config.applicantEmail,phone:this.config.applicantPhone,i18n:{}}).on("idCheck.onStepCompleted",s=>{console.log("Sumsub step completed:",s)}).on("idCheck.onError",s=>{console.error("Sumsub error:",s)}).build(),this.sdk.launch(`#${r}`)}destroy(){this.sdk&&(this.sdk.destroy(),this.sdk=null)}onComplete(r){this.sdk&&this.sdk.on("idCheck.applicantStatus",s=>{s.applicantStatus==="completed"&&r(s)})}onError(r){this.sdk&&this.sdk.on("idCheck.onError",r)}}class Ut{constructor(r){ee(this,"sdk",null);ee(this,"config");this.config=r}async loadSDK(){await Xe("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 Kt{constructor(r){ee(this,"sardineContext",null);ee(this,"config");ee(this,"sessionKey");this.config=r,this.sessionKey=r.sessionKey||this.generateSessionKey()}generateSessionKey(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(r){const s=Math.random()*16|0;return(r==="x"?s:s&3|8).toString(16)})}getSardineHost(){const{environment:r,region:s}=this.config;if(r==="sandbox")return"api.sandbox.sardine.ai";switch(s){case"eu":return"api.eu.sardine.ai";case"ca":return"api.ca.sardine.ai";case"au":return"api.au.sardine.ai";default:return"api.sardine.ai"}}async loadSDK(){return new Promise((r,s)=>{if(window._Sardine){r();return}const a=this.getSardineHost(),n=document.createElement("script");n.type="text/javascript",n.async=!0,n.src=`https://${a}/assets/loader.min.js`,n.onload=()=>{console.log("[SardinAI] SDK loaded successfully"),r()},n.onerror=()=>{s(new Error("Failed to load SardinAI SDK"))};const i=document.getElementsByTagName("script")[0];i&&i.parentNode?i.parentNode.insertBefore(n,i):document.head.appendChild(n)})}async initialize(){try{if(await this.loadSDK(),!window._Sardine)throw new Error("SardinAI SDK not available after loading");const r=this.getSardineHost(),{clientId:s,environment:a,flow:n,enableBiometrics:i,enablePortScanning:l}=this.config;this.sardineContext=window._Sardine.createContext({clientId:s,sessionKey:this.sessionKey,userIdHash:void 0,flow:n||window.location.pathname,environment:a||"production",parentElement:document.body,enableBiometrics:i!==!1,enablePortScanning:l===!0,region:this.config.region,onDeviceResponse:d=>{console.log(`[SardinAI] Device ID: ${d.deviceId}`)},onConfigUpdate:(d,m,u)=>{switch(d){case"SESSION_UPDATE_FAILED":console.error("[SardinAI] Session update failed:",u);break;case"SESSION_UPDATED":console.log("[SardinAI] Session updated:",m);break;case"SESSION_NO_UPDATE":console.log("[SardinAI] No session update");break;default:console.warn("[SardinAI] Unknown event:",d)}}}),this.addNoScriptFallback(r),console.log("[SardinAI] SDK initialized with sessionKey:",this.sessionKey)}catch(r){throw console.error("[SardinAI] Initialization failed:",r),r}}addNoScriptFallback(r){const s=document.createElement("noscript"),a=document.createElement("img"),{clientId:n,flow:i}=this.config;a.src=`https://${r}/v1/a.png?clientId=${n}&sessionKey=${this.sessionKey}&flow=${i||"kyc"}&ns=1`,a.style.display="none",s.appendChild(a),document.body.appendChild(s)}updateConfig(r){if(!this.sardineContext){console.warn("[SardinAI] Cannot update config - SDK not initialized");return}r.sessionKey&&(this.sessionKey=r.sessionKey),this.sardineContext.updateConfig({...r,onConfigUpdate:(s,a,n)=>{switch(s){case"SESSION_UPDATE_FAILED":console.error("[SardinAI] Config update failed:",n);break;case"SESSION_UPDATED":console.log("[SardinAI] Config updated:",a);break;case"SESSION_NO_UPDATE":console.log("[SardinAI] No config update needed");break}}})}getSessionKey(){return this.sessionKey}destroy(){this.sardineContext&&(this.sardineContext=null)}}class Oe{static createProvider(r,s){switch(r){case fe.Sumsub:return new Ht(s);case fe.Onfido:return new Ut(s);case fe.SardinAI:return new Kt(s);default:throw new Error(`Unsupported identity provider: ${r}`)}}static parseProviderConfig(r,s,a){var n;switch(r){case fe.Sumsub:return{accessToken:s.accessToken||s.token,applicantEmail:s.email,applicantPhone:s.phone,externalUserId:s.externalUserId,lang:s.lang||"en"};case fe.Onfido:return{token:s.token||s.sdkToken};case fe.SardinAI:const i=((n=a==null?void 0:a.identityProviders)==null?void 0:n.sardinai)||{};return{clientId:i.clientId||s.clientId,sessionKey:i.sessionKey||s.sessionKey,environment:i.environment||s.environment||"production",flow:i.flow||s.flow,region:i.region,enableBiometrics:i.enableBiometrics,enablePortScanning:i.enablePortScanning};default:throw new Error(`Unsupported identity provider: ${r}`)}}}class Wt{constructor(r){ee(this,"currentTheme",pe);ee(this,"customStyleElement",null);ee(this,"container");this.container=r||document.documentElement}applyTheme(r){this.currentTheme=this.mergeWithDefault(r),this.applyColors(this.currentTheme.colors),this.currentTheme.typography&&this.applyTypography(this.currentTheme.typography),this.currentTheme.spacing&&this.applySpacing(this.currentTheme.spacing),this.currentTheme.customCSS&&this.injectCustomCSS(this.currentTheme.customCSS),console.log("[ThemeManager] Theme applied:",this.currentTheme.name||"Custom")}applyColors(r){var a;const s={primary:r.primary,"primary-hover":r.primaryHover,"primary-light":r.primaryLight,"primary-dark":r.primaryDark,secondary:r.secondary,"secondary-hover":r.secondaryHover,success:r.success,warning:r.warning,danger:r.danger,info:r.info,background:r.background,"input-bg":r.background,surface:r.surface,border:r.border,"text-primary":r.textPrimary,"text-secondary":r.textSecondary,"text-muted":r.textMuted};Object.entries(s).forEach(([n,i])=>{this.container.style.setProperty(`--metakyc-${n}`,i)}),(a=this.currentTheme.darkMode)!=null&&a.colors&&this.applyDarkModeColors(this.currentTheme.darkMode.colors)}applyDarkModeColors(r){Object.entries(r).forEach(([s,a])=>{if(a){const n=`--metakyc-dark-${this.kebabCase(s)}`;this.container.style.setProperty(n,a)}})}applyTypography(r){r&&(r.fontFamily&&this.container.style.setProperty("--metakyc-font-family",r.fontFamily),r.headingFont&&this.container.style.setProperty("--metakyc-heading-font",r.headingFont),r.fontSize&&Object.entries(r.fontSize).forEach(([s,a])=>{this.container.style.setProperty(`--metakyc-font-size-${s}`,a)}),r.fontWeight&&Object.entries(r.fontWeight).forEach(([s,a])=>{this.container.style.setProperty(`--metakyc-font-weight-${s}`,a.toString())}))}applySpacing(r){r&&Object.entries(r).forEach(([s,a])=>{const n=`--metakyc-${this.kebabCase(s)}`;this.container.style.setProperty(n,a)})}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||pe.name,title:r.title||pe.title,logo:{...pe.logo,...r.logo},colors:{...pe.colors,...r.colors},typography:r.typography?{...pe.typography,...r.typography}:pe.typography,spacing:r.spacing?{...pe.spacing,...r.spacing}:pe.spacing,customCSS:r.customCSS,darkMode:r.darkMode?{colors:{...(s=pe.darkMode)==null?void 0:s.colors,...r.darkMode.colors}}:pe.darkMode,applicantFormVisibleFields:r.applicantFormVisibleFields,applicantFormRequiredFields:r.applicantFormRequiredFields,allowedLanguages:r.allowedLanguages,applicantFormPages:r.applicantFormPages,reviewPageFields:r.reviewPageFields}}getCurrentTheme(){return this.currentTheme}resetTheme(){this.applyTheme(pe)}cleanup(){this.customStyleElement&&(this.customStyleElement.remove(),this.customStyleElement=null)}kebabCase(r){return r.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}}const et=o.createContext(null),Cr=({config:t,children:r})=>{const[s,a]=o.useState(null),n=o.useRef(!1),i=o.useRef(!1),l=o.useMemo(()=>{const m=new kt(t),u=new wt(m),f=new jt(m),S=new St(m),p=new Nt(m),b=new Ct(m),g=new Et(m),I=new At(m),E=new Rt(m),j=new It(m),M=new Ot(m),C=new Wt;return{httpClient:m,applicantService:u,questionnaireService:f,uploadDocumentService:S,appropriatenessTestService:p,overviewService:b,riskScoringService:g,identityService:I,baseInformationService:E,investorCategorizationService:j,themeService:M,themeManager:C}},[t]),d=o.useMemo(()=>({config:t,...l,currentTheme:s,createOrchestrator:()=>new _t(l.applicantService,l.questionnaireService,l.uploadDocumentService,l.appropriatenessTestService,l.overviewService,l.riskScoringService,l.identityService,l.investorCategorizationService)}),[t,l,s]);return o.useEffect(()=>((async()=>{if(n.current||i.current){console.log("[MetaKYC] Theme already loading or loaded, skipping...");return}n.current=!0;try{if(t.theme){console.log("[MetaKYC] Applying static theme from config"),l.themeManager.applyTheme(t.theme),a(l.themeManager.getCurrentTheme()),i.current=!0;return}console.log("[MetaKYC] Fetching theme from backend...");const u=await l.themeService.getThemeConfiguration();l.themeManager.applyTheme(u),a(l.themeManager.getCurrentTheme()),i.current=!0,console.log("[MetaKYC] Theme loaded and applied",u)}catch(u){console.warn("[MetaKYC] Failed to load theme, using default:",u),a(l.themeManager.getCurrentTheme()),i.current=!0}finally{n.current=!1}})(),()=>{l.themeManager.cleanup()}),[]),e.jsx(et.Provider,{value:d,children:r})};function xe(){const t=o.useContext(et);if(!t)throw new Error("useMetaKYC must be used within a MetaKYCProvider");return t}async function Yt(t){return new Promise((r,s)=>{const a=new FileReader;a.readAsDataURL(t),a.onload=()=>{const i=a.result.split(",")[1];r(i)},a.onerror=n=>s(n)})}function Er(t,r){return t.size<=r}function Ar(t,r){return r.split(",").map(a=>a.trim()).some(a=>{if(a.endsWith("/*")){const n=a.slice(0,-2);return t.type.startsWith(n)}return t.type===a})}function qe(t){if(t===0)return"0 Bytes";const r=1024,s=["Bytes","KB","MB","GB"],a=Math.floor(Math.log(t)/Math.log(r));return Math.round(t/Math.pow(r,a)*100)/100+" "+s[a]}function Rr(t){return t}function ie(...t){return t.filter(Boolean).join(" ")}const $e={APPLICANT_ID:"metakyc_applicant_id",WORKFLOW_STATE:"metakyc_workflow_state"};function qt(t){try{localStorage.setItem($e.APPLICANT_ID,t.toString())}catch(r){console.warn("Failed to save applicant ID to storage:",r)}}function Qt(){try{const t=localStorage.getItem($e.APPLICANT_ID);return t?parseInt(t,10):null}catch(t){return console.warn("Failed to retrieve applicant ID from storage:",t),null}}function Gt(){try{localStorage.removeItem($e.APPLICANT_ID)}catch(t){console.warn("Failed to clear applicant ID from storage:",t)}}function Vt(t){try{localStorage.setItem($e.WORKFLOW_STATE,JSON.stringify(t))}catch(r){console.warn("Failed to save workflow state to storage:",r)}}function Ir(){try{const t=localStorage.getItem($e.WORKFLOW_STATE);return t?JSON.parse(t):null}catch(t){return console.warn("Failed to retrieve workflow state from storage:",t),null}}function Jt(){try{localStorage.removeItem($e.WORKFLOW_STATE)}catch(t){console.warn("Failed to clear workflow state from storage:",t)}}function Pr(){Gt(),Jt()}function Zt(t){const{createOrchestrator:r}=xe(),[s,a]=o.useState(null),[n,i]=o.useState(!1),[l,d]=o.useState(null),m=o.useRef(null),u=t||Qt();o.useEffect(()=>{m.current||(m.current=r())},[r]),o.useEffect(()=>{var C;s&&u&&(qt(u),Vt({applicantId:u,currentStepOrder:(C=s.currentStep)==null?void 0:C.order,status:s.status,lastUpdated:new Date().toISOString(),workflowKey:s.workFlowKey,nextWorkflowKey:s.nextWorkflowKey}))},[s,u]);const f=o.useRef(!1),S=o.useRef(!1),p=o.useCallback(async()=>{if(!(!u||!m.current)){if(f.current){console.log("[Workflow] Load already in progress, skipping...");return}f.current=!0,i(!0),d(null);try{const C=await m.current.initialize(u);a(C),S.current=!0}catch(C){d(C)}finally{i(!1),f.current=!1}}},[u]);o.useEffect(()=>{u&&!S.current&&p()},[u,p]);const b=o.useCallback(async()=>{if(m.current){if(f.current){console.log("[Workflow] Refresh already in progress, skipping...");return}f.current=!0,i(!0),d(null);try{const C=await m.current.refreshProgress();a(C)}catch(C){d(C)}finally{i(!1),f.current=!1}}},[]),g=o.useCallback(async()=>{if(m.current){i(!0),d(null);try{const C=await m.current.moveToNextStep();a(C)}catch(C){d(C)}finally{i(!1)}}},[]),I=o.useCallback(async()=>{if(m.current){i(!0),d(null);try{const C=await m.current.moveToPreviousStep();a(C)}catch(C){d(C)}finally{i(!1)}}},[]),E=o.useCallback(async C=>{if(m.current){i(!0),d(null);try{await m.current.submitCurrentStep(C);const A=await m.current.refreshProgress();a(A)}catch(A){throw d(A),A}finally{i(!1)}}},[]),j=rt.useMemo(()=>s!=null&&s.stepInfoList?[...s.stepInfoList].sort((C,A)=>C.order-A.order):[],[s==null?void 0:s.stepInfoList]),M=rt.useMemo(()=>s?s.nextWorkflowKey&&s.nextWorkflowKey!==s.workFlowKey:!1,[s]);return{progress:s,applicantId:u,currentStep:(s==null?void 0:s.currentStep)||null,steps:j,status:(s==null?void 0:s.status)||be.None,workflowResult:(s==null?void 0:s.workflowResult)||null,workflowKey:s==null?void 0:s.workFlowKey,nextWorkflowKey:s==null?void 0:s.nextWorkflowKey,hasWorkflowChanged:M,isLoading:n,error:l,isComplete:(s==null?void 0:s.status)===be.Finished,isOnHold:(s==null?void 0:s.status)===be.OnHold,refreshProgress:b,moveToNext:g,moveBack:I,submitCurrentStep:E,orchestrator:m.current}}function Xt(t){const{questionnaireService:r,applicantService:s}=xe(),[a,n]=o.useState(null),[i,l]=o.useState({}),[d,m]=o.useState(!1),[u,f]=o.useState(!1),[S,p]=o.useState(null),b=o.useRef(!1),g=o.useRef(null),I=o.useCallback(async()=>{var j,M;if(t){if(b.current){console.log("[Questionnaire] Load already in progress, skipping...");return}b.current=!0,m(!0),p(null);try{const[C,A]=await Promise.all([r.getQuestionnaire(t),s.getApplicantData(t).catch(()=>null)]);if(n(C),(j=A==null?void 0:A.questionnaireResults)!=null&&j.length&&C){const q=new Map;for(const k of A.questionnaireResults)k.question&&((M=k.answers)!=null&&M.length)&&q.set(k.question.trim().toLowerCase(),k.answers);const W={},N=C.questionGroups.flatMap(k=>k.questions??[]);for(const k of N){const w=k.text.trim().toLowerCase();q.has(w)&&(W[k.id]=q.get(w))}l(W)}g.current=t}catch(C){p(C)}finally{m(!1),b.current=!1}}},[t,r,s]);o.useEffect(()=>{t&&g.current!==t&&I()},[t]);const E=o.useCallback(async j=>{f(!0),p(null);try{return await r.fillQuestionnaire(j)}catch(M){throw p(M),M}finally{f(!1)}},[r]);return{questionnaire:a,initialAnswers:i,isLoading:d,isSubmitting:u,error:S,load:I,submit:E}}function er(t){const{uploadDocumentService:r}=xe(),[s,a]=o.useState(null),[n,i]=o.useState(!1),[l,d]=o.useState(!1),[m,u]=o.useState(0),[f,S]=o.useState(null),p=o.useRef(!1),b=o.useRef(null),g=o.useCallback(async()=>{if(t){if(p.current){console.log("[UploadDocument] Load already in progress, skipping...");return}p.current=!0,i(!0),S(null);try{const E=await r.getUploadDocument(t);a(E),b.current=t}catch(E){S(E)}finally{i(!1),p.current=!1}}},[t,r]);o.useEffect(()=>{t&&b.current!==t&&g()},[t]);const I=o.useCallback(async E=>{d(!0),u(0),S(null);try{await r.fillUploadDocument(E),u(100)}catch(j){throw S(j),j}finally{d(!1)}},[r]);return{uploadDocument:s,isLoading:n,isSubmitting:l,uploadProgress:m,error:f,load:g,submit:I}}function Fr(t){const{appropriatenessTestService:r}=xe(),[s,a]=o.useState(null),[n,i]=o.useState(!1),[l,d]=o.useState(!1),[m,u]=o.useState(null),[f,S]=o.useState(null),p=o.useRef(!1),b=o.useRef(null),g=o.useCallback(async()=>{if(t){if(p.current){console.log("[AppropriatenessTest] Load already in progress, skipping...");return}p.current=!0,i(!0),u(null);try{const E=await r.getAppropriatenessTest(t);a(E),b.current=t}catch(E){u(E)}finally{i(!1),p.current=!1}}},[t,r]);o.useEffect(()=>{t&&b.current!==t&&g()},[t]);const I=o.useCallback(async E=>{d(!0),u(null);try{const j=await r.fillAppropriatenessTest(E);return S(j),j}catch(j){throw u(j),j}finally{d(!1)}},[r]);return{test:s,result:f,isLoading:n,isSubmitting:l,error:m,load:g,submit:I}}function tr(t){const{overviewService:r}=xe(),[s,a]=o.useState(null),[n,i]=o.useState(!1),[l,d]=o.useState(!1),[m,u]=o.useState(null),f=o.useRef(!1),S=o.useRef(null),p=o.useCallback(async()=>{if(t){if(f.current){console.log("[Overview] Load already in progress, skipping...");return}f.current=!0,i(!0),u(null);try{const g=await r.getOverviewData(t);a(g),S.current=t}catch(g){u(g)}finally{i(!1),f.current=!1}}},[t,r]);o.useEffect(()=>{t&&S.current!==t&&p()},[t]);const b=o.useCallback(async()=>{if(t){d(!0),u(null);try{await r.passOverview(t)}catch(g){throw u(g),g}finally{d(!1)}}},[t,r]);return{overview:s,isLoading:n,isSubmitting:l,error:m,load:p,passOverview:b}}function rr(t){const{identityService:r}=xe(),[s,a]=o.useState(null),[n,i]=o.useState(!1),[l,d]=o.useState(null),m=o.useRef(!1),u=o.useCallback(async(p,b)=>{if(t){if(m.current){console.log("[Identity] Request already in progress, skipping...");return}m.current=!0,i(!0),d(null);try{const g={applicantId:t,restart:!1,redirectUrl:p||"",ttl:b||604800};console.log("Identity request input:",g);const I=await r.identityRequest(g);return console.log("Identity request result:",I),a(I),I}catch(g){throw d(g),g}finally{i(!1),m.current=!1}}},[t,r]),f=o.useCallback(async(p,b)=>{if(t){i(!0),d(null);try{const g={applicantId:t,restart:!1,redirectUrl:p,ttl:b},I=await r.identityCompanyRequest(g);return a(I),I}catch(g){throw d(g),g}finally{i(!1)}}},[t,r]),S=o.useCallback(async()=>{if(t){if(m.current){console.log("[Identity] Restart already in progress, skipping...");return}m.current=!0,i(!0),d(null);try{const p={applicantId:t,restart:!0,redirectUrl:"",ttl:604800};console.log("Restarting identity with input:",p);const b=await r.identityRequest(p);return console.log("Restart identity result:",b),a(b),b}catch(p){throw d(p),p}finally{i(!1),m.current=!1}}},[t,r]);return{identityData:s,provider:(s==null?void 0:s.provider)||null,token:(s==null?void 0:s.publicProviderTokenObject)||null,isLoading:n,error:l,requestIdentity:u,requestCompanyIdentity:f,restartIdentity:S}}function sr(t){const{riskScoringService:r,applicantService:s}=xe(),[a,n]=o.useState(null),[i,l]=o.useState({}),[d,m]=o.useState(!1),[u,f]=o.useState(!1),[S,p]=o.useState(null),[b,g]=o.useState(null),I=o.useRef(!1),E=o.useRef(null),j=o.useCallback(async()=>{var C;if(t){if(I.current){console.log("[RiskScoring] Load already in progress, skipping...");return}I.current=!0,m(!0),p(null);try{const[A,q]=await Promise.all([r.getRiskCriterias(t),s.getApplicantData(t).catch(()=>null)]);if(n(A),(C=q==null?void 0:q.riskScoringResults)!=null&&C.length){const W=q.riskScoringResults[0],N={};for(const k of W.riskCriteriaResults??[])if(k.riskCriteriaId!=null&&k.answer!=null&&k.answer!==""){const w=[...new Set(k.answer.split(",").map(T=>T.trim()).filter(T=>T!==""))];w.length>0&&(N[k.riskCriteriaId]=w)}l(N)}E.current=t}catch(A){p(A)}finally{m(!1),I.current=!1}}},[t,r,s]);o.useEffect(()=>{t&&E.current!==t&&j()},[t]);const M=o.useCallback(async C=>{f(!0),p(null);try{const A=await r.submitRiskScoring(C);return g(A),A}catch(A){throw p(A),A}finally{f(!1)}},[r]);return{criteria:a,initialAnswers:i,result:b,isLoading:d,isSubmitting:u,error:S,load:j,submit:M}}function ar(){const{applicantService:t,config:r}=xe(),[s,a]=o.useState(!1),[n,i]=o.useState(null),l=o.useRef(!1),d=o.useRef(!1),m=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(b){const g=Math.random()*16|0;return(b==="x"?g:g&3|8).toString(16)}),u=o.useCallback(async b=>{var g;if(l.current)throw console.log("[Applicant] Create already in progress, skipping..."),new Error("Creation already in progress");l.current=!0,a(!0),i(null);try{if(b.applicantAdditionalDatas||(b.applicantAdditionalDatas=[]),(g=r.identityProviders)!=null&&g.sardinai){const E=m();console.log("[SardinAI] Generated session key:",E),b.applicantAdditionalDatas.push({paramName:"sessionKey",value:E})}return await t.createApplicant(b)}catch(I){throw i(I),I}finally{a(!1),l.current=!1}},[t,r]),f=o.useCallback(async b=>{a(!0),i(null);try{return await t.createCompanyApplicant(b)}catch(g){throw i(g),g}finally{a(!1)}},[t]),S=o.useCallback(async b=>{if(d.current)throw console.log("[Applicant] Data load already in progress, skipping..."),new Error("Data load already in progress");d.current=!0,a(!0),i(null);try{return await t.getApplicantData(b)}catch(g){throw i(g),g}finally{a(!1),d.current=!1}},[t]),p=o.useCallback(async b=>{a(!0),i(null);try{await t.stopProgress(b)}catch(g){throw i(g),g}finally{a(!1)}},[t]);return{isLoading:s,error:n,createApplicant:u,createCompanyApplicant:f,getApplicantData:S,stopProgress:p}}const K=({children:t,variant:r="primary",size:s="md",isLoading:a=!1,disabled:n,className:i,...l})=>{const d="inline-flex items-center justify-center rounded-lg font-medium transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed",m={primary:"bg-primary-500 text-white hover:bg-primary-600 focus:ring-primary-500",secondary:"bg-gray-200 text-gray-900 hover:bg-gray-300 focus:ring-gray-400",outline:"border-2 border-primary-500 text-primary-500 hover:bg-primary-50 focus:ring-primary-500",danger:"bg-danger-500 text-white hover:bg-danger-600 focus:ring-danger-500",ghost:"text-gray-700 hover:bg-gray-100 focus:ring-gray-400"},u={sm:"px-3 py-1.5 text-sm",md:"px-4 py-2 text-base",lg:"px-6 py-3 text-lg"};return e.jsxs("button",{className:ie(d,m[r],u[s],i),disabled:n||a,...l,children:[a&&e.jsxs("svg",{className:"animate-spin -ml-1 mr-2 h-4 w-4",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),t]})},ue=o.forwardRef(({label:t,error:r,helperText:s,leftIcon:a,rightIcon:n,className:i,style:l,...d},m)=>e.jsxs("div",{className:"w-full",children:[t&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[t,d.required&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),e.jsxs("div",{className:"relative",children:[a&&e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:a}),e.jsx("input",{ref:m,className:ie("block w-full rounded-lg border px-3 py-2 text-sm transition-colors","focus:outline-none focus:ring-2 focus:ring-offset-0","disabled:opacity-60 disabled:cursor-not-allowed",a?"pl-10":"",n?"pr-10":"",i),style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:"var(--metakyc-text-primary, #111827)",borderColor:r?"var(--metakyc-danger, #ef4444)":"var(--metakyc-border, #d1d5db)",...l},...d}),n&&e.jsx("div",{className:"absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none",children:n})]}),r&&e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-danger, #ef4444)"},children:r}),!r&&s&&e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:s})]}));ue.displayName="Input";const H=({children:t,className:r,...s})=>e.jsx("div",{className:ie("metakyc-card rounded-xl shadow-sm border",r),style:{backgroundColor:"var(--metakyc-surface, #ffffff)",borderColor:"var(--metakyc-border, #e5e7eb)"},...s,children:t}),le=({children:t,className:r,...s})=>e.jsx("div",{className:ie("px-6 py-4 border-b",r),style:{borderColor:"var(--metakyc-border, #e5e7eb)"},...s,children:t}),U=({children:t,className:r,...s})=>e.jsx("div",{className:ie("px-6 py-4",r),...s,children:t}),me=({children:t,className:r,...s})=>e.jsx("div",{className:ie("px-6 py-4 border-t",r),style:{borderColor:"var(--metakyc-border, #e5e7eb)"},...s,children:t}),Ne=({children:t,variant:r="default",className:s,...a})=>{const n={default:"bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-300",success:"bg-success-100 text-success-800 dark:bg-success-900 dark:text-success-300",danger:"bg-danger-100 text-danger-800 dark:bg-danger-900 dark:text-danger-300",warning:"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300",info:"bg-primary-100 text-primary-800 dark:bg-primary-900 dark:text-primary-300"};return e.jsx("span",{className:ie("inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium",n[r],s),...a,children:t})},ve=({size:t="md",className:r,...s})=>{const a={sm:"h-4 w-4",md:"h-8 w-8",lg:"h-12 w-12"};return e.jsx("div",{className:ie("flex items-center justify-center",r),...s,children:e.jsxs("svg",{className:ie("animate-spin text-primary-500",a[t]),xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})})},Ge=o.forwardRef(({label:t,error:r,helperText:s,options:a,placeholder:n,className:i,style:l,...d},m)=>e.jsxs("div",{className:"w-full",children:[t&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[t,d.required&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),e.jsxs("select",{ref:m,className:ie("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":"",i),style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:"var(--metakyc-text-primary, #111827)",borderColor:r?"var(--metakyc-error, #ef4444)":"var(--metakyc-border, #d1d5db)",...l},...d,children:[n&&e.jsx("option",{value:"",disabled:!0,style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:"var(--metakyc-text-secondary, #6b7280)"},children:n},"__placeholder__"),a.map((u,f)=>e.jsx("option",{value:u.value,disabled:u.disabled,style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:u.disabled?"var(--metakyc-text-secondary, #9ca3af)":"var(--metakyc-text-primary, #111827)"},children:u.label},u.value||`option-${f}`))]}),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})]}));Ge.displayName="Select";const st=280,nr=({label:t,value:r,onChange:s,options:a,placeholder:n="Select...",disabled:i=!1,required:l=!1})=>{const[d,m]=o.useState(!1),[u,f]=o.useState(""),[S,p]=o.useState(null),b=o.useRef(null),g=o.useRef(null),I=o.useRef(null),E=o.useCallback(()=>{if(!g.current)return null;const v=g.current.getBoundingClientRect(),X=window.innerHeight-v.bottom<st&&v.top>st;return{top:X?v.top:v.bottom+4,left:v.left,width:v.width,openUp:X}},[]),j=o.useCallback(()=>{if(i)return;const v=E();v&&p(v),m(!0)},[i,E]),M=o.useCallback(()=>{m(!1),f("")},[]);o.useEffect(()=>{if(!d)return;const v=_=>{var we,se;const X=_.target;!((we=b.current)!=null&&we.contains(X))&&!((se=I.current)!=null&&se.contains(X))&&M()};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[d,M]),o.useEffect(()=>{if(!d)return;const v=()=>{const _=E();_&&p(_)};return window.addEventListener("scroll",v,!0),window.addEventListener("resize",v),()=>{window.removeEventListener("scroll",v,!0),window.removeEventListener("resize",v)}},[d,E]);const C=a.filter(v=>v.label.toLowerCase().includes(u.toLowerCase())),A=v=>{i||s(r.includes(v)?r.filter(_=>_!==v):[...r,v])},q=(v,_)=>{_.stopPropagation(),i||s(r.filter(X=>X!==v))},W=v=>{var _;return((_=a.find(X=>X.value===v))==null?void 0:_.label)||v},N=g.current?getComputedStyle(g.current):null,k=(N==null?void 0:N.getPropertyValue("--metakyc-input-bg").trim())||"#ffffff",w=(N==null?void 0:N.getPropertyValue("--metakyc-border").trim())||"#d1d5db",T=(N==null?void 0:N.getPropertyValue("--metakyc-text-primary").trim())||"#111827",F=(N==null?void 0:N.getPropertyValue("--metakyc-text-secondary").trim())||"#6b7280",Y=(N==null?void 0:N.getPropertyValue("--metakyc-primary").trim())||"#2563eb",O=(N==null?void 0:N.getPropertyValue("--metakyc-primary-light").trim())||"#eff6ff",D=(N==null?void 0:N.getPropertyValue("--metakyc-hover-bg").trim())||"#f9fafb",G=d&&S&&e.jsxs("div",{ref:I,className:"metakyc-multiselect-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 ${w}`,backgroundColor:k,overflow:"hidden"},children:[e.jsx("div",{style:{padding:"8px",borderBottom:`1px solid ${w}`},children:e.jsx("input",{type:"text",value:u,onChange:v=>f(v.target.value),placeholder:"Search...",autoFocus:!0,onClick:v=>v.stopPropagation(),className:"metakyc-multiselect-search w-full",style:{display:"block",width:"100%",padding:"6px 8px",fontSize:"13px",borderRadius:"6px",border:`1px solid ${w}`,backgroundColor:k,color:T,outline:"none",boxSizing:"border-box"}})}),e.jsx("ul",{style:{listStyle:"none",margin:0,padding:"4px 0",maxHeight:"192px",overflowY:"auto"},children:C.length===0?e.jsx("li",{style:{padding:"8px 12px",fontSize:"13px",color:F},children:"No results"}):C.map(v=>{const _=r.includes(v.value);return e.jsxs("li",{onClick:()=>A(v.value),className:"metakyc-multiselect-option",style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",fontSize:"13px",cursor:"pointer",backgroundColor:_?O:"transparent",color:_?Y:T,userSelect:"none"},onMouseEnter:X=>{_||(X.currentTarget.style.backgroundColor=D)},onMouseLeave:X=>{_||(X.currentTarget.style.backgroundColor="transparent")},children:[e.jsx("input",{type:"checkbox",checked:_,readOnly:!0,style:{accentColor:Y,pointerEvents:"none",flexShrink:0}}),e.jsx("span",{children:v.label})]},v.value)})}),r.length>0&&e.jsx("div",{style:{padding:"6px 12px",borderTop:`1px solid ${w}`},children:e.jsxs("button",{type:"button",onClick:()=>{s([]),f("")},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:b,children:[t&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[t,l&&e.jsx("span",{style:{color:"var(--metakyc-error, #ef4444)",marginLeft:"4px"},children:"*"})]}),e.jsxs("div",{ref:g,onClick:()=>d?M():j(),className:ie("metakyc-multiselect-trigger","min-h-[42px] w-full px-3 py-2 rounded-lg border text-sm transition-colors relative",i?"opacity-50 cursor-not-allowed":"cursor-pointer"),style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",borderColor:d?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #d1d5db)",outline:d?"2px solid var(--metakyc-primary, #2563eb)":"none",outlineOffset:"-1px"},children:[r.length===0?e.jsx("span",{className:"metakyc-multiselect-placeholder leading-6",style:{color:"var(--metakyc-text-secondary, #9ca3af)"},children:n}):e.jsx("div",{className:"flex flex-wrap gap-1 pr-6",children:r.map(v=>e.jsxs("span",{className:"metakyc-multiselect-chip inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium",style:{backgroundColor:"var(--metakyc-primary-light, #eff6ff)",color:"var(--metakyc-primary, #2563eb)"},children:[W(v),!i&&e.jsx("button",{type:"button",onClick:_=>q(v,_),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:"×"})]},v))}),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:d?"▲":"▼"})]}),typeof document<"u"&&G?Ze.createPortal(G,document.body):null]})},at=260,Te=({label:t,error:r,helperText:s,options:a,placeholder:n="Select...",value:i,onChange:l,disabled:d=!1,required:m=!1,className:u})=>{var se;const[f,S]=o.useState(!1),[p,b]=o.useState(""),[g,I]=o.useState(null),E=o.useRef(null),j=o.useRef(null),M=o.useRef(null),C=o.useRef(null),A=o.useCallback(()=>{if(!j.current)return null;const P=j.current.getBoundingClientRect(),ae=window.innerHeight-P.bottom<at&&P.top>at;return{top:ae?P.top:P.bottom+4,left:P.left,width:P.width,openUp:ae}},[]),q=o.useCallback(()=>{if(d)return;const P=A();P&&I(P),S(!0)},[d,A]),W=o.useCallback(()=>{S(!1),b("")},[]),N=()=>f?W():q();o.useEffect(()=>{if(!f)return;const P=te=>{var Ae,Re;const ae=te.target;!((Ae=E.current)!=null&&Ae.contains(ae))&&!((Re=M.current)!=null&&Re.contains(ae))&&W()};return document.addEventListener("mousedown",P),()=>document.removeEventListener("mousedown",P)},[f,W]),o.useEffect(()=>{if(!f)return;const P=()=>{const te=A();te&&I(te)};return window.addEventListener("scroll",P,!0),window.addEventListener("resize",P),()=>{window.removeEventListener("scroll",P,!0),window.removeEventListener("resize",P)}},[f,A]),o.useEffect(()=>{f&&C.current&&setTimeout(()=>{var P;return(P=C.current)==null?void 0:P.focus()},0)},[f]);const k=a.filter(P=>P.label.toLowerCase().includes(p.toLowerCase())||P.value.toLowerCase().includes(p.toLowerCase())),w=(se=a.find(P=>P.value===i))==null?void 0:se.label,T=(P,te)=>{d||te||(l(P),W())},F=j.current?getComputedStyle(j.current):null,Y=(F==null?void 0:F.getPropertyValue("--metakyc-input-bg").trim())||"#ffffff",O=(F==null?void 0:F.getPropertyValue("--metakyc-border").trim())||"#d1d5db",D=(F==null?void 0:F.getPropertyValue("--metakyc-text-primary").trim())||"#111827",G=(F==null?void 0:F.getPropertyValue("--metakyc-text-secondary").trim())||"#6b7280",v=(F==null?void 0:F.getPropertyValue("--metakyc-primary").trim())||"#2563eb",_=(F==null?void 0:F.getPropertyValue("--metakyc-primary-light").trim())||"#eff6ff",X=(F==null?void 0:F.getPropertyValue("--metakyc-hover-bg").trim())||"#f9fafb",we=f&&g&&e.jsxs("div",{ref:M,className:"metakyc-searchable-select-dropdown",style:{position:"fixed",top:g.openUp?void 0:g.top,bottom:g.openUp?window.innerHeight-g.top+4:void 0,left:g.left,width:g.width,zIndex:99999,borderRadius:"8px",boxShadow:"0 4px 16px rgba(0,0,0,0.18)",border:`1px solid ${O}`,backgroundColor:Y,overflow:"hidden"},children:[e.jsx("div",{style:{padding:"8px",borderBottom:`1px solid ${O}`},children:e.jsx("input",{ref:C,type:"text",value:p,onChange:P=>b(P.target.value),placeholder:"Search...",onClick:P=>P.stopPropagation(),className:"metakyc-searchable-select-search w-full",style:{display:"block",width:"100%",padding:"6px 8px",fontSize:"13px",borderRadius:"6px",border:`1px solid ${O}`,backgroundColor:Y,color:D,outline:"none",boxSizing:"border-box"}})}),e.jsx("ul",{style:{listStyle:"none",margin:0,padding:"4px 0",maxHeight:"208px",overflowY:"auto"},children:k.length===0?e.jsx("li",{style:{padding:"8px 12px",fontSize:"13px",color:G},children:"No results"}):k.map(P=>{const te=P.value===i;return e.jsx("li",{className:"metakyc-searchable-select-option",onClick:()=>T(P.value,P.disabled),style:{padding:"8px 12px",fontSize:"13px",cursor:P.disabled?"not-allowed":"pointer",opacity:P.disabled?.4:1,backgroundColor:te?_:"transparent",color:te?v:D,userSelect:"none"},onMouseEnter:ae=>{!te&&!P.disabled&&(ae.currentTarget.style.backgroundColor=X)},onMouseLeave:ae=>{te||(ae.currentTarget.style.backgroundColor="transparent")},children:P.label},P.value)})})]});return e.jsxs("div",{className:ie("w-full metakyc-searchable-select",u),ref:E,children:[t&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[t,m&&e.jsx("span",{style:{color:"var(--metakyc-error, #ef4444)",marginLeft:"4px"},children:"*"})]}),e.jsxs("div",{ref:j,role:"button",tabIndex:d?-1:0,onClick:N,onKeyDown:P=>{(P.key==="Enter"||P.key===" ")&&(P.preventDefault(),N()),P.key==="Escape"&&W()},className:ie("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",d?"opacity-60 cursor-not-allowed":"cursor-pointer"),style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:w?"var(--metakyc-text-primary, #111827)":"var(--metakyc-text-secondary, #9ca3af)",borderColor:r?"var(--metakyc-error, #ef4444)":f?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #d1d5db)",minHeight:"42px",outline:f?"2px solid var(--metakyc-primary, #2563eb)":"none",outlineOffset:"-1px"},children:[e.jsx("span",{className:"truncate flex-1",children:w||n}),e.jsx("span",{className:"flex-shrink-0 text-xs pointer-events-none",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:f?"▲":"▼"})]}),typeof document<"u"&&we?Ze.createPortal(we,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})]})};Te.displayName="SearchableSelect";const ir=({label:t,error:r,accept:s,multiple:a=!1,maxSize:n,onChange:i,value:l=[],className:d})=>{const[m,u]=o.useState(!1),f=o.useRef(null),S=j=>{if(!j)return;const M=Array.from(j);if(n&&M.filter(A=>A.size>n).length>0){const A=qe(n);alert(`Some files exceed the maximum size of ${A}`);return}i==null||i(a?[...l,...M]:[M[0]])},p=j=>{j.preventDefault(),u(!0)},b=()=>{u(!1)},g=j=>{j.preventDefault(),u(!1),S(j.dataTransfer.files)},I=()=>{var j;(j=f.current)==null||j.click()},E=j=>{const M=l.filter((C,A)=>A!==j);i==null||i(M)};return e.jsxs("div",{className:ie("w-full",d),children:[t&&e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:t}),e.jsxs("div",{className:ie("border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors",m?"border-primary-500 bg-primary-50 dark:bg-primary-900/20":"border-gray-300 dark:border-gray-600 hover:border-primary-500",r&&"border-danger-500"),onDragOver:p,onDragLeave:b,onDrop:g,onClick:I,children:[e.jsx("input",{ref:f,type:"file",className:"hidden",accept:s,multiple:a,onChange:j=>S(j.target.files)}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("svg",{className:"mx-auto h-12 w-12 text-gray-400",stroke:"currentColor",fill:"none",viewBox:"0 0 48 48",children:e.jsx("path",{d:"M28 8H12a4 4 0 00-4 4v20m32-12v8m0 0v8a4 4 0 01-4 4H12a4 4 0 01-4-4v-4m32-4l-3.172-3.172a4 4 0 00-5.656 0L28 28M8 32l9.172-9.172a4 4 0 015.656 0L28 28m0 0l4 4m4-24h8m-4-4v8m-12 4h.02",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"})}),e.jsxs("div",{className:"text-sm text-gray-600 dark:text-gray-400",children:[e.jsx("span",{className:"font-medium text-primary-500",children:"Click to upload"})," or drag and drop"]}),n&&e.jsxs("p",{className:"text-xs text-gray-500",children:["Maximum file size: ",qe(n)]})]})]}),l.length>0&&e.jsx("div",{className:"mt-3 space-y-2",children:l.map((j,M)=>e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 bg-gray-50 dark:bg-gray-700 rounded-lg",children:[e.jsxs("div",{className:"flex items-center space-x-2 flex-1 min-w-0",children:[e.jsx("svg",{className:"h-5 w-5 text-gray-400 flex-shrink-0",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M4 4a2 2 0 012-2h4.586A2 2 0 0112 2.586L15.414 6A2 2 0 0116 7.414V16a2 2 0 01-2 2H6a2 2 0 01-2-2V4z",clipRule:"evenodd"})}),e.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300 truncate",children:j.name}),e.jsxs("span",{className:"text-xs text-gray-500",children:["(",qe(j.size),")"]})]}),e.jsx("button",{type:"button",onClick:C=>{C.stopPropagation(),E(M)},className:"ml-2 text-danger-500 hover:text-danger-700 focus:outline-none",children:e.jsx("svg",{className:"h-5 w-5",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",clipRule:"evenodd"})})})]},M))}),r&&e.jsx("p",{className:"mt-1 text-sm text-danger-500",children:r})]})},or=o.forwardRef(({countryCode:t="+1",onCountryCodeChange:r,className:s,...a},n)=>e.jsxs("div",{className:"w-full",children:[a.label&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[a.label,a.required&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:t,onChange:i=>r==null?void 0:r(i.target.value),className:ie("w-20 rounded-lg border px-3 py-2 text-sm","focus:outline-none focus:ring-2 focus:ring-offset-0"),style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:"var(--metakyc-text-primary, #111827)",borderColor:"var(--metakyc-border, #d1d5db)"},placeholder:"+1"}),e.jsx(ue,{ref:n,type:"tel",className:ie("flex-1",s),...a,label:""})]}),a.error&&e.jsx("p",{className:"mt-1 text-sm text-danger-500",children:a.error})]}));or.displayName="PhoneInput";/**
|
|
1
|
+
"use strict";var vr=Object.defineProperty;var kr=(t,r,s)=>r in t?vr(t,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[r]=s;var ee=(t,r,s)=>kr(t,typeof r!="symbol"?r+"":r,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const wr=require("axios"),o=require("react"),e=require("react/jsx-runtime"),Ge=require("react-dom"),Ne=require("react-hook-form"),Se=require("zod");function jr(t){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const a=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(r,s,a.get?a:{enumerable:!0,get:()=>t[s]})}}return r.default=t,Object.freeze(r)}const rt=jr(o);var G=(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))(G||{}),_e=(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))(_e||{}),ye=(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))(ye||{}),ot=(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))(ot||{}),lt=(t=>(t[t.LowRisk=0]="LowRisk",t[t.MediumRisk=1]="MediumRisk",t[t.HighRisk=2]="HighRisk",t[t.Alert=3]="Alert",t))(lt||{}),Ce=(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))(Ce||{}),Re=(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))(Re||{}),ct=(t=>(t[t.ProviderResultPending=0]="ProviderResultPending",t[t.ProviderResultReceived=1]="ProviderResultReceived",t[t.Canceled=2]="Canceled",t[t.ExtendedToNewApplicant=3]="ExtendedToNewApplicant",t))(ct||{}),dt=(t=>(t[t.None=0]="None",t[t.ProviderResultPending=1]="ProviderResultPending",t[t.ProviderResultReceived=2]="ProviderResultReceived",t[t.Canceled=3]="Canceled",t))(dt||{}),ge=(t=>(t[t.Onfido=0]="Onfido",t[t.Sumsub=2]="Sumsub",t[t.SardinAI=3]="SardinAI",t))(ge||{}),ut=(t=>(t[t.Individual=0]="Individual",t[t.Company=1]="Company",t))(ut||{}),He=(t=>(t[t.Male=0]="Male",t[t.Female=1]="Female",t[t.Other=2]="Other",t))(He||{}),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||{}),pt=(t=>(t[t.Pending=0]="Pending",t[t.Approved=1]="Approved",t[t.Rejected=2]="Rejected",t[t.RequiresRevision=3]="RequiresRevision",t))(pt||{}),ht=(t=>(t[t.SingleChoice=0]="SingleChoice",t[t.MultipleChoice=1]="MultipleChoice",t[t.Text=2]="Text",t))(ht||{}),je=(t=>(t[t.String=0]="String",t[t.Integer=1]="Integer",t[t.Decimal=2]="Decimal",t[t.Boolean=3]="Boolean",t[t.Date=4]="Date",t[t.Country=5]="Country",t[t.DigitOnly=6]="DigitOnly",t))(je||{}),xt=(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))(xt||{}),gt=(t=>(t[t.None=0]="None",t[t.Country=1]="Country",t))(gt||{}),pe=(t=>(t[t.Individual=0]="Individual",t[t.Sophisticated=1]="Sophisticated",t[t.HighNetWorth=2]="HighNetWorth",t[t.Business=3]="Business",t))(pe||{}),yt=(t=>(t[t.Retail=0]="Retail",t[t.Professional=1]="Professional",t[t.EligibleCounterparty=2]="EligibleCounterparty",t))(yt||{});const Fe={Nationality:10,Address:20,CountryOfBirth:30,PhoneNumber:40,UboAddress:50},Ae={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:Fe.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:Fe.Address},nationality:{label:"Nationality",type:"select",countriesType:Fe.Nationality},otherNationality:{label:"Other Nationalities",type:"multiselect",countriesType:Fe.Nationality},countryOfBirth:{label:"Country of Birth",type:"select",countriesType:Fe.CountryOfBirth},placeOfBirth:{label:"Place of Birth",type:"text"},taxCountry:{label:"Tax Country",type:"select",countriesType:Fe.Address},taxNumber:{label:"Tax Number",type:"text"},defaultLanguage:{label:"Default Language",type:"select"},educationLevel:{label:"Education Level",type:"text"},occupation:{label:"Occupation",type:"text"}},ft=["firstName","lastName","email","phonenumber","dateOfBirth"],Ze=[{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 ne=(t=>(t.Default="default",t.Corporate="corporate",t.Fintech="fintech",t.Healthcare="healthcare",t.Modern="modern",t.Minimal="minimal",t))(ne||{});const bt={timeout:3e4,retries:3,locale:"en",endpoints:{pattern:"host-controller"}};class vt{constructor(r){this.config=r}build(r,s){const a=`${r}.${s}`;if(this.config.customPaths&&this.config.customPaths[a])return this.config.customPaths[a];switch(this.config.pattern){case"host-controller":return`/api/${r}/${s}`;case"application-service":return`/services/app/${this.getServiceName(r)}/${s}`;case"custom":throw new Error(`Custom endpoint path not found for ${a}. Please provide it in customPaths.`);default:throw new Error(`Unknown endpoint pattern: ${this.config.pattern}`)}}getServiceName(r){return{Applicant:"MetaKYCVerification",Questionnaire:"MetaKYCVerification",UploadDocument:"MetaKYCVerification",AppropriatenessTest:"MetaKYCVerification",BaseInformation:"MetaKYCVerification"}[r]||r}}class ke extends Error{constructor(s,a,n,i,d){super(s);ee(this,"response");this.code=a,this.details=n,this.validationErrors=i,this.name="MetaKYCError",this.response=d,Object.setPrototypeOf(this,ke.prototype)}}class De{static handleApiError(r){return new ke(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 ke(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 ke(s.result.message,r.response.status,`HTTP ${r.response.status}: ${r.response.statusText}`,void 0,r.response):new ke((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 ke("No response from server",0,"The request was made but no response was received. Please check your network connection."):new ke(r.message||"An unexpected error occurred",0,r.toString())}static isMetaKYCError(r){return r instanceof ke}}class kt{constructor(r){ee(this,"axiosInstance");ee(this,"endpointBuilder");ee(this,"config");this.config={...bt,...r},this.endpointBuilder=new vt(this.config.endpoints),this.axiosInstance=wr.create({baseURL:this.config.baseUrl,timeout:this.config.timeout,headers:{"Content-Type":"application/json"}}),this.axiosInstance.interceptors.request.use(s=>(s.headers["Abp-TenantId"]=this.config.tenantId.toString(),s.headers.ApiKey=this.config.apiKey,s.headers["X-API-KEY"]=this.config.apiKey,this.config.locale&&(s.headers["Accept-Language"]=this.config.locale),s),s=>Promise.reject(s)),this.axiosInstance.interceptors.response.use(s=>s,async s=>{var n;const a=s.config;return((n=s.response)==null?void 0:n.status)>=500&&!a._retry&&(a._retry=!0,a._retryCount=(a._retryCount||0)+1,a._retryCount<(this.config.retries||3))?(await new Promise(i=>setTimeout(i,1e3*a._retryCount)),this.axiosInstance(a)):Promise.reject(s)})}buildEndpoint(r,s){return this.endpointBuilder.build(r,s)}async get(r,s,a){try{const n=this.buildEndpoint(r,s),i=await this.axiosInstance.get(n,{params:a});return this.handleResponse(i)}catch(n){throw De.handleAxiosError(n)}}async post(r,s,a){try{const n=this.buildEndpoint(r,s),i=await this.axiosInstance.post(n,a);return this.handleResponse(i)}catch(n){throw De.handleAxiosError(n)}}async put(r,s,a){try{const n=this.buildEndpoint(r,s),i=await this.axiosInstance.put(n,a);return this.handleResponse(i)}catch(n){throw De.handleAxiosError(n)}}async delete(r,s,a){try{const n=this.buildEndpoint(r,s),i=await this.axiosInstance.delete(n,{params:a});return this.handleResponse(i)}catch(n){throw De.handleAxiosError(n)}}handleResponse(r){const s=r.data;if(!s.success&&s.error)throw De.handleApiError(s.error);return s}getAxiosInstance(){return this.axiosInstance}}class wt{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 jt{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 St{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 Nt{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 Ct{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 Rt{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 At{constructor(r){this.httpClient=r}async identityRequest(r){console.log("[IdentityService] Calling IdentityRequest with input:",r);const s=await this.httpClient.post("Applicant","IdentityRequest",r);return console.log("[IdentityService] IdentityRequest response:",s),s.result}async identityCompanyRequest(r){return(await this.httpClient.post("Applicant","IdentityCompanyRequest",r)).result}async restartIdentityRequest(r){const s={applicantId:r,restart:!0,redirectUrl:"",ttl:604800};return console.log("[IdentityService] Restarting identity with restart=true:",s),this.identityRequest(s)}async restartIdentityCompanyRequest(r){const s={applicantId:r,restart:!0,redirectUrl:"",ttl:604800};return this.identityCompanyRequest(s)}}class Et{constructor(r){this.httpClient=r}async getCountries(r,s,a){return(await this.httpClient.get("BaseInformation","GetAllCountries",{filter:r||"",lng:s||"en",type:a})).result}async getBranches(){return(await this.httpClient.get("BaseInformation","GetBranches")).result}async getLegalEntities(){return(await this.httpClient.get("BaseInformation","GetLegalEntities")).result}}class It{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 de={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"}}},Pt={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"}},Ft={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"}},Tt={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"}}},Lt={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"}},Dt={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"}},Mt={[ne.Default]:de,[ne.Corporate]:Pt,[ne.Fintech]:Ft,[ne.Healthcare]:Tt,[ne.Modern]:Lt,[ne.Minimal]:Dt};function Me(t){return Mt[t]||de}class Ot{constructor(r){this.httpClient=r}async getThemeConfiguration(){var r;try{const s=await this.httpClient.get("Tenant","GetThemeConfiguration");if(!s.result.isEnabled)return Me(ne.Default);let a=s.result.preset?Me(s.result.preset):Me(ne.Default);if(s.result.title&&(a.title=s.result.title),s.result.logo&&(a.logo={...a.logo,...s.result.logo}),s.result.colors&&(a.colors={...a.colors,...s.result.colors}),s.result.typography&&(a.typography={...a.typography,...s.result.typography}),s.result.spacing&&(a.spacing={...a.spacing,...s.result.spacing}),s.result.customCSS&&(a.customCSS=s.result.customCSS),s.result.darkMode&&(a.darkMode={colors:{...(r=a.darkMode)==null?void 0:r.colors,...s.result.darkMode.colors}}),s.result.applicantFormVisibleFields&&s.result.applicantFormVisibleFields.length>0&&(a.applicantFormVisibleFields=s.result.applicantFormVisibleFields),s.result.applicantFormRequiredFields&&s.result.applicantFormRequiredFields.length>0&&(a.applicantFormRequiredFields=s.result.applicantFormRequiredFields),s.result.allowedLanguages&&s.result.allowedLanguages.length>0&&(a.allowedLanguages=s.result.allowedLanguages),s.result.applicantFormPages)try{const n=typeof s.result.applicantFormPages=="string"?JSON.parse(s.result.applicantFormPages):s.result.applicantFormPages;Array.isArray(n)&&n.length>0&&(a.applicantFormPages=n.map(i=>{const d=!i._v||i._v<4;return{...i,fields:(i.fields||[]).map(u=>({...u,colSpan:d?u.colSpan===1?2:4:Math.min(4,Math.max(1,u.colSpan??4))}))}}))}catch{}if(s.result.reviewPageFields)try{const n=typeof s.result.reviewPageFields=="string"?JSON.parse(s.result.reviewPageFields):s.result.reviewPageFields;Array.isArray(n)&&n.length>0&&(a.reviewPageFields=n)}catch{}return a}catch(s){return console.warn("[ThemeService] Failed to fetch theme configuration:",s),Me(ne.Default)}}async saveThemeConfiguration(r){await this.httpClient.post("Tenant","SaveThemeConfiguration",r)}getAvailablePresets(){return[{id:ne.Default,name:"Default"},{id:ne.Corporate,name:"Corporate"},{id:ne.Fintech,name:"Fintech"},{id:ne.Healthcare,name:"Healthcare"},{id:ne.Modern,name:"Modern"},{id:ne.Minimal,name:"Minimal"}]}getPreviewTheme(r,s){const a=Me(r);return s?{...a,...s,logo:{...a.logo,...s.logo},colors:{...a.colors,...s.colors},typography:s.typography?{...a.typography,...s.typography}:a.typography,spacing:s.spacing?{...a.spacing,...s.spacing}:a.spacing}:a}}class zt{constructor(){ee(this,"listeners",new Map)}on(r,s){return this.listeners.has(r)||this.listeners.set(r,new Set),this.listeners.get(r).add(s),()=>{this.off(r,s)}}off(r,s){const a=this.listeners.get(r);a&&a.delete(s)}emit(r,s){const a=this.listeners.get(r);a&&a.forEach(n=>{try{n(s)}catch(i){console.error(`Error in event listener for "${r}":`,i)}})}clear(){this.listeners.clear()}clearEvent(r){this.listeners.delete(r)}}class Bt{constructor(){ee(this,"events",new zt);ee(this,"_applicantId",null);ee(this,"_progress",null);ee(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)||ye.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===ye.Finished}get isOnHold(){return this.status===ye.OnHold}get isInProgress(){return this.status===ye.InProgress}setApplicantId(r){this._applicantId=r}updateProgress(r){var a,n;const s=(a=this._progress)==null?void 0:a.currentStep;this._progress=r,this._applicantId=r.applicantId,this._error=null,this.events.emit("progressUpdated",r),(s==null?void 0:s.order)!==((n=r.currentStep)==null?void 0:n.order)&&this.events.emit("stepChanged",r.currentStep),this.events.emit("statusChanged",r.status),r.status===ye.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 $t{constructor(){ee(this,"handlers",new Map)}registerHandler(r,s){this.handlers.set(r,s)}getHandler(r){return this.handlers.get(r)}hasHandler(r){return this.handlers.has(r)}async loadStepData(r,s){const a=this.getHandler(r);if(!a)throw new Error(`No handler registered for step action: ${G[r]}`);return a.loadData(s)}async submitStepData(r,s){const a=this.getHandler(r);if(!a)throw new Error(`No handler registered for step action: ${G[r]}`);return a.submitData(s)}}class _t{constructor(r,s,a,n,i,d,u,x){ee(this,"state");ee(this,"stepRouter");this.applicantService=r,this.questionnaireService=s,this.uploadDocumentService=a,this.appropriatenessTestService=n,this.overviewService=i,this.riskScoringService=d,this.investorCategorizationService=x,this.state=new Bt,this.stepRouter=new $t,this.registerStepHandlers()}registerStepHandlers(){this.stepRouter.registerHandler(G.Questionaries,{loadData:r=>this.questionnaireService.getQuestionnaire(r),submitData:async r=>{await this.questionnaireService.fillQuestionnaire(r)}}),this.stepRouter.registerHandler(G.UploadDocument,{loadData:r=>this.uploadDocumentService.getUploadDocument(r),submitData:r=>this.uploadDocumentService.fillUploadDocument(r)}),this.stepRouter.registerHandler(G.AppropriatenessTest,{loadData:r=>this.appropriatenessTestService.getAppropriatenessTest(r),submitData:async r=>{await this.appropriatenessTestService.fillAppropriatenessTest(r)}}),this.stepRouter.registerHandler(G.Overview,{loadData:r=>this.overviewService.getOverviewData(r),submitData:r=>this.overviewService.passOverview(r.applicantId)}),this.stepRouter.registerHandler(G.RiskScoring,{loadData:r=>this.riskScoringService.getRiskCriterias(r),submitData:async r=>{await this.riskScoringService.submitRiskScoring(r)}}),this.stepRouter.registerHandler(G.IdentitySdk,{loadData:async r=>({applicantId:r,message:"Identity verification required"}),submitData:async()=>{}}),this.stepRouter.registerHandler(G.InvestorCategorization,{loadData:r=>this.investorCategorizationService.getInvestorCategorization(r),submitData:async r=>{await this.investorCategorizationService.setInvestorCategorization(r)}}),this.stepRouter.registerHandler(G.ManualReview,{loadData:async r=>({applicantId:r,message:"Your application is under manual review"}),submitData:async()=>{}}),this.stepRouter.registerHandler(G.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 et(t,r){return new Promise((s,a)=>{if(r&&document.getElementById(r)){s();return}const n=document.createElement("script");n.src=t,r&&(n.id=r),n.async=!0,n.onload=()=>s(),n.onerror=()=>a(new Error(`Failed to load script: ${t}`)),document.head.appendChild(n)})}function Sr(t){return!!document.getElementById(t)}function Nr(t){const r=document.getElementById(t);r&&r.remove()}class Ht{constructor(r){ee(this,"sdk",null);ee(this,"config");this.config=r}async loadSDK(){await et("https://cdn.sumsub.com/websdk/v2/production/websdk.js","sumsub-sdk")}async initialize(r){if(window.snsWebSdk||await this.loadSDK(),!window.snsWebSdk)throw new Error("Sumsub SDK failed to load");this.sdk=window.snsWebSdk.init(this.config.accessToken,()=>this.config.accessToken).withConf({lang:this.config.lang||"en",email:this.config.applicantEmail,phone:this.config.applicantPhone,i18n:{}}).on("idCheck.onStepCompleted",s=>{console.log("Sumsub step completed:",s)}).on("idCheck.onError",s=>{console.error("Sumsub error:",s)}).build(),this.sdk.launch(`#${r}`)}destroy(){this.sdk&&(this.sdk.destroy(),this.sdk=null)}onComplete(r){this.sdk&&this.sdk.on("idCheck.applicantStatus",s=>{s.applicantStatus==="completed"&&r(s)})}onError(r){this.sdk&&this.sdk.on("idCheck.onError",r)}}class Ut{constructor(r){ee(this,"sdk",null);ee(this,"config");this.config=r}async loadSDK(){await et("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 Kt{constructor(r){ee(this,"sardineContext",null);ee(this,"config");ee(this,"sessionKey");this.config=r,this.sessionKey=r.sessionKey||this.generateSessionKey()}generateSessionKey(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(r){const s=Math.random()*16|0;return(r==="x"?s:s&3|8).toString(16)})}getSardineHost(){const{environment:r,region:s}=this.config;if(r==="sandbox")return"api.sandbox.sardine.ai";switch(s){case"eu":return"api.eu.sardine.ai";case"ca":return"api.ca.sardine.ai";case"au":return"api.au.sardine.ai";default:return"api.sardine.ai"}}async loadSDK(){return new Promise((r,s)=>{if(window._Sardine){r();return}const a=this.getSardineHost(),n=document.createElement("script");n.type="text/javascript",n.async=!0,n.src=`https://${a}/assets/loader.min.js`,n.onload=()=>{console.log("[SardinAI] SDK loaded successfully"),r()},n.onerror=()=>{s(new Error("Failed to load SardinAI SDK"))};const i=document.getElementsByTagName("script")[0];i&&i.parentNode?i.parentNode.insertBefore(n,i):document.head.appendChild(n)})}async initialize(){try{if(await this.loadSDK(),!window._Sardine)throw new Error("SardinAI SDK not available after loading");const r=this.getSardineHost(),{clientId:s,environment:a,flow:n,enableBiometrics:i,enablePortScanning:d}=this.config;this.sardineContext=window._Sardine.createContext({clientId:s,sessionKey:this.sessionKey,userIdHash:void 0,flow:n||window.location.pathname,environment:a||"production",parentElement:document.body,enableBiometrics:i!==!1,enablePortScanning:d===!0,region:this.config.region,onDeviceResponse:u=>{console.log(`[SardinAI] Device ID: ${u.deviceId}`)},onConfigUpdate:(u,x,p)=>{switch(u){case"SESSION_UPDATE_FAILED":console.error("[SardinAI] Session update failed:",p);break;case"SESSION_UPDATED":console.log("[SardinAI] Session updated:",x);break;case"SESSION_NO_UPDATE":console.log("[SardinAI] No session update");break;default:console.warn("[SardinAI] Unknown event:",u)}}}),this.addNoScriptFallback(r),console.log("[SardinAI] SDK initialized with sessionKey:",this.sessionKey)}catch(r){throw console.error("[SardinAI] Initialization failed:",r),r}}addNoScriptFallback(r){const s=document.createElement("noscript"),a=document.createElement("img"),{clientId:n,flow:i}=this.config;a.src=`https://${r}/v1/a.png?clientId=${n}&sessionKey=${this.sessionKey}&flow=${i||"kyc"}&ns=1`,a.style.display="none",s.appendChild(a),document.body.appendChild(s)}updateConfig(r){if(!this.sardineContext){console.warn("[SardinAI] Cannot update config - SDK not initialized");return}r.sessionKey&&(this.sessionKey=r.sessionKey),this.sardineContext.updateConfig({...r,onConfigUpdate:(s,a,n)=>{switch(s){case"SESSION_UPDATE_FAILED":console.error("[SardinAI] Config update failed:",n);break;case"SESSION_UPDATED":console.log("[SardinAI] Config updated:",a);break;case"SESSION_NO_UPDATE":console.log("[SardinAI] No config update needed");break}}})}getSessionKey(){return this.sessionKey}destroy(){this.sardineContext&&(this.sardineContext=null)}}class Te{static createProvider(r,s){switch(r){case ge.Sumsub:return new Ht(s);case ge.Onfido:return new Ut(s);case ge.SardinAI:return new Kt(s);default:throw new Error(`Unsupported identity provider: ${r}`)}}static parseProviderConfig(r,s,a){var n;switch(r){case ge.Sumsub:return{accessToken:s.accessToken||s.token,applicantEmail:s.email,applicantPhone:s.phone,externalUserId:s.externalUserId,lang:s.lang||"en"};case ge.Onfido:return{token:s.token||s.sdkToken};case ge.SardinAI:const i=((n=a==null?void 0:a.identityProviders)==null?void 0:n.sardinai)||{};return{clientId:i.clientId||s.clientId,sessionKey:i.sessionKey||s.sessionKey,environment:i.environment||s.environment||"production",flow:i.flow||s.flow,region:i.region,enableBiometrics:i.enableBiometrics,enablePortScanning:i.enablePortScanning};default:throw new Error(`Unsupported identity provider: ${r}`)}}}class Wt{constructor(r){ee(this,"currentTheme",de);ee(this,"customStyleElement",null);ee(this,"container");this.container=r||document.documentElement}applyTheme(r){this.currentTheme=this.mergeWithDefault(r),this.applyColors(this.currentTheme.colors),this.currentTheme.typography&&this.applyTypography(this.currentTheme.typography),this.currentTheme.spacing&&this.applySpacing(this.currentTheme.spacing),this.currentTheme.customCSS&&this.injectCustomCSS(this.currentTheme.customCSS),console.log("[ThemeManager] Theme applied:",this.currentTheme.name||"Custom")}applyColors(r){var a;const s={primary:r.primary,"primary-hover":r.primaryHover,"primary-light":r.primaryLight,"primary-dark":r.primaryDark,secondary:r.secondary,"secondary-hover":r.secondaryHover,success:r.success,warning:r.warning,danger:r.danger,info:r.info,background:r.background,"input-bg":r.background,surface:r.surface,border:r.border,"text-primary":r.textPrimary,"text-secondary":r.textSecondary,"text-muted":r.textMuted};Object.entries(s).forEach(([n,i])=>{this.container.style.setProperty(`--metakyc-${n}`,i)}),(a=this.currentTheme.darkMode)!=null&&a.colors&&this.applyDarkModeColors(this.currentTheme.darkMode.colors)}applyDarkModeColors(r){Object.entries(r).forEach(([s,a])=>{if(a){const n=`--metakyc-dark-${this.kebabCase(s)}`;this.container.style.setProperty(n,a)}})}applyTypography(r){r&&(r.fontFamily&&this.container.style.setProperty("--metakyc-font-family",r.fontFamily),r.headingFont&&this.container.style.setProperty("--metakyc-heading-font",r.headingFont),r.fontSize&&Object.entries(r.fontSize).forEach(([s,a])=>{this.container.style.setProperty(`--metakyc-font-size-${s}`,a)}),r.fontWeight&&Object.entries(r.fontWeight).forEach(([s,a])=>{this.container.style.setProperty(`--metakyc-font-weight-${s}`,a.toString())}))}applySpacing(r){r&&Object.entries(r).forEach(([s,a])=>{const n=`--metakyc-${this.kebabCase(s)}`;this.container.style.setProperty(n,a)})}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||de.name,title:r.title||de.title,logo:{...de.logo,...r.logo},colors:{...de.colors,...r.colors},typography:r.typography?{...de.typography,...r.typography}:de.typography,spacing:r.spacing?{...de.spacing,...r.spacing}:de.spacing,customCSS:r.customCSS,darkMode:r.darkMode?{colors:{...(s=de.darkMode)==null?void 0:s.colors,...r.darkMode.colors}}:de.darkMode,applicantFormVisibleFields:r.applicantFormVisibleFields,applicantFormRequiredFields:r.applicantFormRequiredFields,allowedLanguages:r.allowedLanguages,applicantFormPages:r.applicantFormPages,reviewPageFields:r.reviewPageFields}}getCurrentTheme(){return this.currentTheme}resetTheme(){this.applyTheme(de)}cleanup(){this.customStyleElement&&(this.customStyleElement.remove(),this.customStyleElement=null)}kebabCase(r){return r.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}}const tt=o.createContext(null),Cr=({config:t,children:r})=>{const[s,a]=o.useState(null),n=o.useRef(!1),i=o.useRef(!1),d=o.useMemo(()=>{const x=new kt(t),p=new wt(x),b=new jt(x),N=new St(x),g=new Nt(x),v=new Ct(x),f=new Rt(x),P=new At(x),A=new Et(x),S=new It(x),z=new Ot(x),R=new Wt;return{httpClient:x,applicantService:p,questionnaireService:b,uploadDocumentService:N,appropriatenessTestService:g,overviewService:v,riskScoringService:f,identityService:P,baseInformationService:A,investorCategorizationService:S,themeService:z,themeManager:R}},[t]),u=o.useMemo(()=>({config:t,...d,currentTheme:s,createOrchestrator:()=>new _t(d.applicantService,d.questionnaireService,d.uploadDocumentService,d.appropriatenessTestService,d.overviewService,d.riskScoringService,d.identityService,d.investorCategorizationService)}),[t,d,s]);return o.useEffect(()=>((async()=>{if(n.current||i.current){console.log("[MetaKYC] Theme already loading or loaded, skipping...");return}n.current=!0;try{if(t.theme){console.log("[MetaKYC] Applying static theme from config"),d.themeManager.applyTheme(t.theme),a(d.themeManager.getCurrentTheme()),i.current=!0;return}console.log("[MetaKYC] Fetching theme from backend...");const p=await d.themeService.getThemeConfiguration();d.themeManager.applyTheme(p),a(d.themeManager.getCurrentTheme()),i.current=!0,console.log("[MetaKYC] Theme loaded and applied",p)}catch(p){console.warn("[MetaKYC] Failed to load theme, using default:",p),a(d.themeManager.getCurrentTheme()),i.current=!0}finally{n.current=!1}})(),()=>{d.themeManager.cleanup()}),[]),e.jsx(tt.Provider,{value:u,children:r})};function he(){const t=o.useContext(tt);if(!t)throw new Error("useMetaKYC must be used within a MetaKYCProvider");return t}async function Yt(t){return new Promise((r,s)=>{const a=new FileReader;a.readAsDataURL(t),a.onload=()=>{const i=a.result.split(",")[1];r(i)},a.onerror=n=>s(n)})}function Rr(t,r){return t.size<=r}function Ar(t,r){return r.split(",").map(a=>a.trim()).some(a=>{if(a.endsWith("/*")){const n=a.slice(0,-2);return t.type.startsWith(n)}return t.type===a})}function qe(t){if(t===0)return"0 Bytes";const r=1024,s=["Bytes","KB","MB","GB"],a=Math.floor(Math.log(t)/Math.log(r));return Math.round(t/Math.pow(r,a)*100)/100+" "+s[a]}function Er(t){return t}function re(...t){return t.filter(Boolean).join(" ")}const Oe={APPLICANT_ID:"metakyc_applicant_id",WORKFLOW_STATE:"metakyc_workflow_state"};function qt(t){try{localStorage.setItem(Oe.APPLICANT_ID,t.toString())}catch(r){console.warn("Failed to save applicant ID to storage:",r)}}function Qt(){try{const t=localStorage.getItem(Oe.APPLICANT_ID);return t?parseInt(t,10):null}catch(t){return console.warn("Failed to retrieve applicant ID from storage:",t),null}}function Gt(){try{localStorage.removeItem(Oe.APPLICANT_ID)}catch(t){console.warn("Failed to clear applicant ID from storage:",t)}}function Vt(t){try{localStorage.setItem(Oe.WORKFLOW_STATE,JSON.stringify(t))}catch(r){console.warn("Failed to save workflow state to storage:",r)}}function Ir(){try{const t=localStorage.getItem(Oe.WORKFLOW_STATE);return t?JSON.parse(t):null}catch(t){return console.warn("Failed to retrieve workflow state from storage:",t),null}}function Jt(){try{localStorage.removeItem(Oe.WORKFLOW_STATE)}catch(t){console.warn("Failed to clear workflow state from storage:",t)}}function Pr(){Gt(),Jt()}function Zt(t){const{createOrchestrator:r}=he(),[s,a]=o.useState(null),[n,i]=o.useState(!1),[d,u]=o.useState(null),x=o.useRef(null),p=t||Qt();o.useEffect(()=>{x.current||(x.current=r())},[r]),o.useEffect(()=>{var R;s&&p&&(qt(p),Vt({applicantId:p,currentStepOrder:(R=s.currentStep)==null?void 0:R.order,status:s.status,lastUpdated:new Date().toISOString(),workflowKey:s.workFlowKey,nextWorkflowKey:s.nextWorkflowKey}))},[s,p]);const b=o.useRef(!1),N=o.useRef(!1),g=o.useCallback(async()=>{if(!(!p||!x.current)){if(b.current){console.log("[Workflow] Load already in progress, skipping...");return}b.current=!0,i(!0),u(null);try{const R=await x.current.initialize(p);a(R),N.current=!0}catch(R){u(R)}finally{i(!1),b.current=!1}}},[p]);o.useEffect(()=>{p&&!N.current&&g()},[p,g]);const v=o.useCallback(async()=>{if(x.current){if(b.current){console.log("[Workflow] Refresh already in progress, skipping...");return}b.current=!0,i(!0),u(null);try{const R=await x.current.refreshProgress();a(R)}catch(R){u(R)}finally{i(!1),b.current=!1}}},[]),f=o.useCallback(async()=>{if(x.current){i(!0),u(null);try{const R=await x.current.moveToNextStep();a(R)}catch(R){u(R)}finally{i(!1)}}},[]),P=o.useCallback(async()=>{if(x.current){i(!0),u(null);try{const R=await x.current.moveToPreviousStep();a(R)}catch(R){u(R)}finally{i(!1)}}},[]),A=o.useCallback(async R=>{if(x.current){i(!0),u(null);try{await x.current.submitCurrentStep(R);const E=await x.current.refreshProgress();a(E)}catch(E){throw u(E),E}finally{i(!1)}}},[]),S=rt.useMemo(()=>s!=null&&s.stepInfoList?[...s.stepInfoList].sort((R,E)=>R.order-E.order):[],[s==null?void 0:s.stepInfoList]),z=rt.useMemo(()=>s?s.nextWorkflowKey&&s.nextWorkflowKey!==s.workFlowKey:!1,[s]);return{progress:s,applicantId:p,currentStep:(s==null?void 0:s.currentStep)||null,steps:S,status:(s==null?void 0:s.status)||ye.None,workflowResult:(s==null?void 0:s.workflowResult)||null,workflowKey:s==null?void 0:s.workFlowKey,nextWorkflowKey:s==null?void 0:s.nextWorkflowKey,hasWorkflowChanged:z,isLoading:n,error:d,isComplete:(s==null?void 0:s.status)===ye.Finished,isOnHold:(s==null?void 0:s.status)===ye.OnHold,refreshProgress:v,moveToNext:f,moveBack:P,submitCurrentStep:A,orchestrator:x.current}}function Xt(t){const{questionnaireService:r,applicantService:s}=he(),[a,n]=o.useState(null),[i,d]=o.useState({}),[u,x]=o.useState(!1),[p,b]=o.useState(!1),[N,g]=o.useState(null),v=o.useRef(!1),f=o.useRef(null),P=o.useCallback(async()=>{var S,z;if(t){if(v.current){console.log("[Questionnaire] Load already in progress, skipping...");return}v.current=!0,x(!0),g(null);try{const[R,E]=await Promise.all([r.getQuestionnaire(t),s.getApplicantData(t).catch(()=>null)]);if(n(R),(S=E==null?void 0:E.questionnaireResults)!=null&&S.length&&R){const Q=new Map;for(const w of E.questionnaireResults)w.question&&((z=w.answers)!=null&&z.length)&&Q.set(w.question.trim().toLowerCase(),w.answers);const Y={},C=R.questionGroups.flatMap(w=>w.questions??[]);for(const w of C){const j=w.text.trim().toLowerCase();Q.has(j)&&(Y[w.id]=Q.get(j))}d(Y)}f.current=t}catch(R){g(R)}finally{x(!1),v.current=!1}}},[t,r,s]);o.useEffect(()=>{t&&f.current!==t&&P()},[t]);const A=o.useCallback(async S=>{b(!0),g(null);try{return await r.fillQuestionnaire(S)}catch(z){throw g(z),z}finally{b(!1)}},[r]);return{questionnaire:a,initialAnswers:i,isLoading:u,isSubmitting:p,error:N,load:P,submit:A}}function er(t){const{uploadDocumentService:r}=he(),[s,a]=o.useState(null),[n,i]=o.useState(!1),[d,u]=o.useState(!1),[x,p]=o.useState(0),[b,N]=o.useState(null),g=o.useRef(!1),v=o.useRef(null),f=o.useCallback(async()=>{if(t){if(g.current){console.log("[UploadDocument] Load already in progress, skipping...");return}g.current=!0,i(!0),N(null);try{const A=await r.getUploadDocument(t);a(A),v.current=t}catch(A){N(A)}finally{i(!1),g.current=!1}}},[t,r]);o.useEffect(()=>{t&&v.current!==t&&f()},[t]);const P=o.useCallback(async A=>{u(!0),p(0),N(null);try{await r.fillUploadDocument(A),p(100)}catch(S){throw N(S),S}finally{u(!1)}},[r]);return{uploadDocument:s,isLoading:n,isSubmitting:d,uploadProgress:x,error:b,load:f,submit:P}}function Fr(t){const{appropriatenessTestService:r}=he(),[s,a]=o.useState(null),[n,i]=o.useState(!1),[d,u]=o.useState(!1),[x,p]=o.useState(null),[b,N]=o.useState(null),g=o.useRef(!1),v=o.useRef(null),f=o.useCallback(async()=>{if(t){if(g.current){console.log("[AppropriatenessTest] Load already in progress, skipping...");return}g.current=!0,i(!0),p(null);try{const A=await r.getAppropriatenessTest(t);a(A),v.current=t}catch(A){p(A)}finally{i(!1),g.current=!1}}},[t,r]);o.useEffect(()=>{t&&v.current!==t&&f()},[t]);const P=o.useCallback(async A=>{u(!0),p(null);try{const S=await r.fillAppropriatenessTest(A);return N(S),S}catch(S){throw p(S),S}finally{u(!1)}},[r]);return{test:s,result:b,isLoading:n,isSubmitting:d,error:x,load:f,submit:P}}function tr(t){const{overviewService:r}=he(),[s,a]=o.useState(null),[n,i]=o.useState(!1),[d,u]=o.useState(!1),[x,p]=o.useState(null),b=o.useRef(!1),N=o.useRef(null),g=o.useCallback(async()=>{if(t){if(b.current){console.log("[Overview] Load already in progress, skipping...");return}b.current=!0,i(!0),p(null);try{const f=await r.getOverviewData(t);a(f),N.current=t}catch(f){p(f)}finally{i(!1),b.current=!1}}},[t,r]);o.useEffect(()=>{t&&N.current!==t&&g()},[t]);const v=o.useCallback(async()=>{if(t){u(!0),p(null);try{await r.passOverview(t)}catch(f){throw p(f),f}finally{u(!1)}}},[t,r]);return{overview:s,isLoading:n,isSubmitting:d,error:x,load:g,passOverview:v}}function rr(t){const{identityService:r}=he(),[s,a]=o.useState(null),[n,i]=o.useState(!1),[d,u]=o.useState(null),x=o.useRef(!1),p=o.useCallback(async(g,v)=>{if(t){if(x.current){console.log("[Identity] Request already in progress, skipping...");return}x.current=!0,i(!0),u(null);try{const f={applicantId:t,restart:!1,redirectUrl:g||"",ttl:v||604800};console.log("Identity request input:",f);const P=await r.identityRequest(f);return console.log("Identity request result:",P),a(P),P}catch(f){throw u(f),f}finally{i(!1),x.current=!1}}},[t,r]),b=o.useCallback(async(g,v)=>{if(t){i(!0),u(null);try{const f={applicantId:t,restart:!1,redirectUrl:g,ttl:v},P=await r.identityCompanyRequest(f);return a(P),P}catch(f){throw u(f),f}finally{i(!1)}}},[t,r]),N=o.useCallback(async()=>{if(t){if(x.current){console.log("[Identity] Restart already in progress, skipping...");return}x.current=!0,i(!0),u(null);try{const g={applicantId:t,restart:!0,redirectUrl:"",ttl:604800};console.log("Restarting identity with input:",g);const v=await r.identityRequest(g);return console.log("Restart identity result:",v),a(v),v}catch(g){throw u(g),g}finally{i(!1),x.current=!1}}},[t,r]);return{identityData:s,provider:(s==null?void 0:s.provider)||null,token:(s==null?void 0:s.publicProviderTokenObject)||null,isLoading:n,error:d,requestIdentity:p,requestCompanyIdentity:b,restartIdentity:N}}function sr(t){const{riskScoringService:r,applicantService:s}=he(),[a,n]=o.useState(null),[i,d]=o.useState({}),[u,x]=o.useState(!1),[p,b]=o.useState(!1),[N,g]=o.useState(null),[v,f]=o.useState(null),P=o.useRef(!1),A=o.useRef(null),S=o.useCallback(async()=>{var R;if(t){if(P.current){console.log("[RiskScoring] Load already in progress, skipping...");return}P.current=!0,x(!0),g(null);try{const[E,Q]=await Promise.all([r.getRiskCriterias(t),s.getApplicantData(t).catch(()=>null)]);if(n(E),(R=Q==null?void 0:Q.riskScoringResults)!=null&&R.length){const Y=Q.riskScoringResults[0],C={};for(const w of Y.riskCriteriaResults??[])if(w.riskCriteriaId!=null&&w.answer!=null&&w.answer!==""){const j=[...new Set(w.answer.split(",").map(M=>M.trim()).filter(M=>M!==""))];j.length>0&&(C[w.riskCriteriaId]=j)}d(C)}A.current=t}catch(E){g(E)}finally{x(!1),P.current=!1}}},[t,r,s]);o.useEffect(()=>{t&&A.current!==t&&S()},[t]);const z=o.useCallback(async R=>{b(!0),g(null);try{const E=await r.submitRiskScoring(R);return f(E),E}catch(E){throw g(E),E}finally{b(!1)}},[r]);return{criteria:a,initialAnswers:i,result:v,isLoading:u,isSubmitting:p,error:N,load:S,submit:z}}function ar(){const{applicantService:t,config:r}=he(),[s,a]=o.useState(!1),[n,i]=o.useState(null),d=o.useRef(!1),u=o.useRef(!1),x=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(v){const f=Math.random()*16|0;return(v==="x"?f:f&3|8).toString(16)}),p=o.useCallback(async v=>{var f;if(d.current)throw console.log("[Applicant] Create already in progress, skipping..."),new Error("Creation already in progress");d.current=!0,a(!0),i(null);try{if(v.applicantAdditionalDatas||(v.applicantAdditionalDatas=[]),(f=r.identityProviders)!=null&&f.sardinai){const A=x();console.log("[SardinAI] Generated session key:",A),v.applicantAdditionalDatas.push({paramName:"sessionKey",value:A})}return await t.createApplicant(v)}catch(P){throw i(P),P}finally{a(!1),d.current=!1}},[t,r]),b=o.useCallback(async v=>{a(!0),i(null);try{return await t.createCompanyApplicant(v)}catch(f){throw i(f),f}finally{a(!1)}},[t]),N=o.useCallback(async v=>{if(u.current)throw console.log("[Applicant] Data load already in progress, skipping..."),new Error("Data load already in progress");u.current=!0,a(!0),i(null);try{return await t.getApplicantData(v)}catch(f){throw i(f),f}finally{a(!1),u.current=!1}},[t]),g=o.useCallback(async v=>{a(!0),i(null);try{await t.stopProgress(v)}catch(f){throw i(f),f}finally{a(!1)}},[t]);return{isLoading:s,error:n,createApplicant:p,createCompanyApplicant:b,getApplicantData:N,stopProgress:g}}const W=({children:t,variant:r="primary",size:s="md",isLoading:a=!1,disabled:n,className:i,...d})=>{const u="inline-flex items-center justify-center rounded-lg font-medium transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed",x={primary:"bg-primary-500 text-white hover:bg-primary-600 focus:ring-primary-500",secondary:"bg-gray-200 text-gray-900 hover:bg-gray-300 focus:ring-gray-400",outline:"border-2 border-primary-500 text-primary-500 hover:bg-primary-50 focus:ring-primary-500",danger:"bg-danger-500 text-white hover:bg-danger-600 focus:ring-danger-500",ghost:"text-gray-700 hover:bg-gray-100 focus:ring-gray-400"},p={sm:"px-3 py-1.5 text-sm",md:"px-4 py-2 text-base",lg:"px-6 py-3 text-lg"};return e.jsxs("button",{className:re(u,x[r],p[s],i),disabled:n||a,...d,children:[a&&e.jsxs("svg",{className:"animate-spin -ml-1 mr-2 h-4 w-4",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),t]})},ie=o.forwardRef(({label:t,error:r,helperText:s,leftIcon:a,rightIcon:n,className:i,style:d,...u},x)=>e.jsxs("div",{className:"w-full",children:[t&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[t,u.required&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),e.jsxs("div",{className:"relative",children:[a&&e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:a}),e.jsx("input",{ref:x,className:re("block w-full rounded-lg border px-3 py-2 text-sm transition-colors","focus:outline-none focus:ring-2 focus:ring-offset-0","disabled:opacity-60 disabled:cursor-not-allowed",a?"pl-10":"",n?"pr-10":"",i),style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:"var(--metakyc-text-primary, #111827)",borderColor:r?"var(--metakyc-danger, #ef4444)":"var(--metakyc-border, #d1d5db)",...d},...u}),n&&e.jsx("div",{className:"absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none",children:n})]}),r&&e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-danger, #ef4444)"},children:r}),!r&&s&&e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:s})]}));ie.displayName="Input";const U=({children:t,className:r,...s})=>e.jsx("div",{className:re("metakyc-card rounded-xl shadow-sm border",r),style:{backgroundColor:"var(--metakyc-surface, #ffffff)",borderColor:"var(--metakyc-border, #e5e7eb)"},...s,children:t}),oe=({children:t,className:r,...s})=>e.jsx("div",{className:re("px-6 py-4 border-b",r),style:{borderColor:"var(--metakyc-border, #e5e7eb)"},...s,children:t}),K=({children:t,className:r,...s})=>e.jsx("div",{className:re("px-6 py-4",r),...s,children:t}),ce=({children:t,className:r,...s})=>e.jsx("div",{className:re("px-6 py-4 border-t",r),style:{borderColor:"var(--metakyc-border, #e5e7eb)"},...s,children:t}),we=({children:t,variant:r="default",className:s,...a})=>{const n={default:"bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-300",success:"bg-success-100 text-success-800 dark:bg-success-900 dark:text-success-300",danger:"bg-danger-100 text-danger-800 dark:bg-danger-900 dark:text-danger-300",warning:"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300",info:"bg-primary-100 text-primary-800 dark:bg-primary-900 dark:text-primary-300"};return e.jsx("span",{className:re("inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium",n[r],s),...a,children:t})},fe=({size:t="md",className:r,...s})=>{const a={sm:"h-4 w-4",md:"h-8 w-8",lg:"h-12 w-12"};return e.jsx("div",{className:re("flex items-center justify-center",r),...s,children:e.jsxs("svg",{className:re("animate-spin text-primary-500",a[t]),xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})})},Ve=o.forwardRef(({label:t,error:r,helperText:s,options:a,placeholder:n,className:i,style:d,...u},x)=>e.jsxs("div",{className:"w-full",children:[t&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[t,u.required&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),e.jsxs("select",{ref:x,className:re("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":"",i),style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:"var(--metakyc-text-primary, #111827)",borderColor:r?"var(--metakyc-error, #ef4444)":"var(--metakyc-border, #d1d5db)",...d},...u,children:[n&&e.jsx("option",{value:"",disabled:!0,style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:"var(--metakyc-text-secondary, #6b7280)"},children:n},"__placeholder__"),a.map((p,b)=>e.jsx("option",{value:p.value,disabled:p.disabled,style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:p.disabled?"var(--metakyc-text-secondary, #9ca3af)":"var(--metakyc-text-primary, #111827)"},children:p.label},p.value||`option-${b}`))]}),r&&e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-error, #ef4444)"},children:r}),!r&&s&&e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:s})]}));Ve.displayName="Select";const st=280,nr=({label:t,value:r,onChange:s,options:a,placeholder:n="Select...",disabled:i=!1,required:d=!1})=>{const[u,x]=o.useState(!1),[p,b]=o.useState(""),[N,g]=o.useState(null),v=o.useRef(null),f=o.useRef(null),P=o.useRef(null),A=o.useCallback(()=>{if(!f.current)return null;const k=f.current.getBoundingClientRect(),V=window.innerHeight-k.bottom<st&&k.top>st;return{top:V?k.top:k.bottom+4,left:k.left,width:k.width,openUp:V}},[]),S=o.useCallback(()=>{if(i)return;const k=A();k&&g(k),x(!0)},[i,A]),z=o.useCallback(()=>{x(!1),b("")},[]);o.useEffect(()=>{if(!u)return;const k=H=>{var ve,se;const V=H.target;!((ve=v.current)!=null&&ve.contains(V))&&!((se=P.current)!=null&&se.contains(V))&&z()};return document.addEventListener("mousedown",k),()=>document.removeEventListener("mousedown",k)},[u,z]),o.useEffect(()=>{if(!u)return;const k=()=>{const H=A();H&&g(H)};return window.addEventListener("scroll",k,!0),window.addEventListener("resize",k),()=>{window.removeEventListener("scroll",k,!0),window.removeEventListener("resize",k)}},[u,A]);const R=a.filter(k=>k.label.toLowerCase().includes(p.toLowerCase())),E=k=>{i||s(r.includes(k)?r.filter(H=>H!==k):[...r,k])},Q=(k,H)=>{H.stopPropagation(),i||s(r.filter(V=>V!==k))},Y=k=>{var H;return((H=a.find(V=>V.value===k))==null?void 0:H.label)||k},C=f.current?getComputedStyle(f.current):null,w=(C==null?void 0:C.getPropertyValue("--metakyc-input-bg").trim())||"#ffffff",j=(C==null?void 0:C.getPropertyValue("--metakyc-border").trim())||"#d1d5db",M=(C==null?void 0:C.getPropertyValue("--metakyc-text-primary").trim())||"#111827",L=(C==null?void 0:C.getPropertyValue("--metakyc-text-secondary").trim())||"#6b7280",q=(C==null?void 0:C.getPropertyValue("--metakyc-primary").trim())||"#2563eb",B=(C==null?void 0:C.getPropertyValue("--metakyc-primary-light").trim())||"#eff6ff",O=(C==null?void 0:C.getPropertyValue("--metakyc-hover-bg").trim())||"#f9fafb",Z=u&&N&&e.jsxs("div",{ref:P,className:"metakyc-multiselect-dropdown",style:{position:"fixed",top:N.openUp?void 0:N.top,bottom:N.openUp?window.innerHeight-N.top+4:void 0,left:N.left,width:N.width,zIndex:99999,borderRadius:"8px",boxShadow:"0 4px 16px rgba(0,0,0,0.18)",border:`1px solid ${j}`,backgroundColor:w,overflow:"hidden"},children:[e.jsx("div",{style:{padding:"8px",borderBottom:`1px solid ${j}`},children:e.jsx("input",{type:"text",value:p,onChange:k=>b(k.target.value),placeholder:"Search...",autoFocus:!0,onClick:k=>k.stopPropagation(),className:"metakyc-multiselect-search w-full",style:{display:"block",width:"100%",padding:"6px 8px",fontSize:"13px",borderRadius:"6px",border:`1px solid ${j}`,backgroundColor:w,color:M,outline:"none",boxSizing:"border-box"}})}),e.jsx("ul",{style:{listStyle:"none",margin:0,padding:"4px 0",maxHeight:"192px",overflowY:"auto"},children:R.length===0?e.jsx("li",{style:{padding:"8px 12px",fontSize:"13px",color:L},children:"No results"}):R.map(k=>{const H=r.includes(k.value);return e.jsxs("li",{onClick:()=>E(k.value),className:"metakyc-multiselect-option",style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",fontSize:"13px",cursor:"pointer",backgroundColor:H?B:"transparent",color:H?q:M,userSelect:"none"},onMouseEnter:V=>{H||(V.currentTarget.style.backgroundColor=O)},onMouseLeave:V=>{H||(V.currentTarget.style.backgroundColor="transparent")},children:[e.jsx("input",{type:"checkbox",checked:H,readOnly:!0,style:{accentColor:q,pointerEvents:"none",flexShrink:0}}),e.jsx("span",{children:k.label})]},k.value)})}),r.length>0&&e.jsx("div",{style:{padding:"6px 12px",borderTop:`1px solid ${j}`},children:e.jsxs("button",{type:"button",onClick:()=>{s([]),b("")},style:{fontSize:"12px",color:"#ef4444",background:"none",border:"none",cursor:"pointer",padding:0},children:["Clear all (",r.length," selected)"]})})]});return e.jsxs("div",{className:"w-full metakyc-multiselect",ref:v,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:f,onClick:()=>u?z():S(),className:re("metakyc-multiselect-trigger","min-h-[42px] w-full px-3 py-2 rounded-lg border text-sm transition-colors relative",i?"opacity-50 cursor-not-allowed":"cursor-pointer"),style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",borderColor:u?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #d1d5db)",outline:u?"2px solid var(--metakyc-primary, #2563eb)":"none",outlineOffset:"-1px"},children:[r.length===0?e.jsx("span",{className:"metakyc-multiselect-placeholder leading-6",style:{color:"var(--metakyc-text-secondary, #9ca3af)"},children:n}):e.jsx("div",{className:"flex flex-wrap gap-1 pr-6",children:r.map(k=>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:[Y(k),!i&&e.jsx("button",{type:"button",onClick:H=>Q(k,H),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:"×"})]},k))}),e.jsx("span",{className:"metakyc-multiselect-arrow absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none text-xs",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:u?"▲":"▼"})]}),typeof document<"u"&&Z?Ge.createPortal(Z,document.body):null]})},at=260,Ee=({label:t,error:r,helperText:s,options:a,placeholder:n="Select...",value:i,onChange:d,disabled:u=!1,required:x=!1,className:p})=>{var se;const[b,N]=o.useState(!1),[g,v]=o.useState(""),[f,P]=o.useState(null),A=o.useRef(null),S=o.useRef(null),z=o.useRef(null),R=o.useRef(null),E=o.useCallback(()=>{if(!S.current)return null;const T=S.current.getBoundingClientRect(),ae=window.innerHeight-T.bottom<at&&T.top>at;return{top:ae?T.top:T.bottom+4,left:T.left,width:T.width,openUp:ae}},[]),Q=o.useCallback(()=>{if(u)return;const T=E();T&&P(T),N(!0)},[u,E]),Y=o.useCallback(()=>{N(!1),v("")},[]),C=()=>b?Y():Q();o.useEffect(()=>{if(!b)return;const T=J=>{var Ie,ue;const ae=J.target;!((Ie=A.current)!=null&&Ie.contains(ae))&&!((ue=z.current)!=null&&ue.contains(ae))&&Y()};return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},[b,Y]),o.useEffect(()=>{if(!b)return;const T=()=>{const J=E();J&&P(J)};return window.addEventListener("scroll",T,!0),window.addEventListener("resize",T),()=>{window.removeEventListener("scroll",T,!0),window.removeEventListener("resize",T)}},[b,E]),o.useEffect(()=>{b&&R.current&&setTimeout(()=>{var T;return(T=R.current)==null?void 0:T.focus()},0)},[b]);const w=a.filter(T=>T.label.toLowerCase().includes(g.toLowerCase())||T.value.toLowerCase().includes(g.toLowerCase())),j=(se=a.find(T=>T.value===i))==null?void 0:se.label,M=(T,J)=>{u||J||(d(T),Y())},L=S.current?getComputedStyle(S.current):null,q=(L==null?void 0:L.getPropertyValue("--metakyc-input-bg").trim())||"#ffffff",B=(L==null?void 0:L.getPropertyValue("--metakyc-border").trim())||"#d1d5db",O=(L==null?void 0:L.getPropertyValue("--metakyc-text-primary").trim())||"#111827",Z=(L==null?void 0:L.getPropertyValue("--metakyc-text-secondary").trim())||"#6b7280",k=(L==null?void 0:L.getPropertyValue("--metakyc-primary").trim())||"#2563eb",H=(L==null?void 0:L.getPropertyValue("--metakyc-primary-light").trim())||"#eff6ff",V=(L==null?void 0:L.getPropertyValue("--metakyc-hover-bg").trim())||"#f9fafb",ve=b&&f&&e.jsxs("div",{ref:z,className:"metakyc-searchable-select-dropdown",style:{position:"fixed",top:f.openUp?void 0:f.top,bottom:f.openUp?window.innerHeight-f.top+4:void 0,left:f.left,width:f.width,zIndex:99999,borderRadius:"8px",boxShadow:"0 4px 16px rgba(0,0,0,0.18)",border:`1px solid ${B}`,backgroundColor:q,overflow:"hidden"},children:[e.jsx("div",{style:{padding:"8px",borderBottom:`1px solid ${B}`},children:e.jsx("input",{ref:R,type:"text",value:g,onChange:T=>v(T.target.value),placeholder:"Search...",onClick:T=>T.stopPropagation(),className:"metakyc-searchable-select-search w-full",style:{display:"block",width:"100%",padding:"6px 8px",fontSize:"13px",borderRadius:"6px",border:`1px solid ${B}`,backgroundColor:q,color:O,outline:"none",boxSizing:"border-box"}})}),e.jsx("ul",{style:{listStyle:"none",margin:0,padding:"4px 0",maxHeight:"208px",overflowY:"auto"},children:w.length===0?e.jsx("li",{style:{padding:"8px 12px",fontSize:"13px",color:Z},children:"No results"}):w.map(T=>{const J=T.value===i;return e.jsx("li",{className:"metakyc-searchable-select-option",onClick:()=>M(T.value,T.disabled),style:{padding:"8px 12px",fontSize:"13px",cursor:T.disabled?"not-allowed":"pointer",opacity:T.disabled?.4:1,backgroundColor:J?H:"transparent",color:J?k:O,userSelect:"none"},onMouseEnter:ae=>{!J&&!T.disabled&&(ae.currentTarget.style.backgroundColor=V)},onMouseLeave:ae=>{J||(ae.currentTarget.style.backgroundColor="transparent")},children:T.label},T.value)})})]});return e.jsxs("div",{className:re("w-full metakyc-searchable-select",p),ref:A,children:[t&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[t,x&&e.jsx("span",{style:{color:"var(--metakyc-error, #ef4444)",marginLeft:"4px"},children:"*"})]}),e.jsxs("div",{ref:S,role:"button",tabIndex:u?-1:0,onClick:C,onKeyDown:T=>{(T.key==="Enter"||T.key===" ")&&(T.preventDefault(),C()),T.key==="Escape"&&Y()},className:re("metakyc-searchable-select-trigger","w-full px-3 py-2 rounded-lg border text-sm transition-colors text-left","flex items-center justify-between gap-2","focus:outline-none",u?"opacity-60 cursor-not-allowed":"cursor-pointer"),style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:j?"var(--metakyc-text-primary, #111827)":"var(--metakyc-text-secondary, #9ca3af)",borderColor:r?"var(--metakyc-error, #ef4444)":b?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #d1d5db)",minHeight:"42px",outline:b?"2px solid var(--metakyc-primary, #2563eb)":"none",outlineOffset:"-1px"},children:[e.jsx("span",{className:"truncate flex-1",children:j||n}),e.jsx("span",{className:"flex-shrink-0 text-xs pointer-events-none",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:b?"▲":"▼"})]}),typeof document<"u"&&ve?Ge.createPortal(ve,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})]})};Ee.displayName="SearchableSelect";const ir=({label:t,error:r,accept:s,multiple:a=!1,maxSize:n,onChange:i,value:d=[],className:u})=>{const[x,p]=o.useState(!1),b=o.useRef(null),N=S=>{if(!S)return;const z=Array.from(S);if(n&&z.filter(E=>E.size>n).length>0){const E=qe(n);alert(`Some files exceed the maximum size of ${E}`);return}i==null||i(a?[...d,...z]:[z[0]])},g=S=>{S.preventDefault(),p(!0)},v=()=>{p(!1)},f=S=>{S.preventDefault(),p(!1),N(S.dataTransfer.files)},P=()=>{var S;(S=b.current)==null||S.click()},A=S=>{const z=d.filter((R,E)=>E!==S);i==null||i(z)};return e.jsxs("div",{className:re("w-full",u),children:[t&&e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:t}),e.jsxs("div",{className:re("border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors",x?"border-primary-500 bg-primary-50 dark:bg-primary-900/20":"border-gray-300 dark:border-gray-600 hover:border-primary-500",r&&"border-danger-500"),onDragOver:g,onDragLeave:v,onDrop:f,onClick:P,children:[e.jsx("input",{ref:b,type:"file",className:"hidden",accept:s,multiple:a,onChange:S=>N(S.target.files)}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("svg",{className:"mx-auto h-12 w-12 text-gray-400",stroke:"currentColor",fill:"none",viewBox:"0 0 48 48",children:e.jsx("path",{d:"M28 8H12a4 4 0 00-4 4v20m32-12v8m0 0v8a4 4 0 01-4 4H12a4 4 0 01-4-4v-4m32-4l-3.172-3.172a4 4 0 00-5.656 0L28 28M8 32l9.172-9.172a4 4 0 015.656 0L28 28m0 0l4 4m4-24h8m-4-4v8m-12 4h.02",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"})}),e.jsxs("div",{className:"text-sm text-gray-600 dark:text-gray-400",children:[e.jsx("span",{className:"font-medium text-primary-500",children:"Click to upload"})," or drag and drop"]}),n&&e.jsxs("p",{className:"text-xs text-gray-500",children:["Maximum file size: ",qe(n)]})]})]}),d.length>0&&e.jsx("div",{className:"mt-3 space-y-2",children:d.map((S,z)=>e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 bg-gray-50 dark:bg-gray-700 rounded-lg",children:[e.jsxs("div",{className:"flex items-center space-x-2 flex-1 min-w-0",children:[e.jsx("svg",{className:"h-5 w-5 text-gray-400 flex-shrink-0",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M4 4a2 2 0 012-2h4.586A2 2 0 0112 2.586L15.414 6A2 2 0 0116 7.414V16a2 2 0 01-2 2H6a2 2 0 01-2-2V4z",clipRule:"evenodd"})}),e.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300 truncate",children:S.name}),e.jsxs("span",{className:"text-xs text-gray-500",children:["(",qe(S.size),")"]})]}),e.jsx("button",{type:"button",onClick:R=>{R.stopPropagation(),A(z)},className:"ml-2 text-danger-500 hover:text-danger-700 focus:outline-none",children:e.jsx("svg",{className:"h-5 w-5",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",clipRule:"evenodd"})})})]},z))}),r&&e.jsx("p",{className:"mt-1 text-sm text-danger-500",children:r})]})},or=o.forwardRef(({countryCode:t="+1",onCountryCodeChange:r,className:s,...a},n)=>e.jsxs("div",{className:"w-full",children:[a.label&&e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--metakyc-text-primary, #374151)"},children:[a.label,a.required&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:t,onChange:i=>r==null?void 0:r(i.target.value),className:re("w-20 rounded-lg border px-3 py-2 text-sm","focus:outline-none focus:ring-2 focus:ring-offset-0"),style:{backgroundColor:"var(--metakyc-input-bg, #ffffff)",color:"var(--metakyc-text-primary, #111827)",borderColor:"var(--metakyc-border, #d1d5db)"},placeholder:"+1"}),e.jsx(ie,{ref:n,type:"tel",className:re("flex-1",s),...a,label:""})]}),a.error&&e.jsx("p",{className:"mt-1 text-sm text-danger-500",children:a.error})]}));or.displayName="PhoneInput";/**
|
|
2
2
|
* @license lucide-react v0.574.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -8,17 +8,17 @@
|
|
|
8
8
|
*
|
|
9
9
|
* This source code is licensed under the ISC license.
|
|
10
10
|
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/const
|
|
11
|
+
*/const Tr=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();/**
|
|
12
12
|
* @license lucide-react v0.574.0 - ISC
|
|
13
13
|
*
|
|
14
14
|
* This source code is licensed under the ISC license.
|
|
15
15
|
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
-
*/const
|
|
16
|
+
*/const Lr=t=>t.replace(/^([A-Z])|[\s-_]+(\w)/g,(r,s,a)=>a?a.toUpperCase():s.toLowerCase());/**
|
|
17
17
|
* @license lucide-react v0.574.0 - ISC
|
|
18
18
|
*
|
|
19
19
|
* This source code is licensed under the ISC license.
|
|
20
20
|
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
-
*/const nt=t=>{const r=
|
|
21
|
+
*/const nt=t=>{const r=Lr(t);return r.charAt(0).toUpperCase()+r.slice(1)};/**
|
|
22
22
|
* @license lucide-react v0.574.0 - ISC
|
|
23
23
|
*
|
|
24
24
|
* This source code is licensed under the ISC license.
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
*
|
|
34
34
|
* This source code is licensed under the ISC license.
|
|
35
35
|
* See the LICENSE file in the root directory of this source tree.
|
|
36
|
-
*/const Or=o.forwardRef(({color:t="currentColor",size:r=24,strokeWidth:s=2,absoluteStrokeWidth:a,className:n="",children:i,iconNode:
|
|
36
|
+
*/const Or=o.forwardRef(({color:t="currentColor",size:r=24,strokeWidth:s=2,absoluteStrokeWidth:a,className:n="",children:i,iconNode:d,...u},x)=>o.createElement("svg",{ref:x,...Dr,width:r,height:r,stroke:t,strokeWidth:a?Number(s)*24/Number(r):s,className:lr("lucide",n),...!i&&!Mr(u)&&{"aria-hidden":"true"},...u},[...d.map(([p,b])=>o.createElement(p,b)),...Array.isArray(i)?i:[i]]));/**
|
|
37
37
|
* @license lucide-react v0.574.0 - ISC
|
|
38
38
|
*
|
|
39
39
|
* This source code is licensed under the ISC license.
|
|
40
40
|
* See the LICENSE file in the root directory of this source tree.
|
|
41
|
-
*/const cr=(t,r)=>{const s=o.forwardRef(({className:a,...n},i)=>o.createElement(Or,{ref:i,iconNode:r,className:lr(`lucide-${
|
|
41
|
+
*/const cr=(t,r)=>{const s=o.forwardRef(({className:a,...n},i)=>o.createElement(Or,{ref:i,iconNode:r,className:lr(`lucide-${Tr(nt(t))}`,`lucide-${t}`,a),...n}));return s.displayName=nt(t),s};/**
|
|
42
42
|
* @license lucide-react v0.574.0 - ISC
|
|
43
43
|
*
|
|
44
44
|
* This source code is licensed under the ISC license.
|
|
@@ -48,22 +48,22 @@
|
|
|
48
48
|
*
|
|
49
49
|
* This source code is licensed under the ISC license.
|
|
50
50
|
* See the LICENSE file in the root directory of this source tree.
|
|
51
|
-
*/const Br=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],ur=cr("chevron-right",Br);function $r(t,r){const s=!r||r.length===0||r.every(a=>!a||!a.trim());if(t.isRequired&&s)return t.errorMessage||"This field is required";if(!s){const a=r[0]??"";if(a&&t.regex)try{if(!new RegExp(t.regex).test(a))return t.errorMessage||"Invalid format"}catch{}if(a!==""){const n=Number(a);if(!isNaN(n)&&a.trim()!==""){if(t.min!==void 0&&t.min!==null&&n<t.min)return`Minimum value is ${t.min}`;if(t.max!==void 0&&t.max!==null&&n>t.max)return`Maximum value is ${t.max}`}else{if(t.min!==void 0&&t.min!==null&&a.length<t.min)return`Minimum length is ${t.min} characters`;if(t.max!==void 0&&t.max!==null&&a.length>t.max)return`Maximum length is ${t.max} characters`}}}return null}function _r(t){const r=t.flatMap((a,n)=>(a.questions??[]).map((i,l)=>({question:i,groupIndex:n,qIdx:l}))),s=new Map;for(const a of r){const n=a.question.pageNumber!=null&&a.question.pageNumber>0?a.question.pageNumber:1;s.has(n)||s.set(n,[]),s.get(n).push(a)}return Array.from(s.entries()).sort(([a],[n])=>a-n).map(([,a])=>a)}const mr=({applicantId:t,onComplete:r,onBack:s})=>{const{questionnaire:a,initialAnswers:n,isLoading:i,isSubmitting:l,error:d,submit:m}=Xt(t),[u,f]=o.useState({}),[S,p]=o.useState({}),[b,g]=o.useState(0);o.useEffect(()=>{n&&Object.keys(n).length>0&&Object.keys(u).length===0&&f(n)},[n]);const I=o.useMemo(()=>a?_r(a.questionGroups):[],[a]),E=b===I.length-1,j=I[b]??[],M=o.useCallback((N,k)=>{f(w=>({...w,[N]:k})),p(w=>{const T={...w};return delete T[N],T})},[]),C=o.useCallback(()=>{const N={};for(const{question:k}of j){const w=$r(k,u[k.id]??[]);w&&(N[k.id]=w)}return p(k=>({...k,...N})),Object.keys(N).length===0},[j,u]),A=()=>{C()&&g(N=>N+1)},q=()=>{b>0?g(N=>N-1):s==null||s()},W=async()=>{if(!(!C()||!a))try{const N=a.questionGroups.flatMap(w=>(w.questions??[]).map(T=>({questionId:T.id,values:u[T.id]??[]}))),k={applicantId:t,questionnarieId:a.id,questionResults:N};await m(k),r==null||r()}catch(N){console.error("Questionnaire submit error:",N)}};return i?e.jsx(H,{children:e.jsx(U,{children:e.jsx(ve,{className:"my-8"})})}):d?e.jsx(H,{children:e.jsx(U,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading questionnaire: ",d.message]})})}):a?e.jsxs(H,{children:[e.jsxs(le,{children:[e.jsx("h2",{className:"text-lg font-bold",children:a.displayName}),a.subtitle&&e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:a.subtitle}),I.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 ",b+1," of ",I.length]}),e.jsx("div",{className:"flex items-center gap-1.5",children:I.map((N,k)=>e.jsx("div",{className:"rounded-full transition-all duration-200",style:{height:"6px",width:k===b?"20px":"6px",backgroundColor:k<=b?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},k))})]})]}),e.jsx(U,{className:"space-y-6",children:j.map(({question:N})=>e.jsx(Hr,{question:N,value:u[N.id]??[],error:S[N.id],onChange:k=>M(N.id,k)},N.id))}),e.jsxs(me,{className:"flex items-center justify-between",children:[e.jsxs(K,{type:"button",variant:"outline",onClick:q,style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(dr,{size:14}),b>0?"Previous":"Back"]}),E?e.jsx(K,{type:"button",isLoading:l,onClick:W,children:"Continue"}):e.jsxs(K,{type:"button",onClick:A,style:{display:"flex",alignItems:"center",gap:"4px"},children:["Next",e.jsx(ur,{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},Hr=({question:t,value:r,error:s,onChange:a})=>{var l;const i=(((l=t.defaultAnswers)==null?void 0:l.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}),i==="text"&&e.jsx(ue,{value:r[0]??"",onChange:d=>a([d.target.value]),placeholder:t.subtitle?void 0:"Enter your answer…",error:s,required:t.isRequired}),i==="single-select"&&e.jsx(Ge,{value:r[0]??"",onChange:d=>a([d.target.value]),options:(t.defaultAnswers??[]).map(d=>({value:d,label:d})),placeholder:"Select an option…",error:s,required:t.isRequired}),i==="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:()=>a([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})]}),(i==="checkbox"||i==="multi-select")&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultAnswers??[]).map(d=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"checkbox",checked:r.includes(d),onChange:m=>{m.target.checked?a([...r,d]):a(r.filter(u=>u!==d))},className:"metakyc-option-input",style:{width:"16px",height:"16px",minWidth:"16px",flexShrink:0,flexGrow:0,accentColor:"var(--metakyc-primary, #2563eb)",cursor:"pointer",margin:0,padding:0,display:"inline-block",verticalAlign:"middle"}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:d})]},d)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),s&&i==="text"&&null]})},pr=({applicantId:t,onComplete:r,onBack:s})=>{const{uploadDocument:a,isLoading:n,isSubmitting:i,error:l,submit:d}=er(t),[m,u]=o.useState({}),f=async S=>{if(S.preventDefault(),!a)return;const p=await Promise.all(a.uploadDocumentFiles.map(async g=>{const I=m[g.id]||[],E=await Promise.all(I.map(async j=>({fileName:j.name,fileData:await Yt(j)})));return{uploadDocumentFileId:g.id,valueList:E}})),b={applicantId:t,uploadDocumentId:a.id,uploadDocumentResults:p};await d(b),r==null||r()};return n?e.jsx(H,{children:e.jsx(U,{children:e.jsx(ve,{className:"my-8"})})}):l?e.jsx(H,{children:e.jsx(U,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading document requirements: ",l.message]})})}):a?e.jsx("form",{onSubmit:f,children:e.jsxs(H,{children:[e.jsxs(le,{children:[e.jsx("h2",{className:"text-lg font-bold",children:a.displayName}),a.subtitle&&e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:a.subtitle})]}),e.jsx(U,{className:"space-y-6",children:a.uploadDocumentFiles.map(S=>e.jsx(ir,{label:S.displayName,accept:S.allowedTypes,multiple:S.multipleFile,maxSize:S.maxEachFileSizeByte,value:m[S.id]||[],onChange:p=>{u(b=>({...b,[S.id]:p}))}},S.id))}),e.jsxs(me,{className:"flex justify-between",children:[s&&e.jsx(K,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(K,{type:"submit",isLoading:i,children:"Continue"})]})]})}):null},hr=({applicantId:t,onComplete:r,onBack:s})=>{const{overview:a,isLoading:n,isSubmitting:i,error:l,passOverview:d}=tr(t),m=async()=>{await d(),r==null||r()};return n?e.jsx(H,{children:e.jsx(U,{children:e.jsx(ve,{className:"my-8"})})}):l?e.jsx(H,{children:e.jsx(U,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading overview: ",l.message]})})}):a?e.jsxs(H,{children:[e.jsxs(le,{children:[e.jsx("h2",{className:"text-lg font-bold",children:a.title||"Overview"}),a.description&&e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:a.description})]}),e.jsx(U,{className:"space-y-8",children:a.steps&&a.steps.length>0?a.steps.sort((u,f)=>u.order-f.order).map(u=>e.jsxs("div",{className:"metakyc-overview-step-item flex items-center space-x-3",children:[e.jsx("div",{className:"metakyc-step-icon flex-shrink-0",children:e.jsx("div",{className:"w-8 h-8 rounded-full bg-primary-500 text-white flex items-center justify-center font-medium text-sm",children:u.order+1})}),e.jsxs("div",{className:"metakyc-step-content",style:{flex:1,border:"none",height:"auto",background:"transparent"},children:[e.jsx("span",{className:"metakyc-step-title text-sm font-semibold text-gray-900 dark:text-white",children:u.title}),u.description&&e.jsx("p",{className:"metakyc-step-description text-sm text-gray-600 dark:text-gray-400",children:u.description})]})]},u.order)):e.jsx("div",{className:"text-center py-8",children:e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Loading overview data..."})})}),e.jsxs(me,{className:"flex justify-between",children:[s&&e.jsx(K,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(K,{onClick:m,isLoading:i,children:"Continue"})]})]}):null};function Ur(t,r){const s=!r||r.length===0||r.every(a=>!a||!a.trim());if(t.isRequired&&s)return t.errorMessage||`${t.displayName} is required`;if(!s){const a=r[0]??"";if(a&&t.regex)try{if(!new RegExp(t.regex).test(a))return t.errorMessage||"Invalid format"}catch{}const n=t.valueDataType===Ce.Integer||t.valueDataType===Ce.Decimal||t.valueDataType===Ce.DigitOnly;if(n&&a.trim()!==""){const i=Number(a);if(!isNaN(i)){if(t.min!==void 0&&t.min!==null&&i<t.min)return`Minimum value is ${t.min}`;if(t.max!==void 0&&t.max!==null&&i>t.max)return`Maximum value is ${t.max}`}}else if(!n&&a!==""){if(t.min!==void 0&&t.min!==null&&a.length<t.min)return`Minimum length is ${t.min} characters`;if(t.max!==void 0&&t.max!==null&&a.length>t.max)return`Maximum length is ${t.max} characters`}}return null}function Kr(t){const r=new Map;return t.forEach((s,a)=>{const n=s.pageNumber!=null&&s.pageNumber>0?s.pageNumber:1;r.has(n)||r.set(n,[]),r.get(n).push({criterion:s,idx:a})}),Array.from(r.entries()).sort(([s],[a])=>s-a).map(([,s])=>s)}function Wr(t){return t.builtInType===1?"country":!t.defaultValues||t.defaultValues.length===0?"text":t.multipleValue?"checkbox":"radio"}const gr=({applicantId:t,onComplete:r,onBack:s})=>{const{criteria:a,initialAnswers:n,isLoading:i,isSubmitting:l,error:d,submit:m}=sr(t),[u,f]=o.useState({}),[S,p]=o.useState({}),[b,g]=o.useState(0),[I,E]=o.useState(!1);o.useEffect(()=>{n&&Object.keys(n).length>0&&Object.keys(u).length===0&&f(n)},[n]);const j=o.useMemo(()=>a&&a.length>0?Kr(a):[],[a]),M=b===j.length-1,C=j[b]??[];o.useEffect(()=>{!i&&a&&a.length===0&&!I&&!l&&(E(!0),m({applicantId:t,criteriaValueInputs:[]}).then(()=>r==null?void 0:r()).catch(console.error))},[i,a,I,l,m,t,r]);const A=o.useCallback((w,T)=>{f(F=>({...F,[w]:T})),p(F=>{const Y={...F};return delete Y[w],Y})},[]),q=o.useCallback(()=>{const w={};for(const{criterion:T}of C){const F=Ur(T,u[T.id]??[]);F&&(w[T.id]=F)}return p(T=>({...T,...w})),Object.keys(w).length===0},[C,u]),W=()=>{q()&&g(w=>w+1)},N=()=>{b>0?g(w=>w-1):s==null||s()},k=async()=>{if(!(!q()||!a))try{const w=a.map(F=>{const Y=(u[F.id]??[]).filter(O=>O&&O.trim());return Y.length>0?{riskCriteriaId:F.id,values:Y}:null}).filter(F=>F!==null);await m({applicantId:t,criteriaValueInputs:w}),r==null||r()}catch(w){console.error("Risk scoring submit error:",w)}};return i?e.jsx(H,{children:e.jsxs(U,{children:[e.jsx(ve,{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…"})]})}):!i&&a&&a.length===0?e.jsx(H,{children:e.jsxs(U,{children:[e.jsx(ve,{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…"})]})}):d?e.jsx(H,{children:e.jsx(U,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading criteria: ",d.message]})})}):a?e.jsxs(H,{children:[e.jsxs(le,{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"}),j.length>1&&e.jsxs("div",{className:"flex items-center justify-between mt-3",children:[e.jsxs("span",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:["Page ",b+1," of ",j.length]}),e.jsx("div",{className:"flex items-center gap-1.5",children:j.map((w,T)=>e.jsx("div",{className:"rounded-full transition-all duration-200",style:{height:"6px",width:T===b?"20px":"6px",backgroundColor:T<=b?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},T))})]})]}),e.jsx(U,{className:"space-y-6",children:C.map(({criterion:w})=>e.jsx(Yr,{criterion:w,value:u[w.id]??[],error:S[w.id],onChange:T=>A(w.id,T)},w.id))}),e.jsxs(me,{className:"flex items-center justify-between",children:[e.jsxs(K,{type:"button",variant:"outline",onClick:N,style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(dr,{size:14}),b>0?"Previous":"Back"]}),M?e.jsx(K,{type:"button",isLoading:l,onClick:k,children:"Continue"}):e.jsxs(K,{type:"button",onClick:W,style:{display:"flex",alignItems:"center",gap:"4px"},children:["Next",e.jsx(ur,{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},Yr=({criterion:t,value:r,error:s,onChange:a})=>{const n=Wr(t),i=t.valueDataType===Ce.Integer||t.valueDataType===Ce.Decimal||t.valueDataType===Ce.DigitOnly;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}),i&&(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}`}),n==="text"&&e.jsx(ue,{value:r[0]??"",onChange:l=>a([l.target.value]),type:i?"number":"text",placeholder:"Enter your answer…",error:s,required:t.isRequired,min:t.min,max:t.max,onKeyDown:l=>{t.valueDataType===Ce.DigitOnly&&["e","E","+","-","."].includes(l.key)&&l.preventDefault()}}),n==="radio"&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultValues??[]).map(l=>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]===l,onChange:()=>a([l]),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:l})]},l)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),n==="checkbox"&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultValues??[]).map(l=>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(l),onChange:d=>{d.target.checked?a([...r,l]):a(r.filter(m=>m!==l))},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:l})]},l)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),n==="country"&&e.jsx(Ge,{value:r[0]??"",onChange:l=>a([l.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})]})},xr=({applicantId:t,onComplete:r,onBack:s})=>{const{investorCategorizationService:a}=xe(),[n,i]=o.useState(null),[l,d]=o.useState(!1),[m,u]=o.useState(null),f=async S=>{if(S.preventDefault(),n===null){u("Please select an investor type");return}d(!0),u(null);try{const p={applicantId:t,investorType:n};console.log("Submitting investor categorization:",p);const b=await a.setInvestorCategorization(p);console.log("Investor categorization result:",b),r==null||r()}catch(p){console.error("Error submitting investor categorization:",p),u(p.message||"Failed to submit investor categorization")}finally{d(!1)}};return e.jsx("form",{onSubmit:f,children:e.jsxs(H,{children:[e.jsxs(le,{children:[e.jsx("h2",{className:"text-lg font-bold text-gray-900 dark:text-white",children:"Which statement best describes you?"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-2",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(U,{className:"space-y-4",children:[e.jsx("p",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 mb-3",children:"Choose one"}),e.jsx("label",{className:`
|
|
51
|
+
*/const Br=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],ur=cr("chevron-right",Br);function $r(t,r){const s=!r||r.length===0||r.every(a=>!a||!a.trim());if(t.isRequired&&s)return t.errorMessage||"This field is required";if(!s){const a=r[0]??"";if(a&&t.regex)try{if(!new RegExp(t.regex).test(a))return t.errorMessage||"Invalid format"}catch{}if(a!==""){const n=Number(a);if(!isNaN(n)&&a.trim()!==""){if(t.min!==void 0&&t.min!==null&&n<t.min)return`Minimum value is ${t.min}`;if(t.max!==void 0&&t.max!==null&&n>t.max)return`Maximum value is ${t.max}`}else{if(t.min!==void 0&&t.min!==null&&a.length<t.min)return`Minimum length is ${t.min} characters`;if(t.max!==void 0&&t.max!==null&&a.length>t.max)return`Maximum length is ${t.max} characters`}}}return null}function _r(t){const r=t.flatMap((a,n)=>(a.questions??[]).map((i,d)=>({question:i,groupIndex:n,qIdx:d}))),s=new Map;for(const a of r){const n=a.question.pageNumber!=null&&a.question.pageNumber>0?a.question.pageNumber:1;s.has(n)||s.set(n,[]),s.get(n).push(a)}return Array.from(s.entries()).sort(([a],[n])=>a-n).map(([,a])=>a)}const mr=({applicantId:t,onComplete:r,onBack:s})=>{const{questionnaire:a,initialAnswers:n,isLoading:i,isSubmitting:d,error:u,submit:x}=Xt(t),[p,b]=o.useState({}),[N,g]=o.useState({}),[v,f]=o.useState(0);o.useEffect(()=>{n&&Object.keys(n).length>0&&Object.keys(p).length===0&&b(n)},[n]);const P=o.useMemo(()=>a?_r(a.questionGroups):[],[a]),A=v===P.length-1,S=P[v]??[],z=o.useCallback((C,w)=>{b(j=>({...j,[C]:w})),g(j=>{const M={...j};return delete M[C],M})},[]),R=o.useCallback(()=>{const C={};for(const{question:w}of S){const j=$r(w,p[w.id]??[]);j&&(C[w.id]=j)}return g(w=>({...w,...C})),Object.keys(C).length===0},[S,p]),E=()=>{R()&&f(C=>C+1)},Q=()=>{v>0?f(C=>C-1):s==null||s()},Y=async()=>{if(!(!R()||!a))try{const C=a.questionGroups.flatMap(j=>(j.questions??[]).map(M=>({questionId:M.id,values:p[M.id]??[]}))),w={applicantId:t,questionnarieId:a.id,questionResults:C};await x(w),r==null||r()}catch(C){console.error("Questionnaire submit error:",C)}};return i?e.jsx(U,{children:e.jsx(K,{children:e.jsx(fe,{className:"my-8"})})}):u?e.jsx(U,{children:e.jsx(K,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading questionnaire: ",u.message]})})}):a?e.jsxs(U,{children:[e.jsxs(oe,{children:[e.jsx("h2",{className:"text-lg font-bold",children:a.displayName}),a.subtitle&&e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:a.subtitle}),P.length>1&&e.jsxs("div",{className:"flex items-center justify-between mt-3",children:[e.jsxs("span",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:["Page ",v+1," of ",P.length]}),e.jsx("div",{className:"flex items-center gap-1.5",children:P.map((C,w)=>e.jsx("div",{className:"rounded-full transition-all duration-200",style:{height:"6px",width:w===v?"20px":"6px",backgroundColor:w<=v?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},w))})]})]}),e.jsx(K,{className:"space-y-6",children:S.map(({question:C})=>e.jsx(Hr,{question:C,value:p[C.id]??[],error:N[C.id],onChange:w=>z(C.id,w)},C.id))}),e.jsxs(ce,{className:"flex items-center justify-between",children:[e.jsxs(W,{type:"button",variant:"outline",onClick:Q,style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(dr,{size:14}),v>0?"Previous":"Back"]}),A?e.jsx(W,{type:"button",isLoading:d,onClick:Y,children:"Continue"}):e.jsxs(W,{type:"button",onClick:E,style:{display:"flex",alignItems:"center",gap:"4px"},children:["Next",e.jsx(ur,{size:14})]})]}),u&&e.jsx("div",{className:"mx-6 mb-4 p-3 bg-red-50 border border-red-200 rounded",children:e.jsx("p",{className:"text-red-600 text-sm",children:u.message})})]}):null},Hr=({question:t,value:r,error:s,onChange:a})=>{var d;const i=(((d=t.defaultAnswers)==null?void 0:d.length)??0)>0?t.showAsDropdown?t.canMultipleAnswer?"multi-select":"single-select":t.canMultipleAnswer?"checkbox":"radio":"text";return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[t.text,t.isRequired&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),t.subtitle&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:t.subtitle}),t.description&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:t.description}),i==="text"&&e.jsx(ie,{value:r[0]??"",onChange:u=>a([u.target.value]),placeholder:t.subtitle?void 0:"Enter your answer…",error:s,required:t.isRequired}),i==="single-select"&&e.jsx(Ve,{value:r[0]??"",onChange:u=>a([u.target.value]),options:(t.defaultAnswers??[]).map(u=>({value:u,label:u})),placeholder:"Select an option…",error:s,required:t.isRequired}),i==="radio"&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultAnswers??[]).map(u=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"radio",checked:r[0]===u,onChange:()=>a([u]),className:"metakyc-option-input",style:{width:"16px",height:"16px",minWidth:"16px",flexShrink:0,flexGrow:0,accentColor:"var(--metakyc-primary, #2563eb)",cursor:"pointer",margin:0,padding:0,display:"inline-block",verticalAlign:"middle"}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:u})]},u)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),(i==="checkbox"||i==="multi-select")&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultAnswers??[]).map(u=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"checkbox",checked:r.includes(u),onChange:x=>{x.target.checked?a([...r,u]):a(r.filter(p=>p!==u))},className:"metakyc-option-input",style:{width:"16px",height:"16px",minWidth:"16px",flexShrink:0,flexGrow:0,accentColor:"var(--metakyc-primary, #2563eb)",cursor:"pointer",margin:0,padding:0,display:"inline-block",verticalAlign:"middle"}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:u})]},u)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),s&&i==="text"&&null]})},pr=({applicantId:t,onComplete:r,onBack:s})=>{const{uploadDocument:a,isLoading:n,isSubmitting:i,error:d,submit:u}=er(t),[x,p]=o.useState({}),b=async N=>{if(N.preventDefault(),!a)return;const g=await Promise.all(a.uploadDocumentFiles.map(async f=>{const P=x[f.id]||[],A=await Promise.all(P.map(async S=>({fileName:S.name,fileData:await Yt(S)})));return{uploadDocumentFileId:f.id,valueList:A}})),v={applicantId:t,uploadDocumentId:a.id,uploadDocumentResults:g};await u(v),r==null||r()};return n?e.jsx(U,{children:e.jsx(K,{children:e.jsx(fe,{className:"my-8"})})}):d?e.jsx(U,{children:e.jsx(K,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading document requirements: ",d.message]})})}):a?e.jsx("form",{onSubmit:b,children:e.jsxs(U,{children:[e.jsxs(oe,{children:[e.jsx("h2",{className:"text-lg font-bold",children:a.displayName}),a.subtitle&&e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:a.subtitle})]}),e.jsx(K,{className:"space-y-6",children:a.uploadDocumentFiles.map(N=>e.jsx(ir,{label:N.displayName,accept:N.allowedTypes,multiple:N.multipleFile,maxSize:N.maxEachFileSizeByte,value:x[N.id]||[],onChange:g=>{p(v=>({...v,[N.id]:g}))}},N.id))}),e.jsxs(ce,{className:"flex justify-between",children:[s&&e.jsx(W,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(W,{type:"submit",isLoading:i,children:"Continue"})]})]})}):null},hr=({applicantId:t,onComplete:r,onBack:s})=>{const{overview:a,isLoading:n,isSubmitting:i,error:d,passOverview:u}=tr(t),x=async()=>{await u(),r==null||r()};return n?e.jsx(U,{children:e.jsx(K,{children:e.jsx(fe,{className:"my-8"})})}):d?e.jsx(U,{children:e.jsx(K,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading overview: ",d.message]})})}):a?e.jsxs(U,{children:[e.jsxs(oe,{children:[e.jsx("h2",{className:"text-lg font-bold",children:a.title||"Overview"}),a.description&&e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:a.description})]}),e.jsx(K,{className:"space-y-8",children:a.steps&&a.steps.length>0?a.steps.sort((p,b)=>p.order-b.order).map(p=>e.jsxs("div",{className:"metakyc-overview-step-item flex items-center space-x-3",children:[e.jsx("div",{className:"metakyc-step-icon flex-shrink-0",children:e.jsx("div",{className:"w-8 h-8 rounded-full bg-primary-500 text-white flex items-center justify-center font-medium text-sm",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 text-gray-900 dark:text-white",children:p.title}),p.description&&e.jsx("p",{className:"metakyc-step-description text-sm text-gray-600 dark:text-gray-400",children:p.description})]})]},p.order)):e.jsx("div",{className:"text-center py-8",children:e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Loading overview data..."})})}),e.jsxs(ce,{className:"flex justify-between",children:[s&&e.jsx(W,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(W,{onClick:x,isLoading:i,children:"Continue"})]})]}):null};function Ur(t,r){const s=!r||r.length===0||r.every(a=>!a||!a.trim());if(t.isRequired&&s)return t.errorMessage||`${t.displayName} is required`;if(!s){const a=r[0]??"";if(a&&t.regex)try{if(!new RegExp(t.regex).test(a))return t.errorMessage||"Invalid format"}catch{}const n=t.valueDataType===je.Integer||t.valueDataType===je.Decimal||t.valueDataType===je.DigitOnly;if(n&&a.trim()!==""){const i=Number(a);if(!isNaN(i)){if(t.min!==void 0&&t.min!==null&&i<t.min)return`Minimum value is ${t.min}`;if(t.max!==void 0&&t.max!==null&&i>t.max)return`Maximum value is ${t.max}`}}else if(!n&&a!==""){if(t.min!==void 0&&t.min!==null&&a.length<t.min)return`Minimum length is ${t.min} characters`;if(t.max!==void 0&&t.max!==null&&a.length>t.max)return`Maximum length is ${t.max} characters`}}return null}function Kr(t){const r=new Map;return t.forEach((s,a)=>{const n=s.pageNumber!=null&&s.pageNumber>0?s.pageNumber:1;r.has(n)||r.set(n,[]),r.get(n).push({criterion:s,idx:a})}),Array.from(r.entries()).sort(([s],[a])=>s-a).map(([,s])=>s)}function Wr(t){return t.builtInType===1?"country":!t.defaultValues||t.defaultValues.length===0?"text":t.multipleValue?"checkbox":"radio"}const xr=({applicantId:t,onComplete:r,onBack:s})=>{const{criteria:a,initialAnswers:n,isLoading:i,isSubmitting:d,error:u,submit:x}=sr(t),[p,b]=o.useState({}),[N,g]=o.useState({}),[v,f]=o.useState(0),[P,A]=o.useState(!1);o.useEffect(()=>{n&&Object.keys(n).length>0&&Object.keys(p).length===0&&b(n)},[n]);const S=o.useMemo(()=>a&&a.length>0?Kr(a):[],[a]),z=v===S.length-1,R=S[v]??[];o.useEffect(()=>{!i&&a&&a.length===0&&!P&&!d&&(A(!0),x({applicantId:t,criteriaValueInputs:[]}).then(()=>r==null?void 0:r()).catch(console.error))},[i,a,P,d,x,t,r]);const E=o.useCallback((j,M)=>{b(L=>({...L,[j]:M})),g(L=>{const q={...L};return delete q[j],q})},[]),Q=o.useCallback(()=>{const j={};for(const{criterion:M}of R){const L=Ur(M,p[M.id]??[]);L&&(j[M.id]=L)}return g(M=>({...M,...j})),Object.keys(j).length===0},[R,p]),Y=()=>{Q()&&f(j=>j+1)},C=()=>{v>0?f(j=>j-1):s==null||s()},w=async()=>{if(!(!Q()||!a))try{const j=a.map(L=>{const q=(p[L.id]??[]).filter(B=>B&&B.trim());return q.length>0?{riskCriteriaId:L.id,values:q}:null}).filter(L=>L!==null);await x({applicantId:t,criteriaValueInputs:j}),r==null||r()}catch(j){console.error("Risk scoring submit error:",j)}};return i?e.jsx(U,{children:e.jsxs(K,{children:[e.jsx(fe,{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…"})]})}):!i&&a&&a.length===0?e.jsx(U,{children:e.jsxs(K,{children:[e.jsx(fe,{className:"my-8"}),e.jsx("p",{className:"text-center text-sm mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"No criteria required. Moving to next step…"})]})}):u?e.jsx(U,{children:e.jsx(K,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading criteria: ",u.message]})})}):a?e.jsxs(U,{children:[e.jsxs(oe,{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"}),S.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 ",v+1," of ",S.length]}),e.jsx("div",{className:"flex items-center gap-1.5",children:S.map((j,M)=>e.jsx("div",{className:"rounded-full transition-all duration-200",style:{height:"6px",width:M===v?"20px":"6px",backgroundColor:M<=v?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},M))})]})]}),e.jsx(K,{className:"space-y-6",children:R.map(({criterion:j})=>e.jsx(Yr,{criterion:j,value:p[j.id]??[],error:N[j.id],onChange:M=>E(j.id,M)},j.id))}),e.jsxs(ce,{className:"flex items-center justify-between",children:[e.jsxs(W,{type:"button",variant:"outline",onClick:C,style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(dr,{size:14}),v>0?"Previous":"Back"]}),z?e.jsx(W,{type:"button",isLoading:d,onClick:w,children:"Continue"}):e.jsxs(W,{type:"button",onClick:Y,style:{display:"flex",alignItems:"center",gap:"4px"},children:["Next",e.jsx(ur,{size:14})]})]}),u&&e.jsx("div",{className:"mx-6 mb-4 p-3 bg-red-50 border border-red-200 rounded",children:e.jsx("p",{className:"text-red-600 text-sm",children:u.message})})]}):null},Yr=({criterion:t,value:r,error:s,onChange:a})=>{const n=Wr(t),i=t.valueDataType===je.Integer||t.valueDataType===je.Decimal||t.valueDataType===je.DigitOnly;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}),i&&(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}`}),n==="text"&&e.jsx(ie,{value:r[0]??"",onChange:d=>a([d.target.value]),type:i?"number":"text",placeholder:"Enter your answer…",error:s,required:t.isRequired,min:t.min,max:t.max,onKeyDown:d=>{t.valueDataType===je.DigitOnly&&["e","E","+","-","."].includes(d.key)&&d.preventDefault()}}),n==="radio"&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultValues??[]).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:()=>a([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})]}),n==="checkbox"&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultValues??[]).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:u=>{u.target.checked?a([...r,d]):a(r.filter(x=>x!==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})]}),n==="country"&&e.jsx(Ve,{value:r[0]??"",onChange:d=>a([d.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})]})},gr=({applicantId:t,onComplete:r,onBack:s})=>{const{investorCategorizationService:a}=he(),[n,i]=o.useState(null),[d,u]=o.useState(!1),[x,p]=o.useState(null),b=async N=>{if(N.preventDefault(),n===null){p("Please select an investor type");return}u(!0),p(null);try{const g={applicantId:t,investorType:n};console.log("Submitting investor categorization:",g);const v=await a.setInvestorCategorization(g);console.log("Investor categorization result:",v),r==null||r()}catch(g){console.error("Error submitting investor categorization:",g),p(g.message||"Failed to submit investor categorization")}finally{u(!1)}};return e.jsx("form",{onSubmit:b,children:e.jsxs(U,{children:[e.jsxs(oe,{children:[e.jsx("h2",{className:"text-lg font-bold text-gray-900 dark:text-white",children:"Which statement best describes you?"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-2",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(K,{className:"space-y-4",children:[e.jsx("p",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 mb-3",children:"Choose one"}),e.jsx("label",{className:`
|
|
52
52
|
block p-4 border-2 rounded-lg cursor-pointer transition-all
|
|
53
|
-
${n===
|
|
54
|
-
`,children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:
|
|
53
|
+
${n===pe.Individual?"border-primary-500 bg-primary-50 dark:bg-primary-900/20":"border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600"}
|
|
54
|
+
`,children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:pe.Individual,checked:n===pe.Individual,onChange:()=>i(pe.Individual),className:"mt-1 h-4 w-4 text-primary-500 border-gray-300 focus:ring-primary-500"}),e.jsxs("div",{className:"ml-3",children:[e.jsx("div",{className:"text-base font-semibold text-gray-900 dark:text-white",children:"Individual investor"}),e.jsx("div",{className:"text-sm text-gray-600 dark:text-gray-400 mt-1",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:`
|
|
55
55
|
block p-4 border-2 rounded-lg cursor-pointer transition-all
|
|
56
|
-
${n===
|
|
57
|
-
`,children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:
|
|
56
|
+
${n===pe.Sophisticated?"border-primary-500 bg-primary-50 dark:bg-primary-900/20":"border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600"}
|
|
57
|
+
`,children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:pe.Sophisticated,checked:n===pe.Sophisticated,onChange:()=>i(pe.Sophisticated),className:"mt-1 h-4 w-4 text-primary-500 border-gray-300 focus:ring-primary-500"}),e.jsxs("div",{className:"ml-3",children:[e.jsx("div",{className:"text-base font-semibold text-gray-900 dark:text-white",children:"Sophisticated investor"}),e.jsx("div",{className:"text-sm text-gray-600 dark:text-gray-400 mt-1",children:"In the last 2 years, I have done one or more of the following:"}),e.jsxs("ul",{className:"text-sm text-gray-600 dark:text-gray-400 mt-2 space-y-1 list-none",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:`
|
|
58
58
|
block p-4 border-2 rounded-lg cursor-pointer transition-all
|
|
59
|
-
${n===
|
|
60
|
-
`,children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:
|
|
59
|
+
${n===pe.HighNetWorth?"border-primary-500 bg-primary-50 dark:bg-primary-900/20":"border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600"}
|
|
60
|
+
`,children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:pe.HighNetWorth,checked:n===pe.HighNetWorth,onChange:()=>i(pe.HighNetWorth),className:"mt-1 h-4 w-4 text-primary-500 border-gray-300 focus:ring-primary-500"}),e.jsxs("div",{className:"ml-3",children:[e.jsx("div",{className:"text-base font-semibold text-gray-900 dark:text-white",children:"High networth investor"}),e.jsxs("div",{className:"text-sm text-gray-600 dark:text-gray-400 mt-1",children:["I earn more than (USD/EUR) $150,000 per year, and/or",e.jsx("br",{}),"I have net assets (excluding my main property) of at least $/EUR 300,000"]})]})]})}),x&&e.jsx("div",{className:"p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg",children:e.jsxs("p",{className:"text-red-600 dark:text-red-400 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",x]})})]}),e.jsxs(ce,{className:"flex justify-between",children:[s&&e.jsx(W,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(W,{type:"submit",isLoading:d,disabled:n===null,children:"Submit"})]})]})})},yr=({applicantId:t,onComplete:r,onBack:s})=>{const{appropriatenessTestService:a}=he(),[n,i]=o.useState(null),[d,u]=o.useState(!0),[x,p]=o.useState(!1),[b,N]=o.useState(null),[g,v]=o.useState({}),[f,P]=o.useState(0),[A,S]=o.useState(!1),[z,R]=o.useState(!1),[E,Q]=o.useState(0);o.useEffect(()=>{(async()=>{try{u(!0),N(null),console.log("Loading appropriateness test for applicant:",t);const O=await a.getAppropriatenessTest(t);if(console.log("Appropriateness test data:",O),i(O),O.waitTimeSpanForNextTry&&O.waitTimeSpanForNextTry!=="00:00:00"){const Z=Y(O.waitTimeSpanForNextTry);Z>0&&Q(Z)}}catch(O){console.error("Error loading appropriateness test:",O),N(O.message||"Failed to load appropriateness test")}finally{u(!1)}})()},[t,a]);const Y=B=>{const O=B.split(":").map(Number);if(O.length===3){const[Z,k,H]=O;return Z*3600+k*60+H}return 0},C=B=>{const O=Math.floor(B/60),Z=B%60;return`${O.toString().padStart(2,"0")}:${Z.toString().padStart(2,"0")}`};o.useEffect(()=>{if(!A||f<=0)return;const B=setInterval(()=>{P(O=>O<=1?(R(!0),0):O-1)},1e3);return()=>clearInterval(B)},[A,f]),o.useEffect(()=>{if(E<=0)return;const B=setInterval(()=>{Q(O=>O<=1?0:O-1)},1e3);return()=>clearInterval(B)},[E]),o.useEffect(()=>{z&&!x&&M()},[z]);const w=()=>{n&&(S(!0),P(n.testDurationSec))},j=(B,O)=>{v(Z=>({...Z,[B]:O}))},M=async B=>{if(B&&B.preventDefault(),!!n){if(!z){const O=n.appropriatenessQuestions.length-Object.keys(g).length;if(O>0){N(`Please answer all questions. ${O} question(s) remaining.`);return}}p(!0),N(null);try{const O=n.appropriatenessQuestions.map(k=>({appropriatenessQuestionId:k.id,value:g[k.id]||""})),Z={applicantId:t,appropriatenessTestId:n.id,appropriatenessQuestionResults:O};console.log("Submitting appropriateness test:",Z);try{const k=await a.fillAppropriatenessTest(Z);console.log("Appropriateness test result:",k),k.message&&(k.message.toLowerCase().includes("pass")||k.message.toLowerCase().includes("success")||k.message.toLowerCase().includes("congratulations"))?r==null||r():(N(k.message||"Test completed. Please check the result."),S(!1),R(!1),v({}),setTimeout(()=>L(),1e3))}catch(k){if(k.code===400&&k.message){const H=k.message;console.log("Test failed:",H),N(H),S(!1),R(!1),v({}),setTimeout(()=>L(),1500)}else throw k}}catch(O){console.error("Error submitting appropriateness test:",O),N(O.message||"Failed to submit test. Please try again."),S(!1),R(!1),v({})}finally{p(!1)}}},L=async()=>{try{const B=await a.getAppropriatenessTest(t);if(console.log("Reloaded test data:",B),i(B),B.waitTimeSpanForNextTry&&B.waitTimeSpanForNextTry!=="00:00:00"){const O=Y(B.waitTimeSpanForNextTry);O>0&&Q(O)}}catch(B){console.error("Error reloading test data:",B),N(O=>O+`
|
|
61
61
|
|
|
62
|
-
Failed to reload test data. Please refresh the page.`)}};if(
|
|
62
|
+
Failed to reload test data. Please refresh the page.`)}};if(d)return e.jsx(U,{children:e.jsxs(K,{children:[e.jsx(fe,{className:"my-8"}),e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-4",children:"Loading appropriateness test..."})]})});if(!n)return e.jsx(U,{children:e.jsxs(K,{className:"py-12 text-center",children:[e.jsx("p",{className:"text-danger-500 text-lg mb-4",children:"No test data available"}),b&&e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:b})]})});if(E>0)return e.jsxs(U,{children:[e.jsxs(oe,{children:[e.jsx("h2",{className:"text-lg font-bold text-gray-900 dark:text-white",children:n.displayName}),n.subtitle&&e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-2",children:n.subtitle})]}),e.jsxs(K,{className:"py-12 text-center",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("div",{className:"text-6xl font-bold text-primary-500 mb-2",children:C(E)}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Please wait before attempting the test again"})]}),b&&e.jsx("div",{className:"mt-4 p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg",children:e.jsx("p",{className:"text-red-600 dark:text-red-400 text-sm",children:b})})]})]});const q=n.testAllowedMaxTry-n.totalFailedTries;return A?e.jsx("form",{onSubmit:M,children:e.jsxs(U,{children:[e.jsx(oe,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-gray-900 dark:text-white",children:n.displayName}),n.subtitle&&e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:n.subtitle})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:`text-3xl font-bold ${f<=60?"text-danger-500":"text-primary-500"}`,children:C(f)}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Time Remaining"})]})]})}),e.jsxs(K,{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs(we,{variant:"info",children:["Question ",Object.keys(g).length," of ",n.totalQuestionCount]}),e.jsxs(we,{variant:q>1?"success":"warning",children:[q," attempt",q!==1?"s":""," remaining"]})]}),n.appropriatenessQuestions.map((B,O)=>e.jsxs("div",{className:"p-4 border border-gray-200 dark:border-gray-700 rounded-lg",children:[e.jsxs("div",{className:"mb-4",children:[e.jsxs("span",{className:"inline-block px-2 py-1 text-xs font-semibold text-primary-700 bg-primary-100 dark:text-primary-300 dark:bg-primary-900/30 rounded mb-2",children:["Question ",O+1]}),B.groupName&&e.jsx("span",{className:"ml-2 text-xs text-gray-500 dark:text-gray-400",children:B.groupName}),e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white mt-2",children:B.question})]}),e.jsx("div",{className:"space-y-2",children:B.answers.map((Z,k)=>e.jsxs("label",{className:`
|
|
63
63
|
flex items-center p-3 border-2 rounded-lg cursor-pointer transition-all
|
|
64
|
-
${
|
|
65
|
-
`,children:[e.jsx("input",{type:"radio",name:`question-${O.id}`,value:G,checked:p[O.id]===G,onChange:_=>w(O.id,_.target.value),className:"h-4 w-4 text-primary-500 border-gray-300 focus:ring-primary-500",disabled:m}),e.jsx("span",{className:"ml-3 text-gray-700 dark:text-gray-300",children:G})]},v))})]},O.id)),f&&!M&&e.jsx("div",{className:"p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg",children:e.jsxs("p",{className:"text-red-600 dark:text-red-400 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",f]})}),M&&e.jsx("div",{className:"p-4 bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg",children:e.jsxs("p",{className:"text-yellow-700 dark:text-yellow-400 text-sm",children:[e.jsx("strong",{children:"Time's up!"})," Your answers are being submitted automatically."]})})]}),e.jsxs(me,{className:"flex justify-between",children:[e.jsx(K,{type:"button",variant:"outline",onClick:s,disabled:m,children:"Cancel"}),e.jsx(K,{type:"submit",isLoading:m,disabled:Object.keys(p).length<n.totalQuestionCount,children:M?"Submitting...":"Submit Test"})]})]})}):e.jsxs(H,{children:[e.jsxs(le,{children:[e.jsx("h2",{className:"text-lg font-bold text-gray-900 dark:text-white",children:n.displayName}),n.subtitle&&e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-2",children:n.subtitle})]}),e.jsxs(U,{children:[n.description&&e.jsx("div",{className:"mb-6 p-4 bg-gray-50 dark:bg-gray-800 rounded-lg",children:e.jsx("p",{className:"text-gray-700 dark:text-gray-300",children:n.description})}),e.jsxs("div",{className:"space-y-4 mb-6",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg",children:[e.jsx("span",{className:"text-gray-700 dark:text-gray-300 font-medium",children:"Total Questions:"}),e.jsx(Ne,{variant:"info",children:n.totalQuestionCount})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg",children:[e.jsx("span",{className:"text-gray-700 dark:text-gray-300 font-medium",children:"Time Limit:"}),e.jsx(Ne,{variant:"info",children:N(n.testDurationSec)})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg",children:[e.jsx("span",{className:"text-gray-700 dark:text-gray-300 font-medium",children:"Correct Answers Required:"}),e.jsx(Ne,{variant:"info",children:n.testCorrectAnswerPassLimit})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg",children:[e.jsx("span",{className:"text-gray-700 dark:text-gray-300 font-medium",children:"Attempts Remaining:"}),e.jsx(Ne,{variant:Y>1?"success":"warning",children:Y})]})]}),f&&e.jsx("div",{className:"mb-4 p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg",children:e.jsxs("p",{className:"text-red-600 dark:text-red-400 text-sm",children:[e.jsx("strong",{children:"Previous Attempt:"})," ",f]})}),Y<=0&&e.jsx("div",{className:"p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg",children:e.jsx("p",{className:"text-red-600 dark:text-red-400",children:"You have used all your attempts. Please contact support for assistance."})})]}),e.jsxs(me,{className:"flex justify-between",children:[s&&e.jsx(K,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(K,{type:"button",onClick:k,disabled:Y<=0,children:"Start Test"})]})]})},fr=({applicantId:t,onComplete:r,onBack:s})=>{var ae,Ae,Re,We;const{applicantService:a,baseInformationService:n,config:i,currentTheme:l}=xe(),{identityData:d,provider:m,token:u,isLoading:f,error:S,requestIdentity:p,restartIdentity:b}=rr(t),[g,I]=o.useState(null),[E,j]=o.useState(null),[M,C]=o.useState([]),[A,q]=o.useState(!0),[W,N]=o.useState(!1),[k,w]=o.useState(null),[T,F]=o.useState(!1),Y=o.useRef(!1),[O,D]=o.useState({}),G=l!=null&&l.reviewPageFields&&l.reviewPageFields.length>0?l.reviewPageFields:null,v=Ie.useForm({defaultValues:{street:"",streetNumber:"",city:"",zip:"",country:"",nationality:"",phonenumber:""}});o.useEffect(()=>{(async()=>{try{const[z,V]=await Promise.all([a.getApplicantData(t),n.getCountries("","en")]);j(z);const J=new Set,ne=V.map(ce=>({value:ce.abbreviation3||ce.abbreviation,label:ce.name})).filter(ce=>!ce.value||J.has(ce.value)?!1:(J.add(ce.value),!0));C(ne);const h=z.applicantRequestData;if(D({firstName:(h==null?void 0:h.firstName)||"",lastName:(h==null?void 0:h.lastName)||"",email:(h==null?void 0:h.email)||"",dateOfBirth:(h==null?void 0:h.dateOfBirth)||"",title:(h==null?void 0:h.title)||"",salutation:(h==null?void 0:h.salutation)||"",phonenumber:(h==null?void 0:h.phonenumber)||"",mobileCountryCode:(h==null?void 0:h.mobileCountryCode)||"",street:(h==null?void 0:h.street)||"",streetNumber:(h==null?void 0:h.streetNumber)||"",city:(h==null?void 0:h.city)||"",zip:(h==null?void 0:h.zip)||"",country:(h==null?void 0:h.country)||"",nationality:(h==null?void 0:h.nationality)||"",taxCountry:(h==null?void 0:h.taxCountry)||"",countryOfBirth:(h==null?void 0:h.countryOfBirth)||"",placeOfBirth:(h==null?void 0:h.placeOfBirth)||"",educationLevel:(h==null?void 0:h.educationLevel)||"",occupation:(h==null?void 0:h.occupation)||"",taxNumber:(h==null?void 0:h.taxNumber)||"",defaultLanguage:(h==null?void 0:h.defaultLanguage)||""}),v.reset({street:(h==null?void 0:h.street)||"",streetNumber:(h==null?void 0:h.streetNumber)||"",city:(h==null?void 0:h.city)||"",zip:(h==null?void 0:h.zip)||"",country:(h==null?void 0:h.country)||"",nationality:(h==null?void 0:h.nationality)||"",phonenumber:(h==null?void 0:h.phonenumber)||""}),z.kycRecords&&z.kycRecords.length>0&&z.kycRecords[0].providerTokenObject!==null&&!Y.current){console.log("[Identity] Found existing identity verification, auto-requesting..."),Y.current=!0;try{await p(),N(!0)}catch(ce){console.error("[Identity] Auto-request failed:",ce)}}}catch(z){console.error("Error loading applicant data:",z)}finally{q(!1)}})()},[t]),o.useEffect(()=>{d&&!W&&(console.log("[Identity] Identity data already loaded, showing provider"),N(!0))},[d,W]),o.useEffect(()=>{if(u){if(u.expiresAt){const R=new Date(u.expiresAt).getTime();if(Date.now()>=R){console.warn("[Identity] Token has expired (expiresAt)"),F(!0),w("Your verification session has expired. Please restart.");return}}if(u.url)try{const z=new URL(u.url).toString().toLowerCase();if(z.includes("expired")||z.includes("invalid")||z.includes("error")){console.warn("[Identity] Token URL indicates expiration"),F(!0),w("Your verification link has expired. Please restart.");return}}catch{console.error("[Identity] Invalid token URL")}if(u.status==="expired"||u.error==="expired"||u.expired===!0){console.warn("[Identity] Token object indicates expiration"),F(!0),w("Your verification session has expired. Please restart.");return}}},[u]),o.useEffect(()=>{if(m!==null&&u&&!g&&W&&!T){const R=m;if(u.url){console.log("[Identity] Loading provider URL for user verification:",u.url),w(null);try{if(new URL(u.url),R===fe.SardinAI){console.log("[SardinAI] Initializing Risk SDK in background...");try{const z=Oe.parseProviderConfig(m,u,i);Oe.createProvider(m,z).initialize().then(()=>{console.log("[SardinAI] Risk SDK initialized successfully in background")}).catch(J=>{console.warn("[SardinAI] Risk SDK initialization failed (non-blocking):",J)})}catch(z){console.warn("[SardinAI] Risk SDK setup failed (non-blocking):",z)}}I({type:"url",url:u.url})}catch(z){console.error("[Identity] Invalid URL:",z),w("Invalid verification URL. Please restart."),F(!0)}return}if(R===fe.SardinAI){console.log("[SardinAI] No URL provided - initializing Risk SDK only..."),w(null);try{const z=Oe.parseProviderConfig(m,u,i),V=Oe.createProvider(m,z);V.initialize().then(()=>{console.log("[SardinAI] Risk SDK initialized successfully"),I(V),setTimeout(()=>{r==null||r()},2e3)}).catch(J=>{var h;console.error("[SardinAI] Failed to initialize:",J);const ne=((h=J.message)==null?void 0:h.toLowerCase())||"";ne.includes("expired")||ne.includes("invalid")||ne.includes("401")||ne.includes("400")?(F(!0),w("Session expired or invalid. Please restart verification.")):w(`Failed to initialize: ${J.message}`)})}catch(z){console.error("[SardinAI] Error creating provider:",z),w(`Configuration error: ${z.message}`)}return}try{w(null);const z=Oe.parseProviderConfig(m,u,i),V=Oe.createProvider(m,z);R===fe.Sumsub?(V.initialize("identity-container").catch(J=>{var ne;console.error("[Sumsub] Initialization error:",J),w(`Failed to initialize: ${J.message}`),(ne=J.message)!=null&&ne.toLowerCase().includes("expired")&&F(!0)}),V.onComplete&&V.onComplete(()=>{r==null||r()})):R===fe.Onfido&&V.initialize("identity-container").catch(J=>{console.error("[Onfido] Initialization error:",J),w(`Failed to initialize: ${J.message}`)}),I(V)}catch(z){console.error("[Identity] Provider setup error:",z),w(`Setup error: ${z.message}`)}}return()=>{if(g&&g.destroy)try{g.destroy()}catch(R){console.error("[Identity] Error destroying provider:",R)}}},[m,u,g,W,r,T]);const _=async()=>{try{w(null),F(!1),await p(),N(!0)}catch(R){console.error("Error starting identity verification:",R)}},X=async()=>{try{w(null),F(!1),I(null),console.log("[Identity] Restarting verification..."),await b(),N(!0)}catch(R){console.error("Error restarting identity verification:",R),w(R.message||"Failed to restart verification")}};if(A||f)return e.jsx(H,{children:e.jsxs(U,{children:[e.jsx(ve,{className:"my-8"}),e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-4",children:"Loading identity verification..."})]})});if(S)return e.jsx(H,{children:e.jsx(U,{children:e.jsxs("p",{className:"text-danger-500",children:["Error: ",S.message]})})});if(W&&(k||T))return e.jsxs(H,{children:[e.jsx(le,{children:e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"Verification Session Issue"})}),e.jsxs(U,{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:T?"Session Expired":"Verification Error"}),e.jsx("p",{className:"text-red-800 dark:text-red-200 text-sm",children:k||"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(me,{className:"flex justify-between",children:[s&&e.jsx(K,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(K,{type:"button",onClick:X,disabled:f,children:f?"Restarting...":"Restart Verification"})]})]});if(W&&d){const R=m;return u!=null&&u.url?e.jsxs(H,{children:[e.jsx(le,{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(K,{type:"button",variant:"outline",size:"sm",onClick:X,disabled:f,children:"Restart"})]})}),e.jsxs(U,{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:u.url,className:"w-full h-full border-0 rounded-lg",allow:"camera; microphone; geolocation",title:"Identity Verification",onLoad:z=>{var V,J,ne;console.log("[Identity] Iframe loaded");try{const h=z.target,je=h.contentDocument||((V=h.contentWindow)==null?void 0:V.document);if(je){const ce=((ne=(J=je.body)==null?void 0:J.textContent)==null?void 0:ne.toLowerCase())||"";(ce.includes("expired")||ce.includes("invalid")||ce.includes("error"))&&(console.warn("[Identity] Iframe shows expiration message"),F(!0),w("Your verification link has expired."))}}catch{console.log("[Identity] Cannot check iframe content (CORS)")}}})})]}),s&&e.jsx(me,{children:e.jsx(K,{variant:"outline",onClick:s,children:"Back"})})]}):R===fe.SardinAI?e.jsxs(H,{children:[e.jsxs(le,{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(U,{children:e.jsxs("div",{className:"text-center py-12",children:[e.jsx(ve,{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(H,{children:[e.jsxs(le,{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(U,{children:e.jsx("div",{id:"identity-container",className:"min-h-[400px]"})}),s&&e.jsx(me,{children:e.jsx(K,{variant:"outline",onClick:s,children:"Back"})})]})}const we=new Set(["country","nationality","taxCountry","countryOfBirth"]),se=(R=4)=>({1:"col-span-1",2:"col-span-2",3:"col-span-3",4:"col-span-4"})[R]||"col-span-4",P=(R,z)=>{if(!z&&z!==0)return"—";if(we.has(R)){const V=M.find(J=>J.value===z);return V?V.label:String(z)}return String(z)},te=(R,z)=>{const V=Le[R.name],J=R.displayText||(V==null?void 0:V.label)||R.name,ne=O[R.name]??"";return R.editable?we.has(R.name)?e.jsx("div",{className:se(R.colSpan??2),children:e.jsx(Te,{label:J,value:String(ne),onChange:h=>D(je=>({...je,[R.name]:h})),options:[{value:"",label:`Select ${J.toLowerCase()}…`},...M]})},`rf-${z}`):e.jsx("div",{className:se(R.colSpan??2),children:e.jsx(ue,{label:J,type:(V==null?void 0:V.type)==="date"?"date":(V==null?void 0:V.type)==="email"?"email":"text",value:String(ne),onChange:h=>D(je=>({...je,[R.name]:h.target.value}))})},`rf-${z}`):e.jsxs("div",{className:se(R.colSpan??2),children:[e.jsx("label",{className:"block text-sm font-medium mb-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:J}),e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)",minHeight:"1.5rem"},children:P(R.name,ne)})]},`rf-${z}`)};return G?e.jsx("form",{onSubmit:R=>{R.preventDefault(),_()},children:e.jsxs(H,{children:[e.jsxs(le,{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.jsx(U,{children:e.jsx("div",{className:"grid grid-cols-4 gap-4",children:G.map((R,z)=>te(R,z))})}),e.jsxs(me,{className:"flex justify-between",children:[s&&e.jsx(K,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(K,{type:"submit",isLoading:f,children:"Confirm and Start Verification"})]})]})}):e.jsx("form",{onSubmit:v.handleSubmit(_),children:e.jsxs(H,{children:[e.jsxs(le,{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(U,{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:`${((ae=E==null?void 0:E.applicantRequestData)==null?void 0:ae.firstName)||""} ${((Ae=E==null?void 0:E.applicantRequestData)==null?void 0:Ae.lastName)||""}`.trim()},{label:"Email",value:(Re=E==null?void 0:E.applicantRequestData)==null?void 0:Re.email},{label:"Date of Birth",value:((We=E==null?void 0:E.applicantRequestData)==null?void 0:We.dateOfBirth)||"Not provided"}].map(({label:R,value:z})=>e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:R}),e.jsx("p",{className:"mt-1 text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:z})]},R))}),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(Ie.Controller,{control:v.control,name:"country",render:({field:R})=>e.jsx(Te,{label:"Country",value:R.value,onChange:R.onChange,options:[{value:"",label:"Select country…"},...M]})}),e.jsx(Ie.Controller,{control:v.control,name:"nationality",render:({field:R})=>e.jsx(Te,{label:"Nationality",value:R.value,onChange:R.onChange,options:[{value:"",label:"Select nationality…"},...M]})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Ie.Controller,{control:v.control,name:"street",render:({field:R})=>e.jsx(ue,{...R,label:"Street"})}),e.jsx(Ie.Controller,{control:v.control,name:"streetNumber",render:({field:R})=>e.jsx(ue,{...R,label:"Street Number"})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Ie.Controller,{control:v.control,name:"city",render:({field:R})=>e.jsx(ue,{...R,label:"City"})}),e.jsx(Ie.Controller,{control:v.control,name:"zip",render:({field:R})=>e.jsx(ue,{...R,label:"ZIP / Postal Code"})})]}),e.jsx(Ie.Controller,{control:v.control,name:"phonenumber",render:({field:R})=>e.jsx(ue,{...R,label:"Phone Number",type:"tel"})})]})]}),e.jsxs(me,{className:"flex justify-between",children:[s&&e.jsx(K,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(K,{type:"submit",isLoading:f,children:"Confirm and Start Verification"})]})]})})},Je=({kycStatus:t,reviewStatus:r,workflowResult:s,customMessage:a,onContinue:n,onContactSupport:i})=>{const d=t===Pe.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===Pe.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===Pe.Pending||t===Pe.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===Fe.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===Fe.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===Fe.UnderReview||r===Fe.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===Ue.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===Ue.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===Ue.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(H,{children:[e.jsxs(U,{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 text-gray-900 dark:text-white mb-4",children:d.title}),e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx(Ne,{variant:d.type==="success"?"success":d.type==="error"?"danger":d.type==="pending"?"warning":"info",children:t!=null?Pe[t]:Fe[r]})}),e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mb-6 max-w-md mx-auto",children:a||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 border-t border-gray-200 dark:border-gray-700",children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500 dark:text-gray-400",children:"KYC Status:"}),e.jsx("div",{className:"font-medium text-gray-900 dark:text-white mt-1",children:t!=null?Pe[t]:"Not Available"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500 dark:text-gray-400",children:"Review Status:"}),e.jsx("div",{className:"font-medium text-gray-900 dark:text-white mt-1",children:Fe[r]})]})]})})]}),e.jsxs(me,{className:"flex justify-center gap-4",children:[d.type==="success"&&n&&e.jsx(K,{onClick:n,size:"lg",children:"Continue"}),d.type==="error"&&e.jsxs(e.Fragment,{children:[i&&e.jsx(K,{variant:"outline",onClick:i,children:"Contact Support"}),n&&e.jsx(K,{onClick:n,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"})})]})]})},br=({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"}})}),Qe=({title:t,subtitle:r,className:s=""})=>{const{currentTheme:a}=xe(),n=t||(a==null?void 0:a.title)||"",i=!!(a!=null&&a.logo&&a.logo.visible&&a.logo.url),l=!!n;return!i&&!l?null:e.jsxs("div",{className:`metakyc-header ${s}`,children:[e.jsxs("div",{className:"metakyc-header-title flex items-center text-xl font-bold text-gray-900 dark:text-white",children:[i&&e.jsx(br,{config:a.logo}),i&&l&&e.jsx("span",{className:"text-gray-400 dark:text-gray-500 mx-3",style:{fontSize:"1.5rem",fontWeight:300},children:"|"}),l&&e.jsx("span",{children:n})]}),r&&e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mt-1",children:r})]})},Ye=["firstName","lastName","email","phonenumber","dateOfBirth"];function _e(t){return t==null||t===""||Array.isArray(t)&&t.length===0}const He={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,a]=o.useState(!1);if(!t)return e.jsx(e.Fragment,{children:r});const n=s?e.jsx("div",{role:"dialog","aria-modal":"true",onClick:()=>a(!1),style:{position:"fixed",inset:0,zIndex:999999,background:"rgba(0, 0, 0, 0.45)",display:"flex",alignItems:"center",justifyContent:"center",padding:"16px"},children:e.jsxs("div",{onClick:i=>i.stopPropagation(),style:{background:"var(--metakyc-card-bg, #ffffff)",borderRadius:"12px",padding:"28px 24px 24px",maxWidth:"480px",width:"100%",maxHeight:"80vh",overflowY:"auto",boxShadow:"0 24px 64px rgba(0,0,0,0.25)",position:"relative"},children:[e.jsx("button",{type:"button",onClick:()=>a(!1),"aria-label":"Close",style:{position:"absolute",top:"12px",right:"12px",width:"28px",height:"28px",borderRadius:"50%",border:"1px solid var(--metakyc-border, #e5e7eb)",background:"var(--metakyc-input-bg, #f3f4f6)",color:"var(--metakyc-text-secondary, #6b7280)",fontSize:"16px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:"×"}),e.jsx("div",{style:{color:"var(--metakyc-text-primary, #111827)",fontSize:"14px",lineHeight:1.75},dangerouslySetInnerHTML:{__html:t}})]})}):null;return e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"5px",flexWrap:"nowrap"},children:[r,e.jsx("button",{type:"button",onClick:()=>a(!0),"aria-label":"Help",style:{flexShrink:0,marginTop:"2px",width:"18px",height:"18px",borderRadius:"50%",border:"1.5px solid var(--metakyc-primary, #2563eb)",background:"transparent",color:"var(--metakyc-primary, #2563eb)",fontSize:"10px",fontWeight:"700",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,padding:0,transition:"background 0.15s, color 0.15s"},onMouseEnter:i=>{i.currentTarget.style.background="var(--metakyc-primary, #2563eb)",i.currentTarget.style.color="#fff"},onMouseLeave:i=>{i.currentTarget.style.background="transparent",i.currentTarget.style.color="var(--metakyc-primary, #2563eb)"},children:"?"}),typeof document<"u"&&n?Ze.createPortal(n,document.body):null]})},qr=({workflowKey:t,externalRefId:r,onSuccess:s,onCancel:a})=>{var h,je,ce,tt;const{config:n,baseInformationService:i,currentTheme:l}=xe(),{createApplicant:d,isLoading:m}=ar(),u=t||((h=n.applicantForm)==null?void 0:h.workflowKey);if(!u)throw new Error("workflowKey is required. Provide it either as a prop to CreateApplicantForm or set it in config.applicantForm.workflowKey");const f=r||((je=n.applicantForm)==null?void 0:je.externalRefId)||"",S=((ce=n.applicantForm)==null?void 0:ce.email)||"",p=o.useMemo(()=>l!=null&&l.applicantFormPages&&l.applicantFormPages.length>0?l.applicantFormPages:null,[l==null?void 0:l.applicantFormPages]),b=o.useMemo(()=>{const c=new Set(Ye),L=l==null?void 0:l.applicantFormRequiredFields;if(L)for(const B of L)c.add(B);if(p)for(const B of p)for(const y of B.fields)!y.isCustom&&y.name&&y.required&&c.add(y.name);return Array.from(c)},[l==null?void 0:l.applicantFormRequiredFields,p]),g=o.useMemo(()=>{var B;if(p){const y=p.flatMap($=>$.fields).filter($=>!$.isCustom&&$.name).map($=>$.name),x=new Set(y);for(const $ of Ye)x.add($);return Array.from(x)}let c;(B=n.applicantForm)!=null&&B.visibleFields?c=n.applicantForm.visibleFields:l!=null&&l.applicantFormVisibleFields&&l.applicantFormVisibleFields.length>0?c=l.applicantFormVisibleFields:c=ft;const L=new Set(c);for(const y of Ye)L.add(y);return Array.from(L)},[(tt=n.applicantForm)==null?void 0:tt.visibleFields,l==null?void 0:l.applicantFormVisibleFields,p]),I=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),E=o.useMemo(()=>{var L,B;const c=new Set;if(p)for(const y of p)for(const x of y.fields)!x.isCustom&&x.name&&I.has(x.name)&&c.add(x.countriesType??((L=Le[x.name])==null?void 0:L.countriesType));else for(const y of g)I.has(y)&&c.add((B=Le[y])==null?void 0:B.countriesType);return c.size===0&&c.add(void 0),Array.from(c)},[g,p]),[j,M]=o.useState({}),[C,A]=o.useState(!0),q=o.useRef(new Set),W=o.useRef(new Set);o.useEffect(()=>{if(!l)return;const c=E.filter(y=>{const x=y!=null?String(y):"all";return!W.current.has(x)&&!q.current.has(x)});if(c.length===0){E.every(x=>{const $=x!=null?String(x):"all";return W.current.has($)})&&A(!1);return}A(!0);const L=c.map(y=>y!=null?String(y):"all");L.forEach(y=>q.current.add(y)),(async()=>{try{const y=await Promise.all(c.map(async x=>{const $=x!=null?String(x):"all",Z=await i.getCountries("",n.locale||"en",x),re=x===40,ye=new Set,ke=Z.map(he=>re&&he.countryCode?{value:he.countryCode,label:`${he.countryCode} – ${he.name}`}:{value:he.abbreviation3||he.abbreviation,label:he.name}).filter(he=>!he.value||ye.has(he.value)?!1:(ye.add(he.value),!0));return W.current.add($),q.current.delete($),[$,ke]}));M(x=>({...x,...Object.fromEntries(y)}))}catch(y){L.forEach(x=>q.current.delete(x)),console.error("Failed to load countries:",y)}finally{E.every(x=>{const $=x!=null?String(x):"all";return W.current.has($)})&&A(!1)}})()},[E,l]);const N=(c,L)=>{var x;const B=L??((x=Le[c])==null?void 0:x.countriesType),y=B!=null?String(B):"all";return j[y]||[]},[k,w]=o.useState({workflowKey:u,firstName:"",lastName:"",title:"",email:S,dateOfBirth:"",phonenumber:"",externalRefId:f,mobileCountryCode:"",street:"",streetNumber:"",zip:"",city:"",country:"",nationality:"",otherNationality:[],defaultLanguage:"EN",taxCountry:"",placeOfBirth:"",countryOfBirth:"",salutation:null,educationLevel:"",occupation:"",taxNumber:""}),[T,F]=o.useState({}),[Y,O]=o.useState(0),[D,G]=o.useState({}),[v,_]=o.useState(null),[X,we]=o.useState(!1),se=(c,L)=>w(B=>({...B,[c]:L})),P=(c,L)=>F(B=>({...B,[c]:L})),te=c=>!c.conditionalOn||T[c.conditionalOn]==="true",ae=p&&Y<p.length-1?Y+1:-1,Ae=p&&Y>0?Y-1:-1,Re=c=>{var B;const L={};for(const y of c.fields)if(y.isCustom){if(y.customType==="paragraph"||y.customType==="br"||y.customType==="link")continue;if(y.required&&y.paramName){const x=T[y.paramName],$=y.displayText||y.label||y.paramName;y.customType==="checkbox"||y.customType==="link_checkbox"?x!=="true"&&(L[y.paramName]=`${$} is required.`):(!x||x.trim()==="")&&(L[y.paramName]=`${$} is required.`)}}else if(y.name){const x=y.name;if(b.includes(x)&&_e(k[x])){const $=y.displayText||((B=Le[x])==null?void 0:B.label)||x;L[x]=`${$} is required.`}}return L},We=async()=>{if(!p)return;const c=p[Y];if(c.conditionalOn&&!te(c)){G({}),ae>=0?O(ae):await R();return}const L=Re(c);if(Object.keys(L).length>0){G(L);return}G({}),ae>=0?O(ae):await R()},R=async()=>{if(p){let c={};for(const L of p)te(L)&&(c={...c,...Re(L)});if(Object.keys(c).length>0){G(c);return}}we(!0),_(null);try{if(!k.externalRefId||k.externalRefId.trim()===""){_("External Reference ID is required. Please pass it via config.applicantForm.externalRefId.");return}const c={workflowKey:k.workflowKey,externalRefId:k.externalRefId.trim()};if(p){for(const y of p)if(te(y)){for(const x of y.fields)if(!x.isCustom&&x.name){const $=x.name,Z=k[$];_e(Z)||(c[$]=Z)}}for(const y of Ye)if(c[y]===void 0){const x=k[y];_e(x)||(c[y]=x)}}else g.forEach(y=>{if(y==="externalRefId")return;const x=k[y];_e(x)||(c[y]=x)});const L=[];if(p){for(const y of p)if(te(y))for(const x of y.fields){if(!x.isCustom||!x.paramName||x.customType==="paragraph"||x.customType==="br"||x.customType==="link")continue;const $=T[x.paramName]??"";let Z;if(x.customType==="checkbox"||x.customType==="link_checkbox")Z=$==="true"?"yes":"no";else if(Z=$,!Z&&!x.required)continue;L.push({paramName:x.paramName,paramValue:Z})}}L.length>0&&(c.applicantAdditionalDatas=L);const B=await d(c);s(B.applicantId)}catch(c){console.error("Error creating applicant:",c),_(c.message||"Failed to create applicant")}finally{we(!1)}},z=async c=>{var L;c.preventDefault();for(const B of b)if(_e(k[B])){const y=((L=Le[B])==null?void 0:L.label)||B;_(`${y} is required.`);return}await R()},V=(c,L,B,y)=>{var he;const x=Le[c];if(!x)return null;const $=b.includes(c),Z=D[c],re=B||x.label,ye=L??c,ke={required:$};switch(x.type){case"select":if(c==="country"||c==="nationality"||c==="taxCountry"||c==="countryOfBirth"||c==="mobileCountryCode"){const de=N(c,y);return e.jsx(Te,{...ke,label:re,value:k[c]||"",onChange:De=>se(c,De),options:[{value:"",label:`Select ${re.toLowerCase()}...`},...de],disabled:C,error:Z},ye)}if(c==="salutation")return e.jsx(Te,{...ke,label:re,value:((he=k[c])==null?void 0:he.toString())||"",onChange:de=>se(c,de?Number(de):null),options:[{value:"",label:"Select salutation..."},{value:Ke.Male.toString(),label:"Male"},{value:Ke.Female.toString(),label:"Female"},{value:Ke.Other.toString(),label:"Other"}],error:Z},ye);if(c==="defaultLanguage"){const de=l!=null&&l.allowedLanguages&&l.allowedLanguages.length>0?Ve.filter(De=>l.allowedLanguages.includes(De.value)):Ve;return e.jsx(Te,{...ke,label:re,value:k[c]||"",onChange:De=>se(c,De),options:[{value:"",label:"Select language..."},...de],error:Z},ye)}return null;case"multiselect":if(c==="otherNationality"){const de=N(c,y);return e.jsx(nr,{...ke,label:re,value:k[c]||[],onChange:De=>se(c,De),options:de,placeholder:"Select other nationalities...",disabled:C},ye)}return null;case"date":return e.jsx(ue,{...ke,type:"date",label:re,value:k[c]||"",onChange:de=>se(c,de.target.value),error:Z},ye);case"email":return e.jsx(ue,{...ke,type:"email",label:re,value:k[c]||"",onChange:de=>se(c,de.target.value),error:Z},ye);case"tel":return e.jsx(ue,{...ke,type:"tel",label:re,value:k[c]||"",onChange:de=>se(c,de.target.value),error:Z},ye);default:return e.jsx(ue,{...ke,type:"text",label:re,value:k[c]||"",onChange:de=>se(c,de.target.value),error:Z},ye)}},J=(c,L)=>{if(c.customType==="paragraph"){const x=c.displayText||c.label||"";return e.jsx("p",{className:"metakyc-paragraph",style:{fontSize:"14px",lineHeight:"1.7",margin:0,color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:x}},`custom-${L}`)}if(c.customType==="br")return e.jsx("div",{style:{height:"12px"}},`custom-${L}`);if(c.customType==="link"){const x=c.displayText||c.label||c.linkText||c.linkUrl||"";return e.jsx("div",{className:"metakyc-link-field",children:e.jsxs("a",{href:c.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:[x,e.jsx("span",{style:{fontSize:"10px",opacity:.7},children:"↗"})]})},`custom-${L}`)}if(!c.paramName)return null;const B=D[c.paramName],y=c.displayText||c.label||c.paramName;if(c.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:T[c.paramName]==="true",onChange:x=>P(c.paramName,x.target.checked?"true":"false"),className:"metakyc-option-input",style:He}),e.jsxs("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:[y,c.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-${L}`);if(c.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:T[c.paramName]==="true",onChange:x=>P(c.paramName,x.target.checked?"true":"false"),className:"metakyc-option-input",style:{...He,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:[y," ",c.linkUrl&&e.jsx("a",{href:c.linkUrl,target:"_blank",rel:"noopener noreferrer",className:"underline",style:{color:"var(--metakyc-primary, #2563eb)"},onClick:x=>x.stopPropagation(),children:c.linkText||c.linkUrl}),c.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-${L}`);if(c.customType==="group_checkbox"){const x=(T[c.paramName]||"").split(",").filter(Boolean);return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[y,c.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:(c.options||[]).map($=>{const Z=c.singleSelect?T[c.paramName]===$.value:x.includes($.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:Z,onChange:re=>{if(c.singleSelect)P(c.paramName,re.target.checked?$.value:"");else{const ye=re.target.checked?[...x,$.value]:x.filter(ke=>ke!==$.value);P(c.paramName,ye.join(","))}},className:"metakyc-option-input",style:He}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:$.label})]},$.value)})}),B&&e.jsx("p",{className:"text-red-500 text-xs",children:B})]},`custom-${L}`)}return c.customType==="radio_group"?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[y,c.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:(c.options||[]).map(x=>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:T[c.paramName]===x.value,onChange:()=>P(c.paramName,x.value),name:`radio-group-${c.paramName}-${L}`,className:"metakyc-option-input",style:He}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:x.label})]},x.value))}),B&&e.jsx("p",{className:"text-red-500 text-xs",children:B})]},`custom-${L}`):e.jsx(ue,{type:"text",label:`${y}${c.required?" *":""}`,value:T[c.paramName]||"",onChange:x=>P(c.paramName,x.target.value),required:c.required,error:B},`custom-${L}`)},ne=(c,L)=>{const B=te(c);return e.jsxs("div",{className:"space-y-4",children:[c.conditionalOn&&e.jsx(it,{helpText:c.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:B,onChange:y=>P(c.conditionalOn,y.target.checked?"true":"false"),className:"metakyc-option-input",style:He}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",fontWeight:500},children:c.conditionalOn})]})}),B&&e.jsx("div",{className:"grid grid-cols-4 gap-4",children:c.fields.map((y,x)=>{const $=y.colSpan===1?"col-span-1":y.colSpan===2?"col-span-2":y.colSpan===3?"col-span-3":"col-span-4",Z=y.isCustom?`custom-${x}-${y.paramName}`:`builtin-${y.name}-${x}`;return e.jsx("div",{className:$,children:e.jsx(it,{helpText:y.helpText,children:y.isCustom?J(y,x):V(y.name,Z,y.displayText,y.countriesType)})},Z)})})]})};if(!l||C)return e.jsx("div",{className:"metakyc-sdk",children:e.jsx(H,{children:e.jsxs(U,{children:[e.jsx(ve,{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(p){const c=p[Y]??p[0],L=Ae===-1,B=ae===-1,y=p.length,x=te(c),$=Object.values(D);return e.jsx("div",{className:"metakyc-sdk",children:e.jsxs(H,{children:[e.jsx(le,{children:e.jsx(Qe,{title:(l==null?void 0:l.title)||"Create Applicant"})}),e.jsxs(U,{children:[(c.title||c.subtitle||c.description)&&e.jsxs("div",{className:"mb-4",children:[c.title&&e.jsx("h3",{className:"font-semibold text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:c.title}),c.subtitle&&e.jsx("p",{className:"text-sm mt-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:c.subtitle}),c.description&&c.description!==c.subtitle&&e.jsx("p",{className:"text-xs mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:c.description})]}),(v||$.length>0)&&e.jsxs("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-lg",children:[v&&e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",v]}),$.map((Z,re)=>e.jsx("p",{className:"text-red-600 text-sm",children:Z},re))]}),y>1&&e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[p.map((Z,re)=>e.jsx("div",{className:`h-1.5 rounded-full transition-all ${re===Y?"flex-1":"w-8"}`,style:re===Y?{backgroundColor:"var(--metakyc-primary, #2563eb)"}:re<Y?{backgroundColor:"var(--metakyc-primary-light, #93c5fd)",opacity:.7}:{backgroundColor:"#e5e7eb"}},re)),e.jsxs("span",{className:"text-xs text-gray-400 flex-shrink-0",children:[Y+1," / ",y]})]}),ne(c)]}),e.jsxs(me,{className:"flex justify-between",children:[e.jsxs("div",{children:[!L&&e.jsx(K,{type:"button",variant:"outline",onClick:()=>{O(Ae),G({})},disabled:X||m,children:"Previous"}),L&&a&&e.jsx(K,{type:"button",variant:"outline",onClick:a,disabled:X||m,children:"Cancel"})]}),e.jsx(K,{type:"button",isLoading:X||m,onClick:B?R:We,children:B?c.conditionalOn&&!x?"Skip & Submit":"Submit":c.conditionalOn&&!x?"Skip":"Next"})]})]})})}return e.jsx("div",{className:"metakyc-sdk",children:e.jsx("form",{onSubmit:z,children:e.jsxs(H,{children:[e.jsx(le,{children:e.jsx(Qe,{title:(l==null?void 0:l.title)||"Create Applicant"})}),e.jsxs(U,{children:[v&&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:"})," ",v]})}),e.jsx("div",{className:"grid grid-cols-4 gap-4",children:g.map(c=>e.jsx("div",{className:"col-span-4",children:V(c)},c))})]}),e.jsxs(me,{className:"flex justify-between",children:[a&&e.jsx(K,{type:"button",variant:"outline",onClick:a,disabled:X||m,children:"Cancel"}),e.jsx(K,{type:"submit",isLoading:X||m,children:"Create Applicant"})]})]})})})},Qr=({applicantId:t,onComplete:r,onError:s,theme:a="light",className:n})=>{const{progress:i,currentStep:l,steps:d,workflowKey:m,nextWorkflowKey:u,hasWorkflowChanged:f,isLoading:S,error:p,moveBack:b,refreshProgress:g}=Zt(t),[I,E]=o.useState(!1);if(o.useEffect(()=>{p&&s&&s(p)},[p,s]),o.useEffect(()=>{i!=null&&i.workflowResult&&r&&r(i.workflowResult)},[i==null?void 0:i.workflowResult,r]),o.useEffect(()=>{a==="dark"?document.documentElement.classList.add("dark"):document.documentElement.classList.remove("dark")},[a]),o.useEffect(()=>{f&&E(!1)},[f]),S||!i)return e.jsx("div",{className:n,children:e.jsx(H,{children:e.jsxs(U,{children:[e.jsx(ve,{className:"my-8"}),e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-4",children:"Loading workflow..."})]})})});if(p)return e.jsx("div",{className:n,children:e.jsx(H,{children:e.jsx(U,{children:e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-danger-500 text-lg mb-4",children:"An error occurred"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:p.message})]})})})});if(f&&!I)return e.jsx("div",{className:`metakyc-sdk ${n||""}`,children:e.jsx(H,{children:e.jsx(U,{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 bg-blue-100 dark:bg-blue-900 mb-4",children:e.jsx("svg",{className:"w-8 h-8 text-blue-600 dark:text-blue-400",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 text-gray-900 dark:text-white mb-2",children:"Workflow Transition"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mb-6",children:"Your application workflow has been updated based on your progress."}),e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-lg p-4 mb-6 max-w-md mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"text-gray-500 dark:text-gray-400 mb-1",children:"Previous Workflow"}),e.jsx("p",{className:"font-medium text-gray-900 dark:text-white",children:m})]}),e.jsx("svg",{className:"w-6 h-6 text-gray-400 mx-4",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:"text-gray-500 dark:text-gray-400 mb-1",children:"New Workflow"}),e.jsx("p",{className:"font-medium text-blue-600 dark:text-blue-400",children:u})]})]}),i.nextWorkflowName&&e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-2 text-xs",children:i.nextWorkflowName})]}),e.jsx("button",{onClick:()=>E(!0),className:"px-6 py-3 bg-blue-600 hover:bg-blue-700 text-white font-medium rounded-lg transition-colors",children:"Continue with New Workflow"})]})})})});if(i.status===be.Finished||i.status===be.OnHold)return e.jsx("div",{className:`metakyc-sdk ${n||""}`,children:e.jsx(Je,{kycStatus:i.kycStatus,reviewStatus:i.reviewStatus,workflowResult:i.workflowResult,customMessage:i.customMessage,onContinue:r&&i.workflowResult?()=>r(i.workflowResult):void 0,onContactSupport:()=>{typeof window<"u"&&(window.location.href="mailto:support@example.com")}})});if(!l)return e.jsx("div",{className:`metakyc-sdk ${n||""}`,children:e.jsx(H,{children:e.jsxs(U,{children:[e.jsx(ve,{className:"my-8"}),e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-4",children:i.status===be.IdentityPending?"Loading identity verification...":"Loading current step..."})]})})});const j=A=>{switch(A){case Q.Overview:return"Overview";case Q.Questionaries:return"Questionnaire";case Q.UploadDocument:return"Documents";case Q.IdentitySdk:return"Identity";case Q.RiskScoring:return"Risk Assessment";case Q.InvestorCategorization:return"Investor Categorization";case Q.AppropriatenessTest:return"Appropriateness Test";case Q.AdditionalData:return"Additional Data";case Q.ManualReview:return"Review";default:return""}},M=()=>{const A=d.filter(k=>k.visibility!==!1),q=A.findIndex(k=>k.order===l.order),W=q>=0?q+1:1,N=A.length;return e.jsxs("div",{className:"mb-6",children:[e.jsxs("div",{className:"flex items-start justify-between mb-4",children:[e.jsx(Qe,{}),e.jsxs(Ne,{variant:i.status===1?"info":"success",children:["Step ",W," of ",N]})]}),e.jsx("div",{className:"flex items-center",children:A.map((k,w)=>{const T=w<q,F=k.order===l.order;return e.jsxs(o.Fragment,{children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:`
|
|
64
|
+
${g[B.id]===Z?"border-primary-500 bg-primary-50 dark:bg-primary-900/20":"border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600"}
|
|
65
|
+
`,children:[e.jsx("input",{type:"radio",name:`question-${B.id}`,value:Z,checked:g[B.id]===Z,onChange:H=>j(B.id,H.target.value),className:"h-4 w-4 text-primary-500 border-gray-300 focus:ring-primary-500",disabled:x}),e.jsx("span",{className:"ml-3 text-gray-700 dark:text-gray-300",children:Z})]},k))})]},B.id)),b&&!z&&e.jsx("div",{className:"p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg",children:e.jsxs("p",{className:"text-red-600 dark:text-red-400 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",b]})}),z&&e.jsx("div",{className:"p-4 bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg",children:e.jsxs("p",{className:"text-yellow-700 dark:text-yellow-400 text-sm",children:[e.jsx("strong",{children:"Time's up!"})," Your answers are being submitted automatically."]})})]}),e.jsxs(ce,{className:"flex justify-between",children:[e.jsx(W,{type:"button",variant:"outline",onClick:s,disabled:x,children:"Cancel"}),e.jsx(W,{type:"submit",isLoading:x,disabled:Object.keys(g).length<n.totalQuestionCount,children:z?"Submitting...":"Submit Test"})]})]})}):e.jsxs(U,{children:[e.jsxs(oe,{children:[e.jsx("h2",{className:"text-lg font-bold text-gray-900 dark:text-white",children:n.displayName}),n.subtitle&&e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-2",children:n.subtitle})]}),e.jsxs(K,{children:[n.description&&e.jsx("div",{className:"mb-6 p-4 bg-gray-50 dark:bg-gray-800 rounded-lg",children:e.jsx("p",{className:"text-gray-700 dark:text-gray-300",children:n.description})}),e.jsxs("div",{className:"space-y-4 mb-6",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg",children:[e.jsx("span",{className:"text-gray-700 dark:text-gray-300 font-medium",children:"Total Questions:"}),e.jsx(we,{variant:"info",children:n.totalQuestionCount})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg",children:[e.jsx("span",{className:"text-gray-700 dark:text-gray-300 font-medium",children:"Time Limit:"}),e.jsx(we,{variant:"info",children:C(n.testDurationSec)})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg",children:[e.jsx("span",{className:"text-gray-700 dark:text-gray-300 font-medium",children:"Correct Answers Required:"}),e.jsx(we,{variant:"info",children:n.testCorrectAnswerPassLimit})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg",children:[e.jsx("span",{className:"text-gray-700 dark:text-gray-300 font-medium",children:"Attempts Remaining:"}),e.jsx(we,{variant:q>1?"success":"warning",children:q})]})]}),b&&e.jsx("div",{className:"mb-4 p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg",children:e.jsxs("p",{className:"text-red-600 dark:text-red-400 text-sm",children:[e.jsx("strong",{children:"Previous Attempt:"})," ",b]})}),q<=0&&e.jsx("div",{className:"p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg",children:e.jsx("p",{className:"text-red-600 dark:text-red-400",children:"You have used all your attempts. Please contact support for assistance."})})]}),e.jsxs(ce,{className:"flex justify-between",children:[s&&e.jsx(W,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(W,{type:"button",onClick:w,disabled:q<=0,children:"Start Test"})]})]})},fr=({applicantId:t,onComplete:r,onBack:s})=>{var Ue,ze,Ke,We;const{applicantService:a,baseInformationService:n,config:i,currentTheme:d}=he(),{identityData:u,provider:x,token:p,isLoading:b,error:N,requestIdentity:g,restartIdentity:v}=rr(t),[f,P]=o.useState(null),[A,S]=o.useState(null),[z,R]=o.useState([]),[E,Q]=o.useState(!0),[Y,C]=o.useState(!1),[w,j]=o.useState(null),[M,L]=o.useState(!1),q=o.useRef(!1),[B,O]=o.useState({}),[Z,k]=o.useState({}),H=d!=null&&d.reviewPageFields&&d.reviewPageFields.length>0?d.reviewPageFields[0]:null,V=Ne.useForm({defaultValues:{street:"",streetNumber:"",city:"",zip:"",country:"",nationality:"",phonenumber:""}});o.useEffect(()=>{(async()=>{try{const[F,$]=await Promise.all([a.getApplicantData(t),n.getCountries("","en")]);S(F);const D=new Set,l=$.map(m=>({value:m.abbreviation3||m.abbreviation,label:m.name})).filter(m=>!m.value||D.has(m.value)?!1:(D.add(m.value),!0));R(l);const c=F.applicantRequestData;if(O({firstName:(c==null?void 0:c.firstName)||"",lastName:(c==null?void 0:c.lastName)||"",email:(c==null?void 0:c.email)||"",dateOfBirth:(c==null?void 0:c.dateOfBirth)||"",title:(c==null?void 0:c.title)||"",salutation:(c==null?void 0:c.salutation)||"",phonenumber:(c==null?void 0:c.phonenumber)||"",mobileCountryCode:(c==null?void 0:c.mobileCountryCode)||"",street:(c==null?void 0:c.street)||"",streetNumber:(c==null?void 0:c.streetNumber)||"",city:(c==null?void 0:c.city)||"",zip:(c==null?void 0:c.zip)||"",country:(c==null?void 0:c.country)||"",nationality:(c==null?void 0:c.nationality)||"",taxCountry:(c==null?void 0:c.taxCountry)||"",countryOfBirth:(c==null?void 0:c.countryOfBirth)||"",placeOfBirth:(c==null?void 0:c.placeOfBirth)||"",educationLevel:(c==null?void 0:c.educationLevel)||"",occupation:(c==null?void 0:c.occupation)||"",taxNumber:(c==null?void 0:c.taxNumber)||"",defaultLanguage:(c==null?void 0:c.defaultLanguage)||""}),V.reset({street:(c==null?void 0:c.street)||"",streetNumber:(c==null?void 0:c.streetNumber)||"",city:(c==null?void 0:c.city)||"",zip:(c==null?void 0:c.zip)||"",country:(c==null?void 0:c.country)||"",nationality:(c==null?void 0:c.nationality)||"",phonenumber:(c==null?void 0:c.phonenumber)||""}),F.kycRecords&&F.kycRecords.length>0&&F.kycRecords[0].providerTokenObject!==null&&!q.current){console.log("[Identity] Found existing identity verification, auto-requesting..."),q.current=!0;try{await g(),C(!0)}catch(m){console.error("[Identity] Auto-request failed:",m)}}}catch(F){console.error("Error loading applicant data:",F)}finally{Q(!1)}})()},[t]),o.useEffect(()=>{u&&!Y&&(console.log("[Identity] Identity data already loaded, showing provider"),C(!0))},[u,Y]),o.useEffect(()=>{if(p){if(p.expiresAt){const h=new Date(p.expiresAt).getTime();if(Date.now()>=h){console.warn("[Identity] Token has expired (expiresAt)"),L(!0),j("Your verification session has expired. Please restart.");return}}if(p.url)try{const F=new URL(p.url).toString().toLowerCase();if(F.includes("expired")||F.includes("invalid")||F.includes("error")){console.warn("[Identity] Token URL indicates expiration"),L(!0),j("Your verification link has expired. Please restart.");return}}catch{console.error("[Identity] Invalid token URL")}if(p.status==="expired"||p.error==="expired"||p.expired===!0){console.warn("[Identity] Token object indicates expiration"),L(!0),j("Your verification session has expired. Please restart.");return}}},[p]),o.useEffect(()=>{if(x!==null&&p&&!f&&Y&&!M){const h=x;if(p.url){console.log("[Identity] Loading provider URL for user verification:",p.url),j(null);try{if(new URL(p.url),h===ge.SardinAI){console.log("[SardinAI] Initializing Risk SDK in background...");try{const F=Te.parseProviderConfig(x,p,i);Te.createProvider(x,F).initialize().then(()=>{console.log("[SardinAI] Risk SDK initialized successfully in background")}).catch(D=>{console.warn("[SardinAI] Risk SDK initialization failed (non-blocking):",D)})}catch(F){console.warn("[SardinAI] Risk SDK setup failed (non-blocking):",F)}}P({type:"url",url:p.url})}catch(F){console.error("[Identity] Invalid URL:",F),j("Invalid verification URL. Please restart."),L(!0)}return}if(h===ge.SardinAI){console.log("[SardinAI] No URL provided - initializing Risk SDK only..."),j(null);try{const F=Te.parseProviderConfig(x,p,i),$=Te.createProvider(x,F);$.initialize().then(()=>{console.log("[SardinAI] Risk SDK initialized successfully"),P($),setTimeout(()=>{r==null||r()},2e3)}).catch(D=>{var c;console.error("[SardinAI] Failed to initialize:",D);const l=((c=D.message)==null?void 0:c.toLowerCase())||"";l.includes("expired")||l.includes("invalid")||l.includes("401")||l.includes("400")?(L(!0),j("Session expired or invalid. Please restart verification.")):j(`Failed to initialize: ${D.message}`)})}catch(F){console.error("[SardinAI] Error creating provider:",F),j(`Configuration error: ${F.message}`)}return}try{j(null);const F=Te.parseProviderConfig(x,p,i),$=Te.createProvider(x,F);h===ge.Sumsub?($.initialize("identity-container").catch(D=>{var l;console.error("[Sumsub] Initialization error:",D),j(`Failed to initialize: ${D.message}`),(l=D.message)!=null&&l.toLowerCase().includes("expired")&&L(!0)}),$.onComplete&&$.onComplete(()=>{r==null||r()})):h===ge.Onfido&&$.initialize("identity-container").catch(D=>{console.error("[Onfido] Initialization error:",D),j(`Failed to initialize: ${D.message}`)}),P($)}catch(F){console.error("[Identity] Provider setup error:",F),j(`Setup error: ${F.message}`)}}return()=>{if(f&&f.destroy)try{f.destroy()}catch(h){console.error("[Identity] Error destroying provider:",h)}}},[x,p,f,Y,r,M]);const ve=async()=>{try{j(null),L(!1),await g(),C(!0)}catch(h){console.error("Error starting identity verification:",h)}},se=async()=>{try{j(null),L(!1),P(null),console.log("[Identity] Restarting verification..."),await v(),C(!0)}catch(h){console.error("Error restarting identity verification:",h),j(h.message||"Failed to restart verification")}};if(E||b)return e.jsx(U,{children:e.jsxs(K,{children:[e.jsx(fe,{className:"my-8"}),e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-4",children:"Loading identity verification..."})]})});if(N)return e.jsx(U,{children:e.jsx(K,{children:e.jsxs("p",{className:"text-danger-500",children:["Error: ",N.message]})})});if(Y&&(w||M))return e.jsxs(U,{children:[e.jsx(oe,{children:e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"Verification Session Issue"})}),e.jsxs(K,{children:[e.jsx("div",{className:"p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg mb-6",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("svg",{className:"h-6 w-6 text-red-600 dark:text-red-400 mr-3 mt-0.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-red-900 dark:text-red-100 mb-1",children:M?"Session Expired":"Verification Error"}),e.jsx("p",{className:"text-red-800 dark:text-red-200 text-sm",children:w||"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(ce,{className:"flex justify-between",children:[s&&e.jsx(W,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(W,{type:"button",onClick:se,disabled:b,children:b?"Restarting...":"Restart Verification"})]})]});if(Y&&u){const h=x;return p!=null&&p.url?e.jsxs(U,{children:[e.jsx(oe,{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(W,{type:"button",variant:"outline",size:"sm",onClick:se,disabled:b,children:"Restart"})]})}),e.jsxs(K,{children:[e.jsx("div",{className:"mb-4 p-3 bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg",children:e.jsxs("p",{className:"text-yellow-800 dark:text-yellow-200 text-sm",children:[e.jsx("strong",{children:"Important:"}),' If you see an "expired" or "invalid link" message below, click the "Restart" button above to generate a new verification session.']})}),e.jsx("div",{className:"w-full",style:{height:"600px"},children:e.jsx("iframe",{src:p.url,className:"w-full h-full border-0 rounded-lg",allow:"camera; microphone; geolocation",title:"Identity Verification",onLoad:F=>{var $,D,l;console.log("[Identity] Iframe loaded");try{const c=F.target,I=c.contentDocument||(($=c.contentWindow)==null?void 0:$.document);if(I){const m=((l=(D=I.body)==null?void 0:D.textContent)==null?void 0:l.toLowerCase())||"";(m.includes("expired")||m.includes("invalid")||m.includes("error"))&&(console.warn("[Identity] Iframe shows expiration message"),L(!0),j("Your verification link has expired."))}}catch{console.log("[Identity] Cannot check iframe content (CORS)")}}})})]}),s&&e.jsx(ce,{children:e.jsx(W,{variant:"outline",onClick:s,children:"Back"})})]}):h===ge.SardinAI?e.jsxs(U,{children:[e.jsxs(oe,{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(K,{children:e.jsxs("div",{className:"text-center py-12",children:[e.jsx(fe,{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(U,{children:[e.jsxs(oe,{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(K,{children:e.jsx("div",{id:"identity-container",className:"min-h-[400px]"})}),s&&e.jsx(ce,{children:e.jsx(W,{variant:"outline",onClick:s,children:"Back"})})]})}const T=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),J=(h=4)=>({1:"col-span-1",2:"col-span-2",3:"col-span-3",4:"col-span-4"})[h]||"col-span-4",ae=(h,F)=>{if(!F&&F!==0)return"—";if(T.has(h)&&h!=="mobileCountryCode"){const $=z.find(D=>D.value===F);return $?$.label:String(F)}return String(F)},Ie=({helpText:h})=>{const[F,$]=o.useState(!1),D=o.useRef(null),[,l]=o.useState({top:0,left:0}),c=()=>{if(D.current){const I=D.current.getBoundingClientRect();l({top:I.bottom+window.scrollY+6,left:I.left+window.scrollX})}$(!0)};return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",ref:D,onClick:c,style:{width:18,height:18,borderRadius:"50%",border:"1.5px solid var(--metakyc-primary, #6366f1)",background:"transparent",color:"var(--metakyc-primary, #6366f1)",fontSize:11,fontWeight:700,cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,lineHeight:1},children:"?"}),F&&Ge.createPortal(e.jsx("div",{style:{position:"fixed",inset:0,zIndex:99999,background:"rgba(0,0,0,0.25)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:()=>$(!1),children:e.jsxs("div",{onClick:I=>I.stopPropagation(),style:{background:"var(--metakyc-surface, #fff)",border:"1px solid var(--metakyc-border, #e5e7eb)",borderRadius:"var(--metakyc-border-radius, 8px)",padding:"16px 20px",maxWidth:400,width:"90%",boxShadow:"0 10px 30px rgba(0,0,0,0.15)"},children:[e.jsx("div",{dangerouslySetInnerHTML:{__html:h},style:{fontSize:13,color:"var(--metakyc-text-primary, #111827)",lineHeight:1.6}}),e.jsx("button",{type:"button",onClick:()=>$(!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)]})},ue=(h,F)=>F?e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:5,flexWrap:"nowrap"},children:[e.jsx("div",{style:{flex:1,minWidth:0},children:h}),e.jsx("div",{style:{paddingTop:24},children:e.jsx(Ie,{helpText:F})})]}):h,Je=(h,F)=>{const $=`cf-${F}`,D=h.paramName??"",l=Z[D];if(h.customType==="br")return e.jsx("div",{className:J(h.colSpan),style:{minHeight:"0.5rem"}},$);if(h.customType==="paragraph")return e.jsx("div",{className:J(h.colSpan),children:e.jsx("div",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:h.label||""}})},$);if(h.customType==="link")return e.jsx("div",{className:J(h.colSpan),children:ue(e.jsx("a",{href:h.linkUrl??"#",target:"_blank",rel:"noopener noreferrer",className:"text-sm underline",style:{color:"var(--metakyc-primary, #6366f1)"},children:h.displayText||h.label||h.linkText||h.linkUrl}),h.helpText)},$);if(h.customType==="checkbox"||h.customType==="link_checkbox"){const c=l==="true"||l===!0;return e.jsx("div",{className:J(h.colSpan),children:ue(e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:!!c,onChange:I=>k(m=>({...m,[D]:String(I.target.checked)})),style:{width:16,height:16,flexShrink:0,marginTop:2,accentColor:"var(--metakyc-primary, #6366f1)"}}),e.jsx("span",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)"},children:h.customType==="link_checkbox"&&h.linkUrl?e.jsxs(e.Fragment,{children:[e.jsx("a",{href:h.linkUrl,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--metakyc-primary, #6366f1)",textDecoration:"underline"},children:h.linkText||h.label}),h.label&&h.linkText?` ${h.label}`:""]}):h.displayText||h.label})]}),h.helpText)},$)}if(h.customType==="group_checkbox"){const c=Array.isArray(l)?l:l?[l]:[],I=m=>{h.singleSelect?k(y=>({...y,[D]:c[0]===m?[]:[m]})):k(y=>({...y,[D]:c.includes(m)?c.filter(_=>_!==m):[...c,m]}))};return e.jsx("div",{className:J(h.colSpan),children:ue(e.jsxs("div",{className:"space-y-1.5",children:[h.label&&e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:h.displayText||h.label}),(h.options||[]).map(m=>e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:c.includes(m.value),onChange:()=>I(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))]}),h.helpText)},$)}return h.customType==="radio_group"?e.jsx("div",{className:J(h.colSpan),children:ue(e.jsxs("div",{className:"space-y-1.5",children:[h.label&&e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:h.displayText||h.label}),(h.options||[]).map(c=>e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"radio",name:`rg-${D}`,value:c.value,checked:l===c.value,onChange:()=>k(I=>({...I,[D]:c.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:c.label})]},c.value))]}),h.helpText)},$):e.jsx("div",{className:J(h.colSpan),children:ue(e.jsx(ie,{label:h.displayText||h.label||D,value:String(l??""),onChange:c=>k(I=>({...I,[D]:c.target.value}))}),h.helpText)},$)},Le=(h,F)=>{if(h.isCustom)return Je(h,F);const $=h.name??"",D=Ae[$],l=h.displayText||(D==null?void 0:D.label)||$,c=B[$]??"",I=!!(D!=null&&D.countriesType)&&$!=="mobileCountryCode";return h.editable?I?e.jsx("div",{className:J(h.colSpan??2),children:ue(e.jsx(Ee,{label:l,value:String(c),onChange:m=>O(y=>({...y,[$]:m})),options:[{value:"",label:`Select ${l.toLowerCase()}…`},...z]}),h.helpText)},`ec-${F}`):e.jsx("div",{className:J(h.colSpan??2),children:ue(e.jsx(ie,{label:l,type:(D==null?void 0:D.type)==="date"?"date":(D==null?void 0:D.type)==="email"?"email":"text",value:String(c),onChange:m=>O(y=>({...y,[$]:m.target.value}))}),h.helpText)},`ei-${F}`):e.jsx("div",{className:J(h.colSpan??2),children:ue(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:l}),e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)",minHeight:"1.5rem"},children:ae($,c)})]}),h.helpText)},`ro-${F}`)};if(H){const h=H.title||"Review Your Information",F=H.subtitle||"Please review and confirm your information before starting identity verification";return e.jsx("form",{onSubmit:$=>{$.preventDefault(),ve()},children:e.jsxs(U,{children:[e.jsxs(oe,{children:[e.jsx("h2",{className:"text-lg font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:h}),e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:F})]}),e.jsx(K,{children:e.jsx("div",{className:"grid grid-cols-4 gap-4",children:H.fields.map(($,D)=>Le($,D))})}),e.jsxs(ce,{className:"flex justify-between",children:[s&&e.jsx(W,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(W,{type:"submit",isLoading:b,children:"Confirm and Start Verification"})]})]})})}return e.jsx("form",{onSubmit:V.handleSubmit(ve),children:e.jsxs(U,{children:[e.jsxs(oe,{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(K,{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:`${((Ue=A==null?void 0:A.applicantRequestData)==null?void 0:Ue.firstName)||""} ${((ze=A==null?void 0:A.applicantRequestData)==null?void 0:ze.lastName)||""}`.trim()},{label:"Email",value:(Ke=A==null?void 0:A.applicantRequestData)==null?void 0:Ke.email},{label:"Date of Birth",value:((We=A==null?void 0:A.applicantRequestData)==null?void 0:We.dateOfBirth)||"Not provided"}].map(({label:h,value:F})=>e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:h}),e.jsx("p",{className:"mt-1 text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:F})]},h))}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Address Information"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Ne.Controller,{control:V.control,name:"country",render:({field:h})=>e.jsx(Ee,{label:"Country",value:h.value,onChange:h.onChange,options:[{value:"",label:"Select country…"},...z]})}),e.jsx(Ne.Controller,{control:V.control,name:"nationality",render:({field:h})=>e.jsx(Ee,{label:"Nationality",value:h.value,onChange:h.onChange,options:[{value:"",label:"Select nationality…"},...z]})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Ne.Controller,{control:V.control,name:"street",render:({field:h})=>e.jsx(ie,{...h,label:"Street"})}),e.jsx(Ne.Controller,{control:V.control,name:"streetNumber",render:({field:h})=>e.jsx(ie,{...h,label:"Street Number"})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Ne.Controller,{control:V.control,name:"city",render:({field:h})=>e.jsx(ie,{...h,label:"City"})}),e.jsx(Ne.Controller,{control:V.control,name:"zip",render:({field:h})=>e.jsx(ie,{...h,label:"ZIP / Postal Code"})})]}),e.jsx(Ne.Controller,{control:V.control,name:"phonenumber",render:({field:h})=>e.jsx(ie,{...h,label:"Phone Number",type:"tel"})})]})]}),e.jsxs(ce,{className:"flex justify-between",children:[s&&e.jsx(W,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(W,{type:"submit",isLoading:b,children:"Confirm and Start Verification"})]})]})})},Xe=({kycStatus:t,reviewStatus:r,workflowResult:s,customMessage:a,onContinue:n,onContactSupport:i})=>{const u=t===Ce.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===Ce.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===Ce.Pending||t===Ce.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===Re.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===Re.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===Re.UnderReview||r===Re.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===_e.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===_e.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===_e.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(U,{children:[e.jsxs(K,{className:"py-12",children:[e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx("div",{className:`w-24 h-24 rounded-full flex items-center justify-center ${u.iconBg}`,children:e.jsx("span",{className:`text-5xl ${u.iconColor}`,children:u.icon})})}),e.jsx("h2",{className:"text-3xl font-bold text-center text-gray-900 dark:text-white mb-4",children:u.title}),e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx(we,{variant:u.type==="success"?"success":u.type==="error"?"danger":u.type==="pending"?"warning":"info",children:t!=null?Ce[t]:Re[r]})}),e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mb-6 max-w-md mx-auto",children:a||u.message}),u.type==="success"&&e.jsxs("div",{className:"bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg p-4 mb-6",children:[e.jsx("h3",{className:"font-semibold text-green-900 dark:text-green-100 mb-2",children:"What's Next?"}),e.jsxs("ul",{className:"text-sm text-green-800 dark:text-green-200 space-y-1",children:[e.jsx("li",{children:"✓ Your identity has been verified"}),e.jsx("li",{children:"✓ You can now proceed with your application"}),e.jsx("li",{children:"✓ All features are now accessible"})]})]}),u.type==="error"&&e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 mb-6",children:[e.jsx("h3",{className:"font-semibold text-red-900 dark:text-red-100 mb-2",children:"What Can You Do?"}),e.jsxs("ul",{className:"text-sm text-red-800 dark:text-red-200 space-y-2",children:[e.jsx("li",{children:"• Review the requirements and ensure all information is correct"}),e.jsx("li",{children:"• Contact our support team for assistance"}),e.jsx("li",{children:"• You may be able to resubmit your application"})]})]}),u.type==="pending"&&e.jsxs("div",{className:"bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-4 mb-6",children:[e.jsx("h3",{className:"font-semibold text-blue-900 dark:text-blue-100 mb-2",children:"What Happens Next?"}),e.jsxs("ul",{className:"text-sm text-blue-800 dark:text-blue-200 space-y-2",children:[e.jsx("li",{children:"• Our team is reviewing your information"}),e.jsx("li",{children:"• You will be notified via email once the review is complete"}),e.jsx("li",{children:"• This typically takes 24-48 hours"}),e.jsx("li",{children:"• No action is required from you at this time"})]})]}),e.jsx("div",{className:"mt-6 pt-6 border-t border-gray-200 dark:border-gray-700",children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500 dark:text-gray-400",children:"KYC Status:"}),e.jsx("div",{className:"font-medium text-gray-900 dark:text-white mt-1",children:t!=null?Ce[t]:"Not Available"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500 dark:text-gray-400",children:"Review Status:"}),e.jsx("div",{className:"font-medium text-gray-900 dark:text-white mt-1",children:Re[r]})]})]})})]}),e.jsxs(ce,{className:"flex justify-center gap-4",children:[u.type==="success"&&n&&e.jsx(W,{onClick:n,size:"lg",children:"Continue"}),u.type==="error"&&e.jsxs(e.Fragment,{children:[i&&e.jsx(W,{variant:"outline",onClick:i,children:"Contact Support"}),n&&e.jsx(W,{onClick:n,children:"Try Again"})]}),u.type==="pending"&&e.jsx("div",{className:"text-center",children:e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Please check back later or wait for our email notification"})})]})]})},br=({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"}})}),Qe=({title:t,subtitle:r,className:s=""})=>{const{currentTheme:a}=he(),n=t||(a==null?void 0:a.title)||"",i=!!(a!=null&&a.logo&&a.logo.visible&&a.logo.url),d=!!n;return!i&&!d?null:e.jsxs("div",{className:`metakyc-header ${s}`,children:[e.jsxs("div",{className:"metakyc-header-title flex items-center text-xl font-bold text-gray-900 dark:text-white",children:[i&&e.jsx(br,{config:a.logo}),i&&d&&e.jsx("span",{className:"text-gray-400 dark:text-gray-500 mx-3",style:{fontSize:"1.5rem",fontWeight:300},children:"|"}),d&&e.jsx("span",{children:n})]}),r&&e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mt-1",children:r})]})},Ye=["firstName","lastName","email","phonenumber","dateOfBirth"];function Be(t){return t==null||t===""||Array.isArray(t)&&t.length===0}const $e={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,a]=o.useState(!1);if(!t)return e.jsx(e.Fragment,{children:r});const n=s?e.jsx("div",{role:"dialog","aria-modal":"true",onClick:()=>a(!1),style:{position:"fixed",inset:0,zIndex:999999,background:"rgba(0, 0, 0, 0.45)",display:"flex",alignItems:"center",justifyContent:"center",padding:"16px"},children:e.jsxs("div",{onClick:i=>i.stopPropagation(),style:{background:"var(--metakyc-card-bg, #ffffff)",borderRadius:"12px",padding:"28px 24px 24px",maxWidth:"480px",width:"100%",maxHeight:"80vh",overflowY:"auto",boxShadow:"0 24px 64px rgba(0,0,0,0.25)",position:"relative"},children:[e.jsx("button",{type:"button",onClick:()=>a(!1),"aria-label":"Close",style:{position:"absolute",top:"12px",right:"12px",width:"28px",height:"28px",borderRadius:"50%",border:"1px solid var(--metakyc-border, #e5e7eb)",background:"var(--metakyc-input-bg, #f3f4f6)",color:"var(--metakyc-text-secondary, #6b7280)",fontSize:"16px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:"×"}),e.jsx("div",{style:{color:"var(--metakyc-text-primary, #111827)",fontSize:"14px",lineHeight:1.75},dangerouslySetInnerHTML:{__html:t}})]})}):null;return e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"5px",flexWrap:"nowrap"},children:[r,e.jsx("button",{type:"button",onClick:()=>a(!0),"aria-label":"Help",style:{flexShrink:0,marginTop:"2px",width:"18px",height:"18px",borderRadius:"50%",border:"1.5px solid var(--metakyc-primary, #2563eb)",background:"transparent",color:"var(--metakyc-primary, #2563eb)",fontSize:"10px",fontWeight:"700",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,padding:0,transition:"background 0.15s, color 0.15s"},onMouseEnter:i=>{i.currentTarget.style.background="var(--metakyc-primary, #2563eb)",i.currentTarget.style.color="#fff"},onMouseLeave:i=>{i.currentTarget.style.background="transparent",i.currentTarget.style.color="var(--metakyc-primary, #2563eb)"},children:"?"}),typeof document<"u"&&n?Ge.createPortal(n,document.body):null]})},qr=({workflowKey:t,externalRefId:r,onSuccess:s,onCancel:a})=>{var h,F,$,D;const{config:n,baseInformationService:i,currentTheme:d}=he(),{createApplicant:u,isLoading:x}=ar(),p=t||((h=n.applicantForm)==null?void 0:h.workflowKey);if(!p)throw new Error("workflowKey is required. Provide it either as a prop to CreateApplicantForm or set it in config.applicantForm.workflowKey");const b=r||((F=n.applicantForm)==null?void 0:F.externalRefId)||"",N=(($=n.applicantForm)==null?void 0:$.email)||"",g=o.useMemo(()=>d!=null&&d.applicantFormPages&&d.applicantFormPages.length>0?d.applicantFormPages:null,[d==null?void 0:d.applicantFormPages]),v=o.useMemo(()=>{const l=new Set(Ye),c=d==null?void 0:d.applicantFormRequiredFields;if(c)for(const I of c)l.add(I);if(g)for(const I of g)for(const m of I.fields)!m.isCustom&&m.name&&m.required&&l.add(m.name);return Array.from(l)},[d==null?void 0:d.applicantFormRequiredFields,g]),f=o.useMemo(()=>{var I;if(g){const m=g.flatMap(_=>_.fields).filter(_=>!_.isCustom&&_.name).map(_=>_.name),y=new Set(m);for(const _ of Ye)y.add(_);return Array.from(y)}let l;(I=n.applicantForm)!=null&&I.visibleFields?l=n.applicantForm.visibleFields:d!=null&&d.applicantFormVisibleFields&&d.applicantFormVisibleFields.length>0?l=d.applicantFormVisibleFields:l=ft;const c=new Set(l);for(const m of Ye)c.add(m);return Array.from(c)},[(D=n.applicantForm)==null?void 0:D.visibleFields,d==null?void 0:d.applicantFormVisibleFields,g]),P=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),A=o.useMemo(()=>{var c,I;const l=new Set;if(g)for(const m of g)for(const y of m.fields)!y.isCustom&&y.name&&P.has(y.name)&&l.add(y.countriesType??((c=Ae[y.name])==null?void 0:c.countriesType));else for(const m of f)P.has(m)&&l.add((I=Ae[m])==null?void 0:I.countriesType);return l.size===0&&l.add(void 0),Array.from(l)},[f,g]),[S,z]=o.useState({}),[R,E]=o.useState(!0),Q=o.useRef(new Set),Y=o.useRef(new Set);o.useEffect(()=>{if(!d)return;const l=A.filter(m=>{const y=m!=null?String(m):"all";return!Y.current.has(y)&&!Q.current.has(y)});if(l.length===0){A.every(y=>{const _=y!=null?String(y):"all";return Y.current.has(_)})&&E(!1);return}E(!0);const c=l.map(m=>m!=null?String(m):"all");c.forEach(m=>Q.current.add(m)),(async()=>{try{const m=await Promise.all(l.map(async y=>{const _=y!=null?String(y):"all",X=await i.getCountries("",n.locale||"en",y),te=y===40,xe=new Set,be=X.map(me=>te&&me.countryCode?{value:me.countryCode,label:`${me.countryCode} – ${me.name}`}:{value:me.abbreviation3||me.abbreviation,label:me.name}).filter(me=>!me.value||xe.has(me.value)?!1:(xe.add(me.value),!0));return Y.current.add(_),Q.current.delete(_),[_,be]}));z(y=>({...y,...Object.fromEntries(m)}))}catch(m){c.forEach(y=>Q.current.delete(y)),console.error("Failed to load countries:",m)}finally{A.every(y=>{const _=y!=null?String(y):"all";return Y.current.has(_)})&&E(!1)}})()},[A,d]);const C=(l,c)=>{var y;const I=c??((y=Ae[l])==null?void 0:y.countriesType),m=I!=null?String(I):"all";return S[m]||[]},[w,j]=o.useState({workflowKey:p,firstName:"",lastName:"",title:"",email:N,dateOfBirth:"",phonenumber:"",externalRefId:b,mobileCountryCode:"",street:"",streetNumber:"",zip:"",city:"",country:"",nationality:"",otherNationality:[],defaultLanguage:"EN",taxCountry:"",placeOfBirth:"",countryOfBirth:"",salutation:null,educationLevel:"",occupation:"",taxNumber:""}),[M,L]=o.useState({}),[q,B]=o.useState(0),[O,Z]=o.useState({}),[k,H]=o.useState(null),[V,ve]=o.useState(!1),se=(l,c)=>j(I=>({...I,[l]:c})),T=(l,c)=>L(I=>({...I,[l]:c})),J=l=>!l.conditionalOn||M[l.conditionalOn]==="true",ae=g&&q<g.length-1?q+1:-1,Ie=g&&q>0?q-1:-1,ue=l=>{var I;const c={};for(const m of l.fields)if(m.isCustom){if(m.customType==="paragraph"||m.customType==="br"||m.customType==="link")continue;if(m.required&&m.paramName){const y=M[m.paramName],_=m.displayText||m.label||m.paramName;m.customType==="checkbox"||m.customType==="link_checkbox"?y!=="true"&&(c[m.paramName]=`${_} is required.`):(!y||y.trim()==="")&&(c[m.paramName]=`${_} is required.`)}}else if(m.name){const y=m.name;if(v.includes(y)&&Be(w[y])){const _=m.displayText||((I=Ae[y])==null?void 0:I.label)||y;c[y]=`${_} is required.`}}return c},Je=async()=>{if(!g)return;const l=g[q];if(l.conditionalOn&&!J(l)){Z({}),ae>=0?B(ae):await Le();return}const c=ue(l);if(Object.keys(c).length>0){Z(c);return}Z({}),ae>=0?B(ae):await Le()},Le=async()=>{if(g){let l={};for(const c of g)J(c)&&(l={...l,...ue(c)});if(Object.keys(l).length>0){Z(l);return}}ve(!0),H(null);try{if(!w.externalRefId||w.externalRefId.trim()===""){H("External Reference ID is required. Please pass it via config.applicantForm.externalRefId.");return}const l={workflowKey:w.workflowKey,externalRefId:w.externalRefId.trim()};if(g){for(const m of g)if(J(m)){for(const y of m.fields)if(!y.isCustom&&y.name){const _=y.name,X=w[_];Be(X)||(l[_]=X)}}for(const m of Ye)if(l[m]===void 0){const y=w[m];Be(y)||(l[m]=y)}}else f.forEach(m=>{if(m==="externalRefId")return;const y=w[m];Be(y)||(l[m]=y)});const c=[];if(g){for(const m of g)if(J(m))for(const y of m.fields){if(!y.isCustom||!y.paramName||y.customType==="paragraph"||y.customType==="br"||y.customType==="link")continue;const _=M[y.paramName]??"";let X;if(y.customType==="checkbox"||y.customType==="link_checkbox")X=_==="true"?"yes":"no";else if(X=_,!X&&!y.required)continue;c.push({paramName:y.paramName,paramValue:X})}}c.length>0&&(l.applicantAdditionalDatas=c);const I=await u(l);s(I.applicantId)}catch(l){console.error("Error creating applicant:",l),H(l.message||"Failed to create applicant")}finally{ve(!1)}},Ue=async l=>{var c;l.preventDefault();for(const I of v)if(Be(w[I])){const m=((c=Ae[I])==null?void 0:c.label)||I;H(`${m} is required.`);return}await Le()},ze=(l,c,I,m)=>{var me;const y=Ae[l];if(!y)return null;const _=v.includes(l),X=O[l],te=I||y.label,xe=c??l,be={required:_};switch(y.type){case"select":if(l==="country"||l==="nationality"||l==="taxCountry"||l==="countryOfBirth"||l==="mobileCountryCode"){const le=C(l,m);return e.jsx(Ee,{...be,label:te,value:w[l]||"",onChange:Pe=>se(l,Pe),options:[{value:"",label:`Select ${te.toLowerCase()}...`},...le],disabled:R,error:X},xe)}if(l==="salutation")return e.jsx(Ee,{...be,label:te,value:((me=w[l])==null?void 0:me.toString())||"",onChange:le=>se(l,le?Number(le):null),options:[{value:"",label:"Select salutation..."},{value:He.Male.toString(),label:"Male"},{value:He.Female.toString(),label:"Female"},{value:He.Other.toString(),label:"Other"}],error:X},xe);if(l==="defaultLanguage"){const le=d!=null&&d.allowedLanguages&&d.allowedLanguages.length>0?Ze.filter(Pe=>d.allowedLanguages.includes(Pe.value)):Ze;return e.jsx(Ee,{...be,label:te,value:w[l]||"",onChange:Pe=>se(l,Pe),options:[{value:"",label:"Select language..."},...le],error:X},xe)}return null;case"multiselect":if(l==="otherNationality"){const le=C(l,m);return e.jsx(nr,{...be,label:te,value:w[l]||[],onChange:Pe=>se(l,Pe),options:le,placeholder:"Select other nationalities...",disabled:R},xe)}return null;case"date":return e.jsx(ie,{...be,type:"date",label:te,value:w[l]||"",onChange:le=>se(l,le.target.value),error:X},xe);case"email":return e.jsx(ie,{...be,type:"email",label:te,value:w[l]||"",onChange:le=>se(l,le.target.value),error:X},xe);case"tel":return e.jsx(ie,{...be,type:"tel",label:te,value:w[l]||"",onChange:le=>se(l,le.target.value),error:X},xe);default:return e.jsx(ie,{...be,type:"text",label:te,value:w[l]||"",onChange:le=>se(l,le.target.value),error:X},xe)}},Ke=(l,c)=>{if(l.customType==="paragraph"){const y=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:y}},`custom-${c}`)}if(l.customType==="br")return e.jsx("div",{style:{height:"12px"}},`custom-${c}`);if(l.customType==="link"){const y=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:[y,e.jsx("span",{style:{fontSize:"10px",opacity:.7},children:"↗"})]})},`custom-${c}`)}if(!l.paramName)return null;const I=O[l.paramName],m=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:M[l.paramName]==="true",onChange:y=>T(l.paramName,y.target.checked?"true":"false"),className:"metakyc-option-input",style:$e}),e.jsxs("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:[m,l.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),I&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:I})]},`custom-${c}`);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:M[l.paramName]==="true",onChange:y=>T(l.paramName,y.target.checked?"true":"false"),className:"metakyc-option-input",style:{...$e,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:[m," ",l.linkUrl&&e.jsx("a",{href:l.linkUrl,target:"_blank",rel:"noopener noreferrer",className:"underline",style:{color:"var(--metakyc-primary, #2563eb)"},onClick:y=>y.stopPropagation(),children:l.linkText||l.linkUrl}),l.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),I&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:I})]},`custom-${c}`);if(l.customType==="group_checkbox"){const y=(M[l.paramName]||"").split(",").filter(Boolean);return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[m,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(_=>{const X=l.singleSelect?M[l.paramName]===_.value:y.includes(_.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:X,onChange:te=>{if(l.singleSelect)T(l.paramName,te.target.checked?_.value:"");else{const xe=te.target.checked?[...y,_.value]:y.filter(be=>be!==_.value);T(l.paramName,xe.join(","))}},className:"metakyc-option-input",style:$e}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:_.label})]},_.value)})}),I&&e.jsx("p",{className:"text-red-500 text-xs",children:I})]},`custom-${c}`)}return l.customType==="radio_group"?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[m,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(y=>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:M[l.paramName]===y.value,onChange:()=>T(l.paramName,y.value),name:`radio-group-${l.paramName}-${c}`,className:"metakyc-option-input",style:$e}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:y.label})]},y.value))}),I&&e.jsx("p",{className:"text-red-500 text-xs",children:I})]},`custom-${c}`):e.jsx(ie,{type:"text",label:`${m}${l.required?" *":""}`,value:M[l.paramName]||"",onChange:y=>T(l.paramName,y.target.value),required:l.required,error:I},`custom-${c}`)},We=(l,c)=>{const I=J(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:I,onChange:m=>T(l.conditionalOn,m.target.checked?"true":"false"),className:"metakyc-option-input",style:$e}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",fontWeight:500},children:l.conditionalOn})]})}),I&&e.jsx("div",{className:"grid grid-cols-4 gap-4",children:l.fields.map((m,y)=>{const _=m.colSpan===1?"col-span-1":m.colSpan===2?"col-span-2":m.colSpan===3?"col-span-3":"col-span-4",X=m.isCustom?`custom-${y}-${m.paramName}`:`builtin-${m.name}-${y}`;return e.jsx("div",{className:_,children:e.jsx(it,{helpText:m.helpText,children:m.isCustom?Ke(m,y):ze(m.name,X,m.displayText,m.countriesType)})},X)})})]})};if(!d||R)return e.jsx("div",{className:"metakyc-sdk",children:e.jsx(U,{children:e.jsxs(K,{children:[e.jsx(fe,{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(g){const l=g[q]??g[0],c=Ie===-1,I=ae===-1,m=g.length,y=J(l),_=Object.values(O);return e.jsx("div",{className:"metakyc-sdk",children:e.jsxs(U,{children:[e.jsx(oe,{children:e.jsx(Qe,{title:(d==null?void 0:d.title)||"Create Applicant"})}),e.jsxs(K,{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})]}),(k||_.length>0)&&e.jsxs("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-lg",children:[k&&e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",k]}),_.map((X,te)=>e.jsx("p",{className:"text-red-600 text-sm",children:X},te))]}),m>1&&e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[g.map((X,te)=>e.jsx("div",{className:`h-1.5 rounded-full transition-all ${te===q?"flex-1":"w-8"}`,style:te===q?{backgroundColor:"var(--metakyc-primary, #2563eb)"}:te<q?{backgroundColor:"var(--metakyc-primary-light, #93c5fd)",opacity:.7}:{backgroundColor:"#e5e7eb"}},te)),e.jsxs("span",{className:"text-xs text-gray-400 flex-shrink-0",children:[q+1," / ",m]})]}),We(l)]}),e.jsxs(ce,{className:"flex justify-between",children:[e.jsxs("div",{children:[!c&&e.jsx(W,{type:"button",variant:"outline",onClick:()=>{B(Ie),Z({})},disabled:V||x,children:"Previous"}),c&&a&&e.jsx(W,{type:"button",variant:"outline",onClick:a,disabled:V||x,children:"Cancel"})]}),e.jsx(W,{type:"button",isLoading:V||x,onClick:I?Le:Je,children:I?l.conditionalOn&&!y?"Skip & Submit":"Submit":l.conditionalOn&&!y?"Skip":"Next"})]})]})})}return e.jsx("div",{className:"metakyc-sdk",children:e.jsx("form",{onSubmit:Ue,children:e.jsxs(U,{children:[e.jsx(oe,{children:e.jsx(Qe,{title:(d==null?void 0:d.title)||"Create Applicant"})}),e.jsxs(K,{children:[k&&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:"})," ",k]})}),e.jsx("div",{className:"grid grid-cols-4 gap-4",children:f.map(l=>e.jsx("div",{className:"col-span-4",children:ze(l)},l))})]}),e.jsxs(ce,{className:"flex justify-between",children:[a&&e.jsx(W,{type:"button",variant:"outline",onClick:a,disabled:V||x,children:"Cancel"}),e.jsx(W,{type:"submit",isLoading:V||x,children:"Create Applicant"})]})]})})})},Qr=({applicantId:t,onComplete:r,onError:s,theme:a="light",className:n})=>{const{progress:i,currentStep:d,steps:u,workflowKey:x,nextWorkflowKey:p,hasWorkflowChanged:b,isLoading:N,error:g,moveBack:v,refreshProgress:f}=Zt(t),[P,A]=o.useState(!1);if(o.useEffect(()=>{g&&s&&s(g)},[g,s]),o.useEffect(()=>{i!=null&&i.workflowResult&&r&&r(i.workflowResult)},[i==null?void 0:i.workflowResult,r]),o.useEffect(()=>{a==="dark"?document.documentElement.classList.add("dark"):document.documentElement.classList.remove("dark")},[a]),o.useEffect(()=>{b&&A(!1)},[b]),N||!i)return e.jsx("div",{className:n,children:e.jsx(U,{children:e.jsxs(K,{children:[e.jsx(fe,{className:"my-8"}),e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-4",children:"Loading workflow..."})]})})});if(g)return e.jsx("div",{className:n,children:e.jsx(U,{children:e.jsx(K,{children:e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-danger-500 text-lg mb-4",children:"An error occurred"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:g.message})]})})})});if(b&&!P)return e.jsx("div",{className:`metakyc-sdk ${n||""}`,children:e.jsx(U,{children:e.jsx(K,{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 bg-blue-100 dark:bg-blue-900 mb-4",children:e.jsx("svg",{className:"w-8 h-8 text-blue-600 dark:text-blue-400",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 text-gray-900 dark:text-white mb-2",children:"Workflow Transition"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mb-6",children:"Your application workflow has been updated based on your progress."}),e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-lg p-4 mb-6 max-w-md mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"text-gray-500 dark:text-gray-400 mb-1",children:"Previous Workflow"}),e.jsx("p",{className:"font-medium text-gray-900 dark:text-white",children:x})]}),e.jsx("svg",{className:"w-6 h-6 text-gray-400 mx-4",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:"text-gray-500 dark:text-gray-400 mb-1",children:"New Workflow"}),e.jsx("p",{className:"font-medium text-blue-600 dark:text-blue-400",children:p})]})]}),i.nextWorkflowName&&e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-2 text-xs",children:i.nextWorkflowName})]}),e.jsx("button",{onClick:()=>A(!0),className:"px-6 py-3 bg-blue-600 hover:bg-blue-700 text-white font-medium rounded-lg transition-colors",children:"Continue with New Workflow"})]})})})});if(i.status===ye.Finished||i.status===ye.OnHold)return e.jsx("div",{className:`metakyc-sdk ${n||""}`,children:e.jsx(Xe,{kycStatus:i.kycStatus,reviewStatus:i.reviewStatus,workflowResult:i.workflowResult,customMessage:i.customMessage,onContinue:r&&i.workflowResult?()=>r(i.workflowResult):void 0,onContactSupport:()=>{typeof window<"u"&&(window.location.href="mailto:support@example.com")}})});if(!d)return e.jsx("div",{className:`metakyc-sdk ${n||""}`,children:e.jsx(U,{children:e.jsxs(K,{children:[e.jsx(fe,{className:"my-8"}),e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-4",children:i.status===ye.IdentityPending?"Loading identity verification...":"Loading current step..."})]})})});const S=E=>{switch(E){case G.Overview:return"Overview";case G.Questionaries:return"Questionnaire";case G.UploadDocument:return"Documents";case G.IdentitySdk:return"Identity";case G.RiskScoring:return"Risk Assessment";case G.InvestorCategorization:return"Investor Categorization";case G.AppropriatenessTest:return"Appropriateness Test";case G.AdditionalData:return"Additional Data";case G.ManualReview:return"Review";default:return""}},z=()=>{const E=u.filter(w=>w.visibility!==!1),Q=E.findIndex(w=>w.order===d.order),Y=Q>=0?Q+1:1,C=E.length;return e.jsxs("div",{className:"mb-6",children:[e.jsxs("div",{className:"flex items-start justify-between mb-4",children:[e.jsx(Qe,{}),e.jsxs(we,{variant:i.status===1?"info":"success",children:["Step ",Y," of ",C]})]}),e.jsx("div",{className:"flex items-center",children:E.map((w,j)=>{const M=j<Q,L=w.order===d.order;return e.jsxs(o.Fragment,{children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:`
|
|
66
66
|
w-8 h-8 rounded-full flex items-center justify-center text-sm font-medium
|
|
67
|
-
${
|
|
68
|
-
`,children:
|
|
67
|
+
${M||L?"bg-primary-500 text-white":"bg-gray-200 text-gray-600 dark:bg-gray-700 dark:text-gray-400"}
|
|
68
|
+
`,children:j+1}),e.jsx("span",{className:`ml-2 text-sm ${L?"font-semibold text-gray-900 dark:text-white":"text-gray-600 dark:text-gray-400"}`,children:w.displayName||w.name||S(w.action)||`Step ${j+1}`})]}),j<E.length-1&&e.jsx("div",{className:`flex-1 h-0.5 mx-4 ${M?"bg-primary-500":"bg-gray-200 dark:bg-gray-700"}`})]},w.order)})})]})},R=()=>{const E={applicantId:t,onComplete:async()=>{await f()},onBack:d.order>0?v:void 0};switch(d.action){case G.Questionaries:return e.jsx(mr,{...E});case G.UploadDocument:return e.jsx(pr,{...E});case G.Overview:return e.jsx(hr,{...E});case G.IdentitySdk:return e.jsx(fr,{...E});case G.RiskScoring:return e.jsx(xr,{...E});case G.AdditionalData:case G.InvestorCategorization:return e.jsx(gr,{...E});case G.AppropriatenessTest:return e.jsx(yr,{...E});case G.ManualReview:return e.jsx(Xe,{kycStatus:i.kycStatus,reviewStatus:i.reviewStatus,workflowResult:i.workflowResult,customMessage:i.customMessage});default:return e.jsx(U,{children:e.jsxs(K,{className:"py-12 text-center",children:[e.jsx("div",{className:"mb-4",children:e.jsx(fe,{})}),e.jsxs("p",{className:"text-gray-600 dark:text-gray-400 mb-2",children:["Processing step: ",d.title||d.name]}),e.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:["Action type: ",G[d.action]]})]})})}};return e.jsxs("div",{className:`metakyc-sdk ${n||""}`,children:[z(),R()]})};function Gr(t){return Se.z.object({questionResults:Se.z.any()}).passthrough()}function Vr(t){let r=Se.z.array(Se.z.instanceof(File));if(t.isRequired?r=r.min(1,`${t.displayName} is required`):r=r.optional(),t.multipleFile||(r=r.refine(s=>!s||s.length<=1,{message:"Only one file is allowed"})),t.maxEachFileSizeByte>0&&(r=r.refine(s=>!s||s.every(a=>a.size<=t.maxEachFileSizeByte),{message:`File size must not exceed ${Math.round(t.maxEachFileSizeByte/1024/1024)}MB`})),t.allowedTypes){const s=t.allowedTypes.split(",").map(a=>a.trim());r=r.refine(a=>a?a.every(n=>s.some(i=>i.endsWith("/*")?n.type.startsWith(i.slice(0,-2)):n.type===i)):!0,{message:"Invalid file type"})}return r}function Jr(t){const r={};return t.uploadDocumentFiles.forEach(s=>{const a=`file_${s.id}`;r[a]=Vr(s)}),Se.z.object(r)}function Zr(t){return Se.z.any()}function Xr(t){return Se.z.string().min(1,"This question is required")}function es(t){const r={};return t.appropriatenessQuestions.forEach(s=>{const a=`question_${s.id}`;r[a]=Xr()}),Se.z.object(r)}const ts=Se.z.any();exports.ALLOWED_LANGUAGES=Ze;exports.ApplicantProgressOnHoldReason=ot;exports.ApplicantProgressStatus=ye;exports.ApplicantService=wt;exports.ApplicantStatus=ct;exports.AppropriatenessQuestionType=ht;exports.AppropriatenessTestService=Nt;exports.AppropriatenessTestStep=yr;exports.Badge=we;exports.BaseInformationService=Et;exports.Button=W;exports.Card=U;exports.CardContent=K;exports.CardFooter=ce;exports.CardHeader=oe;exports.CountriesType=Fe;exports.CreateApplicantForm=qr;exports.CriteriaBuiltInType=gt;exports.DEFAULT_VISIBLE_FIELDS=ft;exports.DocumentReviewStatus=pt;exports.EndpointBuilder=vt;exports.ErrorHandler=De;exports.EventEmitter=zt;exports.FIELD_METADATA=Ae;exports.FileType=mt;exports.FileUpload=ir;exports.GenderType=He;exports.Header=Qe;exports.HttpClient=kt;exports.IdentityProviderManager=Te;exports.IdentityService=At;exports.IdentityVerificationProvider=ge;exports.IdentityVerificationStep=fr;exports.Input=ie;exports.InvestorCategorizationService=It;exports.InvestorCategorizationStep=gr;exports.InvestorCategorizationType=pe;exports.InvestorCategoryType=yt;exports.KycProcessStatus=dt;exports.KycStatus=Ce;exports.KycStatusDisplay=Xe;exports.KycWorkflow=Qr;exports.Logo=br;exports.MetaKYCContext=tt;exports.MetaKYCError=ke;exports.MetaKYCProvider=Cr;exports.MultiSelect=nr;exports.OnfidoProvider=Ut;exports.OverviewService=Ct;exports.OverviewStep=hr;exports.PhoneInput=or;exports.QuestionnaireService=jt;exports.QuestionnaireStep=mr;exports.ReviewStatus=Re;exports.RiskCriteriaType=xt;exports.RiskLevel=lt;exports.RiskScoringService=Rt;exports.RiskScoringStep=xr;exports.SardinAIProvider=Kt;exports.SearchableSelect=Ee;exports.Select=Ve;exports.Spinner=fe;exports.StepRouter=$t;exports.SumsubProvider=Ht;exports.ThemeManager=Wt;exports.ThemePreset=ne;exports.ThemeService=Ot;exports.UploadDocumentService=St;exports.UploadDocumentStep=pr;exports.UserType=ut;exports.ValueDataType=je;exports.WorkflowOrchestrator=_t;exports.WorkflowResultType=_e;exports.WorkflowState=Bt;exports.WorkflowStepAction=G;exports.appropriatenessTestSchema=ts;exports.clearAllStorage=Pr;exports.clearApplicantId=Gt;exports.clearWorkflowState=Jt;exports.cn=re;exports.corporateTheme=Pt;exports.defaultConfig=bt;exports.defaultTheme=de;exports.fileToBase64=Yt;exports.fintechTheme=Ft;exports.formatFileSize=qe;exports.generateAppropriatenessSchema=es;exports.generateQuestionnaireSchema=Gr;exports.generateRiskScoringSchema=Zr;exports.generateUploadDocumentSchema=Jr;exports.getAcceptString=Er;exports.getApplicantId=Qt;exports.getThemePreset=Me;exports.getWorkflowState=Ir;exports.healthcareTheme=Tt;exports.isScriptLoaded=Sr;exports.loadScript=et;exports.minimalTheme=Dt;exports.modernTheme=Lt;exports.removeScript=Nr;exports.saveApplicantId=qt;exports.saveWorkflowState=Vt;exports.themePresets=Mt;exports.useApplicant=ar;exports.useAppropriatenessTest=Fr;exports.useIdentityVerification=rr;exports.useKycWorkflow=Zt;exports.useMetaKYC=he;exports.useOverview=tr;exports.useQuestionnaire=Xt;exports.useRiskScoring=sr;exports.useUploadDocument=er;exports.validateFileSize=Rr;exports.validateFileType=Ar;
|
|
69
69
|
//# sourceMappingURL=index.cjs.map
|