import{j as e}from"./vendor-mui-69397583.js";import{a as w,F as v,I as d,ai as y,cd as A,cM as D,a5 as S,c_ as U,B as f,ej as P,O as R,Q as C}from"./index-c62ac197.js";import{U as E}from"./Upload-fb34ce03.js";import{S as I}from"./Switcher-c8648037.js";import{F as $}from"./FormContainer-91c2b0e4.js";import{F as q,a as c,u as O,e as Q,b as k}from"./index-51ee35f9.js";import{c as G,a as m,h as L,e as T,F as z,b as V,d as u}from"./index.esm-70ab539c.js";import{r as B}from"./vendor-react-ece1c85f.js";import{Q as Z}from"./index-0ec48d3d.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"./PreferenceService-75bf9db6.js";const J=i=>{let{value:a}=i.target;a=a.replace(/\D/g,"");var n=a.length;n>0&&(a="("+a),n>3&&(a=a.slice(0,4)+") "+a.slice(4,11)),n>6&&(a=a.slice(0,9)+"-"+a.slice(9)),i.target.value=a},M=G().shape({name:m().min(3,"Too Short!").max(40,"Too Long!").required("User Name Required"),email:m().matches(/^[^\s@]+@[^\s@]+\.[a-zA-Z]{2,}$/,"Invalid email").required("Email Required"),title:m(),avatar:L(),lang:m(),timeZone:m(),syncData:T(),phoneNo:m().required("Phone No Required").matches(/^[0-9()\-\s]+$/,"Phone must only contain numbers, parentheses, dashes, and spaces").test("is-ten-digits","Please enter valid Phone No",i=>i?i.replace(/[()\-\s]/g,"").length===10:!0)}),me=()=>{const i=w(),a=v(s=>s.auth.user),[n,x]=B.useState(null),F={name:a.userName,email:a.email,title:"",avatar:a.avatar||"",timeZone:"",lang:"",syncData:!1,twoFactor:a.twoFactorEnabled||!1,twoFactorForAllUsers:a.twoFactorForAllUsers||!1,phoneNo:a.phone},j=(s,r,t)=>{t.length>0?(x(t[0]),s.setFieldValue(r.name,t[0])):(x(null),s.setFieldValue(r.name,null))},g=async(s,r)=>{var p,h,l;if(n){const o=await i(O({file:n}));s.avatar=o}a.twoFactorForAllUsers&&(localStorage.setItem("twoFactorEnabled",s.twoFactor.toString()),await Q(s.twoFactor??!1));const t=await k(s);if(t&&t.userDetails){localStorage.setItem("updatedUserDetails",JSON.stringify(t.userDetails)),i(P({...t==null?void 0:t.userDetails,userName:`${(p=t==null?void 0:t.userDetails)==null?void 0:p.firstName} ${(h=t==null?void 0:t.userDetails)==null?void 0:h.lastName}`,phone:(l=t==null?void 0:t.userDetails)==null?void 0:l.phoneNumber}));const o=localStorage.getItem("updatedUserDetails");o&&JSON.parse(o),R.push(e.jsx(C,{title:"Profile Updated",type:"success"}),{placement:"top-center"})}r(!1)};return e.jsx(z,{enableReinitialize:!0,initialValues:F,validationSchema:M,onSubmit:(s,{setSubmitting:r})=>{r(!0),setTimeout(()=>{g(s,r)},1e3)},children:({values:s,touched:r,errors:t,isSubmitting:p,resetForm:h})=>{const l={touched:r,errors:t};return e.jsx(V,{children:e.jsxs($,{children:[e.jsx(q,{title:"General",desc:"Basic info, like your name and address that will displayed in public"}),e.jsx(c,{name:"name",label:"Name",...l,children:e.jsx(u,{type:"text",autoComplete:"off",name:"name",placeholder:"Name",component:d,prefix:e.jsx(y,{className:"text-xl"})})}),e.jsx(c,{name:"email",label:"Email",...l,children:e.jsx(u,{disabled:!0,readOnly:!0,type:"email",autoComplete:"off",name:"email",placeholder:"Email",component:d,prefix:e.jsx(A,{className:"text-xl"})})}),e.jsx(c,{name:"phoneNo",label:"Phone Number",...l,children:e.jsx(u,{type:"text",autoComplete:"off",onInput:o=>{J(o)},name:"phoneNo",placeholder:"Phone No",component:d,prefix:e.jsx(D,{className:"text-xl"})})}),e.jsx(c,{name:"avatar",label:"Avatar",...l,children:e.jsx(u,{name:"avatar",children:({field:o,form:b})=>e.jsx(E,{className:"cursor-pointer",showList:!1,uploadLimit:1,aspectRatio:1,objectFit:"contain",onChange:N=>j(b,o,N),children:e.jsx(S,{className:"border-2 border-white dark:border-gray-800 shadow-lg",size:60,shape:"circle",icon:e.jsx(U,{}),src:o.value instanceof File?URL.createObjectURL(o.value):o.value})})})}),a.twoFactorForAllUsers&&e.jsx(c,{name:"twoFactor",label:"Two Factor Authentication",...l,border:!1,children:e.jsx(u,{name:"twoFactor",component:I})}),a.twoFactorEnabled&&e.jsx(c,{name:"AuthenticatorQr",label:"Authenticator Qr",...l,border:!1,children:e.jsxs("div",{className:"flex flex-col sm:flex-row gap-4",children:[e.jsx(Z,{value:a.authenticatorUrl||""}),e.jsxs("p",{className:"text-sm text-gray-700 leading-relaxed pt-2 dark:text-gray-400",children:[e.jsx("span",{children:"Scan the QR code using Google or Microsoft Authenticator to set up 2FA."}),e.jsx("br",{}),e.jsx("span",{children:"If you choose to use the Authenticator app for 2FA, enter the OTP shown in the app each time you log in."}),e.jsx("br",{}),e.jsx("span",{children:"Get an authenticator app from the App Store or Google Play."})]})]})}),e.jsxs("div",{className:"mt-4 ltr:text-right",children:[e.jsx(f,{className:"ltr:mr-2 rtl:ml-2",type:"button",onClick:()=>h(),children:"Reset"}),e.jsx(f,{variant:"solid",loading:p,type:"submit",children:p?"Updating":"Update"})]})]})})}})};export{me as default};
