import{r as n,a as b,b as _,j as t,l as i}from"./index-7c7a558c.js";import{g as x,a as v}from"./adminCommonApi-0dc9ea8e.js";import{S as j,a as p}from"./Switch-6e983219.js";function y({user_id:l}){const[r,u]=n.useState("on"),[f,m]=n.useState(""),{isLoading:g,data:e}=b("getTwoFactorStatus",()=>x(l)),{isLoading:c,mutate:d}=_(v,{onSuccess:a=>{var o,s;(o=a==null?void 0:a.data)!=null&&o.success&&i.success((s=a==null?void 0:a.data)==null?void 0:s.success)},onError:a=>{var o,s,w,h;(s=(o=a==null?void 0:a.response)==null?void 0:o.data)!=null&&s.message?i.error((h=(w=a==null?void 0:a.response)==null?void 0:w.data)==null?void 0:h.message):i.error("something went wrong. Please try again")}});return n.useEffect(()=>{var a;(a=e==null?void 0:e.data)!=null&&a.two_fa_status&&(u(e.data.two_fa_status=="Enabled"?"on":"off"),m(e.data.two_fa_method))},[e]),t.jsx(j,{visible:g,children:t.jsx("div",{className:"relative overflow-x-auto p-2 bg-gradient-to-r from-main to-second shadow-md border-dashed border rounded-tr-xl rounded-bl-xl",children:t.jsxs("div",{className:"p-6 space-y-4 md:space-y-6 sm:p-8",children:[t.jsx("div",{className:"relative z-0 w-full mb-6 group",children:t.jsx(p,{size:"lg",onLabel:"ON",offLabel:"OFF",label:"Two Factor Authentication",withAsterisk:!0,styles:{track:"background: white",label:"color: white"},checked:r=="on",disabled:c,onChange:a=>{c||(u(a.currentTarget.checked?"on":"off"),a.currentTarget.checked?d({formdata:{user_id:l,two_fa_enabled:!0,two_fa_method:f}}):d({formdata:{user_id:l,two_fa_enabled:!1}}))}})}),r=="on"?t.jsxs("div",{className:"relative z-0 w-full mb-6 group",children:[t.jsx("p",{className:"text-sm font-medium text-white",children:"Two Factor Authentication Method"}),t.jsxs("select",{onChange:a=>{m(a.target.value),d({formdata:{user_id:l,two_fa_enabled:!0,two_fa_method:a.target.value}})},value:f,disabled:c,className:"w-full px-4 py-2 mt-2 text-gray-700 bg-white border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",children:[t.jsx("option",{value:"email",children:"Email"}),t.jsx("option",{value:"mobile",children:"SMS"})]})]}):null]})})})}export{y as T};
