import{a3 as B,a4 as V,bd as E,aA as w,r as c,al as N,am as W,be as $,Y as H,ao as A,j as t,aq as U,ar as O,as as z,at as q,T,a as Y,b as G,c as J,B as K,e as j,M as Q,A as X,g as Z,h as ee,L as M}from"./index-B1H8BCL7.js";import{C as te}from"./Card-Dkp4tDNB.js";import{C as oe}from"./CardContent-uvNuWwEy.js";import{S as F}from"./Stack-BIAbaqpj.js";import"./useThemeProps-DL_l3A7P.js";function ne(o){return B("MuiLink",o)}const re=V("MuiLink",["root","underlineNone","underlineHover","underlineAlways","button","focusVisible"]),_={primary:"primary.main",textPrimary:"text.primary",secondary:"secondary.main",textSecondary:"text.secondary",error:"error.main"},se=o=>_[o]||o,ae=({theme:o,ownerState:e})=>{const s=se(e.color),r=E(o,`palette.${s}`,!1)||e.color,l=E(o,`palette.${s}Channel`);return"vars"in o&&l?`rgba(${l} / 0.4)`:w(r,.4)},ie=["className","color","component","onBlur","onFocus","TypographyClasses","underline","variant","sx"],le=o=>{const{classes:e,component:s,focusVisible:r,underline:l}=o,i={root:["root",`underline${O(l)}`,s==="button"&&"button",r&&"focusVisible"]};return z(i,ne,e)},ce=q(T,{name:"MuiLink",slot:"Root",overridesResolver:(o,e)=>{const{ownerState:s}=o;return[e.root,e[`underline${O(s.underline)}`],s.component==="button"&&e.button]}})(({theme:o,ownerState:e})=>A({},e.underline==="none"&&{textDecoration:"none"},e.underline==="hover"&&{textDecoration:"none","&:hover":{textDecoration:"underline"}},e.underline==="always"&&A({textDecoration:"underline"},e.color!=="inherit"&&{textDecorationColor:ae({theme:o,ownerState:e})},{"&:hover":{textDecorationColor:"inherit"}}),e.component==="button"&&{position:"relative",WebkitTapHighlightColor:"transparent",backgroundColor:"transparent",outline:0,border:0,margin:0,borderRadius:0,padding:0,cursor:"pointer",userSelect:"none",verticalAlign:"middle",MozAppearance:"none",WebkitAppearance:"none","&::-moz-focus-inner":{borderStyle:"none"},[`&.${re.focusVisible}`]:{outline:"auto"}})),I=c.forwardRef(function(e,s){const r=N({props:e,name:"MuiLink"}),{className:l,color:i="primary",component:f="a",onBlur:d,onFocus:g,TypographyClasses:x,underline:L="always",variant:p="inherit",sx:u}=r,y=W(r,ie),{isFocusVisibleRef:m,onBlur:P,onFocus:n,ref:C}=$(),[S,b]=c.useState(!1),a=H(s,C),k=h=>{P(h),m.current===!1&&b(!1),d&&d(h)},R=h=>{n(h),m.current===!0&&b(!0),g&&g(h)},v=A({},r,{color:i,component:f,focusVisible:S,underline:L,variant:p}),D=le(v);return t.jsx(ce,A({color:i,className:U(D.root,l),classes:x,component:f,onBlur:k,onFocus:R,ref:a,ownerState:v,variant:p,sx:[...Object.keys(_).includes(i)?[]:[{color:i}],...Array.isArray(u)?u:[u]]},y))}),ue=[{value:"EMAIL_PASSWORD",label:"Email + password"},{value:"PHONE_PIN",label:"Phone + PIN (doctors)"}];function fe(){const o=Y(),e=G(),{login:s}=J(),[r,l]=c.useState("EMAIL_PASSWORD"),[i,f]=c.useState(""),[d,g]=c.useState(""),[x,L]=c.useState(()=>{try{return localStorage.getItem("labSlug")||""}catch{return""}}),[p,u]=c.useState(!1),[y,m]=c.useState(null),P=async n=>{var C,S,b;n.preventDefault(),m(null),u(!0);try{const a=await s({identifier:i.trim(),credential:d,method:r,labSlug:x.trim()||null}),k=["LAB","HOSPITAL","DOCTOR"],R=Array.isArray(a==null?void 0:a.roles)&&a.roles.some(D=>k.includes(D)),v=((S=(C=e.state)==null?void 0:C.from)==null?void 0:S.pathname)||(R?"/lab-portal":"/dashboard/default");o(v,{replace:!0})}catch(a){m(((b=a==null?void 0:a.data)==null?void 0:b.message)||"Sign-in failed. Please check your credentials.")}finally{u(!1)}};return t.jsx(K,{sx:{display:"flex",justifyContent:"center",mt:6,px:2},children:t.jsx(te,{sx:{maxWidth:420,width:"100%"},children:t.jsxs(oe,{children:[t.jsx(T,{variant:"h4",gutterBottom:!0,children:"Sign in"}),t.jsx(T,{variant:"body2",color:"text.secondary",sx:{mb:3},children:"Sign in to your lab dashboard."}),t.jsx("form",{onSubmit:P,children:t.jsxs(F,{spacing:2,children:[t.jsx(j,{select:!0,label:"Sign-in method",value:r,onChange:n=>l(n.target.value),children:ue.map(n=>t.jsx(Q,{value:n.value,children:n.label},n.value))}),t.jsx(j,{label:r==="EMAIL_PASSWORD"?"Email":"Phone number",value:i,onChange:n=>f(n.target.value),required:!0,autoComplete:"username"}),t.jsx(j,{label:r==="EMAIL_PASSWORD"?"Password":"PIN",type:"password",value:d,onChange:n=>g(n.target.value),required:!0,autoComplete:"current-password"}),t.jsx(j,{label:"Your lab (optional)",value:x,onChange:n=>L(n.target.value),helperText:"Enter your lab name/code if you belong to more than one lab."}),y&&t.jsx(X,{severity:"error",children:y}),t.jsx(Z,{type:"submit",variant:"contained",disabled:p,size:"large",children:p?t.jsx(ee,{size:22}):"Sign in"}),t.jsxs(F,{direction:"row",justifyContent:"space-between",children:[t.jsx(I,{component:M,to:"/forgot-password",variant:"body2",children:"Forgot password?"}),t.jsx(I,{component:M,to:"/signup",variant:"body2",children:"Create a lab"})]})]})})]})})})}export{fe as default};
