@vpdev2/metakyc 1.0.14 → 1.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/KycWorkflow.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -121,5 +121,5 @@ ${Object.entries(n).filter(([,y])=>!!y).map(([y,p])=>` --metakyc-${y}: ${p} !im
|
|
|
121
121
|
*
|
|
122
122
|
* This source code is licensed under the ISC license.
|
|
123
123
|
* See the LICENSE file in the root directory of this source tree.
|
|
124
|
-
*/const va=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],Or=Mr("chevron-right",va);function wa(t,r){const a=!r||r.length===0||r.every(s=>!s||!s.trim());if(t.isRequired&&a)return t.errorMessage||"This field is required";if(!a){const s=r[0]??"";if(s&&t.regex)try{if(!new RegExp(t.regex).test(s))return t.errorMessage||"Invalid format"}catch{}if(s!==""){const n=Number(s);if(!isNaN(n)&&s.trim()!==""){if(t.min!==void 0&&t.min!==null&&n<t.min)return`Minimum value is ${t.min}`;if(t.max!==void 0&&t.max!==null&&n>t.max)return`Maximum value is ${t.max}`}else{if(t.min!==void 0&&t.min!==null&&s.length<t.min)return`Minimum length is ${t.min} characters`;if(t.max!==void 0&&t.max!==null&&s.length>t.max)return`Maximum length is ${t.max} characters`}}}return null}function ja(t){const r=t.flatMap((s,n)=>(s.questions??[]).map((l,c)=>({question:l,groupIndex:n,qIdx:c}))),a=new Map;for(const s of r){const n=s.question.pageNumber!=null&&s.question.pageNumber>0?s.question.pageNumber:1;a.has(n)||a.set(n,[]),a.get(n).push(s)}return Array.from(a.entries()).sort(([s],[n])=>s-n).map(([,s])=>s)}const $r=({applicantId:t,onComplete:r,onBack:a})=>{const{questionnaire:s,initialAnswers:n,isLoading:l,isSubmitting:c,error:d,submit:y}=Rr(t),[p,k]=i.useState({}),[I,w]=i.useState({}),[A,T]=i.useState(0);i.useEffect(()=>{n&&Object.keys(n).length>0&&Object.keys(p).length===0&&k(n)},[n]);const b=i.useMemo(()=>s?ja(s.questionGroups):[],[s]),S=A===b.length-1,O=b[A]??[],q=i.useCallback((N,h)=>{k(z=>({...z,[N]:h})),w(z=>{const G={...z};return delete G[N],G})},[]),F=i.useCallback(()=>{const N={};for(const{question:h}of O){const z=wa(h,p[h.id]??[]);z&&(N[h.id]=z)}return w(h=>({...h,...N})),Object.keys(N).length===0},[O,p]),D=()=>{F()&&T(N=>N+1)},X=()=>{A>0?T(N=>N-1):a==null||a()},re=async()=>{if(!(!F()||!s))try{const N=s.questionGroups.flatMap(z=>(z.questions??[]).map(G=>({questionId:G.id,values:p[G.id]??[]}))),h={applicantId:t,questionnarieId:s.id,questionResults:N};await y(h),r==null||r()}catch(N){console.error("Questionnaire submit error:",N)}};return l?e.jsx(Z,{children:e.jsx(ee,{children:e.jsx(Ee,{className:"my-8"})})}):d?e.jsx(Z,{children:e.jsx(ee,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading questionnaire: ",d.message]})})}):s?e.jsxs(Z,{children:[e.jsxs(he,{children:[e.jsx("h2",{className:"text-lg font-bold",children:s.displayName}),s.subtitle&&e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:s.subtitle}),b.length>1&&e.jsxs("div",{className:"flex items-center justify-between mt-3",children:[e.jsxs("span",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:["Page ",A+1," of ",b.length]}),e.jsx("div",{className:"flex items-center gap-1.5",children:b.map((N,h)=>e.jsx("div",{className:"rounded-full transition-all duration-200",style:{height:"6px",width:h===A?"20px":"6px",backgroundColor:h<=A?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},h))})]})]}),e.jsx(ee,{className:"space-y-6",children:O.map(({question:N})=>e.jsx(Sa,{question:N,value:p[N.id]??[],error:I[N.id],onChange:h=>q(N.id,h)},N.id))}),e.jsxs(fe,{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs(Q,{type:"button",variant:"outline",onClick:X,style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(zr,{size:14}),A>0?"Previous":"Back"]}),S?e.jsx(Q,{type:"button",isLoading:c,onClick:re,children:"Continue"}):e.jsxs(Q,{type:"button",onClick:D,style:{display:"flex",alignItems:"center",gap:"4px"},children:["Next",e.jsx(Or,{size:14})]})]}),d&&e.jsx("div",{className:"mx-6 mb-4 p-3 bg-red-50 border border-red-200 rounded",children:e.jsx("p",{className:"text-red-600 text-sm",children:d.message})})]}):null},Sa=({question:t,value:r,error:a,onChange:s})=>{var c;const l=(((c=t.defaultAnswers)==null?void 0:c.length)??0)>0?t.showAsDropdown?t.canMultipleAnswer?"multi-select":"single-select":t.canMultipleAnswer?"checkbox":"radio":"text";return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[t.text,t.isRequired&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),t.subtitle&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:t.subtitle}),t.description&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:t.description}),l==="text"&&e.jsx(ye,{value:r[0]??"",onChange:d=>s([d.target.value]),placeholder:t.subtitle?void 0:"Enter your answer…",error:a,required:t.isRequired}),l==="single-select"&&e.jsx(ut,{value:r[0]??"",onChange:d=>s([d.target.value]),options:(t.defaultAnswers??[]).map(d=>({value:d,label:d})),placeholder:"Select an option…",error:a,required:t.isRequired}),l==="radio"&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultAnswers??[]).map(d=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"radio",checked:r[0]===d,onChange:()=>s([d]),className:"metakyc-option-input",style:{width:"16px",height:"16px",minWidth:"16px",flexShrink:0,flexGrow:0,accentColor:"var(--metakyc-primary, #2563eb)",cursor:"pointer",margin:0,padding:0,display:"inline-block",verticalAlign:"middle"}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:d})]},d)),a&&e.jsx("p",{className:"text-sm text-danger-500",children:a})]}),(l==="checkbox"||l==="multi-select")&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultAnswers??[]).map(d=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx(Fe,{checked:r.includes(d),onChange:y=>{s(y?[...r,d]:r.filter(p=>p!==d))}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:d})]},d)),a&&e.jsx("p",{className:"text-sm text-danger-500",children:a})]}),a&&l==="text"&&null]})};function Ca(t){const r=new Map;for(const a of t){const s=a.pageNumber!=null&&a.pageNumber>0?a.pageNumber:1;r.has(s)||r.set(s,[]),r.get(s).push(a)}return Array.from(r.entries()).sort(([a],[s])=>a-s).map(([,a])=>a)}const Br=({applicantId:t,onComplete:r,onBack:a})=>{const{uploadDocument:s,isLoading:n,isSubmitting:l,error:c,submit:d}=Ir(t),[y,p]=i.useState({}),[k,I]=i.useState(null),[w,A]=i.useState(0),[T,b]=i.useState({}),S=i.useMemo(()=>s?Ca(s.uploadDocumentFiles):[],[s]),O=S[w]??[],q=w===S.length-1,F=S.length,D=i.useCallback(()=>{const h={};for(const z of O)z.isRequired&&(y[z.id]||[]).length===0&&(h[z.id]=`${z.displayName} is required`);return b(h),Object.keys(h).length===0},[O,y]),X=()=>{D()&&(A(h=>h+1),b({}))},re=()=>{w>0?(A(h=>h-1),b({})):a==null||a()},N=async()=>{if(!(!D()||!s)){I(null);try{const h=await Promise.all(s.uploadDocumentFiles.map(async G=>{const Y=y[G.id]||[],B=await Promise.all(Y.map(async V=>({fileName:V.name,fileData:await br(V)})));return{uploadDocumentFileId:G.id,valueList:B}})),z={applicantId:t,uploadDocumentId:s.id,uploadDocumentResults:h};await d(z),r==null||r()}catch(h){I((h==null?void 0:h.message)||"Failed to submit documents. Please try again.")}}};return n?e.jsx(Z,{children:e.jsx(ee,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"48px 0",gap:"16px"},children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)"},children:"Loading document requirements..."})]})})}):c?e.jsx(Z,{children:e.jsx(ee,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"32px 0",gap:"12px",textAlign:"center"},children:[e.jsx("div",{style:{width:"48px",height:"48px",borderRadius:"50%",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 10%, transparent)",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),e.jsx("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]})}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-danger, #ef4444)",fontWeight:500},children:"Error loading document requirements"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-muted, #9ca3af)"},children:c.message})]})})}):s?e.jsxs(Z,{children:[e.jsxs(he,{children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:s.displayName||"Upload Documents"}),s.subtitle&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",marginTop:"4px"},children:s.subtitle}),F>1&&e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginTop:"12px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)"},children:["Page ",w+1," of ",F]}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:S.map((h,z)=>e.jsx("div",{style:{height:"6px",width:z===w?"20px":"6px",borderRadius:"999px",transition:"all 0.2s ease",backgroundColor:z<=w?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},z))})]})]}),s.description&&w===0&&e.jsxs("div",{style:{margin:"0 24px",marginTop:"4px",display:"flex",gap:"10px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-primary, #2563eb) 5%, var(--metakyc-background, #ffffff))",border:"1px solid color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-primary, #2563eb)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:"1px"},children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-secondary, #374151)",margin:0,lineHeight:1.5},children:s.description})]}),e.jsx(ee,{children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"24px"},children:O.map(h=>e.jsx(Pr,{label:h.displayName,subtitle:h.subtitle,accept:h.allowedTypes,multiple:h.multipleFile,maxSize:h.maxEachFileSizeByte,required:h.isRequired,error:T[h.id],value:y[h.id]||[],onChange:z=>{I(null),b(G=>{const Y={...G};return delete Y[h.id],Y}),p(G=>({...G,[h.id]:z}))}},h.id))})}),k&&e.jsxs("div",{style:{margin:"0 24px",padding:"10px 14px",borderRadius:"8px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:k})]}),e.jsx(fe,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[e.jsx(Q,{type:"button",variant:"outline",onClick:re,children:w>0?"Previous":"Back"}),q?e.jsx(Q,{type:"button",isLoading:l,onClick:N,children:l?"Uploading...":"Continue"}):e.jsx(Q,{type:"button",onClick:X,children:"Next"})]})})]}):null},_r=({applicantId:t,onComplete:r,onBack:a})=>{const{overview:s,isLoading:n,isSubmitting:l,error:c,passOverview:d}=Er(t),y=async()=>{await d(),r==null||r()};return n?e.jsx(Z,{children:e.jsx(ee,{children:e.jsx(Ee,{className:"my-8"})})}):c?e.jsx(Z,{children:e.jsx(ee,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading overview: ",c.message]})})}):s?e.jsxs(Z,{children:[e.jsxs(he,{children:[e.jsx("h2",{className:"text-lg font-bold",children:s.title||"Overview"}),s.description&&e.jsx("p",{className:"mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:s.description})]}),e.jsx(ee,{className:"space-y-8",children:s.steps&&s.steps.length>0?s.steps.sort((p,k)=>p.order-k.order).map(p=>e.jsxs("div",{className:"metakyc-overview-step-item flex items-center space-x-3",children:[e.jsx("div",{className:"metakyc-step-icon flex-shrink-0",children:e.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center font-medium text-sm",style:{backgroundColor:"var(--metakyc-primary, #2563eb)",color:"#ffffff"},children:p.order+1})}),e.jsxs("div",{className:"metakyc-step-content",style:{flex:1,border:"none",height:"auto",background:"transparent"},children:[e.jsx("span",{className:"metakyc-step-title text-sm font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:p.title}),p.description&&e.jsx("p",{className:"metakyc-step-description text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:p.description})]})]},p.order)):e.jsx("div",{className:"text-center py-8",children:e.jsx("p",{style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Loading overview data..."})})}),e.jsxs(fe,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[a&&e.jsx(Q,{type:"button",variant:"outline",onClick:a,children:"Back"}),e.jsx(Q,{onClick:y,isLoading:l,children:"Continue"})]})]}):null};function Na(t){const r=(t??"en").toLowerCase().replace("_","-");try{return Intl.NumberFormat.supportedLocalesOf([r]),r}catch{return"en"}}function Ra(t){return t.valueDataType===Me.Money&&Array.isArray(t.defaultValues)&&t.defaultValues.length>0}function Ia(t,r){const a=new Intl.NumberFormat(Na(r),{minimumFractionDigits:0,maximumFractionDigits:2});return t.replace(/([\d]+(?:\.\d+)?)/g,s=>{const n=parseFloat(s);return isNaN(n)?s:a.format(n)})}function Ea(t,r){const a=!r||r.length===0||r.every(s=>!s||!s.trim());if(t.isRequired&&a)return t.errorMessage||`${t.displayName} is required`;if(!a){const s=r[0]??"";if(s&&t.regex)try{if(!new RegExp(t.regex).test(s))return t.errorMessage||"Invalid format"}catch{}const n=t.valueDataType===Me.Integer||t.valueDataType===Me.Money||t.valueDataType===Me.DigitOnly;if(n&&s.trim()!==""){const l=Number(s);if(!isNaN(l)){if(t.min!==void 0&&t.min!==null&&l<t.min)return`Minimum value is ${t.min}`;if(t.max!==void 0&&t.max!==null&&l>t.max)return`Maximum value is ${t.max}`}}else if(!n&&s!==""){if(t.min!==void 0&&t.min!==null&&s.length<t.min)return`Minimum length is ${t.min} characters`;if(t.max!==void 0&&t.max!==null&&s.length>t.max)return`Maximum length is ${t.max} characters`}}return null}function Aa(t){const r=new Map;return t.forEach((a,s)=>{const n=a.pageNumber!=null&&a.pageNumber>0?a.pageNumber:1;r.has(n)||r.set(n,[]),r.get(n).push({criterion:a,idx:s})}),Array.from(r.entries()).sort(([a],[s])=>a-s).map(([,a])=>a)}function Ta(t){return t.builtInType===1?"country":!t.defaultValues||t.defaultValues.length===0?"text":t.multipleValue?"checkbox":"radio"}const Hr=({applicantId:t,onComplete:r,onBack:a})=>{const{config:s}=Re(),n=s.locale??"en",{criteria:l,initialAnswers:c,isLoading:d,isSubmitting:y,error:p,submit:k}=Tr(t),[I,w]=i.useState({}),[A,T]=i.useState({}),[b,S]=i.useState(0),[O,q]=i.useState(!1);i.useEffect(()=>{c&&Object.keys(c).length>0&&Object.keys(I).length===0&&w(c)},[c]);const F=i.useMemo(()=>l&&l.length>0?Aa(l):[],[l]),D=b===F.length-1,X=F[b]??[];i.useEffect(()=>{!d&&l&&l.length===0&&!O&&!y&&(q(!0),k({applicantId:t,criteriaValueInputs:[]}).then(()=>r==null?void 0:r()).catch(console.error))},[d,l,O,y,k,t,r]);const re=i.useCallback((Y,B)=>{w(V=>({...V,[Y]:B})),T(V=>{const ae={...V};return delete ae[Y],ae})},[]),N=i.useCallback(()=>{const Y={};for(const{criterion:B}of X){const V=Ea(B,I[B.id]??[]);V&&(Y[B.id]=V)}return T(B=>({...B,...Y})),Object.keys(Y).length===0},[X,I]),h=()=>{N()&&S(Y=>Y+1)},z=()=>{b>0?S(Y=>Y-1):a==null||a()},G=async()=>{if(!(!N()||!l))try{const Y=l.map(V=>{const ae=(I[V.id]??[]).filter(K=>K&&K.trim());return ae.length>0?{riskCriteriaId:V.id,values:ae}:null}).filter(V=>V!==null);await k({applicantId:t,criteriaValueInputs:Y}),r==null||r()}catch(Y){console.error("Risk scoring submit error:",Y)}};return d?e.jsx(Z,{children:e.jsxs(ee,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center text-sm mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Loading risk scoring criteria…"})]})}):!d&&l&&l.length===0?e.jsx(Z,{children:e.jsxs(ee,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center text-sm mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"No criteria required. Moving to next step…"})]})}):p?e.jsx(Z,{children:e.jsx(ee,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading criteria: ",p.message]})})}):l?e.jsxs(Z,{children:[e.jsxs(he,{children:[e.jsx("h2",{className:"text-lg font-bold",children:"Risk Assessment"}),e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Please answer the following questions for risk evaluation"}),F.length>1&&e.jsxs("div",{className:"flex items-center justify-between mt-3",children:[e.jsxs("span",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:["Page ",b+1," of ",F.length]}),e.jsx("div",{className:"flex items-center gap-1.5",children:F.map((Y,B)=>e.jsx("div",{className:"rounded-full transition-all duration-200",style:{height:"6px",width:B===b?"20px":"6px",backgroundColor:B<=b?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},B))})]})]}),e.jsx(ee,{className:"space-y-6",children:X.map(({criterion:Y})=>e.jsx(Fa,{criterion:Y,value:I[Y.id]??[],error:A[Y.id],locale:n,onChange:B=>re(Y.id,B)},Y.id))}),e.jsxs(fe,{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs(Q,{type:"button",variant:"outline",onClick:z,style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(zr,{size:14}),b>0?"Previous":"Back"]}),D?e.jsx(Q,{type:"button",isLoading:y,onClick:G,children:"Continue"}):e.jsxs(Q,{type:"button",onClick:h,style:{display:"flex",alignItems:"center",gap:"4px"},children:["Next",e.jsx(Or,{size:14})]})]}),p&&e.jsx("div",{className:"mx-6 mb-4 p-3 bg-red-50 border border-red-200 rounded",children:e.jsx("p",{className:"text-red-600 text-sm",children:p.message})})]}):null},Fa=({criterion:t,value:r,error:a,locale:s,onChange:n})=>{const l=Ta(t),c=t.valueDataType===Me.Integer||t.valueDataType===Me.Money||t.valueDataType===Me.DigitOnly,d=Ra(t),y=p=>d?Ia(p,s):p;return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[t.displayName,t.isRequired&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),t.description&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:t.description}),c&&(t.min!==void 0||t.max!==void 0)&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:t.min!==void 0&&t.max!==void 0?`Range: ${t.min} – ${t.max}`:t.min!==void 0?`Minimum: ${t.min}`:`Maximum: ${t.max}`}),l==="text"&&e.jsx(ye,{value:r[0]??"",onChange:p=>n([p.target.value]),type:c?"number":"text",placeholder:"Enter your answer…",error:a,required:t.isRequired,min:t.min,max:t.max,onKeyDown:p=>{t.valueDataType===Me.DigitOnly&&["e","E","+","-","."].includes(p.key)&&p.preventDefault()}}),l==="radio"&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultValues??[]).map(p=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"radio",checked:r[0]===p,onChange:()=>n([p]),className:"metakyc-option-input",style:{width:"16px",height:"16px",minWidth:"16px",flexShrink:0,flexGrow:0,accentColor:"var(--metakyc-primary, #2563eb)",cursor:"pointer",margin:0,padding:0,display:"inline-block",verticalAlign:"middle"}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:y(p)})]},p)),a&&e.jsx("p",{className:"text-sm text-danger-500",children:a})]}),l==="checkbox"&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultValues??[]).map(p=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx(Fe,{checked:r.includes(p),onChange:k=>{n(k?[...r,p]:r.filter(I=>I!==p))}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:y(p)})]},p)),a&&e.jsx("p",{className:"text-sm text-danger-500",children:a})]}),l==="country"&&e.jsx(ut,{value:r[0]??"",onChange:p=>n([p.target.value]),options:[{value:"US",label:"United States"},{value:"GB",label:"United Kingdom"},{value:"DE",label:"Germany"},{value:"FR",label:"France"},{value:"AE",label:"United Arab Emirates"}],placeholder:"Select a country…",error:a,required:t.isRequired})]})},Wr=({applicantId:t,onComplete:r,onBack:a})=>{const{investorCategorizationService:s}=Re(),[n,l]=i.useState(null),[c,d]=i.useState(!1),[y,p]=i.useState(null),k=async I=>{if(I.preventDefault(),n===null){p("Please select an investor type");return}d(!0),p(null);try{const w={applicantId:t,investorType:n};console.log("Submitting investor categorization:",w);const A=await s.setInvestorCategorization(w);console.log("Investor categorization result:",A),r==null||r()}catch(w){console.error("Error submitting investor categorization:",w),p(w.message||"Failed to submit investor categorization")}finally{d(!1)}};return e.jsx("form",{onSubmit:k,children:e.jsxs(Z,{children:[e.jsxs(he,{children:[e.jsx("h2",{className:"text-lg font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Which statement best describes you?"}),e.jsx("p",{className:"mt-2",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"All Tokenise clients are treated as Retail Investors under EU regulation, which gives you the highest level of investor protection. For our internal purposes, we ask you to select the description that best matches your situation"})]}),e.jsxs(ee,{className:"space-y-4",children:[e.jsx("p",{className:"text-sm font-medium mb-3",style:{color:"var(--metakyc-text-secondary, #374151)"},children:"Choose one"}),e.jsx("label",{className:"block p-4 border-2 rounded-lg cursor-pointer transition-all",style:{borderColor:n===we.Individual?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:n===we.Individual?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:we.Individual,checked:n===we.Individual,onChange:()=>l(we.Individual),className:"mt-1"}),e.jsxs("div",{className:"ml-3",children:[e.jsx("div",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Individual investor"}),e.jsx("div",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"(Recommended) Most of our clients choose this option. Provides the strongest protection and aligns with our mission to make investing accessible to everyone."})]})]})}),e.jsx("label",{className:"block p-4 border-2 rounded-lg cursor-pointer transition-all",style:{borderColor:n===we.Sophisticated?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:n===we.Sophisticated?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:we.Sophisticated,checked:n===we.Sophisticated,onChange:()=>l(we.Sophisticated),className:"mt-1"}),e.jsxs("div",{className:"ml-3",children:[e.jsx("div",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Sophisticated investor"}),e.jsx("div",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"In the last 2 years, I have done one or more of the following:"}),e.jsxs("ul",{className:"text-sm mt-2 space-y-1 list-none",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:[e.jsx("li",{children:"Worked in private equity or provided capital to small and medium enterprises, and/or"}),e.jsx("li",{children:"Been the director of a company with an annual turnover of at least (USD) $2m million, and/or"}),e.jsx("li",{children:"Invested directly in at least 2 private (not listed) companies."})]})]})]})}),e.jsx("label",{className:"block p-4 border-2 rounded-lg cursor-pointer transition-all",style:{borderColor:n===we.HighNetWorth?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:n===we.HighNetWorth?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:we.HighNetWorth,checked:n===we.HighNetWorth,onChange:()=>l(we.HighNetWorth),className:"mt-1"}),e.jsxs("div",{className:"ml-3",children:[e.jsx("div",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"High networth investor"}),e.jsxs("div",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:["I earn more than (USD/EUR) $150,000 per year, and/or",e.jsx("br",{}),"I have net assets (excluding my main property) of at least $/EUR 300,000"]})]})]})}),y&&e.jsx("div",{className:"p-4 rounded-lg",style:{backgroundColor:"#fee2e2",border:"1px solid #fca5a5"},children:e.jsxs("p",{className:"text-sm",style:{color:"#991b1b"},children:[e.jsx("strong",{children:"Error:"})," ",y]})})]}),e.jsxs(fe,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[a&&e.jsx(Q,{type:"button",variant:"outline",onClick:a,children:"Back"}),e.jsx(Q,{type:"submit",isLoading:c,disabled:n===null,children:"Submit"})]})]})})};function At(t){const r=t.split(":").map(Number);return r.length===3?r[0]*3600+r[1]*60+r[2]:0}function xt(t){const r=Math.floor(t/60),a=t%60;return`${r.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`}const Ur=({applicantId:t,onComplete:r,onBack:a})=>{const{appropriatenessTestService:s}=Re(),[n,l]=i.useState(null),[c,d]=i.useState(!0),[y,p]=i.useState(!1),[k,I]=i.useState(null),[w,A]=i.useState({}),[T,b]=i.useState(0),[S,O]=i.useState(!1),[q,F]=i.useState(!1),[D,X]=i.useState(0),[re,N]=i.useState(0),[h,z]=i.useState(null);i.useEffect(()=>{(async()=>{try{d(!0),I(null);const $=await s.getAppropriatenessTest(t);if(l($),$.waitTimeSpanForNextTry&&$.waitTimeSpanForNextTry!=="00:00:00"){const _=At($.waitTimeSpanForNextTry);_>0&&X(_)}}catch($){I($.message||"Failed to load appropriateness test")}finally{d(!1)}})()},[t,s]),i.useEffect(()=>{if(!S||T<=0)return;const $=setInterval(()=>{b(_=>_<=1?(F(!0),0):_-1)},1e3);return()=>clearInterval($)},[S,T]),i.useEffect(()=>{if(D<=0)return;const $=setInterval(()=>{X(_=>_<=1?0:_-1)},1e3);return()=>clearInterval($)},[D]),i.useEffect(()=>{q&&!y&&V()},[q]);const G=()=>{n&&(O(!0),b(n.testDurationSec),N(0),A({}),I(null))},Y=($,_)=>{A(ue=>({...ue,[$]:_}))},B=i.useCallback(async()=>{try{const $=await s.getAppropriatenessTest(t);if(l($),$.waitTimeSpanForNextTry&&$.waitTimeSpanForNextTry!=="00:00:00"){const _=At($.waitTimeSpanForNextTry);_>0&&X(_)}}catch{}},[t,s]),V=async $=>{if(n){if(!q){const _=n.appropriatenessQuestions.length-Object.keys(w).length;if(_>0){I(`Please answer all questions. ${_} remaining.`);return}}p(!0),I(null);try{const _=n.appropriatenessQuestions.map(R=>({appropriatenessQuestionId:R.id,value:w[R.id]||""})),ue={applicantId:t,appropriatenessTestId:n.id,appropriatenessQuestionResults:_};try{const R=await s.fillAppropriatenessTest(ue);R.isSuccess?z({success:!0,message:R.message||"Congratulations! You have passed the test."}):(z({success:!1,message:R.message||"You did not pass the test."}),setTimeout(()=>B(),1e3))}catch(R){if(R.code===400&&R.message)z({success:!1,message:R.message}),setTimeout(()=>B(),1500);else throw R}}catch(_){I(_.message||"Failed to submit test. Please try again."),ae()}finally{p(!1)}}},ae=()=>{O(!1),F(!1),A({}),N(0)};if(c)return e.jsx(Z,{children:e.jsx(ee,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"48px 0",gap:"16px"},children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)"},children:"Loading test..."})]})})});if(!n)return e.jsx(Z,{children:e.jsx(ee,{children:e.jsxs("div",{style:{textAlign:"center",padding:"48px 0"},children:[e.jsx("p",{style:{fontSize:"16px",fontWeight:600,color:"var(--metakyc-danger, #ef4444)"},children:"No test data available"}),k&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"8px"},children:k})]})})});const K=n.testAllowedMaxTry-n.totalFailedTries,ke=n.appropriatenessQuestions.length,ce=Object.keys(w).length;if(D>0)return e.jsxs(Z,{children:[e.jsx(he,{children:e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:n.displayName})}),e.jsx(ee,{children:e.jsxs("div",{style:{textAlign:"center",padding:"32px 0"},children:[e.jsx("div",{style:{width:"100px",height:"100px",borderRadius:"50%",margin:"0 auto 20px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"color-mix(in srgb, var(--metakyc-primary, #2563eb) 8%, transparent)"},children:e.jsx("span",{style:{fontSize:"28px",fontWeight:700,color:"var(--metakyc-primary, #2563eb)",fontVariantNumeric:"tabular-nums"},children:xt(D)})}),e.jsx("p",{style:{fontSize:"15px",fontWeight:500,color:"var(--metakyc-text-primary, #111827)"},children:"Please wait before retrying"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"4px"},children:"You can attempt the test again once the timer expires"}),k&&e.jsx("div",{style:{marginTop:"20px",padding:"12px 16px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:k})})]})})]});if(h){const $=()=>{z(null),ae(),I(null)};return e.jsxs(Z,{children:[e.jsx(ee,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",textAlign:"center",padding:"40px 16px",gap:"16px"},children:[e.jsx("div",{style:{width:"72px",height:"72px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:h.success?"color-mix(in srgb, var(--metakyc-success, #10b981) 12%, transparent)":"color-mix(in srgb, var(--metakyc-danger, #ef4444) 10%, transparent)"},children:h.success?e.jsxs("svg",{width:"36",height:"36",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-success, #10b981)",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),e.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]}):e.jsxs("svg",{width:"36",height:"36",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),e.jsx("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]})}),e.jsx("h2",{style:{fontSize:"20px",fontWeight:700,color:h.success?"var(--metakyc-success, #10b981)":"var(--metakyc-danger, #ef4444)",margin:0},children:h.success?"Test Passed":"Test Failed"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",margin:0,lineHeight:1.6,maxWidth:"400px",whiteSpace:"pre-line"},children:h.message}),!h.success&&K>0&&e.jsx("div",{style:{marginTop:"4px",padding:"10px 20px",borderRadius:"10px",backgroundColor:"var(--metakyc-surface, #f9fafb)",border:"1px solid var(--metakyc-border, #e5e7eb)"},children:e.jsxs("p",{style:{fontSize:"13px",color:"var(--metakyc-text-muted, #9ca3af)",margin:0},children:["You have ",e.jsx("strong",{style:{color:"var(--metakyc-text-primary, #111827)"},children:K})," attempt",K!==1?"s":""," remaining"]})}),!h.success&&K<=0&&e.jsx("div",{style:{marginTop:"4px",padding:"10px 20px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:"No attempts remaining. Please contact support for assistance."})})]})}),e.jsx(fe,{children:e.jsx("div",{style:{display:"flex",justifyContent:"center",width:"100%",gap:"12px"},children:h.success?e.jsx(Q,{type:"button",onClick:()=>r==null?void 0:r(),children:"Continue"}):e.jsxs(e.Fragment,{children:[K>0&&D<=0&&e.jsx(Q,{type:"button",onClick:$,children:"Retake Test"}),K>0&&D>0&&e.jsx(Q,{type:"button",onClick:$,children:"OK"}),K<=0&&a&&e.jsx(Q,{type:"button",variant:"outline",onClick:a,children:"Back"})]})})})]})}if(!S)return e.jsxs(Z,{children:[e.jsxs(he,{children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:n.displayName}),n.subtitle&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",marginTop:"4px"},children:n.subtitle})]}),e.jsxs(ee,{children:[n.description&&e.jsxs("div",{style:{marginBottom:"20px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-primary, #2563eb) 5%, var(--metakyc-background, #ffffff))",border:"1px solid color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)",display:"flex",gap:"10px"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-primary, #2563eb)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:"1px"},children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-secondary, #374151)",margin:0,lineHeight:1.5},children:n.description})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px",marginBottom:"20px"},children:[e.jsx(ct,{icon:"questions",label:"Questions",value:String(n.totalQuestionCount)}),e.jsx(ct,{icon:"time",label:"Time Limit",value:xt(n.testDurationSec)}),e.jsx(ct,{icon:"target",label:"Pass Requirement",value:`${n.testCorrectAnswerPassLimit} correct`}),e.jsx(ct,{icon:"retry",label:"Attempts Left",value:String(K),variant:K<=1?"warning":"default"})]}),k&&e.jsxs("div",{style:{marginBottom:"16px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)",display:"flex",gap:"10px"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:"1px"},children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),e.jsxs("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0,lineHeight:1.5},children:[e.jsx("strong",{children:"Previous attempt:"})," ",k]})]}),K<=0&&e.jsx("div",{style:{padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:"You have used all your attempts. Please contact support for assistance."})})]}),e.jsx(fe,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:a?"space-between":"flex-end",width:"100%"},children:[a&&e.jsx(Q,{type:"button",variant:"outline",onClick:a,children:"Back"}),e.jsx(Q,{type:"button",onClick:G,disabled:K<=0,children:"Start Test"})]})})]});const de=n.appropriatenessQuestions[re],ge=re===ke-1,E=ce===ke,W=T<=60;return e.jsxs(Z,{children:[e.jsxs(he,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:n.displayName}),e.jsxs("p",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"2px"},children:["Question ",re+1," of ",ke]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 14px",borderRadius:"999px",backgroundColor:W?"color-mix(in srgb, var(--metakyc-danger, #ef4444) 10%, transparent)":"var(--metakyc-surface, #f3f4f6)",transition:"all 0.3s ease"},children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:W?"var(--metakyc-danger, #ef4444)":"var(--metakyc-text-muted, #9ca3af)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),e.jsx("span",{style:{fontSize:"16px",fontWeight:700,fontVariantNumeric:"tabular-nums",color:W?"var(--metakyc-danger, #ef4444)":"var(--metakyc-text-primary, #111827)",transition:"color 0.3s ease"},children:xt(T)})]})]}),e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsx("div",{style:{height:"4px",borderRadius:"999px",backgroundColor:"var(--metakyc-border, #e5e7eb)",overflow:"hidden"},children:e.jsx("div",{style:{height:"100%",borderRadius:"999px",backgroundColor:"var(--metakyc-primary, #2563eb)",width:`${ce/ke*100}%`,transition:"width 0.3s ease"}})}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:"4px"},children:[e.jsxs("span",{style:{fontSize:"11px",color:"var(--metakyc-text-muted, #9ca3af)"},children:[ce," answered"]}),e.jsxs("span",{style:{fontSize:"11px",color:"var(--metakyc-text-muted, #9ca3af)"},children:[K," attempt",K!==1?"s":""," left"]})]})]})]}),e.jsxs(ee,{children:[de&&e.jsx(La,{question:de,index:re,selectedAnswer:w[de.id],onSelect:$=>Y(de.id,$),disabled:y}),ke>1&&e.jsx("div",{style:{display:"flex",justifyContent:"center",gap:"6px",marginTop:"20px",flexWrap:"wrap"},children:n.appropriatenessQuestions.map(($,_)=>e.jsx("button",{type:"button",onClick:()=>N(_),style:{width:"28px",height:"28px",borderRadius:"8px",border:_===re?"2px solid var(--metakyc-primary, #2563eb)":"1px solid var(--metakyc-border, #e5e7eb)",backgroundColor:w[$.id]?_===re?"color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)":"color-mix(in srgb, var(--metakyc-primary, #2563eb) 8%, transparent)":_===re?"var(--metakyc-surface, #f9fafb)":"var(--metakyc-background, #ffffff)",color:w[$.id]?"var(--metakyc-primary, #2563eb)":"var(--metakyc-text-muted, #9ca3af)",fontSize:"12px",fontWeight:600,cursor:"pointer",transition:"all 0.15s ease",padding:0,display:"flex",alignItems:"center",justifyContent:"center"},children:_+1},$.id))}),q&&e.jsxs("div",{style:{marginTop:"16px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, #f59e0b 10%, transparent)",border:"1px solid color-mix(in srgb, #f59e0b 25%, transparent)",display:"flex",alignItems:"center",gap:"10px"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"#f59e0b",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),e.jsx("p",{style:{fontSize:"13px",color:"#b45309",margin:0,fontWeight:500},children:"Time's up! Your answers are being submitted."})]}),k&&!q&&e.jsx("div",{style:{marginTop:"16px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:k})})]}),e.jsx(fe,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[e.jsx(Q,{type:"button",variant:"outline",onClick:()=>{re>0?N($=>$-1):a==null||a()},disabled:y,children:re>0?"Previous":"Cancel"}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[!ge&&e.jsx(Q,{type:"button",onClick:()=>N($=>$+1),children:"Next"}),(ge||E)&&e.jsx(Q,{type:"button",isLoading:y,onClick:()=>V(),disabled:!E&&!q,style:{opacity:E||q?1:.5},children:q?"Submitting...":"Submit Test"})]})]})})]})},Pa={questions:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M9 11l3 3L22 4"}),e.jsx("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),time:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),target:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("circle",{cx:"12",cy:"12",r:"6"}),e.jsx("circle",{cx:"12",cy:"12",r:"2"})]}),retry:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})},ct=({icon:t,label:r,value:a,variant:s="default"})=>{const n=s==="warning";return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px",padding:"14px",borderRadius:"10px",backgroundColor:n?"color-mix(in srgb, #f59e0b 8%, transparent)":"var(--metakyc-surface, #f9fafb)",border:n?"1px solid color-mix(in srgb, #f59e0b 20%, transparent)":"1px solid var(--metakyc-border, #e5e7eb)"},children:[e.jsx("div",{style:{color:n?"#f59e0b":"var(--metakyc-primary, #2563eb)",flexShrink:0},children:Pa[t]}),e.jsxs("div",{children:[e.jsx("p",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)",margin:0},children:r}),e.jsx("p",{style:{fontSize:"15px",fontWeight:600,color:n?"#b45309":"var(--metakyc-text-primary, #111827)",margin:0,marginTop:"1px"},children:a})]})]})},La=({question:t,selectedAnswer:r,onSelect:a,disabled:s})=>e.jsxs("div",{children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[t.groupName&&e.jsx("span",{style:{display:"inline-block",fontSize:"11px",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em",color:"var(--metakyc-primary, #2563eb)",marginBottom:"8px"},children:t.groupName}),e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--metakyc-text-primary, #111827)",margin:0,lineHeight:1.5},children:t.question})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.answers.map((n,l)=>{const c=r===n;return e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"12px",padding:"14px 16px",borderRadius:"10px",border:`2px solid ${c?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}`,backgroundColor:c?"color-mix(in srgb, var(--metakyc-primary, #2563eb) 5%, var(--metakyc-background, #ffffff))":"var(--metakyc-background, #ffffff)",cursor:s?"default":"pointer",transition:"all 0.15s ease",opacity:s?.6:1},onMouseEnter:d=>{!s&&!c&&(d.currentTarget.style.borderColor="color-mix(in srgb, var(--metakyc-primary, #2563eb) 50%, var(--metakyc-border, #e5e7eb))")},onMouseLeave:d=>{c||(d.currentTarget.style.borderColor="var(--metakyc-border, #e5e7eb)")},children:[e.jsx("div",{style:{width:"20px",height:"20px",borderRadius:"50%",border:`2px solid ${c?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #d1d5db)"}`,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,transition:"border-color 0.15s ease"},children:c&&e.jsx("div",{style:{width:"10px",height:"10px",borderRadius:"50%",backgroundColor:"var(--metakyc-primary, #2563eb)"}})}),e.jsx("input",{type:"radio",name:`q-${t.id}`,value:n,checked:c,onChange:()=>a(n),disabled:s,style:{position:"absolute",opacity:0,width:0,height:0}}),e.jsx("span",{style:{fontSize:"14px",color:c?"var(--metakyc-text-primary, #111827)":"var(--metakyc-text-secondary, #6b7280)",fontWeight:c?500:400,transition:"color 0.15s ease"},children:n})]},l)})})]}),Kr=({applicantId:t,onComplete:r,onBack:a})=>{var Je,$e,tt,Ke;const{applicantService:s,baseInformationService:n,identityService:l,config:c,currentTheme:d}=Re(),{identityData:y,provider:p,token:k,isLoading:I,error:w,requestIdentity:A,restartIdentity:T}=Ar(t),[b,S]=i.useState(null),[O,q]=i.useState(null),[F,D]=i.useState([]),[X,re]=i.useState([]),[N,h]=i.useState(!0),[z,G]=i.useState(!1),[Y,B]=i.useState(null),[V,ae]=i.useState(!1),K=i.useRef(!1),[ke,ce]=i.useState({}),[de,ge]=i.useState({}),E=d!=null&&d.reviewPageFields&&d.reviewPageFields.length>0?d.reviewPageFields[0]:null,W=!!(d!=null&&d.reviewPageDisabled),$=i.useRef(!1);$.current=W;const _=Ye.useForm({defaultValues:{street:"",streetNumber:"",city:"",zip:"",country:"",nationality:"",phonenumber:""}});i.useEffect(()=>{if(W){K.current||(K.current=!0,A().then(()=>G(!0)).catch(M=>console.error("[Identity] Auto-request failed:",M)).finally(()=>h(!1)));return}(async()=>{try{const[M,U,H]=await Promise.all([s.getApplicantData(t),n.getCountries("","en"),n.getCountries("","en",40)]);q(M);const J=new Set,u=U.map(g=>({value:g.abbreviation3||g.abbreviation,label:g.name})).filter(g=>!g.value||J.has(g.value)?!1:(J.add(g.value),!0));D(u);const C=new Set,P=H.filter(g=>g.countryCode).map(g=>({value:g.countryCode,label:`${g.countryCode} – ${g.name}`})).filter(g=>C.has(g.value)?!1:(C.add(g.value),!0));re(P);const m=M.applicantRequestData;if(ce({firstName:(m==null?void 0:m.firstName)||"",lastName:(m==null?void 0:m.lastName)||"",email:(m==null?void 0:m.email)||"",dateOfBirth:(m==null?void 0:m.dateOfBirth)||"",title:(m==null?void 0:m.title)||"",salutation:(m==null?void 0:m.salutation)||"",phonenumber:(m==null?void 0:m.phonenumber)||"",mobileCountryCode:(m==null?void 0:m.mobileCountryCode)||"",street:(m==null?void 0:m.street)||"",streetNumber:(m==null?void 0:m.streetNumber)||"",city:(m==null?void 0:m.city)||"",zip:(m==null?void 0:m.zip)||"",country:(m==null?void 0:m.country)||"",nationality:(m==null?void 0:m.nationality)||"",taxCountry:(m==null?void 0:m.taxCountry)||"",countryOfBirth:(m==null?void 0:m.countryOfBirth)||"",placeOfBirth:(m==null?void 0:m.placeOfBirth)||"",educationLevel:(m==null?void 0:m.educationLevel)||"",occupation:(m==null?void 0:m.occupation)||"",taxNumber:(m==null?void 0:m.taxNumber)||"",defaultLanguage:(m==null?void 0:m.defaultLanguage)||""}),_.reset({street:(m==null?void 0:m.street)||"",streetNumber:(m==null?void 0:m.streetNumber)||"",city:(m==null?void 0:m.city)||"",zip:(m==null?void 0:m.zip)||"",country:(m==null?void 0:m.country)||"",nationality:(m==null?void 0:m.nationality)||"",phonenumber:(m==null?void 0:m.phonenumber)||""}),M.kycRecords&&M.kycRecords.length>0&&M.kycRecords[0].providerTokenObject!==null&&!K.current&&$.current){console.log("[Identity] Review page disabled + existing identity — auto-requesting..."),K.current=!0;try{await A(),G(!0)}catch(g){console.error("[Identity] Auto-request failed:",g)}}}catch(M){console.error("Error loading applicant data:",M)}finally{h(!1)}})()},[t]),i.useEffect(()=>{y&&!z&&$.current&&(console.log("[Identity] Review page disabled — showing cached provider"),G(!0))},[y,z]),i.useEffect(()=>{if(k){if(k.expiresAt){const x=new Date(k.expiresAt).getTime();if(Date.now()>=x){console.warn("[Identity] Token has expired (expiresAt)"),ae(!0),B("Your verification session has expired. Please restart.");return}}if(k.url)try{const M=new URL(k.url).toString().toLowerCase();if(M.includes("expired")||M.includes("invalid")||M.includes("error")){console.warn("[Identity] Token URL indicates expiration"),ae(!0),B("Your verification link has expired. Please restart.");return}}catch{console.error("[Identity] Invalid token URL")}if(k.status==="expired"||k.error==="expired"||k.expired===!0){console.warn("[Identity] Token object indicates expiration"),ae(!0),B("Your verification session has expired. Please restart.");return}}},[k]);const ue=p!==null&&p===Ae.Sumsub;i.useEffect(()=>{if(p!==null&&k&&!b&&z&&!V){const x=p;if(ue){console.log("[Sumsub] Fetching access token for Web SDK…"),B(null),(async()=>{try{const M=await l.refreshSumsubToken(t),U=He.parseProviderConfig(p,k,c);U.accessToken=M,U.onTokenRefresh=()=>l.refreshSumsubToken(t);const H=He.createProvider(p,U);H.onComplete(J=>{console.log("[Sumsub] Verification complete:",J),r==null||r()}),H.onError(J=>{console.error("[Sumsub] SDK error:",J),(typeof J=="string"?J:(J==null?void 0:J.message)||"Unknown error").toLowerCase().includes("expired")&&(ae(!0),B("Session expired. Please restart."))}),await H.initialize("sumsub-websdk-container"),console.log("[Sumsub] Web SDK launched"),S(H)}catch(M){console.error("[Sumsub] Initialization error:",M),B(`Failed to initialize: ${M.message||M}`),String(M.message||M).toLowerCase().includes("expired")&&ae(!0)}})();return}if(k.url){console.log("[Identity] Loading provider URL for user verification:",k.url),B(null);try{if(new URL(k.url),x===Ae.SardinAI){console.log("[SardinAI] Initializing Risk SDK in background...");try{const M=He.parseProviderConfig(p,k,c);He.createProvider(p,M).initialize().then(()=>console.log("[SardinAI] Risk SDK initialized in background")).catch(H=>console.warn("[SardinAI] Risk SDK init failed (non-blocking):",H))}catch(M){console.warn("[SardinAI] Risk SDK setup failed (non-blocking):",M)}}S({type:"url",url:k.url})}catch(M){console.error("[Identity] Invalid URL:",M),B("Invalid verification URL. Please restart."),ae(!0)}return}if(x===Ae.SardinAI){console.log("[SardinAI] No URL provided - initializing Risk SDK only..."),B(null);try{const M=He.parseProviderConfig(p,k,c),U=He.createProvider(p,M);U.initialize().then(()=>{console.log("[SardinAI] Risk SDK initialized successfully"),S(U),setTimeout(()=>r==null?void 0:r(),2e3)}).catch(H=>{var u;console.error("[SardinAI] Failed to initialize:",H);const J=((u=H.message)==null?void 0:u.toLowerCase())||"";J.includes("expired")||J.includes("invalid")||J.includes("401")||J.includes("400")?(ae(!0),B("Session expired or invalid. Please restart verification.")):B(`Failed to initialize: ${H.message}`)})}catch(M){console.error("[SardinAI] Error creating provider:",M),B(`Configuration error: ${M.message}`)}return}try{B(null);const M=He.parseProviderConfig(p,k,c),U=He.createProvider(p,M);x===Ae.Onfido&&U.initialize("identity-container").catch(H=>{console.error("[Onfido] Initialization error:",H),B(`Failed to initialize: ${H.message}`)}),S(U)}catch(M){console.error("[Identity] Provider setup error:",M),B(`Setup error: ${M.message}`)}}return()=>{if(b&&b.destroy)try{b.destroy()}catch(x){console.error("[Identity] Error destroying provider:",x)}}},[p,k,b,z,r,V,ue,t,c,l]);const R=async()=>{try{B(null),ae(!1),await A(),G(!0)}catch(x){console.error("Error starting identity verification:",x)}},te=async()=>{try{B(null),ae(!1),S(null),console.log("[Identity] Restarting verification..."),await T(),G(!0)}catch(x){console.error("Error restarting identity verification:",x),B(x.message||"Failed to restart verification")}};if(N||I)return e.jsx(Z,{children:e.jsxs(ee,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-4",children:"Loading identity verification..."})]})});if(w)return e.jsx(Z,{children:e.jsx(ee,{children:e.jsxs("p",{className:"text-danger-500",children:["Error: ",w.message]})})});if(z&&(Y||V))return e.jsxs(Z,{children:[e.jsx(he,{children:e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"Verification Session Issue"})}),e.jsxs(ee,{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:V?"Session Expired":"Verification Error"}),e.jsx("p",{className:"text-red-800 dark:text-red-200 text-sm",children:Y||"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(fe,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[a&&e.jsx(Q,{type:"button",variant:"outline",onClick:a,children:"Back"}),e.jsx(Q,{type:"button",onClick:te,disabled:I,children:I?"Restarting...":"Restart Verification"})]})]});if(z&&y){const x=p;return ue?e.jsxs("div",{style:{background:"var(--metakyc-background, #ffffff)",borderRadius:"12px",border:"1px solid var(--metakyc-border, #e5e7eb)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"20px 24px",borderBottom:"1px solid var(--metakyc-border, #e5e7eb)"},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{margin:0,fontSize:"20px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)"},children:"Identity Verification"}),e.jsx("p",{style:{margin:"4px 0 0",fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)"},children:"Please complete the identity verification process"})]}),e.jsx("button",{type:"button",onClick:te,disabled:I,style:{padding:"6px 14px",fontSize:"13px",fontWeight:500,borderRadius:"8px",border:"1px solid var(--metakyc-border, #d1d5db)",background:"var(--metakyc-background, #ffffff)",color:"var(--metakyc-text-primary, #111827)",cursor:I?"not-allowed":"pointer",opacity:I?.5:1},children:I?"Restarting…":"Restart"})]}),e.jsx("div",{id:"sumsub-websdk-container",style:{minHeight:"520px",width:"100%",padding:"16px 24px",background:"var(--metakyc-background, #ffffff)"}}),a&&e.jsx("div",{style:{padding:"16px 24px",borderTop:"1px solid var(--metakyc-border, #e5e7eb)"},children:e.jsx(Q,{variant:"outline",onClick:a,children:"Back"})})]}):k!=null&&k.url?e.jsxs(Z,{children:[e.jsx(he,{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(Q,{type:"button",variant:"outline",size:"sm",onClick:te,disabled:I,children:"Restart"})]})}),e.jsxs(ee,{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:k.url,className:"w-full h-full border-0 rounded-lg",allow:"camera; microphone; geolocation",title:"Identity Verification",onLoad:M=>{var U,H,J;console.log("[Identity] Iframe loaded");try{const u=M.target,C=u.contentDocument||((U=u.contentWindow)==null?void 0:U.document);if(C){const P=((J=(H=C.body)==null?void 0:H.textContent)==null?void 0:J.toLowerCase())||"";(P.includes("expired")||P.includes("invalid")||P.includes("error"))&&(console.warn("[Identity] Iframe shows expiration message"),ae(!0),B("Your verification link has expired."))}}catch{console.log("[Identity] Cannot check iframe content (CORS)")}}})})]}),a&&e.jsx(fe,{children:e.jsx(Q,{variant:"outline",onClick:a,children:"Back"})})]}):x===Ae.SardinAI?e.jsxs(Z,{children:[e.jsxs(he,{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(ee,{children:e.jsxs("div",{className:"text-center py-12",children:[e.jsx(Ee,{className:"mb-4"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Please wait while we verify your device security"}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-500 mt-2",children:"This process is automatic and will complete in a few seconds"})]})})]}):e.jsxs(Z,{children:[e.jsxs(he,{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(ee,{children:e.jsx("div",{id:"identity-container",className:"min-h-[400px]"})}),a&&e.jsx(fe,{children:e.jsx(Q,{variant:"outline",onClick:a,children:"Back"})})]})}const me=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),se=(x=4)=>{const M=Math.min(4,Math.max(1,Number(x)||4));return{gridColumn:`span ${M} / span ${M}`}},be=(x,M)=>{if(!M&&M!==0)return"—";if(me.has(x)&&x!=="mobileCountryCode"){const U=F.find(H=>H.value===M);return U?U.label:String(M)}return String(M)},Pe=({helpText:x})=>{const[M,U]=i.useState(!1),H=i.useRef(null),[,J]=i.useState({top:0,left:0}),u=()=>{if(H.current){const C=H.current.getBoundingClientRect();J({top:C.bottom+window.scrollY+6,left:C.left+window.scrollX})}U(!0)};return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"metakyc-help-btn",ref:H,onClick:u,style:{width:18,height:18,borderRadius:"50%",border:"1.5px solid var(--metakyc-primary, #2563eb)",background:"transparent",color:"var(--metakyc-primary, #2563eb)",fontSize:11,fontWeight:700,cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,lineHeight:1,position:"relative",zIndex:2},children:"?"}),M&&pt.createPortal(e.jsx("div",{style:{position:"fixed",inset:0,zIndex:99999,background:"rgba(0,0,0,0.55)",backdropFilter:"blur(6px)",WebkitBackdropFilter:"blur(6px)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:()=>U(!1),children:e.jsxs("div",{onClick:C=>C.stopPropagation(),style:{background:"var(--metakyc-surface, var(--metakyc-background, #ffffff))",border:"1px solid var(--metakyc-border, #e5e7eb)",borderRadius:"var(--metakyc-border-radius, 8px)",padding:"20px 24px",maxWidth:400,width:"90%",boxShadow:"0 24px 64px rgba(0,0,0,0.4)"},children:[e.jsx("div",{dangerouslySetInnerHTML:{__html:x},style:{fontSize:13,color:"var(--metakyc-text-primary, #111827)",lineHeight:1.6}}),e.jsx("button",{type:"button",onClick:()=>U(!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)]})},ve=(x,M)=>M?e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:5,flexWrap:"nowrap"},children:[e.jsx("div",{style:{flex:1,minWidth:0},children:x}),e.jsx("div",{style:{paddingTop:24},children:e.jsx(Pe,{helpText:M})})]}):x,Oe=(x,M)=>{const U=`cf-${M}`,H=x.paramName??"",J=de[H];if(x.customType==="br")return e.jsx("div",{style:{...se(x.colSpan),minHeight:"0.5rem"}},U);if(x.customType==="paragraph")return e.jsx("div",{style:se(x.colSpan),children:e.jsx("div",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:x.label||""}})},U);if(x.customType==="html")return e.jsx("div",{style:se(x.colSpan),dangerouslySetInnerHTML:{__html:x.label||""}},U);if(x.customType==="link")return e.jsx("div",{style:se(x.colSpan),children:ve(e.jsx("a",{href:x.linkUrl??"#",target:"_blank",rel:"noopener noreferrer",className:"text-sm underline",style:{color:"var(--metakyc-primary, #6366f1)"},children:x.displayText||x.label||x.linkText||x.linkUrl}),x.helpText)},U);if(x.customType==="checkbox"||x.customType==="link_checkbox"){const u=J==="true"||J===!0;return e.jsx("div",{style:se(x.colSpan),children:ve(e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx(Fe,{checked:!!u,onChange:C=>ge(P=>({...P,[H]:String(C)})),style:{marginTop:2}}),e.jsx("span",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)"},children:x.customType==="link_checkbox"&&x.linkUrl?e.jsxs(e.Fragment,{children:[e.jsx("a",{href:x.linkUrl,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--metakyc-primary, #6366f1)",textDecoration:"underline"},children:x.linkText||x.label}),x.label&&x.linkText?` ${x.label}`:""]}):x.displayText||x.label})]}),x.helpText)},U)}if(x.customType==="group_checkbox"){const u=Array.isArray(J)?J:J?[J]:[],C=P=>{x.singleSelect?ge(m=>({...m,[H]:u[0]===P?[]:[P]})):ge(m=>({...m,[H]:u.includes(P)?u.filter(o=>o!==P):[...u,P]}))};return e.jsx("div",{style:se(x.colSpan),children:ve(e.jsxs("div",{className:"space-y-1.5",children:[x.label&&e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:x.displayText||x.label}),(x.options||[]).map(P=>e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx(Fe,{checked:u.includes(P.value),onChange:()=>C(P.value),style:{marginTop:2}}),e.jsx("span",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)"},children:P.label})]},P.value))]}),x.helpText)},U)}return x.customType==="radio_group"?e.jsx("div",{style:se(x.colSpan),children:ve(e.jsxs("div",{className:"space-y-1.5",children:[x.label&&e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:x.displayText||x.label}),(x.options||[]).map(u=>e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"radio",name:`rg-${H}`,value:u.value,checked:J===u.value,onChange:()=>ge(C=>({...C,[H]:u.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:u.label})]},u.value))]}),x.helpText)},U):e.jsx("div",{style:se(x.colSpan),children:ve(e.jsx(ye,{label:x.displayText||x.label||H,value:String(J??""),onChange:u=>ge(C=>({...C,[H]:u.target.value}))}),x.helpText)},U)},et=(x,M)=>{if(x.isCustom)return Oe(x,M);const U=x.name??"",H=Ge[U],J=x.displayText||(H==null?void 0:H.label)||U,u=ke[U]??"",C=U==="mobileCountryCode",P=!!(H!=null&&H.countriesType)&&!C;return x.editable?C?e.jsx("div",{style:se(x.colSpan??2),children:ve(e.jsx(ze,{label:J,value:String(u),onChange:m=>ce(o=>({...o,[U]:m})),options:[{value:"",label:"Select country code…"},...X]}),x.helpText)},`epc-${M}`):P?e.jsx("div",{style:se(x.colSpan??2),children:ve(e.jsx(ze,{label:J,value:String(u),onChange:m=>ce(o=>({...o,[U]:m})),options:[{value:"",label:`Select ${J.toLowerCase()}…`},...F]}),x.helpText)},`ec-${M}`):e.jsx("div",{style:se(x.colSpan??2),children:ve(e.jsx(ye,{label:J,type:(H==null?void 0:H.type)==="date"?"date":(H==null?void 0:H.type)==="email"?"email":"text",value:String(u),onChange:m=>ce(o=>({...o,[U]:m.target.value}))}),x.helpText)},`ei-${M}`):e.jsx("div",{style:se(x.colSpan??2),children:ve(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:J}),e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)",minHeight:"1.5rem"},children:be(U,u)})]}),x.helpText)},`ro-${M}`)};if(E){const x=E.title||"Review Your Information",M=E.subtitle||"Please review and confirm your information before starting identity verification";return e.jsx("form",{onSubmit:U=>{U.preventDefault(),R()},children:e.jsxs(Z,{children:[e.jsxs(he,{children:[e.jsx("h2",{className:"text-lg font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:x}),e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:M})]}),e.jsx(ee,{children:e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:E.fields.map((U,H)=>et(U,H))})}),e.jsxs(fe,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[a&&e.jsx(Q,{type:"button",variant:"outline",onClick:a,children:"Back"}),e.jsx(Q,{type:"submit",isLoading:I,children:"Confirm and Start Verification"})]})]})})}return e.jsx("form",{onSubmit:_.handleSubmit(R),children:e.jsxs(Z,{children:[e.jsxs(he,{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(ee,{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:`${((Je=O==null?void 0:O.applicantRequestData)==null?void 0:Je.firstName)||""} ${(($e=O==null?void 0:O.applicantRequestData)==null?void 0:$e.lastName)||""}`.trim()},{label:"Email",value:(tt=O==null?void 0:O.applicantRequestData)==null?void 0:tt.email},{label:"Date of Birth",value:((Ke=O==null?void 0:O.applicantRequestData)==null?void 0:Ke.dateOfBirth)||"Not provided"}].map(({label:x,value:M})=>e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:x}),e.jsx("p",{className:"mt-1 text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:M})]},x))}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Address Information"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Ye.Controller,{control:_.control,name:"country",render:({field:x})=>e.jsx(ze,{label:"Country",value:x.value,onChange:x.onChange,options:[{value:"",label:"Select country…"},...F]})}),e.jsx(Ye.Controller,{control:_.control,name:"nationality",render:({field:x})=>e.jsx(ze,{label:"Nationality",value:x.value,onChange:x.onChange,options:[{value:"",label:"Select nationality…"},...F]})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Ye.Controller,{control:_.control,name:"street",render:({field:x})=>e.jsx(ye,{...x,label:"Street"})}),e.jsx(Ye.Controller,{control:_.control,name:"streetNumber",render:({field:x})=>e.jsx(ye,{...x,label:"Street Number"})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Ye.Controller,{control:_.control,name:"city",render:({field:x})=>e.jsx(ye,{...x,label:"City"})}),e.jsx(Ye.Controller,{control:_.control,name:"zip",render:({field:x})=>e.jsx(ye,{...x,label:"ZIP / Postal Code"})})]}),e.jsx(Ye.Controller,{control:_.control,name:"phonenumber",render:({field:x})=>e.jsx(ye,{...x,label:"Phone Number",type:"tel"})})]})]}),e.jsxs(fe,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[a&&e.jsx(Q,{type:"button",variant:"outline",onClick:a,children:"Back"}),e.jsx(Q,{type:"submit",isLoading:I,children:"Confirm and Start Verification"})]})]})})},ft=({kycStatus:t,reviewStatus:r,workflowResult:a,customMessage:s,onContinue:n,onContactSupport:l})=>{const d=t===Ve.Approved?{type:"success",title:"Verification Approved",icon:"✓",iconBg:"bg-green-100 dark:bg-green-900/30",iconColor:"text-green-600 dark:text-green-400",message:"Your identity verification has been successfully approved."}:t===Ve.Rejected?{type:"error",title:"Verification Rejected",icon:"✕",iconBg:"bg-red-100 dark:bg-red-900/30",iconColor:"text-red-600 dark:text-red-400",message:"Unfortunately, your identity verification was not approved."}:t===Ve.Pending||t===Ve.InProgress?{type:"pending",title:"Verification Pending",icon:"⏱",iconBg:"bg-blue-100 dark:bg-blue-900/30",iconColor:"text-blue-600 dark:text-blue-400",message:"Your identity verification is currently being processed."}:r===Qe.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===Qe.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===Qe.UnderReview||r===Qe.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."}:a===ot.Success?{type:"success",title:"Process Complete",icon:"✓",iconBg:"bg-green-100 dark:bg-green-900/30",iconColor:"text-green-600 dark:text-green-400",message:"Your verification process has been completed successfully."}:a===ot.Failed?{type:"error",title:"Process Failed",icon:"✕",iconBg:"bg-red-100 dark:bg-red-900/30",iconColor:"text-red-600 dark:text-red-400",message:"The verification process could not be completed."}:a===ot.AdminReview?{type:"pending",title:"Admin Review Required",icon:"📋",iconBg:"bg-yellow-100 dark:bg-yellow-900/30",iconColor:"text-yellow-700 dark:text-yellow-400",message:"Your application requires administrator review."}:{type:"pending",title:"Processing",icon:"⏱",iconBg:"bg-blue-100 dark:bg-blue-900/30",iconColor:"text-blue-600 dark:text-blue-400",message:"Your application is being reviewed."};return e.jsxs(Z,{children:[e.jsxs(ee,{className:"py-12",children:[e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx("div",{className:`w-24 h-24 rounded-full flex items-center justify-center ${d.iconBg}`,children:e.jsx("span",{className:`text-5xl ${d.iconColor}`,children:d.icon})})}),e.jsx("h2",{className:"text-3xl font-bold text-center mb-4",style:{color:"var(--metakyc-text-primary, #111827)"},children:d.title}),e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx(wt,{variant:d.type==="success"?"success":d.type==="error"?"danger":d.type==="pending"?"warning":"info",children:t!=null?Ve[t]:Qe[r]})}),e.jsx("p",{className:"text-center mb-6 max-w-md mx-auto",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:s||d.message}),d.type==="success"&&e.jsxs("div",{className:"bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg p-4 mb-6",children:[e.jsx("h3",{className:"font-semibold text-green-900 dark:text-green-100 mb-2",children:"What's Next?"}),e.jsxs("ul",{className:"text-sm text-green-800 dark:text-green-200 space-y-1",children:[e.jsx("li",{children:"✓ Your identity has been verified"}),e.jsx("li",{children:"✓ You can now proceed with your application"}),e.jsx("li",{children:"✓ All features are now accessible"})]})]}),d.type==="error"&&e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 mb-6",children:[e.jsx("h3",{className:"font-semibold text-red-900 dark:text-red-100 mb-2",children:"What Can You Do?"}),e.jsxs("ul",{className:"text-sm text-red-800 dark:text-red-200 space-y-2",children:[e.jsx("li",{children:"• Review the requirements and ensure all information is correct"}),e.jsx("li",{children:"• Contact our support team for assistance"}),e.jsx("li",{children:"• You may be able to resubmit your application"})]})]}),d.type==="pending"&&e.jsxs("div",{className:"bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-4 mb-6",children:[e.jsx("h3",{className:"font-semibold text-blue-900 dark:text-blue-100 mb-2",children:"What Happens Next?"}),e.jsxs("ul",{className:"text-sm text-blue-800 dark:text-blue-200 space-y-2",children:[e.jsx("li",{children:"• Our team is reviewing your information"}),e.jsx("li",{children:"• You will be notified via email once the review is complete"}),e.jsx("li",{children:"• This typically takes 24-48 hours"}),e.jsx("li",{children:"• No action is required from you at this time"})]})]}),e.jsx("div",{className:"mt-6 pt-6",style:{borderTop:"1px solid var(--metakyc-border, #e5e7eb)"},children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"KYC Status:"}),e.jsx("div",{className:"font-medium mt-1",style:{color:"var(--metakyc-text-primary, #111827)"},children:t!=null?Ve[t]:"Not Available"})]}),e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"Review Status:"}),e.jsx("div",{className:"font-medium mt-1",style:{color:"var(--metakyc-text-primary, #111827)"},children:Qe[r]})]})]})})]}),e.jsxs(fe,{style:{display:"flex",justifyContent:"center",gap:"1rem"},children:[d.type==="success"&&n&&e.jsx(Q,{onClick:n,size:"lg",children:"Continue"}),d.type==="error"&&e.jsxs(e.Fragment,{children:[l&&e.jsx(Q,{variant:"outline",onClick:l,children:"Contact Support"}),n&&e.jsx(Q,{onClick:n,children:"Try Again"})]}),d.type==="pending"&&e.jsx("div",{className:"text-center",children:e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Please check back later or wait for our email notification"})})]})]})},qr=({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:a=>{console.warn("[Logo] Failed to load logo:",t.url),a.target.style.display="none"}})}),nt=({title:t,subtitle:r,className:a=""})=>{const{currentTheme:s}=Re(),n=t||(s==null?void 0:s.title)||"",l=!!(s!=null&&s.logo&&s.logo.visible&&s.logo.url),c=!!n;return!l&&!c?null:e.jsxs("div",{className:`metakyc-header ${a}`,children:[e.jsxs("div",{className:"metakyc-header-title flex items-center text-xl font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:[l&&e.jsx(qr,{config:s.logo}),l&&c&&e.jsx("span",{style:{fontSize:"1.5rem",fontWeight:300,color:"var(--metakyc-text-muted, #9ca3af)",margin:"0 12px"},children:"|"}),c&&e.jsx("span",{style:{color:"var(--metakyc-text-primary, #111827)"},children:n})]}),r&&e.jsx("p",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:r})]})},dt=["firstName","lastName","email","phonenumber","dateOfBirth"];function rt(t){return t==null||t===""||Array.isArray(t)&&t.length===0}const Da={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"},Tt=({helpText:t,children:r})=>{const[a,s]=i.useState(!1);if(!t)return e.jsx(e.Fragment,{children:r});const n=a?e.jsx("div",{role:"dialog","aria-modal":"true",onClick:()=>s(!1),style:{position:"fixed",inset:0,zIndex:999999,background:"rgba(0, 0, 0, 0.55)",backdropFilter:"blur(6px)",WebkitBackdropFilter:"blur(6px)",display:"flex",alignItems:"center",justifyContent:"center",padding:"16px"},children:e.jsxs("div",{onClick:l=>l.stopPropagation(),style:{background:"var(--metakyc-surface, var(--metakyc-background, #ffffff))",border:"1px solid var(--metakyc-border, #e5e7eb)",borderRadius:"12px",padding:"28px 24px 24px",maxWidth:"480px",width:"100%",maxHeight:"80vh",overflowY:"auto",boxShadow:"0 24px 64px rgba(0,0,0,0.4)",position:"relative"},children:[e.jsx("button",{type:"button",onClick:()=>s(!1),"aria-label":"Close",style:{position:"absolute",top:"12px",right:"12px",width:"28px",height:"28px",borderRadius:"50%",border:"1px solid var(--metakyc-border, #e5e7eb)",background:"var(--metakyc-input-bg, #f3f4f6)",color:"var(--metakyc-text-secondary, #6b7280)",fontSize:"16px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:"×"}),e.jsx("div",{style:{color:"var(--metakyc-text-primary, #111827)",fontSize:"14px",lineHeight:1.75},dangerouslySetInnerHTML:{__html:t}})]})}):null;return e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"5px",flexWrap:"nowrap"},children:[r,e.jsx("button",{type:"button",className:"metakyc-help-btn",onClick:()=>s(!0),"aria-label":"Help",style:{flexShrink:0,marginTop:"2px",width:"18px",height:"18px",borderRadius:"50%",border:"1.5px solid var(--metakyc-primary, #2563eb)",background:"transparent",color:"var(--metakyc-primary, #2563eb)",fontSize:"10px",fontWeight:"700",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,padding:0,position:"relative",zIndex:2,transition:"background 0.15s, color 0.15s"},onMouseEnter:l=>{l.currentTarget.style.background="var(--metakyc-primary, #2563eb)",l.currentTarget.style.color="#ffffff"},onMouseLeave:l=>{l.currentTarget.style.background="transparent",l.currentTarget.style.color="var(--metakyc-primary, #2563eb)"},children:"?"}),typeof document<"u"&&n?pt.createPortal(n,document.body):null]})},Ma=({workflowKey:t,externalRefId:r,onSuccess:a,onCancel:s})=>{var U,H,J,u,C,P,m;const{config:n,baseInformationService:l,currentTheme:c}=Re(),{createApplicant:d,isLoading:y}=vt(),p=t||((U=n.applicantForm)==null?void 0:U.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 k=r||((H=n.applicantForm)==null?void 0:H.externalRefId)||"",I=((J=n.applicantForm)==null?void 0:J.email)||"",w=((u=n.applicantForm)==null?void 0:u.hiddenValues)||{},A=((C=n.applicantForm)==null?void 0:C.initialValues)||{},b=(((P=n.applicantForm)==null?void 0:P.fieldLabelMode)||(c==null?void 0:c.fieldLabelMode)||"label")!=="placeholder",S=i.useMemo(()=>c!=null&&c.applicantFormPages&&c.applicantFormPages.length>0?c.applicantFormPages:null,[c==null?void 0:c.applicantFormPages]),O=i.useMemo(()=>{const o=new Set(dt),g=c==null?void 0:c.applicantFormRequiredFields;if(g)for(const L of g)o.add(L);if(S)for(const L of S)for(const f of L.fields)!f.isCustom&&f.name&&f.required&&o.add(f.name);return Array.from(o)},[c==null?void 0:c.applicantFormRequiredFields,S]),q=i.useMemo(()=>{var L;if(S){const f=S.flatMap(v=>v.fields).filter(v=>!v.isCustom&&v.name).map(v=>v.name),j=new Set(f);for(const v of dt)j.add(v);return Array.from(j)}let o;(L=n.applicantForm)!=null&&L.visibleFields?o=n.applicantForm.visibleFields:c!=null&&c.applicantFormVisibleFields&&c.applicantFormVisibleFields.length>0?o=c.applicantFormVisibleFields:o=Kt;const g=new Set(o);for(const f of dt)g.add(f);return Array.from(g)},[(m=n.applicantForm)==null?void 0:m.visibleFields,c==null?void 0:c.applicantFormVisibleFields,S]),F=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),D=i.useMemo(()=>{var g,L;const o=new Set;if(S)for(const f of S)for(const j of f.fields)!j.isCustom&&j.name&&F.has(j.name)&&o.add(j.countriesType??((g=Ge[j.name])==null?void 0:g.countriesType));else for(const f of q)F.has(f)&&o.add((L=Ge[f])==null?void 0:L.countriesType);return o.size===0&&o.add(void 0),Array.from(o)},[q,S]),[X,re]=i.useState({}),[N,h]=i.useState(!0),z=i.useRef(new Set),G=i.useRef(new Set);i.useEffect(()=>{if(!c)return;const o=D.filter(f=>{const j=f!=null?String(f):"all";return!G.current.has(j)&&!z.current.has(j)});if(o.length===0){D.every(j=>{const v=j!=null?String(j):"all";return G.current.has(v)})&&h(!1);return}h(!0);const g=o.map(f=>f!=null?String(f):"all");g.forEach(f=>z.current.add(f)),(async()=>{try{const f=await Promise.all(o.map(async j=>{const v=j!=null?String(j):"all",le=await l.getCountries("",n.locale||"en",j),ne=j===40,xe=new Set,Ie=le.map(ie=>ne&&ie.countryCode?{value:ie.countryCode,label:`${ie.countryCode} – ${ie.name}`}:{value:ie.abbreviation3||ie.abbreviation,label:ie.name}).filter(ie=>!ie.value||xe.has(ie.value)?!1:(xe.add(ie.value),!0));return G.current.add(v),z.current.delete(v),[v,Ie]}));re(j=>({...j,...Object.fromEntries(f)}))}catch(f){g.forEach(j=>z.current.delete(j)),console.error("Failed to load countries:",f)}finally{D.every(j=>{const v=j!=null?String(j):"all";return G.current.has(v)})&&h(!1)}})()},[D,c]);const Y=(o,g)=>{var j;const L=g??((j=Ge[o])==null?void 0:j.countriesType),f=L!=null?String(L):"all";return X[f]||[]},B={firstName:1,lastName:1,title:1,email:1,dateOfBirth:1,phonenumber:1,mobileCountryCode:1,street:1,streetNumber:1,zip:1,city:1,country:1,nationality:1,otherNationality:1,defaultLanguage:1,taxCountry:1,placeOfBirth:1,countryOfBirth:1,salutation:1,educationLevel:1,occupation:1,taxNumber:1},V=Object.fromEntries(Object.entries(w).filter(([o])=>o in B)),ae=Object.fromEntries(Object.entries(A).filter(([o])=>o in B)),[K,ke]=i.useState({workflowKey:p,firstName:"",lastName:"",title:"",email:I,dateOfBirth:"",phonenumber:"",externalRefId:k,mobileCountryCode:"",street:"",streetNumber:"",zip:"",city:"",country:"",nationality:"",otherNationality:[],defaultLanguage:"EN",taxCountry:"",placeOfBirth:"",countryOfBirth:"",salutation:null,educationLevel:"",occupation:"",taxNumber:"",...V,...ae}),ce=Object.fromEntries(Object.entries(w).filter(([o])=>!(o in V)&&o!=="externalRefId"&&o!=="workflowKey")),[de,ge]=i.useState({...ce}),[E,W]=i.useState(0),[$,_]=i.useState({}),[ue,R]=i.useState(null),[te,me]=i.useState(!1),se=(o,g)=>ke(L=>({...L,[o]:g})),be=(o,g)=>ge(L=>({...L,[o]:g})),Pe=o=>!o.conditionalOn||de[o.conditionalOn]==="true",ve=S&&E<S.length-1?E+1:-1,Oe=S&&E>0?E-1:-1,et=o=>{var L;const g={};for(const f of o.fields)if(f.isCustom){if(f.customType==="paragraph"||f.customType==="html"||f.customType==="br"||f.customType==="link")continue;if(f.required&&f.paramName){const j=de[f.paramName],v=f.displayText||f.label||f.paramName;f.customType==="checkbox"||f.customType==="link_checkbox"?j!=="true"&&(g[f.paramName]=`${v} is required.`):(!j||j.trim()==="")&&(g[f.paramName]=`${v} is required.`)}}else if(f.name){const j=f.name;if(O.includes(j)&&rt(K[j])){const v=f.displayText||((L=Ge[j])==null?void 0:L.label)||j;g[j]=`${v} is required.`}}return g},Je=async()=>{if(!S)return;const o=S[E];if(o.conditionalOn&&!Pe(o)){_({}),ve>=0?W(ve):await $e();return}const g=et(o);if(Object.keys(g).length>0){_(g);return}_({}),ve>=0?W(ve):await $e()},$e=async()=>{if(S){let o={};for(const g of S)Pe(g)&&(o={...o,...et(g)});if(Object.keys(o).length>0){_(o);return}}me(!0),R(null);try{if(!K.externalRefId||K.externalRefId.trim()===""){R("External Reference ID is required. Please pass it via config.applicantForm.externalRefId.");return}const o={workflowKey:K.workflowKey,externalRefId:K.externalRefId.trim()};if(S){for(const j of S)if(Pe(j)){for(const v of j.fields)if(!v.isCustom&&v.name){const le=v.name,ne=K[le];rt(ne)||(o[le]=ne)}}for(const j of dt)if(o[j]===void 0){const v=K[j];rt(v)||(o[j]=v)}}else q.forEach(j=>{if(j==="externalRefId")return;const v=K[j];rt(v)||(o[j]=v)});const g=[];if(S){for(const j of S)if(Pe(j))for(const v of j.fields){if(!v.isCustom||!v.paramName||v.customType==="paragraph"||v.customType==="html"||v.customType==="br"||v.customType==="link")continue;const le=de[v.paramName]??"";let ne;if(v.customType==="checkbox"||v.customType==="link_checkbox")ne=le==="true"?"yes":"no";else if(ne=le,!ne&&!v.required)continue;g.push({paramName:v.paramName,value:ne})}}for(const[j,v]of Object.entries(V))o[j]===void 0&&!rt(v)&&(o[j]=v);const L=new Set(g.map(j=>j.paramName));for(const[j,v]of Object.entries(ce))!L.has(j)&&v&&g.push({paramName:j,value:v});g.length>0&&(o.applicantAdditionalDatas=g);const f=await d(o);a(f.applicantId)}catch(o){console.error("Error creating applicant:",o),R(o.message||"Failed to create applicant")}finally{me(!1)}},tt=async o=>{var g;o.preventDefault();for(const L of O)if(rt(K[L])){const f=((g=Ge[L])==null?void 0:g.label)||L;R(`${f} is required.`);return}await $e()},Ke=(o,g,L,f,j)=>{var jt;const v=Ge[o];if(!v)return null;const le=O.includes(o),ne=$[o],xe=L||v.label,Ie=o in ae,ie=g??o,Le={required:le},Be=j?j!=="placeholder":b,qe=Be?xe:void 0,Yr=Be?"...":xe;switch(v.type){case"select":if(o==="country"||o==="nationality"||o==="taxCountry"||o==="countryOfBirth"||o==="mobileCountryCode"){const Ne=Y(o,f);return e.jsx(ze,{...Le,label:qe,value:K[o]||"",onChange:Xe=>se(o,Xe),options:[{value:"",label:`Select ${Yr.toLowerCase()}`},...Ne],disabled:N,readOnly:Ie,error:ne},ie)}if(o==="salutation")return e.jsx(ze,{...Le,label:qe,value:((jt=K[o])==null?void 0:jt.toString())||"",onChange:Ne=>se(o,Ne?Number(Ne):null),options:[{value:"",label:Be?"Select salutation...":xe},{value:lt.Male.toString(),label:"Male"},{value:lt.Female.toString(),label:"Female"},{value:lt.Other.toString(),label:"Other"}],readOnly:Ie,error:ne},ie);if(o==="defaultLanguage"){const Ne=c!=null&&c.allowedLanguages&&c.allowedLanguages.length>0?ht.filter(Xe=>c.allowedLanguages.includes(Xe.value)):ht;return e.jsx(ze,{...Le,label:qe,value:K[o]||"",onChange:Xe=>se(o,Xe),options:[{value:"",label:Be?"Select language...":xe},...Ne],readOnly:Ie,error:ne},ie)}return null;case"multiselect":if(o==="otherNationality"){const Ne=Y(o,f);return e.jsx(Fr,{...Le,label:qe,value:K[o]||[],onChange:Xe=>se(o,Xe),options:Ne,placeholder:Be?"Select other nationalities...":xe,disabled:N,readOnly:Ie},ie)}return null;case"date":return e.jsx(ye,{...Le,type:"date",label:qe,placeholder:Be?void 0:xe,value:K[o]||"",onChange:Ne=>se(o,Ne.target.value),readOnly:Ie,error:ne},ie);case"email":return e.jsx(ye,{...Le,type:"email",label:qe,placeholder:Be?void 0:xe,value:K[o]||"",onChange:Ne=>se(o,Ne.target.value),readOnly:Ie,error:ne},ie);case"tel":return e.jsx(ye,{...Le,type:"tel",label:qe,placeholder:Be?void 0:xe,value:K[o]||"",onChange:Ne=>se(o,Ne.target.value),readOnly:Ie,error:ne},ie);default:return e.jsx(ye,{...Le,type:"text",label:qe,placeholder:Be?void 0:xe,value:K[o]||"",onChange:Ne=>se(o,Ne.target.value),readOnly:Ie,error:ne},ie)}},x=(o,g)=>{const L=o.labelMode?o.labelMode!=="placeholder":b;if(o.customType==="paragraph"){const v=o.displayText||o.label||"";return e.jsx("p",{className:"metakyc-paragraph",style:{fontSize:"14px",lineHeight:"1.7",margin:0,color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:v}},`custom-${g}`)}if(o.customType==="html")return e.jsx("div",{dangerouslySetInnerHTML:{__html:o.label||""}},`custom-${g}`);if(o.customType==="br")return e.jsx("div",{style:{height:"12px"}},`custom-${g}`);if(o.customType==="link"){const v=o.displayText||o.label||o.linkText||o.linkUrl||"";return e.jsx("div",{className:"metakyc-link-field",children:e.jsxs("a",{href:o.linkUrl||"#",target:"_blank",rel:"noopener noreferrer",style:{display:"inline-flex",alignItems:"center",gap:"4px",color:"var(--metakyc-primary, #2563eb)",fontSize:"14px",textDecoration:"underline",cursor:"pointer"},children:[v,e.jsx("span",{style:{fontSize:"10px",opacity:.7},children:"↗"})]})},`custom-${g}`)}if(!o.paramName)return null;const f=$[o.paramName],j=o.displayText||o.label||o.paramName;if(o.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(Fe,{checked:de[o.paramName]==="true",onChange:v=>be(o.paramName,v?"true":"false")}),e.jsxs("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:[j,o.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),f&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:f})]},`custom-${g}`);if(o.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(Fe,{checked:de[o.paramName]==="true",onChange:v=>be(o.paramName,v?"true":"false")}),e.jsxs("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:[j," ",o.linkUrl&&e.jsx("a",{href:o.linkUrl,target:"_blank",rel:"noopener noreferrer",className:"underline",style:{color:"var(--metakyc-primary, #2563eb)"},onClick:v=>v.stopPropagation(),children:o.linkText||o.linkUrl}),o.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),f&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:f})]},`custom-${g}`);if(o.customType==="group_checkbox"){const v=(de[o.paramName]||"").split(",").filter(Boolean);return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[L&&e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[j,o.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:(o.options||[]).map(le=>{const ne=o.singleSelect?de[o.paramName]===le.value:v.includes(le.value);return e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx(Fe,{checked:ne,onChange:xe=>{if(o.singleSelect)be(o.paramName,xe?le.value:"");else{const Ie=xe?[...v,le.value]:v.filter(ie=>ie!==le.value);be(o.paramName,Ie.join(","))}}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:le.label})]},le.value)})}),f&&e.jsx("p",{className:"text-red-500 text-xs",children:f})]},`custom-${g}`)}return o.customType==="radio_group"?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[L&&e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[j,o.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:(o.options||[]).map(v=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"radio",checked:de[o.paramName]===v.value,onChange:()=>be(o.paramName,v.value),name:`radio-group-${o.paramName}-${g}`,className:"metakyc-option-input",style:Da}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:v.label})]},v.value))}),f&&e.jsx("p",{className:"text-red-500 text-xs",children:f})]},`custom-${g}`):e.jsx(ye,{type:"text",label:L?`${j}${o.required?" *":""}`:void 0,placeholder:L?void 0:j,value:de[o.paramName]||"",onChange:v=>be(o.paramName,v.target.value),required:o.required,error:f},`custom-${g}`)},M=(o,g)=>{const L=Pe(o);return e.jsxs("div",{className:"space-y-4",children:[o.conditionalOn&&e.jsx(Tt,{helpText:o.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(Fe,{checked:L,onChange:f=>be(o.conditionalOn,f?"true":"false")}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",fontWeight:500},children:o.conditionalOn})]})}),L&&e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:o.fields.map((f,j)=>{const v=Math.min(4,Math.max(1,Number(f.colSpan)||4)),le=f.isCustom?`custom-${j}-${f.paramName}`:`builtin-${f.name}-${j}`;return e.jsx("div",{style:{gridColumn:`span ${v} / span ${v}`},children:e.jsx(Tt,{helpText:f.helpText,children:f.isCustom?x(f,j):Ke(f.name,le,f.displayText,f.countriesType,f.labelMode)})},le)})})]})};if(!c||N)return e.jsx("div",{className:"metakyc-sdk",children:e.jsx(Z,{children:e.jsxs(ee,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)",fontSize:"0.875rem"},children:"Loading form…"})]})})});if(S){const o=S[E]??S[0],g=Oe===-1,L=ve===-1,f=S.length,j=Pe(o),v=Object.values($);return e.jsx("div",{className:"metakyc-sdk",children:e.jsxs(Z,{children:[e.jsx(he,{children:e.jsx(nt,{title:(c==null?void 0:c.title)||"Create Applicant"})}),e.jsxs(ee,{children:[(o.title||o.subtitle||o.description)&&e.jsxs("div",{className:"mb-4",children:[o.title&&e.jsx("h3",{className:"font-semibold text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:o.title}),o.subtitle&&e.jsx("p",{className:"text-sm mt-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:o.subtitle}),o.description&&o.description!==o.subtitle&&e.jsx("p",{className:"text-xs mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:o.description})]}),(ue||v.length>0)&&e.jsxs("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-lg",children:[ue&&e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",ue]}),v.map((le,ne)=>e.jsx("p",{className:"text-red-600 text-sm",children:le},ne))]}),f>1&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem",marginBottom:"1rem"},children:[S.map((le,ne)=>e.jsx("div",{style:{height:"0.375rem",borderRadius:"9999px",transition:"all 150ms",...ne===E?{flex:"1 1 0%",backgroundColor:"var(--metakyc-primary, #2563eb)"}:ne<E?{width:"2rem",backgroundColor:"var(--metakyc-primary-light, #93c5fd)",opacity:.7}:{width:"2rem",backgroundColor:"#e5e7eb"}}},ne)),e.jsxs("span",{style:{fontSize:"0.75rem",color:"var(--metakyc-text-muted, #9ca3af)",flexShrink:0},children:[E+1," / ",f]})]}),M(o)]}),e.jsxs(fe,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{children:[!g&&e.jsx(Q,{type:"button",variant:"outline",onClick:()=>{W(Oe),_({})},disabled:te||y,children:"Previous"}),g&&s&&e.jsx(Q,{type:"button",variant:"outline",onClick:s,disabled:te||y,children:"Cancel"})]}),e.jsx(Q,{type:"button",isLoading:te||y,onClick:L?$e:Je,children:L?o.conditionalOn&&!j?"Skip & Submit":"Submit":o.conditionalOn&&!j?"Skip":"Next"})]})]})})}return e.jsx("div",{className:"metakyc-sdk",children:e.jsx("form",{onSubmit:tt,children:e.jsxs(Z,{children:[e.jsx(he,{children:e.jsx(nt,{title:(c==null?void 0:c.title)||"Create Applicant"})}),e.jsxs(ee,{children:[ue&&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:"})," ",ue]})}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:q.map(o=>e.jsx("div",{style:{gridColumn:"span 4 / span 4"},children:Ke(o)},o))})]}),e.jsxs(fe,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s&&e.jsx(Q,{type:"button",variant:"outline",onClick:s,disabled:te||y,children:"Cancel"}),e.jsx(Q,{type:"submit",isLoading:te||y,children:"Create Applicant"})]})]})})})},Ft=["companyName","email"];function gt(t){return t==null||t===""||Array.isArray(t)&&t.length===0}const za=({workflowKey:t,externalRefId:r,onSuccess:a,onCancel:s})=>{var Ke,x,M,U,H,J;const{config:n,baseInformationService:l,currentTheme:c}=Re(),{createCompanyApplicant:d,isLoading:y}=vt(),p=t||((Ke=n.applicantForm)==null?void 0:Ke.workflowKey);if(!p)throw new Error("workflowKey is required. Provide it either as a prop to CreateCompanyApplicantForm or set it in config.applicantForm.workflowKey");const k=r||((x=n.applicantForm)==null?void 0:x.externalRefId)||"",I=((M=n.applicantForm)==null?void 0:M.email)||"",w=((U=n.applicantForm)==null?void 0:U.initialValues)||{},T=(((H=n.applicantForm)==null?void 0:H.fieldLabelMode)||(c==null?void 0:c.fieldLabelMode)||"label")!=="placeholder",b=i.useMemo(()=>c!=null&&c.companyFormPages&&c.companyFormPages.length>0?c.companyFormPages:null,[c==null?void 0:c.companyFormPages]),S=i.useMemo(()=>{const u=new Set(Ft),C=c==null?void 0:c.companyFormRequiredFields;if(C)for(const P of C)u.add(P);if(b)for(const P of b)for(const m of P.fields)!m.isCustom&&m.name&&m.required&&u.add(m.name);return Array.from(u)},[c==null?void 0:c.companyFormRequiredFields,b]),O=i.useMemo(()=>{var u;if(b){const C=b.flatMap(m=>m.fields).filter(m=>!m.isCustom&&m.name).map(m=>m.name),P=new Set(C);for(const m of Ft)P.add(m);return Array.from(P)}return(u=n.applicantForm)!=null&&u.visibleFields?n.applicantForm.visibleFields:c!=null&&c.companyFormVisibleFields&&c.companyFormVisibleFields.length>0?c.companyFormVisibleFields:Ut},[(J=n.applicantForm)==null?void 0:J.visibleFields,c==null?void 0:c.companyFormVisibleFields,b]),q=new Set(["countryResidence","addressCountry"]),F=i.useMemo(()=>{var C,P;const u=new Set;if(b)for(const m of b)for(const o of m.fields)!o.isCustom&&o.name&&q.has(o.name)&&u.add(o.countriesType??((C=Ze[o.name])==null?void 0:C.countriesType));else for(const m of O)q.has(m)&&u.add((P=Ze[m])==null?void 0:P.countriesType);return u.size===0&&u.add(void 0),Array.from(u)},[O,b]),[D,X]=i.useState({}),[re,N]=i.useState(!0),h=i.useRef(new Set),z=i.useRef(new Set);i.useEffect(()=>{if(!c)return;const u=F.filter(m=>{const o=m!=null?String(m):"all";return!z.current.has(o)&&!h.current.has(o)});if(u.length===0){F.every(o=>z.current.has(o!=null?String(o):"all"))&&N(!1);return}N(!0);const C=u.map(m=>m!=null?String(m):"all");C.forEach(m=>h.current.add(m)),(async()=>{try{const m=await Promise.all(u.map(async o=>{const g=o!=null?String(o):"all",L=await l.getCountries("",n.locale||"en",o),f=new Set,j=L.map(v=>({value:v.abbreviation3||v.abbreviation,label:v.name})).filter(v=>!v.value||f.has(v.value)?!1:(f.add(v.value),!0));return z.current.add(g),h.current.delete(g),[g,j]}));X(o=>({...o,...Object.fromEntries(m)}))}catch(m){C.forEach(o=>h.current.delete(o)),console.error("Failed to load countries:",m)}finally{F.every(o=>z.current.has(o!=null?String(o):"all"))&&N(!1)}})()},[F,c]);const G=(u,C)=>{var o;const P=C??((o=Ze[u])==null?void 0:o.countriesType),m=P!=null?String(P):"all";return D[m]||[]},Y={companyName:1,registrationNumber:1,email:1,phone:1,countryResidence:1,legalAddress:1,incorporatedOn:1,controlScheme:1,taxId:1,registrationLocation:1,website:1,postalAddress:1,street:1,streetNumber:1,city:1,state:1,postalCode:1,addressCountry:1,lei:1},B=Object.fromEntries(Object.entries(w).filter(([u])=>u in Y)),[V,ae]=i.useState({workflowKey:p,companyName:"",email:I,phone:"",registrationNumber:"",countryResidence:"",legalAddress:"",incorporatedOn:"",controlScheme:"",taxId:"",registrationLocation:"",website:"",postalAddress:"",street:"",streetNumber:"",city:"",state:"",postalCode:"",addressCountry:"",lei:"",externalRefId:k,...B}),[K,ke]=i.useState({}),[ce,de]=i.useState(0),[ge,E]=i.useState({}),[W,$]=i.useState(null),[_,ue]=i.useState(!1),R=(u,C)=>ae(P=>({...P,[u]:C})),te=(u,C)=>ke(P=>({...P,[u]:C})),me=u=>!u.conditionalOn||K[u.conditionalOn]==="true",se=b&&ce<b.length-1?ce+1:-1,be=b&&ce>0?ce-1:-1,Pe=u=>{var P;const C={};for(const m of u.fields)if(m.isCustom){if(m.customType==="paragraph"||m.customType==="html"||m.customType==="br"||m.customType==="link")continue;if(m.required&&m.paramName){const o=K[m.paramName],g=m.displayText||m.label||m.paramName;m.customType==="checkbox"||m.customType==="link_checkbox"?o!=="true"&&(C[m.paramName]=`${g} is required.`):(!o||o.trim()==="")&&(C[m.paramName]=`${g} is required.`)}}else if(m.name){const o=m.name;if(S.includes(o)&>(V[o])){const g=m.displayText||((P=Ze[o])==null?void 0:P.label)||o;C[o]=`${g} is required.`}}return C},ve=async()=>{if(!b)return;const u=b[ce];if(u.conditionalOn&&!me(u)){E({}),se>=0?de(se):await Oe();return}const C=Pe(u);if(Object.keys(C).length>0){E(C);return}E({}),se>=0?de(se):await Oe()},Oe=async()=>{var u;if(b){let C={};for(const P of b)me(P)&&(C={...C,...Pe(P)});if(Object.keys(C).length>0){E(C);return}}ue(!0),$(null);try{const C={workflowKey:V.workflowKey,externalRefId:((u=V.externalRefId)==null?void 0:u.trim())||void 0},P=b?b.filter(g=>me(g)).flatMap(g=>g.fields).filter(g=>!g.isCustom&&g.name).map(g=>g.name):O;for(const g of P){const L=V[g];if(!gt(L))switch(g){case"companyName":C.companyName=L;break;case"email":C.companyEmail=L;break;case"phone":C.companyPhone=L;break;case"registrationNumber":C.companyRegistrationNumber=L;break;case"countryResidence":C.companyCountry=L;break;case"city":C.companyCity=L;break;case"street":C.companyStreet=L;break;case"postalCode":C.companyZip=L;break;default:C[g]=L;break}}const m=[];if(b){for(const g of b)if(me(g))for(const L of g.fields){if(!L.isCustom||!L.paramName||L.customType==="paragraph"||L.customType==="html"||L.customType==="br"||L.customType==="link")continue;const f=K[L.paramName]??"";let j;if(L.customType==="checkbox"||L.customType==="link_checkbox")j=f==="true"?"yes":"no";else if(j=f,!j&&!L.required)continue;m.push({paramName:L.paramName,value:j})}}m.length>0&&(C.applicantAdditionalDatas=m);const o=await d(C);a(o.applicantId)}catch(C){console.error("Error creating company applicant:",C),$(C.message||"Failed to create company applicant")}finally{ue(!1)}},et=async u=>{var C;u.preventDefault();for(const P of S)if(gt(V[P])){const m=((C=Ze[P])==null?void 0:C.label)||P;$(`${m} is required.`);return}await Oe()},Je=(u,C,P,m,o)=>{const g=Ze[u];if(!g)return null;const L=S.includes(u),f=ge[u],j=P||g.label,v=u in B,le=C??u,ne=o?o!=="placeholder":T,xe=ne?j:void 0,Ie=ne?"...":j;switch(g.type){case"select":if(u==="countryResidence"||u==="addressCountry"){const ie=G(u,m);return e.jsx(ze,{required:L,label:xe,value:V[u]||"",onChange:Le=>R(u,Le),options:[{value:"",label:`Select ${Ie.toLowerCase()}`},...ie],disabled:re,readOnly:v,error:f},le)}return null;case"date":return e.jsx(ye,{required:L,type:"date",label:xe,placeholder:ne?void 0:j,value:V[u]||"",onChange:ie=>R(u,ie.target.value),readOnly:v,error:f},le);case"email":return e.jsx(ye,{required:L,type:"email",label:xe,placeholder:ne?void 0:j,value:V[u]||"",onChange:ie=>R(u,ie.target.value),readOnly:v,error:f},le);case"tel":return e.jsx(ye,{required:L,type:"tel",label:xe,placeholder:ne?void 0:j,value:V[u]||"",onChange:ie=>R(u,ie.target.value),readOnly:v,error:f},le);default:return e.jsx(ye,{required:L,type:"text",label:xe,placeholder:ne?void 0:j,value:V[u]||"",onChange:ie=>R(u,ie.target.value),readOnly:v,error:f},le)}},$e=(u,C)=>{if(u.customType==="paragraph")return e.jsx("p",{style:{fontSize:"14px",lineHeight:"1.7",margin:0,color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:u.displayText||u.label||""}},`custom-${C}`);if(u.customType==="html")return e.jsx("div",{dangerouslySetInnerHTML:{__html:u.label||""}},`custom-${C}`);if(u.customType==="br")return e.jsx("div",{style:{height:"12px"}},`custom-${C}`);if(u.customType==="link")return e.jsx("div",{children:e.jsx("a",{href:u.linkUrl||"#",target:"_blank",rel:"noopener noreferrer",style:{color:"var(--metakyc-primary, #2563eb)",fontSize:"14px",textDecoration:"underline"},children:u.displayText||u.label||u.linkText||u.linkUrl||""})},`custom-${C}`);if(!u.paramName)return null;const P=ge[u.paramName],m=u.displayText||u.label||u.paramName,o=u.labelMode?u.labelMode!=="placeholder":T;return u.customType==="checkbox"?e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer"},children:[e.jsx(Fe,{checked:K[u.paramName]==="true",onChange:g=>te(u.paramName,g?"true":"false")}),e.jsxs("span",{style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)"},children:[m,u.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),P&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:P})]},`custom-${C}`):e.jsx(ye,{type:"text",label:o?`${m}${u.required?" *":""}`:void 0,placeholder:o?void 0:m,value:K[u.paramName]||"",onChange:g=>te(u.paramName,g.target.value),required:u.required,error:P},`custom-${C}`)},tt=u=>{const C=me(u);return e.jsxs("div",{className:"space-y-4",children:[u.conditionalOn&&e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer"},children:[e.jsx(Fe,{checked:C,onChange:P=>te(u.conditionalOn,P?"true":"false")}),e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:u.conditionalOn})]}),C&&e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:u.fields.map((P,m)=>{const o=Math.min(4,Math.max(1,Number(P.colSpan)||4)),g=P.isCustom?`custom-${m}-${P.paramName}`:`builtin-${P.name}-${m}`;return e.jsx("div",{style:{gridColumn:`span ${o} / span ${o}`},children:P.isCustom?$e(P,m):Je(P.name,g,P.displayText,P.countriesType,P.labelMode)},g)})})]})};if(!c||re)return e.jsx("div",{className:"metakyc-sdk",children:e.jsx(Z,{children:e.jsxs(ee,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)",fontSize:"0.875rem"},children:"Loading form…"})]})})});if(b){const u=b[ce]??b[0],C=be===-1,P=se===-1,m=b.length,o=me(u),g=Object.values(ge);return e.jsx("div",{className:"metakyc-sdk",children:e.jsxs(Z,{children:[e.jsx(he,{children:e.jsx(nt,{title:(c==null?void 0:c.title)||"Company Registration"})}),e.jsxs(ee,{children:[(u.title||u.subtitle)&&e.jsxs("div",{className:"mb-4",children:[u.title&&e.jsx("h3",{className:"font-semibold text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:u.title}),u.subtitle&&e.jsx("p",{className:"text-sm mt-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:u.subtitle})]}),(W||g.length>0)&&e.jsxs("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-lg",children:[W&&e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",W]}),g.map((L,f)=>e.jsx("p",{className:"text-red-600 text-sm",children:L},f))]}),m>1&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem",marginBottom:"1rem"},children:[b.map((L,f)=>e.jsx("div",{style:{height:"0.375rem",borderRadius:"9999px",transition:"all 150ms",...f===ce?{flex:"1 1 0%",backgroundColor:"var(--metakyc-primary, #2563eb)"}:f<ce?{width:"2rem",backgroundColor:"var(--metakyc-primary-light, #93c5fd)",opacity:.7}:{width:"2rem",backgroundColor:"#e5e7eb"}}},f)),e.jsxs("span",{style:{fontSize:"0.75rem",color:"var(--metakyc-text-muted, #9ca3af)",flexShrink:0},children:[ce+1," / ",m]})]}),tt(u)]}),e.jsxs(fe,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{children:[!C&&e.jsx(Q,{type:"button",variant:"outline",onClick:()=>{de(be),E({})},disabled:_||y,children:"Previous"}),C&&s&&e.jsx(Q,{type:"button",variant:"outline",onClick:s,disabled:_||y,children:"Cancel"})]}),e.jsx(Q,{type:"button",isLoading:_||y,onClick:P?Oe:ve,children:P?u.conditionalOn&&!o?"Skip & Submit":"Submit":u.conditionalOn&&!o?"Skip":"Next"})]})]})})}return e.jsx("div",{className:"metakyc-sdk",children:e.jsx("form",{onSubmit:et,children:e.jsxs(Z,{children:[e.jsx(he,{children:e.jsx(nt,{title:(c==null?void 0:c.title)||"Company Registration"})}),e.jsxs(ee,{children:[W&&e.jsx("div",{className:"mb-6 p-4 bg-red-50 border border-red-200 rounded-lg",children:e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",W]})}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:O.map(u=>e.jsx("div",{style:{gridColumn:"span 4 / span 4"},children:Je(u)},u))})]}),e.jsxs(fe,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s&&e.jsx(Q,{type:"button",variant:"outline",onClick:s,disabled:_||y,children:"Cancel"}),e.jsx(Q,{type:"submit",isLoading:_||y,children:"Register Company"})]})]})})})},Oa=({applicantId:t,onComplete:r,onError:a,className:s})=>{const{progress:n,currentStep:l,steps:c,workflowKey:d,nextWorkflowKey:y,hasWorkflowChanged:p,isLoading:k,error:I,moveBack:w,refreshProgress:A}=Nr(t),[T,b]=i.useState(!1),S=i.useRef(null);if(i.useEffect(()=>{I&&a&&a(I)},[I,a]),i.useEffect(()=>{n!=null&&n.workflowResult&&r&&r(n.workflowResult)},[n==null?void 0:n.workflowResult,r]),i.useEffect(()=>{p&&b(!1)},[p]),k||!n)return e.jsx("div",{className:`metakyc-sdk ${s||""}`,children:e.jsx(Z,{children:e.jsxs(ee,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Loading workflow..."})]})})});if(I)return e.jsx("div",{className:`metakyc-sdk ${s||""}`,children:e.jsx(Z,{children:e.jsx(ee,{children:e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-lg mb-4",style:{color:"var(--metakyc-danger, #ef4444)"},children:"An error occurred"}),e.jsx("p",{style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:I.message})]})})})});if(p&&!T)return e.jsx("div",{className:`metakyc-sdk ${s||""}`,children:e.jsx(Z,{children:e.jsx(ee,{children:e.jsxs("div",{className:"text-center py-8",children:[e.jsx("div",{className:"mb-6",children:e.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-full mb-4",style:{backgroundColor:"var(--metakyc-primary-light, #dbeafe)"},children:e.jsx("svg",{className:"w-8 h-8",style:{color:"var(--metakyc-primary, #2563eb)"},fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})})}),e.jsx("h3",{className:"text-xl font-semibold mb-2",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Workflow Transition"}),e.jsx("p",{className:"mb-6",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Your application workflow has been updated based on your progress."}),e.jsxs("div",{className:"rounded-lg p-4 mb-6 max-w-md mx-auto",style:{backgroundColor:"var(--metakyc-surface, #f9fafb)"},children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"mb-1",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"Previous Workflow"}),e.jsx("p",{className:"font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:d})]}),e.jsx("svg",{className:"w-6 h-6 mx-4",style:{color:"var(--metakyc-text-muted, #9ca3af)"},fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 7l5 5m0 0l-5 5m5-5H6"})}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"mb-1",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"New Workflow"}),e.jsx("p",{className:"font-medium",style:{color:"var(--metakyc-primary, #2563eb)"},children:y})]})]}),n.nextWorkflowName&&e.jsx("p",{className:"text-center mt-2 text-xs",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:n.nextWorkflowName})]}),e.jsx("button",{onClick:()=>b(!0),className:"px-6 py-3 font-medium rounded-lg transition-opacity hover:opacity-90",style:{backgroundColor:"var(--metakyc-primary, #2563eb)",color:"#ffffff"},children:"Continue with New Workflow"})]})})})});if(n.status===Te.Finished||n.status===Te.OnHold)return e.jsx("div",{className:`metakyc-sdk ${s||""}`,children:e.jsx(ft,{kycStatus:n.kycStatus,reviewStatus:n.reviewStatus,workflowResult:n.workflowResult,customMessage:n.customMessage,onContinue:r&&n.workflowResult?()=>r(n.workflowResult):void 0,onContactSupport:()=>{typeof window<"u"&&(window.location.href="mailto:support@example.com")}})});if(!l)return e.jsx("div",{className:`metakyc-sdk ${s||""}`,children:e.jsx(Z,{children:e.jsxs(ee,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:n.status===Te.IdentityPending?"Loading identity verification...":"Loading current step..."})]})})});const O=D=>{switch(D){case oe.Overview:return"Overview";case oe.Questionaries:return"Questionnaire";case oe.UploadDocument:return"Documents";case oe.IdentitySdk:return"Identity";case oe.RiskScoring:return"Risk Assessment";case oe.InvestorCategorization:return"Investor Categorization";case oe.AppropriatenessTest:return"Appropriateness Test";case oe.AdditionalData:return"Additional Data";case oe.ManualReview:return"Review";default:return""}},q=()=>{const D=c.filter(z=>z.visibility!==!1),X=D.findIndex(z=>z.order===l.order),re=X>=0?X+1:1,N=D.length,h=N>1?X/(N-1)*100:100;return e.jsxs("div",{style:{marginBottom:"24px",backgroundColor:"var(--metakyc-surface, var(--metakyc-background, #ffffff))",borderRadius:"0.75rem",border:"1px solid var(--metakyc-border, #e5e7eb)",padding:"1rem 1.5rem",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",marginBottom:"16px"},children:[e.jsx(nt,{}),e.jsxs(wt,{variant:n.status===1?"info":"success",children:["Step ",re," of ",N]})]}),e.jsx("div",{style:{marginBottom:"16px"},children:e.jsx("div",{style:{height:"4px",borderRadius:"999px",backgroundColor:"var(--metakyc-border, #e5e7eb)",overflow:"hidden"},children:e.jsx("div",{style:{height:"100%",borderRadius:"999px",backgroundColor:"var(--metakyc-primary, #2563eb)",width:`${h}%`,transition:"width 0.4s ease"}})})}),e.jsx($a,{ref:S,visibleSteps:D,currentVisibleStepIndex:X,getStepFallbackName:O})]})},F=()=>{const D={applicantId:t,onComplete:async()=>{await A()},onBack:l.order>0?w:void 0};switch(l.action){case oe.Questionaries:return e.jsx($r,{...D});case oe.UploadDocument:return e.jsx(Br,{...D});case oe.Overview:return e.jsx(_r,{...D});case oe.IdentitySdk:return e.jsx(Kr,{...D});case oe.RiskScoring:return e.jsx(Hr,{...D});case oe.AdditionalData:case oe.InvestorCategorization:return e.jsx(Wr,{...D});case oe.AppropriatenessTest:return e.jsx(Ur,{...D});case oe.ManualReview:return e.jsx(ft,{kycStatus:n.kycStatus,reviewStatus:n.reviewStatus,workflowResult:n.workflowResult,customMessage:n.customMessage});default:return e.jsx(Z,{children:e.jsxs(ee,{className:"py-12 text-center",children:[e.jsx("div",{className:"mb-4",children:e.jsx(Ee,{})}),e.jsxs("p",{className:"text-gray-600 dark:text-gray-400 mb-2",children:["Processing step: ",l.title||l.name]}),e.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:["Action type: ",oe[l.action]]})]})})}};return e.jsxs("div",{className:`metakyc-sdk ${s||""}`,children:[q(),F()]})},$a=i.forwardRef(({visibleSteps:t,currentVisibleStepIndex:r,getStepFallbackName:a},s)=>{const n=i.useRef(null),l=i.useRef(null);return i.useImperativeHandle(s,()=>n.current),i.useEffect(()=>{if(l.current&&n.current){const c=n.current,d=l.current,y=d.offsetLeft-c.offsetWidth/2+d.offsetWidth/2;c.scrollTo({left:Math.max(0,y),behavior:"smooth"})}},[r]),e.jsx("div",{ref:n,className:"metakyc-stepper-scroll",style:{display:"flex",alignItems:"center",width:"100%",overflowX:"auto",overflowY:"hidden",scrollbarWidth:"none",msOverflowStyle:"none",WebkitOverflowScrolling:"touch",padding:"4px 0",gap:"0"},children:t.map((c,d)=>{const y=d<r,p=d===r,k=y||p,I=c.displayName||c.name||a(c.action)||`Step ${d+1}`;return e.jsxs(i.Fragment,{children:[e.jsxs("div",{ref:p?l:void 0,style:{display:"flex",alignItems:"center",flexShrink:0},children:[e.jsx("div",{style:{width:"28px",height:"28px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"12px",fontWeight:600,flexShrink:0,transition:"all 0.2s ease",...k?{backgroundColor:"var(--metakyc-primary, #2563eb)",color:"#ffffff",border:"none"}:{backgroundColor:"transparent",color:"var(--metakyc-text-muted, #9ca3af)",border:"2px solid var(--metakyc-border, #e5e7eb)"}},children:y?e.jsx("svg",{width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:2.5,viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}):d+1}),e.jsx("span",{style:{marginLeft:"6px",fontSize:"13px",whiteSpace:"nowrap",fontWeight:p?600:400,color:p?"var(--metakyc-text-primary, #111827)":y?"var(--metakyc-primary, #2563eb)":"var(--metakyc-text-muted, #9ca3af)",transition:"color 0.2s ease"},children:I})]}),d<t.length-1&&e.jsx("div",{style:{flex:"1 1 0%",minWidth:"16px",height:"2px",margin:"0 8px",borderRadius:"999px",backgroundColor:"var(--metakyc-primary, #2563eb)",opacity:y?1:.25,transition:"opacity 0.2s ease"}})]},c.order)})})});function Ba(t){return Ue.z.object({questionResults:Ue.z.any()}).passthrough()}function _a(t){let r=Ue.z.array(Ue.z.instanceof(File));if(t.isRequired?r=r.min(1,`${t.displayName} is required`):r=r.optional(),t.multipleFile||(r=r.refine(a=>!a||a.length<=1,{message:"Only one file is allowed"})),t.maxEachFileSizeByte>0&&(r=r.refine(a=>!a||a.every(s=>s.size<=t.maxEachFileSizeByte),{message:`File size must not exceed ${Math.round(t.maxEachFileSizeByte/1024/1024)}MB`})),t.allowedTypes){const a=t.allowedTypes.split(",").map(s=>s.trim());r=r.refine(s=>s?s.every(n=>a.some(l=>l.endsWith("/*")?n.type.startsWith(l.slice(0,-2)):n.type===l)):!0,{message:"Invalid file type"})}return r}function Ha(t){const r={};return t.uploadDocumentFiles.forEach(a=>{const s=`file_${a.id}`;r[s]=_a(a)}),Ue.z.object(r)}function Wa(t){return Ue.z.any()}function Ua(t){return Ue.z.string().min(1,"This question is required")}function Ka(t){const r={};return t.appropriatenessQuestions.forEach(a=>{const s=`question_${a.id}`;r[s]=Ua()}),Ue.z.object(r)}const qa=Ue.z.any();exports.ALLOWED_LANGUAGES=ht;exports.ApplicantProgressOnHoldReason=Pt;exports.ApplicantProgressStatus=Te;exports.ApplicantService=Qt;exports.ApplicantStatus=Dt;exports.AppropriatenessQuestionType=Bt;exports.AppropriatenessTestService=Xt;exports.AppropriatenessTestStep=Ur;exports.Badge=wt;exports.BaseInformationService=rr;exports.Button=Q;exports.COMPANY_FIELD_METADATA=Ze;exports.Card=Z;exports.CardContent=ee;exports.CardFooter=fe;exports.CardHeader=he;exports.Checkbox=Fe;exports.CountriesType=We;exports.CreateApplicantForm=Ma;exports.CreateCompanyApplicantForm=za;exports.CriteriaBuiltInType=Ht;exports.DEFAULT_COMPANY_VISIBLE_FIELDS=Ut;exports.DEFAULT_VISIBLE_FIELDS=Kt;exports.DocumentReviewStatus=$t;exports.EndpointBuilder=Yt;exports.ErrorHandler=at;exports.EventEmitter=mr;exports.FIELD_METADATA=Ge;exports.FileType=Ot;exports.FileUpload=Pr;exports.GenderType=lt;exports.Header=nt;exports.HttpClient=Vt;exports.IdentityProviderManager=He;exports.IdentityService=tr;exports.IdentityVerificationProvider=Ae;exports.IdentityVerificationStep=Kr;exports.Input=ye;exports.InvestorCategorizationService=ar;exports.InvestorCategorizationStep=Wr;exports.InvestorCategorizationType=we;exports.InvestorCategoryType=Wt;exports.KycProcessStatus=Mt;exports.KycStatus=Ve;exports.KycStatusDisplay=ft;exports.KycWorkflow=Oa;exports.Logo=qr;exports.MetaKYCContext=bt;exports.MetaKYCError=De;exports.MetaKYCProvider=sa;exports.MultiSelect=Fr;exports.OnfidoProvider=gr;exports.OverviewService=Zt;exports.OverviewStep=_r;exports.PhoneInput=Lr;exports.QuestionnaireService=Gt;exports.QuestionnaireStep=$r;exports.ReviewStatus=Qe;exports.RiskCriteriaType=_t;exports.RiskLevel=Lt;exports.RiskScoringService=er;exports.RiskScoringStep=Hr;exports.SDK_VERSION=kr;exports.SardinAIProvider=hr;exports.SearchableSelect=ze;exports.Select=ut;exports.Spinner=Ee;exports.StepRouter=ur;exports.SumsubProvider=xr;exports.ThemeManager=fr;exports.ThemePreset=Se;exports.ThemeService=dr;exports.UploadDocumentService=Jt;exports.UploadDocumentStep=Br;exports.UserType=zt;exports.ValueDataType=Me;exports.WorkflowOrchestrator=yr;exports.WorkflowResultType=ot;exports.WorkflowState=pr;exports.WorkflowStepAction=oe;exports.appropriatenessTestSchema=qa;exports.clearAllStorage=ca;exports.clearApplicantId=jr;exports.clearWorkflowState=Cr;exports.cn=Ce;exports.corporateTheme=sr;exports.defaultConfig=qt;exports.defaultTheme=je;exports.fileToBase64=br;exports.fintechTheme=nr;exports.formatFileSize=mt;exports.generateAppropriatenessSchema=Ka;exports.generateQuestionnaireSchema=Ba;exports.generateRiskScoringSchema=Wa;exports.generateUploadDocumentSchema=Ha;exports.getAcceptString=oa;exports.getApplicantId=wr;exports.getThemePreset=st;exports.getWorkflowState=la;exports.healthcareTheme=ir;exports.isScriptLoaded=Xr;exports.loadScript=kt;exports.minimalTheme=lr;exports.modernTheme=or;exports.removeScript=Zr;exports.saveApplicantId=vr;exports.saveWorkflowState=Sr;exports.themePresets=cr;exports.useApplicant=vt;exports.useAppropriatenessTest=da;exports.useIdentityVerification=Ar;exports.useKycWorkflow=Nr;exports.useMetaKYC=Re;exports.useOverview=Er;exports.useQuestionnaire=Rr;exports.useRiskScoring=Tr;exports.useUploadDocument=Ir;exports.validateFileSize=na;exports.validateFileType=ia;
|
|
124
|
+
*/const va=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],Or=Mr("chevron-right",va);function wa(t,r){const a=!r||r.length===0||r.every(s=>!s||!s.trim());if(t.isRequired&&a)return t.errorMessage||"This field is required";if(!a){const s=r[0]??"";if(s&&t.regex)try{if(!new RegExp(t.regex).test(s))return t.errorMessage||"Invalid format"}catch{}if(s!==""){const n=Number(s);if(!isNaN(n)&&s.trim()!==""){if(t.min!==void 0&&t.min!==null&&n<t.min)return`Minimum value is ${t.min}`;if(t.max!==void 0&&t.max!==null&&n>t.max)return`Maximum value is ${t.max}`}else{if(t.min!==void 0&&t.min!==null&&s.length<t.min)return`Minimum length is ${t.min} characters`;if(t.max!==void 0&&t.max!==null&&s.length>t.max)return`Maximum length is ${t.max} characters`}}}return null}function ja(t){const r=t.flatMap((s,n)=>(s.questions??[]).map((l,c)=>({question:l,groupIndex:n,qIdx:c}))),a=new Map;for(const s of r){const n=s.question.pageNumber!=null&&s.question.pageNumber>0?s.question.pageNumber:1;a.has(n)||a.set(n,[]),a.get(n).push(s)}return Array.from(a.entries()).sort(([s],[n])=>s-n).map(([,s])=>s)}const $r=({applicantId:t,onComplete:r,onBack:a})=>{const{questionnaire:s,initialAnswers:n,isLoading:l,isSubmitting:c,error:d,submit:y}=Rr(t),[p,k]=i.useState({}),[I,w]=i.useState({}),[A,T]=i.useState(0);i.useEffect(()=>{n&&Object.keys(n).length>0&&Object.keys(p).length===0&&k(n)},[n]);const b=i.useMemo(()=>s?ja(s.questionGroups):[],[s]),S=A===b.length-1,O=b[A]??[],q=i.useCallback((N,h)=>{k(z=>({...z,[N]:h})),w(z=>{const G={...z};return delete G[N],G})},[]),F=i.useCallback(()=>{const N={};for(const{question:h}of O){const z=wa(h,p[h.id]??[]);z&&(N[h.id]=z)}return w(h=>({...h,...N})),Object.keys(N).length===0},[O,p]),D=()=>{F()&&T(N=>N+1)},X=()=>{A>0?T(N=>N-1):a==null||a()},re=async()=>{if(!(!F()||!s))try{const N=s.questionGroups.flatMap(z=>(z.questions??[]).map(G=>({questionId:G.id,values:p[G.id]??[]}))),h={applicantId:t,questionnarieId:s.id,questionResults:N};await y(h),r==null||r()}catch(N){console.error("Questionnaire submit error:",N)}};return l?e.jsx(Z,{children:e.jsx(ee,{children:e.jsx(Ee,{className:"my-8"})})}):d?e.jsx(Z,{children:e.jsx(ee,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading questionnaire: ",d.message]})})}):s?e.jsxs(Z,{children:[e.jsxs(he,{children:[e.jsx("h2",{className:"text-lg font-bold",children:s.displayName}),s.subtitle&&e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:s.subtitle}),b.length>1&&e.jsxs("div",{className:"flex items-center justify-between mt-3",children:[e.jsxs("span",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:["Page ",A+1," of ",b.length]}),e.jsx("div",{className:"flex items-center gap-1.5",children:b.map((N,h)=>e.jsx("div",{className:"rounded-full transition-all duration-200",style:{height:"6px",width:h===A?"20px":"6px",backgroundColor:h<=A?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},h))})]})]}),e.jsx(ee,{className:"space-y-6",children:O.map(({question:N})=>e.jsx(Sa,{question:N,value:p[N.id]??[],error:I[N.id],onChange:h=>q(N.id,h)},N.id))}),e.jsxs(fe,{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs(Q,{type:"button",variant:"outline",onClick:X,style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(zr,{size:14}),A>0?"Previous":"Back"]}),S?e.jsx(Q,{type:"button",isLoading:c,onClick:re,children:"Continue"}):e.jsxs(Q,{type:"button",onClick:D,style:{display:"flex",alignItems:"center",gap:"4px"},children:["Next",e.jsx(Or,{size:14})]})]}),d&&e.jsx("div",{className:"mx-6 mb-4 p-3 bg-red-50 border border-red-200 rounded",children:e.jsx("p",{className:"text-red-600 text-sm",children:d.message})})]}):null},Sa=({question:t,value:r,error:a,onChange:s})=>{var c;const l=(((c=t.defaultAnswers)==null?void 0:c.length)??0)>0?t.showAsDropdown?t.canMultipleAnswer?"multi-select":"single-select":t.canMultipleAnswer?"checkbox":"radio":"text";return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[t.text,t.isRequired&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),t.subtitle&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:t.subtitle}),t.description&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:t.description}),l==="text"&&e.jsx(ye,{value:r[0]??"",onChange:d=>s([d.target.value]),placeholder:t.subtitle?void 0:"Enter your answer…",error:a,required:t.isRequired}),l==="single-select"&&e.jsx(ut,{value:r[0]??"",onChange:d=>s([d.target.value]),options:(t.defaultAnswers??[]).map(d=>({value:d,label:d})),placeholder:"Select an option…",error:a,required:t.isRequired}),l==="radio"&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultAnswers??[]).map(d=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"radio",checked:r[0]===d,onChange:()=>s([d]),className:"metakyc-option-input",style:{width:"16px",height:"16px",minWidth:"16px",flexShrink:0,flexGrow:0,accentColor:"var(--metakyc-primary, #2563eb)",cursor:"pointer",margin:0,padding:0,display:"inline-block",verticalAlign:"middle"}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:d})]},d)),a&&e.jsx("p",{className:"text-sm text-danger-500",children:a})]}),(l==="checkbox"||l==="multi-select")&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultAnswers??[]).map(d=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx(Fe,{checked:r.includes(d),onChange:y=>{s(y?[...r,d]:r.filter(p=>p!==d))}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:d})]},d)),a&&e.jsx("p",{className:"text-sm text-danger-500",children:a})]}),a&&l==="text"&&null]})};function Ca(t){const r=new Map;for(const a of t){const s=a.pageNumber!=null&&a.pageNumber>0?a.pageNumber:1;r.has(s)||r.set(s,[]),r.get(s).push(a)}return Array.from(r.entries()).sort(([a],[s])=>a-s).map(([,a])=>a)}const Br=({applicantId:t,onComplete:r,onBack:a})=>{const{uploadDocument:s,isLoading:n,isSubmitting:l,error:c,submit:d}=Ir(t),[y,p]=i.useState({}),[k,I]=i.useState(null),[w,A]=i.useState(0),[T,b]=i.useState({}),S=i.useMemo(()=>s?Ca(s.uploadDocumentFiles):[],[s]),O=S[w]??[],q=w===S.length-1,F=S.length,D=i.useCallback(()=>{const h={};for(const z of O)z.isRequired&&(y[z.id]||[]).length===0&&(h[z.id]=`${z.displayName} is required`);return b(h),Object.keys(h).length===0},[O,y]),X=()=>{D()&&(A(h=>h+1),b({}))},re=()=>{w>0?(A(h=>h-1),b({})):a==null||a()},N=async()=>{if(!(!D()||!s)){I(null);try{const h=await Promise.all(s.uploadDocumentFiles.map(async G=>{const Y=y[G.id]||[],B=await Promise.all(Y.map(async V=>({fileName:V.name,fileData:await br(V)})));return{uploadDocumentFileId:G.id,valueList:B}})),z={applicantId:t,uploadDocumentId:s.id,uploadDocumentResults:h};await d(z),r==null||r()}catch(h){I((h==null?void 0:h.message)||"Failed to submit documents. Please try again.")}}};return n?e.jsx(Z,{children:e.jsx(ee,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"48px 0",gap:"16px"},children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)"},children:"Loading document requirements..."})]})})}):c?e.jsx(Z,{children:e.jsx(ee,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"32px 0",gap:"12px",textAlign:"center"},children:[e.jsx("div",{style:{width:"48px",height:"48px",borderRadius:"50%",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 10%, transparent)",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),e.jsx("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]})}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-danger, #ef4444)",fontWeight:500},children:"Error loading document requirements"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-muted, #9ca3af)"},children:c.message})]})})}):s?e.jsxs(Z,{children:[e.jsxs(he,{children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:s.displayName||"Upload Documents"}),s.subtitle&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",marginTop:"4px"},children:s.subtitle}),F>1&&e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginTop:"12px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)"},children:["Page ",w+1," of ",F]}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:S.map((h,z)=>e.jsx("div",{style:{height:"6px",width:z===w?"20px":"6px",borderRadius:"999px",transition:"all 0.2s ease",backgroundColor:z<=w?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},z))})]})]}),s.description&&w===0&&e.jsxs("div",{style:{margin:"0 24px",marginTop:"4px",display:"flex",gap:"10px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-primary, #2563eb) 5%, var(--metakyc-background, #ffffff))",border:"1px solid color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-primary, #2563eb)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:"1px"},children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-secondary, #374151)",margin:0,lineHeight:1.5},children:s.description})]}),e.jsx(ee,{children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"24px"},children:O.map(h=>e.jsx(Pr,{label:h.displayName,subtitle:h.subtitle,accept:h.allowedTypes,multiple:h.multipleFile,maxSize:h.maxEachFileSizeByte,required:h.isRequired,error:T[h.id],value:y[h.id]||[],onChange:z=>{I(null),b(G=>{const Y={...G};return delete Y[h.id],Y}),p(G=>({...G,[h.id]:z}))}},h.id))})}),k&&e.jsxs("div",{style:{margin:"0 24px",padding:"10px 14px",borderRadius:"8px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:k})]}),e.jsx(fe,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[e.jsx(Q,{type:"button",variant:"outline",onClick:re,children:w>0?"Previous":"Back"}),q?e.jsx(Q,{type:"button",isLoading:l,onClick:N,children:l?"Uploading...":"Continue"}):e.jsx(Q,{type:"button",onClick:X,children:"Next"})]})})]}):null},_r=({applicantId:t,onComplete:r,onBack:a})=>{const{overview:s,isLoading:n,isSubmitting:l,error:c,passOverview:d}=Er(t),y=async()=>{await d(),r==null||r()};return n?e.jsx(Z,{children:e.jsx(ee,{children:e.jsx(Ee,{className:"my-8"})})}):c?e.jsx(Z,{children:e.jsx(ee,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading overview: ",c.message]})})}):s?e.jsxs(Z,{children:[e.jsxs(he,{children:[e.jsx("h2",{className:"text-lg font-bold",children:s.title||"Overview"}),s.description&&e.jsx("p",{className:"mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:s.description})]}),e.jsx(ee,{className:"space-y-8",children:s.steps&&s.steps.length>0?s.steps.sort((p,k)=>p.order-k.order).map(p=>e.jsxs("div",{className:"metakyc-overview-step-item flex items-center space-x-3",children:[e.jsx("div",{className:"metakyc-step-icon flex-shrink-0",children:e.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center font-medium text-sm",style:{backgroundColor:"var(--metakyc-primary, #2563eb)",color:"#ffffff"},children:p.order+1})}),e.jsxs("div",{className:"metakyc-step-content",style:{flex:1,border:"none",height:"auto",background:"transparent"},children:[e.jsx("span",{className:"metakyc-step-title text-sm font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:p.title}),p.description&&e.jsx("p",{className:"metakyc-step-description text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:p.description})]})]},p.order)):e.jsx("div",{className:"text-center py-8",children:e.jsx("p",{style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Loading overview data..."})})}),e.jsxs(fe,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[a&&e.jsx(Q,{type:"button",variant:"outline",onClick:a,children:"Back"}),e.jsx(Q,{onClick:y,isLoading:l,children:"Continue"})]})]}):null};function Na(t){const r=(t??"en").toLowerCase().replace("_","-");try{return Intl.NumberFormat.supportedLocalesOf([r]),r}catch{return"en"}}function Ra(t){return t.valueDataType===Me.Money&&Array.isArray(t.defaultValues)&&t.defaultValues.length>0}function Ia(t,r){const a=new Intl.NumberFormat(Na(r),{minimumFractionDigits:0,maximumFractionDigits:2});return t.replace(/([\d]+(?:\.\d+)?)/g,s=>{const n=parseFloat(s);return isNaN(n)?s:a.format(n)})}function Ea(t,r){const a=!r||r.length===0||r.every(s=>!s||!s.trim());if(t.isRequired&&a)return t.errorMessage||`${t.displayName} is required`;if(!a){const s=r[0]??"";if(s&&t.regex)try{if(!new RegExp(t.regex).test(s))return t.errorMessage||"Invalid format"}catch{}const n=t.valueDataType===Me.Integer||t.valueDataType===Me.Money||t.valueDataType===Me.DigitOnly;if(n&&s.trim()!==""){const l=Number(s);if(!isNaN(l)){if(t.min!==void 0&&t.min!==null&&l<t.min)return`Minimum value is ${t.min}`;if(t.max!==void 0&&t.max!==null&&l>t.max)return`Maximum value is ${t.max}`}}else if(!n&&s!==""){if(t.min!==void 0&&t.min!==null&&s.length<t.min)return`Minimum length is ${t.min} characters`;if(t.max!==void 0&&t.max!==null&&s.length>t.max)return`Maximum length is ${t.max} characters`}}return null}function Aa(t){const r=new Map;return t.forEach((a,s)=>{const n=a.pageNumber!=null&&a.pageNumber>0?a.pageNumber:1;r.has(n)||r.set(n,[]),r.get(n).push({criterion:a,idx:s})}),Array.from(r.entries()).sort(([a],[s])=>a-s).map(([,a])=>a)}function Ta(t){return t.builtInType===1?"country":!t.defaultValues||t.defaultValues.length===0?"text":t.multipleValue?"checkbox":"radio"}const Hr=({applicantId:t,onComplete:r,onBack:a})=>{const{config:s}=Re(),n=s.locale??"en",{criteria:l,initialAnswers:c,isLoading:d,isSubmitting:y,error:p,submit:k}=Tr(t),[I,w]=i.useState({}),[A,T]=i.useState({}),[b,S]=i.useState(0),[O,q]=i.useState(!1);i.useEffect(()=>{c&&Object.keys(c).length>0&&Object.keys(I).length===0&&w(c)},[c]);const F=i.useMemo(()=>l&&l.length>0?Aa(l):[],[l]),D=b===F.length-1,X=F[b]??[];i.useEffect(()=>{!d&&l&&l.length===0&&!O&&!y&&(q(!0),k({applicantId:t,criteriaValueInputs:[]}).then(()=>r==null?void 0:r()).catch(console.error))},[d,l,O,y,k,t,r]);const re=i.useCallback((Y,B)=>{w(V=>({...V,[Y]:B})),T(V=>{const ae={...V};return delete ae[Y],ae})},[]),N=i.useCallback(()=>{const Y={};for(const{criterion:B}of X){const V=Ea(B,I[B.id]??[]);V&&(Y[B.id]=V)}return T(B=>({...B,...Y})),Object.keys(Y).length===0},[X,I]),h=()=>{N()&&S(Y=>Y+1)},z=()=>{b>0?S(Y=>Y-1):a==null||a()},G=async()=>{if(!(!N()||!l))try{const Y=l.map(V=>{const ae=(I[V.id]??[]).filter(K=>K&&K.trim());return ae.length>0?{riskCriteriaId:V.id,values:ae}:null}).filter(V=>V!==null);await k({applicantId:t,criteriaValueInputs:Y}),r==null||r()}catch(Y){console.error("Risk scoring submit error:",Y)}};return d?e.jsx(Z,{children:e.jsxs(ee,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center text-sm mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Loading risk scoring criteria…"})]})}):!d&&l&&l.length===0?e.jsx(Z,{children:e.jsxs(ee,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center text-sm mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"No criteria required. Moving to next step…"})]})}):p?e.jsx(Z,{children:e.jsx(ee,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading criteria: ",p.message]})})}):l?e.jsxs(Z,{children:[e.jsxs(he,{children:[e.jsx("h2",{className:"text-lg font-bold",children:"Risk Assessment"}),e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Please answer the following questions for risk evaluation"}),F.length>1&&e.jsxs("div",{className:"flex items-center justify-between mt-3",children:[e.jsxs("span",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:["Page ",b+1," of ",F.length]}),e.jsx("div",{className:"flex items-center gap-1.5",children:F.map((Y,B)=>e.jsx("div",{className:"rounded-full transition-all duration-200",style:{height:"6px",width:B===b?"20px":"6px",backgroundColor:B<=b?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},B))})]})]}),e.jsx(ee,{className:"space-y-6",children:X.map(({criterion:Y})=>e.jsx(Fa,{criterion:Y,value:I[Y.id]??[],error:A[Y.id],locale:n,onChange:B=>re(Y.id,B)},Y.id))}),e.jsxs(fe,{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs(Q,{type:"button",variant:"outline",onClick:z,style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(zr,{size:14}),b>0?"Previous":"Back"]}),D?e.jsx(Q,{type:"button",isLoading:y,onClick:G,children:"Continue"}):e.jsxs(Q,{type:"button",onClick:h,style:{display:"flex",alignItems:"center",gap:"4px"},children:["Next",e.jsx(Or,{size:14})]})]}),p&&e.jsx("div",{className:"mx-6 mb-4 p-3 bg-red-50 border border-red-200 rounded",children:e.jsx("p",{className:"text-red-600 text-sm",children:p.message})})]}):null},Fa=({criterion:t,value:r,error:a,locale:s,onChange:n})=>{const l=Ta(t),c=t.valueDataType===Me.Integer||t.valueDataType===Me.Money||t.valueDataType===Me.DigitOnly,d=Ra(t),y=p=>d?Ia(p,s):p;return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[t.displayName,t.isRequired&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),t.description&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:t.description}),c&&(t.min!==void 0||t.max!==void 0)&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:t.min!==void 0&&t.max!==void 0?`Range: ${t.min} – ${t.max}`:t.min!==void 0?`Minimum: ${t.min}`:`Maximum: ${t.max}`}),l==="text"&&e.jsx(ye,{value:r[0]??"",onChange:p=>n([p.target.value]),type:c?"number":"text",placeholder:"Enter your answer…",error:a,required:t.isRequired,min:t.min,max:t.max,onKeyDown:p=>{t.valueDataType===Me.DigitOnly&&["e","E","+","-","."].includes(p.key)&&p.preventDefault()}}),l==="radio"&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultValues??[]).map(p=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"radio",checked:r[0]===p,onChange:()=>n([p]),className:"metakyc-option-input",style:{width:"16px",height:"16px",minWidth:"16px",flexShrink:0,flexGrow:0,accentColor:"var(--metakyc-primary, #2563eb)",cursor:"pointer",margin:0,padding:0,display:"inline-block",verticalAlign:"middle"}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:y(p)})]},p)),a&&e.jsx("p",{className:"text-sm text-danger-500",children:a})]}),l==="checkbox"&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultValues??[]).map(p=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx(Fe,{checked:r.includes(p),onChange:k=>{n(k?[...r,p]:r.filter(I=>I!==p))}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:y(p)})]},p)),a&&e.jsx("p",{className:"text-sm text-danger-500",children:a})]}),l==="country"&&e.jsx(ut,{value:r[0]??"",onChange:p=>n([p.target.value]),options:[{value:"US",label:"United States"},{value:"GB",label:"United Kingdom"},{value:"DE",label:"Germany"},{value:"FR",label:"France"},{value:"AE",label:"United Arab Emirates"}],placeholder:"Select a country…",error:a,required:t.isRequired})]})},Wr=({applicantId:t,onComplete:r,onBack:a})=>{const{investorCategorizationService:s}=Re(),[n,l]=i.useState(null),[c,d]=i.useState(!1),[y,p]=i.useState(null),k=async I=>{if(I.preventDefault(),n===null){p("Please select an investor type");return}d(!0),p(null);try{const w={applicantId:t,investorType:n};console.log("Submitting investor categorization:",w);const A=await s.setInvestorCategorization(w);console.log("Investor categorization result:",A),r==null||r()}catch(w){console.error("Error submitting investor categorization:",w),p(w.message||"Failed to submit investor categorization")}finally{d(!1)}};return e.jsx("form",{onSubmit:k,children:e.jsxs(Z,{children:[e.jsxs(he,{children:[e.jsx("h2",{className:"text-lg font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Which statement best describes you?"}),e.jsx("p",{className:"mt-2",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"All Tokenise clients are treated as Retail Investors under EU regulation, which gives you the highest level of investor protection. For our internal purposes, we ask you to select the description that best matches your situation"})]}),e.jsxs(ee,{className:"space-y-4",children:[e.jsx("p",{className:"text-sm font-medium mb-3",style:{color:"var(--metakyc-text-secondary, #374151)"},children:"Choose one"}),e.jsx("label",{className:"block p-4 border-2 rounded-lg cursor-pointer transition-all",style:{borderColor:n===we.Individual?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:n===we.Individual?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:we.Individual,checked:n===we.Individual,onChange:()=>l(we.Individual),className:"mt-1"}),e.jsxs("div",{className:"ml-3",children:[e.jsx("div",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Individual investor"}),e.jsx("div",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"(Recommended) Most of our clients choose this option. Provides the strongest protection and aligns with our mission to make investing accessible to everyone."})]})]})}),e.jsx("label",{className:"block p-4 border-2 rounded-lg cursor-pointer transition-all",style:{borderColor:n===we.Sophisticated?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:n===we.Sophisticated?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:we.Sophisticated,checked:n===we.Sophisticated,onChange:()=>l(we.Sophisticated),className:"mt-1"}),e.jsxs("div",{className:"ml-3",children:[e.jsx("div",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Sophisticated investor"}),e.jsx("div",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"In the last 2 years, I have done one or more of the following:"}),e.jsxs("ul",{className:"text-sm mt-2 space-y-1 list-none",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:[e.jsx("li",{children:"Worked in private equity or provided capital to small and medium enterprises, and/or"}),e.jsx("li",{children:"Been the director of a company with an annual turnover of at least (USD) $2m million, and/or"}),e.jsx("li",{children:"Invested directly in at least 2 private (not listed) companies."})]})]})]})}),e.jsx("label",{className:"block p-4 border-2 rounded-lg cursor-pointer transition-all",style:{borderColor:n===we.HighNetWorth?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:n===we.HighNetWorth?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:we.HighNetWorth,checked:n===we.HighNetWorth,onChange:()=>l(we.HighNetWorth),className:"mt-1"}),e.jsxs("div",{className:"ml-3",children:[e.jsx("div",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"High networth investor"}),e.jsxs("div",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:["I earn more than (USD/EUR) $150,000 per year, and/or",e.jsx("br",{}),"I have net assets (excluding my main property) of at least $/EUR 300,000"]})]})]})}),y&&e.jsx("div",{className:"p-4 rounded-lg",style:{backgroundColor:"#fee2e2",border:"1px solid #fca5a5"},children:e.jsxs("p",{className:"text-sm",style:{color:"#991b1b"},children:[e.jsx("strong",{children:"Error:"})," ",y]})})]}),e.jsxs(fe,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[a&&e.jsx(Q,{type:"button",variant:"outline",onClick:a,children:"Back"}),e.jsx(Q,{type:"submit",isLoading:c,disabled:n===null,children:"Submit"})]})]})})};function At(t){const r=t.split(":").map(Number);return r.length===3?r[0]*3600+r[1]*60+r[2]:0}function xt(t){const r=Math.floor(t/60),a=t%60;return`${r.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`}const Ur=({applicantId:t,onComplete:r,onBack:a})=>{const{appropriatenessTestService:s}=Re(),[n,l]=i.useState(null),[c,d]=i.useState(!0),[y,p]=i.useState(!1),[k,I]=i.useState(null),[w,A]=i.useState({}),[T,b]=i.useState(0),[S,O]=i.useState(!1),[q,F]=i.useState(!1),[D,X]=i.useState(0),[re,N]=i.useState(0),[h,z]=i.useState(null);i.useEffect(()=>{(async()=>{try{d(!0),I(null);const $=await s.getAppropriatenessTest(t);if(l($),$.waitTimeSpanForNextTry&&$.waitTimeSpanForNextTry!=="00:00:00"){const _=At($.waitTimeSpanForNextTry);_>0&&X(_)}}catch($){I($.message||"Failed to load appropriateness test")}finally{d(!1)}})()},[t,s]),i.useEffect(()=>{if(!S||T<=0)return;const $=setInterval(()=>{b(_=>_<=1?(F(!0),0):_-1)},1e3);return()=>clearInterval($)},[S,T]),i.useEffect(()=>{if(D<=0)return;const $=setInterval(()=>{X(_=>_<=1?0:_-1)},1e3);return()=>clearInterval($)},[D]),i.useEffect(()=>{q&&!y&&V()},[q]);const G=()=>{n&&(O(!0),b(n.testDurationSec),N(0),A({}),I(null))},Y=($,_)=>{A(ue=>({...ue,[$]:_}))},B=i.useCallback(async()=>{try{const $=await s.getAppropriatenessTest(t);if(l($),$.waitTimeSpanForNextTry&&$.waitTimeSpanForNextTry!=="00:00:00"){const _=At($.waitTimeSpanForNextTry);_>0&&X(_)}}catch{}},[t,s]),V=async $=>{if(n){if(!q){const _=n.appropriatenessQuestions.length-Object.keys(w).length;if(_>0){I(`Please answer all questions. ${_} remaining.`);return}}p(!0),I(null);try{const _=n.appropriatenessQuestions.map(R=>({appropriatenessQuestionId:R.id,value:w[R.id]||""})),ue={applicantId:t,appropriatenessTestId:n.id,appropriatenessQuestionResults:_};try{const R=await s.fillAppropriatenessTest(ue);R.isSuccess?z({success:!0,message:R.message||"Congratulations! You have passed the test."}):(z({success:!1,message:R.message||"You did not pass the test."}),setTimeout(()=>B(),1e3))}catch(R){if(R.code===400&&R.message)z({success:!1,message:R.message}),setTimeout(()=>B(),1500);else throw R}}catch(_){I(_.message||"Failed to submit test. Please try again."),ae()}finally{p(!1)}}},ae=()=>{O(!1),F(!1),A({}),N(0)};if(c)return e.jsx(Z,{children:e.jsx(ee,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"48px 0",gap:"16px"},children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)"},children:"Loading test..."})]})})});if(!n)return e.jsx(Z,{children:e.jsx(ee,{children:e.jsxs("div",{style:{textAlign:"center",padding:"48px 0"},children:[e.jsx("p",{style:{fontSize:"16px",fontWeight:600,color:"var(--metakyc-danger, #ef4444)"},children:"No test data available"}),k&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"8px"},children:k})]})})});const K=n.testAllowedMaxTry-n.totalFailedTries,ke=n.appropriatenessQuestions.length,ce=Object.keys(w).length;if(D>0)return e.jsxs(Z,{children:[e.jsx(he,{children:e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:n.displayName})}),e.jsx(ee,{children:e.jsxs("div",{style:{textAlign:"center",padding:"32px 0"},children:[e.jsx("div",{style:{width:"100px",height:"100px",borderRadius:"50%",margin:"0 auto 20px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"color-mix(in srgb, var(--metakyc-primary, #2563eb) 8%, transparent)"},children:e.jsx("span",{style:{fontSize:"28px",fontWeight:700,color:"var(--metakyc-primary, #2563eb)",fontVariantNumeric:"tabular-nums"},children:xt(D)})}),e.jsx("p",{style:{fontSize:"15px",fontWeight:500,color:"var(--metakyc-text-primary, #111827)"},children:"Please wait before retrying"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"4px"},children:"You can attempt the test again once the timer expires"}),k&&e.jsx("div",{style:{marginTop:"20px",padding:"12px 16px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:k})})]})})]});if(h){const $=()=>{z(null),ae(),I(null)};return e.jsxs(Z,{children:[e.jsx(ee,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",textAlign:"center",padding:"40px 16px",gap:"16px"},children:[e.jsx("div",{style:{width:"72px",height:"72px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:h.success?"color-mix(in srgb, var(--metakyc-success, #10b981) 12%, transparent)":"color-mix(in srgb, var(--metakyc-danger, #ef4444) 10%, transparent)"},children:h.success?e.jsxs("svg",{width:"36",height:"36",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-success, #10b981)",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),e.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]}):e.jsxs("svg",{width:"36",height:"36",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),e.jsx("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]})}),e.jsx("h2",{style:{fontSize:"20px",fontWeight:700,color:h.success?"var(--metakyc-success, #10b981)":"var(--metakyc-danger, #ef4444)",margin:0},children:h.success?"Test Passed":"Test Failed"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",margin:0,lineHeight:1.6,maxWidth:"400px",whiteSpace:"pre-line"},children:h.message}),!h.success&&K>0&&e.jsx("div",{style:{marginTop:"4px",padding:"10px 20px",borderRadius:"10px",backgroundColor:"var(--metakyc-surface, #f9fafb)",border:"1px solid var(--metakyc-border, #e5e7eb)"},children:e.jsxs("p",{style:{fontSize:"13px",color:"var(--metakyc-text-muted, #9ca3af)",margin:0},children:["You have ",e.jsx("strong",{style:{color:"var(--metakyc-text-primary, #111827)"},children:K})," attempt",K!==1?"s":""," remaining"]})}),!h.success&&K<=0&&e.jsx("div",{style:{marginTop:"4px",padding:"10px 20px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:"No attempts remaining. Please contact support for assistance."})})]})}),e.jsx(fe,{children:e.jsx("div",{style:{display:"flex",justifyContent:"center",width:"100%",gap:"12px"},children:h.success?e.jsx(Q,{type:"button",onClick:()=>r==null?void 0:r(),children:"Continue"}):e.jsxs(e.Fragment,{children:[K>0&&D<=0&&e.jsx(Q,{type:"button",onClick:$,children:"Retake Test"}),K>0&&D>0&&e.jsx(Q,{type:"button",onClick:$,children:"OK"}),K<=0&&a&&e.jsx(Q,{type:"button",variant:"outline",onClick:a,children:"Back"})]})})})]})}if(!S)return e.jsxs(Z,{children:[e.jsxs(he,{children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:n.displayName}),n.subtitle&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",marginTop:"4px"},children:n.subtitle})]}),e.jsxs(ee,{children:[n.description&&e.jsxs("div",{style:{marginBottom:"20px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-primary, #2563eb) 5%, var(--metakyc-background, #ffffff))",border:"1px solid color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)",display:"flex",gap:"10px"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-primary, #2563eb)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:"1px"},children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-secondary, #374151)",margin:0,lineHeight:1.5},children:n.description})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px",marginBottom:"20px"},children:[e.jsx(ct,{icon:"questions",label:"Questions",value:String(n.totalQuestionCount)}),e.jsx(ct,{icon:"time",label:"Time Limit",value:xt(n.testDurationSec)}),e.jsx(ct,{icon:"target",label:"Pass Requirement",value:`${n.testCorrectAnswerPassLimit} correct`}),e.jsx(ct,{icon:"retry",label:"Attempts Left",value:String(K),variant:K<=1?"warning":"default"})]}),k&&e.jsxs("div",{style:{marginBottom:"16px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)",display:"flex",gap:"10px"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:"1px"},children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),e.jsxs("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0,lineHeight:1.5},children:[e.jsx("strong",{children:"Previous attempt:"})," ",k]})]}),K<=0&&e.jsx("div",{style:{padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:"You have used all your attempts. Please contact support for assistance."})})]}),e.jsx(fe,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:a?"space-between":"flex-end",width:"100%"},children:[a&&e.jsx(Q,{type:"button",variant:"outline",onClick:a,children:"Back"}),e.jsx(Q,{type:"button",onClick:G,disabled:K<=0,children:"Start Test"})]})})]});const de=n.appropriatenessQuestions[re],ge=re===ke-1,E=ce===ke,W=T<=60;return e.jsxs(Z,{children:[e.jsxs(he,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:n.displayName}),e.jsxs("p",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"2px"},children:["Question ",re+1," of ",ke]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 14px",borderRadius:"999px",backgroundColor:W?"color-mix(in srgb, var(--metakyc-danger, #ef4444) 10%, transparent)":"var(--metakyc-surface, #f3f4f6)",transition:"all 0.3s ease"},children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:W?"var(--metakyc-danger, #ef4444)":"var(--metakyc-text-muted, #9ca3af)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),e.jsx("span",{style:{fontSize:"16px",fontWeight:700,fontVariantNumeric:"tabular-nums",color:W?"var(--metakyc-danger, #ef4444)":"var(--metakyc-text-primary, #111827)",transition:"color 0.3s ease"},children:xt(T)})]})]}),e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsx("div",{style:{height:"4px",borderRadius:"999px",backgroundColor:"var(--metakyc-border, #e5e7eb)",overflow:"hidden"},children:e.jsx("div",{style:{height:"100%",borderRadius:"999px",backgroundColor:"var(--metakyc-primary, #2563eb)",width:`${ce/ke*100}%`,transition:"width 0.3s ease"}})}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:"4px"},children:[e.jsxs("span",{style:{fontSize:"11px",color:"var(--metakyc-text-muted, #9ca3af)"},children:[ce," answered"]}),e.jsxs("span",{style:{fontSize:"11px",color:"var(--metakyc-text-muted, #9ca3af)"},children:[K," attempt",K!==1?"s":""," left"]})]})]})]}),e.jsxs(ee,{children:[de&&e.jsx(La,{question:de,index:re,selectedAnswer:w[de.id],onSelect:$=>Y(de.id,$),disabled:y}),ke>1&&e.jsx("div",{style:{display:"flex",justifyContent:"center",gap:"6px",marginTop:"20px",flexWrap:"wrap"},children:n.appropriatenessQuestions.map(($,_)=>e.jsx("button",{type:"button",onClick:()=>N(_),style:{width:"28px",height:"28px",borderRadius:"8px",border:_===re?"2px solid var(--metakyc-primary, #2563eb)":"1px solid var(--metakyc-border, #e5e7eb)",backgroundColor:w[$.id]?_===re?"color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)":"color-mix(in srgb, var(--metakyc-primary, #2563eb) 8%, transparent)":_===re?"var(--metakyc-surface, #f9fafb)":"var(--metakyc-background, #ffffff)",color:w[$.id]?"var(--metakyc-primary, #2563eb)":"var(--metakyc-text-muted, #9ca3af)",fontSize:"12px",fontWeight:600,cursor:"pointer",transition:"all 0.15s ease",padding:0,display:"flex",alignItems:"center",justifyContent:"center"},children:_+1},$.id))}),q&&e.jsxs("div",{style:{marginTop:"16px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, #f59e0b 10%, transparent)",border:"1px solid color-mix(in srgb, #f59e0b 25%, transparent)",display:"flex",alignItems:"center",gap:"10px"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"#f59e0b",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),e.jsx("p",{style:{fontSize:"13px",color:"#b45309",margin:0,fontWeight:500},children:"Time's up! Your answers are being submitted."})]}),k&&!q&&e.jsx("div",{style:{marginTop:"16px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:k})})]}),e.jsx(fe,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[e.jsx(Q,{type:"button",variant:"outline",onClick:()=>{re>0?N($=>$-1):a==null||a()},disabled:y,children:re>0?"Previous":"Cancel"}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[!ge&&e.jsx(Q,{type:"button",onClick:()=>N($=>$+1),children:"Next"}),(ge||E)&&e.jsx(Q,{type:"button",isLoading:y,onClick:()=>V(),disabled:!E&&!q,style:{opacity:E||q?1:.5},children:q?"Submitting...":"Submit Test"})]})]})})]})},Pa={questions:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M9 11l3 3L22 4"}),e.jsx("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),time:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),target:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("circle",{cx:"12",cy:"12",r:"6"}),e.jsx("circle",{cx:"12",cy:"12",r:"2"})]}),retry:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})},ct=({icon:t,label:r,value:a,variant:s="default"})=>{const n=s==="warning";return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px",padding:"14px",borderRadius:"10px",backgroundColor:n?"color-mix(in srgb, #f59e0b 8%, transparent)":"var(--metakyc-surface, #f9fafb)",border:n?"1px solid color-mix(in srgb, #f59e0b 20%, transparent)":"1px solid var(--metakyc-border, #e5e7eb)"},children:[e.jsx("div",{style:{color:n?"#f59e0b":"var(--metakyc-primary, #2563eb)",flexShrink:0},children:Pa[t]}),e.jsxs("div",{children:[e.jsx("p",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)",margin:0},children:r}),e.jsx("p",{style:{fontSize:"15px",fontWeight:600,color:n?"#b45309":"var(--metakyc-text-primary, #111827)",margin:0,marginTop:"1px"},children:a})]})]})},La=({question:t,selectedAnswer:r,onSelect:a,disabled:s})=>e.jsxs("div",{children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[t.groupName&&e.jsx("span",{style:{display:"inline-block",fontSize:"11px",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em",color:"var(--metakyc-primary, #2563eb)",marginBottom:"8px"},children:t.groupName}),e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--metakyc-text-primary, #111827)",margin:0,lineHeight:1.5},children:t.question})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.answers.map((n,l)=>{const c=r===n;return e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"12px",padding:"14px 16px",borderRadius:"10px",border:`2px solid ${c?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}`,backgroundColor:c?"color-mix(in srgb, var(--metakyc-primary, #2563eb) 5%, var(--metakyc-background, #ffffff))":"var(--metakyc-background, #ffffff)",cursor:s?"default":"pointer",transition:"all 0.15s ease",opacity:s?.6:1},onMouseEnter:d=>{!s&&!c&&(d.currentTarget.style.borderColor="color-mix(in srgb, var(--metakyc-primary, #2563eb) 50%, var(--metakyc-border, #e5e7eb))")},onMouseLeave:d=>{c||(d.currentTarget.style.borderColor="var(--metakyc-border, #e5e7eb)")},children:[e.jsx("div",{style:{width:"20px",height:"20px",borderRadius:"50%",border:`2px solid ${c?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #d1d5db)"}`,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,transition:"border-color 0.15s ease"},children:c&&e.jsx("div",{style:{width:"10px",height:"10px",borderRadius:"50%",backgroundColor:"var(--metakyc-primary, #2563eb)"}})}),e.jsx("input",{type:"radio",name:`q-${t.id}`,value:n,checked:c,onChange:()=>a(n),disabled:s,style:{position:"absolute",opacity:0,width:0,height:0}}),e.jsx("span",{style:{fontSize:"14px",color:c?"var(--metakyc-text-primary, #111827)":"var(--metakyc-text-secondary, #6b7280)",fontWeight:c?500:400,transition:"color 0.15s ease"},children:n})]},l)})})]}),Kr=({applicantId:t,onComplete:r,onBack:a})=>{var Je,$e,tt,Ke;const{applicantService:s,baseInformationService:n,identityService:l,config:c,currentTheme:d}=Re(),{identityData:y,provider:p,token:k,isLoading:I,error:w,requestIdentity:A,restartIdentity:T}=Ar(t),[b,S]=i.useState(null),[O,q]=i.useState(null),[F,D]=i.useState([]),[X,re]=i.useState([]),[N,h]=i.useState(!0),[z,G]=i.useState(!1),[Y,B]=i.useState(null),[V,ae]=i.useState(!1),K=i.useRef(!1),[ke,ce]=i.useState({}),[de,ge]=i.useState({}),E=d!=null&&d.reviewPageFields&&d.reviewPageFields.length>0?d.reviewPageFields[0]:null,W=!!(d!=null&&d.reviewPageDisabled),$=i.useRef(!1);$.current=W;const _=Ye.useForm({defaultValues:{street:"",streetNumber:"",city:"",zip:"",country:"",nationality:"",phonenumber:""}});i.useEffect(()=>{if(W){K.current||(K.current=!0,A().then(()=>G(!0)).catch(M=>console.error("[Identity] Auto-request failed:",M)).finally(()=>h(!1)));return}(async()=>{try{const[M,U,H]=await Promise.all([s.getApplicantData(t),n.getCountries("","en"),n.getCountries("","en",40)]);q(M);const J=new Set,u=U.map(g=>({value:g.abbreviation3||g.abbreviation,label:g.name})).filter(g=>!g.value||J.has(g.value)?!1:(J.add(g.value),!0));D(u);const C=new Set,P=H.filter(g=>g.countryCode).map(g=>({value:g.countryCode,label:`${g.countryCode} – ${g.name}`})).filter(g=>C.has(g.value)?!1:(C.add(g.value),!0));re(P);const m=M.applicantRequestData;if(ce({firstName:(m==null?void 0:m.firstName)||"",lastName:(m==null?void 0:m.lastName)||"",email:(m==null?void 0:m.email)||"",dateOfBirth:(m==null?void 0:m.dateOfBirth)||"",title:(m==null?void 0:m.title)||"",salutation:(m==null?void 0:m.salutation)||"",phonenumber:(m==null?void 0:m.phonenumber)||"",mobileCountryCode:(m==null?void 0:m.mobileCountryCode)||"",street:(m==null?void 0:m.street)||"",streetNumber:(m==null?void 0:m.streetNumber)||"",city:(m==null?void 0:m.city)||"",zip:(m==null?void 0:m.zip)||"",country:(m==null?void 0:m.country)||"",nationality:(m==null?void 0:m.nationality)||"",taxCountry:(m==null?void 0:m.taxCountry)||"",countryOfBirth:(m==null?void 0:m.countryOfBirth)||"",placeOfBirth:(m==null?void 0:m.placeOfBirth)||"",educationLevel:(m==null?void 0:m.educationLevel)||"",occupation:(m==null?void 0:m.occupation)||"",taxNumber:(m==null?void 0:m.taxNumber)||"",defaultLanguage:(m==null?void 0:m.defaultLanguage)||""}),_.reset({street:(m==null?void 0:m.street)||"",streetNumber:(m==null?void 0:m.streetNumber)||"",city:(m==null?void 0:m.city)||"",zip:(m==null?void 0:m.zip)||"",country:(m==null?void 0:m.country)||"",nationality:(m==null?void 0:m.nationality)||"",phonenumber:(m==null?void 0:m.phonenumber)||""}),M.kycRecords&&M.kycRecords.length>0&&M.kycRecords[0].providerTokenObject!==null&&!K.current&&$.current){console.log("[Identity] Review page disabled + existing identity — auto-requesting..."),K.current=!0;try{await A(),G(!0)}catch(g){console.error("[Identity] Auto-request failed:",g)}}}catch(M){console.error("Error loading applicant data:",M)}finally{h(!1)}})()},[t]),i.useEffect(()=>{y&&!z&&$.current&&(console.log("[Identity] Review page disabled — showing cached provider"),G(!0))},[y,z]),i.useEffect(()=>{if(k){if(k.expiresAt){const x=new Date(k.expiresAt).getTime();if(Date.now()>=x){console.warn("[Identity] Token has expired (expiresAt)"),ae(!0),B("Your verification session has expired. Please restart.");return}}if(k.url)try{const M=new URL(k.url).toString().toLowerCase();if(M.includes("expired")||M.includes("invalid")||M.includes("error")){console.warn("[Identity] Token URL indicates expiration"),ae(!0),B("Your verification link has expired. Please restart.");return}}catch{console.error("[Identity] Invalid token URL")}if(k.status==="expired"||k.error==="expired"||k.expired===!0){console.warn("[Identity] Token object indicates expiration"),ae(!0),B("Your verification session has expired. Please restart.");return}}},[k]);const ue=p!==null&&p===Ae.Sumsub;i.useEffect(()=>{if(p!==null&&k&&!b&&z&&!V){const x=p;if(ue){console.log("[Sumsub] Fetching access token for Web SDK…"),B(null),(async()=>{try{const M=await l.refreshSumsubToken(t),U=He.parseProviderConfig(p,k,c);U.accessToken=M,U.onTokenRefresh=()=>l.refreshSumsubToken(t);const H=He.createProvider(p,U);H.onComplete(J=>{console.log("[Sumsub] Verification complete:",J),r==null||r()}),H.onError(J=>{console.error("[Sumsub] SDK error:",J),(typeof J=="string"?J:(J==null?void 0:J.message)||"Unknown error").toLowerCase().includes("expired")&&(ae(!0),B("Session expired. Please restart."))}),await H.initialize("sumsub-websdk-container"),console.log("[Sumsub] Web SDK launched"),S(H)}catch(M){console.error("[Sumsub] Initialization error:",M),B(`Failed to initialize: ${M.message||M}`),String(M.message||M).toLowerCase().includes("expired")&&ae(!0)}})();return}if(k.url){console.log("[Identity] Loading provider URL for user verification:",k.url),B(null);try{if(new URL(k.url),x===Ae.SardinAI){console.log("[SardinAI] Initializing Risk SDK in background...");try{const M=He.parseProviderConfig(p,k,c);He.createProvider(p,M).initialize().then(()=>console.log("[SardinAI] Risk SDK initialized in background")).catch(H=>console.warn("[SardinAI] Risk SDK init failed (non-blocking):",H))}catch(M){console.warn("[SardinAI] Risk SDK setup failed (non-blocking):",M)}}S({type:"url",url:k.url})}catch(M){console.error("[Identity] Invalid URL:",M),B("Invalid verification URL. Please restart."),ae(!0)}return}if(x===Ae.SardinAI){console.log("[SardinAI] No URL provided - initializing Risk SDK only..."),B(null);try{const M=He.parseProviderConfig(p,k,c),U=He.createProvider(p,M);U.initialize().then(()=>{console.log("[SardinAI] Risk SDK initialized successfully"),S(U),setTimeout(()=>r==null?void 0:r(),2e3)}).catch(H=>{var u;console.error("[SardinAI] Failed to initialize:",H);const J=((u=H.message)==null?void 0:u.toLowerCase())||"";J.includes("expired")||J.includes("invalid")||J.includes("401")||J.includes("400")?(ae(!0),B("Session expired or invalid. Please restart verification.")):B(`Failed to initialize: ${H.message}`)})}catch(M){console.error("[SardinAI] Error creating provider:",M),B(`Configuration error: ${M.message}`)}return}try{B(null);const M=He.parseProviderConfig(p,k,c),U=He.createProvider(p,M);x===Ae.Onfido&&U.initialize("identity-container").catch(H=>{console.error("[Onfido] Initialization error:",H),B(`Failed to initialize: ${H.message}`)}),S(U)}catch(M){console.error("[Identity] Provider setup error:",M),B(`Setup error: ${M.message}`)}}return()=>{if(b&&b.destroy)try{b.destroy()}catch(x){console.error("[Identity] Error destroying provider:",x)}}},[p,k,b,z,r,V,ue,t,c,l]);const R=async()=>{try{B(null),ae(!1),await A(),G(!0)}catch(x){console.error("Error starting identity verification:",x)}},te=async()=>{try{B(null),ae(!1),S(null),console.log("[Identity] Restarting verification..."),await T(),G(!0)}catch(x){console.error("Error restarting identity verification:",x),B(x.message||"Failed to restart verification")}};if(N||I)return e.jsx(Z,{children:e.jsxs(ee,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-4",children:"Loading identity verification..."})]})});if(w)return e.jsx(Z,{children:e.jsx(ee,{children:e.jsxs("p",{className:"text-danger-500",children:["Error: ",w.message]})})});if(z&&(Y||V))return e.jsxs(Z,{children:[e.jsx(he,{children:e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"Verification Session Issue"})}),e.jsxs(ee,{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:V?"Session Expired":"Verification Error"}),e.jsx("p",{className:"text-red-800 dark:text-red-200 text-sm",children:Y||"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(fe,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[a&&e.jsx(Q,{type:"button",variant:"outline",onClick:a,children:"Back"}),e.jsx(Q,{type:"button",onClick:te,disabled:I,children:I?"Restarting...":"Restart Verification"})]})]});if(z&&y){const x=p;return ue?e.jsxs("div",{style:{background:"var(--metakyc-background, #ffffff)",borderRadius:"12px",border:"1px solid var(--metakyc-border, #e5e7eb)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"20px 24px",borderBottom:"1px solid var(--metakyc-border, #e5e7eb)"},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{margin:0,fontSize:"20px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)"},children:"Identity Verification"}),e.jsx("p",{style:{margin:"4px 0 0",fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)"},children:"Please complete the identity verification process"})]}),e.jsx("button",{type:"button",onClick:te,disabled:I,style:{padding:"6px 14px",fontSize:"13px",fontWeight:500,borderRadius:"8px",border:"1px solid var(--metakyc-border, #d1d5db)",background:"var(--metakyc-background, #ffffff)",color:"var(--metakyc-text-primary, #111827)",cursor:I?"not-allowed":"pointer",opacity:I?.5:1},children:I?"Restarting…":"Restart"})]}),e.jsx("div",{id:"sumsub-websdk-container",style:{minHeight:"520px",width:"100%",padding:"16px 24px",background:"var(--metakyc-background, #ffffff)"}}),a&&e.jsx("div",{style:{padding:"16px 24px",borderTop:"1px solid var(--metakyc-border, #e5e7eb)"},children:e.jsx(Q,{variant:"outline",onClick:a,children:"Back"})})]}):k!=null&&k.url?e.jsxs(Z,{children:[e.jsx(he,{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(Q,{type:"button",variant:"outline",size:"sm",onClick:te,disabled:I,children:"Restart"})]})}),e.jsxs(ee,{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:k.url,className:"w-full h-full border-0 rounded-lg",allow:"camera; microphone; geolocation",title:"Identity Verification",onLoad:M=>{var U,H,J;console.log("[Identity] Iframe loaded");try{const u=M.target,C=u.contentDocument||((U=u.contentWindow)==null?void 0:U.document);if(C){const P=((J=(H=C.body)==null?void 0:H.textContent)==null?void 0:J.toLowerCase())||"";(P.includes("expired")||P.includes("invalid")||P.includes("error"))&&(console.warn("[Identity] Iframe shows expiration message"),ae(!0),B("Your verification link has expired."))}}catch{console.log("[Identity] Cannot check iframe content (CORS)")}}})})]}),a&&e.jsx(fe,{children:e.jsx(Q,{variant:"outline",onClick:a,children:"Back"})})]}):x===Ae.SardinAI?e.jsxs(Z,{children:[e.jsxs(he,{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(ee,{children:e.jsxs("div",{className:"text-center py-12",children:[e.jsx(Ee,{className:"mb-4"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Please wait while we verify your device security"}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-500 mt-2",children:"This process is automatic and will complete in a few seconds"})]})})]}):e.jsxs(Z,{children:[e.jsxs(he,{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(ee,{children:e.jsx("div",{id:"identity-container",className:"min-h-[400px]"})}),a&&e.jsx(fe,{children:e.jsx(Q,{variant:"outline",onClick:a,children:"Back"})})]})}const me=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),se=(x=4)=>{const M=Math.min(4,Math.max(1,Number(x)||4));return{gridColumn:`span ${M} / span ${M}`}},be=(x,M)=>{if(!M&&M!==0)return"—";if(me.has(x)&&x!=="mobileCountryCode"){const U=F.find(H=>H.value===M);return U?U.label:String(M)}return String(M)},Pe=({helpText:x})=>{const[M,U]=i.useState(!1),H=i.useRef(null),[,J]=i.useState({top:0,left:0}),u=()=>{if(H.current){const C=H.current.getBoundingClientRect();J({top:C.bottom+window.scrollY+6,left:C.left+window.scrollX})}U(!0)};return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"metakyc-help-btn",ref:H,onClick:u,style:{width:18,height:18,borderRadius:"50%",border:"1.5px solid var(--metakyc-primary, #2563eb)",background:"transparent",color:"var(--metakyc-primary, #2563eb)",fontSize:11,fontWeight:700,cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,lineHeight:1,position:"relative",zIndex:2},children:"?"}),M&&pt.createPortal(e.jsx("div",{style:{position:"fixed",inset:0,zIndex:99999,background:"rgba(0,0,0,0.55)",backdropFilter:"blur(6px)",WebkitBackdropFilter:"blur(6px)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:()=>U(!1),children:e.jsxs("div",{onClick:C=>C.stopPropagation(),style:{background:"var(--metakyc-surface, var(--metakyc-background, #ffffff))",border:"1px solid var(--metakyc-border, #e5e7eb)",borderRadius:"var(--metakyc-border-radius, 8px)",padding:"20px 24px",maxWidth:400,width:"90%",boxShadow:"0 24px 64px rgba(0,0,0,0.4)"},children:[e.jsx("div",{dangerouslySetInnerHTML:{__html:x},style:{fontSize:13,color:"var(--metakyc-text-primary, #111827)",lineHeight:1.6}}),e.jsx("button",{type:"button",onClick:()=>U(!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)]})},ve=(x,M)=>M?e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:5,flexWrap:"nowrap"},children:[e.jsx("div",{style:{flex:1,minWidth:0},children:x}),e.jsx("div",{style:{paddingTop:24},children:e.jsx(Pe,{helpText:M})})]}):x,Oe=(x,M)=>{const U=`cf-${M}`,H=x.paramName??"",J=de[H];if(x.customType==="br")return e.jsx("div",{style:{...se(x.colSpan),minHeight:"0.5rem"}},U);if(x.customType==="paragraph")return e.jsx("div",{style:se(x.colSpan),children:e.jsx("div",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:x.label||""}})},U);if(x.customType==="html")return e.jsx("div",{style:se(x.colSpan),dangerouslySetInnerHTML:{__html:x.label||""}},U);if(x.customType==="link")return e.jsx("div",{style:se(x.colSpan),children:ve(e.jsx("a",{href:x.linkUrl??"#",target:"_blank",rel:"noopener noreferrer",className:"text-sm underline",style:{color:"var(--metakyc-primary, #6366f1)"},children:x.displayText||x.label||x.linkText||x.linkUrl}),x.helpText)},U);if(x.customType==="checkbox"||x.customType==="link_checkbox"){const u=J==="true"||J===!0;return e.jsx("div",{style:se(x.colSpan),children:ve(e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx(Fe,{checked:!!u,onChange:C=>ge(P=>({...P,[H]:String(C)})),style:{marginTop:2}}),e.jsx("span",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)"},children:x.customType==="link_checkbox"&&x.linkUrl?e.jsxs(e.Fragment,{children:[e.jsx("a",{href:x.linkUrl,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--metakyc-primary, #6366f1)",textDecoration:"underline"},children:x.linkText||x.label}),x.label&&x.linkText?` ${x.label}`:""]}):x.displayText||x.label})]}),x.helpText)},U)}if(x.customType==="group_checkbox"){const u=Array.isArray(J)?J:J?[J]:[],C=P=>{x.singleSelect?ge(m=>({...m,[H]:u[0]===P?[]:[P]})):ge(m=>({...m,[H]:u.includes(P)?u.filter(o=>o!==P):[...u,P]}))};return e.jsx("div",{style:se(x.colSpan),children:ve(e.jsxs("div",{className:"space-y-1.5",children:[x.label&&e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:x.displayText||x.label}),(x.options||[]).map(P=>e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx(Fe,{checked:u.includes(P.value),onChange:()=>C(P.value),style:{marginTop:2}}),e.jsx("span",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)"},children:P.label})]},P.value))]}),x.helpText)},U)}return x.customType==="radio_group"?e.jsx("div",{style:se(x.colSpan),children:ve(e.jsxs("div",{className:"space-y-1.5",children:[x.label&&e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:x.displayText||x.label}),(x.options||[]).map(u=>e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"radio",name:`rg-${H}`,value:u.value,checked:J===u.value,onChange:()=>ge(C=>({...C,[H]:u.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:u.label})]},u.value))]}),x.helpText)},U):e.jsx("div",{style:se(x.colSpan),children:ve(e.jsx(ye,{label:x.displayText||x.label||H,value:String(J??""),onChange:u=>ge(C=>({...C,[H]:u.target.value}))}),x.helpText)},U)},et=(x,M)=>{if(x.isCustom)return Oe(x,M);const U=x.name??"",H=Ge[U],J=x.displayText||(H==null?void 0:H.label)||U,u=ke[U]??"",C=U==="mobileCountryCode",P=!!(H!=null&&H.countriesType)&&!C;return x.editable?C?e.jsx("div",{style:se(x.colSpan??2),children:ve(e.jsx(ze,{label:J,value:String(u),onChange:m=>ce(o=>({...o,[U]:m})),options:[{value:"",label:"Select country code…"},...X]}),x.helpText)},`epc-${M}`):P?e.jsx("div",{style:se(x.colSpan??2),children:ve(e.jsx(ze,{label:J,value:String(u),onChange:m=>ce(o=>({...o,[U]:m})),options:[{value:"",label:`Select ${J.toLowerCase()}…`},...F]}),x.helpText)},`ec-${M}`):e.jsx("div",{style:se(x.colSpan??2),children:ve(e.jsx(ye,{label:J,type:(H==null?void 0:H.type)==="date"?"date":(H==null?void 0:H.type)==="email"?"email":"text",value:String(u),onChange:m=>ce(o=>({...o,[U]:m.target.value}))}),x.helpText)},`ei-${M}`):e.jsx("div",{style:se(x.colSpan??2),children:ve(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:J}),e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)",minHeight:"1.5rem"},children:be(U,u)})]}),x.helpText)},`ro-${M}`)};if(E){const x=E.title||"Review Your Information",M=E.subtitle||"Please review and confirm your information before starting identity verification";return e.jsx("form",{onSubmit:U=>{U.preventDefault(),R()},children:e.jsxs(Z,{children:[e.jsxs(he,{children:[e.jsx("h2",{className:"text-lg font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:x}),e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:M})]}),e.jsx(ee,{children:e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:E.fields.map((U,H)=>et(U,H))})}),e.jsxs(fe,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[a&&e.jsx(Q,{type:"button",variant:"outline",onClick:a,children:"Back"}),e.jsx(Q,{type:"submit",isLoading:I,children:"Confirm and Start Verification"})]})]})})}return e.jsx("form",{onSubmit:_.handleSubmit(R),children:e.jsxs(Z,{children:[e.jsxs(he,{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(ee,{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:`${((Je=O==null?void 0:O.applicantRequestData)==null?void 0:Je.firstName)||""} ${(($e=O==null?void 0:O.applicantRequestData)==null?void 0:$e.lastName)||""}`.trim()},{label:"Email",value:(tt=O==null?void 0:O.applicantRequestData)==null?void 0:tt.email},{label:"Date of Birth",value:((Ke=O==null?void 0:O.applicantRequestData)==null?void 0:Ke.dateOfBirth)||"Not provided"}].map(({label:x,value:M})=>e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:x}),e.jsx("p",{className:"mt-1 text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:M})]},x))}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Address Information"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Ye.Controller,{control:_.control,name:"country",render:({field:x})=>e.jsx(ze,{label:"Country",value:x.value,onChange:x.onChange,options:[{value:"",label:"Select country…"},...F]})}),e.jsx(Ye.Controller,{control:_.control,name:"nationality",render:({field:x})=>e.jsx(ze,{label:"Nationality",value:x.value,onChange:x.onChange,options:[{value:"",label:"Select nationality…"},...F]})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Ye.Controller,{control:_.control,name:"street",render:({field:x})=>e.jsx(ye,{...x,label:"Street"})}),e.jsx(Ye.Controller,{control:_.control,name:"streetNumber",render:({field:x})=>e.jsx(ye,{...x,label:"Street Number"})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Ye.Controller,{control:_.control,name:"city",render:({field:x})=>e.jsx(ye,{...x,label:"City"})}),e.jsx(Ye.Controller,{control:_.control,name:"zip",render:({field:x})=>e.jsx(ye,{...x,label:"ZIP / Postal Code"})})]}),e.jsx(Ye.Controller,{control:_.control,name:"phonenumber",render:({field:x})=>e.jsx(ye,{...x,label:"Phone Number",type:"tel"})})]})]}),e.jsxs(fe,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[a&&e.jsx(Q,{type:"button",variant:"outline",onClick:a,children:"Back"}),e.jsx(Q,{type:"submit",isLoading:I,children:"Confirm and Start Verification"})]})]})})},ft=({kycStatus:t,reviewStatus:r,workflowResult:a,customMessage:s,onContinue:n,onContactSupport:l})=>{const d=t===Ve.Approved?{type:"success",title:"Verification Approved",icon:"✓",iconBg:"bg-green-100 dark:bg-green-900/30",iconColor:"text-green-600 dark:text-green-400",message:"Your identity verification has been successfully approved."}:t===Ve.Rejected?{type:"error",title:"Verification Rejected",icon:"✕",iconBg:"bg-red-100 dark:bg-red-900/30",iconColor:"text-red-600 dark:text-red-400",message:"Unfortunately, your identity verification was not approved."}:t===Ve.Pending||t===Ve.InProgress?{type:"pending",title:"Verification Pending",icon:"⏱",iconBg:"bg-blue-100 dark:bg-blue-900/30",iconColor:"text-blue-600 dark:text-blue-400",message:"Your identity verification is currently being processed."}:r===Qe.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===Qe.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===Qe.UnderReview||r===Qe.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."}:a===ot.Success?{type:"success",title:"Process Complete",icon:"✓",iconBg:"bg-green-100 dark:bg-green-900/30",iconColor:"text-green-600 dark:text-green-400",message:"Your verification process has been completed successfully."}:a===ot.Failed?{type:"error",title:"Process Failed",icon:"✕",iconBg:"bg-red-100 dark:bg-red-900/30",iconColor:"text-red-600 dark:text-red-400",message:"The verification process could not be completed."}:a===ot.AdminReview?{type:"pending",title:"Admin Review Required",icon:"📋",iconBg:"bg-yellow-100 dark:bg-yellow-900/30",iconColor:"text-yellow-700 dark:text-yellow-400",message:"Your application requires administrator review."}:{type:"pending",title:"Processing",icon:"⏱",iconBg:"bg-blue-100 dark:bg-blue-900/30",iconColor:"text-blue-600 dark:text-blue-400",message:"Your application is being reviewed."};return e.jsxs(Z,{children:[e.jsxs(ee,{className:"py-12",children:[e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx("div",{className:`w-24 h-24 rounded-full flex items-center justify-center ${d.iconBg}`,children:e.jsx("span",{className:`text-5xl ${d.iconColor}`,children:d.icon})})}),e.jsx("h2",{className:"text-3xl font-bold text-center mb-4",style:{color:"var(--metakyc-text-primary, #111827)"},children:d.title}),e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx(wt,{variant:d.type==="success"?"success":d.type==="error"?"danger":d.type==="pending"?"warning":"info",children:t!=null?Ve[t]:Qe[r]})}),e.jsx("p",{className:"text-center mb-6 max-w-md mx-auto",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:s||d.message}),d.type==="success"&&e.jsxs("div",{className:"bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg p-4 mb-6",children:[e.jsx("h3",{className:"font-semibold text-green-900 dark:text-green-100 mb-2",children:"What's Next?"}),e.jsxs("ul",{className:"text-sm text-green-800 dark:text-green-200 space-y-1",children:[e.jsx("li",{children:"✓ Your identity has been verified"}),e.jsx("li",{children:"✓ You can now proceed with your application"}),e.jsx("li",{children:"✓ All features are now accessible"})]})]}),d.type==="error"&&e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 mb-6",children:[e.jsx("h3",{className:"font-semibold text-red-900 dark:text-red-100 mb-2",children:"What Can You Do?"}),e.jsxs("ul",{className:"text-sm text-red-800 dark:text-red-200 space-y-2",children:[e.jsx("li",{children:"• Review the requirements and ensure all information is correct"}),e.jsx("li",{children:"• Contact our support team for assistance"}),e.jsx("li",{children:"• You may be able to resubmit your application"})]})]}),d.type==="pending"&&e.jsxs("div",{className:"bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-4 mb-6",children:[e.jsx("h3",{className:"font-semibold text-blue-900 dark:text-blue-100 mb-2",children:"What Happens Next?"}),e.jsxs("ul",{className:"text-sm text-blue-800 dark:text-blue-200 space-y-2",children:[e.jsx("li",{children:"• Our team is reviewing your information"}),e.jsx("li",{children:"• You will be notified via email once the review is complete"}),e.jsx("li",{children:"• This typically takes 24-48 hours"}),e.jsx("li",{children:"• No action is required from you at this time"})]})]}),e.jsx("div",{className:"mt-6 pt-6",style:{borderTop:"1px solid var(--metakyc-border, #e5e7eb)"},children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"KYC Status:"}),e.jsx("div",{className:"font-medium mt-1",style:{color:"var(--metakyc-text-primary, #111827)"},children:t!=null?Ve[t]:"Not Available"})]}),e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"Review Status:"}),e.jsx("div",{className:"font-medium mt-1",style:{color:"var(--metakyc-text-primary, #111827)"},children:Qe[r]})]})]})})]}),e.jsxs(fe,{style:{display:"flex",justifyContent:"center",gap:"1rem"},children:[d.type==="success"&&n&&e.jsx(Q,{onClick:n,size:"lg",children:"Continue"}),d.type==="error"&&e.jsxs(e.Fragment,{children:[l&&e.jsx(Q,{variant:"outline",onClick:l,children:"Contact Support"}),n&&e.jsx(Q,{onClick:n,children:"Try Again"})]}),d.type==="pending"&&e.jsx("div",{className:"text-center",children:e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Please check back later or wait for our email notification"})})]})]})},qr=({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:a=>{console.warn("[Logo] Failed to load logo:",t.url),a.target.style.display="none"}})}),nt=({title:t,subtitle:r,className:a=""})=>{const{currentTheme:s}=Re(),n=t||(s==null?void 0:s.title)||"",l=!!(s!=null&&s.logo&&s.logo.visible&&s.logo.url),c=!!n;return!l&&!c?null:e.jsxs("div",{className:`metakyc-header ${a}`,children:[e.jsxs("div",{className:"metakyc-header-title flex items-center text-xl font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:[l&&e.jsx(qr,{config:s.logo}),l&&c&&e.jsx("span",{style:{fontSize:"1.5rem",fontWeight:300,color:"var(--metakyc-text-muted, #9ca3af)",margin:"0 12px"},children:"|"}),c&&e.jsx("span",{style:{color:"var(--metakyc-text-primary, #111827)"},children:n})]}),r&&e.jsx("p",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:r})]})},dt=["firstName","lastName","email","phonenumber","dateOfBirth"];function rt(t){return t==null||t===""||Array.isArray(t)&&t.length===0}const Da={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"},Tt=({helpText:t,children:r})=>{const[a,s]=i.useState(!1);if(!t)return e.jsx(e.Fragment,{children:r});const n=a?e.jsx("div",{role:"dialog","aria-modal":"true",onClick:()=>s(!1),style:{position:"fixed",inset:0,zIndex:999999,background:"rgba(0, 0, 0, 0.55)",backdropFilter:"blur(6px)",WebkitBackdropFilter:"blur(6px)",display:"flex",alignItems:"center",justifyContent:"center",padding:"16px"},children:e.jsxs("div",{onClick:l=>l.stopPropagation(),style:{background:"var(--metakyc-surface, var(--metakyc-background, #ffffff))",border:"1px solid var(--metakyc-border, #e5e7eb)",borderRadius:"12px",padding:"28px 24px 24px",maxWidth:"480px",width:"100%",maxHeight:"80vh",overflowY:"auto",boxShadow:"0 24px 64px rgba(0,0,0,0.4)",position:"relative"},children:[e.jsx("button",{type:"button",onClick:()=>s(!1),"aria-label":"Close",style:{position:"absolute",top:"12px",right:"12px",width:"28px",height:"28px",borderRadius:"50%",border:"1px solid var(--metakyc-border, #e5e7eb)",background:"var(--metakyc-input-bg, #f3f4f6)",color:"var(--metakyc-text-secondary, #6b7280)",fontSize:"16px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:"×"}),e.jsx("div",{style:{color:"var(--metakyc-text-primary, #111827)",fontSize:"14px",lineHeight:1.75},dangerouslySetInnerHTML:{__html:t}})]})}):null;return e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"5px",flexWrap:"nowrap"},children:[r,e.jsx("button",{type:"button",className:"metakyc-help-btn",onClick:()=>s(!0),"aria-label":"Help",style:{flexShrink:0,marginTop:"2px",width:"18px",height:"18px",borderRadius:"50%",border:"1.5px solid var(--metakyc-primary, #2563eb)",background:"transparent",color:"var(--metakyc-primary, #2563eb)",fontSize:"10px",fontWeight:"700",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,padding:0,position:"relative",zIndex:2,transition:"background 0.15s, color 0.15s"},onMouseEnter:l=>{l.currentTarget.style.background="var(--metakyc-primary, #2563eb)",l.currentTarget.style.color="#ffffff"},onMouseLeave:l=>{l.currentTarget.style.background="transparent",l.currentTarget.style.color="var(--metakyc-primary, #2563eb)"},children:"?"}),typeof document<"u"&&n?pt.createPortal(n,document.body):null]})},Ma=({workflowKey:t,externalRefId:r,onSuccess:a,onCancel:s})=>{var U,H,J,u,C,P,m;const{config:n,baseInformationService:l,currentTheme:c}=Re(),{createApplicant:d,isLoading:y}=vt(),p=t||((U=n.applicantForm)==null?void 0:U.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 k=r||((H=n.applicantForm)==null?void 0:H.externalRefId)||"",I=((J=n.applicantForm)==null?void 0:J.email)||"",w=((u=n.applicantForm)==null?void 0:u.hiddenValues)||{},A=((C=n.applicantForm)==null?void 0:C.initialValues)||{},b=(((P=n.applicantForm)==null?void 0:P.fieldLabelMode)||(c==null?void 0:c.fieldLabelMode)||"label")!=="placeholder",S=i.useMemo(()=>c!=null&&c.applicantFormPages&&c.applicantFormPages.length>0?c.applicantFormPages:null,[c==null?void 0:c.applicantFormPages]),O=i.useMemo(()=>{const o=new Set(dt),g=c==null?void 0:c.applicantFormRequiredFields;if(g)for(const L of g)o.add(L);if(S)for(const L of S)for(const f of L.fields)!f.isCustom&&f.name&&f.required&&o.add(f.name);return Array.from(o)},[c==null?void 0:c.applicantFormRequiredFields,S]),q=i.useMemo(()=>{var L;if(S){const f=S.flatMap(v=>v.fields).filter(v=>!v.isCustom&&v.name).map(v=>v.name),j=new Set(f);for(const v of dt)j.add(v);return Array.from(j)}let o;(L=n.applicantForm)!=null&&L.visibleFields?o=n.applicantForm.visibleFields:c!=null&&c.applicantFormVisibleFields&&c.applicantFormVisibleFields.length>0?o=c.applicantFormVisibleFields:o=Kt;const g=new Set(o);for(const f of dt)g.add(f);return Array.from(g)},[(m=n.applicantForm)==null?void 0:m.visibleFields,c==null?void 0:c.applicantFormVisibleFields,S]),F=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),D=i.useMemo(()=>{var g,L;const o=new Set;if(S)for(const f of S)for(const j of f.fields)!j.isCustom&&j.name&&F.has(j.name)&&o.add(j.countriesType??((g=Ge[j.name])==null?void 0:g.countriesType));else for(const f of q)F.has(f)&&o.add((L=Ge[f])==null?void 0:L.countriesType);return o.size===0&&o.add(void 0),Array.from(o)},[q,S]),[X,re]=i.useState({}),[N,h]=i.useState(!0),z=i.useRef(new Set),G=i.useRef(new Set);i.useEffect(()=>{if(!c)return;const o=D.filter(f=>{const j=f!=null?String(f):"all";return!G.current.has(j)&&!z.current.has(j)});if(o.length===0){D.every(j=>{const v=j!=null?String(j):"all";return G.current.has(v)})&&h(!1);return}h(!0);const g=o.map(f=>f!=null?String(f):"all");g.forEach(f=>z.current.add(f)),(async()=>{try{const f=await Promise.all(o.map(async j=>{const v=j!=null?String(j):"all",le=await l.getCountries("",n.locale||"en",j),ne=j===40,xe=new Set,Ie=le.map(ie=>ne&&ie.countryCode?{value:ie.countryCode,label:`${ie.countryCode} – ${ie.name}`}:{value:ie.abbreviation3||ie.abbreviation,label:ie.name}).filter(ie=>!ie.value||xe.has(ie.value)?!1:(xe.add(ie.value),!0));return G.current.add(v),z.current.delete(v),[v,Ie]}));re(j=>({...j,...Object.fromEntries(f)}))}catch(f){g.forEach(j=>z.current.delete(j)),console.error("Failed to load countries:",f)}finally{D.every(j=>{const v=j!=null?String(j):"all";return G.current.has(v)})&&h(!1)}})()},[D,c]);const Y=(o,g)=>{var j;const L=g??((j=Ge[o])==null?void 0:j.countriesType),f=L!=null?String(L):"all";return X[f]||[]},B={firstName:1,lastName:1,title:1,email:1,dateOfBirth:1,phonenumber:1,mobileCountryCode:1,street:1,streetNumber:1,zip:1,city:1,country:1,nationality:1,otherNationality:1,defaultLanguage:1,taxCountry:1,placeOfBirth:1,countryOfBirth:1,salutation:1,educationLevel:1,occupation:1,taxNumber:1},V=Object.fromEntries(Object.entries(w).filter(([o])=>o in B)),ae=Object.fromEntries(Object.entries(A).filter(([o])=>o in B)),[K,ke]=i.useState({workflowKey:p,firstName:"",lastName:"",title:"",email:I,dateOfBirth:"",phonenumber:"",externalRefId:k,mobileCountryCode:"",street:"",streetNumber:"",zip:"",city:"",country:"",nationality:"",otherNationality:[],defaultLanguage:"EN",taxCountry:"",placeOfBirth:"",countryOfBirth:"",salutation:null,educationLevel:"",occupation:"",taxNumber:"",...V,...ae}),ce=Object.fromEntries(Object.entries(w).filter(([o])=>!(o in V)&&o!=="externalRefId"&&o!=="workflowKey")),[de,ge]=i.useState({...ce}),[E,W]=i.useState(0),[$,_]=i.useState({}),[ue,R]=i.useState(null),[te,me]=i.useState(!1),se=(o,g)=>ke(L=>({...L,[o]:g})),be=(o,g)=>ge(L=>({...L,[o]:g})),Pe=o=>!o.conditionalOn||de[o.conditionalOn]==="true",ve=S&&E<S.length-1?E+1:-1,Oe=S&&E>0?E-1:-1,et=o=>{var L;const g={};for(const f of o.fields)if(f.isCustom){if(f.customType==="paragraph"||f.customType==="html"||f.customType==="br"||f.customType==="link")continue;if(f.required&&f.paramName){const j=de[f.paramName],v=f.displayText||f.label||f.paramName;f.customType==="checkbox"||f.customType==="link_checkbox"?j!=="true"&&(g[f.paramName]=`${v} is required.`):(!j||j.trim()==="")&&(g[f.paramName]=`${v} is required.`)}}else if(f.name){const j=f.name;if(O.includes(j)&&rt(K[j])){const v=f.displayText||((L=Ge[j])==null?void 0:L.label)||j;g[j]=`${v} is required.`}}return g},Je=async()=>{if(!S)return;const o=S[E];if(o.conditionalOn&&!Pe(o)){_({}),ve>=0?W(ve):await $e();return}const g=et(o);if(Object.keys(g).length>0){_(g);return}_({}),ve>=0?W(ve):await $e()},$e=async()=>{if(S){let o={};for(const g of S)Pe(g)&&(o={...o,...et(g)});if(Object.keys(o).length>0){_(o);return}}me(!0),R(null);try{if(!K.externalRefId||K.externalRefId.trim()===""){R("External Reference ID is required. Please pass it via config.applicantForm.externalRefId.");return}const o={workflowKey:K.workflowKey,externalRefId:K.externalRefId.trim()};if(S){for(const j of S)if(Pe(j)){for(const v of j.fields)if(!v.isCustom&&v.name){const le=v.name,ne=K[le];rt(ne)||(o[le]=ne)}}for(const j of dt)if(o[j]===void 0){const v=K[j];rt(v)||(o[j]=v)}}else q.forEach(j=>{if(j==="externalRefId")return;const v=K[j];rt(v)||(o[j]=v)});const g=[];if(S){for(const j of S)if(Pe(j))for(const v of j.fields){if(!v.isCustom||!v.paramName||v.customType==="paragraph"||v.customType==="html"||v.customType==="br"||v.customType==="link")continue;const le=de[v.paramName]??"";let ne;if(v.customType==="checkbox"||v.customType==="link_checkbox")ne=le==="true"?"yes":"no";else if(ne=le,!ne&&!v.required)continue;g.push({paramName:v.paramName,value:ne})}}for(const[j,v]of Object.entries(V))o[j]===void 0&&!rt(v)&&(o[j]=v);const L=new Set(g.map(j=>j.paramName));for(const[j,v]of Object.entries(ce))!L.has(j)&&v&&g.push({paramName:j,value:v});g.length>0&&(o.applicantAdditionalDatas=g);const f=await d(o);a(f.applicantId)}catch(o){console.error("Error creating applicant:",o),R(o.message||"Failed to create applicant")}finally{me(!1)}},tt=async o=>{var g;o.preventDefault();for(const L of O)if(rt(K[L])){const f=((g=Ge[L])==null?void 0:g.label)||L;R(`${f} is required.`);return}await $e()},Ke=(o,g,L,f,j)=>{var jt;const v=Ge[o];if(!v)return null;const le=O.includes(o),ne=$[o],xe=L||v.label,Ie=o in ae,ie=g??o,Le={required:le},Be=j?j!=="placeholder":b,qe=Be?xe:void 0,Yr=Be?"...":xe;switch(v.type){case"select":if(o==="country"||o==="nationality"||o==="taxCountry"||o==="countryOfBirth"||o==="mobileCountryCode"){const Ne=Y(o,f);return e.jsx(ze,{...Le,label:qe,value:K[o]||"",onChange:Xe=>se(o,Xe),options:[{value:"",label:`Select ${Yr.toLowerCase()}`},...Ne],disabled:N,readOnly:Ie,error:ne},ie)}if(o==="salutation")return e.jsx(ze,{...Le,label:qe,value:((jt=K[o])==null?void 0:jt.toString())||"",onChange:Ne=>se(o,Ne?Number(Ne):null),options:[{value:"",label:Be?"Select salutation...":xe},{value:lt.Male.toString(),label:"Male"},{value:lt.Female.toString(),label:"Female"},{value:lt.Other.toString(),label:"Other"}],readOnly:Ie,error:ne},ie);if(o==="defaultLanguage"){const Ne=c!=null&&c.allowedLanguages&&c.allowedLanguages.length>0?ht.filter(Xe=>c.allowedLanguages.includes(Xe.value)):ht;return e.jsx(ze,{...Le,label:qe,value:K[o]||"",onChange:Xe=>se(o,Xe),options:[{value:"",label:Be?"Select language...":xe},...Ne],readOnly:Ie,error:ne},ie)}return null;case"multiselect":if(o==="otherNationality"){const Ne=Y(o,f);return e.jsx(Fr,{...Le,label:qe,value:K[o]||[],onChange:Xe=>se(o,Xe),options:Ne,placeholder:Be?"Select other nationalities...":xe,disabled:N,readOnly:Ie},ie)}return null;case"date":return e.jsx(ye,{...Le,type:"date",label:qe,placeholder:Be?void 0:xe,value:K[o]||"",onChange:Ne=>se(o,Ne.target.value),readOnly:Ie,error:ne},ie);case"email":return e.jsx(ye,{...Le,type:"email",label:qe,placeholder:Be?void 0:xe,value:K[o]||"",onChange:Ne=>se(o,Ne.target.value),readOnly:Ie,error:ne},ie);case"tel":return e.jsx(ye,{...Le,type:"tel",label:qe,placeholder:Be?void 0:xe,value:K[o]||"",onChange:Ne=>se(o,Ne.target.value),readOnly:Ie,error:ne},ie);default:return e.jsx(ye,{...Le,type:"text",label:qe,placeholder:Be?void 0:xe,value:K[o]||"",onChange:Ne=>se(o,Ne.target.value),readOnly:Ie,error:ne},ie)}},x=(o,g)=>{const L=o.labelMode?o.labelMode!=="placeholder":b;if(o.customType==="paragraph"){const v=o.displayText||o.label||"";return e.jsx("p",{className:"metakyc-paragraph",style:{fontSize:"14px",lineHeight:"1.7",margin:0,color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:v}},`custom-${g}`)}if(o.customType==="html")return e.jsx("div",{dangerouslySetInnerHTML:{__html:o.label||""}},`custom-${g}`);if(o.customType==="br")return e.jsx("div",{style:{height:"12px"}},`custom-${g}`);if(o.customType==="link"){const v=o.displayText||o.label||o.linkText||o.linkUrl||"";return e.jsx("div",{className:"metakyc-link-field",children:e.jsxs("a",{href:o.linkUrl||"#",target:"_blank",rel:"noopener noreferrer",style:{display:"inline-flex",alignItems:"center",gap:"4px",color:"var(--metakyc-primary, #2563eb)",fontSize:"14px",textDecoration:"underline",cursor:"pointer"},children:[v,e.jsx("span",{style:{fontSize:"10px",opacity:.7},children:"↗"})]})},`custom-${g}`)}if(!o.paramName)return null;const f=$[o.paramName],j=o.displayText||o.label||o.paramName;if(o.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(Fe,{checked:de[o.paramName]==="true",onChange:v=>be(o.paramName,v?"true":"false")}),e.jsxs("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:[j,o.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),f&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:f})]},`custom-${g}`);if(o.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(Fe,{checked:de[o.paramName]==="true",onChange:v=>be(o.paramName,v?"true":"false")}),e.jsxs("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:[j," ",o.linkUrl&&e.jsx("a",{href:o.linkUrl,target:"_blank",rel:"noopener noreferrer",className:"underline",style:{color:"var(--metakyc-primary, #2563eb)"},onClick:v=>v.stopPropagation(),children:o.linkText||o.linkUrl}),o.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),f&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:f})]},`custom-${g}`);if(o.customType==="group_checkbox"){const v=(de[o.paramName]||"").split(",").filter(Boolean);return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[L&&e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[j,o.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:(o.options||[]).map(le=>{const ne=o.singleSelect?de[o.paramName]===le.value:v.includes(le.value);return e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx(Fe,{checked:ne,onChange:xe=>{if(o.singleSelect)be(o.paramName,xe?le.value:"");else{const Ie=xe?[...v,le.value]:v.filter(ie=>ie!==le.value);be(o.paramName,Ie.join(","))}}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:le.label})]},le.value)})}),f&&e.jsx("p",{className:"text-red-500 text-xs",children:f})]},`custom-${g}`)}return o.customType==="radio_group"?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[L&&e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[j,o.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:(o.options||[]).map(v=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"radio",checked:de[o.paramName]===v.value,onChange:()=>be(o.paramName,v.value),name:`radio-group-${o.paramName}-${g}`,className:"metakyc-option-input",style:Da}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:v.label})]},v.value))}),f&&e.jsx("p",{className:"text-red-500 text-xs",children:f})]},`custom-${g}`):e.jsx(ye,{type:"text",label:L?`${j}${o.required?" *":""}`:void 0,placeholder:L?void 0:j,value:de[o.paramName]||"",onChange:v=>be(o.paramName,v.target.value),required:o.required,error:f},`custom-${g}`)},M=(o,g)=>{const L=Pe(o);return e.jsxs("div",{className:"space-y-4",children:[o.conditionalOn&&e.jsx(Tt,{helpText:o.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(Fe,{checked:L,onChange:f=>be(o.conditionalOn,f?"true":"false")}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",fontWeight:500},children:o.conditionalOn})]})}),L&&e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:o.fields.map((f,j)=>{const v=Math.min(4,Math.max(1,Number(f.colSpan)||4)),le=f.isCustom?`custom-${j}-${f.paramName}`:`builtin-${f.name}-${j}`;return e.jsx("div",{style:{gridColumn:`span ${v} / span ${v}`},children:e.jsx(Tt,{helpText:f.helpText,children:f.isCustom?x(f,j):Ke(f.name,le,f.displayText,f.countriesType,f.labelMode)})},le)})})]})};if(!c||N)return e.jsx("div",{className:"metakyc-sdk",children:e.jsx(Z,{children:e.jsxs(ee,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)",fontSize:"0.875rem"},children:"Loading form…"})]})})});if(S){const o=S[E]??S[0],g=Oe===-1,L=ve===-1,f=S.length,j=Pe(o),v=Object.values($);return e.jsx("div",{className:"metakyc-sdk",children:e.jsxs(Z,{children:[e.jsx(he,{children:e.jsx(nt,{title:(c==null?void 0:c.title)||"Create Applicant"})}),e.jsxs(ee,{children:[(o.title||o.subtitle||o.description)&&e.jsxs("div",{className:"mb-4",children:[o.title&&e.jsx("h3",{className:"font-semibold text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:o.title}),o.subtitle&&e.jsx("p",{className:"text-sm mt-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:o.subtitle}),o.description&&o.description!==o.subtitle&&e.jsx("p",{className:"text-xs mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:o.description})]}),(ue||v.length>0)&&e.jsxs("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-lg",children:[ue&&e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",ue]}),v.map((le,ne)=>e.jsx("p",{className:"text-red-600 text-sm",children:le},ne))]}),f>1&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem",marginBottom:"1rem"},children:[S.map((le,ne)=>e.jsx("div",{style:{height:"0.375rem",borderRadius:"9999px",transition:"all 150ms",...ne===E?{flex:"1 1 0%",backgroundColor:"var(--metakyc-primary, #2563eb)"}:ne<E?{width:"2rem",backgroundColor:"var(--metakyc-primary-light, #93c5fd)",opacity:.7}:{width:"2rem",backgroundColor:"#e5e7eb"}}},ne)),e.jsxs("span",{style:{fontSize:"0.75rem",color:"var(--metakyc-text-muted, #9ca3af)",flexShrink:0},children:[E+1," / ",f]})]}),M(o)]}),e.jsxs(fe,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{children:[!g&&e.jsx(Q,{type:"button",variant:"outline",onClick:()=>{W(Oe),_({})},disabled:te||y,children:"Previous"}),g&&s&&e.jsx(Q,{type:"button",variant:"outline",onClick:s,disabled:te||y,children:"Cancel"})]}),e.jsx(Q,{type:"button",isLoading:te||y,onClick:L?$e:Je,children:L?o.conditionalOn&&!j?"Skip & Submit":"Submit":o.conditionalOn&&!j?"Skip":"Next"})]})]})})}return e.jsx("div",{className:"metakyc-sdk",children:e.jsx("form",{onSubmit:tt,children:e.jsxs(Z,{children:[e.jsx(he,{children:e.jsx(nt,{title:(c==null?void 0:c.title)||"Create Applicant"})}),e.jsxs(ee,{children:[ue&&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:"})," ",ue]})}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:q.map(o=>e.jsx("div",{style:{gridColumn:"span 4 / span 4"},children:Ke(o)},o))})]}),e.jsxs(fe,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s&&e.jsx(Q,{type:"button",variant:"outline",onClick:s,disabled:te||y,children:"Cancel"}),e.jsx(Q,{type:"submit",isLoading:te||y,children:"Create Applicant"})]})]})})})},Ft=["companyName","email"];function gt(t){return t==null||t===""||Array.isArray(t)&&t.length===0}const za=({workflowKey:t,externalRefId:r,onSuccess:a,onCancel:s})=>{var Ke,x,M,U,H,J;const{config:n,baseInformationService:l,currentTheme:c}=Re(),{createCompanyApplicant:d,isLoading:y}=vt(),p=t||((Ke=n.applicantForm)==null?void 0:Ke.workflowKey);if(!p)throw new Error("workflowKey is required. Provide it either as a prop to CreateCompanyApplicantForm or set it in config.applicantForm.workflowKey");const k=r||((x=n.applicantForm)==null?void 0:x.externalRefId)||"",I=((M=n.applicantForm)==null?void 0:M.email)||"",w=((U=n.applicantForm)==null?void 0:U.initialValues)||{},T=(((H=n.applicantForm)==null?void 0:H.fieldLabelMode)||(c==null?void 0:c.fieldLabelMode)||"label")!=="placeholder",b=i.useMemo(()=>c!=null&&c.companyFormPages&&c.companyFormPages.length>0?c.companyFormPages:null,[c==null?void 0:c.companyFormPages]),S=i.useMemo(()=>{const u=new Set(Ft),C=c==null?void 0:c.companyFormRequiredFields;if(C)for(const P of C)u.add(P);if(b)for(const P of b)for(const m of P.fields)!m.isCustom&&m.name&&m.required&&u.add(m.name);return Array.from(u)},[c==null?void 0:c.companyFormRequiredFields,b]),O=i.useMemo(()=>{var u;if(b){const C=b.flatMap(m=>m.fields).filter(m=>!m.isCustom&&m.name).map(m=>m.name),P=new Set(C);for(const m of Ft)P.add(m);return Array.from(P)}return(u=n.applicantForm)!=null&&u.visibleFields?n.applicantForm.visibleFields:c!=null&&c.companyFormVisibleFields&&c.companyFormVisibleFields.length>0?c.companyFormVisibleFields:Ut},[(J=n.applicantForm)==null?void 0:J.visibleFields,c==null?void 0:c.companyFormVisibleFields,b]),q=new Set(["countryResidence","addressCountry"]),F=i.useMemo(()=>{var C,P;const u=new Set;if(b)for(const m of b)for(const o of m.fields)!o.isCustom&&o.name&&q.has(o.name)&&u.add(o.countriesType??((C=Ze[o.name])==null?void 0:C.countriesType));else for(const m of O)q.has(m)&&u.add((P=Ze[m])==null?void 0:P.countriesType);return u.size===0&&u.add(void 0),Array.from(u)},[O,b]),[D,X]=i.useState({}),[re,N]=i.useState(!0),h=i.useRef(new Set),z=i.useRef(new Set);i.useEffect(()=>{if(!c)return;const u=F.filter(m=>{const o=m!=null?String(m):"all";return!z.current.has(o)&&!h.current.has(o)});if(u.length===0){F.every(o=>z.current.has(o!=null?String(o):"all"))&&N(!1);return}N(!0);const C=u.map(m=>m!=null?String(m):"all");C.forEach(m=>h.current.add(m)),(async()=>{try{const m=await Promise.all(u.map(async o=>{const g=o!=null?String(o):"all",L=await l.getCountries("",n.locale||"en",o),f=new Set,j=L.map(v=>({value:v.abbreviation3||v.abbreviation,label:v.name})).filter(v=>!v.value||f.has(v.value)?!1:(f.add(v.value),!0));return z.current.add(g),h.current.delete(g),[g,j]}));X(o=>({...o,...Object.fromEntries(m)}))}catch(m){C.forEach(o=>h.current.delete(o)),console.error("Failed to load countries:",m)}finally{F.every(o=>z.current.has(o!=null?String(o):"all"))&&N(!1)}})()},[F,c]);const G=(u,C)=>{var o;const P=C??((o=Ze[u])==null?void 0:o.countriesType),m=P!=null?String(P):"all";return D[m]||[]},Y={companyName:1,registrationNumber:1,email:1,phone:1,countryResidence:1,legalAddress:1,incorporatedOn:1,controlScheme:1,taxId:1,registrationLocation:1,website:1,postalAddress:1,street:1,streetNumber:1,city:1,state:1,postalCode:1,addressCountry:1,lei:1},B=Object.fromEntries(Object.entries(w).filter(([u])=>u in Y)),[V,ae]=i.useState({workflowKey:p,companyName:"",email:I,phone:"",registrationNumber:"",countryResidence:"",legalAddress:"",incorporatedOn:"",controlScheme:"",taxId:"",registrationLocation:"",website:"",postalAddress:"",street:"",streetNumber:"",city:"",state:"",postalCode:"",addressCountry:"",lei:"",externalRefId:k,...B}),[K,ke]=i.useState({}),[ce,de]=i.useState(0),[ge,E]=i.useState({}),[W,$]=i.useState(null),[_,ue]=i.useState(!1),R=(u,C)=>ae(P=>({...P,[u]:C})),te=(u,C)=>ke(P=>({...P,[u]:C})),me=u=>!u.conditionalOn||K[u.conditionalOn]==="true",se=b&&ce<b.length-1?ce+1:-1,be=b&&ce>0?ce-1:-1,Pe=u=>{var P;const C={};for(const m of u.fields)if(m.isCustom){if(m.customType==="paragraph"||m.customType==="html"||m.customType==="br"||m.customType==="link")continue;if(m.required&&m.paramName){const o=K[m.paramName],g=m.displayText||m.label||m.paramName;m.customType==="checkbox"||m.customType==="link_checkbox"?o!=="true"&&(C[m.paramName]=`${g} is required.`):(!o||o.trim()==="")&&(C[m.paramName]=`${g} is required.`)}}else if(m.name){const o=m.name;if(S.includes(o)&>(V[o])){const g=m.displayText||((P=Ze[o])==null?void 0:P.label)||o;C[o]=`${g} is required.`}}return C},ve=async()=>{if(!b)return;const u=b[ce];if(u.conditionalOn&&!me(u)){E({}),se>=0?de(se):await Oe();return}const C=Pe(u);if(Object.keys(C).length>0){E(C);return}E({}),se>=0?de(se):await Oe()},Oe=async()=>{var u;if(b){let C={};for(const P of b)me(P)&&(C={...C,...Pe(P)});if(Object.keys(C).length>0){E(C);return}}ue(!0),$(null);try{const C={workflowKey:V.workflowKey,externalRefId:((u=V.externalRefId)==null?void 0:u.trim())||void 0},P=b?b.filter(g=>me(g)).flatMap(g=>g.fields).filter(g=>!g.isCustom&&g.name).map(g=>g.name):O;for(const g of P){const L=V[g];if(!gt(L))switch(g){case"companyName":C.companyName=L;break;case"email":C.companyEmail=L;break;case"phone":C.companyPhone=L;break;case"registrationNumber":C.companyRegistrationNumber=L;break;case"countryResidence":C.companyCountry=L;break;case"city":C.companyCity=L;break;case"street":C.companyStreet=L;break;case"postalCode":C.companyZip=L;break;default:C[g]=L;break}}const m=[];if(b){for(const g of b)if(me(g))for(const L of g.fields){if(!L.isCustom||!L.paramName||L.customType==="paragraph"||L.customType==="html"||L.customType==="br"||L.customType==="link")continue;const f=K[L.paramName]??"";let j;if(L.customType==="checkbox"||L.customType==="link_checkbox")j=f==="true"?"yes":"no";else if(j=f,!j&&!L.required)continue;m.push({paramName:L.paramName,value:j})}}m.length>0&&(C.applicantAdditionalDatas=m);const o=await d(C);a(o.applicantId)}catch(C){console.error("Error creating company applicant:",C),$(C.message||"Failed to create company applicant")}finally{ue(!1)}},et=async u=>{var C;u.preventDefault();for(const P of S)if(gt(V[P])){const m=((C=Ze[P])==null?void 0:C.label)||P;$(`${m} is required.`);return}await Oe()},Je=(u,C,P,m,o)=>{const g=Ze[u];if(!g)return null;const L=S.includes(u),f=ge[u],j=P||g.label,v=u in B,le=C??u,ne=o?o!=="placeholder":T,xe=ne?j:void 0,Ie=ne?"...":j;switch(g.type){case"select":if(u==="countryResidence"||u==="addressCountry"){const ie=G(u,m);return e.jsx(ze,{required:L,label:xe,value:V[u]||"",onChange:Le=>R(u,Le),options:[{value:"",label:`Select ${Ie.toLowerCase()}`},...ie],disabled:re,readOnly:v,error:f},le)}return null;case"date":return e.jsx(ye,{required:L,type:"date",label:xe,placeholder:ne?void 0:j,value:V[u]||"",onChange:ie=>R(u,ie.target.value),readOnly:v,error:f},le);case"email":return e.jsx(ye,{required:L,type:"email",label:xe,placeholder:ne?void 0:j,value:V[u]||"",onChange:ie=>R(u,ie.target.value),readOnly:v,error:f},le);case"tel":return e.jsx(ye,{required:L,type:"tel",label:xe,placeholder:ne?void 0:j,value:V[u]||"",onChange:ie=>R(u,ie.target.value),readOnly:v,error:f},le);default:return e.jsx(ye,{required:L,type:"text",label:xe,placeholder:ne?void 0:j,value:V[u]||"",onChange:ie=>R(u,ie.target.value),readOnly:v,error:f},le)}},$e=(u,C)=>{if(u.customType==="paragraph")return e.jsx("p",{style:{fontSize:"14px",lineHeight:"1.7",margin:0,color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:u.displayText||u.label||""}},`custom-${C}`);if(u.customType==="html")return e.jsx("div",{dangerouslySetInnerHTML:{__html:u.label||""}},`custom-${C}`);if(u.customType==="br")return e.jsx("div",{style:{height:"12px"}},`custom-${C}`);if(u.customType==="link")return e.jsx("div",{children:e.jsx("a",{href:u.linkUrl||"#",target:"_blank",rel:"noopener noreferrer",style:{color:"var(--metakyc-primary, #2563eb)",fontSize:"14px",textDecoration:"underline"},children:u.displayText||u.label||u.linkText||u.linkUrl||""})},`custom-${C}`);if(!u.paramName)return null;const P=ge[u.paramName],m=u.displayText||u.label||u.paramName,o=u.labelMode?u.labelMode!=="placeholder":T;return u.customType==="checkbox"?e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer"},children:[e.jsx(Fe,{checked:K[u.paramName]==="true",onChange:g=>te(u.paramName,g?"true":"false")}),e.jsxs("span",{style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)"},children:[m,u.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),P&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:P})]},`custom-${C}`):e.jsx(ye,{type:"text",label:o?`${m}${u.required?" *":""}`:void 0,placeholder:o?void 0:m,value:K[u.paramName]||"",onChange:g=>te(u.paramName,g.target.value),required:u.required,error:P},`custom-${C}`)},tt=u=>{const C=me(u);return e.jsxs("div",{className:"space-y-4",children:[u.conditionalOn&&e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer"},children:[e.jsx(Fe,{checked:C,onChange:P=>te(u.conditionalOn,P?"true":"false")}),e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:u.conditionalOn})]}),C&&e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:u.fields.map((P,m)=>{const o=Math.min(4,Math.max(1,Number(P.colSpan)||4)),g=P.isCustom?`custom-${m}-${P.paramName}`:`builtin-${P.name}-${m}`;return e.jsx("div",{style:{gridColumn:`span ${o} / span ${o}`},children:P.isCustom?$e(P,m):Je(P.name,g,P.displayText,P.countriesType,P.labelMode)},g)})})]})};if(!c||re)return e.jsx("div",{className:"metakyc-sdk",children:e.jsx(Z,{children:e.jsxs(ee,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)",fontSize:"0.875rem"},children:"Loading form…"})]})})});if(b){const u=b[ce]??b[0],C=be===-1,P=se===-1,m=b.length,o=me(u),g=Object.values(ge);return e.jsx("div",{className:"metakyc-sdk",children:e.jsxs(Z,{children:[e.jsx(he,{children:e.jsx(nt,{title:(c==null?void 0:c.title)||"Company Registration"})}),e.jsxs(ee,{children:[(u.title||u.subtitle)&&e.jsxs("div",{className:"mb-4",children:[u.title&&e.jsx("h3",{className:"font-semibold text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:u.title}),u.subtitle&&e.jsx("p",{className:"text-sm mt-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:u.subtitle})]}),(W||g.length>0)&&e.jsxs("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-lg",children:[W&&e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",W]}),g.map((L,f)=>e.jsx("p",{className:"text-red-600 text-sm",children:L},f))]}),m>1&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem",marginBottom:"1rem"},children:[b.map((L,f)=>e.jsx("div",{style:{height:"0.375rem",borderRadius:"9999px",transition:"all 150ms",...f===ce?{flex:"1 1 0%",backgroundColor:"var(--metakyc-primary, #2563eb)"}:f<ce?{width:"2rem",backgroundColor:"var(--metakyc-primary-light, #93c5fd)",opacity:.7}:{width:"2rem",backgroundColor:"#e5e7eb"}}},f)),e.jsxs("span",{style:{fontSize:"0.75rem",color:"var(--metakyc-text-muted, #9ca3af)",flexShrink:0},children:[ce+1," / ",m]})]}),tt(u)]}),e.jsxs(fe,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{children:[!C&&e.jsx(Q,{type:"button",variant:"outline",onClick:()=>{de(be),E({})},disabled:_||y,children:"Previous"}),C&&s&&e.jsx(Q,{type:"button",variant:"outline",onClick:s,disabled:_||y,children:"Cancel"})]}),e.jsx(Q,{type:"button",isLoading:_||y,onClick:P?Oe:ve,children:P?u.conditionalOn&&!o?"Skip & Submit":"Submit":u.conditionalOn&&!o?"Skip":"Next"})]})]})})}return e.jsx("div",{className:"metakyc-sdk",children:e.jsx("form",{onSubmit:et,children:e.jsxs(Z,{children:[e.jsx(he,{children:e.jsx(nt,{title:(c==null?void 0:c.title)||"Company Registration"})}),e.jsxs(ee,{children:[W&&e.jsx("div",{className:"mb-6 p-4 bg-red-50 border border-red-200 rounded-lg",children:e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",W]})}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:O.map(u=>e.jsx("div",{style:{gridColumn:"span 4 / span 4"},children:Je(u)},u))})]}),e.jsxs(fe,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s&&e.jsx(Q,{type:"button",variant:"outline",onClick:s,disabled:_||y,children:"Cancel"}),e.jsx(Q,{type:"submit",isLoading:_||y,children:"Register Company"})]})]})})})},Oa=({applicantId:t,onComplete:r,onError:a,className:s})=>{const{progress:n,currentStep:l,steps:c,workflowKey:d,nextWorkflowKey:y,hasWorkflowChanged:p,isLoading:k,error:I,moveBack:w,refreshProgress:A}=Nr(t),[T,b]=i.useState(!1),S=i.useRef(null);if(i.useEffect(()=>{I&&a&&a(I)},[I,a]),i.useEffect(()=>{n!=null&&n.workflowResult&&r&&r(n.workflowResult)},[n==null?void 0:n.workflowResult,r]),i.useEffect(()=>{p&&b(!1)},[p]),k||!n)return e.jsx("div",{className:`metakyc-sdk ${s||""}`,children:e.jsx(Z,{children:e.jsxs(ee,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Loading workflow..."})]})})});if(I)return e.jsx("div",{className:`metakyc-sdk ${s||""}`,children:e.jsx(Z,{children:e.jsx(ee,{children:e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-lg mb-4",style:{color:"var(--metakyc-danger, #ef4444)"},children:"An error occurred"}),e.jsx("p",{style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:I.message})]})})})});if(p&&!T)return e.jsx("div",{className:`metakyc-sdk ${s||""}`,children:e.jsx(Z,{children:e.jsx(ee,{children:e.jsxs("div",{className:"text-center py-8",children:[e.jsx("div",{className:"mb-6",children:e.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-full mb-4",style:{backgroundColor:"var(--metakyc-primary-light, #dbeafe)"},children:e.jsx("svg",{className:"w-8 h-8",style:{color:"var(--metakyc-primary, #2563eb)"},fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})})}),e.jsx("h3",{className:"text-xl font-semibold mb-2",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Workflow Transition"}),e.jsx("p",{className:"mb-6",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Your application workflow has been updated based on your progress."}),e.jsxs("div",{className:"rounded-lg p-4 mb-6 max-w-md mx-auto",style:{backgroundColor:"var(--metakyc-surface, #f9fafb)"},children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"mb-1",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"Previous Workflow"}),e.jsx("p",{className:"font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:d})]}),e.jsx("svg",{className:"w-6 h-6 mx-4",style:{color:"var(--metakyc-text-muted, #9ca3af)"},fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 7l5 5m0 0l-5 5m5-5H6"})}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"mb-1",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"New Workflow"}),e.jsx("p",{className:"font-medium",style:{color:"var(--metakyc-primary, #2563eb)"},children:y})]})]}),n.nextWorkflowName&&e.jsx("p",{className:"text-center mt-2 text-xs",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:n.nextWorkflowName})]}),e.jsx("button",{onClick:()=>b(!0),className:"px-6 py-3 font-medium rounded-lg transition-opacity hover:opacity-90",style:{backgroundColor:"var(--metakyc-primary, #2563eb)",color:"#ffffff"},children:"Continue with New Workflow"})]})})})});if(n.status===Te.Finished||n.status===Te.OnHold)return e.jsx("div",{className:`metakyc-sdk ${s||""}`,children:e.jsx(ft,{kycStatus:n.kycStatus,reviewStatus:n.reviewStatus,workflowResult:n.workflowResult,customMessage:n.customMessage,onContinue:r&&n.workflowResult?()=>r(n.workflowResult):void 0,onContactSupport:()=>{typeof window<"u"&&(window.location.href="mailto:support@example.com")}})});if(!l)return e.jsx("div",{className:`metakyc-sdk ${s||""}`,children:e.jsx(Z,{children:e.jsxs(ee,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:n.status===Te.IdentityPending?"Loading identity verification...":"Loading current step..."})]})})});const O=D=>{switch(D){case oe.Overview:return"Overview";case oe.Questionaries:return"Questionnaire";case oe.UploadDocument:return"Documents";case oe.IdentitySdk:return"Identity";case oe.RiskScoring:return"Risk Assessment";case oe.InvestorCategorization:return"Investor Categorization";case oe.AppropriatenessTest:return"Appropriateness Test";case oe.AdditionalData:return"Additional Data";case oe.ManualReview:return"Review";default:return""}},q=()=>{const D=c.filter(z=>z.visibility!==!1),X=D.findIndex(z=>z.order===l.order),re=X>=0?X+1:1,N=D.length,h=N>1?(X+1)/N*100:100;return e.jsxs("div",{style:{marginBottom:"24px",backgroundColor:"var(--metakyc-surface, var(--metakyc-background, #ffffff))",borderRadius:"0.75rem",border:"1px solid var(--metakyc-border, #e5e7eb)",padding:"1rem 1.5rem",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",marginBottom:"16px"},children:[e.jsx(nt,{}),e.jsxs(wt,{variant:n.status===1?"info":"success",children:["Step ",re," of ",N]})]}),e.jsx("div",{style:{marginBottom:"16px"},children:e.jsx("div",{style:{height:"4px",borderRadius:"999px",backgroundColor:"var(--metakyc-border, #e5e7eb)",overflow:"hidden"},children:e.jsx("div",{style:{height:"100%",borderRadius:"999px",backgroundColor:"var(--metakyc-primary, #2563eb)",width:`${h}%`,transition:"width 0.4s ease"}})})}),e.jsx($a,{ref:S,visibleSteps:D,currentVisibleStepIndex:X,getStepFallbackName:O})]})},F=()=>{const D={applicantId:t,onComplete:async()=>{await A()},onBack:l.order>0?w:void 0};switch(l.action){case oe.Questionaries:return e.jsx($r,{...D});case oe.UploadDocument:return e.jsx(Br,{...D});case oe.Overview:return e.jsx(_r,{...D});case oe.IdentitySdk:return e.jsx(Kr,{...D});case oe.RiskScoring:return e.jsx(Hr,{...D});case oe.AdditionalData:case oe.InvestorCategorization:return e.jsx(Wr,{...D});case oe.AppropriatenessTest:return e.jsx(Ur,{...D});case oe.ManualReview:return e.jsx(ft,{kycStatus:n.kycStatus,reviewStatus:n.reviewStatus,workflowResult:n.workflowResult,customMessage:n.customMessage});default:return e.jsx(Z,{children:e.jsxs(ee,{className:"py-12 text-center",children:[e.jsx("div",{className:"mb-4",children:e.jsx(Ee,{})}),e.jsxs("p",{className:"text-gray-600 dark:text-gray-400 mb-2",children:["Processing step: ",l.title||l.name]}),e.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:["Action type: ",oe[l.action]]})]})})}};return e.jsxs("div",{className:`metakyc-sdk ${s||""}`,children:[q(),F()]})},$a=i.forwardRef(({visibleSteps:t,currentVisibleStepIndex:r,getStepFallbackName:a},s)=>{const n=i.useRef(null),l=i.useRef(null);return i.useImperativeHandle(s,()=>n.current),i.useEffect(()=>{if(l.current&&n.current){const c=n.current,d=l.current,y=d.offsetLeft-c.offsetWidth/2+d.offsetWidth/2;c.scrollTo({left:Math.max(0,y),behavior:"smooth"})}},[r]),e.jsx("div",{ref:n,className:"metakyc-stepper-scroll",style:{display:"flex",alignItems:"center",width:"100%",overflowX:"auto",overflowY:"hidden",scrollbarWidth:"none",msOverflowStyle:"none",WebkitOverflowScrolling:"touch",padding:"4px 0",gap:"0"},children:t.map((c,d)=>{const y=d<r,p=d===r,k=y||p,I=c.displayName||c.name||a(c.action)||`Step ${d+1}`;return e.jsxs(i.Fragment,{children:[e.jsxs("div",{ref:p?l:void 0,style:{display:"flex",alignItems:"center",flexShrink:0},children:[e.jsx("div",{style:{width:"28px",height:"28px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"12px",fontWeight:600,flexShrink:0,transition:"all 0.2s ease",...k?{backgroundColor:"var(--metakyc-primary, #2563eb)",color:"#ffffff",border:"none"}:{backgroundColor:"transparent",color:"var(--metakyc-text-muted, #9ca3af)",border:"2px solid var(--metakyc-border, #e5e7eb)"}},children:y?e.jsx("svg",{width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:2.5,viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}):d+1}),e.jsx("span",{style:{marginLeft:"6px",fontSize:"13px",whiteSpace:"nowrap",fontWeight:p?600:400,color:p?"var(--metakyc-text-primary, #111827)":y?"var(--metakyc-primary, #2563eb)":"var(--metakyc-text-muted, #9ca3af)",transition:"color 0.2s ease"},children:I})]}),d<t.length-1&&e.jsx("div",{style:{flex:"1 1 0%",minWidth:"16px",height:"2px",margin:"0 8px",borderRadius:"999px",backgroundColor:"var(--metakyc-primary, #2563eb)",opacity:y?1:.25,transition:"opacity 0.2s ease"}})]},c.order)})})});function Ba(t){return Ue.z.object({questionResults:Ue.z.any()}).passthrough()}function _a(t){let r=Ue.z.array(Ue.z.instanceof(File));if(t.isRequired?r=r.min(1,`${t.displayName} is required`):r=r.optional(),t.multipleFile||(r=r.refine(a=>!a||a.length<=1,{message:"Only one file is allowed"})),t.maxEachFileSizeByte>0&&(r=r.refine(a=>!a||a.every(s=>s.size<=t.maxEachFileSizeByte),{message:`File size must not exceed ${Math.round(t.maxEachFileSizeByte/1024/1024)}MB`})),t.allowedTypes){const a=t.allowedTypes.split(",").map(s=>s.trim());r=r.refine(s=>s?s.every(n=>a.some(l=>l.endsWith("/*")?n.type.startsWith(l.slice(0,-2)):n.type===l)):!0,{message:"Invalid file type"})}return r}function Ha(t){const r={};return t.uploadDocumentFiles.forEach(a=>{const s=`file_${a.id}`;r[s]=_a(a)}),Ue.z.object(r)}function Wa(t){return Ue.z.any()}function Ua(t){return Ue.z.string().min(1,"This question is required")}function Ka(t){const r={};return t.appropriatenessQuestions.forEach(a=>{const s=`question_${a.id}`;r[s]=Ua()}),Ue.z.object(r)}const qa=Ue.z.any();exports.ALLOWED_LANGUAGES=ht;exports.ApplicantProgressOnHoldReason=Pt;exports.ApplicantProgressStatus=Te;exports.ApplicantService=Qt;exports.ApplicantStatus=Dt;exports.AppropriatenessQuestionType=Bt;exports.AppropriatenessTestService=Xt;exports.AppropriatenessTestStep=Ur;exports.Badge=wt;exports.BaseInformationService=rr;exports.Button=Q;exports.COMPANY_FIELD_METADATA=Ze;exports.Card=Z;exports.CardContent=ee;exports.CardFooter=fe;exports.CardHeader=he;exports.Checkbox=Fe;exports.CountriesType=We;exports.CreateApplicantForm=Ma;exports.CreateCompanyApplicantForm=za;exports.CriteriaBuiltInType=Ht;exports.DEFAULT_COMPANY_VISIBLE_FIELDS=Ut;exports.DEFAULT_VISIBLE_FIELDS=Kt;exports.DocumentReviewStatus=$t;exports.EndpointBuilder=Yt;exports.ErrorHandler=at;exports.EventEmitter=mr;exports.FIELD_METADATA=Ge;exports.FileType=Ot;exports.FileUpload=Pr;exports.GenderType=lt;exports.Header=nt;exports.HttpClient=Vt;exports.IdentityProviderManager=He;exports.IdentityService=tr;exports.IdentityVerificationProvider=Ae;exports.IdentityVerificationStep=Kr;exports.Input=ye;exports.InvestorCategorizationService=ar;exports.InvestorCategorizationStep=Wr;exports.InvestorCategorizationType=we;exports.InvestorCategoryType=Wt;exports.KycProcessStatus=Mt;exports.KycStatus=Ve;exports.KycStatusDisplay=ft;exports.KycWorkflow=Oa;exports.Logo=qr;exports.MetaKYCContext=bt;exports.MetaKYCError=De;exports.MetaKYCProvider=sa;exports.MultiSelect=Fr;exports.OnfidoProvider=gr;exports.OverviewService=Zt;exports.OverviewStep=_r;exports.PhoneInput=Lr;exports.QuestionnaireService=Gt;exports.QuestionnaireStep=$r;exports.ReviewStatus=Qe;exports.RiskCriteriaType=_t;exports.RiskLevel=Lt;exports.RiskScoringService=er;exports.RiskScoringStep=Hr;exports.SDK_VERSION=kr;exports.SardinAIProvider=hr;exports.SearchableSelect=ze;exports.Select=ut;exports.Spinner=Ee;exports.StepRouter=ur;exports.SumsubProvider=xr;exports.ThemeManager=fr;exports.ThemePreset=Se;exports.ThemeService=dr;exports.UploadDocumentService=Jt;exports.UploadDocumentStep=Br;exports.UserType=zt;exports.ValueDataType=Me;exports.WorkflowOrchestrator=yr;exports.WorkflowResultType=ot;exports.WorkflowState=pr;exports.WorkflowStepAction=oe;exports.appropriatenessTestSchema=qa;exports.clearAllStorage=ca;exports.clearApplicantId=jr;exports.clearWorkflowState=Cr;exports.cn=Ce;exports.corporateTheme=sr;exports.defaultConfig=qt;exports.defaultTheme=je;exports.fileToBase64=br;exports.fintechTheme=nr;exports.formatFileSize=mt;exports.generateAppropriatenessSchema=Ka;exports.generateQuestionnaireSchema=Ba;exports.generateRiskScoringSchema=Wa;exports.generateUploadDocumentSchema=Ha;exports.getAcceptString=oa;exports.getApplicantId=wr;exports.getThemePreset=st;exports.getWorkflowState=la;exports.healthcareTheme=ir;exports.isScriptLoaded=Xr;exports.loadScript=kt;exports.minimalTheme=lr;exports.modernTheme=or;exports.removeScript=Zr;exports.saveApplicantId=vr;exports.saveWorkflowState=Sr;exports.themePresets=cr;exports.useApplicant=vt;exports.useAppropriatenessTest=da;exports.useIdentityVerification=Ar;exports.useKycWorkflow=Nr;exports.useMetaKYC=Re;exports.useOverview=Er;exports.useQuestionnaire=Rr;exports.useRiskScoring=Tr;exports.useUploadDocument=Ir;exports.validateFileSize=na;exports.validateFileType=ia;
|
|
125
125
|
//# sourceMappingURL=index.cjs.map
|