@vpdev2/metakyc-sdk 1.0.72 → 1.0.73

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -62,7 +62,7 @@
62
62
  Failed to reload test data. Please refresh the page.`)}};if(c)return e.jsx(_,{children:e.jsxs(H,{children:[e.jsx(ge,{className:"my-8"}),e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-4",children:"Loading appropriateness test..."})]})});if(!i)return e.jsx(_,{children:e.jsxs(H,{className:"py-12 text-center",children:[e.jsx("p",{className:"text-danger-500 text-lg mb-4",children:"No test data available"}),v&&e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:v})]})});if(I>0)return e.jsxs(_,{children:[e.jsxs(ie,{children:[e.jsx("h2",{className:"text-lg font-bold text-gray-900 dark:text-white",children:i.displayName}),i.subtitle&&e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-2",children:i.subtitle})]}),e.jsxs(H,{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:A(I)}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Please wait before attempting the test again"})]}),v&&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:v})})]})]});const K=i.testAllowedMaxTry-i.totalFailedTries;return E?e.jsx("form",{onSubmit:z,children:e.jsxs(_,{children:[e.jsx(ie,{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:i.displayName}),i.subtitle&&e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:i.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:A(f)}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Time Remaining"})]})]})}),e.jsxs(H,{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs(be,{variant:"info",children:["Question ",Object.keys(y).length," of ",i.totalQuestionCount]}),e.jsxs(be,{variant:K>1?"success":"warning",children:[K," attempt",K!==1?"s":""," remaining"]})]}),i.appropriatenessQuestions.map((D,M)=>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 ",M+1]}),D.groupName&&e.jsx("span",{className:"ml-2 text-xs text-gray-500 dark:text-gray-400",children:D.groupName}),e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white mt-2",children:D.question})]}),e.jsx("div",{className:"space-y-2",children:D.answers.map((G,S)=>e.jsxs("label",{className:`
63
63
  flex items-center p-3 border-2 rounded-lg cursor-pointer transition-all
64
64
  ${y[D.id]===G?"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-${D.id}`,value:G,checked:y[D.id]===G,onChange:U=>T(D.id,U.target.value),className:"h-4 w-4 text-primary-500 border-gray-300 focus:ring-primary-500",disabled:h}),e.jsx("span",{className:"ml-3 text-gray-700 dark:text-gray-300",children:G})]},S))})]},D.id)),v&&!O&&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:"})," ",v]})}),O&&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(le,{className:"flex justify-between",children:[e.jsx(W,{type:"button",variant:"outline",onClick:s,disabled:h,children:"Cancel"}),e.jsx(W,{type:"submit",isLoading:h,disabled:Object.keys(y).length<i.totalQuestionCount,children:O?"Submitting...":"Submit Test"})]})]})}):e.jsxs(_,{children:[e.jsxs(ie,{children:[e.jsx("h2",{className:"text-lg font-bold text-gray-900 dark:text-white",children:i.displayName}),i.subtitle&&e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-2",children:i.subtitle})]}),e.jsxs(H,{children:[i.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:i.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(be,{variant:"info",children:i.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(be,{variant:"info",children:A(i.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(be,{variant:"info",children:i.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(be,{variant:K>1?"success":"warning",children:K})]})]}),v&&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:"})," ",v]})}),K<=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(le,{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:K<=0,children:"Start Test"})]})]})},fr=({applicantId:t,onComplete:r,onBack:s})=>{var Me,Oe,ze,$e;const{applicantService:a,baseInformationService:i,config:o,currentTheme:c}=me(),{identityData:u,provider:h,token:p,isLoading:v,error:C,requestIdentity:y,restartIdentity:k}=rr(t),[f,F]=l.useState(null),[E,N]=l.useState(null),[O,R]=l.useState([]),[I,q]=l.useState([]),[J,A]=l.useState(!0),[w,T]=l.useState(!1),[z,P]=l.useState(null),[K,D]=l.useState(!1),M=l.useRef(!1),[G,S]=l.useState({}),[U,Z]=l.useState({}),pe=c!=null&&c.reviewPageFields&&c.reviewPageFields.length>0?c.reviewPageFields[0]:null,se=!!(c!=null&&c.reviewPageDisabled),L=l.useRef(!1);L.current=se;const V=Se.useForm({defaultValues:{street:"",streetNumber:"",city:"",zip:"",country:"",nationality:"",phonenumber:""}});l.useEffect(()=>{if(se){M.current||(M.current=!0,y().then(()=>T(!0)).catch(x=>console.error("[Identity] Auto-request failed:",x)).finally(()=>A(!1)));return}(async()=>{try{const[x,b,d]=await Promise.all([a.getApplicantData(t),i.getCountries("","en"),i.getCountries("","en",40)]);N(x);const m=new Set,j=b.map(Y=>({value:Y.abbreviation3||Y.abbreviation,label:Y.name})).filter(Y=>!Y.value||m.has(Y.value)?!1:(m.add(Y.value),!0));R(j);const $=new Set,B=d.filter(Y=>Y.countryCode).map(Y=>({value:Y.countryCode,label:`${Y.countryCode} – ${Y.name}`})).filter(Y=>$.has(Y.value)?!1:($.add(Y.value),!0));q(B);const g=x.applicantRequestData;if(S({firstName:(g==null?void 0:g.firstName)||"",lastName:(g==null?void 0:g.lastName)||"",email:(g==null?void 0:g.email)||"",dateOfBirth:(g==null?void 0:g.dateOfBirth)||"",title:(g==null?void 0:g.title)||"",salutation:(g==null?void 0:g.salutation)||"",phonenumber:(g==null?void 0:g.phonenumber)||"",mobileCountryCode:(g==null?void 0:g.mobileCountryCode)||"",street:(g==null?void 0:g.street)||"",streetNumber:(g==null?void 0:g.streetNumber)||"",city:(g==null?void 0:g.city)||"",zip:(g==null?void 0:g.zip)||"",country:(g==null?void 0:g.country)||"",nationality:(g==null?void 0:g.nationality)||"",taxCountry:(g==null?void 0:g.taxCountry)||"",countryOfBirth:(g==null?void 0:g.countryOfBirth)||"",placeOfBirth:(g==null?void 0:g.placeOfBirth)||"",educationLevel:(g==null?void 0:g.educationLevel)||"",occupation:(g==null?void 0:g.occupation)||"",taxNumber:(g==null?void 0:g.taxNumber)||"",defaultLanguage:(g==null?void 0:g.defaultLanguage)||""}),V.reset({street:(g==null?void 0:g.street)||"",streetNumber:(g==null?void 0:g.streetNumber)||"",city:(g==null?void 0:g.city)||"",zip:(g==null?void 0:g.zip)||"",country:(g==null?void 0:g.country)||"",nationality:(g==null?void 0:g.nationality)||"",phonenumber:(g==null?void 0:g.phonenumber)||""}),x.kycRecords&&x.kycRecords.length>0&&x.kycRecords[0].providerTokenObject!==null&&!M.current&&L.current){console.log("[Identity] Review page disabled + existing identity — auto-requesting..."),M.current=!0;try{await y(),T(!0)}catch(Y){console.error("[Identity] Auto-request failed:",Y)}}}catch(x){console.error("Error loading applicant data:",x)}finally{A(!1)}})()},[t]),l.useEffect(()=>{u&&!w&&L.current&&(console.log("[Identity] Review page disabled — showing cached provider"),T(!0))},[u,w]),l.useEffect(()=>{if(p){if(p.expiresAt){const n=new Date(p.expiresAt).getTime();if(Date.now()>=n){console.warn("[Identity] Token has expired (expiresAt)"),D(!0),P("Your verification session has expired. Please restart.");return}}if(p.url)try{const x=new URL(p.url).toString().toLowerCase();if(x.includes("expired")||x.includes("invalid")||x.includes("error")){console.warn("[Identity] Token URL indicates expiration"),D(!0),P("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"),D(!0),P("Your verification session has expired. Please restart.");return}}},[p]),l.useEffect(()=>{if(h!==null&&p&&!f&&w&&!K){const n=h;if(p.url){console.log("[Identity] Loading provider URL for user verification:",p.url),P(null);try{if(new URL(p.url),n===he.SardinAI){console.log("[SardinAI] Initializing Risk SDK in background...");try{const x=Pe.parseProviderConfig(h,p,o);Pe.createProvider(h,x).initialize().then(()=>{console.log("[SardinAI] Risk SDK initialized successfully in background")}).catch(d=>{console.warn("[SardinAI] Risk SDK initialization failed (non-blocking):",d)})}catch(x){console.warn("[SardinAI] Risk SDK setup failed (non-blocking):",x)}}F({type:"url",url:p.url})}catch(x){console.error("[Identity] Invalid URL:",x),P("Invalid verification URL. Please restart."),D(!0)}return}if(n===he.SardinAI){console.log("[SardinAI] No URL provided - initializing Risk SDK only..."),P(null);try{const x=Pe.parseProviderConfig(h,p,o),b=Pe.createProvider(h,x);b.initialize().then(()=>{console.log("[SardinAI] Risk SDK initialized successfully"),F(b),setTimeout(()=>{r==null||r()},2e3)}).catch(d=>{var j;console.error("[SardinAI] Failed to initialize:",d);const m=((j=d.message)==null?void 0:j.toLowerCase())||"";m.includes("expired")||m.includes("invalid")||m.includes("401")||m.includes("400")?(D(!0),P("Session expired or invalid. Please restart verification.")):P(`Failed to initialize: ${d.message}`)})}catch(x){console.error("[SardinAI] Error creating provider:",x),P(`Configuration error: ${x.message}`)}return}try{P(null);const x=Pe.parseProviderConfig(h,p,o),b=Pe.createProvider(h,x);n===he.Sumsub?(b.initialize("identity-container").catch(d=>{var m;console.error("[Sumsub] Initialization error:",d),P(`Failed to initialize: ${d.message}`),(m=d.message)!=null&&m.toLowerCase().includes("expired")&&D(!0)}),b.onComplete&&b.onComplete(()=>{r==null||r()})):n===he.Onfido&&b.initialize("identity-container").catch(d=>{console.error("[Onfido] Initialization error:",d),P(`Failed to initialize: ${d.message}`)}),F(b)}catch(x){console.error("[Identity] Provider setup error:",x),P(`Setup error: ${x.message}`)}}return()=>{if(f&&f.destroy)try{f.destroy()}catch(n){console.error("[Identity] Error destroying provider:",n)}}},[h,p,f,w,r,K]);const te=async()=>{try{P(null),D(!1),await y(),T(!0)}catch(n){console.error("Error starting identity verification:",n)}},je=async()=>{try{P(null),D(!1),F(null),console.log("[Identity] Restarting verification..."),await k(),T(!0)}catch(n){console.error("Error restarting identity verification:",n),P(n.message||"Failed to restart verification")}};if(J||v)return e.jsx(_,{children:e.jsxs(H,{children:[e.jsx(ge,{className:"my-8"}),e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-4",children:"Loading identity verification..."})]})});if(C)return e.jsx(_,{children:e.jsx(H,{children:e.jsxs("p",{className:"text-danger-500",children:["Error: ",C.message]})})});if(w&&(z||K))return e.jsxs(_,{children:[e.jsx(ie,{children:e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"Verification Session Issue"})}),e.jsxs(H,{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:K?"Session Expired":"Verification Error"}),e.jsx("p",{className:"text-red-800 dark:text-red-200 text-sm",children:z||"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(le,{className:"flex justify-between",children:[s&&e.jsx(W,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(W,{type:"button",onClick:je,disabled:v,children:v?"Restarting...":"Restart Verification"})]})]});if(w&&u){const n=h;return p!=null&&p.url?e.jsxs(_,{children:[e.jsx(ie,{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:je,disabled:v,children:"Restart"})]})}),e.jsxs(H,{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:x=>{var b,d,m;console.log("[Identity] Iframe loaded");try{const j=x.target,$=j.contentDocument||((b=j.contentWindow)==null?void 0:b.document);if($){const B=((m=(d=$.body)==null?void 0:d.textContent)==null?void 0:m.toLowerCase())||"";(B.includes("expired")||B.includes("invalid")||B.includes("error"))&&(console.warn("[Identity] Iframe shows expiration message"),D(!0),P("Your verification link has expired."))}}catch{console.log("[Identity] Cannot check iframe content (CORS)")}}})})]}),s&&e.jsx(le,{children:e.jsx(W,{variant:"outline",onClick:s,children:"Back"})})]}):n===he.SardinAI?e.jsxs(_,{children:[e.jsxs(ie,{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(H,{children:e.jsxs("div",{className:"text-center py-12",children:[e.jsx(ge,{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(_,{children:[e.jsxs(ie,{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(H,{children:e.jsx("div",{id:"identity-container",className:"min-h-[400px]"})}),s&&e.jsx(le,{children:e.jsx(W,{variant:"outline",onClick:s,children:"Back"})})]})}const Ae=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),de=(n=4)=>({1:"col-span-1",2:"col-span-2",3:"col-span-3",4:"col-span-4"})[n]||"col-span-4",Te=(n,x)=>{if(!x&&x!==0)return"—";if(Ae.has(n)&&n!=="mobileCountryCode"){const b=O.find(d=>d.value===x);return b?b.label:String(x)}return String(x)},Ge=({helpText:n})=>{const[x,b]=l.useState(!1),d=l.useRef(null),[,m]=l.useState({top:0,left:0}),j=()=>{if(d.current){const $=d.current.getBoundingClientRect();m({top:$.bottom+window.scrollY+6,left:$.left+window.scrollX})}b(!0)};return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",ref:d,onClick:j,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:"?"}),x&&qe.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:()=>b(!1),children:e.jsxs("div",{onClick:$=>$.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:n},style:{fontSize:13,color:"var(--metakyc-text-primary, #111827)",lineHeight:1.6}}),e.jsx("button",{type:"button",onClick:()=>b(!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)]})},ye=(n,x)=>x?e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:5,flexWrap:"nowrap"},children:[e.jsx("div",{style:{flex:1,minWidth:0},children:n}),e.jsx("div",{style:{paddingTop:24},children:e.jsx(Ge,{helpText:x})})]}):n,Ve=(n,x)=>{const b=`cf-${x}`,d=n.paramName??"",m=U[d];if(n.customType==="br")return e.jsx("div",{className:de(n.colSpan),style:{minHeight:"0.5rem"}},b);if(n.customType==="paragraph")return e.jsx("div",{className:de(n.colSpan),children:e.jsx("div",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:n.label||""}})},b);if(n.customType==="html")return e.jsx("div",{className:de(n.colSpan),dangerouslySetInnerHTML:{__html:n.label||""}},b);if(n.customType==="link")return e.jsx("div",{className:de(n.colSpan),children:ye(e.jsx("a",{href:n.linkUrl??"#",target:"_blank",rel:"noopener noreferrer",className:"text-sm underline",style:{color:"var(--metakyc-primary, #6366f1)"},children:n.displayText||n.label||n.linkText||n.linkUrl}),n.helpText)},b);if(n.customType==="checkbox"||n.customType==="link_checkbox"){const j=m==="true"||m===!0;return e.jsx("div",{className:de(n.colSpan),children:ye(e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:!!j,onChange:$=>Z(B=>({...B,[d]:String($.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:n.customType==="link_checkbox"&&n.linkUrl?e.jsxs(e.Fragment,{children:[e.jsx("a",{href:n.linkUrl,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--metakyc-primary, #6366f1)",textDecoration:"underline"},children:n.linkText||n.label}),n.label&&n.linkText?` ${n.label}`:""]}):n.displayText||n.label})]}),n.helpText)},b)}if(n.customType==="group_checkbox"){const j=Array.isArray(m)?m:m?[m]:[],$=B=>{n.singleSelect?Z(g=>({...g,[d]:j[0]===B?[]:[B]})):Z(g=>({...g,[d]:j.includes(B)?j.filter(ee=>ee!==B):[...j,B]}))};return e.jsx("div",{className:de(n.colSpan),children:ye(e.jsxs("div",{className:"space-y-1.5",children:[n.label&&e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:n.displayText||n.label}),(n.options||[]).map(B=>e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:j.includes(B.value),onChange:()=>$(B.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:B.label})]},B.value))]}),n.helpText)},b)}return n.customType==="radio_group"?e.jsx("div",{className:de(n.colSpan),children:ye(e.jsxs("div",{className:"space-y-1.5",children:[n.label&&e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:n.displayText||n.label}),(n.options||[]).map(j=>e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"radio",name:`rg-${d}`,value:j.value,checked:m===j.value,onChange:()=>Z($=>({...$,[d]:j.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:j.label})]},j.value))]}),n.helpText)},b):e.jsx("div",{className:de(n.colSpan),children:ye(e.jsx(ne,{label:n.displayText||n.label||d,value:String(m??""),onChange:j=>Z($=>({...$,[d]:j.target.value}))}),n.helpText)},b)},Je=(n,x)=>{if(n.isCustom)return Ve(n,x);const b=n.name??"",d=Re[b],m=n.displayText||(d==null?void 0:d.label)||b,j=G[b]??"",$=b==="mobileCountryCode",B=!!(d!=null&&d.countriesType)&&!$;return n.editable?$?e.jsx("div",{className:de(n.colSpan??2),children:ye(e.jsx(ke,{label:m,value:String(j),onChange:g=>S(ee=>({...ee,[b]:g})),options:[{value:"",label:"Select country code…"},...I]}),n.helpText)},`epc-${x}`):B?e.jsx("div",{className:de(n.colSpan??2),children:ye(e.jsx(ke,{label:m,value:String(j),onChange:g=>S(ee=>({...ee,[b]:g})),options:[{value:"",label:`Select ${m.toLowerCase()}…`},...O]}),n.helpText)},`ec-${x}`):e.jsx("div",{className:de(n.colSpan??2),children:ye(e.jsx(ne,{label:m,type:(d==null?void 0:d.type)==="date"?"date":(d==null?void 0:d.type)==="email"?"email":"text",value:String(j),onChange:g=>S(ee=>({...ee,[b]:g.target.value}))}),n.helpText)},`ei-${x}`):e.jsx("div",{className:de(n.colSpan??2),children:ye(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:m}),e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)",minHeight:"1.5rem"},children:Te(b,j)})]}),n.helpText)},`ro-${x}`)};if(pe){const n=pe.title||"Review Your Information",x=pe.subtitle||"Please review and confirm your information before starting identity verification";return e.jsx("form",{onSubmit:b=>{b.preventDefault(),te()},children:e.jsxs(_,{children:[e.jsxs(ie,{children:[e.jsx("h2",{className:"text-lg font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:n}),e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:x})]}),e.jsx(H,{children:e.jsx("div",{className:"grid grid-cols-4 gap-4",children:pe.fields.map((b,d)=>Je(b,d))})}),e.jsxs(le,{className:"flex justify-between",children:[s&&e.jsx(W,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(W,{type:"submit",isLoading:v,children:"Confirm and Start Verification"})]})]})})}return e.jsx("form",{onSubmit:V.handleSubmit(te),children:e.jsxs(_,{children:[e.jsxs(ie,{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(H,{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:`${((Me=E==null?void 0:E.applicantRequestData)==null?void 0:Me.firstName)||""} ${((Oe=E==null?void 0:E.applicantRequestData)==null?void 0:Oe.lastName)||""}`.trim()},{label:"Email",value:(ze=E==null?void 0:E.applicantRequestData)==null?void 0:ze.email},{label:"Date of Birth",value:(($e=E==null?void 0:E.applicantRequestData)==null?void 0:$e.dateOfBirth)||"Not provided"}].map(({label:n,value:x})=>e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:n}),e.jsx("p",{className:"mt-1 text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:x})]},n))}),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(Se.Controller,{control:V.control,name:"country",render:({field:n})=>e.jsx(ke,{label:"Country",value:n.value,onChange:n.onChange,options:[{value:"",label:"Select country…"},...O]})}),e.jsx(Se.Controller,{control:V.control,name:"nationality",render:({field:n})=>e.jsx(ke,{label:"Nationality",value:n.value,onChange:n.onChange,options:[{value:"",label:"Select nationality…"},...O]})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Se.Controller,{control:V.control,name:"street",render:({field:n})=>e.jsx(ne,{...n,label:"Street"})}),e.jsx(Se.Controller,{control:V.control,name:"streetNumber",render:({field:n})=>e.jsx(ne,{...n,label:"Street Number"})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Se.Controller,{control:V.control,name:"city",render:({field:n})=>e.jsx(ne,{...n,label:"City"})}),e.jsx(Se.Controller,{control:V.control,name:"zip",render:({field:n})=>e.jsx(ne,{...n,label:"ZIP / Postal Code"})})]}),e.jsx(Se.Controller,{control:V.control,name:"phonenumber",render:({field:n})=>e.jsx(ne,{...n,label:"Phone Number",type:"tel"})})]})]}),e.jsxs(le,{className:"flex justify-between",children:[s&&e.jsx(W,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(W,{type:"submit",isLoading:v,children:"Confirm and Start Verification"})]})]})})},Xe=({kycStatus:t,reviewStatus:r,workflowResult:s,customMessage:a,onContinue:i,onContactSupport:o})=>{const u=t===Ne.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===Ne.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===Ne.Pending||t===Ne.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===Ce.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===Ce.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===Ce.UnderReview||r===Ce.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===He.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===He.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===He.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(_,{children:[e.jsxs(H,{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(be,{variant:u.type==="success"?"success":u.type==="error"?"danger":u.type==="pending"?"warning":"info",children:t!=null?Ne[t]:Ce[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?Ne[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:Ce[r]})]})]})})]}),e.jsxs(le,{className:"flex justify-center gap-4",children:[u.type==="success"&&i&&e.jsx(W,{onClick:i,size:"lg",children:"Continue"}),u.type==="error"&&e.jsxs(e.Fragment,{children:[o&&e.jsx(W,{variant:"outline",onClick:o,children:"Contact Support"}),i&&e.jsx(W,{onClick:i,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"}})}),Ye=({title:t,subtitle:r,className:s=""})=>{const{currentTheme:a}=me(),i=t||(a==null?void 0:a.title)||"",o=!!(a!=null&&a.logo&&a.logo.visible&&a.logo.url),c=!!i;return!o&&!c?null:e.jsxs("div",{className:`metakyc-header ${s}`,children:[e.jsxs("div",{className:"metakyc-header-title flex items-center text-xl font-bold text-gray-900 dark:text-white",children:[o&&e.jsx(br,{config:a.logo}),o&&c&&e.jsx("span",{className:"text-gray-400 dark:text-gray-500 mx-3",style:{fontSize:"1.5rem",fontWeight:300},children:"|"}),c&&e.jsx("span",{children:i})]}),r&&e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mt-1",children:r})]})},Ke=["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]=l.useState(!1);if(!t)return e.jsx(e.Fragment,{children:r});const i=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:o=>o.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:o=>{o.currentTarget.style.background="var(--metakyc-primary, #2563eb)",o.currentTarget.style.color="#fff"},onMouseLeave:o=>{o.currentTarget.style.background="transparent",o.currentTarget.style.color="var(--metakyc-primary, #2563eb)"},children:"?"}),typeof document<"u"&&i?qe.createPortal(i,document.body):null]})},qr=({workflowKey:t,externalRefId:r,onSuccess:s,onCancel:a})=>{var Me,Oe,ze,$e;const{config:i,baseInformationService:o,currentTheme:c}=me(),{createApplicant:u,isLoading:h}=ar(),p=t||((Me=i.applicantForm)==null?void 0:Me.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 v=r||((Oe=i.applicantForm)==null?void 0:Oe.externalRefId)||"",C=((ze=i.applicantForm)==null?void 0:ze.email)||"",y=l.useMemo(()=>c!=null&&c.applicantFormPages&&c.applicantFormPages.length>0?c.applicantFormPages:null,[c==null?void 0:c.applicantFormPages]),k=l.useMemo(()=>{const n=new Set(Ke),x=c==null?void 0:c.applicantFormRequiredFields;if(x)for(const b of x)n.add(b);if(y)for(const b of y)for(const d of b.fields)!d.isCustom&&d.name&&d.required&&n.add(d.name);return Array.from(n)},[c==null?void 0:c.applicantFormRequiredFields,y]),f=l.useMemo(()=>{var b;if(y){const d=y.flatMap(j=>j.fields).filter(j=>!j.isCustom&&j.name).map(j=>j.name),m=new Set(d);for(const j of Ke)m.add(j);return Array.from(m)}let n;(b=i.applicantForm)!=null&&b.visibleFields?n=i.applicantForm.visibleFields:c!=null&&c.applicantFormVisibleFields&&c.applicantFormVisibleFields.length>0?n=c.applicantFormVisibleFields:n=ft;const x=new Set(n);for(const d of Ke)x.add(d);return Array.from(x)},[($e=i.applicantForm)==null?void 0:$e.visibleFields,c==null?void 0:c.applicantFormVisibleFields,y]),F=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),E=l.useMemo(()=>{var x,b;const n=new Set;if(y)for(const d of y)for(const m of d.fields)!m.isCustom&&m.name&&F.has(m.name)&&n.add(m.countriesType??((x=Re[m.name])==null?void 0:x.countriesType));else for(const d of f)F.has(d)&&n.add((b=Re[d])==null?void 0:b.countriesType);return n.size===0&&n.add(void 0),Array.from(n)},[f,y]),[N,O]=l.useState({}),[R,I]=l.useState(!0),q=l.useRef(new Set),J=l.useRef(new Set);l.useEffect(()=>{if(!c)return;const n=E.filter(d=>{const m=d!=null?String(d):"all";return!J.current.has(m)&&!q.current.has(m)});if(n.length===0){E.every(m=>{const j=m!=null?String(m):"all";return J.current.has(j)})&&I(!1);return}I(!0);const x=n.map(d=>d!=null?String(d):"all");x.forEach(d=>q.current.add(d)),(async()=>{try{const d=await Promise.all(n.map(async m=>{const j=m!=null?String(m):"all",$=await o.getCountries("",i.locale||"en",m),B=m===40,g=new Set,ee=$.map(Y=>B&&Y.countryCode?{value:Y.countryCode,label:`${Y.countryCode} – ${Y.name}`}:{value:Y.abbreviation3||Y.abbreviation,label:Y.name}).filter(Y=>!Y.value||g.has(Y.value)?!1:(g.add(Y.value),!0));return J.current.add(j),q.current.delete(j),[j,ee]}));O(m=>({...m,...Object.fromEntries(d)}))}catch(d){x.forEach(m=>q.current.delete(m)),console.error("Failed to load countries:",d)}finally{E.every(m=>{const j=m!=null?String(m):"all";return J.current.has(j)})&&I(!1)}})()},[E,c]);const A=(n,x)=>{var m;const b=x??((m=Re[n])==null?void 0:m.countriesType),d=b!=null?String(b):"all";return N[d]||[]},[w,T]=l.useState({workflowKey:p,firstName:"",lastName:"",title:"",email:C,dateOfBirth:"",phonenumber:"",externalRefId:v,mobileCountryCode:"",street:"",streetNumber:"",zip:"",city:"",country:"",nationality:"",otherNationality:[],defaultLanguage:"EN",taxCountry:"",placeOfBirth:"",countryOfBirth:"",salutation:null,educationLevel:"",occupation:"",taxNumber:""}),[z,P]=l.useState({}),[K,D]=l.useState(0),[M,G]=l.useState({}),[S,U]=l.useState(null),[Z,pe]=l.useState(!1),se=(n,x)=>T(b=>({...b,[n]:x})),L=(n,x)=>P(b=>({...b,[n]:x})),V=n=>!n.conditionalOn||z[n.conditionalOn]==="true",te=y&&K<y.length-1?K+1:-1,je=y&&K>0?K-1:-1,Ae=n=>{var b;const x={};for(const d of n.fields)if(d.isCustom){if(d.customType==="paragraph"||d.customType==="html"||d.customType==="br"||d.customType==="link")continue;if(d.required&&d.paramName){const m=z[d.paramName],j=d.displayText||d.label||d.paramName;d.customType==="checkbox"||d.customType==="link_checkbox"?m!=="true"&&(x[d.paramName]=`${j} is required.`):(!m||m.trim()==="")&&(x[d.paramName]=`${j} is required.`)}}else if(d.name){const m=d.name;if(k.includes(m)&&Be(w[m])){const j=d.displayText||((b=Re[m])==null?void 0:b.label)||m;x[m]=`${j} is required.`}}return x},de=async()=>{if(!y)return;const n=y[K];if(n.conditionalOn&&!V(n)){G({}),te>=0?D(te):await Te();return}const x=Ae(n);if(Object.keys(x).length>0){G(x);return}G({}),te>=0?D(te):await Te()},Te=async()=>{if(y){let n={};for(const x of y)V(x)&&(n={...n,...Ae(x)});if(Object.keys(n).length>0){G(n);return}}pe(!0),U(null);try{if(!w.externalRefId||w.externalRefId.trim()===""){U("External Reference ID is required. Please pass it via config.applicantForm.externalRefId.");return}const n={workflowKey:w.workflowKey,externalRefId:w.externalRefId.trim()};if(y){for(const d of y)if(V(d)){for(const m of d.fields)if(!m.isCustom&&m.name){const j=m.name,$=w[j];Be($)||(n[j]=$)}}for(const d of Ke)if(n[d]===void 0){const m=w[d];Be(m)||(n[d]=m)}}else f.forEach(d=>{if(d==="externalRefId")return;const m=w[d];Be(m)||(n[d]=m)});const x=[];if(y){for(const d of y)if(V(d))for(const m of d.fields){if(!m.isCustom||!m.paramName||m.customType==="paragraph"||m.customType==="html"||m.customType==="br"||m.customType==="link")continue;const j=z[m.paramName]??"";let $;if(m.customType==="checkbox"||m.customType==="link_checkbox")$=j==="true"?"yes":"no";else if($=j,!$&&!m.required)continue;x.push({paramName:m.paramName,paramValue:$})}}x.length>0&&(n.applicantAdditionalDatas=x);const b=await u(n);s(b.applicantId)}catch(n){console.error("Error creating applicant:",n),U(n.message||"Failed to create applicant")}finally{pe(!1)}},Ge=async n=>{var x;n.preventDefault();for(const b of k)if(Be(w[b])){const d=((x=Re[b])==null?void 0:x.label)||b;U(`${d} is required.`);return}await Te()},ye=(n,x,b,d)=>{var Y;const m=Re[n];if(!m)return null;const j=k.includes(n),$=M[n],B=b||m.label,g=x??n,ee={required:j};switch(m.type){case"select":if(n==="country"||n==="nationality"||n==="taxCountry"||n==="countryOfBirth"||n==="mobileCountryCode"){const oe=A(n,d);return e.jsx(ke,{...ee,label:B,value:w[n]||"",onChange:Ee=>se(n,Ee),options:[{value:"",label:`Select ${B.toLowerCase()}...`},...oe],disabled:R,error:$},g)}if(n==="salutation")return e.jsx(ke,{...ee,label:B,value:((Y=w[n])==null?void 0:Y.toString())||"",onChange:oe=>se(n,oe?Number(oe):null),options:[{value:"",label:"Select salutation..."},{value:Ue.Male.toString(),label:"Male"},{value:Ue.Female.toString(),label:"Female"},{value:Ue.Other.toString(),label:"Other"}],error:$},g);if(n==="defaultLanguage"){const oe=c!=null&&c.allowedLanguages&&c.allowedLanguages.length>0?Ze.filter(Ee=>c.allowedLanguages.includes(Ee.value)):Ze;return e.jsx(ke,{...ee,label:B,value:w[n]||"",onChange:Ee=>se(n,Ee),options:[{value:"",label:"Select language..."},...oe],error:$},g)}return null;case"multiselect":if(n==="otherNationality"){const oe=A(n,d);return e.jsx(nr,{...ee,label:B,value:w[n]||[],onChange:Ee=>se(n,Ee),options:oe,placeholder:"Select other nationalities...",disabled:R},g)}return null;case"date":return e.jsx(ne,{...ee,type:"date",label:B,value:w[n]||"",onChange:oe=>se(n,oe.target.value),error:$},g);case"email":return e.jsx(ne,{...ee,type:"email",label:B,value:w[n]||"",onChange:oe=>se(n,oe.target.value),error:$},g);case"tel":return e.jsx(ne,{...ee,type:"tel",label:B,value:w[n]||"",onChange:oe=>se(n,oe.target.value),error:$},g);default:return e.jsx(ne,{...ee,type:"text",label:B,value:w[n]||"",onChange:oe=>se(n,oe.target.value),error:$},g)}},Ve=(n,x)=>{if(n.customType==="paragraph"){const m=n.displayText||n.label||"";return e.jsx("p",{className:"metakyc-paragraph",style:{fontSize:"14px",lineHeight:"1.7",margin:0,color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:m}},`custom-${x}`)}if(n.customType==="html")return e.jsx("div",{dangerouslySetInnerHTML:{__html:n.label||""}},`custom-${x}`);if(n.customType==="br")return e.jsx("div",{style:{height:"12px"}},`custom-${x}`);if(n.customType==="link"){const m=n.displayText||n.label||n.linkText||n.linkUrl||"";return e.jsx("div",{className:"metakyc-link-field",children:e.jsxs("a",{href:n.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:[m,e.jsx("span",{style:{fontSize:"10px",opacity:.7},children:"↗"})]})},`custom-${x}`)}if(!n.paramName)return null;const b=M[n.paramName],d=n.displayText||n.label||n.paramName;if(n.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:z[n.paramName]==="true",onChange:m=>L(n.paramName,m.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:[d,n.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-${x}`);if(n.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:z[n.paramName]==="true",onChange:m=>L(n.paramName,m.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:[d," ",n.linkUrl&&e.jsx("a",{href:n.linkUrl,target:"_blank",rel:"noopener noreferrer",className:"underline",style:{color:"var(--metakyc-primary, #2563eb)"},onClick:m=>m.stopPropagation(),children:n.linkText||n.linkUrl}),n.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-${x}`);if(n.customType==="group_checkbox"){const m=(z[n.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:[d,n.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:(n.options||[]).map(j=>{const $=n.singleSelect?z[n.paramName]===j.value:m.includes(j.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:$,onChange:B=>{if(n.singleSelect)L(n.paramName,B.target.checked?j.value:"");else{const g=B.target.checked?[...m,j.value]:m.filter(ee=>ee!==j.value);L(n.paramName,g.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:j.label})]},j.value)})}),b&&e.jsx("p",{className:"text-red-500 text-xs",children:b})]},`custom-${x}`)}return n.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:[d,n.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:(n.options||[]).map(m=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"radio",checked:z[n.paramName]===m.value,onChange:()=>L(n.paramName,m.value),name:`radio-group-${n.paramName}-${x}`,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:m.label})]},m.value))}),b&&e.jsx("p",{className:"text-red-500 text-xs",children:b})]},`custom-${x}`):e.jsx(ne,{type:"text",label:`${d}${n.required?" *":""}`,value:z[n.paramName]||"",onChange:m=>L(n.paramName,m.target.value),required:n.required,error:b},`custom-${x}`)},Je=(n,x)=>{const b=V(n);return e.jsxs("div",{className:"space-y-4",children:[n.conditionalOn&&e.jsx(it,{helpText:n.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:d=>L(n.conditionalOn,d.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:n.conditionalOn})]})}),b&&e.jsx("div",{className:"grid grid-cols-4 gap-4",children:n.fields.map((d,m)=>{const j=d.colSpan===1?"col-span-1":d.colSpan===2?"col-span-2":d.colSpan===3?"col-span-3":"col-span-4",$=d.isCustom?`custom-${m}-${d.paramName}`:`builtin-${d.name}-${m}`;return e.jsx("div",{className:j,children:e.jsx(it,{helpText:d.helpText,children:d.isCustom?Ve(d,m):ye(d.name,$,d.displayText,d.countriesType)})},$)})})]})};if(!c||R)return e.jsx("div",{className:"metakyc-sdk",children:e.jsx(_,{children:e.jsxs(H,{children:[e.jsx(ge,{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(y){const n=y[K]??y[0],x=je===-1,b=te===-1,d=y.length,m=V(n),j=Object.values(M);return e.jsx("div",{className:"metakyc-sdk",children:e.jsxs(_,{children:[e.jsx(ie,{children:e.jsx(Ye,{title:(c==null?void 0:c.title)||"Create Applicant"})}),e.jsxs(H,{children:[(n.title||n.subtitle||n.description)&&e.jsxs("div",{className:"mb-4",children:[n.title&&e.jsx("h3",{className:"font-semibold text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:n.title}),n.subtitle&&e.jsx("p",{className:"text-sm mt-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:n.subtitle}),n.description&&n.description!==n.subtitle&&e.jsx("p",{className:"text-xs mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:n.description})]}),(S||j.length>0)&&e.jsxs("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-lg",children:[S&&e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",S]}),j.map(($,B)=>e.jsx("p",{className:"text-red-600 text-sm",children:$},B))]}),d>1&&e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[y.map(($,B)=>e.jsx("div",{className:`h-1.5 rounded-full transition-all ${B===K?"flex-1":"w-8"}`,style:B===K?{backgroundColor:"var(--metakyc-primary, #2563eb)"}:B<K?{backgroundColor:"var(--metakyc-primary-light, #93c5fd)",opacity:.7}:{backgroundColor:"#e5e7eb"}},B)),e.jsxs("span",{className:"text-xs text-gray-400 flex-shrink-0",children:[K+1," / ",d]})]}),Je(n)]}),e.jsxs(le,{className:"flex justify-between",children:[e.jsxs("div",{children:[!x&&e.jsx(W,{type:"button",variant:"outline",onClick:()=>{D(je),G({})},disabled:Z||h,children:"Previous"}),x&&a&&e.jsx(W,{type:"button",variant:"outline",onClick:a,disabled:Z||h,children:"Cancel"})]}),e.jsx(W,{type:"button",isLoading:Z||h,onClick:b?Te:de,children:b?n.conditionalOn&&!m?"Skip & Submit":"Submit":n.conditionalOn&&!m?"Skip":"Next"})]})]})})}return e.jsx("div",{className:"metakyc-sdk",children:e.jsx("form",{onSubmit:Ge,children:e.jsxs(_,{children:[e.jsx(ie,{children:e.jsx(Ye,{title:(c==null?void 0:c.title)||"Create Applicant"})}),e.jsxs(H,{children:[S&&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:"})," ",S]})}),e.jsx("div",{className:"grid grid-cols-4 gap-4",children:f.map(n=>e.jsx("div",{className:"col-span-4",children:ye(n)},n))})]}),e.jsxs(le,{className:"flex justify-between",children:[a&&e.jsx(W,{type:"button",variant:"outline",onClick:a,disabled:Z||h,children:"Cancel"}),e.jsx(W,{type:"submit",isLoading:Z||h,children:"Create Applicant"})]})]})})})},Qr=({applicantId:t,onComplete:r,onError:s,theme:a="light",className:i})=>{const{progress:o,currentStep:c,steps:u,workflowKey:h,nextWorkflowKey:p,hasWorkflowChanged:v,isLoading:C,error:y,moveBack:k,refreshProgress:f}=Zt(t),[F,E]=l.useState(!1);if(l.useEffect(()=>{y&&s&&s(y)},[y,s]),l.useEffect(()=>{o!=null&&o.workflowResult&&r&&r(o.workflowResult)},[o==null?void 0:o.workflowResult,r]),l.useEffect(()=>{a==="dark"?document.documentElement.classList.add("dark"):document.documentElement.classList.remove("dark")},[a]),l.useEffect(()=>{v&&E(!1)},[v]),C||!o)return e.jsx("div",{className:i,children:e.jsx(_,{children:e.jsxs(H,{children:[e.jsx(ge,{className:"my-8"}),e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-4",children:"Loading workflow..."})]})})});if(y)return e.jsx("div",{className:i,children:e.jsx(_,{children:e.jsx(H,{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:y.message})]})})})});if(v&&!F)return e.jsx("div",{className:`metakyc-sdk ${i||""}`,children:e.jsx(_,{children:e.jsx(H,{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:h})]}),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})]})]}),o.nextWorkflowName&&e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-2 text-xs",children:o.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(o.status===xe.Finished||o.status===xe.OnHold)return e.jsx("div",{className:`metakyc-sdk ${i||""}`,children:e.jsx(Xe,{kycStatus:o.kycStatus,reviewStatus:o.reviewStatus,workflowResult:o.workflowResult,customMessage:o.customMessage,onContinue:r&&o.workflowResult?()=>r(o.workflowResult):void 0,onContactSupport:()=>{typeof window<"u"&&(window.location.href="mailto:support@example.com")}})});if(!c)return e.jsx("div",{className:`metakyc-sdk ${i||""}`,children:e.jsx(_,{children:e.jsxs(H,{children:[e.jsx(ge,{className:"my-8"}),e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-4",children:o.status===xe.IdentityPending?"Loading identity verification...":"Loading current step..."})]})})});const N=I=>{switch(I){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""}},O=()=>{const I=u.filter(w=>w.visibility!==!1),q=I.findIndex(w=>w.order===c.order),J=q>=0?q+1:1,A=I.length;return e.jsxs("div",{className:"mb-6",children:[e.jsxs("div",{className:"flex items-start justify-between mb-4",children:[e.jsx(Ye,{}),e.jsxs(be,{variant:o.status===1?"info":"success",children:["Step ",J," of ",A]})]}),e.jsx("div",{className:"flex items-center",children:I.map((w,T)=>{const z=T<q,P=w.order===c.order;return e.jsxs(l.Fragment,{children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:`
65
+ `,children:[e.jsx("input",{type:"radio",name:`question-${D.id}`,value:G,checked:y[D.id]===G,onChange:U=>T(D.id,U.target.value),className:"h-4 w-4 text-primary-500 border-gray-300 focus:ring-primary-500",disabled:h}),e.jsx("span",{className:"ml-3 text-gray-700 dark:text-gray-300",children:G})]},S))})]},D.id)),v&&!O&&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:"})," ",v]})}),O&&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(le,{className:"flex justify-between",children:[e.jsx(W,{type:"button",variant:"outline",onClick:s,disabled:h,children:"Cancel"}),e.jsx(W,{type:"submit",isLoading:h,disabled:Object.keys(y).length<i.totalQuestionCount,children:O?"Submitting...":"Submit Test"})]})]})}):e.jsxs(_,{children:[e.jsxs(ie,{children:[e.jsx("h2",{className:"text-lg font-bold text-gray-900 dark:text-white",children:i.displayName}),i.subtitle&&e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-2",children:i.subtitle})]}),e.jsxs(H,{children:[i.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:i.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(be,{variant:"info",children:i.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(be,{variant:"info",children:A(i.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(be,{variant:"info",children:i.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(be,{variant:K>1?"success":"warning",children:K})]})]}),v&&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:"})," ",v]})}),K<=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(le,{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:K<=0,children:"Start Test"})]})]})},fr=({applicantId:t,onComplete:r,onBack:s})=>{var Me,Oe,ze,$e;const{applicantService:a,baseInformationService:i,config:o,currentTheme:c}=me(),{identityData:u,provider:h,token:p,isLoading:v,error:C,requestIdentity:y,restartIdentity:k}=rr(t),[f,F]=l.useState(null),[E,N]=l.useState(null),[O,R]=l.useState([]),[I,q]=l.useState([]),[J,A]=l.useState(!0),[w,T]=l.useState(!1),[z,P]=l.useState(null),[K,D]=l.useState(!1),M=l.useRef(!1),[G,S]=l.useState({}),[U,Z]=l.useState({}),pe=c!=null&&c.reviewPageFields&&c.reviewPageFields.length>0?c.reviewPageFields[0]:null,se=!!(c!=null&&c.reviewPageDisabled),L=l.useRef(!1);L.current=se;const V=Se.useForm({defaultValues:{street:"",streetNumber:"",city:"",zip:"",country:"",nationality:"",phonenumber:""}});l.useEffect(()=>{if(se){M.current||(M.current=!0,y().then(()=>T(!0)).catch(x=>console.error("[Identity] Auto-request failed:",x)).finally(()=>A(!1)));return}(async()=>{try{const[x,b,d]=await Promise.all([a.getApplicantData(t),i.getCountries("","en"),i.getCountries("","en",40)]);N(x);const m=new Set,j=b.map(Y=>({value:Y.abbreviation3||Y.abbreviation,label:Y.name})).filter(Y=>!Y.value||m.has(Y.value)?!1:(m.add(Y.value),!0));R(j);const $=new Set,B=d.filter(Y=>Y.countryCode).map(Y=>({value:Y.countryCode,label:`${Y.countryCode} – ${Y.name}`})).filter(Y=>$.has(Y.value)?!1:($.add(Y.value),!0));q(B);const g=x.applicantRequestData;if(S({firstName:(g==null?void 0:g.firstName)||"",lastName:(g==null?void 0:g.lastName)||"",email:(g==null?void 0:g.email)||"",dateOfBirth:(g==null?void 0:g.dateOfBirth)||"",title:(g==null?void 0:g.title)||"",salutation:(g==null?void 0:g.salutation)||"",phonenumber:(g==null?void 0:g.phonenumber)||"",mobileCountryCode:(g==null?void 0:g.mobileCountryCode)||"",street:(g==null?void 0:g.street)||"",streetNumber:(g==null?void 0:g.streetNumber)||"",city:(g==null?void 0:g.city)||"",zip:(g==null?void 0:g.zip)||"",country:(g==null?void 0:g.country)||"",nationality:(g==null?void 0:g.nationality)||"",taxCountry:(g==null?void 0:g.taxCountry)||"",countryOfBirth:(g==null?void 0:g.countryOfBirth)||"",placeOfBirth:(g==null?void 0:g.placeOfBirth)||"",educationLevel:(g==null?void 0:g.educationLevel)||"",occupation:(g==null?void 0:g.occupation)||"",taxNumber:(g==null?void 0:g.taxNumber)||"",defaultLanguage:(g==null?void 0:g.defaultLanguage)||""}),V.reset({street:(g==null?void 0:g.street)||"",streetNumber:(g==null?void 0:g.streetNumber)||"",city:(g==null?void 0:g.city)||"",zip:(g==null?void 0:g.zip)||"",country:(g==null?void 0:g.country)||"",nationality:(g==null?void 0:g.nationality)||"",phonenumber:(g==null?void 0:g.phonenumber)||""}),x.kycRecords&&x.kycRecords.length>0&&x.kycRecords[0].providerTokenObject!==null&&!M.current&&L.current){console.log("[Identity] Review page disabled + existing identity — auto-requesting..."),M.current=!0;try{await y(),T(!0)}catch(Y){console.error("[Identity] Auto-request failed:",Y)}}}catch(x){console.error("Error loading applicant data:",x)}finally{A(!1)}})()},[t]),l.useEffect(()=>{u&&!w&&L.current&&(console.log("[Identity] Review page disabled — showing cached provider"),T(!0))},[u,w]),l.useEffect(()=>{if(p){if(p.expiresAt){const n=new Date(p.expiresAt).getTime();if(Date.now()>=n){console.warn("[Identity] Token has expired (expiresAt)"),D(!0),P("Your verification session has expired. Please restart.");return}}if(p.url)try{const x=new URL(p.url).toString().toLowerCase();if(x.includes("expired")||x.includes("invalid")||x.includes("error")){console.warn("[Identity] Token URL indicates expiration"),D(!0),P("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"),D(!0),P("Your verification session has expired. Please restart.");return}}},[p]),l.useEffect(()=>{if(h!==null&&p&&!f&&w&&!K){const n=h;if(p.url){console.log("[Identity] Loading provider URL for user verification:",p.url),P(null);try{if(new URL(p.url),n===he.SardinAI){console.log("[SardinAI] Initializing Risk SDK in background...");try{const x=Pe.parseProviderConfig(h,p,o);Pe.createProvider(h,x).initialize().then(()=>{console.log("[SardinAI] Risk SDK initialized successfully in background")}).catch(d=>{console.warn("[SardinAI] Risk SDK initialization failed (non-blocking):",d)})}catch(x){console.warn("[SardinAI] Risk SDK setup failed (non-blocking):",x)}}F({type:"url",url:p.url})}catch(x){console.error("[Identity] Invalid URL:",x),P("Invalid verification URL. Please restart."),D(!0)}return}if(n===he.SardinAI){console.log("[SardinAI] No URL provided - initializing Risk SDK only..."),P(null);try{const x=Pe.parseProviderConfig(h,p,o),b=Pe.createProvider(h,x);b.initialize().then(()=>{console.log("[SardinAI] Risk SDK initialized successfully"),F(b),setTimeout(()=>{r==null||r()},2e3)}).catch(d=>{var j;console.error("[SardinAI] Failed to initialize:",d);const m=((j=d.message)==null?void 0:j.toLowerCase())||"";m.includes("expired")||m.includes("invalid")||m.includes("401")||m.includes("400")?(D(!0),P("Session expired or invalid. Please restart verification.")):P(`Failed to initialize: ${d.message}`)})}catch(x){console.error("[SardinAI] Error creating provider:",x),P(`Configuration error: ${x.message}`)}return}try{P(null);const x=Pe.parseProviderConfig(h,p,o),b=Pe.createProvider(h,x);n===he.Sumsub?(b.initialize("identity-container").catch(d=>{var m;console.error("[Sumsub] Initialization error:",d),P(`Failed to initialize: ${d.message}`),(m=d.message)!=null&&m.toLowerCase().includes("expired")&&D(!0)}),b.onComplete&&b.onComplete(()=>{r==null||r()})):n===he.Onfido&&b.initialize("identity-container").catch(d=>{console.error("[Onfido] Initialization error:",d),P(`Failed to initialize: ${d.message}`)}),F(b)}catch(x){console.error("[Identity] Provider setup error:",x),P(`Setup error: ${x.message}`)}}return()=>{if(f&&f.destroy)try{f.destroy()}catch(n){console.error("[Identity] Error destroying provider:",n)}}},[h,p,f,w,r,K]);const te=async()=>{try{P(null),D(!1),await y(),T(!0)}catch(n){console.error("Error starting identity verification:",n)}},je=async()=>{try{P(null),D(!1),F(null),console.log("[Identity] Restarting verification..."),await k(),T(!0)}catch(n){console.error("Error restarting identity verification:",n),P(n.message||"Failed to restart verification")}};if(J||v)return e.jsx(_,{children:e.jsxs(H,{children:[e.jsx(ge,{className:"my-8"}),e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-4",children:"Loading identity verification..."})]})});if(C)return e.jsx(_,{children:e.jsx(H,{children:e.jsxs("p",{className:"text-danger-500",children:["Error: ",C.message]})})});if(w&&(z||K))return e.jsxs(_,{children:[e.jsx(ie,{children:e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"Verification Session Issue"})}),e.jsxs(H,{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:K?"Session Expired":"Verification Error"}),e.jsx("p",{className:"text-red-800 dark:text-red-200 text-sm",children:z||"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(le,{className:"flex justify-between",children:[s&&e.jsx(W,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(W,{type:"button",onClick:je,disabled:v,children:v?"Restarting...":"Restart Verification"})]})]});if(w&&u){const n=h;return p!=null&&p.url?e.jsxs(_,{children:[e.jsx(ie,{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:je,disabled:v,children:"Restart"})]})}),e.jsxs(H,{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:x=>{var b,d,m;console.log("[Identity] Iframe loaded");try{const j=x.target,$=j.contentDocument||((b=j.contentWindow)==null?void 0:b.document);if($){const B=((m=(d=$.body)==null?void 0:d.textContent)==null?void 0:m.toLowerCase())||"";(B.includes("expired")||B.includes("invalid")||B.includes("error"))&&(console.warn("[Identity] Iframe shows expiration message"),D(!0),P("Your verification link has expired."))}}catch{console.log("[Identity] Cannot check iframe content (CORS)")}}})})]}),s&&e.jsx(le,{children:e.jsx(W,{variant:"outline",onClick:s,children:"Back"})})]}):n===he.SardinAI?e.jsxs(_,{children:[e.jsxs(ie,{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(H,{children:e.jsxs("div",{className:"text-center py-12",children:[e.jsx(ge,{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(_,{children:[e.jsxs(ie,{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(H,{children:e.jsx("div",{id:"identity-container",className:"min-h-[400px]"})}),s&&e.jsx(le,{children:e.jsx(W,{variant:"outline",onClick:s,children:"Back"})})]})}const Ae=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),de=(n=4)=>({1:"col-span-1",2:"col-span-2",3:"col-span-3",4:"col-span-4"})[n]||"col-span-4",Te=(n,x)=>{if(!x&&x!==0)return"—";if(Ae.has(n)&&n!=="mobileCountryCode"){const b=O.find(d=>d.value===x);return b?b.label:String(x)}return String(x)},Ge=({helpText:n})=>{const[x,b]=l.useState(!1),d=l.useRef(null),[,m]=l.useState({top:0,left:0}),j=()=>{if(d.current){const $=d.current.getBoundingClientRect();m({top:$.bottom+window.scrollY+6,left:$.left+window.scrollX})}b(!0)};return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",ref:d,onClick:j,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:"?"}),x&&qe.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:()=>b(!1),children:e.jsxs("div",{onClick:$=>$.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:n},style:{fontSize:13,color:"var(--metakyc-text-primary, #111827)",lineHeight:1.6}}),e.jsx("button",{type:"button",onClick:()=>b(!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)]})},ye=(n,x)=>x?e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:5,flexWrap:"nowrap"},children:[e.jsx("div",{style:{flex:1,minWidth:0},children:n}),e.jsx("div",{style:{paddingTop:24},children:e.jsx(Ge,{helpText:x})})]}):n,Ve=(n,x)=>{const b=`cf-${x}`,d=n.paramName??"",m=U[d];if(n.customType==="br")return e.jsx("div",{className:de(n.colSpan),style:{minHeight:"0.5rem"}},b);if(n.customType==="paragraph")return e.jsx("div",{className:de(n.colSpan),children:e.jsx("div",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:n.label||""}})},b);if(n.customType==="html")return e.jsx("div",{className:de(n.colSpan),dangerouslySetInnerHTML:{__html:n.label||""}},b);if(n.customType==="link")return e.jsx("div",{className:de(n.colSpan),children:ye(e.jsx("a",{href:n.linkUrl??"#",target:"_blank",rel:"noopener noreferrer",className:"text-sm underline",style:{color:"var(--metakyc-primary, #6366f1)"},children:n.displayText||n.label||n.linkText||n.linkUrl}),n.helpText)},b);if(n.customType==="checkbox"||n.customType==="link_checkbox"){const j=m==="true"||m===!0;return e.jsx("div",{className:de(n.colSpan),children:ye(e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:!!j,onChange:$=>Z(B=>({...B,[d]:String($.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:n.customType==="link_checkbox"&&n.linkUrl?e.jsxs(e.Fragment,{children:[e.jsx("a",{href:n.linkUrl,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--metakyc-primary, #6366f1)",textDecoration:"underline"},children:n.linkText||n.label}),n.label&&n.linkText?` ${n.label}`:""]}):n.displayText||n.label})]}),n.helpText)},b)}if(n.customType==="group_checkbox"){const j=Array.isArray(m)?m:m?[m]:[],$=B=>{n.singleSelect?Z(g=>({...g,[d]:j[0]===B?[]:[B]})):Z(g=>({...g,[d]:j.includes(B)?j.filter(ee=>ee!==B):[...j,B]}))};return e.jsx("div",{className:de(n.colSpan),children:ye(e.jsxs("div",{className:"space-y-1.5",children:[n.label&&e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:n.displayText||n.label}),(n.options||[]).map(B=>e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:j.includes(B.value),onChange:()=>$(B.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:B.label})]},B.value))]}),n.helpText)},b)}return n.customType==="radio_group"?e.jsx("div",{className:de(n.colSpan),children:ye(e.jsxs("div",{className:"space-y-1.5",children:[n.label&&e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:n.displayText||n.label}),(n.options||[]).map(j=>e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"radio",name:`rg-${d}`,value:j.value,checked:m===j.value,onChange:()=>Z($=>({...$,[d]:j.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:j.label})]},j.value))]}),n.helpText)},b):e.jsx("div",{className:de(n.colSpan),children:ye(e.jsx(ne,{label:n.displayText||n.label||d,value:String(m??""),onChange:j=>Z($=>({...$,[d]:j.target.value}))}),n.helpText)},b)},Je=(n,x)=>{if(n.isCustom)return Ve(n,x);const b=n.name??"",d=Re[b],m=n.displayText||(d==null?void 0:d.label)||b,j=G[b]??"",$=b==="mobileCountryCode",B=!!(d!=null&&d.countriesType)&&!$;return n.editable?$?e.jsx("div",{className:de(n.colSpan??2),children:ye(e.jsx(ke,{label:m,value:String(j),onChange:g=>S(ee=>({...ee,[b]:g})),options:[{value:"",label:"Select country code…"},...I]}),n.helpText)},`epc-${x}`):B?e.jsx("div",{className:de(n.colSpan??2),children:ye(e.jsx(ke,{label:m,value:String(j),onChange:g=>S(ee=>({...ee,[b]:g})),options:[{value:"",label:`Select ${m.toLowerCase()}…`},...O]}),n.helpText)},`ec-${x}`):e.jsx("div",{className:de(n.colSpan??2),children:ye(e.jsx(ne,{label:m,type:(d==null?void 0:d.type)==="date"?"date":(d==null?void 0:d.type)==="email"?"email":"text",value:String(j),onChange:g=>S(ee=>({...ee,[b]:g.target.value}))}),n.helpText)},`ei-${x}`):e.jsx("div",{className:de(n.colSpan??2),children:ye(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:m}),e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)",minHeight:"1.5rem"},children:Te(b,j)})]}),n.helpText)},`ro-${x}`)};if(pe){const n=pe.title||"Review Your Information",x=pe.subtitle||"Please review and confirm your information before starting identity verification";return e.jsx("form",{onSubmit:b=>{b.preventDefault(),te()},children:e.jsxs(_,{children:[e.jsxs(ie,{children:[e.jsx("h2",{className:"text-lg font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:n}),e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:x})]}),e.jsx(H,{children:e.jsx("div",{className:"grid grid-cols-4 gap-4",children:pe.fields.map((b,d)=>Je(b,d))})}),e.jsxs(le,{className:"flex justify-between",children:[s&&e.jsx(W,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(W,{type:"submit",isLoading:v,children:"Confirm and Start Verification"})]})]})})}return e.jsx("form",{onSubmit:V.handleSubmit(te),children:e.jsxs(_,{children:[e.jsxs(ie,{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(H,{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:`${((Me=E==null?void 0:E.applicantRequestData)==null?void 0:Me.firstName)||""} ${((Oe=E==null?void 0:E.applicantRequestData)==null?void 0:Oe.lastName)||""}`.trim()},{label:"Email",value:(ze=E==null?void 0:E.applicantRequestData)==null?void 0:ze.email},{label:"Date of Birth",value:(($e=E==null?void 0:E.applicantRequestData)==null?void 0:$e.dateOfBirth)||"Not provided"}].map(({label:n,value:x})=>e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:n}),e.jsx("p",{className:"mt-1 text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:x})]},n))}),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(Se.Controller,{control:V.control,name:"country",render:({field:n})=>e.jsx(ke,{label:"Country",value:n.value,onChange:n.onChange,options:[{value:"",label:"Select country…"},...O]})}),e.jsx(Se.Controller,{control:V.control,name:"nationality",render:({field:n})=>e.jsx(ke,{label:"Nationality",value:n.value,onChange:n.onChange,options:[{value:"",label:"Select nationality…"},...O]})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Se.Controller,{control:V.control,name:"street",render:({field:n})=>e.jsx(ne,{...n,label:"Street"})}),e.jsx(Se.Controller,{control:V.control,name:"streetNumber",render:({field:n})=>e.jsx(ne,{...n,label:"Street Number"})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Se.Controller,{control:V.control,name:"city",render:({field:n})=>e.jsx(ne,{...n,label:"City"})}),e.jsx(Se.Controller,{control:V.control,name:"zip",render:({field:n})=>e.jsx(ne,{...n,label:"ZIP / Postal Code"})})]}),e.jsx(Se.Controller,{control:V.control,name:"phonenumber",render:({field:n})=>e.jsx(ne,{...n,label:"Phone Number",type:"tel"})})]})]}),e.jsxs(le,{className:"flex justify-between",children:[s&&e.jsx(W,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(W,{type:"submit",isLoading:v,children:"Confirm and Start Verification"})]})]})})},Xe=({kycStatus:t,reviewStatus:r,workflowResult:s,customMessage:a,onContinue:i,onContactSupport:o})=>{const u=t===Ne.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===Ne.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===Ne.Pending||t===Ne.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===Ce.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===Ce.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===Ce.UnderReview||r===Ce.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===He.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===He.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===He.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(_,{children:[e.jsxs(H,{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(be,{variant:u.type==="success"?"success":u.type==="error"?"danger":u.type==="pending"?"warning":"info",children:t!=null?Ne[t]:Ce[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?Ne[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:Ce[r]})]})]})})]}),e.jsxs(le,{className:"flex justify-center gap-4",children:[u.type==="success"&&i&&e.jsx(W,{onClick:i,size:"lg",children:"Continue"}),u.type==="error"&&e.jsxs(e.Fragment,{children:[o&&e.jsx(W,{variant:"outline",onClick:o,children:"Contact Support"}),i&&e.jsx(W,{onClick:i,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"}})}),Ye=({title:t,subtitle:r,className:s=""})=>{const{currentTheme:a}=me(),i=t||(a==null?void 0:a.title)||"",o=!!(a!=null&&a.logo&&a.logo.visible&&a.logo.url),c=!!i;return!o&&!c?null:e.jsxs("div",{className:`metakyc-header ${s}`,children:[e.jsxs("div",{className:"metakyc-header-title flex items-center text-xl font-bold text-gray-900 dark:text-white",children:[o&&e.jsx(br,{config:a.logo}),o&&c&&e.jsx("span",{className:"text-gray-400 dark:text-gray-500 mx-3",style:{fontSize:"1.5rem",fontWeight:300},children:"|"}),c&&e.jsx("span",{children:i})]}),r&&e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mt-1",children:r})]})},Ke=["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]=l.useState(!1);if(!t)return e.jsx(e.Fragment,{children:r});const i=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:o=>o.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:o=>{o.currentTarget.style.background="var(--metakyc-primary, #2563eb)",o.currentTarget.style.color="#fff"},onMouseLeave:o=>{o.currentTarget.style.background="transparent",o.currentTarget.style.color="var(--metakyc-primary, #2563eb)"},children:"?"}),typeof document<"u"&&i?qe.createPortal(i,document.body):null]})},qr=({workflowKey:t,externalRefId:r,onSuccess:s,onCancel:a})=>{var Me,Oe,ze,$e;const{config:i,baseInformationService:o,currentTheme:c}=me(),{createApplicant:u,isLoading:h}=ar(),p=t||((Me=i.applicantForm)==null?void 0:Me.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 v=r||((Oe=i.applicantForm)==null?void 0:Oe.externalRefId)||"",C=((ze=i.applicantForm)==null?void 0:ze.email)||"",y=l.useMemo(()=>c!=null&&c.applicantFormPages&&c.applicantFormPages.length>0?c.applicantFormPages:null,[c==null?void 0:c.applicantFormPages]),k=l.useMemo(()=>{const n=new Set(Ke),x=c==null?void 0:c.applicantFormRequiredFields;if(x)for(const b of x)n.add(b);if(y)for(const b of y)for(const d of b.fields)!d.isCustom&&d.name&&d.required&&n.add(d.name);return Array.from(n)},[c==null?void 0:c.applicantFormRequiredFields,y]),f=l.useMemo(()=>{var b;if(y){const d=y.flatMap(j=>j.fields).filter(j=>!j.isCustom&&j.name).map(j=>j.name),m=new Set(d);for(const j of Ke)m.add(j);return Array.from(m)}let n;(b=i.applicantForm)!=null&&b.visibleFields?n=i.applicantForm.visibleFields:c!=null&&c.applicantFormVisibleFields&&c.applicantFormVisibleFields.length>0?n=c.applicantFormVisibleFields:n=ft;const x=new Set(n);for(const d of Ke)x.add(d);return Array.from(x)},[($e=i.applicantForm)==null?void 0:$e.visibleFields,c==null?void 0:c.applicantFormVisibleFields,y]),F=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),E=l.useMemo(()=>{var x,b;const n=new Set;if(y)for(const d of y)for(const m of d.fields)!m.isCustom&&m.name&&F.has(m.name)&&n.add(m.countriesType??((x=Re[m.name])==null?void 0:x.countriesType));else for(const d of f)F.has(d)&&n.add((b=Re[d])==null?void 0:b.countriesType);return n.size===0&&n.add(void 0),Array.from(n)},[f,y]),[N,O]=l.useState({}),[R,I]=l.useState(!0),q=l.useRef(new Set),J=l.useRef(new Set);l.useEffect(()=>{if(!c)return;const n=E.filter(d=>{const m=d!=null?String(d):"all";return!J.current.has(m)&&!q.current.has(m)});if(n.length===0){E.every(m=>{const j=m!=null?String(m):"all";return J.current.has(j)})&&I(!1);return}I(!0);const x=n.map(d=>d!=null?String(d):"all");x.forEach(d=>q.current.add(d)),(async()=>{try{const d=await Promise.all(n.map(async m=>{const j=m!=null?String(m):"all",$=await o.getCountries("",i.locale||"en",m),B=m===40,g=new Set,ee=$.map(Y=>B&&Y.countryCode?{value:Y.countryCode,label:`${Y.countryCode} – ${Y.name}`}:{value:Y.abbreviation3||Y.abbreviation,label:Y.name}).filter(Y=>!Y.value||g.has(Y.value)?!1:(g.add(Y.value),!0));return J.current.add(j),q.current.delete(j),[j,ee]}));O(m=>({...m,...Object.fromEntries(d)}))}catch(d){x.forEach(m=>q.current.delete(m)),console.error("Failed to load countries:",d)}finally{E.every(m=>{const j=m!=null?String(m):"all";return J.current.has(j)})&&I(!1)}})()},[E,c]);const A=(n,x)=>{var m;const b=x??((m=Re[n])==null?void 0:m.countriesType),d=b!=null?String(b):"all";return N[d]||[]},[w,T]=l.useState({workflowKey:p,firstName:"",lastName:"",title:"",email:C,dateOfBirth:"",phonenumber:"",externalRefId:v,mobileCountryCode:"",street:"",streetNumber:"",zip:"",city:"",country:"",nationality:"",otherNationality:[],defaultLanguage:"EN",taxCountry:"",placeOfBirth:"",countryOfBirth:"",salutation:null,educationLevel:"",occupation:"",taxNumber:""}),[z,P]=l.useState({}),[K,D]=l.useState(0),[M,G]=l.useState({}),[S,U]=l.useState(null),[Z,pe]=l.useState(!1),se=(n,x)=>T(b=>({...b,[n]:x})),L=(n,x)=>P(b=>({...b,[n]:x})),V=n=>!n.conditionalOn||z[n.conditionalOn]==="true",te=y&&K<y.length-1?K+1:-1,je=y&&K>0?K-1:-1,Ae=n=>{var b;const x={};for(const d of n.fields)if(d.isCustom){if(d.customType==="paragraph"||d.customType==="html"||d.customType==="br"||d.customType==="link")continue;if(d.required&&d.paramName){const m=z[d.paramName],j=d.displayText||d.label||d.paramName;d.customType==="checkbox"||d.customType==="link_checkbox"?m!=="true"&&(x[d.paramName]=`${j} is required.`):(!m||m.trim()==="")&&(x[d.paramName]=`${j} is required.`)}}else if(d.name){const m=d.name;if(k.includes(m)&&Be(w[m])){const j=d.displayText||((b=Re[m])==null?void 0:b.label)||m;x[m]=`${j} is required.`}}return x},de=async()=>{if(!y)return;const n=y[K];if(n.conditionalOn&&!V(n)){G({}),te>=0?D(te):await Te();return}const x=Ae(n);if(Object.keys(x).length>0){G(x);return}G({}),te>=0?D(te):await Te()},Te=async()=>{if(y){let n={};for(const x of y)V(x)&&(n={...n,...Ae(x)});if(Object.keys(n).length>0){G(n);return}}pe(!0),U(null);try{if(!w.externalRefId||w.externalRefId.trim()===""){U("External Reference ID is required. Please pass it via config.applicantForm.externalRefId.");return}const n={workflowKey:w.workflowKey,externalRefId:w.externalRefId.trim()};if(y){for(const d of y)if(V(d)){for(const m of d.fields)if(!m.isCustom&&m.name){const j=m.name,$=w[j];Be($)||(n[j]=$)}}for(const d of Ke)if(n[d]===void 0){const m=w[d];Be(m)||(n[d]=m)}}else f.forEach(d=>{if(d==="externalRefId")return;const m=w[d];Be(m)||(n[d]=m)});const x=[];if(y){for(const d of y)if(V(d))for(const m of d.fields){if(!m.isCustom||!m.paramName||m.customType==="paragraph"||m.customType==="html"||m.customType==="br"||m.customType==="link")continue;const j=z[m.paramName]??"";let $;if(m.customType==="checkbox"||m.customType==="link_checkbox")$=j==="true"?"yes":"no";else if($=j,!$&&!m.required)continue;x.push({paramName:m.paramName,value:$})}}x.length>0&&(n.applicantAdditionalDatas=x);const b=await u(n);s(b.applicantId)}catch(n){console.error("Error creating applicant:",n),U(n.message||"Failed to create applicant")}finally{pe(!1)}},Ge=async n=>{var x;n.preventDefault();for(const b of k)if(Be(w[b])){const d=((x=Re[b])==null?void 0:x.label)||b;U(`${d} is required.`);return}await Te()},ye=(n,x,b,d)=>{var Y;const m=Re[n];if(!m)return null;const j=k.includes(n),$=M[n],B=b||m.label,g=x??n,ee={required:j};switch(m.type){case"select":if(n==="country"||n==="nationality"||n==="taxCountry"||n==="countryOfBirth"||n==="mobileCountryCode"){const oe=A(n,d);return e.jsx(ke,{...ee,label:B,value:w[n]||"",onChange:Ee=>se(n,Ee),options:[{value:"",label:`Select ${B.toLowerCase()}...`},...oe],disabled:R,error:$},g)}if(n==="salutation")return e.jsx(ke,{...ee,label:B,value:((Y=w[n])==null?void 0:Y.toString())||"",onChange:oe=>se(n,oe?Number(oe):null),options:[{value:"",label:"Select salutation..."},{value:Ue.Male.toString(),label:"Male"},{value:Ue.Female.toString(),label:"Female"},{value:Ue.Other.toString(),label:"Other"}],error:$},g);if(n==="defaultLanguage"){const oe=c!=null&&c.allowedLanguages&&c.allowedLanguages.length>0?Ze.filter(Ee=>c.allowedLanguages.includes(Ee.value)):Ze;return e.jsx(ke,{...ee,label:B,value:w[n]||"",onChange:Ee=>se(n,Ee),options:[{value:"",label:"Select language..."},...oe],error:$},g)}return null;case"multiselect":if(n==="otherNationality"){const oe=A(n,d);return e.jsx(nr,{...ee,label:B,value:w[n]||[],onChange:Ee=>se(n,Ee),options:oe,placeholder:"Select other nationalities...",disabled:R},g)}return null;case"date":return e.jsx(ne,{...ee,type:"date",label:B,value:w[n]||"",onChange:oe=>se(n,oe.target.value),error:$},g);case"email":return e.jsx(ne,{...ee,type:"email",label:B,value:w[n]||"",onChange:oe=>se(n,oe.target.value),error:$},g);case"tel":return e.jsx(ne,{...ee,type:"tel",label:B,value:w[n]||"",onChange:oe=>se(n,oe.target.value),error:$},g);default:return e.jsx(ne,{...ee,type:"text",label:B,value:w[n]||"",onChange:oe=>se(n,oe.target.value),error:$},g)}},Ve=(n,x)=>{if(n.customType==="paragraph"){const m=n.displayText||n.label||"";return e.jsx("p",{className:"metakyc-paragraph",style:{fontSize:"14px",lineHeight:"1.7",margin:0,color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:m}},`custom-${x}`)}if(n.customType==="html")return e.jsx("div",{dangerouslySetInnerHTML:{__html:n.label||""}},`custom-${x}`);if(n.customType==="br")return e.jsx("div",{style:{height:"12px"}},`custom-${x}`);if(n.customType==="link"){const m=n.displayText||n.label||n.linkText||n.linkUrl||"";return e.jsx("div",{className:"metakyc-link-field",children:e.jsxs("a",{href:n.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:[m,e.jsx("span",{style:{fontSize:"10px",opacity:.7},children:"↗"})]})},`custom-${x}`)}if(!n.paramName)return null;const b=M[n.paramName],d=n.displayText||n.label||n.paramName;if(n.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:z[n.paramName]==="true",onChange:m=>L(n.paramName,m.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:[d,n.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-${x}`);if(n.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:z[n.paramName]==="true",onChange:m=>L(n.paramName,m.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:[d," ",n.linkUrl&&e.jsx("a",{href:n.linkUrl,target:"_blank",rel:"noopener noreferrer",className:"underline",style:{color:"var(--metakyc-primary, #2563eb)"},onClick:m=>m.stopPropagation(),children:n.linkText||n.linkUrl}),n.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-${x}`);if(n.customType==="group_checkbox"){const m=(z[n.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:[d,n.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:(n.options||[]).map(j=>{const $=n.singleSelect?z[n.paramName]===j.value:m.includes(j.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:$,onChange:B=>{if(n.singleSelect)L(n.paramName,B.target.checked?j.value:"");else{const g=B.target.checked?[...m,j.value]:m.filter(ee=>ee!==j.value);L(n.paramName,g.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:j.label})]},j.value)})}),b&&e.jsx("p",{className:"text-red-500 text-xs",children:b})]},`custom-${x}`)}return n.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:[d,n.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:(n.options||[]).map(m=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"radio",checked:z[n.paramName]===m.value,onChange:()=>L(n.paramName,m.value),name:`radio-group-${n.paramName}-${x}`,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:m.label})]},m.value))}),b&&e.jsx("p",{className:"text-red-500 text-xs",children:b})]},`custom-${x}`):e.jsx(ne,{type:"text",label:`${d}${n.required?" *":""}`,value:z[n.paramName]||"",onChange:m=>L(n.paramName,m.target.value),required:n.required,error:b},`custom-${x}`)},Je=(n,x)=>{const b=V(n);return e.jsxs("div",{className:"space-y-4",children:[n.conditionalOn&&e.jsx(it,{helpText:n.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:d=>L(n.conditionalOn,d.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:n.conditionalOn})]})}),b&&e.jsx("div",{className:"grid grid-cols-4 gap-4",children:n.fields.map((d,m)=>{const j=d.colSpan===1?"col-span-1":d.colSpan===2?"col-span-2":d.colSpan===3?"col-span-3":"col-span-4",$=d.isCustom?`custom-${m}-${d.paramName}`:`builtin-${d.name}-${m}`;return e.jsx("div",{className:j,children:e.jsx(it,{helpText:d.helpText,children:d.isCustom?Ve(d,m):ye(d.name,$,d.displayText,d.countriesType)})},$)})})]})};if(!c||R)return e.jsx("div",{className:"metakyc-sdk",children:e.jsx(_,{children:e.jsxs(H,{children:[e.jsx(ge,{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(y){const n=y[K]??y[0],x=je===-1,b=te===-1,d=y.length,m=V(n),j=Object.values(M);return e.jsx("div",{className:"metakyc-sdk",children:e.jsxs(_,{children:[e.jsx(ie,{children:e.jsx(Ye,{title:(c==null?void 0:c.title)||"Create Applicant"})}),e.jsxs(H,{children:[(n.title||n.subtitle||n.description)&&e.jsxs("div",{className:"mb-4",children:[n.title&&e.jsx("h3",{className:"font-semibold text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:n.title}),n.subtitle&&e.jsx("p",{className:"text-sm mt-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:n.subtitle}),n.description&&n.description!==n.subtitle&&e.jsx("p",{className:"text-xs mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:n.description})]}),(S||j.length>0)&&e.jsxs("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-lg",children:[S&&e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",S]}),j.map(($,B)=>e.jsx("p",{className:"text-red-600 text-sm",children:$},B))]}),d>1&&e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[y.map(($,B)=>e.jsx("div",{className:`h-1.5 rounded-full transition-all ${B===K?"flex-1":"w-8"}`,style:B===K?{backgroundColor:"var(--metakyc-primary, #2563eb)"}:B<K?{backgroundColor:"var(--metakyc-primary-light, #93c5fd)",opacity:.7}:{backgroundColor:"#e5e7eb"}},B)),e.jsxs("span",{className:"text-xs text-gray-400 flex-shrink-0",children:[K+1," / ",d]})]}),Je(n)]}),e.jsxs(le,{className:"flex justify-between",children:[e.jsxs("div",{children:[!x&&e.jsx(W,{type:"button",variant:"outline",onClick:()=>{D(je),G({})},disabled:Z||h,children:"Previous"}),x&&a&&e.jsx(W,{type:"button",variant:"outline",onClick:a,disabled:Z||h,children:"Cancel"})]}),e.jsx(W,{type:"button",isLoading:Z||h,onClick:b?Te:de,children:b?n.conditionalOn&&!m?"Skip & Submit":"Submit":n.conditionalOn&&!m?"Skip":"Next"})]})]})})}return e.jsx("div",{className:"metakyc-sdk",children:e.jsx("form",{onSubmit:Ge,children:e.jsxs(_,{children:[e.jsx(ie,{children:e.jsx(Ye,{title:(c==null?void 0:c.title)||"Create Applicant"})}),e.jsxs(H,{children:[S&&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:"})," ",S]})}),e.jsx("div",{className:"grid grid-cols-4 gap-4",children:f.map(n=>e.jsx("div",{className:"col-span-4",children:ye(n)},n))})]}),e.jsxs(le,{className:"flex justify-between",children:[a&&e.jsx(W,{type:"button",variant:"outline",onClick:a,disabled:Z||h,children:"Cancel"}),e.jsx(W,{type:"submit",isLoading:Z||h,children:"Create Applicant"})]})]})})})},Qr=({applicantId:t,onComplete:r,onError:s,theme:a="light",className:i})=>{const{progress:o,currentStep:c,steps:u,workflowKey:h,nextWorkflowKey:p,hasWorkflowChanged:v,isLoading:C,error:y,moveBack:k,refreshProgress:f}=Zt(t),[F,E]=l.useState(!1);if(l.useEffect(()=>{y&&s&&s(y)},[y,s]),l.useEffect(()=>{o!=null&&o.workflowResult&&r&&r(o.workflowResult)},[o==null?void 0:o.workflowResult,r]),l.useEffect(()=>{a==="dark"?document.documentElement.classList.add("dark"):document.documentElement.classList.remove("dark")},[a]),l.useEffect(()=>{v&&E(!1)},[v]),C||!o)return e.jsx("div",{className:i,children:e.jsx(_,{children:e.jsxs(H,{children:[e.jsx(ge,{className:"my-8"}),e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-4",children:"Loading workflow..."})]})})});if(y)return e.jsx("div",{className:i,children:e.jsx(_,{children:e.jsx(H,{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:y.message})]})})})});if(v&&!F)return e.jsx("div",{className:`metakyc-sdk ${i||""}`,children:e.jsx(_,{children:e.jsx(H,{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:h})]}),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})]})]}),o.nextWorkflowName&&e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-2 text-xs",children:o.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(o.status===xe.Finished||o.status===xe.OnHold)return e.jsx("div",{className:`metakyc-sdk ${i||""}`,children:e.jsx(Xe,{kycStatus:o.kycStatus,reviewStatus:o.reviewStatus,workflowResult:o.workflowResult,customMessage:o.customMessage,onContinue:r&&o.workflowResult?()=>r(o.workflowResult):void 0,onContactSupport:()=>{typeof window<"u"&&(window.location.href="mailto:support@example.com")}})});if(!c)return e.jsx("div",{className:`metakyc-sdk ${i||""}`,children:e.jsx(_,{children:e.jsxs(H,{children:[e.jsx(ge,{className:"my-8"}),e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-4",children:o.status===xe.IdentityPending?"Loading identity verification...":"Loading current step..."})]})})});const N=I=>{switch(I){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""}},O=()=>{const I=u.filter(w=>w.visibility!==!1),q=I.findIndex(w=>w.order===c.order),J=q>=0?q+1:1,A=I.length;return e.jsxs("div",{className:"mb-6",children:[e.jsxs("div",{className:"flex items-start justify-between mb-4",children:[e.jsx(Ye,{}),e.jsxs(be,{variant:o.status===1?"info":"success",children:["Step ",J," of ",A]})]}),e.jsx("div",{className:"flex items-center",children:I.map((w,T)=>{const z=T<q,P=w.order===c.order;return e.jsxs(l.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
67
  ${z||P?"bg-primary-500 text-white":"bg-gray-200 text-gray-600 dark:bg-gray-700 dark:text-gray-400"}
68
68
  `,children:T+1}),e.jsx("span",{className:`ml-2 text-sm ${P?"font-semibold text-gray-900 dark:text-white":"text-gray-600 dark:text-gray-400"}`,children:w.displayName||w.name||N(w.action)||`Step ${T+1}`})]}),T<I.length-1&&e.jsx("div",{className:`flex-1 h-0.5 mx-4 ${z?"bg-primary-500":"bg-gray-200 dark:bg-gray-700"}`})]},w.order)})})]})},R=()=>{const I={applicantId:t,onComplete:async()=>{await f()},onBack:c.order>0?k:void 0};switch(c.action){case Q.Questionaries:return e.jsx(mr,{...I});case Q.UploadDocument:return e.jsx(pr,{...I});case Q.Overview:return e.jsx(hr,{...I});case Q.IdentitySdk:return e.jsx(fr,{...I});case Q.RiskScoring:return e.jsx(xr,{...I});case Q.AdditionalData:case Q.InvestorCategorization:return e.jsx(gr,{...I});case Q.AppropriatenessTest:return e.jsx(yr,{...I});case Q.ManualReview:return e.jsx(Xe,{kycStatus:o.kycStatus,reviewStatus:o.reviewStatus,workflowResult:o.workflowResult,customMessage:o.customMessage});default:return e.jsx(_,{children:e.jsxs(H,{className:"py-12 text-center",children:[e.jsx("div",{className:"mb-4",children:e.jsx(ge,{})}),e.jsxs("p",{className:"text-gray-600 dark:text-gray-400 mb-2",children:["Processing step: ",c.title||c.name]}),e.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:["Action type: ",Q[c.action]]})]})})}};return e.jsxs("div",{className:`metakyc-sdk ${i||""}`,children:[O(),R()]})};function Gr(t){return we.z.object({questionResults:we.z.any()}).passthrough()}function Vr(t){let r=we.z.array(we.z.instanceof(File));if(t.isRequired?r=r.min(1,`${t.displayName} is required`):r=r.optional(),t.multipleFile||(r=r.refine(s=>!s||s.length<=1,{message:"Only one file is allowed"})),t.maxEachFileSizeByte>0&&(r=r.refine(s=>!s||s.every(a=>a.size<=t.maxEachFileSizeByte),{message:`File size must not exceed ${Math.round(t.maxEachFileSizeByte/1024/1024)}MB`})),t.allowedTypes){const s=t.allowedTypes.split(",").map(a=>a.trim());r=r.refine(a=>a?a.every(i=>s.some(o=>o.endsWith("/*")?i.type.startsWith(o.slice(0,-2)):i.type===o)):!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)}),we.z.object(r)}function Zr(t){return we.z.any()}function Xr(t){return we.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()}),we.z.object(r)}const ts=we.z.any();exports.ALLOWED_LANGUAGES=Ze;exports.ApplicantProgressOnHoldReason=ot;exports.ApplicantProgressStatus=xe;exports.ApplicantService=wt;exports.ApplicantStatus=ct;exports.AppropriatenessQuestionType=ht;exports.AppropriatenessTestService=Nt;exports.AppropriatenessTestStep=yr;exports.Badge=be;exports.BaseInformationService=Et;exports.Button=W;exports.Card=_;exports.CardContent=H;exports.CardFooter=le;exports.CardHeader=ie;exports.CountriesType=Ie;exports.CreateApplicantForm=qr;exports.CriteriaBuiltInType=gt;exports.DEFAULT_VISIBLE_FIELDS=ft;exports.DocumentReviewStatus=pt;exports.EndpointBuilder=vt;exports.ErrorHandler=Fe;exports.EventEmitter=zt;exports.FIELD_METADATA=Re;exports.FileType=mt;exports.FileUpload=ir;exports.GenderType=Ue;exports.Header=Ye;exports.HttpClient=kt;exports.IdentityProviderManager=Pe;exports.IdentityService=At;exports.IdentityVerificationProvider=he;exports.IdentityVerificationStep=fr;exports.Input=ne;exports.InvestorCategorizationService=It;exports.InvestorCategorizationStep=gr;exports.InvestorCategorizationType=ue;exports.InvestorCategoryType=yt;exports.KycProcessStatus=dt;exports.KycStatus=Ne;exports.KycStatusDisplay=Xe;exports.KycWorkflow=Qr;exports.Logo=br;exports.MetaKYCContext=tt;exports.MetaKYCError=fe;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=Ce;exports.RiskCriteriaType=xt;exports.RiskLevel=lt;exports.RiskScoringService=Rt;exports.RiskScoringStep=xr;exports.SardinAIProvider=Kt;exports.SearchableSelect=ke;exports.Select=Qe;exports.Spinner=ge;exports.StepRouter=Bt;exports.SumsubProvider=Ht;exports.ThemeManager=Wt;exports.ThemePreset=ae;exports.ThemeService=Ot;exports.UploadDocumentService=St;exports.UploadDocumentStep=pr;exports.UserType=ut;exports.ValueDataType=ve;exports.WorkflowOrchestrator=_t;exports.WorkflowResultType=He;exports.WorkflowState=$t;exports.WorkflowStepAction=Q;exports.appropriatenessTestSchema=ts;exports.clearAllStorage=Pr;exports.clearApplicantId=Gt;exports.clearWorkflowState=Jt;exports.cn=re;exports.corporateTheme=Pt;exports.defaultConfig=bt;exports.defaultTheme=ce;exports.fileToBase64=Yt;exports.fintechTheme=Tt;exports.formatFileSize=We;exports.generateAppropriatenessSchema=es;exports.generateQuestionnaireSchema=Gr;exports.generateRiskScoringSchema=Zr;exports.generateUploadDocumentSchema=Jr;exports.getAcceptString=Er;exports.getApplicantId=Qt;exports.getThemePreset=Le;exports.getWorkflowState=Ir;exports.healthcareTheme=Ft;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=Tr;exports.useIdentityVerification=rr;exports.useKycWorkflow=Zt;exports.useMetaKYC=me;exports.useOverview=tr;exports.useQuestionnaire=Xt;exports.useRiskScoring=sr;exports.useUploadDocument=er;exports.validateFileSize=Rr;exports.validateFileType=Ar;