import{j as e}from"./vendor-mui-69397583.js";import{f as V,r as g,u as R}from"./vendor-react-ece1c85f.js";import{F as E}from"./FormContainer-91c2b0e4.js";import{h as S,u as v,I,B as k,O as P,Q as B}from"./index-c62ac197.js";import{A as L}from"./Alert-7dfbd254.js";import{c as K,F as $,b as M}from"./index.esm-70ab539c.js";import"./index-6b6d0f06.js";import"./index-c2088808.js";import"./Drawer-949c18c6.js";import"./Switcher-c8648037.js";import"./index-36228db5.js";import"./Upload-fb34ce03.js";import{a as Q}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";import"./useControllableState-d0909575.js";import"./useDidUpdate-25c4d4ed.js";const U=d=>{const{disableSubmit:b=!1,className:y,tempToken:c,email:m,authType:l,userId:f,phone:p}=d,h=V();S(t=>t.auth.user),v();const[j,x]=g.useState(""),[i,w]=g.useState(["","","","","",""]),{verifyTwoFactor:O,signIn:z}=v(),u=g.useRef(Array(6).fill(null)),F=K().shape({}),A=(t,a)=>{var r;if(!/^\d*$/.test(a))return;const o=[...i];o[t]=a,w(o),a&&t<5&&((r=u.current[t+1])==null||r.focus())},D=(t,a)=>{var o;a.key==="Backspace"&&!i[t]&&t>0&&((o=u.current[t-1])==null||o.focus())},N=async(t,a)=>{var r,n;a(!0);let o={userName:m,verificationCode:i.join(""),tempToken:c};try{const s=await O(o);(s==null?void 0:s.status)==="failed"&&x(s.message),a(!1)}catch(s){x((n=(r=s==null?void 0:s.response)==null?void 0:r.data)==null?void 0:n.message),a(!1),console.log(s)}},T=async()=>{var t,a;try{await Q(f,l)&&P.push(e.jsx(B,{title:"Success",type:"success",duration:2500,children:"Resend otp success"}),{placement:"top-center"})}catch(o){x((a=(t=o==null?void 0:o.response)==null?void 0:t.data)==null?void 0:a.message),setSubmitting(!1)}},C=t=>{var n;const a=t.clipboardData.getData("Text").trim();if(!/^\d{6}$/.test(a))return;const o=a.split(""),r=[...i];for(let s=0;s<6;s++)r[s]=o[s];w(r),(n=u.current[5])==null||n.focus(),t.preventDefault()};return e.jsxs(e.Fragment,{children:[e.jsx("img",{src:"/img/logo/logo-light-streamline.png",className:"absolute left-2 top-2 w-10 h-10 block xl:hidden",alt:"Logo"}),e.jsxs("div",{className:"xl:min-w-[550px] w-full px-4 sm:px-8 space-y-6 mt-6 xl:mt-4 text-center",children:[e.jsxs("div",{className:"px-2 pt-4 pb-0 xl:p-4",children:[e.jsx("h2",{className:"text-xl sm:text-2xl font-black mb-2 pb-2",children:"2 Factor Authentication"}),e.jsxs("p",{className:"text-sm sm:text-base text-gray-700 leading-relaxed pb-2 break-words",children:["Enter the One-Time Passcode sent to:",e.jsx("br",{}),e.jsx("span",{className:"text-custom-500 font-medium break-all",children:l==="Email"?m:l==="SMS"?p:"Authenticator App"})]})]}),e.jsxs("div",{className:"pt-2",children:[j&&e.jsx(L,{showIcon:!0,className:"mb-6",type:"danger",children:j}),e.jsx($,{initialValues:{otp:""},validationSchema:F,onSubmit:(t,{setSubmitting:a})=>{N(t,a)},children:({values:t,setSubmitting:a,isSubmitting:o})=>e.jsx(M,{onKeyDown:r=>{r.key==="Enter"&&(r.preventDefault(),N(t,a))},children:e.jsxs(E,{className:"space-y-6 sm:px-0",children:[e.jsx("div",{className:"flex justify-center gap-1 sm:gap-2 flex-wrap sm:flex-nowrap",children:i.map((r,n)=>e.jsx(I,{type:"text",maxLength:1,className:"!w-10 !h-10 sm:w-12 sm:h-14 text-base sm:text-xl text-center border border-gray-300 rounded-md focus:border-custom-500 focus:ring-2 focus:ring-custom-500 bg-gray-100",value:r,ref:s=>u.current[n]=s,onChange:s=>A(n,s.target.value),autoComplete:n===0?"one-time-code":void 0,onKeyDown:s=>D(n,s),onPaste:n===0?C:void 0},n))}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-4",children:[e.jsx(k,{block:!0,onClick:()=>h("/sign-in"),variant:"default",className:"w-full sm:w-1/2",children:"Back"}),e.jsx(k,{block:!0,loading:o,disabled:i.join("").length!==6,variant:"solid",type:"submit",className:"w-full sm:w-1/2",children:"Verify"})]})]})})}),l!=="Authenticator"&&e.jsxs("p",{className:"mt-4 text-sm text-gray-600 text-center px-4 sm:px-8 pt-2",children:["Didn’t get OTP?"," ",e.jsx("span",{onClick:()=>T(),className:"text-custom-500 hover:underline cursor-pointer",children:"Resend"})]})]})]})]})},q=()=>{var p;const{email:d,id:b,phone:y}=S(h=>h.auth.user),c=R(),m=((p=c==null?void 0:c.state)==null?void 0:p.validatethrough)||"",f=new URLSearchParams(document.location.search).get("tempToken")??"";return e.jsx(U,{disableSubmit:!1,tempToken:f,email:d??"",authType:m,userId:b,phone:y})},de=q;export{de as default};
