"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6658],{6658:function(e,a,s){s.r(a);var t=s(5893),r=s(7294),o=s(9513),l=s(1202),n=s(5346),i=s(3838);a.default=e=>{let{isOpen:a,onClose:s,onLoginSuccess:d}=e,[c,u]=(0,r.useState)(!1),[m,g]=(0,r.useState)(!1),[p,h]=(0,r.useState)(!1),[v,y]=(0,r.useState)(!1),[x,w]=(0,r.useState)(""),[f,j]=(0,r.useState)(""),[b,S]=(0,r.useState)(""),[P,C]=(0,r.useState)(""),[k,N]=(0,r.useState)(""),[A,I]=(0,r.useState)(!1),[L,_]=(0,r.useState)(!1),[E,T]=(0,r.useState)(!1),[O,D]=(0,r.useState)(!1),[q,B]=(0,r.useState)(!1),[U,F]=(0,r.useState)(!1),[M,Y]=(0,r.useState)({full_name:"",email:"",password:"",country:""}),[Z,z]=(0,r.useState)(!1),[G,H]=(0,r.useState)(!1),[R,J]=(0,r.useState)({hasUpperCase:!1,hasLowerCase:!1,hasNumber:!1,hasSpecialChar:!1,isMinLength:!1}),[V,$]=(0,r.useState)(""),[K,Q]=(0,r.useState)(""),[W,X]=(0,r.useState)(""),ee=()=>{_(e=>!e)},ea=()=>{z(e=>!e)},es=()=>{T(e=>!e)},et=()=>{D(e=>!e)},er=e=>{J({hasUpperCase:/[A-Z]/.test(e),hasLowerCase:/[a-z]/.test(e),hasNumber:/\d/.test(e),hasSpecialChar:/[!@#$%^&*(),.?":{}|<>]/.test(e),isMinLength:e.length>=8})},eo=e=>{let{name:a,value:s}=e.target;Y({...M,[a]:s}),"password"===a&&er(s)},el=()=>{let{full_name:e,email:a,password:s,country:t}=M;return e&&a&&s&&t?/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(a)?R.hasUpperCase&&R.hasLowerCase&&R.hasNumber&&R.hasSpecialChar&&R.isMinLength?"":"Password does not meet security requirements.":"Invalid email format.":"All fields are required."},en=async e=>{var a,s,t;e.preventDefault(),e.stopPropagation(),I(!0),Q("");try{let e=await i.ZP.post("/patient/auth/login/",{email:x,password:f,sender_id:"senderid",device_type:"web"});if(200===e.status&&!1!==e.data.status)sessionStorage.setItem("tempPassword",f),localStorage.setItem("authToken",e.data.token),u(!0),B(!1),F(!1),Q(""),o.Am.success("Please enter the OTP sent to your email");else{let s=(null===(a=e.data)||void 0===a?void 0:a.message)||"Invalid credentials. Please try again.";s.toLowerCase().includes("invalid credentials")?(Q("Invalid credentials. Please check your email and password."),o.Am.error("Invalid credentials. Please check your email and password.")):(Q(s),o.Am.error(s))}}catch(a){let e=(null===(t=a.response)||void 0===t?void 0:null===(s=t.data)||void 0===s?void 0:s.message)||a.message;e&&e.toLowerCase().includes("invalid credentials")?(Q("Invalid credentials. Please check your email and password."),o.Am.error("Invalid credentials. Please check your email and password.")):(Q(e||"Something went wrong. Please try again later."),o.Am.error(e||"Something went wrong. Please try again later."))}finally{I(!1)}},ei=async e=>{var a,s,t;e.preventDefault(),e.stopPropagation();let r=el();if(r){$(r),o.Am.error(r);return}I(!0),$("");try{let e=await i.ZP.post("/patient/auth/signup/",M);if(200===e.status&&e.data.status)o.Am.success("Signup successful! Please check your email for OTP."),w(M.email),g(!1),u(!0),B(!1),F(!0),sessionStorage.setItem("signupData",JSON.stringify({Full_Name:e.data.data.Full_Name,Email:e.data.data.Email,Password:e.data.data.Password,Sender_ID:"Sender_ID",Device_type:"web",Country:e.data.data.Country})),Y({full_name:"",email:"",password:"",country:""}),J({hasUpperCase:!1,hasLowerCase:!1,hasNumber:!1,hasSpecialChar:!1,isMinLength:!1});else{let s=(null===(a=e.data)||void 0===a?void 0:a.message)||"Signup failed. Please try again.";s.toLowerCase().includes("email")&&s.toLowerCase().includes("exist")?($("Email already exists. Please login or use a different email."),o.Am.error("Email already exists. Please login or use a different email.")):($(s),o.Am.error(s))}}catch(a){let e=(null===(t=a.response)||void 0===t?void 0:null===(s=t.data)||void 0===s?void 0:s.message)||a.message;e&&e.toLowerCase().includes("email")&&e.toLowerCase().includes("exist")?($("Email already exists. Please login or use a different email."),o.Am.error("Email already exists. Please login or use a different email.")):($(e||"An error occurred. Please try again later."),o.Am.error(e||"An error occurred. Please try again later."))}finally{I(!1)}},ed=async e=>{if(e.preventDefault(),e.stopPropagation(),!x){o.Am.error("Email is missing. Please go back and try again.");return}I(!0),X("");try{let e,a;if(U){let s=JSON.parse(sessionStorage.getItem("signupData")||"{}");e="/patient/auth/signup-verificafion/",a={Full_Name:s.Full_Name,Email:s.Email,Password:s.Password,Sender_ID:s.Sender_ID,Device_type:s.Device_type,Country:s.Country,otp:b}}else e=q?"/patient/auth/forgot-password/verify-otp/":"/patient/auth/login-verification/",a={email:x,otp:b};let t=await i.ZP.post(e,a),r=t.data;if((200===t.status||201===t.status)&&(null==r?void 0:r.status)){if(X(""),U&&(null==r?void 0:r.status))localStorage.setItem("authToken",r.token),sessionStorage.removeItem("signupData"),o.Am.success("OTP verified successfully! Please login."),u(!1),F(!1),w(""),j(""),S("");else if(q&&(null==r?void 0:r.status))o.Am.success("OTP verified successfully!"),u(!1),y(!0);else if(!U&&!q&&(null==r?void 0:r.status)){let e={email:x,token:r.token,timestamp:new Date().getTime()};localStorage.setItem("authToken",r.token),localStorage.setItem("userData",JSON.stringify(e)),sessionStorage.removeItem("tempPassword"),o.Am.success("OTP verified successfully!"),s(),d&&d()}}else{let e=(null==r?void 0:r.message)||"Invalid OTP!";e.toLowerCase().includes("otp")?(X("Invalid OTP. Please check the code and try again."),o.Am.warning("Invalid OTP. Please check the code and try again.")):(X(e),o.Am.error(e))}}catch(s){var a,t;let e=(null===(t=s.response)||void 0===t?void 0:null===(a=t.data)||void 0===a?void 0:a.message)||s.message;e&&e.toLowerCase().includes("otp")?(X("Invalid OTP. Please check the code and try again."),o.Am.warning("Invalid OTP. Please check the code and try again.")):(X(e||"Something went wrong, please try again."),o.Am.error(e||"Something went wrong, please try again."))}finally{I(!1)}},ec=async e=>{if(e.preventDefault(),e.stopPropagation(),!x){o.Am.error("Please enter your email address.");return}I(!0);try{let e=await i.ZP.post("/patient/auth/forgot-password/send-email/",{email:x});200===e.status?(localStorage.setItem("authToken",e.data.token),o.Am.success("Password reset code sent to your email!"),h(!1),u(!0),B(!0),F(!1)):o.Am.error("Invalid Email. Please try again.")}catch(e){console.error("One or more issues found:",e),o.Am.error("Something went wrong. Please try again later.")}finally{I(!1)}},eu=async e=>{if(e.preventDefault(),e.stopPropagation(),!P||!k){o.Am.error("Please fill in all fields.");return}if(P!==k){o.Am.error("Passwords do not match.");return}if(!Object.values({hasUpperCase:/[A-Z]/.test(P),hasLowerCase:/[a-z]/.test(P),hasNumber:/\d/.test(P),hasSpecialChar:/[!@#$%^&*(),.?":{}|<>]/.test(P),isMinLength:P.length>=8}).every(Boolean)){o.Am.error("Password does not meet security requirements.");return}I(!0);try{let e=await i.ZP.post("/patient/auth/forgot-password/reset/",{email:x,password:P});200===e.status?(o.Am.success("Password reset successfully! Please login with your new password."),y(!1),u(!1),h(!1),g(!1),B(!1),F(!1),w(""),j(""),S(""),C(""),N(""),sessionStorage.removeItem("tempPassword"),sessionStorage.removeItem("signupData")):o.Am.error("Failed to reset password. Please try again.")}catch(e){console.error("Error resetting password:",e),o.Am.error("Something went wrong. Please try again later.")}finally{I(!1)}};(0,r.useEffect)(()=>{let e=()=>{if(a&&window.google&&!p&&!c&&!v)try{google.accounts.id.initialize({client_id:"915629878612-onuco3uedr9mphji79d2340jrdjh8cfc.apps.googleusercontent.com",callback:em});let e=document.getElementById("google-login-btn"),a=document.getElementById("google-signup-btn");e&&(e.innerHTML=""),a&&(a.innerHTML=""),!m&&e&&google.accounts.id.renderButton(e,{theme:"outline",size:"large",width:"250",text:"signin_with"}),m&&a&&google.accounts.id.renderButton(a,{theme:"outline",size:"large",width:"250",text:"signup_with"})}catch(e){console.error("Error initializing Google Auth:",e)}};if(window.google)e();else{let a=setInterval(()=>{window.google&&(clearInterval(a),e())},100);setTimeout(()=>{clearInterval(a)},1e4)}return()=>{let e=document.getElementById("google-login-btn"),a=document.getElementById("google-signup-btn");e&&(e.innerHTML=""),a&&(a.innerHTML="")}},[a,m,p,c,v]);let em=async e=>{let a=e.credential,t=(0,l.o)(a),r=t.email,n=t.name||"".concat(t.given_name," ").concat(t.family_name);try{let e=await i.ZP.post("/patient/auth/google-signin/",{email:r,full_name:n,sender_id:"8327873829",device_type:"web"},{headers:{"Content-Type":"application/json"}});200===e.status?(localStorage.setItem("authToken",e.data.token),o.Am.success("Google login successful!"),s(),d&&d()):(console.error("Unexpected response status:",e.status),o.Am.error("Something went wrong with Google login."))}catch(a){var c,u,m,g;console.error("Google login error:",a),console.error("Error response:",null===(c=a.response)||void 0===c?void 0:c.data),console.error("Error status:",null===(u=a.response)||void 0===u?void 0:u.status);let e=(null===(g=a.response)||void 0===g?void 0:null===(m=g.data)||void 0===m?void 0:m.message)||a.message||"Google login failed. Please try again.";o.Am.error(e)}},eg=()=>{w(""),j(""),S(""),C(""),N(""),I(!1),u(!1),g(!1),h(!1),y(!1),B(!1),F(!1),_(!1),z(!1),T(!1),D(!1),Y({full_name:"",email:"",password:"",country:""}),J({hasUpperCase:!1,hasLowerCase:!1,hasNumber:!1,hasSpecialChar:!1,isMinLength:!1}),$(""),Q(""),X(""),sessionStorage.removeItem("tempPassword"),sessionStorage.removeItem("signupData"),s()};return a?(0,t.jsx)("div",{className:"modal-overlay",onClick:eg,children:(0,t.jsxs)("div",{className:"modal-content",onClick:e=>e.stopPropagation(),children:[(0,t.jsx)("button",{className:"modal-close",onClick:eg,children:"\xd7"}),(0,t.jsx)("h1",{className:"formhead",children:c?"OTP Verification":m?"Patient Sign Up":p?"Forgot Password":v?"Set Your New Password":"Patient Login"}),c?(0,t.jsx)(t.Fragment,{children:x?(0,t.jsxs)("form",{onSubmit:ed,children:[(0,t.jsxs)("div",{className:"form-group",children:[(0,t.jsx)("label",{htmlFor:"otp-input",children:"Enter OTP"}),(0,t.jsx)("input",{id:"otp-input",type:"text",placeholder:"Enter the OTP sent to your email",value:b,onChange:e=>S(e.target.value),required:!0})]}),c&&W&&(0,t.jsx)("div",{className:"modal-error-message",children:W}),(0,t.jsx)("button",{className:"login-submit-button",type:"submit",disabled:A,children:A?"Verifying...":"Verify OTP"}),(0,t.jsx)("div",{className:"modal-links",children:(0,t.jsx)("button",{type:"button",className:"modal-link back-button",onClick:()=>{u(!1),g(!1),h(!1),F(!1),B(!1),X("")},children:"← Back to Login"})})]}):(0,t.jsxs)("div",{className:"error-message",children:[(0,t.jsx)("p",{children:"Email is missing. Please go back and try again."}),(0,t.jsx)("button",{className:"modal-link back-button",onClick:()=>{u(!1),g(!1),h(!1),F(!1),B(!1),X("")},children:"← Back to Login"})]})}):v?(0,t.jsxs)("form",{onSubmit:eu,children:[(0,t.jsx)("div",{className:"form-group",children:(0,t.jsxs)("div",{style:{position:"relative",width:"100%"},children:[(0,t.jsx)("input",{type:E?"text":"password",placeholder:"Enter new password",value:P,onChange:e=>C(e.target.value),required:!0,style:{paddingRight:"40px"}}),E?(0,t.jsx)(n.tgn,{onClick:es,style:{position:"absolute",top:"60%",right:"10px",transform:"translateY(-80%)",cursor:"pointer",color:"#aaa"}}):(0,t.jsx)(n.dSq,{onClick:es,style:{position:"absolute",top:"60%",right:"10px",transform:"translateY(-80%)",cursor:"pointer",color:"#aaa"}})]})}),(0,t.jsx)("div",{className:"form-group",children:(0,t.jsxs)("div",{style:{position:"relative",width:"100%"},children:[(0,t.jsx)("input",{type:O?"text":"password",placeholder:"Confirm new password",value:k,onChange:e=>N(e.target.value),required:!0,style:{paddingRight:"40px"}}),O?(0,t.jsx)(n.tgn,{onClick:et,style:{position:"absolute",top:"60%",right:"10px",transform:"translateY(-80%)",cursor:"pointer",color:"#aaa"}}):(0,t.jsx)(n.dSq,{onClick:et,style:{position:"absolute",top:"60%",right:"10px",transform:"translateY(-80%)",cursor:"pointer",color:"#aaa"}})]})}),(0,t.jsx)("button",{type:"submit",disabled:A,className:"login-submit-button",children:A?"Saving...":"Set Password"}),(0,t.jsx)("div",{className:"modal-links",children:(0,t.jsx)("button",{type:"button",className:"modal-link back-button",onClick:()=>{y(!1),u(!0)},children:"← Back to OTP"})})]}):p?(0,t.jsxs)("form",{onSubmit:ec,children:[(0,t.jsx)("div",{className:"form-group",children:(0,t.jsx)("input",{type:"email",placeholder:"Enter your email",value:x,onChange:e=>w(e.target.value),required:!0})}),(0,t.jsx)("button",{type:"submit",disabled:A,className:"login-submit-button",children:A?"Sending...":"Send Code"}),(0,t.jsx)("div",{className:"modal-links",children:(0,t.jsx)("button",{type:"button",className:"modal-link back-button",onClick:()=>h(!1),children:"← Back to Login"})})]}):m?(0,t.jsxs)("form",{onSubmit:ei,children:[(0,t.jsxs)("div",{style:{display:"flex",gap:"15px"},children:[(0,t.jsxs)("div",{className:"form-group",style:{flex:1},children:[(0,t.jsx)("label",{children:"Full Name:"}),(0,t.jsx)("input",{type:"text",name:"full_name",placeholder:"Full Name",value:M.full_name,onChange:eo,required:!0})]}),(0,t.jsxs)("div",{className:"form-group",style:{flex:1},children:[(0,t.jsx)("label",{children:"Email:"}),(0,t.jsx)("input",{type:"email",name:"email",placeholder:"Email",value:M.email,onChange:eo,required:!0})]})]}),(0,t.jsxs)("div",{className:"form-group",children:[(0,t.jsx)("label",{children:"Country:"}),(0,t.jsxs)("select",{name:"country",value:M.country,onChange:eo,required:!0,className:"country-select",children:[(0,t.jsx)("option",{value:"",children:"Select a country"}),(0,t.jsx)("option",{value:"United Kingdom",children:"United Kingdom"}),(0,t.jsx)("option",{value:"Canada",children:"Canada"}),(0,t.jsx)("option",{value:"United States",children:"United States"}),(0,t.jsx)("option",{value:"Pakistan",children:"Pakistan"})]})]}),(0,t.jsxs)("div",{className:"form-group",children:[(0,t.jsx)("label",{children:"Password:"}),(0,t.jsxs)("div",{style:{position:"relative",width:"100%"},children:[(0,t.jsx)("input",{type:Z?"text":"password",name:"password",placeholder:"Password",value:M.password,onChange:eo,onFocus:()=>H(!0),onBlur:()=>H(!1),required:!0,style:{paddingRight:"40px"}}),Z?(0,t.jsx)(n.tgn,{onClick:ea,style:{position:"absolute",top:"50%",right:"10px",transform:"translateY(-80%)",cursor:"pointer",color:"#aaa"}}):(0,t.jsx)(n.dSq,{onClick:ea,style:{position:"absolute",top:"50%",right:"10px",transform:"translateY(-80%)",cursor:"pointer",color:"#aaa"}})]})]}),G&&(0,t.jsxs)("div",{style:{marginTop:"10px"},children:[(0,t.jsx)("div",{className:"password-validation",style:{fontSize:"0.8rem",marginBottom:"10px"},children:(0,t.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"5px"},children:[(0,t.jsx)("span",{style:{color:R.hasUpperCase?"green":"red"},children:"at least one uppercase letter"}),(0,t.jsx)("span",{style:{color:R.hasLowerCase?"green":"red"},children:"at least one lowercase letter"}),(0,t.jsx)("span",{style:{color:R.hasNumber?"green":"red"},children:"at least one number"}),(0,t.jsx)("span",{style:{color:R.hasSpecialChar?"green":"red"},children:"at least one special character"}),(0,t.jsx)("span",{style:{color:R.isMinLength?"green":"red"},children:"at least 8 characters"})]})}),(0,t.jsx)("div",{className:"password-strength-bar",children:(0,t.jsx)("div",{className:"password-strength-fill",style:{width:"".concat(Object.values(R).filter(Boolean).length/5*100,"%"),backgroundColor:Object.values(R).filter(Boolean).length<=2?"red":3===Object.values(R).filter(Boolean).length?"orange":"green"}})})]}),V&&(0,t.jsx)("div",{className:"modal-error-message",children:V}),(0,t.jsx)("button",{type:"submit",disabled:A,className:"login-submit-button",children:A?"Signing up...":"Sign Up"}),(0,t.jsx)("div",{className:"modal-links",children:(0,t.jsx)("button",{type:"button",className:"modal-link",onClick:()=>{g(!1),$("")},children:"Already have an account? Login Here"})}),(0,t.jsx)("div",{className:"google-login-container",children:(0,t.jsx)("div",{id:"google-signup-btn"})})]}):(0,t.jsxs)("form",{onSubmit:en,children:[(0,t.jsx)("div",{className:"form-group",children:(0,t.jsx)("input",{type:"email",placeholder:"Email",value:x,onChange:e=>w(e.target.value),required:!0})}),(0,t.jsx)("div",{className:"form-group",children:(0,t.jsxs)("div",{style:{position:"relative",width:"100%"},children:[(0,t.jsx)("input",{type:L?"text":"password",placeholder:"Password",value:f,onChange:e=>j(e.target.value),required:!0,style:{paddingRight:"40px"}}),L?(0,t.jsx)(n.tgn,{onClick:ee,style:{position:"absolute",top:"60%",right:"10px",transform:"translateY(-80%)",cursor:"pointer",color:"#aaa"}}):(0,t.jsx)(n.dSq,{onClick:ee,style:{position:"absolute",top:"60%",right:"10px",transform:"translateY(-80%)",cursor:"pointer",color:"#aaa"}})]})}),!m&&!c&&!p&&!v&&K&&(0,t.jsx)("div",{className:"modal-error-message",children:K}),(0,t.jsx)("button",{type:"submit",disabled:A,className:"login-submit-button",children:A?"Logging in...":"Login"}),(0,t.jsxs)("div",{className:"modal-links",children:[(0,t.jsx)("button",{type:"button",className:"modal-link",onClick:()=>{h(!0),Q("")},children:"Forgot your password?"}),(0,t.jsx)("button",{type:"button",className:"modal-link",onClick:()=>{g(!0),Q("")},children:"Don't have an account? Signup Now!"})]}),(0,t.jsx)("div",{className:"google-login-container",children:(0,t.jsx)("div",{id:"google-login-btn"})})]})]})}):null}}}]);