import{j as e}from"./vendor-mui-69397583.js";import{f as j,r as x,u as y}from"./vendor-react-ece1c85f.js";import{F as N}from"./FormContainer-91c2b0e4.js";import{h as p,d as S,B as k,J as F,K as A,M as C}from"./index-c62ac197.js";import{A as w}from"./Alert-7dfbd254.js";import{c as E,a as M,F as P,b as V}from"./index.esm-70ab539c.js";import{a as $}from"./UserService-047aef51.js";import"./vendor-redux-a1f00e6b.js";import"./vendor-pdf-b2a5d8b1.js";import"./vendor-devex-33a39e11.js";import"./vendor-i18n-2fcb1983.js";import"./vendor-msal-9caa1ed1.js";import"./vendor-charts-eccea5d1.js";const L=({tempToken:l,userId:c})=>{const m=j(),n=p(t=>{var a;return((a=t==null?void 0:t.theme)==null?void 0:a.themeColours)||{}}),[o,d]=x.useState(""),[g,h]=x.useState(!1),v=E().shape({validatethrough:M().required("Please select a verification method")}),f=async t=>{var a,i;h(!0);try{await $(c,t.validatethrough)?m(`/otp-verification?tempToken=${l}`,{state:{validatethrough:t.validatethrough}}):d("Failed to send otp. Please retry.")}catch(r){d(((i=(a=r==null?void 0:r.response)==null?void 0:a.data)==null?void 0:i.message)??"Failed to send otp. Please retry.")}finally{h(!1)}},b=[{label:"Authenticator App",value:"Authenticator",icon:e.jsx(F,{className:"text-3xl text-custom-500"})},{label:"Email",value:"Email",icon:e.jsx(A,{className:"text-3xl text-custom-500"})},{label:"SMS",value:"SMS",icon:e.jsx(C,{className:"text-3xl text-custom-500"})}];return e.jsxs("div",{className:"xl:min-w-[550px] px-4 space-y-6 mt-8 text-center",children:[e.jsxs("div",{className:"p-8 pt-4 pb-0",children:[e.jsx("h2",{className:"text-2xl font-black mb-2 pb-2",children:"2 Factor Authentication"}),e.jsx("p",{className:"text-base text-gray-700 leading-relaxed pb-2",children:"Choose a method to receive your one-time passcode."})]}),e.jsx(P,{initialValues:{validatethrough:""},validationSchema:v,onSubmit:f,children:({values:t,setFieldValue:a,errors:i,touched:r})=>e.jsx(V,{children:e.jsxs(N,{className:"space-y-6 px-4",children:[o&&e.jsx(w,{showIcon:!0,className:"mb-4",type:"danger",children:o}),e.jsx("div",{className:"flex flex-col sm:flex-row justify-center gap-6 sm:gap-8 items-center",children:b.map(s=>{const u=t.validatethrough===s.value;return e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("div",{onClick:()=>a("validatethrough",s.value),className:S("w-32 h-32 border rounded-lg flex items-center justify-center transition dark:text-gray-400 dark:bg-[#292f3c]",u?"border-custom-500 bg-custom-50":"border-gray-300 bg-white cursor-pointer"),children:s.icon}),e.jsxs("label",{className:"flex items-center gap-2 mt-3 text-sm text-gray-800 cursor-pointer dark:text-gray-400",children:[e.jsx("input",{type:"radio",name:"validatethrough",value:s.value,checked:u,onChange:()=>a("validatethrough",s.value),style:{accentColor:n[600]}}),s.label]})]},s.value)})}),i.validatethrough&&r.validatethrough&&e.jsx("div",{className:"text-red-500 text-sm",children:i.validatethrough}),t.validatethrough&&e.jsx("div",{className:"pt-4 sm:pb-4",children:e.jsx(k,{type:"submit",variant:"solid",loading:g,block:!0,children:"Next"})})]})})})]})},O=()=>{const{email:l,id:c}=p(o=>o.auth.user);y();const n=new URLSearchParams(document.location.search).get("tempToken")??"";return e.jsx(L,{tempToken:n,email:l??"",userId:c})},W=O;export{W as default};
