@vpdev2/metakyc 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -49,7 +49,7 @@ a:hover { color: ${r}; }
49
49
  position: relative !important;
50
50
  z-index: 2 !important;
51
51
  }
52
- `}class fr{constructor(r){pe(this,"currentTheme",Re);pe(this,"customStyleElement",null);pe(this,"inputStyleElement",null);pe(this,"container");this.container=r||document.documentElement}applyTheme(r){this.currentTheme=this.mergeWithDefault(r),this.applyColors(this.currentTheme.colors),this.currentTheme.typography&&this.applyTypography(this.currentTheme.typography),this.currentTheme.spacing&&this.applySpacing(this.currentTheme.spacing),this.currentTheme.customCSS&&this.injectCustomCSS(this.currentTheme.customCSS),console.log("[ThemeManager] Theme applied:",this.currentTheme.name||"Custom")}applyColors(r){var n;const s={primary:r.primary,"primary-hover":r.primaryHover,"primary-light":r.primaryLight,"primary-dark":r.primaryDark,secondary:r.secondary,"secondary-hover":r.secondaryHover,success:r.success,warning:r.warning,danger:r.danger,info:r.info,background:r.background,surface:r.surface,border:r.border,"text-primary":r.textPrimary,"text-secondary":r.textSecondary,"text-muted":r.textMuted,"input-bg":r.inputBg||r.background,"input-text":r.inputText||r.textPrimary,"input-border":r.inputBorder||r.border,"input-border-focus":r.inputBorderFocus||r.primary,"input-placeholder":r.inputPlaceholder||r.textMuted};Object.entries(s).forEach(([a,o])=>{o&&this.container.style.setProperty(`--metakyc-${a}`,o)}),this.injectInputColors(),(n=this.currentTheme.darkMode)!=null&&n.colors&&this.applyDarkModeColors(this.currentTheme.darkMode.colors)}applyDarkModeColors(r){Object.entries(r).forEach(([s,n])=>{if(n){const a=`--metakyc-dark-${this.kebabCase(s)}`;this.container.style.setProperty(a,n)}})}applyTypography(r){r&&(r.fontFamily&&this.container.style.setProperty("--metakyc-font-family",r.fontFamily),r.headingFont&&this.container.style.setProperty("--metakyc-heading-font",r.headingFont),r.fontSize&&Object.entries(r.fontSize).forEach(([s,n])=>{this.container.style.setProperty(`--metakyc-font-size-${s}`,n)}),r.fontWeight&&Object.entries(r.fontWeight).forEach(([s,n])=>{this.container.style.setProperty(`--metakyc-font-weight-${s}`,n.toString())}))}applySpacing(r){r&&Object.entries(r).forEach(([s,n])=>{const a=`--metakyc-${this.kebabCase(s)}`;this.container.style.setProperty(a,n)})}injectInputColors(){this.inputStyleElement&&this.inputStyleElement.remove(),this.inputStyleElement=document.createElement("style"),this.inputStyleElement.id="metakyc-input-colors",this.inputStyleElement.textContent=ts(),this.customStyleElement&&this.customStyleElement.parentNode?document.head.insertBefore(this.inputStyleElement,this.customStyleElement):document.head.appendChild(this.inputStyleElement)}injectCustomCSS(r){this.customStyleElement&&this.customStyleElement.remove(),this.customStyleElement=document.createElement("style"),this.customStyleElement.id="metakyc-custom-css",this.customStyleElement.textContent=r,document.head.appendChild(this.customStyleElement)}mergeWithDefault(r){var s;return{name:r.name||Re.name,title:r.title||Re.title,logo:{...Re.logo,...r.logo},colors:{...Re.colors,...r.colors},typography:r.typography?{...Re.typography,...r.typography}:Re.typography,spacing:r.spacing?{...Re.spacing,...r.spacing}:Re.spacing,customCSS:r.customCSS,darkMode:r.darkMode?{colors:{...(s=Re.darkMode)==null?void 0:s.colors,...r.darkMode.colors}}:Re.darkMode,applicantFormVisibleFields:r.applicantFormVisibleFields,applicantFormRequiredFields:r.applicantFormRequiredFields,allowedLanguages:r.allowedLanguages,applicantFormPages:r.applicantFormPages,reviewPageFields:r.reviewPageFields,reviewPageDisabled:r.reviewPageDisabled,fieldLabelMode:r.fieldLabelMode,companyFormVisibleFields:r.companyFormVisibleFields,companyFormRequiredFields:r.companyFormRequiredFields,companyFormPages:r.companyFormPages,companyReviewPageFields:r.companyReviewPageFields}}getCurrentTheme(){return this.currentTheme}resetTheme(){this.applyTheme(Re)}cleanup(){this.inputStyleElement&&(this.inputStyleElement.remove(),this.inputStyleElement=null),this.customStyleElement&&(this.customStyleElement.remove(),this.customStyleElement=null)}kebabCase(r){return r.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}}const vt=i.createContext(null),gr="1.0.6",Ct="metakyc-critical-css",rs=`
52
+ `}class fr{constructor(r){pe(this,"currentTheme",Re);pe(this,"customStyleElement",null);pe(this,"inputStyleElement",null);pe(this,"container");this.container=r||document.documentElement}applyTheme(r){this.currentTheme=this.mergeWithDefault(r),this.applyColors(this.currentTheme.colors),this.currentTheme.typography&&this.applyTypography(this.currentTheme.typography),this.currentTheme.spacing&&this.applySpacing(this.currentTheme.spacing),this.currentTheme.customCSS&&this.injectCustomCSS(this.currentTheme.customCSS),console.log("[ThemeManager] Theme applied:",this.currentTheme.name||"Custom")}applyColors(r){var n;const s={primary:r.primary,"primary-hover":r.primaryHover,"primary-light":r.primaryLight,"primary-dark":r.primaryDark,secondary:r.secondary,"secondary-hover":r.secondaryHover,success:r.success,warning:r.warning,danger:r.danger,info:r.info,background:r.background,surface:r.surface,border:r.border,"text-primary":r.textPrimary,"text-secondary":r.textSecondary,"text-muted":r.textMuted,"input-bg":r.inputBg||r.background,"input-text":r.inputText||r.textPrimary,"input-border":r.inputBorder||r.border,"input-border-focus":r.inputBorderFocus||r.primary,"input-placeholder":r.inputPlaceholder||r.textMuted};Object.entries(s).forEach(([a,o])=>{o&&this.container.style.setProperty(`--metakyc-${a}`,o)}),this.injectInputColors(),(n=this.currentTheme.darkMode)!=null&&n.colors&&this.applyDarkModeColors(this.currentTheme.darkMode.colors)}applyDarkModeColors(r){Object.entries(r).forEach(([s,n])=>{if(n){const a=`--metakyc-dark-${this.kebabCase(s)}`;this.container.style.setProperty(a,n)}})}applyTypography(r){r&&(r.fontFamily&&this.container.style.setProperty("--metakyc-font-family",r.fontFamily),r.headingFont&&this.container.style.setProperty("--metakyc-heading-font",r.headingFont),r.fontSize&&Object.entries(r.fontSize).forEach(([s,n])=>{this.container.style.setProperty(`--metakyc-font-size-${s}`,n)}),r.fontWeight&&Object.entries(r.fontWeight).forEach(([s,n])=>{this.container.style.setProperty(`--metakyc-font-weight-${s}`,n.toString())}))}applySpacing(r){r&&Object.entries(r).forEach(([s,n])=>{const a=`--metakyc-${this.kebabCase(s)}`;this.container.style.setProperty(a,n)})}injectInputColors(){this.inputStyleElement&&this.inputStyleElement.remove(),this.inputStyleElement=document.createElement("style"),this.inputStyleElement.id="metakyc-input-colors",this.inputStyleElement.textContent=ts(),this.customStyleElement&&this.customStyleElement.parentNode?document.head.insertBefore(this.inputStyleElement,this.customStyleElement):document.head.appendChild(this.inputStyleElement)}injectCustomCSS(r){this.customStyleElement&&this.customStyleElement.remove(),this.customStyleElement=document.createElement("style"),this.customStyleElement.id="metakyc-custom-css",this.customStyleElement.textContent=r,document.head.appendChild(this.customStyleElement)}mergeWithDefault(r){var s;return{name:r.name||Re.name,title:r.title||Re.title,logo:{...Re.logo,...r.logo},colors:{...Re.colors,...r.colors},typography:r.typography?{...Re.typography,...r.typography}:Re.typography,spacing:r.spacing?{...Re.spacing,...r.spacing}:Re.spacing,customCSS:r.customCSS,darkMode:r.darkMode?{colors:{...(s=Re.darkMode)==null?void 0:s.colors,...r.darkMode.colors}}:Re.darkMode,applicantFormVisibleFields:r.applicantFormVisibleFields,applicantFormRequiredFields:r.applicantFormRequiredFields,allowedLanguages:r.allowedLanguages,applicantFormPages:r.applicantFormPages,reviewPageFields:r.reviewPageFields,reviewPageDisabled:r.reviewPageDisabled,fieldLabelMode:r.fieldLabelMode,companyFormVisibleFields:r.companyFormVisibleFields,companyFormRequiredFields:r.companyFormRequiredFields,companyFormPages:r.companyFormPages,companyReviewPageFields:r.companyReviewPageFields}}getCurrentTheme(){return this.currentTheme}resetTheme(){this.applyTheme(Re)}cleanup(){this.inputStyleElement&&(this.inputStyleElement.remove(),this.inputStyleElement=null),this.customStyleElement&&(this.customStyleElement.remove(),this.customStyleElement=null)}kebabCase(r){return r.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}}const vt=i.createContext(null),gr="1.0.7",Ct="metakyc-critical-css",rs=`
53
53
  .metakyc-sdk{background-color:var(--metakyc-background,#fff)!important;color:var(--metakyc-text-primary,#111827)!important;color-scheme:light!important;line-height:1.5;-webkit-text-size-adjust:100%}
54
54
  .metakyc-sdk *,.metakyc-sdk *::before,.metakyc-sdk *::after{box-sizing:border-box;border-width:0;border-style:solid;border-color:var(--metakyc-border,#e5e7eb)}
55
55
  .metakyc-sdk .metakyc-card{background-color:var(--metakyc-surface,#fff)!important}
@@ -108,5 +108,5 @@ a:hover { color: ${r}; }
108
108
  *
109
109
  * This source code is licensed under the ISC license.
110
110
  * See the LICENSE file in the root directory of this source tree.
111
- */const ks=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],Or=Dr("chevron-right",ks);function js(t,r){const s=!r||r.length===0||r.every(n=>!n||!n.trim());if(t.isRequired&&s)return t.errorMessage||"This field is required";if(!s){const n=r[0]??"";if(n&&t.regex)try{if(!new RegExp(t.regex).test(n))return t.errorMessage||"Invalid format"}catch{}if(n!==""){const a=Number(n);if(!isNaN(a)&&n.trim()!==""){if(t.min!==void 0&&t.min!==null&&a<t.min)return`Minimum value is ${t.min}`;if(t.max!==void 0&&t.max!==null&&a>t.max)return`Maximum value is ${t.max}`}else{if(t.min!==void 0&&t.min!==null&&n.length<t.min)return`Minimum length is ${t.min} characters`;if(t.max!==void 0&&t.max!==null&&n.length>t.max)return`Maximum length is ${t.max} characters`}}}return null}function ws(t){const r=t.flatMap((n,a)=>(n.questions??[]).map((o,c)=>({question:o,groupIndex:a,qIdx:c}))),s=new Map;for(const n of r){const a=n.question.pageNumber!=null&&n.question.pageNumber>0?n.question.pageNumber:1;s.has(a)||s.set(a,[]),s.get(a).push(n)}return Array.from(s.entries()).sort(([n],[a])=>n-a).map(([,n])=>n)}const zr=({applicantId:t,onComplete:r,onBack:s})=>{const{questionnaire:n,initialAnswers:a,isLoading:o,isSubmitting:c,error:d,submit:y}=Nr(t),[p,g]=i.useState({}),[T,v]=i.useState({}),[E,A]=i.useState(0);i.useEffect(()=>{a&&Object.keys(a).length>0&&Object.keys(p).length===0&&g(a)},[a]);const k=i.useMemo(()=>n?ws(n.questionGroups):[],[n]),S=E===k.length-1,M=k[E]??[],Y=i.useCallback((R,f)=>{g(O=>({...O,[R]:f})),v(O=>{const q={...O};return delete q[R],q})},[]),L=i.useCallback(()=>{const R={};for(const{question:f}of M){const O=js(f,p[f.id]??[]);O&&(R[f.id]=O)}return v(f=>({...f,...R})),Object.keys(R).length===0},[M,p]),B=()=>{L()&&A(R=>R+1)},U=()=>{E>0?A(R=>R-1):s==null||s()},X=async()=>{if(!(!L()||!n))try{const R=n.questionGroups.flatMap(O=>(O.questions??[]).map(q=>({questionId:q.id,values:p[q.id]??[]}))),f={applicantId:t,questionnarieId:n.id,questionResults:R};await y(f),r==null||r()}catch(R){console.error("Questionnaire submit error:",R)}};return o?e.jsx(ee,{children:e.jsx(te,{children:e.jsx(Ee,{className:"my-8"})})}):d?e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading questionnaire: ",d.message]})})}):n?e.jsxs(ee,{children:[e.jsxs(fe,{children:[e.jsx("h2",{className:"text-lg font-bold",children:n.displayName}),n.subtitle&&e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:n.subtitle}),k.length>1&&e.jsxs("div",{className:"flex items-center justify-between mt-3",children:[e.jsxs("span",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:["Page ",E+1," of ",k.length]}),e.jsx("div",{className:"flex items-center gap-1.5",children:k.map((R,f)=>e.jsx("div",{className:"rounded-full transition-all duration-200",style:{height:"6px",width:f===E?"20px":"6px",backgroundColor:f<=E?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},f))})]})]}),e.jsx(te,{className:"space-y-6",children:M.map(({question:R})=>e.jsx(Ss,{question:R,value:p[R.id]??[],error:T[R.id],onChange:f=>Y(R.id,f)},R.id))}),e.jsxs(ge,{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs(J,{type:"button",variant:"outline",onClick:U,style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(Mr,{size:14}),E>0?"Previous":"Back"]}),S?e.jsx(J,{type:"button",isLoading:c,onClick:X,children:"Continue"}):e.jsxs(J,{type:"button",onClick:B,style:{display:"flex",alignItems:"center",gap:"4px"},children:["Next",e.jsx(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},Ss=({question:t,value:r,error:s,onChange:n})=>{var c;const o=(((c=t.defaultAnswers)==null?void 0:c.length)??0)>0?t.showAsDropdown?t.canMultipleAnswer?"multi-select":"single-select":t.canMultipleAnswer?"checkbox":"radio":"text";return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[t.text,t.isRequired&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),t.subtitle&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:t.subtitle}),t.description&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:t.description}),o==="text"&&e.jsx(ye,{value:r[0]??"",onChange:d=>n([d.target.value]),placeholder:t.subtitle?void 0:"Enter your answer…",error:s,required:t.isRequired}),o==="single-select"&&e.jsx(mt,{value:r[0]??"",onChange:d=>n([d.target.value]),options:(t.defaultAnswers??[]).map(d=>({value:d,label:d})),placeholder:"Select an option…",error:s,required:t.isRequired}),o==="radio"&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultAnswers??[]).map(d=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"radio",checked:r[0]===d,onChange:()=>n([d]),className:"metakyc-option-input",style:{width:"16px",height:"16px",minWidth:"16px",flexShrink:0,flexGrow:0,accentColor:"var(--metakyc-primary, #2563eb)",cursor:"pointer",margin:0,padding:0,display:"inline-block",verticalAlign:"middle"}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:d})]},d)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),(o==="checkbox"||o==="multi-select")&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultAnswers??[]).map(d=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx(Fe,{checked:r.includes(d),onChange:y=>{n(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)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),s&&o==="text"&&null]})};function Cs(t){const r=new Map;for(const s of t){const n=s.pageNumber!=null&&s.pageNumber>0?s.pageNumber:1;r.has(n)||r.set(n,[]),r.get(n).push(s)}return Array.from(r.entries()).sort(([s],[n])=>s-n).map(([,s])=>s)}const $r=({applicantId:t,onComplete:r,onBack:s})=>{const{uploadDocument:n,isLoading:a,isSubmitting:o,error:c,submit:d}=Rr(t),[y,p]=i.useState({}),[g,T]=i.useState(null),[v,E]=i.useState(0),[A,k]=i.useState({}),S=i.useMemo(()=>n?Cs(n.uploadDocumentFiles):[],[n]),M=S[v]??[],Y=v===S.length-1,L=S.length,B=i.useCallback(()=>{const f={};for(const O of M)O.isRequired&&(y[O.id]||[]).length===0&&(f[O.id]=`${O.displayName} is required`);return k(f),Object.keys(f).length===0},[M,y]),U=()=>{B()&&(E(f=>f+1),k({}))},X=()=>{v>0?(E(f=>f-1),k({})):s==null||s()},R=async()=>{if(!(!B()||!n)){T(null);try{const f=await Promise.all(n.uploadDocumentFiles.map(async q=>{const Q=y[q.id]||[],$=await Promise.all(Q.map(async G=>({fileName:G.name,fileData:await br(G)})));return{uploadDocumentFileId:q.id,valueList:$}})),O={applicantId:t,uploadDocumentId:n.id,uploadDocumentResults:f};await d(O),r==null||r()}catch(f){T((f==null?void 0:f.message)||"Failed to submit documents. Please try again.")}}};return a?e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"48px 0",gap:"16px"},children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)"},children:"Loading document requirements..."})]})})}):c?e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"32px 0",gap:"12px",textAlign:"center"},children:[e.jsx("div",{style:{width:"48px",height:"48px",borderRadius:"50%",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 10%, transparent)",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),e.jsx("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]})}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-danger, #ef4444)",fontWeight:500},children:"Error loading document requirements"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-muted, #9ca3af)"},children:c.message})]})})}):n?e.jsxs(ee,{children:[e.jsxs(fe,{children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:n.displayName||"Upload Documents"}),n.subtitle&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",marginTop:"4px"},children:n.subtitle}),L>1&&e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginTop:"12px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)"},children:["Page ",v+1," of ",L]}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:S.map((f,O)=>e.jsx("div",{style:{height:"6px",width:O===v?"20px":"6px",borderRadius:"999px",transition:"all 0.2s ease",backgroundColor:O<=v?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},O))})]})]}),n.description&&v===0&&e.jsxs("div",{style:{margin:"0 24px",marginTop:"4px",display:"flex",gap:"10px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-primary, #2563eb) 5%, var(--metakyc-background, #ffffff))",border:"1px solid color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-primary, #2563eb)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:"1px"},children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-secondary, #374151)",margin:0,lineHeight:1.5},children:n.description})]}),e.jsx(te,{children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"24px"},children:M.map(f=>e.jsx(Fr,{label:f.displayName,subtitle:f.subtitle,accept:f.allowedTypes,multiple:f.multipleFile,maxSize:f.maxEachFileSizeByte,required:f.isRequired,error:A[f.id],value:y[f.id]||[],onChange:O=>{T(null),k(q=>{const Q={...q};return delete Q[f.id],Q}),p(q=>({...q,[f.id]:O}))}},f.id))})}),g&&e.jsxs("div",{style:{margin:"0 24px",padding:"10px 14px",borderRadius:"8px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:g})]}),e.jsx(ge,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[e.jsx(J,{type:"button",variant:"outline",onClick:X,children:v>0?"Previous":"Back"}),Y?e.jsx(J,{type:"button",isLoading:o,onClick:R,children:o?"Uploading...":"Continue"}):e.jsx(J,{type:"button",onClick:U,children:"Next"})]})})]}):null},Br=({applicantId:t,onComplete:r,onBack:s})=>{const{overview:n,isLoading:a,isSubmitting:o,error:c,passOverview:d}=Ir(t),y=async()=>{await d(),r==null||r()};return a?e.jsx(ee,{children:e.jsx(te,{children:e.jsx(Ee,{className:"my-8"})})}):c?e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading overview: ",c.message]})})}):n?e.jsxs(ee,{children:[e.jsxs(fe,{children:[e.jsx("h2",{className:"text-lg font-bold",children:n.title||"Overview"}),n.description&&e.jsx("p",{className:"mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:n.description})]}),e.jsx(te,{className:"space-y-8",children:n.steps&&n.steps.length>0?n.steps.sort((p,g)=>p.order-g.order).map(p=>e.jsxs("div",{className:"metakyc-overview-step-item flex items-center space-x-3",children:[e.jsx("div",{className:"metakyc-step-icon flex-shrink-0",children:e.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center font-medium text-sm",style:{backgroundColor:"var(--metakyc-primary, #2563eb)",color:"#ffffff"},children:p.order+1})}),e.jsxs("div",{className:"metakyc-step-content",style:{flex:1,border:"none",height:"auto",background:"transparent"},children:[e.jsx("span",{className:"metakyc-step-title text-sm font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:p.title}),p.description&&e.jsx("p",{className:"metakyc-step-description text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:p.description})]})]},p.order)):e.jsx("div",{className:"text-center py-8",children:e.jsx("p",{style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Loading overview data..."})})}),e.jsxs(ge,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{onClick:y,isLoading:o,children:"Continue"})]})]}):null};function Ns(t){const r=(t??"en").toLowerCase().replace("_","-");try{return Intl.NumberFormat.supportedLocalesOf([r]),r}catch{return"en"}}function Rs(t){return t.valueDataType===Me.Money&&Array.isArray(t.defaultValues)&&t.defaultValues.length>0}function Is(t,r){const s=new Intl.NumberFormat(Ns(r),{minimumFractionDigits:0,maximumFractionDigits:2});return t.replace(/([\d]+(?:\.\d+)?)/g,n=>{const a=parseFloat(n);return isNaN(a)?n:s.format(a)})}function Es(t,r){const s=!r||r.length===0||r.every(n=>!n||!n.trim());if(t.isRequired&&s)return t.errorMessage||`${t.displayName} is required`;if(!s){const n=r[0]??"";if(n&&t.regex)try{if(!new RegExp(t.regex).test(n))return t.errorMessage||"Invalid format"}catch{}const a=t.valueDataType===Me.Integer||t.valueDataType===Me.Money||t.valueDataType===Me.DigitOnly;if(a&&n.trim()!==""){const o=Number(n);if(!isNaN(o)){if(t.min!==void 0&&t.min!==null&&o<t.min)return`Minimum value is ${t.min}`;if(t.max!==void 0&&t.max!==null&&o>t.max)return`Maximum value is ${t.max}`}}else if(!a&&n!==""){if(t.min!==void 0&&t.min!==null&&n.length<t.min)return`Minimum length is ${t.min} characters`;if(t.max!==void 0&&t.max!==null&&n.length>t.max)return`Maximum length is ${t.max} characters`}}return null}function As(t){const r=new Map;return t.forEach((s,n)=>{const a=s.pageNumber!=null&&s.pageNumber>0?s.pageNumber:1;r.has(a)||r.set(a,[]),r.get(a).push({criterion:s,idx:n})}),Array.from(r.entries()).sort(([s],[n])=>s-n).map(([,s])=>s)}function Ts(t){return t.builtInType===1?"country":!t.defaultValues||t.defaultValues.length===0?"text":t.multipleValue?"checkbox":"radio"}const _r=({applicantId:t,onComplete:r,onBack:s})=>{const{config:n}=Ne(),a=n.locale??"en",{criteria:o,initialAnswers:c,isLoading:d,isSubmitting:y,error:p,submit:g}=Ar(t),[T,v]=i.useState({}),[E,A]=i.useState({}),[k,S]=i.useState(0),[M,Y]=i.useState(!1);i.useEffect(()=>{c&&Object.keys(c).length>0&&Object.keys(T).length===0&&v(c)},[c]);const L=i.useMemo(()=>o&&o.length>0?As(o):[],[o]),B=k===L.length-1,U=L[k]??[];i.useEffect(()=>{!d&&o&&o.length===0&&!M&&!y&&(Y(!0),g({applicantId:t,criteriaValueInputs:[]}).then(()=>r==null?void 0:r()).catch(console.error))},[d,o,M,y,g,t,r]);const X=i.useCallback((Q,$)=>{v(G=>({...G,[Q]:$})),A(G=>{const se={...G};return delete se[Q],se})},[]),R=i.useCallback(()=>{const Q={};for(const{criterion:$}of U){const G=Es($,T[$.id]??[]);G&&(Q[$.id]=G)}return A($=>({...$,...Q})),Object.keys(Q).length===0},[U,T]),f=()=>{R()&&S(Q=>Q+1)},O=()=>{k>0?S(Q=>Q-1):s==null||s()},q=async()=>{if(!(!R()||!o))try{const Q=o.map(G=>{const se=(T[G.id]??[]).filter(V=>V&&V.trim());return se.length>0?{riskCriteriaId:G.id,values:se}:null}).filter(G=>G!==null);await g({applicantId:t,criteriaValueInputs:Q}),r==null||r()}catch(Q){console.error("Risk scoring submit error:",Q)}};return d?e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center text-sm mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Loading risk scoring criteria…"})]})}):!d&&o&&o.length===0?e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center text-sm mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"No criteria required. Moving to next step…"})]})}):p?e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading criteria: ",p.message]})})}):o?e.jsxs(ee,{children:[e.jsxs(fe,{children:[e.jsx("h2",{className:"text-lg font-bold",children:"Risk Assessment"}),e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Please answer the following questions for risk evaluation"}),L.length>1&&e.jsxs("div",{className:"flex items-center justify-between mt-3",children:[e.jsxs("span",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:["Page ",k+1," of ",L.length]}),e.jsx("div",{className:"flex items-center gap-1.5",children:L.map((Q,$)=>e.jsx("div",{className:"rounded-full transition-all duration-200",style:{height:"6px",width:$===k?"20px":"6px",backgroundColor:$<=k?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},$))})]})]}),e.jsx(te,{className:"space-y-6",children:U.map(({criterion:Q})=>e.jsx(Fs,{criterion:Q,value:T[Q.id]??[],error:E[Q.id],locale:a,onChange:$=>X(Q.id,$)},Q.id))}),e.jsxs(ge,{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs(J,{type:"button",variant:"outline",onClick:O,style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(Mr,{size:14}),k>0?"Previous":"Back"]}),B?e.jsx(J,{type:"button",isLoading:y,onClick:q,children:"Continue"}):e.jsxs(J,{type:"button",onClick:f,style:{display:"flex",alignItems:"center",gap:"4px"},children:["Next",e.jsx(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},Fs=({criterion:t,value:r,error:s,locale:n,onChange:a})=>{const o=Ts(t),c=t.valueDataType===Me.Integer||t.valueDataType===Me.Money||t.valueDataType===Me.DigitOnly,d=Rs(t),y=p=>d?Is(p,n):p;return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[t.displayName,t.isRequired&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),t.description&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:t.description}),c&&(t.min!==void 0||t.max!==void 0)&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:t.min!==void 0&&t.max!==void 0?`Range: ${t.min} – ${t.max}`:t.min!==void 0?`Minimum: ${t.min}`:`Maximum: ${t.max}`}),o==="text"&&e.jsx(ye,{value:r[0]??"",onChange:p=>a([p.target.value]),type:c?"number":"text",placeholder:"Enter your answer…",error:s,required:t.isRequired,min:t.min,max:t.max,onKeyDown:p=>{t.valueDataType===Me.DigitOnly&&["e","E","+","-","."].includes(p.key)&&p.preventDefault()}}),o==="radio"&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultValues??[]).map(p=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"radio",checked:r[0]===p,onChange:()=>a([p]),className:"metakyc-option-input",style:{width:"16px",height:"16px",minWidth:"16px",flexShrink:0,flexGrow:0,accentColor:"var(--metakyc-primary, #2563eb)",cursor:"pointer",margin:0,padding:0,display:"inline-block",verticalAlign:"middle"}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:y(p)})]},p)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),o==="checkbox"&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultValues??[]).map(p=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx(Fe,{checked:r.includes(p),onChange:g=>{a(g?[...r,p]:r.filter(T=>T!==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)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),o==="country"&&e.jsx(mt,{value:r[0]??"",onChange:p=>a([p.target.value]),options:[{value:"US",label:"United States"},{value:"GB",label:"United Kingdom"},{value:"DE",label:"Germany"},{value:"FR",label:"France"},{value:"AE",label:"United Arab Emirates"}],placeholder:"Select a country…",error:s,required:t.isRequired})]})},Hr=({applicantId:t,onComplete:r,onBack:s})=>{const{investorCategorizationService:n}=Ne(),[a,o]=i.useState(null),[c,d]=i.useState(!1),[y,p]=i.useState(null),g=async T=>{if(T.preventDefault(),a===null){p("Please select an investor type");return}d(!0),p(null);try{const v={applicantId:t,investorType:a};console.log("Submitting investor categorization:",v);const E=await n.setInvestorCategorization(v);console.log("Investor categorization result:",E),r==null||r()}catch(v){console.error("Error submitting investor categorization:",v),p(v.message||"Failed to submit investor categorization")}finally{d(!1)}};return e.jsx("form",{onSubmit:g,children:e.jsxs(ee,{children:[e.jsxs(fe,{children:[e.jsx("h2",{className:"text-lg font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Which statement best describes you?"}),e.jsx("p",{className:"mt-2",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"All Tokenise clients are treated as Retail Investors under EU regulation, which gives you the highest level of investor protection. For our internal purposes, we ask you to select the description that best matches your situation"})]}),e.jsxs(te,{className:"space-y-4",children:[e.jsx("p",{className:"text-sm font-medium mb-3",style:{color:"var(--metakyc-text-secondary, #374151)"},children:"Choose one"}),e.jsx("label",{className:"block p-4 border-2 rounded-lg cursor-pointer transition-all",style:{borderColor:a===je.Individual?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:a===je.Individual?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:je.Individual,checked:a===je.Individual,onChange:()=>o(je.Individual),className:"mt-1"}),e.jsxs("div",{className:"ml-3",children:[e.jsx("div",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Individual investor"}),e.jsx("div",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"(Recommended) Most of our clients choose this option. Provides the strongest protection and aligns with our mission to make investing accessible to everyone."})]})]})}),e.jsx("label",{className:"block p-4 border-2 rounded-lg cursor-pointer transition-all",style:{borderColor:a===je.Sophisticated?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:a===je.Sophisticated?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:je.Sophisticated,checked:a===je.Sophisticated,onChange:()=>o(je.Sophisticated),className:"mt-1"}),e.jsxs("div",{className:"ml-3",children:[e.jsx("div",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Sophisticated investor"}),e.jsx("div",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"In the last 2 years, I have done one or more of the following:"}),e.jsxs("ul",{className:"text-sm mt-2 space-y-1 list-none",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:[e.jsx("li",{children:"Worked in private equity or provided capital to small and medium enterprises, and/or"}),e.jsx("li",{children:"Been the director of a company with an annual turnover of at least (USD) $2m million, and/or"}),e.jsx("li",{children:"Invested directly in at least 2 private (not listed) companies."})]})]})]})}),e.jsx("label",{className:"block p-4 border-2 rounded-lg cursor-pointer transition-all",style:{borderColor:a===je.HighNetWorth?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:a===je.HighNetWorth?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:je.HighNetWorth,checked:a===je.HighNetWorth,onChange:()=>o(je.HighNetWorth),className:"mt-1"}),e.jsxs("div",{className:"ml-3",children:[e.jsx("div",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"High networth investor"}),e.jsxs("div",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:["I earn more than (USD/EUR) $150,000 per year, and/or",e.jsx("br",{}),"I have net assets (excluding my main property) of at least $/EUR 300,000"]})]})]})}),y&&e.jsx("div",{className:"p-4 rounded-lg",style:{backgroundColor:"#fee2e2",border:"1px solid #fca5a5"},children:e.jsxs("p",{className:"text-sm",style:{color:"#991b1b"},children:[e.jsx("strong",{children:"Error:"})," ",y]})})]}),e.jsxs(ge,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"submit",isLoading:c,disabled:a===null,children:"Submit"})]})]})})};function Et(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),s=t%60;return`${r.toString().padStart(2,"0")}:${s.toString().padStart(2,"0")}`}const Wr=({applicantId:t,onComplete:r,onBack:s})=>{const{appropriatenessTestService:n}=Ne(),[a,o]=i.useState(null),[c,d]=i.useState(!0),[y,p]=i.useState(!1),[g,T]=i.useState(null),[v,E]=i.useState({}),[A,k]=i.useState(0),[S,M]=i.useState(!1),[Y,L]=i.useState(!1),[B,U]=i.useState(0),[X,R]=i.useState(0),[f,O]=i.useState(null);i.useEffect(()=>{(async()=>{try{d(!0),T(null);const z=await n.getAppropriatenessTest(t);if(o(z),z.waitTimeSpanForNextTry&&z.waitTimeSpanForNextTry!=="00:00:00"){const _=Et(z.waitTimeSpanForNextTry);_>0&&U(_)}}catch(z){T(z.message||"Failed to load appropriateness test")}finally{d(!1)}})()},[t,n]),i.useEffect(()=>{if(!S||A<=0)return;const z=setInterval(()=>{k(_=>_<=1?(L(!0),0):_-1)},1e3);return()=>clearInterval(z)},[S,A]),i.useEffect(()=>{if(B<=0)return;const z=setInterval(()=>{U(_=>_<=1?0:_-1)},1e3);return()=>clearInterval(z)},[B]),i.useEffect(()=>{Y&&!y&&G()},[Y]);const q=()=>{a&&(M(!0),k(a.testDurationSec),R(0),E({}),T(null))},Q=(z,_)=>{E(me=>({...me,[z]:_}))},$=i.useCallback(async()=>{try{const z=await n.getAppropriatenessTest(t);if(o(z),z.waitTimeSpanForNextTry&&z.waitTimeSpanForNextTry!=="00:00:00"){const _=Et(z.waitTimeSpanForNextTry);_>0&&U(_)}}catch{}},[t,n]),G=async z=>{if(a){if(!Y){const _=a.appropriatenessQuestions.length-Object.keys(v).length;if(_>0){T(`Please answer all questions. ${_} remaining.`);return}}p(!0),T(null);try{const _=a.appropriatenessQuestions.map(N=>({appropriatenessQuestionId:N.id,value:v[N.id]||""})),me={applicantId:t,appropriatenessTestId:a.id,appropriatenessQuestionResults:_};try{const N=await n.fillAppropriatenessTest(me);N.isSuccess?O({success:!0,message:N.message||"Congratulations! You have passed the test."}):(O({success:!1,message:N.message||"You did not pass the test."}),setTimeout(()=>$(),1e3))}catch(N){if(N.code===400&&N.message)O({success:!1,message:N.message}),setTimeout(()=>$(),1500);else throw N}}catch(_){T(_.message||"Failed to submit test. Please try again."),se()}finally{p(!1)}}},se=()=>{M(!1),L(!1),E({}),R(0)};if(c)return e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"48px 0",gap:"16px"},children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)"},children:"Loading test..."})]})})});if(!a)return e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("div",{style:{textAlign:"center",padding:"48px 0"},children:[e.jsx("p",{style:{fontSize:"16px",fontWeight:600,color:"var(--metakyc-danger, #ef4444)"},children:"No test data available"}),g&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"8px"},children:g})]})})});const V=a.testAllowedMaxTry-a.totalFailedTries,be=a.appropriatenessQuestions.length,ce=Object.keys(v).length;if(B>0)return e.jsxs(ee,{children:[e.jsx(fe,{children:e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:a.displayName})}),e.jsx(te,{children:e.jsxs("div",{style:{textAlign:"center",padding:"32px 0"},children:[e.jsx("div",{style:{width:"100px",height:"100px",borderRadius:"50%",margin:"0 auto 20px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"color-mix(in srgb, var(--metakyc-primary, #2563eb) 8%, transparent)"},children:e.jsx("span",{style:{fontSize:"28px",fontWeight:700,color:"var(--metakyc-primary, #2563eb)",fontVariantNumeric:"tabular-nums"},children:xt(B)})}),e.jsx("p",{style:{fontSize:"15px",fontWeight:500,color:"var(--metakyc-text-primary, #111827)"},children:"Please wait before retrying"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"4px"},children:"You can attempt the test again once the timer expires"}),g&&e.jsx("div",{style:{marginTop:"20px",padding:"12px 16px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:g})})]})})]});if(f){const z=()=>{O(null),se(),T(null)};return e.jsxs(ee,{children:[e.jsx(te,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",textAlign:"center",padding:"40px 16px",gap:"16px"},children:[e.jsx("div",{style:{width:"72px",height:"72px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:f.success?"color-mix(in srgb, var(--metakyc-success, #10b981) 12%, transparent)":"color-mix(in srgb, var(--metakyc-danger, #ef4444) 10%, transparent)"},children:f.success?e.jsxs("svg",{width:"36",height:"36",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-success, #10b981)",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),e.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]}):e.jsxs("svg",{width:"36",height:"36",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),e.jsx("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]})}),e.jsx("h2",{style:{fontSize:"20px",fontWeight:700,color:f.success?"var(--metakyc-success, #10b981)":"var(--metakyc-danger, #ef4444)",margin:0},children:f.success?"Test Passed":"Test Failed"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",margin:0,lineHeight:1.6,maxWidth:"400px",whiteSpace:"pre-line"},children:f.message}),!f.success&&V>0&&e.jsx("div",{style:{marginTop:"4px",padding:"10px 20px",borderRadius:"10px",backgroundColor:"var(--metakyc-surface, #f9fafb)",border:"1px solid var(--metakyc-border, #e5e7eb)"},children:e.jsxs("p",{style:{fontSize:"13px",color:"var(--metakyc-text-muted, #9ca3af)",margin:0},children:["You have ",e.jsx("strong",{style:{color:"var(--metakyc-text-primary, #111827)"},children:V})," attempt",V!==1?"s":""," remaining"]})}),!f.success&&V<=0&&e.jsx("div",{style:{marginTop:"4px",padding:"10px 20px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:"No attempts remaining. Please contact support for assistance."})})]})}),e.jsx(ge,{children:e.jsx("div",{style:{display:"flex",justifyContent:"center",width:"100%",gap:"12px"},children:f.success?e.jsx(J,{type:"button",onClick:()=>r==null?void 0:r(),children:"Continue"}):e.jsxs(e.Fragment,{children:[V>0&&B<=0&&e.jsx(J,{type:"button",onClick:z,children:"Retake Test"}),V>0&&B>0&&e.jsx(J,{type:"button",onClick:z,children:"OK"}),V<=0&&s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"})]})})})]})}if(!S)return e.jsxs(ee,{children:[e.jsxs(fe,{children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:a.displayName}),a.subtitle&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",marginTop:"4px"},children:a.subtitle})]}),e.jsxs(te,{children:[a.description&&e.jsxs("div",{style:{marginBottom:"20px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-primary, #2563eb) 5%, var(--metakyc-background, #ffffff))",border:"1px solid color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)",display:"flex",gap:"10px"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-primary, #2563eb)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:"1px"},children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-secondary, #374151)",margin:0,lineHeight:1.5},children:a.description})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px",marginBottom:"20px"},children:[e.jsx(ct,{icon:"questions",label:"Questions",value:String(a.totalQuestionCount)}),e.jsx(ct,{icon:"time",label:"Time Limit",value:xt(a.testDurationSec)}),e.jsx(ct,{icon:"target",label:"Pass Requirement",value:`${a.testCorrectAnswerPassLimit} correct`}),e.jsx(ct,{icon:"retry",label:"Attempts Left",value:String(V),variant:V<=1?"warning":"default"})]}),g&&e.jsxs("div",{style:{marginBottom:"16px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)",display:"flex",gap:"10px"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:"1px"},children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),e.jsxs("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0,lineHeight:1.5},children:[e.jsx("strong",{children:"Previous attempt:"})," ",g]})]}),V<=0&&e.jsx("div",{style:{padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:"You have used all your attempts. Please contact support for assistance."})})]}),e.jsx(ge,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:s?"space-between":"flex-end",width:"100%"},children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"button",onClick:q,disabled:V<=0,children:"Start Test"})]})})]});const de=a.appropriatenessQuestions[X],he=X===be-1,I=ce===be,W=A<=60;return e.jsxs(ee,{children:[e.jsxs(fe,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:a.displayName}),e.jsxs("p",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"2px"},children:["Question ",X+1," of ",be]})]}),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(A)})]})]}),e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsx("div",{style:{height:"4px",borderRadius:"999px",backgroundColor:"var(--metakyc-border, #e5e7eb)",overflow:"hidden"},children:e.jsx("div",{style:{height:"100%",borderRadius:"999px",backgroundColor:"var(--metakyc-primary, #2563eb)",width:`${ce/be*100}%`,transition:"width 0.3s ease"}})}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:"4px"},children:[e.jsxs("span",{style:{fontSize:"11px",color:"var(--metakyc-text-muted, #9ca3af)"},children:[ce," answered"]}),e.jsxs("span",{style:{fontSize:"11px",color:"var(--metakyc-text-muted, #9ca3af)"},children:[V," attempt",V!==1?"s":""," left"]})]})]})]}),e.jsxs(te,{children:[de&&e.jsx(Ls,{question:de,index:X,selectedAnswer:v[de.id],onSelect:z=>Q(de.id,z),disabled:y}),be>1&&e.jsx("div",{style:{display:"flex",justifyContent:"center",gap:"6px",marginTop:"20px",flexWrap:"wrap"},children:a.appropriatenessQuestions.map((z,_)=>e.jsx("button",{type:"button",onClick:()=>R(_),style:{width:"28px",height:"28px",borderRadius:"8px",border:_===X?"2px solid var(--metakyc-primary, #2563eb)":"1px solid var(--metakyc-border, #e5e7eb)",backgroundColor:v[z.id]?_===X?"color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)":"color-mix(in srgb, var(--metakyc-primary, #2563eb) 8%, transparent)":_===X?"var(--metakyc-surface, #f9fafb)":"var(--metakyc-background, #ffffff)",color:v[z.id]?"var(--metakyc-primary, #2563eb)":"var(--metakyc-text-muted, #9ca3af)",fontSize:"12px",fontWeight:600,cursor:"pointer",transition:"all 0.15s ease",padding:0,display:"flex",alignItems:"center",justifyContent:"center"},children:_+1},z.id))}),Y&&e.jsxs("div",{style:{marginTop:"16px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, #f59e0b 10%, transparent)",border:"1px solid color-mix(in srgb, #f59e0b 25%, transparent)",display:"flex",alignItems:"center",gap:"10px"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"#f59e0b",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),e.jsx("p",{style:{fontSize:"13px",color:"#b45309",margin:0,fontWeight:500},children:"Time's up! Your answers are being submitted."})]}),g&&!Y&&e.jsx("div",{style:{marginTop:"16px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:g})})]}),e.jsx(ge,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[e.jsx(J,{type:"button",variant:"outline",onClick:()=>{X>0?R(z=>z-1):s==null||s()},disabled:y,children:X>0?"Previous":"Cancel"}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[!he&&e.jsx(J,{type:"button",onClick:()=>R(z=>z+1),children:"Next"}),(he||I)&&e.jsx(J,{type:"button",isLoading:y,onClick:()=>G(),disabled:!I&&!Y,style:{opacity:I||Y?1:.5},children:Y?"Submitting...":"Submit Test"})]})]})})]})},Ps={questions:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M9 11l3 3L22 4"}),e.jsx("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),time:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),target:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("circle",{cx:"12",cy:"12",r:"6"}),e.jsx("circle",{cx:"12",cy:"12",r:"2"})]}),retry:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})},ct=({icon:t,label:r,value:s,variant:n="default"})=>{const a=n==="warning";return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px",padding:"14px",borderRadius:"10px",backgroundColor:a?"color-mix(in srgb, #f59e0b 8%, transparent)":"var(--metakyc-surface, #f9fafb)",border:a?"1px solid color-mix(in srgb, #f59e0b 20%, transparent)":"1px solid var(--metakyc-border, #e5e7eb)"},children:[e.jsx("div",{style:{color:a?"#f59e0b":"var(--metakyc-primary, #2563eb)",flexShrink:0},children:Ps[t]}),e.jsxs("div",{children:[e.jsx("p",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)",margin:0},children:r}),e.jsx("p",{style:{fontSize:"15px",fontWeight:600,color:a?"#b45309":"var(--metakyc-text-primary, #111827)",margin:0,marginTop:"1px"},children:s})]})]})},Ls=({question:t,selectedAnswer:r,onSelect:s,disabled:n})=>e.jsxs("div",{children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[t.groupName&&e.jsx("span",{style:{display:"inline-block",fontSize:"11px",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em",color:"var(--metakyc-primary, #2563eb)",marginBottom:"8px"},children:t.groupName}),e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--metakyc-text-primary, #111827)",margin:0,lineHeight:1.5},children:t.question})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.answers.map((a,o)=>{const c=r===a;return e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"12px",padding:"14px 16px",borderRadius:"10px",border:`2px solid ${c?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}`,backgroundColor:c?"color-mix(in srgb, var(--metakyc-primary, #2563eb) 5%, var(--metakyc-background, #ffffff))":"var(--metakyc-background, #ffffff)",cursor:n?"default":"pointer",transition:"all 0.15s ease",opacity:n?.6:1},onMouseEnter:d=>{!n&&!c&&(d.currentTarget.style.borderColor="color-mix(in srgb, var(--metakyc-primary, #2563eb) 50%, var(--metakyc-border, #e5e7eb))")},onMouseLeave:d=>{c||(d.currentTarget.style.borderColor="var(--metakyc-border, #e5e7eb)")},children:[e.jsx("div",{style:{width:"20px",height:"20px",borderRadius:"50%",border:`2px solid ${c?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #d1d5db)"}`,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,transition:"border-color 0.15s ease"},children:c&&e.jsx("div",{style:{width:"10px",height:"10px",borderRadius:"50%",backgroundColor:"var(--metakyc-primary, #2563eb)"}})}),e.jsx("input",{type:"radio",name:`q-${t.id}`,value:a,checked:c,onChange:()=>s(a),disabled:n,style:{position:"absolute",opacity:0,width:0,height:0}}),e.jsx("span",{style:{fontSize:"14px",color:c?"var(--metakyc-text-primary, #111827)":"var(--metakyc-text-secondary, #6b7280)",fontWeight:c?500:400,transition:"color 0.15s ease"},children:a})]},o)})})]}),Ur=({applicantId:t,onComplete:r,onBack:s})=>{var Je,$e,tt,Ke;const{applicantService:n,baseInformationService:a,identityService:o,config:c,currentTheme:d}=Ne(),{identityData:y,provider:p,token:g,isLoading:T,error:v,requestIdentity:E,restartIdentity:A}=Er(t),[k,S]=i.useState(null),[M,Y]=i.useState(null),[L,B]=i.useState([]),[U,X]=i.useState([]),[R,f]=i.useState(!0),[O,q]=i.useState(!1),[Q,$]=i.useState(null),[G,se]=i.useState(!1),V=i.useRef(!1),[be,ce]=i.useState({}),[de,he]=i.useState({}),I=d!=null&&d.reviewPageFields&&d.reviewPageFields.length>0?d.reviewPageFields[0]:null,W=!!(d!=null&&d.reviewPageDisabled),z=i.useRef(!1);z.current=W;const _=Ve.useForm({defaultValues:{street:"",streetNumber:"",city:"",zip:"",country:"",nationality:"",phonenumber:""}});i.useEffect(()=>{if(W){V.current||(V.current=!0,E().then(()=>q(!0)).catch(D=>console.error("[Identity] Auto-request failed:",D)).finally(()=>f(!1)));return}(async()=>{try{const[D,K,H]=await Promise.all([n.getApplicantData(t),a.getCountries("","en"),a.getCountries("","en",40)]);Y(D);const Z=new Set,m=K.map(h=>({value:h.abbreviation3||h.abbreviation,label:h.name})).filter(h=>!h.value||Z.has(h.value)?!1:(Z.add(h.value),!0));B(m);const C=new Set,F=H.filter(h=>h.countryCode).map(h=>({value:h.countryCode,label:`${h.countryCode} – ${h.name}`})).filter(h=>C.has(h.value)?!1:(C.add(h.value),!0));X(F);const u=D.applicantRequestData;if(ce({firstName:(u==null?void 0:u.firstName)||"",lastName:(u==null?void 0:u.lastName)||"",email:(u==null?void 0:u.email)||"",dateOfBirth:(u==null?void 0:u.dateOfBirth)||"",title:(u==null?void 0:u.title)||"",salutation:(u==null?void 0:u.salutation)||"",phonenumber:(u==null?void 0:u.phonenumber)||"",mobileCountryCode:(u==null?void 0:u.mobileCountryCode)||"",street:(u==null?void 0:u.street)||"",streetNumber:(u==null?void 0:u.streetNumber)||"",city:(u==null?void 0:u.city)||"",zip:(u==null?void 0:u.zip)||"",country:(u==null?void 0:u.country)||"",nationality:(u==null?void 0:u.nationality)||"",taxCountry:(u==null?void 0:u.taxCountry)||"",countryOfBirth:(u==null?void 0:u.countryOfBirth)||"",placeOfBirth:(u==null?void 0:u.placeOfBirth)||"",educationLevel:(u==null?void 0:u.educationLevel)||"",occupation:(u==null?void 0:u.occupation)||"",taxNumber:(u==null?void 0:u.taxNumber)||"",defaultLanguage:(u==null?void 0:u.defaultLanguage)||""}),_.reset({street:(u==null?void 0:u.street)||"",streetNumber:(u==null?void 0:u.streetNumber)||"",city:(u==null?void 0:u.city)||"",zip:(u==null?void 0:u.zip)||"",country:(u==null?void 0:u.country)||"",nationality:(u==null?void 0:u.nationality)||"",phonenumber:(u==null?void 0:u.phonenumber)||""}),D.kycRecords&&D.kycRecords.length>0&&D.kycRecords[0].providerTokenObject!==null&&!V.current&&z.current){console.log("[Identity] Review page disabled + existing identity — auto-requesting..."),V.current=!0;try{await E(),q(!0)}catch(h){console.error("[Identity] Auto-request failed:",h)}}}catch(D){console.error("Error loading applicant data:",D)}finally{f(!1)}})()},[t]),i.useEffect(()=>{y&&!O&&z.current&&(console.log("[Identity] Review page disabled — showing cached provider"),q(!0))},[y,O]),i.useEffect(()=>{if(g){if(g.expiresAt){const x=new Date(g.expiresAt).getTime();if(Date.now()>=x){console.warn("[Identity] Token has expired (expiresAt)"),se(!0),$("Your verification session has expired. Please restart.");return}}if(g.url)try{const D=new URL(g.url).toString().toLowerCase();if(D.includes("expired")||D.includes("invalid")||D.includes("error")){console.warn("[Identity] Token URL indicates expiration"),se(!0),$("Your verification link has expired. Please restart.");return}}catch{console.error("[Identity] Invalid token URL")}if(g.status==="expired"||g.error==="expired"||g.expired===!0){console.warn("[Identity] Token object indicates expiration"),se(!0),$("Your verification session has expired. Please restart.");return}}},[g]);const me=p!==null&&p===Ae.Sumsub;i.useEffect(()=>{if(p!==null&&g&&!k&&O&&!G){const x=p;if(me){console.log("[Sumsub] Fetching access token for Web SDK…"),$(null),(async()=>{try{const D=await o.refreshSumsubToken(t),K=He.parseProviderConfig(p,g,c);K.accessToken=D,K.onTokenRefresh=()=>o.refreshSumsubToken(t);const H=He.createProvider(p,K);H.onComplete(Z=>{console.log("[Sumsub] Verification complete:",Z),r==null||r()}),H.onError(Z=>{console.error("[Sumsub] SDK error:",Z),(typeof Z=="string"?Z:(Z==null?void 0:Z.message)||"Unknown error").toLowerCase().includes("expired")&&(se(!0),$("Session expired. Please restart."))}),await H.initialize("sumsub-websdk-container"),console.log("[Sumsub] Web SDK launched"),S(H)}catch(D){console.error("[Sumsub] Initialization error:",D),$(`Failed to initialize: ${D.message||D}`),String(D.message||D).toLowerCase().includes("expired")&&se(!0)}})();return}if(g.url){console.log("[Identity] Loading provider URL for user verification:",g.url),$(null);try{if(new URL(g.url),x===Ae.SardinAI){console.log("[SardinAI] Initializing Risk SDK in background...");try{const D=He.parseProviderConfig(p,g,c);He.createProvider(p,D).initialize().then(()=>console.log("[SardinAI] Risk SDK initialized in background")).catch(H=>console.warn("[SardinAI] Risk SDK init failed (non-blocking):",H))}catch(D){console.warn("[SardinAI] Risk SDK setup failed (non-blocking):",D)}}S({type:"url",url:g.url})}catch(D){console.error("[Identity] Invalid URL:",D),$("Invalid verification URL. Please restart."),se(!0)}return}if(x===Ae.SardinAI){console.log("[SardinAI] No URL provided - initializing Risk SDK only..."),$(null);try{const D=He.parseProviderConfig(p,g,c),K=He.createProvider(p,D);K.initialize().then(()=>{console.log("[SardinAI] Risk SDK initialized successfully"),S(K),setTimeout(()=>r==null?void 0:r(),2e3)}).catch(H=>{var m;console.error("[SardinAI] Failed to initialize:",H);const Z=((m=H.message)==null?void 0:m.toLowerCase())||"";Z.includes("expired")||Z.includes("invalid")||Z.includes("401")||Z.includes("400")?(se(!0),$("Session expired or invalid. Please restart verification.")):$(`Failed to initialize: ${H.message}`)})}catch(D){console.error("[SardinAI] Error creating provider:",D),$(`Configuration error: ${D.message}`)}return}try{$(null);const D=He.parseProviderConfig(p,g,c),K=He.createProvider(p,D);x===Ae.Onfido&&K.initialize("identity-container").catch(H=>{console.error("[Onfido] Initialization error:",H),$(`Failed to initialize: ${H.message}`)}),S(K)}catch(D){console.error("[Identity] Provider setup error:",D),$(`Setup error: ${D.message}`)}}return()=>{if(k&&k.destroy)try{k.destroy()}catch(x){console.error("[Identity] Error destroying provider:",x)}}},[p,g,k,O,r,G,me,t,c,o]);const N=async()=>{try{$(null),se(!1),await E(),q(!0)}catch(x){console.error("Error starting identity verification:",x)}},re=async()=>{try{$(null),se(!1),S(null),console.log("[Identity] Restarting verification..."),await A(),q(!0)}catch(x){console.error("Error restarting identity verification:",x),$(x.message||"Failed to restart verification")}};if(R||T)return e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-4",children:"Loading identity verification..."})]})});if(v)return e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("p",{className:"text-danger-500",children:["Error: ",v.message]})})});if(O&&(Q||G))return e.jsxs(ee,{children:[e.jsx(fe,{children:e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"Verification Session Issue"})}),e.jsxs(te,{children:[e.jsx("div",{className:"p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg mb-6",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("svg",{className:"h-6 w-6 text-red-600 dark:text-red-400 mr-3 mt-0.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-red-900 dark:text-red-100 mb-1",children:G?"Session Expired":"Verification Error"}),e.jsx("p",{className:"text-red-800 dark:text-red-200 text-sm",children:Q||"Your verification session has expired and needs to be restarted."})]})]})}),e.jsxs("div",{className:"bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-4",children:[e.jsx("h3",{className:"font-semibold text-blue-900 dark:text-blue-100 mb-2",children:"What to do next:"}),e.jsxs("ul",{className:"text-blue-800 dark:text-blue-200 text-sm space-y-1 list-disc list-inside",children:[e.jsx("li",{children:'Click "Restart Verification" below to generate a new session'}),e.jsx("li",{children:"Complete the verification process without delays"}),e.jsx("li",{children:"If issues persist, contact support"})]})]})]}),e.jsxs(ge,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"button",onClick:re,disabled:T,children:T?"Restarting...":"Restart Verification"})]})]});if(O&&y){const x=p;return me?e.jsxs("div",{style:{background:"var(--metakyc-background, #ffffff)",borderRadius:"12px",border:"1px solid var(--metakyc-border, #e5e7eb)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"20px 24px",borderBottom:"1px solid var(--metakyc-border, #e5e7eb)"},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{margin:0,fontSize:"20px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)"},children:"Identity Verification"}),e.jsx("p",{style:{margin:"4px 0 0",fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)"},children:"Please complete the identity verification process"})]}),e.jsx("button",{type:"button",onClick:re,disabled:T,style:{padding:"6px 14px",fontSize:"13px",fontWeight:500,borderRadius:"8px",border:"1px solid var(--metakyc-border, #d1d5db)",background:"var(--metakyc-background, #ffffff)",color:"var(--metakyc-text-primary, #111827)",cursor:T?"not-allowed":"pointer",opacity:T?.5:1},children:T?"Restarting…":"Restart"})]}),e.jsx("div",{id:"sumsub-websdk-container",style:{minHeight:"520px",width:"100%",padding:"16px 24px",background:"var(--metakyc-background, #ffffff)"}}),s&&e.jsx("div",{style:{padding:"16px 24px",borderTop:"1px solid var(--metakyc-border, #e5e7eb)"},children:e.jsx(J,{variant:"outline",onClick:s,children:"Back"})})]}):g!=null&&g.url?e.jsxs(ee,{children:[e.jsx(fe,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Identity Verification"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:"Please complete the identity verification process"})]}),e.jsx(J,{type:"button",variant:"outline",size:"sm",onClick:re,disabled:T,children:"Restart"})]})}),e.jsxs(te,{children:[e.jsx("div",{className:"mb-4 p-3 bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg",children:e.jsxs("p",{className:"text-yellow-800 dark:text-yellow-200 text-sm",children:[e.jsx("strong",{children:"Important:"}),' If you see an "expired" or "invalid link" message below, click the "Restart" button above to generate a new verification session.']})}),e.jsx("div",{className:"w-full",style:{height:"600px"},children:e.jsx("iframe",{src:g.url,className:"w-full h-full border-0 rounded-lg",allow:"camera; microphone; geolocation",title:"Identity Verification",onLoad:D=>{var K,H,Z;console.log("[Identity] Iframe loaded");try{const m=D.target,C=m.contentDocument||((K=m.contentWindow)==null?void 0:K.document);if(C){const F=((Z=(H=C.body)==null?void 0:H.textContent)==null?void 0:Z.toLowerCase())||"";(F.includes("expired")||F.includes("invalid")||F.includes("error"))&&(console.warn("[Identity] Iframe shows expiration message"),se(!0),$("Your verification link has expired."))}}catch{console.log("[Identity] Cannot check iframe content (CORS)")}}})})]}),s&&e.jsx(ge,{children:e.jsx(J,{variant:"outline",onClick:s,children:"Back"})})]}):x===Ae.SardinAI?e.jsxs(ee,{children:[e.jsxs(fe,{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Device Risk Assessment"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:"Analyzing device security and behavioral patterns..."})]}),e.jsx(te,{children:e.jsxs("div",{className:"text-center py-12",children:[e.jsx(Ee,{className:"mb-4"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Please wait while we verify your device security"}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-500 mt-2",children:"This process is automatic and will complete in a few seconds"})]})})]}):e.jsxs(ee,{children:[e.jsxs(fe,{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Identity Verification"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:"Please complete the identity verification process"})]}),e.jsx(te,{children:e.jsx("div",{id:"identity-container",className:"min-h-[400px]"})}),s&&e.jsx(ge,{children:e.jsx(J,{variant:"outline",onClick:s,children:"Back"})})]})}const ue=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),ne=(x=4)=>{const D=Math.min(4,Math.max(1,Number(x)||4));return{gridColumn:`span ${D} / span ${D}`}},ve=(x,D)=>{if(!D&&D!==0)return"—";if(ue.has(x)&&x!=="mobileCountryCode"){const K=L.find(H=>H.value===D);return K?K.label:String(D)}return String(D)},Pe=({helpText:x})=>{const[D,K]=i.useState(!1),H=i.useRef(null),[,Z]=i.useState({top:0,left:0}),m=()=>{if(H.current){const C=H.current.getBoundingClientRect();Z({top:C.bottom+window.scrollY+6,left:C.left+window.scrollX})}K(!0)};return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"metakyc-help-btn",ref:H,onClick:m,style:{width:18,height:18,borderRadius:"50%",border:"1.5px solid var(--metakyc-primary, #2563eb)",background:"transparent",color:"var(--metakyc-primary, #2563eb)",fontSize:11,fontWeight:700,cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,lineHeight:1,position:"relative",zIndex:2},children:"?"}),D&&pt.createPortal(e.jsx("div",{style:{position:"fixed",inset:0,zIndex:99999,background:"rgba(0,0,0,0.55)",backdropFilter:"blur(6px)",WebkitBackdropFilter:"blur(6px)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:()=>K(!1),children:e.jsxs("div",{onClick:C=>C.stopPropagation(),style:{background:"var(--metakyc-surface, var(--metakyc-background, #ffffff))",border:"1px solid var(--metakyc-border, #e5e7eb)",borderRadius:"var(--metakyc-border-radius, 8px)",padding:"20px 24px",maxWidth:400,width:"90%",boxShadow:"0 24px 64px rgba(0,0,0,0.4)"},children:[e.jsx("div",{dangerouslySetInnerHTML:{__html:x},style:{fontSize:13,color:"var(--metakyc-text-primary, #111827)",lineHeight:1.6}}),e.jsx("button",{type:"button",onClick:()=>K(!1),style:{marginTop:12,padding:"4px 12px",fontSize:12,border:"1px solid var(--metakyc-border, #e5e7eb)",borderRadius:"var(--metakyc-border-radius, 6px)",background:"transparent",cursor:"pointer",color:"var(--metakyc-text-secondary, #6b7280)"},children:"Close"})]})}),document.body)]})},ke=(x,D)=>D?e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:5,flexWrap:"nowrap"},children:[e.jsx("div",{style:{flex:1,minWidth:0},children:x}),e.jsx("div",{style:{paddingTop:24},children:e.jsx(Pe,{helpText:D})})]}):x,ze=(x,D)=>{const K=`cf-${D}`,H=x.paramName??"",Z=de[H];if(x.customType==="br")return e.jsx("div",{style:{...ne(x.colSpan),minHeight:"0.5rem"}},K);if(x.customType==="paragraph")return e.jsx("div",{style:ne(x.colSpan),children:e.jsx("div",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:x.label||""}})},K);if(x.customType==="html")return e.jsx("div",{style:ne(x.colSpan),dangerouslySetInnerHTML:{__html:x.label||""}},K);if(x.customType==="link")return e.jsx("div",{style:ne(x.colSpan),children:ke(e.jsx("a",{href:x.linkUrl??"#",target:"_blank",rel:"noopener noreferrer",className:"text-sm underline",style:{color:"var(--metakyc-primary, #6366f1)"},children:x.displayText||x.label||x.linkText||x.linkUrl}),x.helpText)},K);if(x.customType==="checkbox"||x.customType==="link_checkbox"){const m=Z==="true"||Z===!0;return e.jsx("div",{style:ne(x.colSpan),children:ke(e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx(Fe,{checked:!!m,onChange:C=>he(F=>({...F,[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)},K)}if(x.customType==="group_checkbox"){const m=Array.isArray(Z)?Z:Z?[Z]:[],C=F=>{x.singleSelect?he(u=>({...u,[H]:m[0]===F?[]:[F]})):he(u=>({...u,[H]:m.includes(F)?m.filter(l=>l!==F):[...m,F]}))};return e.jsx("div",{style:ne(x.colSpan),children:ke(e.jsxs("div",{className:"space-y-1.5",children:[x.label&&e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:x.displayText||x.label}),(x.options||[]).map(F=>e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx(Fe,{checked:m.includes(F.value),onChange:()=>C(F.value),style:{marginTop:2}}),e.jsx("span",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)"},children:F.label})]},F.value))]}),x.helpText)},K)}return x.customType==="radio_group"?e.jsx("div",{style:ne(x.colSpan),children:ke(e.jsxs("div",{className:"space-y-1.5",children:[x.label&&e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:x.displayText||x.label}),(x.options||[]).map(m=>e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"radio",name:`rg-${H}`,value:m.value,checked:Z===m.value,onChange:()=>he(C=>({...C,[H]:m.value})),style:{width:16,height:16,flexShrink:0,marginTop:2,accentColor:"var(--metakyc-primary, #6366f1)"}}),e.jsx("span",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)"},children:m.label})]},m.value))]}),x.helpText)},K):e.jsx("div",{style:ne(x.colSpan),children:ke(e.jsx(ye,{label:x.displayText||x.label||H,value:String(Z??""),onChange:m=>he(C=>({...C,[H]:m.target.value}))}),x.helpText)},K)},et=(x,D)=>{if(x.isCustom)return ze(x,D);const K=x.name??"",H=Ge[K],Z=x.displayText||(H==null?void 0:H.label)||K,m=be[K]??"",C=K==="mobileCountryCode",F=!!(H!=null&&H.countriesType)&&!C;return x.editable?C?e.jsx("div",{style:ne(x.colSpan??2),children:ke(e.jsx(Oe,{label:Z,value:String(m),onChange:u=>ce(l=>({...l,[K]:u})),options:[{value:"",label:"Select country code…"},...U]}),x.helpText)},`epc-${D}`):F?e.jsx("div",{style:ne(x.colSpan??2),children:ke(e.jsx(Oe,{label:Z,value:String(m),onChange:u=>ce(l=>({...l,[K]:u})),options:[{value:"",label:`Select ${Z.toLowerCase()}…`},...L]}),x.helpText)},`ec-${D}`):e.jsx("div",{style:ne(x.colSpan??2),children:ke(e.jsx(ye,{label:Z,type:(H==null?void 0:H.type)==="date"?"date":(H==null?void 0:H.type)==="email"?"email":"text",value:String(m),onChange:u=>ce(l=>({...l,[K]:u.target.value}))}),x.helpText)},`ei-${D}`):e.jsx("div",{style:ne(x.colSpan??2),children:ke(e.jsxs(e.Fragment,{children:[e.jsx("label",{className:"block text-sm font-medium mb-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:Z}),e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)",minHeight:"1.5rem"},children:ve(K,m)})]}),x.helpText)},`ro-${D}`)};if(I){const x=I.title||"Review Your Information",D=I.subtitle||"Please review and confirm your information before starting identity verification";return e.jsx("form",{onSubmit:K=>{K.preventDefault(),N()},children:e.jsxs(ee,{children:[e.jsxs(fe,{children:[e.jsx("h2",{className:"text-lg font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:x}),e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:D})]}),e.jsx(te,{children:e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:I.fields.map((K,H)=>et(K,H))})}),e.jsxs(ge,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"submit",isLoading:T,children:"Confirm and Start Verification"})]})]})})}return e.jsx("form",{onSubmit:_.handleSubmit(N),children:e.jsxs(ee,{children:[e.jsxs(fe,{children:[e.jsx("h2",{className:"text-lg font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Review Your Information"}),e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Please review and confirm your information before starting identity verification"})]}),e.jsxs(te,{className:"space-y-6",children:[e.jsx("div",{className:"space-y-4 pb-4",style:{borderBottom:"1px solid var(--metakyc-border, #e5e7eb)"},children:[{label:"Name",value:`${((Je=M==null?void 0:M.applicantRequestData)==null?void 0:Je.firstName)||""} ${(($e=M==null?void 0:M.applicantRequestData)==null?void 0:$e.lastName)||""}`.trim()},{label:"Email",value:(tt=M==null?void 0:M.applicantRequestData)==null?void 0:tt.email},{label:"Date of Birth",value:((Ke=M==null?void 0:M.applicantRequestData)==null?void 0:Ke.dateOfBirth)||"Not provided"}].map(({label:x,value:D})=>e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:x}),e.jsx("p",{className:"mt-1 text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:D})]},x))}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Address Information"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Ve.Controller,{control:_.control,name:"country",render:({field:x})=>e.jsx(Oe,{label:"Country",value:x.value,onChange:x.onChange,options:[{value:"",label:"Select country…"},...L]})}),e.jsx(Ve.Controller,{control:_.control,name:"nationality",render:({field:x})=>e.jsx(Oe,{label:"Nationality",value:x.value,onChange:x.onChange,options:[{value:"",label:"Select nationality…"},...L]})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Ve.Controller,{control:_.control,name:"street",render:({field:x})=>e.jsx(ye,{...x,label:"Street"})}),e.jsx(Ve.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(Ve.Controller,{control:_.control,name:"city",render:({field:x})=>e.jsx(ye,{...x,label:"City"})}),e.jsx(Ve.Controller,{control:_.control,name:"zip",render:({field:x})=>e.jsx(ye,{...x,label:"ZIP / Postal Code"})})]}),e.jsx(Ve.Controller,{control:_.control,name:"phonenumber",render:({field:x})=>e.jsx(ye,{...x,label:"Phone Number",type:"tel"})})]})]}),e.jsxs(ge,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"submit",isLoading:T,children:"Confirm and Start Verification"})]})]})})},gt=({kycStatus:t,reviewStatus:r,workflowResult:s,customMessage:n,onContinue:a,onContactSupport:o})=>{const d=t===Ye.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===Ye.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===Ye.Pending||t===Ye.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."}:s===ot.Success?{type:"success",title:"Process Complete",icon:"✓",iconBg:"bg-green-100 dark:bg-green-900/30",iconColor:"text-green-600 dark:text-green-400",message:"Your verification process has been completed successfully."}:s===ot.Failed?{type:"error",title:"Process Failed",icon:"✕",iconBg:"bg-red-100 dark:bg-red-900/30",iconColor:"text-red-600 dark:text-red-400",message:"The verification process could not be completed."}:s===ot.AdminReview?{type:"pending",title:"Admin Review Required",icon:"📋",iconBg:"bg-yellow-100 dark:bg-yellow-900/30",iconColor:"text-yellow-700 dark:text-yellow-400",message:"Your application requires administrator review."}:{type:"pending",title:"Processing",icon:"⏱",iconBg:"bg-blue-100 dark:bg-blue-900/30",iconColor:"text-blue-600 dark:text-blue-400",message:"Your application is being reviewed."};return e.jsxs(ee,{children:[e.jsxs(te,{className:"py-12",children:[e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx("div",{className:`w-24 h-24 rounded-full flex items-center justify-center ${d.iconBg}`,children:e.jsx("span",{className:`text-5xl ${d.iconColor}`,children:d.icon})})}),e.jsx("h2",{className:"text-3xl font-bold text-center mb-4",style:{color:"var(--metakyc-text-primary, #111827)"},children:d.title}),e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx(jt,{variant:d.type==="success"?"success":d.type==="error"?"danger":d.type==="pending"?"warning":"info",children:t!=null?Ye[t]:Qe[r]})}),e.jsx("p",{className:"text-center mb-6 max-w-md mx-auto",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:n||d.message}),d.type==="success"&&e.jsxs("div",{className:"bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg p-4 mb-6",children:[e.jsx("h3",{className:"font-semibold text-green-900 dark:text-green-100 mb-2",children:"What's Next?"}),e.jsxs("ul",{className:"text-sm text-green-800 dark:text-green-200 space-y-1",children:[e.jsx("li",{children:"✓ Your identity has been verified"}),e.jsx("li",{children:"✓ You can now proceed with your application"}),e.jsx("li",{children:"✓ All features are now accessible"})]})]}),d.type==="error"&&e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 mb-6",children:[e.jsx("h3",{className:"font-semibold text-red-900 dark:text-red-100 mb-2",children:"What Can You Do?"}),e.jsxs("ul",{className:"text-sm text-red-800 dark:text-red-200 space-y-2",children:[e.jsx("li",{children:"• Review the requirements and ensure all information is correct"}),e.jsx("li",{children:"• Contact our support team for assistance"}),e.jsx("li",{children:"• You may be able to resubmit your application"})]})]}),d.type==="pending"&&e.jsxs("div",{className:"bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-4 mb-6",children:[e.jsx("h3",{className:"font-semibold text-blue-900 dark:text-blue-100 mb-2",children:"What Happens Next?"}),e.jsxs("ul",{className:"text-sm text-blue-800 dark:text-blue-200 space-y-2",children:[e.jsx("li",{children:"• Our team is reviewing your information"}),e.jsx("li",{children:"• You will be notified via email once the review is complete"}),e.jsx("li",{children:"• This typically takes 24-48 hours"}),e.jsx("li",{children:"• No action is required from you at this time"})]})]}),e.jsx("div",{className:"mt-6 pt-6",style:{borderTop:"1px solid var(--metakyc-border, #e5e7eb)"},children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"KYC Status:"}),e.jsx("div",{className:"font-medium mt-1",style:{color:"var(--metakyc-text-primary, #111827)"},children:t!=null?Ye[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(ge,{style:{display:"flex",justifyContent:"center",gap:"1rem"},children:[d.type==="success"&&a&&e.jsx(J,{onClick:a,size:"lg",children:"Continue"}),d.type==="error"&&e.jsxs(e.Fragment,{children:[o&&e.jsx(J,{variant:"outline",onClick:o,children:"Contact Support"}),a&&e.jsx(J,{onClick:a,children:"Try Again"})]}),d.type==="pending"&&e.jsx("div",{className:"text-center",children:e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Please check back later or wait for our email notification"})})]})]})},Kr=({config:t,className:r=""})=>!(t!=null&&t.visible)||!(t!=null&&t.url)?null:e.jsx("div",{className:`metakyc-logo ${r}`,children:e.jsx("img",{src:t.url,alt:t.alt||"Company Logo",style:{width:t.width||"auto",height:t.height||"40px",maxWidth:"100%",objectFit:"contain"},onError:s=>{console.warn("[Logo] Failed to load logo:",t.url),s.target.style.display="none"}})}),at=({title:t,subtitle:r,className:s=""})=>{const{currentTheme:n}=Ne(),a=t||(n==null?void 0:n.title)||"",o=!!(n!=null&&n.logo&&n.logo.visible&&n.logo.url),c=!!a;return!o&&!c?null:e.jsxs("div",{className:`metakyc-header ${s}`,children:[e.jsxs("div",{className:"metakyc-header-title flex items-center text-xl font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:[o&&e.jsx(Kr,{config:n.logo}),o&&c&&e.jsx("span",{style:{fontSize:"1.5rem",fontWeight:300,color:"var(--metakyc-text-muted, #9ca3af)",margin:"0 12px"},children:"|"}),c&&e.jsx("span",{style:{color:"var(--metakyc-text-primary, #111827)"},children:a})]}),r&&e.jsx("p",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:r})]})},dt=["firstName","lastName","email","phonenumber","dateOfBirth"];function rt(t){return t==null||t===""||Array.isArray(t)&&t.length===0}const Ds={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"},At=({helpText:t,children:r})=>{const[s,n]=i.useState(!1);if(!t)return e.jsx(e.Fragment,{children:r});const a=s?e.jsx("div",{role:"dialog","aria-modal":"true",onClick:()=>n(!1),style:{position:"fixed",inset:0,zIndex:999999,background:"rgba(0, 0, 0, 0.55)",backdropFilter:"blur(6px)",WebkitBackdropFilter:"blur(6px)",display:"flex",alignItems:"center",justifyContent:"center",padding:"16px"},children:e.jsxs("div",{onClick:o=>o.stopPropagation(),style:{background:"var(--metakyc-surface, var(--metakyc-background, #ffffff))",border:"1px solid var(--metakyc-border, #e5e7eb)",borderRadius:"12px",padding:"28px 24px 24px",maxWidth:"480px",width:"100%",maxHeight:"80vh",overflowY:"auto",boxShadow:"0 24px 64px rgba(0,0,0,0.4)",position:"relative"},children:[e.jsx("button",{type:"button",onClick:()=>n(!1),"aria-label":"Close",style:{position:"absolute",top:"12px",right:"12px",width:"28px",height:"28px",borderRadius:"50%",border:"1px solid var(--metakyc-border, #e5e7eb)",background:"var(--metakyc-input-bg, #f3f4f6)",color:"var(--metakyc-text-secondary, #6b7280)",fontSize:"16px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:"×"}),e.jsx("div",{style:{color:"var(--metakyc-text-primary, #111827)",fontSize:"14px",lineHeight:1.75},dangerouslySetInnerHTML:{__html:t}})]})}):null;return e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"5px",flexWrap:"nowrap"},children:[r,e.jsx("button",{type:"button",className:"metakyc-help-btn",onClick:()=>n(!0),"aria-label":"Help",style:{flexShrink:0,marginTop:"2px",width:"18px",height:"18px",borderRadius:"50%",border:"1.5px solid var(--metakyc-primary, #2563eb)",background:"transparent",color:"var(--metakyc-primary, #2563eb)",fontSize:"10px",fontWeight:"700",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,padding:0,position:"relative",zIndex:2,transition:"background 0.15s, color 0.15s"},onMouseEnter:o=>{o.currentTarget.style.background="var(--metakyc-primary, #2563eb)",o.currentTarget.style.color="#ffffff"},onMouseLeave:o=>{o.currentTarget.style.background="transparent",o.currentTarget.style.color="var(--metakyc-primary, #2563eb)"},children:"?"}),typeof document<"u"&&a?pt.createPortal(a,document.body):null]})},Ms=({workflowKey:t,externalRefId:r,onSuccess:s,onCancel:n})=>{var K,H,Z,m,C,F,u;const{config:a,baseInformationService:o,currentTheme:c}=Ne(),{createApplicant:d,isLoading:y}=kt(),p=t||((K=a.applicantForm)==null?void 0:K.workflowKey);if(!p)throw new Error("workflowKey is required. Provide it either as a prop to CreateApplicantForm or set it in config.applicantForm.workflowKey");const g=r||((H=a.applicantForm)==null?void 0:H.externalRefId)||"",T=((Z=a.applicantForm)==null?void 0:Z.email)||"",v=((m=a.applicantForm)==null?void 0:m.hiddenValues)||{},E=((C=a.applicantForm)==null?void 0:C.initialValues)||{},k=(((F=a.applicantForm)==null?void 0:F.fieldLabelMode)||(c==null?void 0:c.fieldLabelMode)||"label")!=="placeholder",S=i.useMemo(()=>c!=null&&c.applicantFormPages&&c.applicantFormPages.length>0?c.applicantFormPages:null,[c==null?void 0:c.applicantFormPages]),M=i.useMemo(()=>{const l=new Set(dt),h=c==null?void 0:c.applicantFormRequiredFields;if(h)for(const P of h)l.add(P);if(S)for(const P of S)for(const b of P.fields)!b.isCustom&&b.name&&b.required&&l.add(b.name);return Array.from(l)},[c==null?void 0:c.applicantFormRequiredFields,S]),Y=i.useMemo(()=>{var P;if(S){const b=S.flatMap(j=>j.fields).filter(j=>!j.isCustom&&j.name).map(j=>j.name),w=new Set(b);for(const j of dt)w.add(j);return Array.from(w)}let l;(P=a.applicantForm)!=null&&P.visibleFields?l=a.applicantForm.visibleFields:c!=null&&c.applicantFormVisibleFields&&c.applicantFormVisibleFields.length>0?l=c.applicantFormVisibleFields:l=Ut;const h=new Set(l);for(const b of dt)h.add(b);return Array.from(h)},[(u=a.applicantForm)==null?void 0:u.visibleFields,c==null?void 0:c.applicantFormVisibleFields,S]),L=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),B=i.useMemo(()=>{var h,P;const l=new Set;if(S)for(const b of S)for(const w of b.fields)!w.isCustom&&w.name&&L.has(w.name)&&l.add(w.countriesType??((h=Ge[w.name])==null?void 0:h.countriesType));else for(const b of Y)L.has(b)&&l.add((P=Ge[b])==null?void 0:P.countriesType);return l.size===0&&l.add(void 0),Array.from(l)},[Y,S]),[U,X]=i.useState({}),[R,f]=i.useState(!0),O=i.useRef(new Set),q=i.useRef(new Set);i.useEffect(()=>{if(!c)return;const l=B.filter(b=>{const w=b!=null?String(b):"all";return!q.current.has(w)&&!O.current.has(w)});if(l.length===0){B.every(w=>{const j=w!=null?String(w):"all";return q.current.has(j)})&&f(!1);return}f(!0);const h=l.map(b=>b!=null?String(b):"all");h.forEach(b=>O.current.add(b)),(async()=>{try{const b=await Promise.all(l.map(async w=>{const j=w!=null?String(w):"all",le=await o.getCountries("",a.locale||"en",w),ae=w===40,xe=new Set,Ie=le.map(ie=>ae&&ie.countryCode?{value:ie.countryCode,label:`${ie.countryCode} – ${ie.name}`}:{value:ie.abbreviation3||ie.abbreviation,label:ie.name}).filter(ie=>!ie.value||xe.has(ie.value)?!1:(xe.add(ie.value),!0));return q.current.add(j),O.current.delete(j),[j,Ie]}));X(w=>({...w,...Object.fromEntries(b)}))}catch(b){h.forEach(w=>O.current.delete(w)),console.error("Failed to load countries:",b)}finally{B.every(w=>{const j=w!=null?String(w):"all";return q.current.has(j)})&&f(!1)}})()},[B,c]);const Q=(l,h)=>{var w;const P=h??((w=Ge[l])==null?void 0:w.countriesType),b=P!=null?String(P):"all";return U[b]||[]},$={firstName:1,lastName:1,title:1,email:1,dateOfBirth:1,phonenumber:1,mobileCountryCode:1,street:1,streetNumber:1,zip:1,city:1,country:1,nationality:1,otherNationality:1,defaultLanguage:1,taxCountry:1,placeOfBirth:1,countryOfBirth:1,salutation:1,educationLevel:1,occupation:1,taxNumber:1},G=Object.fromEntries(Object.entries(v).filter(([l])=>l in $)),se=Object.fromEntries(Object.entries(E).filter(([l])=>l in $)),[V,be]=i.useState({workflowKey:p,firstName:"",lastName:"",title:"",email:T,dateOfBirth:"",phonenumber:"",externalRefId:g,mobileCountryCode:"",street:"",streetNumber:"",zip:"",city:"",country:"",nationality:"",otherNationality:[],defaultLanguage:"EN",taxCountry:"",placeOfBirth:"",countryOfBirth:"",salutation:null,educationLevel:"",occupation:"",taxNumber:"",...G,...se}),ce=Object.fromEntries(Object.entries(v).filter(([l])=>!(l in G)&&l!=="externalRefId"&&l!=="workflowKey")),[de,he]=i.useState({...ce}),[I,W]=i.useState(0),[z,_]=i.useState({}),[me,N]=i.useState(null),[re,ue]=i.useState(!1),ne=(l,h)=>be(P=>({...P,[l]:h})),ve=(l,h)=>he(P=>({...P,[l]:h})),Pe=l=>!l.conditionalOn||de[l.conditionalOn]==="true",ke=S&&I<S.length-1?I+1:-1,ze=S&&I>0?I-1:-1,et=l=>{var P;const h={};for(const b of l.fields)if(b.isCustom){if(b.customType==="paragraph"||b.customType==="html"||b.customType==="br"||b.customType==="link")continue;if(b.required&&b.paramName){const w=de[b.paramName],j=b.displayText||b.label||b.paramName;b.customType==="checkbox"||b.customType==="link_checkbox"?w!=="true"&&(h[b.paramName]=`${j} is required.`):(!w||w.trim()==="")&&(h[b.paramName]=`${j} is required.`)}}else if(b.name){const w=b.name;if(M.includes(w)&&rt(V[w])){const j=b.displayText||((P=Ge[w])==null?void 0:P.label)||w;h[w]=`${j} is required.`}}return h},Je=async()=>{if(!S)return;const l=S[I];if(l.conditionalOn&&!Pe(l)){_({}),ke>=0?W(ke):await $e();return}const h=et(l);if(Object.keys(h).length>0){_(h);return}_({}),ke>=0?W(ke):await $e()},$e=async()=>{if(S){let l={};for(const h of S)Pe(h)&&(l={...l,...et(h)});if(Object.keys(l).length>0){_(l);return}}ue(!0),N(null);try{if(!V.externalRefId||V.externalRefId.trim()===""){N("External Reference ID is required. Please pass it via config.applicantForm.externalRefId.");return}const l={workflowKey:V.workflowKey,externalRefId:V.externalRefId.trim()};if(S){for(const w of S)if(Pe(w)){for(const j of w.fields)if(!j.isCustom&&j.name){const le=j.name,ae=V[le];rt(ae)||(l[le]=ae)}}for(const w of dt)if(l[w]===void 0){const j=V[w];rt(j)||(l[w]=j)}}else Y.forEach(w=>{if(w==="externalRefId")return;const j=V[w];rt(j)||(l[w]=j)});const h=[];if(S){for(const w of S)if(Pe(w))for(const j of w.fields){if(!j.isCustom||!j.paramName||j.customType==="paragraph"||j.customType==="html"||j.customType==="br"||j.customType==="link")continue;const le=de[j.paramName]??"";let ae;if(j.customType==="checkbox"||j.customType==="link_checkbox")ae=le==="true"?"yes":"no";else if(ae=le,!ae&&!j.required)continue;h.push({paramName:j.paramName,value:ae})}}for(const[w,j]of Object.entries(G))l[w]===void 0&&!rt(j)&&(l[w]=j);const P=new Set(h.map(w=>w.paramName));for(const[w,j]of Object.entries(ce))!P.has(w)&&j&&h.push({paramName:w,value:j});h.length>0&&(l.applicantAdditionalDatas=h);const b=await d(l);s(b.applicantId)}catch(l){console.error("Error creating applicant:",l),N(l.message||"Failed to create applicant")}finally{ue(!1)}},tt=async l=>{var h;l.preventDefault();for(const P of M)if(rt(V[P])){const b=((h=Ge[P])==null?void 0:h.label)||P;N(`${b} is required.`);return}await $e()},Ke=(l,h,P,b,w)=>{var wt;const j=Ge[l];if(!j)return null;const le=M.includes(l),ae=z[l],xe=P||j.label,Ie=l in se,ie=h??l,Le={required:le},Be=w?w!=="placeholder":k,qe=Be?xe:void 0,qr=Be?"...":xe;switch(j.type){case"select":if(l==="country"||l==="nationality"||l==="taxCountry"||l==="countryOfBirth"||l==="mobileCountryCode"){const Ce=Q(l,b);return e.jsx(Oe,{...Le,label:qe,value:V[l]||"",onChange:Ze=>ne(l,Ze),options:[{value:"",label:`Select ${qr.toLowerCase()}`},...Ce],disabled:R,readOnly:Ie,error:ae},ie)}if(l==="salutation")return e.jsx(Oe,{...Le,label:qe,value:((wt=V[l])==null?void 0:wt.toString())||"",onChange:Ce=>ne(l,Ce?Number(Ce):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:ae},ie);if(l==="defaultLanguage"){const Ce=c!=null&&c.allowedLanguages&&c.allowedLanguages.length>0?ft.filter(Ze=>c.allowedLanguages.includes(Ze.value)):ft;return e.jsx(Oe,{...Le,label:qe,value:V[l]||"",onChange:Ze=>ne(l,Ze),options:[{value:"",label:Be?"Select language...":xe},...Ce],readOnly:Ie,error:ae},ie)}return null;case"multiselect":if(l==="otherNationality"){const Ce=Q(l,b);return e.jsx(Tr,{...Le,label:qe,value:V[l]||[],onChange:Ze=>ne(l,Ze),options:Ce,placeholder:Be?"Select other nationalities...":xe,disabled:R,readOnly:Ie},ie)}return null;case"date":return e.jsx(ye,{...Le,type:"date",label:qe,placeholder:Be?void 0:xe,value:V[l]||"",onChange:Ce=>ne(l,Ce.target.value),readOnly:Ie,error:ae},ie);case"email":return e.jsx(ye,{...Le,type:"email",label:qe,placeholder:Be?void 0:xe,value:V[l]||"",onChange:Ce=>ne(l,Ce.target.value),readOnly:Ie,error:ae},ie);case"tel":return e.jsx(ye,{...Le,type:"tel",label:qe,placeholder:Be?void 0:xe,value:V[l]||"",onChange:Ce=>ne(l,Ce.target.value),readOnly:Ie,error:ae},ie);default:return e.jsx(ye,{...Le,type:"text",label:qe,placeholder:Be?void 0:xe,value:V[l]||"",onChange:Ce=>ne(l,Ce.target.value),readOnly:Ie,error:ae},ie)}},x=(l,h)=>{const P=l.labelMode?l.labelMode!=="placeholder":k;if(l.customType==="paragraph"){const j=l.displayText||l.label||"";return e.jsx("p",{className:"metakyc-paragraph",style:{fontSize:"14px",lineHeight:"1.7",margin:0,color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:j}},`custom-${h}`)}if(l.customType==="html")return e.jsx("div",{dangerouslySetInnerHTML:{__html:l.label||""}},`custom-${h}`);if(l.customType==="br")return e.jsx("div",{style:{height:"12px"}},`custom-${h}`);if(l.customType==="link"){const j=l.displayText||l.label||l.linkText||l.linkUrl||"";return e.jsx("div",{className:"metakyc-link-field",children:e.jsxs("a",{href:l.linkUrl||"#",target:"_blank",rel:"noopener noreferrer",style:{display:"inline-flex",alignItems:"center",gap:"4px",color:"var(--metakyc-primary, #2563eb)",fontSize:"14px",textDecoration:"underline",cursor:"pointer"},children:[j,e.jsx("span",{style:{fontSize:"10px",opacity:.7},children:"↗"})]})},`custom-${h}`)}if(!l.paramName)return null;const b=z[l.paramName],w=l.displayText||l.label||l.paramName;if(l.customType==="checkbox")return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx(Fe,{checked:de[l.paramName]==="true",onChange:j=>ve(l.paramName,j?"true":"false")}),e.jsxs("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:[w,l.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),b&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:b})]},`custom-${h}`);if(l.customType==="link_checkbox")return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx(Fe,{checked:de[l.paramName]==="true",onChange:j=>ve(l.paramName,j?"true":"false")}),e.jsxs("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:[w," ",l.linkUrl&&e.jsx("a",{href:l.linkUrl,target:"_blank",rel:"noopener noreferrer",className:"underline",style:{color:"var(--metakyc-primary, #2563eb)"},onClick:j=>j.stopPropagation(),children:l.linkText||l.linkUrl}),l.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),b&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:b})]},`custom-${h}`);if(l.customType==="group_checkbox"){const j=(de[l.paramName]||"").split(",").filter(Boolean);return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[P&&e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[w,l.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]}),e.jsx("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:(l.options||[]).map(le=>{const ae=l.singleSelect?de[l.paramName]===le.value:j.includes(le.value);return e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx(Fe,{checked:ae,onChange:xe=>{if(l.singleSelect)ve(l.paramName,xe?le.value:"");else{const Ie=xe?[...j,le.value]:j.filter(ie=>ie!==le.value);ve(l.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)})}),b&&e.jsx("p",{className:"text-red-500 text-xs",children:b})]},`custom-${h}`)}return l.customType==="radio_group"?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[P&&e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[w,l.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]}),e.jsx("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:(l.options||[]).map(j=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"radio",checked:de[l.paramName]===j.value,onChange:()=>ve(l.paramName,j.value),name:`radio-group-${l.paramName}-${h}`,className:"metakyc-option-input",style:Ds}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:j.label})]},j.value))}),b&&e.jsx("p",{className:"text-red-500 text-xs",children:b})]},`custom-${h}`):e.jsx(ye,{type:"text",label:P?`${w}${l.required?" *":""}`:void 0,placeholder:P?void 0:w,value:de[l.paramName]||"",onChange:j=>ve(l.paramName,j.target.value),required:l.required,error:b},`custom-${h}`)},D=(l,h)=>{const P=Pe(l);return e.jsxs("div",{className:"space-y-4",children:[l.conditionalOn&&e.jsx(At,{helpText:l.conditionalHelpText,children:e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx(Fe,{checked:P,onChange:b=>ve(l.conditionalOn,b?"true":"false")}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",fontWeight:500},children:l.conditionalOn})]})}),P&&e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:l.fields.map((b,w)=>{const j=Math.min(4,Math.max(1,Number(b.colSpan)||4)),le=b.isCustom?`custom-${w}-${b.paramName}`:`builtin-${b.name}-${w}`;return e.jsx("div",{style:{gridColumn:`span ${j} / span ${j}`},children:e.jsx(At,{helpText:b.helpText,children:b.isCustom?x(b,w):Ke(b.name,le,b.displayText,b.countriesType,b.labelMode)})},le)})})]})};if(!c||R)return e.jsx("div",{className:"metakyc-sdk",children:e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)",fontSize:"0.875rem"},children:"Loading form…"})]})})});if(S){const l=S[I]??S[0],h=ze===-1,P=ke===-1,b=S.length,w=Pe(l),j=Object.values(z);return e.jsx("div",{className:"metakyc-sdk",children:e.jsxs(ee,{children:[e.jsx(fe,{children:e.jsx(at,{title:(c==null?void 0:c.title)||"Create Applicant"})}),e.jsxs(te,{children:[(l.title||l.subtitle||l.description)&&e.jsxs("div",{className:"mb-4",children:[l.title&&e.jsx("h3",{className:"font-semibold text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:l.title}),l.subtitle&&e.jsx("p",{className:"text-sm mt-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:l.subtitle}),l.description&&l.description!==l.subtitle&&e.jsx("p",{className:"text-xs mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:l.description})]}),(me||j.length>0)&&e.jsxs("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-lg",children:[me&&e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",me]}),j.map((le,ae)=>e.jsx("p",{className:"text-red-600 text-sm",children:le},ae))]}),b>1&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem",marginBottom:"1rem"},children:[S.map((le,ae)=>e.jsx("div",{style:{height:"0.375rem",borderRadius:"9999px",transition:"all 150ms",...ae===I?{flex:"1 1 0%",backgroundColor:"var(--metakyc-primary, #2563eb)"}:ae<I?{width:"2rem",backgroundColor:"var(--metakyc-primary-light, #93c5fd)",opacity:.7}:{width:"2rem",backgroundColor:"#e5e7eb"}}},ae)),e.jsxs("span",{style:{fontSize:"0.75rem",color:"var(--metakyc-text-muted, #9ca3af)",flexShrink:0},children:[I+1," / ",b]})]}),D(l)]}),e.jsxs(ge,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{children:[!h&&e.jsx(J,{type:"button",variant:"outline",onClick:()=>{W(ze),_({})},disabled:re||y,children:"Previous"}),h&&n&&e.jsx(J,{type:"button",variant:"outline",onClick:n,disabled:re||y,children:"Cancel"})]}),e.jsx(J,{type:"button",isLoading:re||y,onClick:P?$e:Je,children:P?l.conditionalOn&&!w?"Skip & Submit":"Submit":l.conditionalOn&&!w?"Skip":"Next"})]})]})})}return e.jsx("div",{className:"metakyc-sdk",children:e.jsx("form",{onSubmit:tt,children:e.jsxs(ee,{children:[e.jsx(fe,{children:e.jsx(at,{title:(c==null?void 0:c.title)||"Create Applicant"})}),e.jsxs(te,{children:[me&&e.jsx("div",{className:"mb-6 p-4 bg-red-50 border border-red-200 rounded-lg",children:e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",me]})}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:Y.map(l=>e.jsx("div",{style:{gridColumn:"span 4 / span 4"},children:Ke(l)},l))})]}),e.jsxs(ge,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[n&&e.jsx(J,{type:"button",variant:"outline",onClick:n,disabled:re||y,children:"Cancel"}),e.jsx(J,{type:"submit",isLoading:re||y,children:"Create Applicant"})]})]})})})},Tt=["companyName","email"];function ht(t){return t==null||t===""||Array.isArray(t)&&t.length===0}const Os=({workflowKey:t,externalRefId:r,onSuccess:s,onCancel:n})=>{var Ke,x,D,K,H,Z;const{config:a,baseInformationService:o,currentTheme:c}=Ne(),{createCompanyApplicant:d,isLoading:y}=kt(),p=t||((Ke=a.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 g=r||((x=a.applicantForm)==null?void 0:x.externalRefId)||"",T=((D=a.applicantForm)==null?void 0:D.email)||"",v=((K=a.applicantForm)==null?void 0:K.initialValues)||{},A=(((H=a.applicantForm)==null?void 0:H.fieldLabelMode)||(c==null?void 0:c.fieldLabelMode)||"label")!=="placeholder",k=i.useMemo(()=>c!=null&&c.companyFormPages&&c.companyFormPages.length>0?c.companyFormPages:null,[c==null?void 0:c.companyFormPages]),S=i.useMemo(()=>{const m=new Set(Tt),C=c==null?void 0:c.companyFormRequiredFields;if(C)for(const F of C)m.add(F);if(k)for(const F of k)for(const u of F.fields)!u.isCustom&&u.name&&u.required&&m.add(u.name);return Array.from(m)},[c==null?void 0:c.companyFormRequiredFields,k]),M=i.useMemo(()=>{var m;if(k){const C=k.flatMap(u=>u.fields).filter(u=>!u.isCustom&&u.name).map(u=>u.name),F=new Set(C);for(const u of Tt)F.add(u);return Array.from(F)}return(m=a.applicantForm)!=null&&m.visibleFields?a.applicantForm.visibleFields:c!=null&&c.companyFormVisibleFields&&c.companyFormVisibleFields.length>0?c.companyFormVisibleFields:Wt},[(Z=a.applicantForm)==null?void 0:Z.visibleFields,c==null?void 0:c.companyFormVisibleFields,k]),Y=new Set(["countryResidence","addressCountry"]),L=i.useMemo(()=>{var C,F;const m=new Set;if(k)for(const u of k)for(const l of u.fields)!l.isCustom&&l.name&&Y.has(l.name)&&m.add(l.countriesType??((C=Xe[l.name])==null?void 0:C.countriesType));else for(const u of M)Y.has(u)&&m.add((F=Xe[u])==null?void 0:F.countriesType);return m.size===0&&m.add(void 0),Array.from(m)},[M,k]),[B,U]=i.useState({}),[X,R]=i.useState(!0),f=i.useRef(new Set),O=i.useRef(new Set);i.useEffect(()=>{if(!c)return;const m=L.filter(u=>{const l=u!=null?String(u):"all";return!O.current.has(l)&&!f.current.has(l)});if(m.length===0){L.every(l=>O.current.has(l!=null?String(l):"all"))&&R(!1);return}R(!0);const C=m.map(u=>u!=null?String(u):"all");C.forEach(u=>f.current.add(u)),(async()=>{try{const u=await Promise.all(m.map(async l=>{const h=l!=null?String(l):"all",P=await o.getCountries("",a.locale||"en",l),b=new Set,w=P.map(j=>({value:j.abbreviation3||j.abbreviation,label:j.name})).filter(j=>!j.value||b.has(j.value)?!1:(b.add(j.value),!0));return O.current.add(h),f.current.delete(h),[h,w]}));U(l=>({...l,...Object.fromEntries(u)}))}catch(u){C.forEach(l=>f.current.delete(l)),console.error("Failed to load countries:",u)}finally{L.every(l=>O.current.has(l!=null?String(l):"all"))&&R(!1)}})()},[L,c]);const q=(m,C)=>{var l;const F=C??((l=Xe[m])==null?void 0:l.countriesType),u=F!=null?String(F):"all";return B[u]||[]},Q={companyName:1,registrationNumber:1,email:1,phone:1,countryResidence:1,legalAddress:1,incorporatedOn:1,controlScheme:1,taxId:1,registrationLocation:1,website:1,postalAddress:1,street:1,streetNumber:1,city:1,state:1,postalCode:1,addressCountry:1,lei:1},$=Object.fromEntries(Object.entries(v).filter(([m])=>m in Q)),[G,se]=i.useState({workflowKey:p,companyName:"",email:T,phone:"",registrationNumber:"",countryResidence:"",legalAddress:"",incorporatedOn:"",controlScheme:"",taxId:"",registrationLocation:"",website:"",postalAddress:"",street:"",streetNumber:"",city:"",state:"",postalCode:"",addressCountry:"",lei:"",externalRefId:g,...$}),[V,be]=i.useState({}),[ce,de]=i.useState(0),[he,I]=i.useState({}),[W,z]=i.useState(null),[_,me]=i.useState(!1),N=(m,C)=>se(F=>({...F,[m]:C})),re=(m,C)=>be(F=>({...F,[m]:C})),ue=m=>!m.conditionalOn||V[m.conditionalOn]==="true",ne=k&&ce<k.length-1?ce+1:-1,ve=k&&ce>0?ce-1:-1,Pe=m=>{var F;const C={};for(const u of m.fields)if(u.isCustom){if(u.customType==="paragraph"||u.customType==="html"||u.customType==="br"||u.customType==="link")continue;if(u.required&&u.paramName){const l=V[u.paramName],h=u.displayText||u.label||u.paramName;u.customType==="checkbox"||u.customType==="link_checkbox"?l!=="true"&&(C[u.paramName]=`${h} is required.`):(!l||l.trim()==="")&&(C[u.paramName]=`${h} is required.`)}}else if(u.name){const l=u.name;if(S.includes(l)&&ht(G[l])){const h=u.displayText||((F=Xe[l])==null?void 0:F.label)||l;C[l]=`${h} is required.`}}return C},ke=async()=>{if(!k)return;const m=k[ce];if(m.conditionalOn&&!ue(m)){I({}),ne>=0?de(ne):await ze();return}const C=Pe(m);if(Object.keys(C).length>0){I(C);return}I({}),ne>=0?de(ne):await ze()},ze=async()=>{var m;if(k){let C={};for(const F of k)ue(F)&&(C={...C,...Pe(F)});if(Object.keys(C).length>0){I(C);return}}me(!0),z(null);try{const C={workflowKey:G.workflowKey,externalRefId:((m=G.externalRefId)==null?void 0:m.trim())||void 0},F=k?k.filter(h=>ue(h)).flatMap(h=>h.fields).filter(h=>!h.isCustom&&h.name).map(h=>h.name):M;for(const h of F){const P=G[h];if(!ht(P))switch(h){case"companyName":C.companyName=P;break;case"email":C.companyEmail=P;break;case"phone":C.companyPhone=P;break;case"registrationNumber":C.companyRegistrationNumber=P;break;case"countryResidence":C.companyCountry=P;break;case"city":C.companyCity=P;break;case"street":C.companyStreet=P;break;case"postalCode":C.companyZip=P;break;default:C[h]=P;break}}const u=[];if(k){for(const h of k)if(ue(h))for(const P of h.fields){if(!P.isCustom||!P.paramName||P.customType==="paragraph"||P.customType==="html"||P.customType==="br"||P.customType==="link")continue;const b=V[P.paramName]??"";let w;if(P.customType==="checkbox"||P.customType==="link_checkbox")w=b==="true"?"yes":"no";else if(w=b,!w&&!P.required)continue;u.push({paramName:P.paramName,value:w})}}u.length>0&&(C.applicantAdditionalDatas=u);const l=await d(C);s(l.applicantId)}catch(C){console.error("Error creating company applicant:",C),z(C.message||"Failed to create company applicant")}finally{me(!1)}},et=async m=>{var C;m.preventDefault();for(const F of S)if(ht(G[F])){const u=((C=Xe[F])==null?void 0:C.label)||F;z(`${u} is required.`);return}await ze()},Je=(m,C,F,u,l)=>{const h=Xe[m];if(!h)return null;const P=S.includes(m),b=he[m],w=F||h.label,j=m in $,le=C??m,ae=l?l!=="placeholder":A,xe=ae?w:void 0,Ie=ae?"...":w;switch(h.type){case"select":if(m==="countryResidence"||m==="addressCountry"){const ie=q(m,u);return e.jsx(Oe,{required:P,label:xe,value:G[m]||"",onChange:Le=>N(m,Le),options:[{value:"",label:`Select ${Ie.toLowerCase()}`},...ie],disabled:X,readOnly:j,error:b},le)}return null;case"date":return e.jsx(ye,{required:P,type:"date",label:xe,placeholder:ae?void 0:w,value:G[m]||"",onChange:ie=>N(m,ie.target.value),readOnly:j,error:b},le);case"email":return e.jsx(ye,{required:P,type:"email",label:xe,placeholder:ae?void 0:w,value:G[m]||"",onChange:ie=>N(m,ie.target.value),readOnly:j,error:b},le);case"tel":return e.jsx(ye,{required:P,type:"tel",label:xe,placeholder:ae?void 0:w,value:G[m]||"",onChange:ie=>N(m,ie.target.value),readOnly:j,error:b},le);default:return e.jsx(ye,{required:P,type:"text",label:xe,placeholder:ae?void 0:w,value:G[m]||"",onChange:ie=>N(m,ie.target.value),readOnly:j,error:b},le)}},$e=(m,C)=>{if(m.customType==="paragraph")return e.jsx("p",{style:{fontSize:"14px",lineHeight:"1.7",margin:0,color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:m.displayText||m.label||""}},`custom-${C}`);if(m.customType==="html")return e.jsx("div",{dangerouslySetInnerHTML:{__html:m.label||""}},`custom-${C}`);if(m.customType==="br")return e.jsx("div",{style:{height:"12px"}},`custom-${C}`);if(m.customType==="link")return e.jsx("div",{children:e.jsx("a",{href:m.linkUrl||"#",target:"_blank",rel:"noopener noreferrer",style:{color:"var(--metakyc-primary, #2563eb)",fontSize:"14px",textDecoration:"underline"},children:m.displayText||m.label||m.linkText||m.linkUrl||""})},`custom-${C}`);if(!m.paramName)return null;const F=he[m.paramName],u=m.displayText||m.label||m.paramName,l=m.labelMode?m.labelMode!=="placeholder":A;return m.customType==="checkbox"?e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer"},children:[e.jsx(Fe,{checked:V[m.paramName]==="true",onChange:h=>re(m.paramName,h?"true":"false")}),e.jsxs("span",{style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)"},children:[u,m.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),F&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:F})]},`custom-${C}`):e.jsx(ye,{type:"text",label:l?`${u}${m.required?" *":""}`:void 0,placeholder:l?void 0:u,value:V[m.paramName]||"",onChange:h=>re(m.paramName,h.target.value),required:m.required,error:F},`custom-${C}`)},tt=m=>{const C=ue(m);return e.jsxs("div",{className:"space-y-4",children:[m.conditionalOn&&e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer"},children:[e.jsx(Fe,{checked:C,onChange:F=>re(m.conditionalOn,F?"true":"false")}),e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:m.conditionalOn})]}),C&&e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:m.fields.map((F,u)=>{const l=Math.min(4,Math.max(1,Number(F.colSpan)||4)),h=F.isCustom?`custom-${u}-${F.paramName}`:`builtin-${F.name}-${u}`;return e.jsx("div",{style:{gridColumn:`span ${l} / span ${l}`},children:F.isCustom?$e(F,u):Je(F.name,h,F.displayText,F.countriesType,F.labelMode)},h)})})]})};if(!c||X)return e.jsx("div",{className:"metakyc-sdk",children:e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)",fontSize:"0.875rem"},children:"Loading form…"})]})})});if(k){const m=k[ce]??k[0],C=ve===-1,F=ne===-1,u=k.length,l=ue(m),h=Object.values(he);return e.jsx("div",{className:"metakyc-sdk",children:e.jsxs(ee,{children:[e.jsx(fe,{children:e.jsx(at,{title:(c==null?void 0:c.title)||"Company Registration"})}),e.jsxs(te,{children:[(m.title||m.subtitle)&&e.jsxs("div",{className:"mb-4",children:[m.title&&e.jsx("h3",{className:"font-semibold text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:m.title}),m.subtitle&&e.jsx("p",{className:"text-sm mt-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:m.subtitle})]}),(W||h.length>0)&&e.jsxs("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-lg",children:[W&&e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",W]}),h.map((P,b)=>e.jsx("p",{className:"text-red-600 text-sm",children:P},b))]}),u>1&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem",marginBottom:"1rem"},children:[k.map((P,b)=>e.jsx("div",{style:{height:"0.375rem",borderRadius:"9999px",transition:"all 150ms",...b===ce?{flex:"1 1 0%",backgroundColor:"var(--metakyc-primary, #2563eb)"}:b<ce?{width:"2rem",backgroundColor:"var(--metakyc-primary-light, #93c5fd)",opacity:.7}:{width:"2rem",backgroundColor:"#e5e7eb"}}},b)),e.jsxs("span",{style:{fontSize:"0.75rem",color:"var(--metakyc-text-muted, #9ca3af)",flexShrink:0},children:[ce+1," / ",u]})]}),tt(m)]}),e.jsxs(ge,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{children:[!C&&e.jsx(J,{type:"button",variant:"outline",onClick:()=>{de(ve),I({})},disabled:_||y,children:"Previous"}),C&&n&&e.jsx(J,{type:"button",variant:"outline",onClick:n,disabled:_||y,children:"Cancel"})]}),e.jsx(J,{type:"button",isLoading:_||y,onClick:F?ze:ke,children:F?m.conditionalOn&&!l?"Skip & Submit":"Submit":m.conditionalOn&&!l?"Skip":"Next"})]})]})})}return e.jsx("div",{className:"metakyc-sdk",children:e.jsx("form",{onSubmit:et,children:e.jsxs(ee,{children:[e.jsx(fe,{children:e.jsx(at,{title:(c==null?void 0:c.title)||"Company Registration"})}),e.jsxs(te,{children:[W&&e.jsx("div",{className:"mb-6 p-4 bg-red-50 border border-red-200 rounded-lg",children:e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",W]})}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:M.map(m=>e.jsx("div",{style:{gridColumn:"span 4 / span 4"},children:Je(m)},m))})]}),e.jsxs(ge,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[n&&e.jsx(J,{type:"button",variant:"outline",onClick:n,disabled:_||y,children:"Cancel"}),e.jsx(J,{type:"submit",isLoading:_||y,children:"Register Company"})]})]})})})},zs=({applicantId:t,onComplete:r,onError:s,theme:n="light",className:a})=>{const{progress:o,currentStep:c,steps:d,workflowKey:y,nextWorkflowKey:p,hasWorkflowChanged:g,isLoading:T,error:v,moveBack:E,refreshProgress:A}=Cr(t),[k,S]=i.useState(!1),M=i.useRef(null);if(i.useEffect(()=>{v&&s&&s(v)},[v,s]),i.useEffect(()=>{o!=null&&o.workflowResult&&r&&r(o.workflowResult)},[o==null?void 0:o.workflowResult,r]),i.useEffect(()=>{n==="dark"?document.documentElement.classList.add("dark"):document.documentElement.classList.remove("dark")},[n]),i.useEffect(()=>{g&&S(!1)},[g]),T||!o)return e.jsx("div",{className:`metakyc-sdk ${a||""}`,children:e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Loading workflow..."})]})})});if(v)return e.jsx("div",{className:`metakyc-sdk ${a||""}`,children:e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-lg mb-4",style:{color:"var(--metakyc-danger, #ef4444)"},children:"An error occurred"}),e.jsx("p",{style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:v.message})]})})})});if(g&&!k)return e.jsx("div",{className:`metakyc-sdk ${a||""}`,children:e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("div",{className:"text-center py-8",children:[e.jsx("div",{className:"mb-6",children:e.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-full mb-4",style:{backgroundColor:"var(--metakyc-primary-light, #dbeafe)"},children:e.jsx("svg",{className:"w-8 h-8",style:{color:"var(--metakyc-primary, #2563eb)"},fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})})}),e.jsx("h3",{className:"text-xl font-semibold mb-2",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Workflow Transition"}),e.jsx("p",{className:"mb-6",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Your application workflow has been updated based on your progress."}),e.jsxs("div",{className:"rounded-lg p-4 mb-6 max-w-md mx-auto",style:{backgroundColor:"var(--metakyc-surface, #f9fafb)"},children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"mb-1",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"Previous Workflow"}),e.jsx("p",{className:"font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:y})]}),e.jsx("svg",{className:"w-6 h-6 mx-4",style:{color:"var(--metakyc-text-muted, #9ca3af)"},fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 7l5 5m0 0l-5 5m5-5H6"})}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"mb-1",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"New Workflow"}),e.jsx("p",{className:"font-medium",style:{color:"var(--metakyc-primary, #2563eb)"},children:p})]})]}),o.nextWorkflowName&&e.jsx("p",{className:"text-center mt-2 text-xs",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:o.nextWorkflowName})]}),e.jsx("button",{onClick:()=>S(!0),className:"px-6 py-3 font-medium rounded-lg transition-opacity hover:opacity-90",style:{backgroundColor:"var(--metakyc-primary, #2563eb)",color:"#ffffff"},children:"Continue with New Workflow"})]})})})});if(o.status===Te.Finished||o.status===Te.OnHold)return e.jsx("div",{className:`metakyc-sdk ${a||""}`,children:e.jsx(gt,{kycStatus:o.kycStatus,reviewStatus:o.reviewStatus,workflowResult:o.workflowResult,customMessage:o.customMessage,onContinue:r&&o.workflowResult?()=>r(o.workflowResult):void 0,onContactSupport:()=>{typeof window<"u"&&(window.location.href="mailto:support@example.com")}})});if(!c)return e.jsx("div",{className:`metakyc-sdk ${a||""}`,children:e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:o.status===Te.IdentityPending?"Loading identity verification...":"Loading current step..."})]})})});const Y=U=>{switch(U){case oe.Overview:return"Overview";case oe.Questionaries:return"Questionnaire";case oe.UploadDocument:return"Documents";case oe.IdentitySdk:return"Identity";case oe.RiskScoring:return"Risk Assessment";case oe.InvestorCategorization:return"Investor Categorization";case oe.AppropriatenessTest:return"Appropriateness Test";case oe.AdditionalData:return"Additional Data";case oe.ManualReview:return"Review";default:return""}},L=()=>{const U=d.filter(q=>q.visibility!==!1),X=U.findIndex(q=>q.order===c.order),R=X>=0?X+1:1,f=U.length,O=f>1?X/(f-1)*100:100;return e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",marginBottom:"16px"},children:[e.jsx(at,{}),e.jsxs(jt,{variant:o.status===1?"info":"success",children:["Step ",R," of ",f]})]}),e.jsx("div",{style:{marginBottom:"16px"},children:e.jsx("div",{style:{height:"4px",borderRadius:"999px",backgroundColor:"var(--metakyc-border, #e5e7eb)",overflow:"hidden"},children:e.jsx("div",{style:{height:"100%",borderRadius:"999px",backgroundColor:"var(--metakyc-primary, #2563eb)",width:`${O}%`,transition:"width 0.4s ease"}})})}),e.jsx($s,{ref:M,visibleSteps:U,currentVisibleStepIndex:X,getStepFallbackName:Y})]})},B=()=>{const U={applicantId:t,onComplete:async()=>{await A()},onBack:c.order>0?E:void 0};switch(c.action){case oe.Questionaries:return e.jsx(zr,{...U});case oe.UploadDocument:return e.jsx($r,{...U});case oe.Overview:return e.jsx(Br,{...U});case oe.IdentitySdk:return e.jsx(Ur,{...U});case oe.RiskScoring:return e.jsx(_r,{...U});case oe.AdditionalData:case oe.InvestorCategorization:return e.jsx(Hr,{...U});case oe.AppropriatenessTest:return e.jsx(Wr,{...U});case oe.ManualReview:return e.jsx(gt,{kycStatus:o.kycStatus,reviewStatus:o.reviewStatus,workflowResult:o.workflowResult,customMessage:o.customMessage});default:return e.jsx(ee,{children:e.jsxs(te,{className:"py-12 text-center",children:[e.jsx("div",{className:"mb-4",children:e.jsx(Ee,{})}),e.jsxs("p",{className:"text-gray-600 dark:text-gray-400 mb-2",children:["Processing step: ",c.title||c.name]}),e.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:["Action type: ",oe[c.action]]})]})})}};return e.jsxs("div",{className:`metakyc-sdk ${a||""}`,children:[L(),B()]})},$s=i.forwardRef(({visibleSteps:t,currentVisibleStepIndex:r,getStepFallbackName:s},n)=>{const a=i.useRef(null),o=i.useRef(null);return i.useImperativeHandle(n,()=>a.current),i.useEffect(()=>{if(o.current&&a.current){const c=a.current,d=o.current,y=d.offsetLeft-c.offsetWidth/2+d.offsetWidth/2;c.scrollTo({left:Math.max(0,y),behavior:"smooth"})}},[r]),e.jsx("div",{ref:a,className:"metakyc-stepper-scroll",style:{display:"flex",alignItems:"center",overflowX:"auto",overflowY:"hidden",scrollbarWidth:"none",msOverflowStyle:"none",WebkitOverflowScrolling:"touch",padding:"4px 0",gap:"0"},children:t.map((c,d)=>{const y=d<r,p=d===r,g=y||p,T=c.displayName||c.name||s(c.action)||`Step ${d+1}`;return e.jsxs(i.Fragment,{children:[e.jsxs("div",{ref:p?o:void 0,style:{display:"flex",alignItems:"center",flexShrink:0},children:[e.jsx("div",{style:{width:"28px",height:"28px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"12px",fontWeight:600,flexShrink:0,transition:"all 0.2s ease",...g?{backgroundColor:"var(--metakyc-primary, #2563eb)",color:"#ffffff",border:"none"}:{backgroundColor:"transparent",color:"var(--metakyc-text-muted, #9ca3af)",border:"2px solid var(--metakyc-border, #e5e7eb)"}},children:y?e.jsx("svg",{width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:2.5,viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}):d+1}),e.jsx("span",{style:{marginLeft:"6px",fontSize:"13px",whiteSpace:"nowrap",fontWeight:p?600:400,color:p?"var(--metakyc-text-primary, #111827)":y?"var(--metakyc-primary, #2563eb)":"var(--metakyc-text-muted, #9ca3af)",transition:"color 0.2s ease"},children:T})]}),d<t.length-1&&e.jsx("div",{style:{width:"32px",minWidth:"16px",height:"2px",margin:"0 8px",flexShrink:0,borderRadius:"999px",backgroundColor:y?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",transition:"background-color 0.2s ease"}})]},c.order)})})});function Bs(t){return Ue.z.object({questionResults:Ue.z.any()}).passthrough()}function _s(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(s=>!s||s.length<=1,{message:"Only one file is allowed"})),t.maxEachFileSizeByte>0&&(r=r.refine(s=>!s||s.every(n=>n.size<=t.maxEachFileSizeByte),{message:`File size must not exceed ${Math.round(t.maxEachFileSizeByte/1024/1024)}MB`})),t.allowedTypes){const s=t.allowedTypes.split(",").map(n=>n.trim());r=r.refine(n=>n?n.every(a=>s.some(o=>o.endsWith("/*")?a.type.startsWith(o.slice(0,-2)):a.type===o)):!0,{message:"Invalid file type"})}return r}function Hs(t){const r={};return t.uploadDocumentFiles.forEach(s=>{const n=`file_${s.id}`;r[n]=_s(s)}),Ue.z.object(r)}function Ws(t){return Ue.z.any()}function Us(t){return Ue.z.string().min(1,"This question is required")}function Ks(t){const r={};return t.appropriatenessQuestions.forEach(s=>{const n=`question_${s.id}`;r[n]=Us()}),Ue.z.object(r)}const qs=Ue.z.any();exports.ALLOWED_LANGUAGES=ft;exports.ApplicantProgressOnHoldReason=Ft;exports.ApplicantProgressStatus=Te;exports.ApplicantService=Yt;exports.ApplicantStatus=Lt;exports.AppropriatenessQuestionType=$t;exports.AppropriatenessTestService=Jt;exports.AppropriatenessTestStep=Wr;exports.Badge=jt;exports.BaseInformationService=tr;exports.Button=J;exports.COMPANY_FIELD_METADATA=Xe;exports.Card=ee;exports.CardContent=te;exports.CardFooter=ge;exports.CardHeader=fe;exports.Checkbox=Fe;exports.CountriesType=We;exports.CreateApplicantForm=Ms;exports.CreateCompanyApplicantForm=Os;exports.CriteriaBuiltInType=_t;exports.DEFAULT_COMPANY_VISIBLE_FIELDS=Wt;exports.DEFAULT_VISIBLE_FIELDS=Ut;exports.DocumentReviewStatus=zt;exports.EndpointBuilder=qt;exports.ErrorHandler=st;exports.EventEmitter=dr;exports.FIELD_METADATA=Ge;exports.FileType=Ot;exports.FileUpload=Fr;exports.GenderType=lt;exports.Header=at;exports.HttpClient=Vt;exports.IdentityProviderManager=He;exports.IdentityService=er;exports.IdentityVerificationProvider=Ae;exports.IdentityVerificationStep=Ur;exports.Input=ye;exports.InvestorCategorizationService=rr;exports.InvestorCategorizationStep=Hr;exports.InvestorCategorizationType=je;exports.InvestorCategoryType=Ht;exports.KycProcessStatus=Dt;exports.KycStatus=Ye;exports.KycStatusDisplay=gt;exports.KycWorkflow=zs;exports.Logo=Kr;exports.MetaKYCContext=vt;exports.MetaKYCError=De;exports.MetaKYCProvider=ns;exports.MultiSelect=Tr;exports.OnfidoProvider=xr;exports.OverviewService=Zt;exports.OverviewStep=Br;exports.PhoneInput=Pr;exports.QuestionnaireService=Qt;exports.QuestionnaireStep=zr;exports.ReviewStatus=Qe;exports.RiskCriteriaType=Bt;exports.RiskLevel=Pt;exports.RiskScoringService=Xt;exports.RiskScoringStep=_r;exports.SDK_VERSION=gr;exports.SardinAIProvider=hr;exports.SearchableSelect=Oe;exports.Select=mt;exports.Spinner=Ee;exports.StepRouter=pr;exports.SumsubProvider=yr;exports.ThemeManager=fr;exports.ThemePreset=we;exports.ThemeService=cr;exports.UploadDocumentService=Gt;exports.UploadDocumentStep=$r;exports.UserType=Mt;exports.ValueDataType=Me;exports.WorkflowOrchestrator=mr;exports.WorkflowResultType=ot;exports.WorkflowState=ur;exports.WorkflowStepAction=oe;exports.appropriatenessTestSchema=qs;exports.clearAllStorage=cs;exports.clearApplicantId=jr;exports.clearWorkflowState=Sr;exports.cn=Se;exports.corporateTheme=sr;exports.defaultConfig=Kt;exports.defaultTheme=Re;exports.fileToBase64=br;exports.fintechTheme=nr;exports.formatFileSize=ut;exports.generateAppropriatenessSchema=Ks;exports.generateQuestionnaireSchema=Bs;exports.generateRiskScoringSchema=Ws;exports.generateUploadDocumentSchema=Hs;exports.getAcceptString=os;exports.getApplicantId=kr;exports.getThemePreset=nt;exports.getWorkflowState=ls;exports.healthcareTheme=ar;exports.isScriptLoaded=Jr;exports.loadScript=bt;exports.minimalTheme=or;exports.modernTheme=ir;exports.removeScript=Zr;exports.saveApplicantId=vr;exports.saveWorkflowState=wr;exports.themePresets=lr;exports.useApplicant=kt;exports.useAppropriatenessTest=ds;exports.useIdentityVerification=Er;exports.useKycWorkflow=Cr;exports.useMetaKYC=Ne;exports.useOverview=Ir;exports.useQuestionnaire=Nr;exports.useRiskScoring=Ar;exports.useUploadDocument=Rr;exports.validateFileSize=as;exports.validateFileType=is;
111
+ */const ks=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],Or=Dr("chevron-right",ks);function js(t,r){const s=!r||r.length===0||r.every(n=>!n||!n.trim());if(t.isRequired&&s)return t.errorMessage||"This field is required";if(!s){const n=r[0]??"";if(n&&t.regex)try{if(!new RegExp(t.regex).test(n))return t.errorMessage||"Invalid format"}catch{}if(n!==""){const a=Number(n);if(!isNaN(a)&&n.trim()!==""){if(t.min!==void 0&&t.min!==null&&a<t.min)return`Minimum value is ${t.min}`;if(t.max!==void 0&&t.max!==null&&a>t.max)return`Maximum value is ${t.max}`}else{if(t.min!==void 0&&t.min!==null&&n.length<t.min)return`Minimum length is ${t.min} characters`;if(t.max!==void 0&&t.max!==null&&n.length>t.max)return`Maximum length is ${t.max} characters`}}}return null}function ws(t){const r=t.flatMap((n,a)=>(n.questions??[]).map((o,c)=>({question:o,groupIndex:a,qIdx:c}))),s=new Map;for(const n of r){const a=n.question.pageNumber!=null&&n.question.pageNumber>0?n.question.pageNumber:1;s.has(a)||s.set(a,[]),s.get(a).push(n)}return Array.from(s.entries()).sort(([n],[a])=>n-a).map(([,n])=>n)}const zr=({applicantId:t,onComplete:r,onBack:s})=>{const{questionnaire:n,initialAnswers:a,isLoading:o,isSubmitting:c,error:d,submit:y}=Nr(t),[p,g]=i.useState({}),[T,v]=i.useState({}),[E,A]=i.useState(0);i.useEffect(()=>{a&&Object.keys(a).length>0&&Object.keys(p).length===0&&g(a)},[a]);const k=i.useMemo(()=>n?ws(n.questionGroups):[],[n]),S=E===k.length-1,M=k[E]??[],Y=i.useCallback((R,f)=>{g(O=>({...O,[R]:f})),v(O=>{const q={...O};return delete q[R],q})},[]),L=i.useCallback(()=>{const R={};for(const{question:f}of M){const O=js(f,p[f.id]??[]);O&&(R[f.id]=O)}return v(f=>({...f,...R})),Object.keys(R).length===0},[M,p]),B=()=>{L()&&A(R=>R+1)},U=()=>{E>0?A(R=>R-1):s==null||s()},X=async()=>{if(!(!L()||!n))try{const R=n.questionGroups.flatMap(O=>(O.questions??[]).map(q=>({questionId:q.id,values:p[q.id]??[]}))),f={applicantId:t,questionnarieId:n.id,questionResults:R};await y(f),r==null||r()}catch(R){console.error("Questionnaire submit error:",R)}};return o?e.jsx(ee,{children:e.jsx(te,{children:e.jsx(Ee,{className:"my-8"})})}):d?e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading questionnaire: ",d.message]})})}):n?e.jsxs(ee,{children:[e.jsxs(fe,{children:[e.jsx("h2",{className:"text-lg font-bold",children:n.displayName}),n.subtitle&&e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:n.subtitle}),k.length>1&&e.jsxs("div",{className:"flex items-center justify-between mt-3",children:[e.jsxs("span",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:["Page ",E+1," of ",k.length]}),e.jsx("div",{className:"flex items-center gap-1.5",children:k.map((R,f)=>e.jsx("div",{className:"rounded-full transition-all duration-200",style:{height:"6px",width:f===E?"20px":"6px",backgroundColor:f<=E?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},f))})]})]}),e.jsx(te,{className:"space-y-6",children:M.map(({question:R})=>e.jsx(Ss,{question:R,value:p[R.id]??[],error:T[R.id],onChange:f=>Y(R.id,f)},R.id))}),e.jsxs(ge,{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs(J,{type:"button",variant:"outline",onClick:U,style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(Mr,{size:14}),E>0?"Previous":"Back"]}),S?e.jsx(J,{type:"button",isLoading:c,onClick:X,children:"Continue"}):e.jsxs(J,{type:"button",onClick:B,style:{display:"flex",alignItems:"center",gap:"4px"},children:["Next",e.jsx(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},Ss=({question:t,value:r,error:s,onChange:n})=>{var c;const o=(((c=t.defaultAnswers)==null?void 0:c.length)??0)>0?t.showAsDropdown?t.canMultipleAnswer?"multi-select":"single-select":t.canMultipleAnswer?"checkbox":"radio":"text";return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[t.text,t.isRequired&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),t.subtitle&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:t.subtitle}),t.description&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:t.description}),o==="text"&&e.jsx(ye,{value:r[0]??"",onChange:d=>n([d.target.value]),placeholder:t.subtitle?void 0:"Enter your answer…",error:s,required:t.isRequired}),o==="single-select"&&e.jsx(mt,{value:r[0]??"",onChange:d=>n([d.target.value]),options:(t.defaultAnswers??[]).map(d=>({value:d,label:d})),placeholder:"Select an option…",error:s,required:t.isRequired}),o==="radio"&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultAnswers??[]).map(d=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"radio",checked:r[0]===d,onChange:()=>n([d]),className:"metakyc-option-input",style:{width:"16px",height:"16px",minWidth:"16px",flexShrink:0,flexGrow:0,accentColor:"var(--metakyc-primary, #2563eb)",cursor:"pointer",margin:0,padding:0,display:"inline-block",verticalAlign:"middle"}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:d})]},d)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),(o==="checkbox"||o==="multi-select")&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultAnswers??[]).map(d=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx(Fe,{checked:r.includes(d),onChange:y=>{n(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)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),s&&o==="text"&&null]})};function Cs(t){const r=new Map;for(const s of t){const n=s.pageNumber!=null&&s.pageNumber>0?s.pageNumber:1;r.has(n)||r.set(n,[]),r.get(n).push(s)}return Array.from(r.entries()).sort(([s],[n])=>s-n).map(([,s])=>s)}const $r=({applicantId:t,onComplete:r,onBack:s})=>{const{uploadDocument:n,isLoading:a,isSubmitting:o,error:c,submit:d}=Rr(t),[y,p]=i.useState({}),[g,T]=i.useState(null),[v,E]=i.useState(0),[A,k]=i.useState({}),S=i.useMemo(()=>n?Cs(n.uploadDocumentFiles):[],[n]),M=S[v]??[],Y=v===S.length-1,L=S.length,B=i.useCallback(()=>{const f={};for(const O of M)O.isRequired&&(y[O.id]||[]).length===0&&(f[O.id]=`${O.displayName} is required`);return k(f),Object.keys(f).length===0},[M,y]),U=()=>{B()&&(E(f=>f+1),k({}))},X=()=>{v>0?(E(f=>f-1),k({})):s==null||s()},R=async()=>{if(!(!B()||!n)){T(null);try{const f=await Promise.all(n.uploadDocumentFiles.map(async q=>{const Q=y[q.id]||[],$=await Promise.all(Q.map(async G=>({fileName:G.name,fileData:await br(G)})));return{uploadDocumentFileId:q.id,valueList:$}})),O={applicantId:t,uploadDocumentId:n.id,uploadDocumentResults:f};await d(O),r==null||r()}catch(f){T((f==null?void 0:f.message)||"Failed to submit documents. Please try again.")}}};return a?e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"48px 0",gap:"16px"},children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)"},children:"Loading document requirements..."})]})})}):c?e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"32px 0",gap:"12px",textAlign:"center"},children:[e.jsx("div",{style:{width:"48px",height:"48px",borderRadius:"50%",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 10%, transparent)",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),e.jsx("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]})}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-danger, #ef4444)",fontWeight:500},children:"Error loading document requirements"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-muted, #9ca3af)"},children:c.message})]})})}):n?e.jsxs(ee,{children:[e.jsxs(fe,{children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:n.displayName||"Upload Documents"}),n.subtitle&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",marginTop:"4px"},children:n.subtitle}),L>1&&e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginTop:"12px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)"},children:["Page ",v+1," of ",L]}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:S.map((f,O)=>e.jsx("div",{style:{height:"6px",width:O===v?"20px":"6px",borderRadius:"999px",transition:"all 0.2s ease",backgroundColor:O<=v?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},O))})]})]}),n.description&&v===0&&e.jsxs("div",{style:{margin:"0 24px",marginTop:"4px",display:"flex",gap:"10px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-primary, #2563eb) 5%, var(--metakyc-background, #ffffff))",border:"1px solid color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-primary, #2563eb)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:"1px"},children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-secondary, #374151)",margin:0,lineHeight:1.5},children:n.description})]}),e.jsx(te,{children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"24px"},children:M.map(f=>e.jsx(Fr,{label:f.displayName,subtitle:f.subtitle,accept:f.allowedTypes,multiple:f.multipleFile,maxSize:f.maxEachFileSizeByte,required:f.isRequired,error:A[f.id],value:y[f.id]||[],onChange:O=>{T(null),k(q=>{const Q={...q};return delete Q[f.id],Q}),p(q=>({...q,[f.id]:O}))}},f.id))})}),g&&e.jsxs("div",{style:{margin:"0 24px",padding:"10px 14px",borderRadius:"8px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:g})]}),e.jsx(ge,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[e.jsx(J,{type:"button",variant:"outline",onClick:X,children:v>0?"Previous":"Back"}),Y?e.jsx(J,{type:"button",isLoading:o,onClick:R,children:o?"Uploading...":"Continue"}):e.jsx(J,{type:"button",onClick:U,children:"Next"})]})})]}):null},Br=({applicantId:t,onComplete:r,onBack:s})=>{const{overview:n,isLoading:a,isSubmitting:o,error:c,passOverview:d}=Ir(t),y=async()=>{await d(),r==null||r()};return a?e.jsx(ee,{children:e.jsx(te,{children:e.jsx(Ee,{className:"my-8"})})}):c?e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading overview: ",c.message]})})}):n?e.jsxs(ee,{children:[e.jsxs(fe,{children:[e.jsx("h2",{className:"text-lg font-bold",children:n.title||"Overview"}),n.description&&e.jsx("p",{className:"mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:n.description})]}),e.jsx(te,{className:"space-y-8",children:n.steps&&n.steps.length>0?n.steps.sort((p,g)=>p.order-g.order).map(p=>e.jsxs("div",{className:"metakyc-overview-step-item flex items-center space-x-3",children:[e.jsx("div",{className:"metakyc-step-icon flex-shrink-0",children:e.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center font-medium text-sm",style:{backgroundColor:"var(--metakyc-primary, #2563eb)",color:"#ffffff"},children:p.order+1})}),e.jsxs("div",{className:"metakyc-step-content",style:{flex:1,border:"none",height:"auto",background:"transparent"},children:[e.jsx("span",{className:"metakyc-step-title text-sm font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:p.title}),p.description&&e.jsx("p",{className:"metakyc-step-description text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:p.description})]})]},p.order)):e.jsx("div",{className:"text-center py-8",children:e.jsx("p",{style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Loading overview data..."})})}),e.jsxs(ge,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{onClick:y,isLoading:o,children:"Continue"})]})]}):null};function Ns(t){const r=(t??"en").toLowerCase().replace("_","-");try{return Intl.NumberFormat.supportedLocalesOf([r]),r}catch{return"en"}}function Rs(t){return t.valueDataType===Me.Money&&Array.isArray(t.defaultValues)&&t.defaultValues.length>0}function Is(t,r){const s=new Intl.NumberFormat(Ns(r),{minimumFractionDigits:0,maximumFractionDigits:2});return t.replace(/([\d]+(?:\.\d+)?)/g,n=>{const a=parseFloat(n);return isNaN(a)?n:s.format(a)})}function Es(t,r){const s=!r||r.length===0||r.every(n=>!n||!n.trim());if(t.isRequired&&s)return t.errorMessage||`${t.displayName} is required`;if(!s){const n=r[0]??"";if(n&&t.regex)try{if(!new RegExp(t.regex).test(n))return t.errorMessage||"Invalid format"}catch{}const a=t.valueDataType===Me.Integer||t.valueDataType===Me.Money||t.valueDataType===Me.DigitOnly;if(a&&n.trim()!==""){const o=Number(n);if(!isNaN(o)){if(t.min!==void 0&&t.min!==null&&o<t.min)return`Minimum value is ${t.min}`;if(t.max!==void 0&&t.max!==null&&o>t.max)return`Maximum value is ${t.max}`}}else if(!a&&n!==""){if(t.min!==void 0&&t.min!==null&&n.length<t.min)return`Minimum length is ${t.min} characters`;if(t.max!==void 0&&t.max!==null&&n.length>t.max)return`Maximum length is ${t.max} characters`}}return null}function As(t){const r=new Map;return t.forEach((s,n)=>{const a=s.pageNumber!=null&&s.pageNumber>0?s.pageNumber:1;r.has(a)||r.set(a,[]),r.get(a).push({criterion:s,idx:n})}),Array.from(r.entries()).sort(([s],[n])=>s-n).map(([,s])=>s)}function Ts(t){return t.builtInType===1?"country":!t.defaultValues||t.defaultValues.length===0?"text":t.multipleValue?"checkbox":"radio"}const _r=({applicantId:t,onComplete:r,onBack:s})=>{const{config:n}=Ne(),a=n.locale??"en",{criteria:o,initialAnswers:c,isLoading:d,isSubmitting:y,error:p,submit:g}=Ar(t),[T,v]=i.useState({}),[E,A]=i.useState({}),[k,S]=i.useState(0),[M,Y]=i.useState(!1);i.useEffect(()=>{c&&Object.keys(c).length>0&&Object.keys(T).length===0&&v(c)},[c]);const L=i.useMemo(()=>o&&o.length>0?As(o):[],[o]),B=k===L.length-1,U=L[k]??[];i.useEffect(()=>{!d&&o&&o.length===0&&!M&&!y&&(Y(!0),g({applicantId:t,criteriaValueInputs:[]}).then(()=>r==null?void 0:r()).catch(console.error))},[d,o,M,y,g,t,r]);const X=i.useCallback((Q,$)=>{v(G=>({...G,[Q]:$})),A(G=>{const se={...G};return delete se[Q],se})},[]),R=i.useCallback(()=>{const Q={};for(const{criterion:$}of U){const G=Es($,T[$.id]??[]);G&&(Q[$.id]=G)}return A($=>({...$,...Q})),Object.keys(Q).length===0},[U,T]),f=()=>{R()&&S(Q=>Q+1)},O=()=>{k>0?S(Q=>Q-1):s==null||s()},q=async()=>{if(!(!R()||!o))try{const Q=o.map(G=>{const se=(T[G.id]??[]).filter(V=>V&&V.trim());return se.length>0?{riskCriteriaId:G.id,values:se}:null}).filter(G=>G!==null);await g({applicantId:t,criteriaValueInputs:Q}),r==null||r()}catch(Q){console.error("Risk scoring submit error:",Q)}};return d?e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center text-sm mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Loading risk scoring criteria…"})]})}):!d&&o&&o.length===0?e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center text-sm mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"No criteria required. Moving to next step…"})]})}):p?e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("p",{className:"text-danger-500",children:["Error loading criteria: ",p.message]})})}):o?e.jsxs(ee,{children:[e.jsxs(fe,{children:[e.jsx("h2",{className:"text-lg font-bold",children:"Risk Assessment"}),e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Please answer the following questions for risk evaluation"}),L.length>1&&e.jsxs("div",{className:"flex items-center justify-between mt-3",children:[e.jsxs("span",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:["Page ",k+1," of ",L.length]}),e.jsx("div",{className:"flex items-center gap-1.5",children:L.map((Q,$)=>e.jsx("div",{className:"rounded-full transition-all duration-200",style:{height:"6px",width:$===k?"20px":"6px",backgroundColor:$<=k?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}},$))})]})]}),e.jsx(te,{className:"space-y-6",children:U.map(({criterion:Q})=>e.jsx(Fs,{criterion:Q,value:T[Q.id]??[],error:E[Q.id],locale:a,onChange:$=>X(Q.id,$)},Q.id))}),e.jsxs(ge,{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs(J,{type:"button",variant:"outline",onClick:O,style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(Mr,{size:14}),k>0?"Previous":"Back"]}),B?e.jsx(J,{type:"button",isLoading:y,onClick:q,children:"Continue"}):e.jsxs(J,{type:"button",onClick:f,style:{display:"flex",alignItems:"center",gap:"4px"},children:["Next",e.jsx(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},Fs=({criterion:t,value:r,error:s,locale:n,onChange:a})=>{const o=Ts(t),c=t.valueDataType===Me.Integer||t.valueDataType===Me.Money||t.valueDataType===Me.DigitOnly,d=Rs(t),y=p=>d?Is(p,n):p;return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[t.displayName,t.isRequired&&e.jsx("span",{className:"text-danger-500 ml-1",children:"*"})]}),t.description&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:t.description}),c&&(t.min!==void 0||t.max!==void 0)&&e.jsx("p",{className:"text-xs",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:t.min!==void 0&&t.max!==void 0?`Range: ${t.min} – ${t.max}`:t.min!==void 0?`Minimum: ${t.min}`:`Maximum: ${t.max}`}),o==="text"&&e.jsx(ye,{value:r[0]??"",onChange:p=>a([p.target.value]),type:c?"number":"text",placeholder:"Enter your answer…",error:s,required:t.isRequired,min:t.min,max:t.max,onKeyDown:p=>{t.valueDataType===Me.DigitOnly&&["e","E","+","-","."].includes(p.key)&&p.preventDefault()}}),o==="radio"&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultValues??[]).map(p=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"radio",checked:r[0]===p,onChange:()=>a([p]),className:"metakyc-option-input",style:{width:"16px",height:"16px",minWidth:"16px",flexShrink:0,flexGrow:0,accentColor:"var(--metakyc-primary, #2563eb)",cursor:"pointer",margin:0,padding:0,display:"inline-block",verticalAlign:"middle"}}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",marginLeft:0},children:y(p)})]},p)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),o==="checkbox"&&e.jsxs("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[(t.defaultValues??[]).map(p=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx(Fe,{checked:r.includes(p),onChange:g=>{a(g?[...r,p]:r.filter(T=>T!==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)),s&&e.jsx("p",{className:"text-sm text-danger-500",children:s})]}),o==="country"&&e.jsx(mt,{value:r[0]??"",onChange:p=>a([p.target.value]),options:[{value:"US",label:"United States"},{value:"GB",label:"United Kingdom"},{value:"DE",label:"Germany"},{value:"FR",label:"France"},{value:"AE",label:"United Arab Emirates"}],placeholder:"Select a country…",error:s,required:t.isRequired})]})},Hr=({applicantId:t,onComplete:r,onBack:s})=>{const{investorCategorizationService:n}=Ne(),[a,o]=i.useState(null),[c,d]=i.useState(!1),[y,p]=i.useState(null),g=async T=>{if(T.preventDefault(),a===null){p("Please select an investor type");return}d(!0),p(null);try{const v={applicantId:t,investorType:a};console.log("Submitting investor categorization:",v);const E=await n.setInvestorCategorization(v);console.log("Investor categorization result:",E),r==null||r()}catch(v){console.error("Error submitting investor categorization:",v),p(v.message||"Failed to submit investor categorization")}finally{d(!1)}};return e.jsx("form",{onSubmit:g,children:e.jsxs(ee,{children:[e.jsxs(fe,{children:[e.jsx("h2",{className:"text-lg font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Which statement best describes you?"}),e.jsx("p",{className:"mt-2",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"All Tokenise clients are treated as Retail Investors under EU regulation, which gives you the highest level of investor protection. For our internal purposes, we ask you to select the description that best matches your situation"})]}),e.jsxs(te,{className:"space-y-4",children:[e.jsx("p",{className:"text-sm font-medium mb-3",style:{color:"var(--metakyc-text-secondary, #374151)"},children:"Choose one"}),e.jsx("label",{className:"block p-4 border-2 rounded-lg cursor-pointer transition-all",style:{borderColor:a===je.Individual?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:a===je.Individual?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:je.Individual,checked:a===je.Individual,onChange:()=>o(je.Individual),className:"mt-1"}),e.jsxs("div",{className:"ml-3",children:[e.jsx("div",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Individual investor"}),e.jsx("div",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"(Recommended) Most of our clients choose this option. Provides the strongest protection and aligns with our mission to make investing accessible to everyone."})]})]})}),e.jsx("label",{className:"block p-4 border-2 rounded-lg cursor-pointer transition-all",style:{borderColor:a===je.Sophisticated?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:a===je.Sophisticated?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:je.Sophisticated,checked:a===je.Sophisticated,onChange:()=>o(je.Sophisticated),className:"mt-1"}),e.jsxs("div",{className:"ml-3",children:[e.jsx("div",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Sophisticated investor"}),e.jsx("div",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"In the last 2 years, I have done one or more of the following:"}),e.jsxs("ul",{className:"text-sm mt-2 space-y-1 list-none",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:[e.jsx("li",{children:"Worked in private equity or provided capital to small and medium enterprises, and/or"}),e.jsx("li",{children:"Been the director of a company with an annual turnover of at least (USD) $2m million, and/or"}),e.jsx("li",{children:"Invested directly in at least 2 private (not listed) companies."})]})]})]})}),e.jsx("label",{className:"block p-4 border-2 rounded-lg cursor-pointer transition-all",style:{borderColor:a===je.HighNetWorth?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",backgroundColor:a===je.HighNetWorth?"var(--metakyc-primary-light, #dbeafe)":"transparent"},children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("input",{type:"radio",name:"investorType",value:je.HighNetWorth,checked:a===je.HighNetWorth,onChange:()=>o(je.HighNetWorth),className:"mt-1"}),e.jsxs("div",{className:"ml-3",children:[e.jsx("div",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"High networth investor"}),e.jsxs("div",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:["I earn more than (USD/EUR) $150,000 per year, and/or",e.jsx("br",{}),"I have net assets (excluding my main property) of at least $/EUR 300,000"]})]})]})}),y&&e.jsx("div",{className:"p-4 rounded-lg",style:{backgroundColor:"#fee2e2",border:"1px solid #fca5a5"},children:e.jsxs("p",{className:"text-sm",style:{color:"#991b1b"},children:[e.jsx("strong",{children:"Error:"})," ",y]})})]}),e.jsxs(ge,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"submit",isLoading:c,disabled:a===null,children:"Submit"})]})]})})};function Et(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),s=t%60;return`${r.toString().padStart(2,"0")}:${s.toString().padStart(2,"0")}`}const Wr=({applicantId:t,onComplete:r,onBack:s})=>{const{appropriatenessTestService:n}=Ne(),[a,o]=i.useState(null),[c,d]=i.useState(!0),[y,p]=i.useState(!1),[g,T]=i.useState(null),[v,E]=i.useState({}),[A,k]=i.useState(0),[S,M]=i.useState(!1),[Y,L]=i.useState(!1),[B,U]=i.useState(0),[X,R]=i.useState(0),[f,O]=i.useState(null);i.useEffect(()=>{(async()=>{try{d(!0),T(null);const z=await n.getAppropriatenessTest(t);if(o(z),z.waitTimeSpanForNextTry&&z.waitTimeSpanForNextTry!=="00:00:00"){const _=Et(z.waitTimeSpanForNextTry);_>0&&U(_)}}catch(z){T(z.message||"Failed to load appropriateness test")}finally{d(!1)}})()},[t,n]),i.useEffect(()=>{if(!S||A<=0)return;const z=setInterval(()=>{k(_=>_<=1?(L(!0),0):_-1)},1e3);return()=>clearInterval(z)},[S,A]),i.useEffect(()=>{if(B<=0)return;const z=setInterval(()=>{U(_=>_<=1?0:_-1)},1e3);return()=>clearInterval(z)},[B]),i.useEffect(()=>{Y&&!y&&G()},[Y]);const q=()=>{a&&(M(!0),k(a.testDurationSec),R(0),E({}),T(null))},Q=(z,_)=>{E(me=>({...me,[z]:_}))},$=i.useCallback(async()=>{try{const z=await n.getAppropriatenessTest(t);if(o(z),z.waitTimeSpanForNextTry&&z.waitTimeSpanForNextTry!=="00:00:00"){const _=Et(z.waitTimeSpanForNextTry);_>0&&U(_)}}catch{}},[t,n]),G=async z=>{if(a){if(!Y){const _=a.appropriatenessQuestions.length-Object.keys(v).length;if(_>0){T(`Please answer all questions. ${_} remaining.`);return}}p(!0),T(null);try{const _=a.appropriatenessQuestions.map(N=>({appropriatenessQuestionId:N.id,value:v[N.id]||""})),me={applicantId:t,appropriatenessTestId:a.id,appropriatenessQuestionResults:_};try{const N=await n.fillAppropriatenessTest(me);N.isSuccess?O({success:!0,message:N.message||"Congratulations! You have passed the test."}):(O({success:!1,message:N.message||"You did not pass the test."}),setTimeout(()=>$(),1e3))}catch(N){if(N.code===400&&N.message)O({success:!1,message:N.message}),setTimeout(()=>$(),1500);else throw N}}catch(_){T(_.message||"Failed to submit test. Please try again."),se()}finally{p(!1)}}},se=()=>{M(!1),L(!1),E({}),R(0)};if(c)return e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",padding:"48px 0",gap:"16px"},children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)"},children:"Loading test..."})]})})});if(!a)return e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("div",{style:{textAlign:"center",padding:"48px 0"},children:[e.jsx("p",{style:{fontSize:"16px",fontWeight:600,color:"var(--metakyc-danger, #ef4444)"},children:"No test data available"}),g&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"8px"},children:g})]})})});const V=a.testAllowedMaxTry-a.totalFailedTries,be=a.appropriatenessQuestions.length,ce=Object.keys(v).length;if(B>0)return e.jsxs(ee,{children:[e.jsx(fe,{children:e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:a.displayName})}),e.jsx(te,{children:e.jsxs("div",{style:{textAlign:"center",padding:"32px 0"},children:[e.jsx("div",{style:{width:"100px",height:"100px",borderRadius:"50%",margin:"0 auto 20px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"color-mix(in srgb, var(--metakyc-primary, #2563eb) 8%, transparent)"},children:e.jsx("span",{style:{fontSize:"28px",fontWeight:700,color:"var(--metakyc-primary, #2563eb)",fontVariantNumeric:"tabular-nums"},children:xt(B)})}),e.jsx("p",{style:{fontSize:"15px",fontWeight:500,color:"var(--metakyc-text-primary, #111827)"},children:"Please wait before retrying"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"4px"},children:"You can attempt the test again once the timer expires"}),g&&e.jsx("div",{style:{marginTop:"20px",padding:"12px 16px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:g})})]})})]});if(f){const z=()=>{O(null),se(),T(null)};return e.jsxs(ee,{children:[e.jsx(te,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",textAlign:"center",padding:"40px 16px",gap:"16px"},children:[e.jsx("div",{style:{width:"72px",height:"72px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:f.success?"color-mix(in srgb, var(--metakyc-success, #10b981) 12%, transparent)":"color-mix(in srgb, var(--metakyc-danger, #ef4444) 10%, transparent)"},children:f.success?e.jsxs("svg",{width:"36",height:"36",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-success, #10b981)",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),e.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]}):e.jsxs("svg",{width:"36",height:"36",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),e.jsx("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]})}),e.jsx("h2",{style:{fontSize:"20px",fontWeight:700,color:f.success?"var(--metakyc-success, #10b981)":"var(--metakyc-danger, #ef4444)",margin:0},children:f.success?"Test Passed":"Test Failed"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",margin:0,lineHeight:1.6,maxWidth:"400px",whiteSpace:"pre-line"},children:f.message}),!f.success&&V>0&&e.jsx("div",{style:{marginTop:"4px",padding:"10px 20px",borderRadius:"10px",backgroundColor:"var(--metakyc-surface, #f9fafb)",border:"1px solid var(--metakyc-border, #e5e7eb)"},children:e.jsxs("p",{style:{fontSize:"13px",color:"var(--metakyc-text-muted, #9ca3af)",margin:0},children:["You have ",e.jsx("strong",{style:{color:"var(--metakyc-text-primary, #111827)"},children:V})," attempt",V!==1?"s":""," remaining"]})}),!f.success&&V<=0&&e.jsx("div",{style:{marginTop:"4px",padding:"10px 20px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:"No attempts remaining. Please contact support for assistance."})})]})}),e.jsx(ge,{children:e.jsx("div",{style:{display:"flex",justifyContent:"center",width:"100%",gap:"12px"},children:f.success?e.jsx(J,{type:"button",onClick:()=>r==null?void 0:r(),children:"Continue"}):e.jsxs(e.Fragment,{children:[V>0&&B<=0&&e.jsx(J,{type:"button",onClick:z,children:"Retake Test"}),V>0&&B>0&&e.jsx(J,{type:"button",onClick:z,children:"OK"}),V<=0&&s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"})]})})})]})}if(!S)return e.jsxs(ee,{children:[e.jsxs(fe,{children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:a.displayName}),a.subtitle&&e.jsx("p",{style:{fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)",marginTop:"4px"},children:a.subtitle})]}),e.jsxs(te,{children:[a.description&&e.jsxs("div",{style:{marginBottom:"20px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-primary, #2563eb) 5%, var(--metakyc-background, #ffffff))",border:"1px solid color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)",display:"flex",gap:"10px"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-primary, #2563eb)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:"1px"},children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]}),e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-text-secondary, #374151)",margin:0,lineHeight:1.5},children:a.description})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px",marginBottom:"20px"},children:[e.jsx(ct,{icon:"questions",label:"Questions",value:String(a.totalQuestionCount)}),e.jsx(ct,{icon:"time",label:"Time Limit",value:xt(a.testDurationSec)}),e.jsx(ct,{icon:"target",label:"Pass Requirement",value:`${a.testCorrectAnswerPassLimit} correct`}),e.jsx(ct,{icon:"retry",label:"Attempts Left",value:String(V),variant:V<=1?"warning":"default"})]}),g&&e.jsxs("div",{style:{marginBottom:"16px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)",display:"flex",gap:"10px"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"var(--metakyc-danger, #ef4444)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:"1px"},children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),e.jsxs("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0,lineHeight:1.5},children:[e.jsx("strong",{children:"Previous attempt:"})," ",g]})]}),V<=0&&e.jsx("div",{style:{padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:"You have used all your attempts. Please contact support for assistance."})})]}),e.jsx(ge,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:s?"space-between":"flex-end",width:"100%"},children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"button",onClick:q,disabled:V<=0,children:"Start Test"})]})})]});const de=a.appropriatenessQuestions[X],he=X===be-1,I=ce===be,W=A<=60;return e.jsxs(ee,{children:[e.jsxs(fe,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)",margin:0},children:a.displayName}),e.jsxs("p",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)",marginTop:"2px"},children:["Question ",X+1," of ",be]})]}),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(A)})]})]}),e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsx("div",{style:{height:"4px",borderRadius:"999px",backgroundColor:"var(--metakyc-border, #e5e7eb)",overflow:"hidden"},children:e.jsx("div",{style:{height:"100%",borderRadius:"999px",backgroundColor:"var(--metakyc-primary, #2563eb)",width:`${ce/be*100}%`,transition:"width 0.3s ease"}})}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:"4px"},children:[e.jsxs("span",{style:{fontSize:"11px",color:"var(--metakyc-text-muted, #9ca3af)"},children:[ce," answered"]}),e.jsxs("span",{style:{fontSize:"11px",color:"var(--metakyc-text-muted, #9ca3af)"},children:[V," attempt",V!==1?"s":""," left"]})]})]})]}),e.jsxs(te,{children:[de&&e.jsx(Ls,{question:de,index:X,selectedAnswer:v[de.id],onSelect:z=>Q(de.id,z),disabled:y}),be>1&&e.jsx("div",{style:{display:"flex",justifyContent:"center",gap:"6px",marginTop:"20px",flexWrap:"wrap"},children:a.appropriatenessQuestions.map((z,_)=>e.jsx("button",{type:"button",onClick:()=>R(_),style:{width:"28px",height:"28px",borderRadius:"8px",border:_===X?"2px solid var(--metakyc-primary, #2563eb)":"1px solid var(--metakyc-border, #e5e7eb)",backgroundColor:v[z.id]?_===X?"color-mix(in srgb, var(--metakyc-primary, #2563eb) 15%, transparent)":"color-mix(in srgb, var(--metakyc-primary, #2563eb) 8%, transparent)":_===X?"var(--metakyc-surface, #f9fafb)":"var(--metakyc-background, #ffffff)",color:v[z.id]?"var(--metakyc-primary, #2563eb)":"var(--metakyc-text-muted, #9ca3af)",fontSize:"12px",fontWeight:600,cursor:"pointer",transition:"all 0.15s ease",padding:0,display:"flex",alignItems:"center",justifyContent:"center"},children:_+1},z.id))}),Y&&e.jsxs("div",{style:{marginTop:"16px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, #f59e0b 10%, transparent)",border:"1px solid color-mix(in srgb, #f59e0b 25%, transparent)",display:"flex",alignItems:"center",gap:"10px"},children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"#f59e0b",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),e.jsx("p",{style:{fontSize:"13px",color:"#b45309",margin:0,fontWeight:500},children:"Time's up! Your answers are being submitted."})]}),g&&!Y&&e.jsx("div",{style:{marginTop:"16px",padding:"12px 14px",borderRadius:"10px",backgroundColor:"color-mix(in srgb, var(--metakyc-danger, #ef4444) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--metakyc-danger, #ef4444) 20%, transparent)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--metakyc-danger, #ef4444)",margin:0},children:g})})]}),e.jsx(ge,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[e.jsx(J,{type:"button",variant:"outline",onClick:()=>{X>0?R(z=>z-1):s==null||s()},disabled:y,children:X>0?"Previous":"Cancel"}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[!he&&e.jsx(J,{type:"button",onClick:()=>R(z=>z+1),children:"Next"}),(he||I)&&e.jsx(J,{type:"button",isLoading:y,onClick:()=>G(),disabled:!I&&!Y,style:{opacity:I||Y?1:.5},children:Y?"Submitting...":"Submit Test"})]})]})})]})},Ps={questions:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M9 11l3 3L22 4"}),e.jsx("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),time:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),target:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("circle",{cx:"12",cy:"12",r:"6"}),e.jsx("circle",{cx:"12",cy:"12",r:"2"})]}),retry:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})},ct=({icon:t,label:r,value:s,variant:n="default"})=>{const a=n==="warning";return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px",padding:"14px",borderRadius:"10px",backgroundColor:a?"color-mix(in srgb, #f59e0b 8%, transparent)":"var(--metakyc-surface, #f9fafb)",border:a?"1px solid color-mix(in srgb, #f59e0b 20%, transparent)":"1px solid var(--metakyc-border, #e5e7eb)"},children:[e.jsx("div",{style:{color:a?"#f59e0b":"var(--metakyc-primary, #2563eb)",flexShrink:0},children:Ps[t]}),e.jsxs("div",{children:[e.jsx("p",{style:{fontSize:"12px",color:"var(--metakyc-text-muted, #9ca3af)",margin:0},children:r}),e.jsx("p",{style:{fontSize:"15px",fontWeight:600,color:a?"#b45309":"var(--metakyc-text-primary, #111827)",margin:0,marginTop:"1px"},children:s})]})]})},Ls=({question:t,selectedAnswer:r,onSelect:s,disabled:n})=>e.jsxs("div",{children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[t.groupName&&e.jsx("span",{style:{display:"inline-block",fontSize:"11px",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em",color:"var(--metakyc-primary, #2563eb)",marginBottom:"8px"},children:t.groupName}),e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--metakyc-text-primary, #111827)",margin:0,lineHeight:1.5},children:t.question})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.answers.map((a,o)=>{const c=r===a;return e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"12px",padding:"14px 16px",borderRadius:"10px",border:`2px solid ${c?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)"}`,backgroundColor:c?"color-mix(in srgb, var(--metakyc-primary, #2563eb) 5%, var(--metakyc-background, #ffffff))":"var(--metakyc-background, #ffffff)",cursor:n?"default":"pointer",transition:"all 0.15s ease",opacity:n?.6:1},onMouseEnter:d=>{!n&&!c&&(d.currentTarget.style.borderColor="color-mix(in srgb, var(--metakyc-primary, #2563eb) 50%, var(--metakyc-border, #e5e7eb))")},onMouseLeave:d=>{c||(d.currentTarget.style.borderColor="var(--metakyc-border, #e5e7eb)")},children:[e.jsx("div",{style:{width:"20px",height:"20px",borderRadius:"50%",border:`2px solid ${c?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #d1d5db)"}`,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,transition:"border-color 0.15s ease"},children:c&&e.jsx("div",{style:{width:"10px",height:"10px",borderRadius:"50%",backgroundColor:"var(--metakyc-primary, #2563eb)"}})}),e.jsx("input",{type:"radio",name:`q-${t.id}`,value:a,checked:c,onChange:()=>s(a),disabled:n,style:{position:"absolute",opacity:0,width:0,height:0}}),e.jsx("span",{style:{fontSize:"14px",color:c?"var(--metakyc-text-primary, #111827)":"var(--metakyc-text-secondary, #6b7280)",fontWeight:c?500:400,transition:"color 0.15s ease"},children:a})]},o)})})]}),Ur=({applicantId:t,onComplete:r,onBack:s})=>{var Je,$e,tt,Ke;const{applicantService:n,baseInformationService:a,identityService:o,config:c,currentTheme:d}=Ne(),{identityData:y,provider:p,token:g,isLoading:T,error:v,requestIdentity:E,restartIdentity:A}=Er(t),[k,S]=i.useState(null),[M,Y]=i.useState(null),[L,B]=i.useState([]),[U,X]=i.useState([]),[R,f]=i.useState(!0),[O,q]=i.useState(!1),[Q,$]=i.useState(null),[G,se]=i.useState(!1),V=i.useRef(!1),[be,ce]=i.useState({}),[de,he]=i.useState({}),I=d!=null&&d.reviewPageFields&&d.reviewPageFields.length>0?d.reviewPageFields[0]:null,W=!!(d!=null&&d.reviewPageDisabled),z=i.useRef(!1);z.current=W;const _=Ve.useForm({defaultValues:{street:"",streetNumber:"",city:"",zip:"",country:"",nationality:"",phonenumber:""}});i.useEffect(()=>{if(W){V.current||(V.current=!0,E().then(()=>q(!0)).catch(D=>console.error("[Identity] Auto-request failed:",D)).finally(()=>f(!1)));return}(async()=>{try{const[D,K,H]=await Promise.all([n.getApplicantData(t),a.getCountries("","en"),a.getCountries("","en",40)]);Y(D);const Z=new Set,m=K.map(h=>({value:h.abbreviation3||h.abbreviation,label:h.name})).filter(h=>!h.value||Z.has(h.value)?!1:(Z.add(h.value),!0));B(m);const C=new Set,F=H.filter(h=>h.countryCode).map(h=>({value:h.countryCode,label:`${h.countryCode} – ${h.name}`})).filter(h=>C.has(h.value)?!1:(C.add(h.value),!0));X(F);const u=D.applicantRequestData;if(ce({firstName:(u==null?void 0:u.firstName)||"",lastName:(u==null?void 0:u.lastName)||"",email:(u==null?void 0:u.email)||"",dateOfBirth:(u==null?void 0:u.dateOfBirth)||"",title:(u==null?void 0:u.title)||"",salutation:(u==null?void 0:u.salutation)||"",phonenumber:(u==null?void 0:u.phonenumber)||"",mobileCountryCode:(u==null?void 0:u.mobileCountryCode)||"",street:(u==null?void 0:u.street)||"",streetNumber:(u==null?void 0:u.streetNumber)||"",city:(u==null?void 0:u.city)||"",zip:(u==null?void 0:u.zip)||"",country:(u==null?void 0:u.country)||"",nationality:(u==null?void 0:u.nationality)||"",taxCountry:(u==null?void 0:u.taxCountry)||"",countryOfBirth:(u==null?void 0:u.countryOfBirth)||"",placeOfBirth:(u==null?void 0:u.placeOfBirth)||"",educationLevel:(u==null?void 0:u.educationLevel)||"",occupation:(u==null?void 0:u.occupation)||"",taxNumber:(u==null?void 0:u.taxNumber)||"",defaultLanguage:(u==null?void 0:u.defaultLanguage)||""}),_.reset({street:(u==null?void 0:u.street)||"",streetNumber:(u==null?void 0:u.streetNumber)||"",city:(u==null?void 0:u.city)||"",zip:(u==null?void 0:u.zip)||"",country:(u==null?void 0:u.country)||"",nationality:(u==null?void 0:u.nationality)||"",phonenumber:(u==null?void 0:u.phonenumber)||""}),D.kycRecords&&D.kycRecords.length>0&&D.kycRecords[0].providerTokenObject!==null&&!V.current&&z.current){console.log("[Identity] Review page disabled + existing identity — auto-requesting..."),V.current=!0;try{await E(),q(!0)}catch(h){console.error("[Identity] Auto-request failed:",h)}}}catch(D){console.error("Error loading applicant data:",D)}finally{f(!1)}})()},[t]),i.useEffect(()=>{y&&!O&&z.current&&(console.log("[Identity] Review page disabled — showing cached provider"),q(!0))},[y,O]),i.useEffect(()=>{if(g){if(g.expiresAt){const x=new Date(g.expiresAt).getTime();if(Date.now()>=x){console.warn("[Identity] Token has expired (expiresAt)"),se(!0),$("Your verification session has expired. Please restart.");return}}if(g.url)try{const D=new URL(g.url).toString().toLowerCase();if(D.includes("expired")||D.includes("invalid")||D.includes("error")){console.warn("[Identity] Token URL indicates expiration"),se(!0),$("Your verification link has expired. Please restart.");return}}catch{console.error("[Identity] Invalid token URL")}if(g.status==="expired"||g.error==="expired"||g.expired===!0){console.warn("[Identity] Token object indicates expiration"),se(!0),$("Your verification session has expired. Please restart.");return}}},[g]);const me=p!==null&&p===Ae.Sumsub;i.useEffect(()=>{if(p!==null&&g&&!k&&O&&!G){const x=p;if(me){console.log("[Sumsub] Fetching access token for Web SDK…"),$(null),(async()=>{try{const D=await o.refreshSumsubToken(t),K=He.parseProviderConfig(p,g,c);K.accessToken=D,K.onTokenRefresh=()=>o.refreshSumsubToken(t);const H=He.createProvider(p,K);H.onComplete(Z=>{console.log("[Sumsub] Verification complete:",Z),r==null||r()}),H.onError(Z=>{console.error("[Sumsub] SDK error:",Z),(typeof Z=="string"?Z:(Z==null?void 0:Z.message)||"Unknown error").toLowerCase().includes("expired")&&(se(!0),$("Session expired. Please restart."))}),await H.initialize("sumsub-websdk-container"),console.log("[Sumsub] Web SDK launched"),S(H)}catch(D){console.error("[Sumsub] Initialization error:",D),$(`Failed to initialize: ${D.message||D}`),String(D.message||D).toLowerCase().includes("expired")&&se(!0)}})();return}if(g.url){console.log("[Identity] Loading provider URL for user verification:",g.url),$(null);try{if(new URL(g.url),x===Ae.SardinAI){console.log("[SardinAI] Initializing Risk SDK in background...");try{const D=He.parseProviderConfig(p,g,c);He.createProvider(p,D).initialize().then(()=>console.log("[SardinAI] Risk SDK initialized in background")).catch(H=>console.warn("[SardinAI] Risk SDK init failed (non-blocking):",H))}catch(D){console.warn("[SardinAI] Risk SDK setup failed (non-blocking):",D)}}S({type:"url",url:g.url})}catch(D){console.error("[Identity] Invalid URL:",D),$("Invalid verification URL. Please restart."),se(!0)}return}if(x===Ae.SardinAI){console.log("[SardinAI] No URL provided - initializing Risk SDK only..."),$(null);try{const D=He.parseProviderConfig(p,g,c),K=He.createProvider(p,D);K.initialize().then(()=>{console.log("[SardinAI] Risk SDK initialized successfully"),S(K),setTimeout(()=>r==null?void 0:r(),2e3)}).catch(H=>{var m;console.error("[SardinAI] Failed to initialize:",H);const Z=((m=H.message)==null?void 0:m.toLowerCase())||"";Z.includes("expired")||Z.includes("invalid")||Z.includes("401")||Z.includes("400")?(se(!0),$("Session expired or invalid. Please restart verification.")):$(`Failed to initialize: ${H.message}`)})}catch(D){console.error("[SardinAI] Error creating provider:",D),$(`Configuration error: ${D.message}`)}return}try{$(null);const D=He.parseProviderConfig(p,g,c),K=He.createProvider(p,D);x===Ae.Onfido&&K.initialize("identity-container").catch(H=>{console.error("[Onfido] Initialization error:",H),$(`Failed to initialize: ${H.message}`)}),S(K)}catch(D){console.error("[Identity] Provider setup error:",D),$(`Setup error: ${D.message}`)}}return()=>{if(k&&k.destroy)try{k.destroy()}catch(x){console.error("[Identity] Error destroying provider:",x)}}},[p,g,k,O,r,G,me,t,c,o]);const N=async()=>{try{$(null),se(!1),await E(),q(!0)}catch(x){console.error("Error starting identity verification:",x)}},re=async()=>{try{$(null),se(!1),S(null),console.log("[Identity] Restarting verification..."),await A(),q(!0)}catch(x){console.error("Error restarting identity verification:",x),$(x.message||"Failed to restart verification")}};if(R||T)return e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center text-gray-600 dark:text-gray-400 mt-4",children:"Loading identity verification..."})]})});if(v)return e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("p",{className:"text-danger-500",children:["Error: ",v.message]})})});if(O&&(Q||G))return e.jsxs(ee,{children:[e.jsx(fe,{children:e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"Verification Session Issue"})}),e.jsxs(te,{children:[e.jsx("div",{className:"p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg mb-6",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("svg",{className:"h-6 w-6 text-red-600 dark:text-red-400 mr-3 mt-0.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-red-900 dark:text-red-100 mb-1",children:G?"Session Expired":"Verification Error"}),e.jsx("p",{className:"text-red-800 dark:text-red-200 text-sm",children:Q||"Your verification session has expired and needs to be restarted."})]})]})}),e.jsxs("div",{className:"bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-4",children:[e.jsx("h3",{className:"font-semibold text-blue-900 dark:text-blue-100 mb-2",children:"What to do next:"}),e.jsxs("ul",{className:"text-blue-800 dark:text-blue-200 text-sm space-y-1 list-disc list-inside",children:[e.jsx("li",{children:'Click "Restart Verification" below to generate a new session'}),e.jsx("li",{children:"Complete the verification process without delays"}),e.jsx("li",{children:"If issues persist, contact support"})]})]})]}),e.jsxs(ge,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"button",onClick:re,disabled:T,children:T?"Restarting...":"Restart Verification"})]})]});if(O&&y){const x=p;return me?e.jsxs("div",{style:{background:"var(--metakyc-background, #ffffff)",borderRadius:"12px",border:"1px solid var(--metakyc-border, #e5e7eb)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"20px 24px",borderBottom:"1px solid var(--metakyc-border, #e5e7eb)"},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{margin:0,fontSize:"20px",fontWeight:700,color:"var(--metakyc-text-primary, #111827)"},children:"Identity Verification"}),e.jsx("p",{style:{margin:"4px 0 0",fontSize:"14px",color:"var(--metakyc-text-secondary, #6b7280)"},children:"Please complete the identity verification process"})]}),e.jsx("button",{type:"button",onClick:re,disabled:T,style:{padding:"6px 14px",fontSize:"13px",fontWeight:500,borderRadius:"8px",border:"1px solid var(--metakyc-border, #d1d5db)",background:"var(--metakyc-background, #ffffff)",color:"var(--metakyc-text-primary, #111827)",cursor:T?"not-allowed":"pointer",opacity:T?.5:1},children:T?"Restarting…":"Restart"})]}),e.jsx("div",{id:"sumsub-websdk-container",style:{minHeight:"520px",width:"100%",padding:"16px 24px",background:"var(--metakyc-background, #ffffff)"}}),s&&e.jsx("div",{style:{padding:"16px 24px",borderTop:"1px solid var(--metakyc-border, #e5e7eb)"},children:e.jsx(J,{variant:"outline",onClick:s,children:"Back"})})]}):g!=null&&g.url?e.jsxs(ee,{children:[e.jsx(fe,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Identity Verification"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:"Please complete the identity verification process"})]}),e.jsx(J,{type:"button",variant:"outline",size:"sm",onClick:re,disabled:T,children:"Restart"})]})}),e.jsxs(te,{children:[e.jsx("div",{className:"mb-4 p-3 bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg",children:e.jsxs("p",{className:"text-yellow-800 dark:text-yellow-200 text-sm",children:[e.jsx("strong",{children:"Important:"}),' If you see an "expired" or "invalid link" message below, click the "Restart" button above to generate a new verification session.']})}),e.jsx("div",{className:"w-full",style:{height:"600px"},children:e.jsx("iframe",{src:g.url,className:"w-full h-full border-0 rounded-lg",allow:"camera; microphone; geolocation",title:"Identity Verification",onLoad:D=>{var K,H,Z;console.log("[Identity] Iframe loaded");try{const m=D.target,C=m.contentDocument||((K=m.contentWindow)==null?void 0:K.document);if(C){const F=((Z=(H=C.body)==null?void 0:H.textContent)==null?void 0:Z.toLowerCase())||"";(F.includes("expired")||F.includes("invalid")||F.includes("error"))&&(console.warn("[Identity] Iframe shows expiration message"),se(!0),$("Your verification link has expired."))}}catch{console.log("[Identity] Cannot check iframe content (CORS)")}}})})]}),s&&e.jsx(ge,{children:e.jsx(J,{variant:"outline",onClick:s,children:"Back"})})]}):x===Ae.SardinAI?e.jsxs(ee,{children:[e.jsxs(fe,{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Device Risk Assessment"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:"Analyzing device security and behavioral patterns..."})]}),e.jsx(te,{children:e.jsxs("div",{className:"text-center py-12",children:[e.jsx(Ee,{className:"mb-4"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Please wait while we verify your device security"}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-500 mt-2",children:"This process is automatic and will complete in a few seconds"})]})})]}):e.jsxs(ee,{children:[e.jsxs(fe,{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Identity Verification"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:"Please complete the identity verification process"})]}),e.jsx(te,{children:e.jsx("div",{id:"identity-container",className:"min-h-[400px]"})}),s&&e.jsx(ge,{children:e.jsx(J,{variant:"outline",onClick:s,children:"Back"})})]})}const ue=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),ne=(x=4)=>{const D=Math.min(4,Math.max(1,Number(x)||4));return{gridColumn:`span ${D} / span ${D}`}},ve=(x,D)=>{if(!D&&D!==0)return"—";if(ue.has(x)&&x!=="mobileCountryCode"){const K=L.find(H=>H.value===D);return K?K.label:String(D)}return String(D)},Pe=({helpText:x})=>{const[D,K]=i.useState(!1),H=i.useRef(null),[,Z]=i.useState({top:0,left:0}),m=()=>{if(H.current){const C=H.current.getBoundingClientRect();Z({top:C.bottom+window.scrollY+6,left:C.left+window.scrollX})}K(!0)};return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"metakyc-help-btn",ref:H,onClick:m,style:{width:18,height:18,borderRadius:"50%",border:"1.5px solid var(--metakyc-primary, #2563eb)",background:"transparent",color:"var(--metakyc-primary, #2563eb)",fontSize:11,fontWeight:700,cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,lineHeight:1,position:"relative",zIndex:2},children:"?"}),D&&pt.createPortal(e.jsx("div",{style:{position:"fixed",inset:0,zIndex:99999,background:"rgba(0,0,0,0.55)",backdropFilter:"blur(6px)",WebkitBackdropFilter:"blur(6px)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:()=>K(!1),children:e.jsxs("div",{onClick:C=>C.stopPropagation(),style:{background:"var(--metakyc-surface, var(--metakyc-background, #ffffff))",border:"1px solid var(--metakyc-border, #e5e7eb)",borderRadius:"var(--metakyc-border-radius, 8px)",padding:"20px 24px",maxWidth:400,width:"90%",boxShadow:"0 24px 64px rgba(0,0,0,0.4)"},children:[e.jsx("div",{dangerouslySetInnerHTML:{__html:x},style:{fontSize:13,color:"var(--metakyc-text-primary, #111827)",lineHeight:1.6}}),e.jsx("button",{type:"button",onClick:()=>K(!1),style:{marginTop:12,padding:"4px 12px",fontSize:12,border:"1px solid var(--metakyc-border, #e5e7eb)",borderRadius:"var(--metakyc-border-radius, 6px)",background:"transparent",cursor:"pointer",color:"var(--metakyc-text-secondary, #6b7280)"},children:"Close"})]})}),document.body)]})},ke=(x,D)=>D?e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:5,flexWrap:"nowrap"},children:[e.jsx("div",{style:{flex:1,minWidth:0},children:x}),e.jsx("div",{style:{paddingTop:24},children:e.jsx(Pe,{helpText:D})})]}):x,ze=(x,D)=>{const K=`cf-${D}`,H=x.paramName??"",Z=de[H];if(x.customType==="br")return e.jsx("div",{style:{...ne(x.colSpan),minHeight:"0.5rem"}},K);if(x.customType==="paragraph")return e.jsx("div",{style:ne(x.colSpan),children:e.jsx("div",{className:"text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:x.label||""}})},K);if(x.customType==="html")return e.jsx("div",{style:ne(x.colSpan),dangerouslySetInnerHTML:{__html:x.label||""}},K);if(x.customType==="link")return e.jsx("div",{style:ne(x.colSpan),children:ke(e.jsx("a",{href:x.linkUrl??"#",target:"_blank",rel:"noopener noreferrer",className:"text-sm underline",style:{color:"var(--metakyc-primary, #6366f1)"},children:x.displayText||x.label||x.linkText||x.linkUrl}),x.helpText)},K);if(x.customType==="checkbox"||x.customType==="link_checkbox"){const m=Z==="true"||Z===!0;return e.jsx("div",{style:ne(x.colSpan),children:ke(e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx(Fe,{checked:!!m,onChange:C=>he(F=>({...F,[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)},K)}if(x.customType==="group_checkbox"){const m=Array.isArray(Z)?Z:Z?[Z]:[],C=F=>{x.singleSelect?he(u=>({...u,[H]:m[0]===F?[]:[F]})):he(u=>({...u,[H]:m.includes(F)?m.filter(l=>l!==F):[...m,F]}))};return e.jsx("div",{style:ne(x.colSpan),children:ke(e.jsxs("div",{className:"space-y-1.5",children:[x.label&&e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:x.displayText||x.label}),(x.options||[]).map(F=>e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx(Fe,{checked:m.includes(F.value),onChange:()=>C(F.value),style:{marginTop:2}}),e.jsx("span",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)"},children:F.label})]},F.value))]}),x.helpText)},K)}return x.customType==="radio_group"?e.jsx("div",{style:ne(x.colSpan),children:ke(e.jsxs("div",{className:"space-y-1.5",children:[x.label&&e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:x.displayText||x.label}),(x.options||[]).map(m=>e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"radio",name:`rg-${H}`,value:m.value,checked:Z===m.value,onChange:()=>he(C=>({...C,[H]:m.value})),style:{width:16,height:16,flexShrink:0,marginTop:2,accentColor:"var(--metakyc-primary, #6366f1)"}}),e.jsx("span",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)"},children:m.label})]},m.value))]}),x.helpText)},K):e.jsx("div",{style:ne(x.colSpan),children:ke(e.jsx(ye,{label:x.displayText||x.label||H,value:String(Z??""),onChange:m=>he(C=>({...C,[H]:m.target.value}))}),x.helpText)},K)},et=(x,D)=>{if(x.isCustom)return ze(x,D);const K=x.name??"",H=Ge[K],Z=x.displayText||(H==null?void 0:H.label)||K,m=be[K]??"",C=K==="mobileCountryCode",F=!!(H!=null&&H.countriesType)&&!C;return x.editable?C?e.jsx("div",{style:ne(x.colSpan??2),children:ke(e.jsx(Oe,{label:Z,value:String(m),onChange:u=>ce(l=>({...l,[K]:u})),options:[{value:"",label:"Select country code…"},...U]}),x.helpText)},`epc-${D}`):F?e.jsx("div",{style:ne(x.colSpan??2),children:ke(e.jsx(Oe,{label:Z,value:String(m),onChange:u=>ce(l=>({...l,[K]:u})),options:[{value:"",label:`Select ${Z.toLowerCase()}…`},...L]}),x.helpText)},`ec-${D}`):e.jsx("div",{style:ne(x.colSpan??2),children:ke(e.jsx(ye,{label:Z,type:(H==null?void 0:H.type)==="date"?"date":(H==null?void 0:H.type)==="email"?"email":"text",value:String(m),onChange:u=>ce(l=>({...l,[K]:u.target.value}))}),x.helpText)},`ei-${D}`):e.jsx("div",{style:ne(x.colSpan??2),children:ke(e.jsxs(e.Fragment,{children:[e.jsx("label",{className:"block text-sm font-medium mb-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:Z}),e.jsx("p",{className:"text-sm",style:{color:"var(--metakyc-text-primary, #111827)",minHeight:"1.5rem"},children:ve(K,m)})]}),x.helpText)},`ro-${D}`)};if(I){const x=I.title||"Review Your Information",D=I.subtitle||"Please review and confirm your information before starting identity verification";return e.jsx("form",{onSubmit:K=>{K.preventDefault(),N()},children:e.jsxs(ee,{children:[e.jsxs(fe,{children:[e.jsx("h2",{className:"text-lg font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:x}),e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:D})]}),e.jsx(te,{children:e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:I.fields.map((K,H)=>et(K,H))})}),e.jsxs(ge,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"submit",isLoading:T,children:"Confirm and Start Verification"})]})]})})}return e.jsx("form",{onSubmit:_.handleSubmit(N),children:e.jsxs(ee,{children:[e.jsxs(fe,{children:[e.jsx("h2",{className:"text-lg font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Review Your Information"}),e.jsx("p",{className:"mt-1 text-sm",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Please review and confirm your information before starting identity verification"})]}),e.jsxs(te,{className:"space-y-6",children:[e.jsx("div",{className:"space-y-4 pb-4",style:{borderBottom:"1px solid var(--metakyc-border, #e5e7eb)"},children:[{label:"Name",value:`${((Je=M==null?void 0:M.applicantRequestData)==null?void 0:Je.firstName)||""} ${(($e=M==null?void 0:M.applicantRequestData)==null?void 0:$e.lastName)||""}`.trim()},{label:"Email",value:(tt=M==null?void 0:M.applicantRequestData)==null?void 0:tt.email},{label:"Date of Birth",value:((Ke=M==null?void 0:M.applicantRequestData)==null?void 0:Ke.dateOfBirth)||"Not provided"}].map(({label:x,value:D})=>e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:x}),e.jsx("p",{className:"mt-1 text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:D})]},x))}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-base font-semibold",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Address Information"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Ve.Controller,{control:_.control,name:"country",render:({field:x})=>e.jsx(Oe,{label:"Country",value:x.value,onChange:x.onChange,options:[{value:"",label:"Select country…"},...L]})}),e.jsx(Ve.Controller,{control:_.control,name:"nationality",render:({field:x})=>e.jsx(Oe,{label:"Nationality",value:x.value,onChange:x.onChange,options:[{value:"",label:"Select nationality…"},...L]})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(Ve.Controller,{control:_.control,name:"street",render:({field:x})=>e.jsx(ye,{...x,label:"Street"})}),e.jsx(Ve.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(Ve.Controller,{control:_.control,name:"city",render:({field:x})=>e.jsx(ye,{...x,label:"City"})}),e.jsx(Ve.Controller,{control:_.control,name:"zip",render:({field:x})=>e.jsx(ye,{...x,label:"ZIP / Postal Code"})})]}),e.jsx(Ve.Controller,{control:_.control,name:"phonenumber",render:({field:x})=>e.jsx(ye,{...x,label:"Phone Number",type:"tel"})})]})]}),e.jsxs(ge,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[s&&e.jsx(J,{type:"button",variant:"outline",onClick:s,children:"Back"}),e.jsx(J,{type:"submit",isLoading:T,children:"Confirm and Start Verification"})]})]})})},gt=({kycStatus:t,reviewStatus:r,workflowResult:s,customMessage:n,onContinue:a,onContactSupport:o})=>{const d=t===Ye.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===Ye.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===Ye.Pending||t===Ye.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."}:s===ot.Success?{type:"success",title:"Process Complete",icon:"✓",iconBg:"bg-green-100 dark:bg-green-900/30",iconColor:"text-green-600 dark:text-green-400",message:"Your verification process has been completed successfully."}:s===ot.Failed?{type:"error",title:"Process Failed",icon:"✕",iconBg:"bg-red-100 dark:bg-red-900/30",iconColor:"text-red-600 dark:text-red-400",message:"The verification process could not be completed."}:s===ot.AdminReview?{type:"pending",title:"Admin Review Required",icon:"📋",iconBg:"bg-yellow-100 dark:bg-yellow-900/30",iconColor:"text-yellow-700 dark:text-yellow-400",message:"Your application requires administrator review."}:{type:"pending",title:"Processing",icon:"⏱",iconBg:"bg-blue-100 dark:bg-blue-900/30",iconColor:"text-blue-600 dark:text-blue-400",message:"Your application is being reviewed."};return e.jsxs(ee,{children:[e.jsxs(te,{className:"py-12",children:[e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx("div",{className:`w-24 h-24 rounded-full flex items-center justify-center ${d.iconBg}`,children:e.jsx("span",{className:`text-5xl ${d.iconColor}`,children:d.icon})})}),e.jsx("h2",{className:"text-3xl font-bold text-center mb-4",style:{color:"var(--metakyc-text-primary, #111827)"},children:d.title}),e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx(jt,{variant:d.type==="success"?"success":d.type==="error"?"danger":d.type==="pending"?"warning":"info",children:t!=null?Ye[t]:Qe[r]})}),e.jsx("p",{className:"text-center mb-6 max-w-md mx-auto",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:n||d.message}),d.type==="success"&&e.jsxs("div",{className:"bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg p-4 mb-6",children:[e.jsx("h3",{className:"font-semibold text-green-900 dark:text-green-100 mb-2",children:"What's Next?"}),e.jsxs("ul",{className:"text-sm text-green-800 dark:text-green-200 space-y-1",children:[e.jsx("li",{children:"✓ Your identity has been verified"}),e.jsx("li",{children:"✓ You can now proceed with your application"}),e.jsx("li",{children:"✓ All features are now accessible"})]})]}),d.type==="error"&&e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 mb-6",children:[e.jsx("h3",{className:"font-semibold text-red-900 dark:text-red-100 mb-2",children:"What Can You Do?"}),e.jsxs("ul",{className:"text-sm text-red-800 dark:text-red-200 space-y-2",children:[e.jsx("li",{children:"• Review the requirements and ensure all information is correct"}),e.jsx("li",{children:"• Contact our support team for assistance"}),e.jsx("li",{children:"• You may be able to resubmit your application"})]})]}),d.type==="pending"&&e.jsxs("div",{className:"bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-4 mb-6",children:[e.jsx("h3",{className:"font-semibold text-blue-900 dark:text-blue-100 mb-2",children:"What Happens Next?"}),e.jsxs("ul",{className:"text-sm text-blue-800 dark:text-blue-200 space-y-2",children:[e.jsx("li",{children:"• Our team is reviewing your information"}),e.jsx("li",{children:"• You will be notified via email once the review is complete"}),e.jsx("li",{children:"• This typically takes 24-48 hours"}),e.jsx("li",{children:"• No action is required from you at this time"})]})]}),e.jsx("div",{className:"mt-6 pt-6",style:{borderTop:"1px solid var(--metakyc-border, #e5e7eb)"},children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"KYC Status:"}),e.jsx("div",{className:"font-medium mt-1",style:{color:"var(--metakyc-text-primary, #111827)"},children:t!=null?Ye[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(ge,{style:{display:"flex",justifyContent:"center",gap:"1rem"},children:[d.type==="success"&&a&&e.jsx(J,{onClick:a,size:"lg",children:"Continue"}),d.type==="error"&&e.jsxs(e.Fragment,{children:[o&&e.jsx(J,{variant:"outline",onClick:o,children:"Contact Support"}),a&&e.jsx(J,{onClick:a,children:"Try Again"})]}),d.type==="pending"&&e.jsx("div",{className:"text-center",children:e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Please check back later or wait for our email notification"})})]})]})},Kr=({config:t,className:r=""})=>!(t!=null&&t.visible)||!(t!=null&&t.url)?null:e.jsx("div",{className:`metakyc-logo ${r}`,children:e.jsx("img",{src:t.url,alt:t.alt||"Company Logo",style:{width:t.width||"auto",height:t.height||"40px",maxWidth:"100%",objectFit:"contain"},onError:s=>{console.warn("[Logo] Failed to load logo:",t.url),s.target.style.display="none"}})}),at=({title:t,subtitle:r,className:s=""})=>{const{currentTheme:n}=Ne(),a=t||(n==null?void 0:n.title)||"",o=!!(n!=null&&n.logo&&n.logo.visible&&n.logo.url),c=!!a;return!o&&!c?null:e.jsxs("div",{className:`metakyc-header ${s}`,children:[e.jsxs("div",{className:"metakyc-header-title flex items-center text-xl font-bold",style:{color:"var(--metakyc-text-primary, #111827)"},children:[o&&e.jsx(Kr,{config:n.logo}),o&&c&&e.jsx("span",{style:{fontSize:"1.5rem",fontWeight:300,color:"var(--metakyc-text-muted, #9ca3af)",margin:"0 12px"},children:"|"}),c&&e.jsx("span",{style:{color:"var(--metakyc-text-primary, #111827)"},children:a})]}),r&&e.jsx("p",{className:"text-sm mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:r})]})},dt=["firstName","lastName","email","phonenumber","dateOfBirth"];function rt(t){return t==null||t===""||Array.isArray(t)&&t.length===0}const Ds={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"},At=({helpText:t,children:r})=>{const[s,n]=i.useState(!1);if(!t)return e.jsx(e.Fragment,{children:r});const a=s?e.jsx("div",{role:"dialog","aria-modal":"true",onClick:()=>n(!1),style:{position:"fixed",inset:0,zIndex:999999,background:"rgba(0, 0, 0, 0.55)",backdropFilter:"blur(6px)",WebkitBackdropFilter:"blur(6px)",display:"flex",alignItems:"center",justifyContent:"center",padding:"16px"},children:e.jsxs("div",{onClick:o=>o.stopPropagation(),style:{background:"var(--metakyc-surface, var(--metakyc-background, #ffffff))",border:"1px solid var(--metakyc-border, #e5e7eb)",borderRadius:"12px",padding:"28px 24px 24px",maxWidth:"480px",width:"100%",maxHeight:"80vh",overflowY:"auto",boxShadow:"0 24px 64px rgba(0,0,0,0.4)",position:"relative"},children:[e.jsx("button",{type:"button",onClick:()=>n(!1),"aria-label":"Close",style:{position:"absolute",top:"12px",right:"12px",width:"28px",height:"28px",borderRadius:"50%",border:"1px solid var(--metakyc-border, #e5e7eb)",background:"var(--metakyc-input-bg, #f3f4f6)",color:"var(--metakyc-text-secondary, #6b7280)",fontSize:"16px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:"×"}),e.jsx("div",{style:{color:"var(--metakyc-text-primary, #111827)",fontSize:"14px",lineHeight:1.75},dangerouslySetInnerHTML:{__html:t}})]})}):null;return e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"5px",flexWrap:"nowrap"},children:[r,e.jsx("button",{type:"button",className:"metakyc-help-btn",onClick:()=>n(!0),"aria-label":"Help",style:{flexShrink:0,marginTop:"2px",width:"18px",height:"18px",borderRadius:"50%",border:"1.5px solid var(--metakyc-primary, #2563eb)",background:"transparent",color:"var(--metakyc-primary, #2563eb)",fontSize:"10px",fontWeight:"700",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,padding:0,position:"relative",zIndex:2,transition:"background 0.15s, color 0.15s"},onMouseEnter:o=>{o.currentTarget.style.background="var(--metakyc-primary, #2563eb)",o.currentTarget.style.color="#ffffff"},onMouseLeave:o=>{o.currentTarget.style.background="transparent",o.currentTarget.style.color="var(--metakyc-primary, #2563eb)"},children:"?"}),typeof document<"u"&&a?pt.createPortal(a,document.body):null]})},Ms=({workflowKey:t,externalRefId:r,onSuccess:s,onCancel:n})=>{var K,H,Z,m,C,F,u;const{config:a,baseInformationService:o,currentTheme:c}=Ne(),{createApplicant:d,isLoading:y}=kt(),p=t||((K=a.applicantForm)==null?void 0:K.workflowKey);if(!p)throw new Error("workflowKey is required. Provide it either as a prop to CreateApplicantForm or set it in config.applicantForm.workflowKey");const g=r||((H=a.applicantForm)==null?void 0:H.externalRefId)||"",T=((Z=a.applicantForm)==null?void 0:Z.email)||"",v=((m=a.applicantForm)==null?void 0:m.hiddenValues)||{},E=((C=a.applicantForm)==null?void 0:C.initialValues)||{},k=(((F=a.applicantForm)==null?void 0:F.fieldLabelMode)||(c==null?void 0:c.fieldLabelMode)||"label")!=="placeholder",S=i.useMemo(()=>c!=null&&c.applicantFormPages&&c.applicantFormPages.length>0?c.applicantFormPages:null,[c==null?void 0:c.applicantFormPages]),M=i.useMemo(()=>{const l=new Set(dt),h=c==null?void 0:c.applicantFormRequiredFields;if(h)for(const P of h)l.add(P);if(S)for(const P of S)for(const b of P.fields)!b.isCustom&&b.name&&b.required&&l.add(b.name);return Array.from(l)},[c==null?void 0:c.applicantFormRequiredFields,S]),Y=i.useMemo(()=>{var P;if(S){const b=S.flatMap(j=>j.fields).filter(j=>!j.isCustom&&j.name).map(j=>j.name),w=new Set(b);for(const j of dt)w.add(j);return Array.from(w)}let l;(P=a.applicantForm)!=null&&P.visibleFields?l=a.applicantForm.visibleFields:c!=null&&c.applicantFormVisibleFields&&c.applicantFormVisibleFields.length>0?l=c.applicantFormVisibleFields:l=Ut;const h=new Set(l);for(const b of dt)h.add(b);return Array.from(h)},[(u=a.applicantForm)==null?void 0:u.visibleFields,c==null?void 0:c.applicantFormVisibleFields,S]),L=new Set(["country","nationality","taxCountry","countryOfBirth","mobileCountryCode","otherNationality"]),B=i.useMemo(()=>{var h,P;const l=new Set;if(S)for(const b of S)for(const w of b.fields)!w.isCustom&&w.name&&L.has(w.name)&&l.add(w.countriesType??((h=Ge[w.name])==null?void 0:h.countriesType));else for(const b of Y)L.has(b)&&l.add((P=Ge[b])==null?void 0:P.countriesType);return l.size===0&&l.add(void 0),Array.from(l)},[Y,S]),[U,X]=i.useState({}),[R,f]=i.useState(!0),O=i.useRef(new Set),q=i.useRef(new Set);i.useEffect(()=>{if(!c)return;const l=B.filter(b=>{const w=b!=null?String(b):"all";return!q.current.has(w)&&!O.current.has(w)});if(l.length===0){B.every(w=>{const j=w!=null?String(w):"all";return q.current.has(j)})&&f(!1);return}f(!0);const h=l.map(b=>b!=null?String(b):"all");h.forEach(b=>O.current.add(b)),(async()=>{try{const b=await Promise.all(l.map(async w=>{const j=w!=null?String(w):"all",le=await o.getCountries("",a.locale||"en",w),ae=w===40,xe=new Set,Ie=le.map(ie=>ae&&ie.countryCode?{value:ie.countryCode,label:`${ie.countryCode} – ${ie.name}`}:{value:ie.abbreviation3||ie.abbreviation,label:ie.name}).filter(ie=>!ie.value||xe.has(ie.value)?!1:(xe.add(ie.value),!0));return q.current.add(j),O.current.delete(j),[j,Ie]}));X(w=>({...w,...Object.fromEntries(b)}))}catch(b){h.forEach(w=>O.current.delete(w)),console.error("Failed to load countries:",b)}finally{B.every(w=>{const j=w!=null?String(w):"all";return q.current.has(j)})&&f(!1)}})()},[B,c]);const Q=(l,h)=>{var w;const P=h??((w=Ge[l])==null?void 0:w.countriesType),b=P!=null?String(P):"all";return U[b]||[]},$={firstName:1,lastName:1,title:1,email:1,dateOfBirth:1,phonenumber:1,mobileCountryCode:1,street:1,streetNumber:1,zip:1,city:1,country:1,nationality:1,otherNationality:1,defaultLanguage:1,taxCountry:1,placeOfBirth:1,countryOfBirth:1,salutation:1,educationLevel:1,occupation:1,taxNumber:1},G=Object.fromEntries(Object.entries(v).filter(([l])=>l in $)),se=Object.fromEntries(Object.entries(E).filter(([l])=>l in $)),[V,be]=i.useState({workflowKey:p,firstName:"",lastName:"",title:"",email:T,dateOfBirth:"",phonenumber:"",externalRefId:g,mobileCountryCode:"",street:"",streetNumber:"",zip:"",city:"",country:"",nationality:"",otherNationality:[],defaultLanguage:"EN",taxCountry:"",placeOfBirth:"",countryOfBirth:"",salutation:null,educationLevel:"",occupation:"",taxNumber:"",...G,...se}),ce=Object.fromEntries(Object.entries(v).filter(([l])=>!(l in G)&&l!=="externalRefId"&&l!=="workflowKey")),[de,he]=i.useState({...ce}),[I,W]=i.useState(0),[z,_]=i.useState({}),[me,N]=i.useState(null),[re,ue]=i.useState(!1),ne=(l,h)=>be(P=>({...P,[l]:h})),ve=(l,h)=>he(P=>({...P,[l]:h})),Pe=l=>!l.conditionalOn||de[l.conditionalOn]==="true",ke=S&&I<S.length-1?I+1:-1,ze=S&&I>0?I-1:-1,et=l=>{var P;const h={};for(const b of l.fields)if(b.isCustom){if(b.customType==="paragraph"||b.customType==="html"||b.customType==="br"||b.customType==="link")continue;if(b.required&&b.paramName){const w=de[b.paramName],j=b.displayText||b.label||b.paramName;b.customType==="checkbox"||b.customType==="link_checkbox"?w!=="true"&&(h[b.paramName]=`${j} is required.`):(!w||w.trim()==="")&&(h[b.paramName]=`${j} is required.`)}}else if(b.name){const w=b.name;if(M.includes(w)&&rt(V[w])){const j=b.displayText||((P=Ge[w])==null?void 0:P.label)||w;h[w]=`${j} is required.`}}return h},Je=async()=>{if(!S)return;const l=S[I];if(l.conditionalOn&&!Pe(l)){_({}),ke>=0?W(ke):await $e();return}const h=et(l);if(Object.keys(h).length>0){_(h);return}_({}),ke>=0?W(ke):await $e()},$e=async()=>{if(S){let l={};for(const h of S)Pe(h)&&(l={...l,...et(h)});if(Object.keys(l).length>0){_(l);return}}ue(!0),N(null);try{if(!V.externalRefId||V.externalRefId.trim()===""){N("External Reference ID is required. Please pass it via config.applicantForm.externalRefId.");return}const l={workflowKey:V.workflowKey,externalRefId:V.externalRefId.trim()};if(S){for(const w of S)if(Pe(w)){for(const j of w.fields)if(!j.isCustom&&j.name){const le=j.name,ae=V[le];rt(ae)||(l[le]=ae)}}for(const w of dt)if(l[w]===void 0){const j=V[w];rt(j)||(l[w]=j)}}else Y.forEach(w=>{if(w==="externalRefId")return;const j=V[w];rt(j)||(l[w]=j)});const h=[];if(S){for(const w of S)if(Pe(w))for(const j of w.fields){if(!j.isCustom||!j.paramName||j.customType==="paragraph"||j.customType==="html"||j.customType==="br"||j.customType==="link")continue;const le=de[j.paramName]??"";let ae;if(j.customType==="checkbox"||j.customType==="link_checkbox")ae=le==="true"?"yes":"no";else if(ae=le,!ae&&!j.required)continue;h.push({paramName:j.paramName,value:ae})}}for(const[w,j]of Object.entries(G))l[w]===void 0&&!rt(j)&&(l[w]=j);const P=new Set(h.map(w=>w.paramName));for(const[w,j]of Object.entries(ce))!P.has(w)&&j&&h.push({paramName:w,value:j});h.length>0&&(l.applicantAdditionalDatas=h);const b=await d(l);s(b.applicantId)}catch(l){console.error("Error creating applicant:",l),N(l.message||"Failed to create applicant")}finally{ue(!1)}},tt=async l=>{var h;l.preventDefault();for(const P of M)if(rt(V[P])){const b=((h=Ge[P])==null?void 0:h.label)||P;N(`${b} is required.`);return}await $e()},Ke=(l,h,P,b,w)=>{var wt;const j=Ge[l];if(!j)return null;const le=M.includes(l),ae=z[l],xe=P||j.label,Ie=l in se,ie=h??l,Le={required:le},Be=w?w!=="placeholder":k,qe=Be?xe:void 0,qr=Be?"...":xe;switch(j.type){case"select":if(l==="country"||l==="nationality"||l==="taxCountry"||l==="countryOfBirth"||l==="mobileCountryCode"){const Ce=Q(l,b);return e.jsx(Oe,{...Le,label:qe,value:V[l]||"",onChange:Ze=>ne(l,Ze),options:[{value:"",label:`Select ${qr.toLowerCase()}`},...Ce],disabled:R,readOnly:Ie,error:ae},ie)}if(l==="salutation")return e.jsx(Oe,{...Le,label:qe,value:((wt=V[l])==null?void 0:wt.toString())||"",onChange:Ce=>ne(l,Ce?Number(Ce):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:ae},ie);if(l==="defaultLanguage"){const Ce=c!=null&&c.allowedLanguages&&c.allowedLanguages.length>0?ft.filter(Ze=>c.allowedLanguages.includes(Ze.value)):ft;return e.jsx(Oe,{...Le,label:qe,value:V[l]||"",onChange:Ze=>ne(l,Ze),options:[{value:"",label:Be?"Select language...":xe},...Ce],readOnly:Ie,error:ae},ie)}return null;case"multiselect":if(l==="otherNationality"){const Ce=Q(l,b);return e.jsx(Tr,{...Le,label:qe,value:V[l]||[],onChange:Ze=>ne(l,Ze),options:Ce,placeholder:Be?"Select other nationalities...":xe,disabled:R,readOnly:Ie},ie)}return null;case"date":return e.jsx(ye,{...Le,type:"date",label:qe,placeholder:Be?void 0:xe,value:V[l]||"",onChange:Ce=>ne(l,Ce.target.value),readOnly:Ie,error:ae},ie);case"email":return e.jsx(ye,{...Le,type:"email",label:qe,placeholder:Be?void 0:xe,value:V[l]||"",onChange:Ce=>ne(l,Ce.target.value),readOnly:Ie,error:ae},ie);case"tel":return e.jsx(ye,{...Le,type:"tel",label:qe,placeholder:Be?void 0:xe,value:V[l]||"",onChange:Ce=>ne(l,Ce.target.value),readOnly:Ie,error:ae},ie);default:return e.jsx(ye,{...Le,type:"text",label:qe,placeholder:Be?void 0:xe,value:V[l]||"",onChange:Ce=>ne(l,Ce.target.value),readOnly:Ie,error:ae},ie)}},x=(l,h)=>{const P=l.labelMode?l.labelMode!=="placeholder":k;if(l.customType==="paragraph"){const j=l.displayText||l.label||"";return e.jsx("p",{className:"metakyc-paragraph",style:{fontSize:"14px",lineHeight:"1.7",margin:0,color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:j}},`custom-${h}`)}if(l.customType==="html")return e.jsx("div",{dangerouslySetInnerHTML:{__html:l.label||""}},`custom-${h}`);if(l.customType==="br")return e.jsx("div",{style:{height:"12px"}},`custom-${h}`);if(l.customType==="link"){const j=l.displayText||l.label||l.linkText||l.linkUrl||"";return e.jsx("div",{className:"metakyc-link-field",children:e.jsxs("a",{href:l.linkUrl||"#",target:"_blank",rel:"noopener noreferrer",style:{display:"inline-flex",alignItems:"center",gap:"4px",color:"var(--metakyc-primary, #2563eb)",fontSize:"14px",textDecoration:"underline",cursor:"pointer"},children:[j,e.jsx("span",{style:{fontSize:"10px",opacity:.7},children:"↗"})]})},`custom-${h}`)}if(!l.paramName)return null;const b=z[l.paramName],w=l.displayText||l.label||l.paramName;if(l.customType==="checkbox")return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx(Fe,{checked:de[l.paramName]==="true",onChange:j=>ve(l.paramName,j?"true":"false")}),e.jsxs("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:[w,l.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),b&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:b})]},`custom-${h}`);if(l.customType==="link_checkbox")return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx(Fe,{checked:de[l.paramName]==="true",onChange:j=>ve(l.paramName,j?"true":"false")}),e.jsxs("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:[w," ",l.linkUrl&&e.jsx("a",{href:l.linkUrl,target:"_blank",rel:"noopener noreferrer",className:"underline",style:{color:"var(--metakyc-primary, #2563eb)"},onClick:j=>j.stopPropagation(),children:l.linkText||l.linkUrl}),l.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),b&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:b})]},`custom-${h}`);if(l.customType==="group_checkbox"){const j=(de[l.paramName]||"").split(",").filter(Boolean);return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[P&&e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[w,l.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]}),e.jsx("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:(l.options||[]).map(le=>{const ae=l.singleSelect?de[l.paramName]===le.value:j.includes(le.value);return e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx(Fe,{checked:ae,onChange:xe=>{if(l.singleSelect)ve(l.paramName,xe?le.value:"");else{const Ie=xe?[...j,le.value]:j.filter(ie=>ie!==le.value);ve(l.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)})}),b&&e.jsx("p",{className:"text-red-500 text-xs",children:b})]},`custom-${h}`)}return l.customType==="radio_group"?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[P&&e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:[w,l.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]}),e.jsx("div",{className:"metakyc-options-group",style:{display:"flex",flexDirection:"column",gap:"8px"},children:(l.options||[]).map(j=>e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx("input",{type:"radio",checked:de[l.paramName]===j.value,onChange:()=>ve(l.paramName,j.value),name:`radio-group-${l.paramName}-${h}`,className:"metakyc-option-input",style:Ds}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4"},children:j.label})]},j.value))}),b&&e.jsx("p",{className:"text-red-500 text-xs",children:b})]},`custom-${h}`):e.jsx(ye,{type:"text",label:P?`${w}${l.required?" *":""}`:void 0,placeholder:P?void 0:w,value:de[l.paramName]||"",onChange:j=>ve(l.paramName,j.target.value),required:l.required,error:b},`custom-${h}`)},D=(l,h)=>{const P=Pe(l);return e.jsxs("div",{className:"space-y-4",children:[l.conditionalOn&&e.jsx(At,{helpText:l.conditionalHelpText,children:e.jsxs("label",{className:"metakyc-option-label",style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer",margin:0,padding:0},children:[e.jsx(Fe,{checked:P,onChange:b=>ve(l.conditionalOn,b?"true":"false")}),e.jsx("span",{className:"metakyc-option-text",style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)",lineHeight:"1.4",fontWeight:500},children:l.conditionalOn})]})}),P&&e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:l.fields.map((b,w)=>{const j=Math.min(4,Math.max(1,Number(b.colSpan)||4)),le=b.isCustom?`custom-${w}-${b.paramName}`:`builtin-${b.name}-${w}`;return e.jsx("div",{style:{gridColumn:`span ${j} / span ${j}`},children:e.jsx(At,{helpText:b.helpText,children:b.isCustom?x(b,w):Ke(b.name,le,b.displayText,b.countriesType,b.labelMode)})},le)})})]})};if(!c||R)return e.jsx("div",{className:"metakyc-sdk",children:e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)",fontSize:"0.875rem"},children:"Loading form…"})]})})});if(S){const l=S[I]??S[0],h=ze===-1,P=ke===-1,b=S.length,w=Pe(l),j=Object.values(z);return e.jsx("div",{className:"metakyc-sdk",children:e.jsxs(ee,{children:[e.jsx(fe,{children:e.jsx(at,{title:(c==null?void 0:c.title)||"Create Applicant"})}),e.jsxs(te,{children:[(l.title||l.subtitle||l.description)&&e.jsxs("div",{className:"mb-4",children:[l.title&&e.jsx("h3",{className:"font-semibold text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:l.title}),l.subtitle&&e.jsx("p",{className:"text-sm mt-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:l.subtitle}),l.description&&l.description!==l.subtitle&&e.jsx("p",{className:"text-xs mt-1",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:l.description})]}),(me||j.length>0)&&e.jsxs("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-lg",children:[me&&e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",me]}),j.map((le,ae)=>e.jsx("p",{className:"text-red-600 text-sm",children:le},ae))]}),b>1&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem",marginBottom:"1rem"},children:[S.map((le,ae)=>e.jsx("div",{style:{height:"0.375rem",borderRadius:"9999px",transition:"all 150ms",...ae===I?{flex:"1 1 0%",backgroundColor:"var(--metakyc-primary, #2563eb)"}:ae<I?{width:"2rem",backgroundColor:"var(--metakyc-primary-light, #93c5fd)",opacity:.7}:{width:"2rem",backgroundColor:"#e5e7eb"}}},ae)),e.jsxs("span",{style:{fontSize:"0.75rem",color:"var(--metakyc-text-muted, #9ca3af)",flexShrink:0},children:[I+1," / ",b]})]}),D(l)]}),e.jsxs(ge,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{children:[!h&&e.jsx(J,{type:"button",variant:"outline",onClick:()=>{W(ze),_({})},disabled:re||y,children:"Previous"}),h&&n&&e.jsx(J,{type:"button",variant:"outline",onClick:n,disabled:re||y,children:"Cancel"})]}),e.jsx(J,{type:"button",isLoading:re||y,onClick:P?$e:Je,children:P?l.conditionalOn&&!w?"Skip & Submit":"Submit":l.conditionalOn&&!w?"Skip":"Next"})]})]})})}return e.jsx("div",{className:"metakyc-sdk",children:e.jsx("form",{onSubmit:tt,children:e.jsxs(ee,{children:[e.jsx(fe,{children:e.jsx(at,{title:(c==null?void 0:c.title)||"Create Applicant"})}),e.jsxs(te,{children:[me&&e.jsx("div",{className:"mb-6 p-4 bg-red-50 border border-red-200 rounded-lg",children:e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",me]})}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:Y.map(l=>e.jsx("div",{style:{gridColumn:"span 4 / span 4"},children:Ke(l)},l))})]}),e.jsxs(ge,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[n&&e.jsx(J,{type:"button",variant:"outline",onClick:n,disabled:re||y,children:"Cancel"}),e.jsx(J,{type:"submit",isLoading:re||y,children:"Create Applicant"})]})]})})})},Tt=["companyName","email"];function ht(t){return t==null||t===""||Array.isArray(t)&&t.length===0}const Os=({workflowKey:t,externalRefId:r,onSuccess:s,onCancel:n})=>{var Ke,x,D,K,H,Z;const{config:a,baseInformationService:o,currentTheme:c}=Ne(),{createCompanyApplicant:d,isLoading:y}=kt(),p=t||((Ke=a.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 g=r||((x=a.applicantForm)==null?void 0:x.externalRefId)||"",T=((D=a.applicantForm)==null?void 0:D.email)||"",v=((K=a.applicantForm)==null?void 0:K.initialValues)||{},A=(((H=a.applicantForm)==null?void 0:H.fieldLabelMode)||(c==null?void 0:c.fieldLabelMode)||"label")!=="placeholder",k=i.useMemo(()=>c!=null&&c.companyFormPages&&c.companyFormPages.length>0?c.companyFormPages:null,[c==null?void 0:c.companyFormPages]),S=i.useMemo(()=>{const m=new Set(Tt),C=c==null?void 0:c.companyFormRequiredFields;if(C)for(const F of C)m.add(F);if(k)for(const F of k)for(const u of F.fields)!u.isCustom&&u.name&&u.required&&m.add(u.name);return Array.from(m)},[c==null?void 0:c.companyFormRequiredFields,k]),M=i.useMemo(()=>{var m;if(k){const C=k.flatMap(u=>u.fields).filter(u=>!u.isCustom&&u.name).map(u=>u.name),F=new Set(C);for(const u of Tt)F.add(u);return Array.from(F)}return(m=a.applicantForm)!=null&&m.visibleFields?a.applicantForm.visibleFields:c!=null&&c.companyFormVisibleFields&&c.companyFormVisibleFields.length>0?c.companyFormVisibleFields:Wt},[(Z=a.applicantForm)==null?void 0:Z.visibleFields,c==null?void 0:c.companyFormVisibleFields,k]),Y=new Set(["countryResidence","addressCountry"]),L=i.useMemo(()=>{var C,F;const m=new Set;if(k)for(const u of k)for(const l of u.fields)!l.isCustom&&l.name&&Y.has(l.name)&&m.add(l.countriesType??((C=Xe[l.name])==null?void 0:C.countriesType));else for(const u of M)Y.has(u)&&m.add((F=Xe[u])==null?void 0:F.countriesType);return m.size===0&&m.add(void 0),Array.from(m)},[M,k]),[B,U]=i.useState({}),[X,R]=i.useState(!0),f=i.useRef(new Set),O=i.useRef(new Set);i.useEffect(()=>{if(!c)return;const m=L.filter(u=>{const l=u!=null?String(u):"all";return!O.current.has(l)&&!f.current.has(l)});if(m.length===0){L.every(l=>O.current.has(l!=null?String(l):"all"))&&R(!1);return}R(!0);const C=m.map(u=>u!=null?String(u):"all");C.forEach(u=>f.current.add(u)),(async()=>{try{const u=await Promise.all(m.map(async l=>{const h=l!=null?String(l):"all",P=await o.getCountries("",a.locale||"en",l),b=new Set,w=P.map(j=>({value:j.abbreviation3||j.abbreviation,label:j.name})).filter(j=>!j.value||b.has(j.value)?!1:(b.add(j.value),!0));return O.current.add(h),f.current.delete(h),[h,w]}));U(l=>({...l,...Object.fromEntries(u)}))}catch(u){C.forEach(l=>f.current.delete(l)),console.error("Failed to load countries:",u)}finally{L.every(l=>O.current.has(l!=null?String(l):"all"))&&R(!1)}})()},[L,c]);const q=(m,C)=>{var l;const F=C??((l=Xe[m])==null?void 0:l.countriesType),u=F!=null?String(F):"all";return B[u]||[]},Q={companyName:1,registrationNumber:1,email:1,phone:1,countryResidence:1,legalAddress:1,incorporatedOn:1,controlScheme:1,taxId:1,registrationLocation:1,website:1,postalAddress:1,street:1,streetNumber:1,city:1,state:1,postalCode:1,addressCountry:1,lei:1},$=Object.fromEntries(Object.entries(v).filter(([m])=>m in Q)),[G,se]=i.useState({workflowKey:p,companyName:"",email:T,phone:"",registrationNumber:"",countryResidence:"",legalAddress:"",incorporatedOn:"",controlScheme:"",taxId:"",registrationLocation:"",website:"",postalAddress:"",street:"",streetNumber:"",city:"",state:"",postalCode:"",addressCountry:"",lei:"",externalRefId:g,...$}),[V,be]=i.useState({}),[ce,de]=i.useState(0),[he,I]=i.useState({}),[W,z]=i.useState(null),[_,me]=i.useState(!1),N=(m,C)=>se(F=>({...F,[m]:C})),re=(m,C)=>be(F=>({...F,[m]:C})),ue=m=>!m.conditionalOn||V[m.conditionalOn]==="true",ne=k&&ce<k.length-1?ce+1:-1,ve=k&&ce>0?ce-1:-1,Pe=m=>{var F;const C={};for(const u of m.fields)if(u.isCustom){if(u.customType==="paragraph"||u.customType==="html"||u.customType==="br"||u.customType==="link")continue;if(u.required&&u.paramName){const l=V[u.paramName],h=u.displayText||u.label||u.paramName;u.customType==="checkbox"||u.customType==="link_checkbox"?l!=="true"&&(C[u.paramName]=`${h} is required.`):(!l||l.trim()==="")&&(C[u.paramName]=`${h} is required.`)}}else if(u.name){const l=u.name;if(S.includes(l)&&ht(G[l])){const h=u.displayText||((F=Xe[l])==null?void 0:F.label)||l;C[l]=`${h} is required.`}}return C},ke=async()=>{if(!k)return;const m=k[ce];if(m.conditionalOn&&!ue(m)){I({}),ne>=0?de(ne):await ze();return}const C=Pe(m);if(Object.keys(C).length>0){I(C);return}I({}),ne>=0?de(ne):await ze()},ze=async()=>{var m;if(k){let C={};for(const F of k)ue(F)&&(C={...C,...Pe(F)});if(Object.keys(C).length>0){I(C);return}}me(!0),z(null);try{const C={workflowKey:G.workflowKey,externalRefId:((m=G.externalRefId)==null?void 0:m.trim())||void 0},F=k?k.filter(h=>ue(h)).flatMap(h=>h.fields).filter(h=>!h.isCustom&&h.name).map(h=>h.name):M;for(const h of F){const P=G[h];if(!ht(P))switch(h){case"companyName":C.companyName=P;break;case"email":C.companyEmail=P;break;case"phone":C.companyPhone=P;break;case"registrationNumber":C.companyRegistrationNumber=P;break;case"countryResidence":C.companyCountry=P;break;case"city":C.companyCity=P;break;case"street":C.companyStreet=P;break;case"postalCode":C.companyZip=P;break;default:C[h]=P;break}}const u=[];if(k){for(const h of k)if(ue(h))for(const P of h.fields){if(!P.isCustom||!P.paramName||P.customType==="paragraph"||P.customType==="html"||P.customType==="br"||P.customType==="link")continue;const b=V[P.paramName]??"";let w;if(P.customType==="checkbox"||P.customType==="link_checkbox")w=b==="true"?"yes":"no";else if(w=b,!w&&!P.required)continue;u.push({paramName:P.paramName,value:w})}}u.length>0&&(C.applicantAdditionalDatas=u);const l=await d(C);s(l.applicantId)}catch(C){console.error("Error creating company applicant:",C),z(C.message||"Failed to create company applicant")}finally{me(!1)}},et=async m=>{var C;m.preventDefault();for(const F of S)if(ht(G[F])){const u=((C=Xe[F])==null?void 0:C.label)||F;z(`${u} is required.`);return}await ze()},Je=(m,C,F,u,l)=>{const h=Xe[m];if(!h)return null;const P=S.includes(m),b=he[m],w=F||h.label,j=m in $,le=C??m,ae=l?l!=="placeholder":A,xe=ae?w:void 0,Ie=ae?"...":w;switch(h.type){case"select":if(m==="countryResidence"||m==="addressCountry"){const ie=q(m,u);return e.jsx(Oe,{required:P,label:xe,value:G[m]||"",onChange:Le=>N(m,Le),options:[{value:"",label:`Select ${Ie.toLowerCase()}`},...ie],disabled:X,readOnly:j,error:b},le)}return null;case"date":return e.jsx(ye,{required:P,type:"date",label:xe,placeholder:ae?void 0:w,value:G[m]||"",onChange:ie=>N(m,ie.target.value),readOnly:j,error:b},le);case"email":return e.jsx(ye,{required:P,type:"email",label:xe,placeholder:ae?void 0:w,value:G[m]||"",onChange:ie=>N(m,ie.target.value),readOnly:j,error:b},le);case"tel":return e.jsx(ye,{required:P,type:"tel",label:xe,placeholder:ae?void 0:w,value:G[m]||"",onChange:ie=>N(m,ie.target.value),readOnly:j,error:b},le);default:return e.jsx(ye,{required:P,type:"text",label:xe,placeholder:ae?void 0:w,value:G[m]||"",onChange:ie=>N(m,ie.target.value),readOnly:j,error:b},le)}},$e=(m,C)=>{if(m.customType==="paragraph")return e.jsx("p",{style:{fontSize:"14px",lineHeight:"1.7",margin:0,color:"var(--metakyc-text-secondary, #6b7280)"},dangerouslySetInnerHTML:{__html:m.displayText||m.label||""}},`custom-${C}`);if(m.customType==="html")return e.jsx("div",{dangerouslySetInnerHTML:{__html:m.label||""}},`custom-${C}`);if(m.customType==="br")return e.jsx("div",{style:{height:"12px"}},`custom-${C}`);if(m.customType==="link")return e.jsx("div",{children:e.jsx("a",{href:m.linkUrl||"#",target:"_blank",rel:"noopener noreferrer",style:{color:"var(--metakyc-primary, #2563eb)",fontSize:"14px",textDecoration:"underline"},children:m.displayText||m.label||m.linkText||m.linkUrl||""})},`custom-${C}`);if(!m.paramName)return null;const F=he[m.paramName],u=m.displayText||m.label||m.paramName,l=m.labelMode?m.labelMode!=="placeholder":A;return m.customType==="checkbox"?e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer"},children:[e.jsx(Fe,{checked:V[m.paramName]==="true",onChange:h=>re(m.paramName,h?"true":"false")}),e.jsxs("span",{style:{fontSize:"14px",color:"var(--metakyc-text-primary, #111827)"},children:[u,m.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})]}),F&&e.jsx("p",{className:"text-red-500 text-xs mt-0.5",children:F})]},`custom-${C}`):e.jsx(ye,{type:"text",label:l?`${u}${m.required?" *":""}`:void 0,placeholder:l?void 0:u,value:V[m.paramName]||"",onChange:h=>re(m.paramName,h.target.value),required:m.required,error:F},`custom-${C}`)},tt=m=>{const C=ue(m);return e.jsxs("div",{className:"space-y-4",children:[m.conditionalOn&&e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"10px",cursor:"pointer"},children:[e.jsx(Fe,{checked:C,onChange:F=>re(m.conditionalOn,F?"true":"false")}),e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:m.conditionalOn})]}),C&&e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:m.fields.map((F,u)=>{const l=Math.min(4,Math.max(1,Number(F.colSpan)||4)),h=F.isCustom?`custom-${u}-${F.paramName}`:`builtin-${F.name}-${u}`;return e.jsx("div",{style:{gridColumn:`span ${l} / span ${l}`},children:F.isCustom?$e(F,u):Je(F.name,h,F.displayText,F.countriesType,F.labelMode)},h)})})]})};if(!c||X)return e.jsx("div",{className:"metakyc-sdk",children:e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)",fontSize:"0.875rem"},children:"Loading form…"})]})})});if(k){const m=k[ce]??k[0],C=ve===-1,F=ne===-1,u=k.length,l=ue(m),h=Object.values(he);return e.jsx("div",{className:"metakyc-sdk",children:e.jsxs(ee,{children:[e.jsx(fe,{children:e.jsx(at,{title:(c==null?void 0:c.title)||"Company Registration"})}),e.jsxs(te,{children:[(m.title||m.subtitle)&&e.jsxs("div",{className:"mb-4",children:[m.title&&e.jsx("h3",{className:"font-semibold text-base",style:{color:"var(--metakyc-text-primary, #111827)"},children:m.title}),m.subtitle&&e.jsx("p",{className:"text-sm mt-0.5",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:m.subtitle})]}),(W||h.length>0)&&e.jsxs("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-lg",children:[W&&e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",W]}),h.map((P,b)=>e.jsx("p",{className:"text-red-600 text-sm",children:P},b))]}),u>1&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem",marginBottom:"1rem"},children:[k.map((P,b)=>e.jsx("div",{style:{height:"0.375rem",borderRadius:"9999px",transition:"all 150ms",...b===ce?{flex:"1 1 0%",backgroundColor:"var(--metakyc-primary, #2563eb)"}:b<ce?{width:"2rem",backgroundColor:"var(--metakyc-primary-light, #93c5fd)",opacity:.7}:{width:"2rem",backgroundColor:"#e5e7eb"}}},b)),e.jsxs("span",{style:{fontSize:"0.75rem",color:"var(--metakyc-text-muted, #9ca3af)",flexShrink:0},children:[ce+1," / ",u]})]}),tt(m)]}),e.jsxs(ge,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{children:[!C&&e.jsx(J,{type:"button",variant:"outline",onClick:()=>{de(ve),I({})},disabled:_||y,children:"Previous"}),C&&n&&e.jsx(J,{type:"button",variant:"outline",onClick:n,disabled:_||y,children:"Cancel"})]}),e.jsx(J,{type:"button",isLoading:_||y,onClick:F?ze:ke,children:F?m.conditionalOn&&!l?"Skip & Submit":"Submit":m.conditionalOn&&!l?"Skip":"Next"})]})]})})}return e.jsx("div",{className:"metakyc-sdk",children:e.jsx("form",{onSubmit:et,children:e.jsxs(ee,{children:[e.jsx(fe,{children:e.jsx(at,{title:(c==null?void 0:c.title)||"Company Registration"})}),e.jsxs(te,{children:[W&&e.jsx("div",{className:"mb-6 p-4 bg-red-50 border border-red-200 rounded-lg",children:e.jsxs("p",{className:"text-red-600 text-sm",children:[e.jsx("strong",{children:"Error:"})," ",W]})}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:"1rem"},children:M.map(m=>e.jsx("div",{style:{gridColumn:"span 4 / span 4"},children:Je(m)},m))})]}),e.jsxs(ge,{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[n&&e.jsx(J,{type:"button",variant:"outline",onClick:n,disabled:_||y,children:"Cancel"}),e.jsx(J,{type:"submit",isLoading:_||y,children:"Register Company"})]})]})})})},zs=({applicantId:t,onComplete:r,onError:s,theme:n="light",className:a})=>{const{progress:o,currentStep:c,steps:d,workflowKey:y,nextWorkflowKey:p,hasWorkflowChanged:g,isLoading:T,error:v,moveBack:E,refreshProgress:A}=Cr(t),[k,S]=i.useState(!1),M=i.useRef(null);if(i.useEffect(()=>{v&&s&&s(v)},[v,s]),i.useEffect(()=>{o!=null&&o.workflowResult&&r&&r(o.workflowResult)},[o==null?void 0:o.workflowResult,r]),i.useEffect(()=>{n==="dark"?document.documentElement.classList.add("dark"):document.documentElement.classList.remove("dark")},[n]),i.useEffect(()=>{g&&S(!1)},[g]),T||!o)return e.jsx("div",{className:`metakyc-sdk ${a||""}`,children:e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Loading workflow..."})]})})});if(v)return e.jsx("div",{className:`metakyc-sdk ${a||""}`,children:e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-lg mb-4",style:{color:"var(--metakyc-danger, #ef4444)"},children:"An error occurred"}),e.jsx("p",{style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:v.message})]})})})});if(g&&!k)return e.jsx("div",{className:`metakyc-sdk ${a||""}`,children:e.jsx(ee,{children:e.jsx(te,{children:e.jsxs("div",{className:"text-center py-8",children:[e.jsx("div",{className:"mb-6",children:e.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-full mb-4",style:{backgroundColor:"var(--metakyc-primary-light, #dbeafe)"},children:e.jsx("svg",{className:"w-8 h-8",style:{color:"var(--metakyc-primary, #2563eb)"},fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})})}),e.jsx("h3",{className:"text-xl font-semibold mb-2",style:{color:"var(--metakyc-text-primary, #111827)"},children:"Workflow Transition"}),e.jsx("p",{className:"mb-6",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:"Your application workflow has been updated based on your progress."}),e.jsxs("div",{className:"rounded-lg p-4 mb-6 max-w-md mx-auto",style:{backgroundColor:"var(--metakyc-surface, #f9fafb)"},children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"mb-1",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"Previous Workflow"}),e.jsx("p",{className:"font-medium",style:{color:"var(--metakyc-text-primary, #111827)"},children:y})]}),e.jsx("svg",{className:"w-6 h-6 mx-4",style:{color:"var(--metakyc-text-muted, #9ca3af)"},fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 7l5 5m0 0l-5 5m5-5H6"})}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"mb-1",style:{color:"var(--metakyc-text-muted, #9ca3af)"},children:"New Workflow"}),e.jsx("p",{className:"font-medium",style:{color:"var(--metakyc-primary, #2563eb)"},children:p})]})]}),o.nextWorkflowName&&e.jsx("p",{className:"text-center mt-2 text-xs",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:o.nextWorkflowName})]}),e.jsx("button",{onClick:()=>S(!0),className:"px-6 py-3 font-medium rounded-lg transition-opacity hover:opacity-90",style:{backgroundColor:"var(--metakyc-primary, #2563eb)",color:"#ffffff"},children:"Continue with New Workflow"})]})})})});if(o.status===Te.Finished||o.status===Te.OnHold)return e.jsx("div",{className:`metakyc-sdk ${a||""}`,children:e.jsx(gt,{kycStatus:o.kycStatus,reviewStatus:o.reviewStatus,workflowResult:o.workflowResult,customMessage:o.customMessage,onContinue:r&&o.workflowResult?()=>r(o.workflowResult):void 0,onContactSupport:()=>{typeof window<"u"&&(window.location.href="mailto:support@example.com")}})});if(!c)return e.jsx("div",{className:`metakyc-sdk ${a||""}`,children:e.jsx(ee,{children:e.jsxs(te,{children:[e.jsx(Ee,{className:"my-8"}),e.jsx("p",{className:"text-center mt-4",style:{color:"var(--metakyc-text-secondary, #6b7280)"},children:o.status===Te.IdentityPending?"Loading identity verification...":"Loading current step..."})]})})});const Y=U=>{switch(U){case oe.Overview:return"Overview";case oe.Questionaries:return"Questionnaire";case oe.UploadDocument:return"Documents";case oe.IdentitySdk:return"Identity";case oe.RiskScoring:return"Risk Assessment";case oe.InvestorCategorization:return"Investor Categorization";case oe.AppropriatenessTest:return"Appropriateness Test";case oe.AdditionalData:return"Additional Data";case oe.ManualReview:return"Review";default:return""}},L=()=>{const U=d.filter(q=>q.visibility!==!1),X=U.findIndex(q=>q.order===c.order),R=X>=0?X+1:1,f=U.length,O=f>1?X/(f-1)*100:100;return e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",marginBottom:"16px"},children:[e.jsx(at,{}),e.jsxs(jt,{variant:o.status===1?"info":"success",children:["Step ",R," of ",f]})]}),e.jsx("div",{style:{marginBottom:"16px"},children:e.jsx("div",{style:{height:"4px",borderRadius:"999px",backgroundColor:"var(--metakyc-border, #e5e7eb)",overflow:"hidden"},children:e.jsx("div",{style:{height:"100%",borderRadius:"999px",backgroundColor:"var(--metakyc-primary, #2563eb)",width:`${O}%`,transition:"width 0.4s ease"}})})}),e.jsx($s,{ref:M,visibleSteps:U,currentVisibleStepIndex:X,getStepFallbackName:Y})]})},B=()=>{const U={applicantId:t,onComplete:async()=>{await A()},onBack:c.order>0?E:void 0};switch(c.action){case oe.Questionaries:return e.jsx(zr,{...U});case oe.UploadDocument:return e.jsx($r,{...U});case oe.Overview:return e.jsx(Br,{...U});case oe.IdentitySdk:return e.jsx(Ur,{...U});case oe.RiskScoring:return e.jsx(_r,{...U});case oe.AdditionalData:case oe.InvestorCategorization:return e.jsx(Hr,{...U});case oe.AppropriatenessTest:return e.jsx(Wr,{...U});case oe.ManualReview:return e.jsx(gt,{kycStatus:o.kycStatus,reviewStatus:o.reviewStatus,workflowResult:o.workflowResult,customMessage:o.customMessage});default:return e.jsx(ee,{children:e.jsxs(te,{className:"py-12 text-center",children:[e.jsx("div",{className:"mb-4",children:e.jsx(Ee,{})}),e.jsxs("p",{className:"text-gray-600 dark:text-gray-400 mb-2",children:["Processing step: ",c.title||c.name]}),e.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:["Action type: ",oe[c.action]]})]})})}};return e.jsxs("div",{className:`metakyc-sdk ${a||""}`,children:[L(),B()]})},$s=i.forwardRef(({visibleSteps:t,currentVisibleStepIndex:r,getStepFallbackName:s},n)=>{const a=i.useRef(null),o=i.useRef(null);return i.useImperativeHandle(n,()=>a.current),i.useEffect(()=>{if(o.current&&a.current){const c=a.current,d=o.current,y=d.offsetLeft-c.offsetWidth/2+d.offsetWidth/2;c.scrollTo({left:Math.max(0,y),behavior:"smooth"})}},[r]),e.jsx("div",{ref:a,className:"metakyc-stepper-scroll",style:{display:"flex",alignItems:"center",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,g=y||p,T=c.displayName||c.name||s(c.action)||`Step ${d+1}`;return e.jsxs(i.Fragment,{children:[e.jsxs("div",{ref:p?o:void 0,style:{display:"flex",alignItems:"center",flexShrink:0},children:[e.jsx("div",{style:{width:"28px",height:"28px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"12px",fontWeight:600,flexShrink:0,transition:"all 0.2s ease",...g?{backgroundColor:"var(--metakyc-primary, #2563eb)",color:"#ffffff",border:"none"}:{backgroundColor:"transparent",color:"var(--metakyc-text-muted, #9ca3af)",border:"2px solid var(--metakyc-border, #e5e7eb)"}},children:y?e.jsx("svg",{width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:2.5,viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}):d+1}),e.jsx("span",{style:{marginLeft:"6px",fontSize:"13px",whiteSpace:"nowrap",fontWeight:p?600:400,color:p?"var(--metakyc-text-primary, #111827)":y?"var(--metakyc-primary, #2563eb)":"var(--metakyc-text-muted, #9ca3af)",transition:"color 0.2s ease"},children:T})]}),d<t.length-1&&e.jsx("div",{style:{flex:"1 1 0%",minWidth:"16px",height:"2px",margin:"0 8px",borderRadius:"999px",backgroundColor:y?"var(--metakyc-primary, #2563eb)":"var(--metakyc-border, #e5e7eb)",transition:"background-color 0.2s ease"}})]},c.order)})})});function Bs(t){return Ue.z.object({questionResults:Ue.z.any()}).passthrough()}function _s(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(s=>!s||s.length<=1,{message:"Only one file is allowed"})),t.maxEachFileSizeByte>0&&(r=r.refine(s=>!s||s.every(n=>n.size<=t.maxEachFileSizeByte),{message:`File size must not exceed ${Math.round(t.maxEachFileSizeByte/1024/1024)}MB`})),t.allowedTypes){const s=t.allowedTypes.split(",").map(n=>n.trim());r=r.refine(n=>n?n.every(a=>s.some(o=>o.endsWith("/*")?a.type.startsWith(o.slice(0,-2)):a.type===o)):!0,{message:"Invalid file type"})}return r}function Hs(t){const r={};return t.uploadDocumentFiles.forEach(s=>{const n=`file_${s.id}`;r[n]=_s(s)}),Ue.z.object(r)}function Ws(t){return Ue.z.any()}function Us(t){return Ue.z.string().min(1,"This question is required")}function Ks(t){const r={};return t.appropriatenessQuestions.forEach(s=>{const n=`question_${s.id}`;r[n]=Us()}),Ue.z.object(r)}const qs=Ue.z.any();exports.ALLOWED_LANGUAGES=ft;exports.ApplicantProgressOnHoldReason=Ft;exports.ApplicantProgressStatus=Te;exports.ApplicantService=Yt;exports.ApplicantStatus=Lt;exports.AppropriatenessQuestionType=$t;exports.AppropriatenessTestService=Jt;exports.AppropriatenessTestStep=Wr;exports.Badge=jt;exports.BaseInformationService=tr;exports.Button=J;exports.COMPANY_FIELD_METADATA=Xe;exports.Card=ee;exports.CardContent=te;exports.CardFooter=ge;exports.CardHeader=fe;exports.Checkbox=Fe;exports.CountriesType=We;exports.CreateApplicantForm=Ms;exports.CreateCompanyApplicantForm=Os;exports.CriteriaBuiltInType=_t;exports.DEFAULT_COMPANY_VISIBLE_FIELDS=Wt;exports.DEFAULT_VISIBLE_FIELDS=Ut;exports.DocumentReviewStatus=zt;exports.EndpointBuilder=qt;exports.ErrorHandler=st;exports.EventEmitter=dr;exports.FIELD_METADATA=Ge;exports.FileType=Ot;exports.FileUpload=Fr;exports.GenderType=lt;exports.Header=at;exports.HttpClient=Vt;exports.IdentityProviderManager=He;exports.IdentityService=er;exports.IdentityVerificationProvider=Ae;exports.IdentityVerificationStep=Ur;exports.Input=ye;exports.InvestorCategorizationService=rr;exports.InvestorCategorizationStep=Hr;exports.InvestorCategorizationType=je;exports.InvestorCategoryType=Ht;exports.KycProcessStatus=Dt;exports.KycStatus=Ye;exports.KycStatusDisplay=gt;exports.KycWorkflow=zs;exports.Logo=Kr;exports.MetaKYCContext=vt;exports.MetaKYCError=De;exports.MetaKYCProvider=ns;exports.MultiSelect=Tr;exports.OnfidoProvider=xr;exports.OverviewService=Zt;exports.OverviewStep=Br;exports.PhoneInput=Pr;exports.QuestionnaireService=Qt;exports.QuestionnaireStep=zr;exports.ReviewStatus=Qe;exports.RiskCriteriaType=Bt;exports.RiskLevel=Pt;exports.RiskScoringService=Xt;exports.RiskScoringStep=_r;exports.SDK_VERSION=gr;exports.SardinAIProvider=hr;exports.SearchableSelect=Oe;exports.Select=mt;exports.Spinner=Ee;exports.StepRouter=pr;exports.SumsubProvider=yr;exports.ThemeManager=fr;exports.ThemePreset=we;exports.ThemeService=cr;exports.UploadDocumentService=Gt;exports.UploadDocumentStep=$r;exports.UserType=Mt;exports.ValueDataType=Me;exports.WorkflowOrchestrator=mr;exports.WorkflowResultType=ot;exports.WorkflowState=ur;exports.WorkflowStepAction=oe;exports.appropriatenessTestSchema=qs;exports.clearAllStorage=cs;exports.clearApplicantId=jr;exports.clearWorkflowState=Sr;exports.cn=Se;exports.corporateTheme=sr;exports.defaultConfig=Kt;exports.defaultTheme=Re;exports.fileToBase64=br;exports.fintechTheme=nr;exports.formatFileSize=ut;exports.generateAppropriatenessSchema=Ks;exports.generateQuestionnaireSchema=Bs;exports.generateRiskScoringSchema=Ws;exports.generateUploadDocumentSchema=Hs;exports.getAcceptString=os;exports.getApplicantId=kr;exports.getThemePreset=nt;exports.getWorkflowState=ls;exports.healthcareTheme=ar;exports.isScriptLoaded=Jr;exports.loadScript=bt;exports.minimalTheme=or;exports.modernTheme=ir;exports.removeScript=Zr;exports.saveApplicantId=vr;exports.saveWorkflowState=wr;exports.themePresets=lr;exports.useApplicant=kt;exports.useAppropriatenessTest=ds;exports.useIdentityVerification=Er;exports.useKycWorkflow=Cr;exports.useMetaKYC=Ne;exports.useOverview=Ir;exports.useQuestionnaire=Nr;exports.useRiskScoring=Ar;exports.useUploadDocument=Rr;exports.validateFileSize=as;exports.validateFileType=is;
112
112
  //# sourceMappingURL=index.cjs.map