import{a as y,ki as k,u as b,z as w,d as L,kj as S,r as m,b0 as v,kk as T,kl as P,j as e,B as r,R as F,T as c,e as I}from"./index-dc933734.js";import"./GenericThumbnailView-69a8725b.js";import{F as E}from"./FormInput-58d4b01b.js";import{P as _}from"./PasswordInput-a7d425c5.js";import"./componentStyles-4df963a1.js";import{P as B}from"./PageMetaData-7ff53e2b.js";import"./ScrollableList-c8354e44.js";import"./TextArea-80ac5c9b.js";import{c as A,b as l,u as D}from"./index.esm-288e984c.js";import{A as q}from"./AuthLayout-c1ed38f0.js";import{o as z}from"./yup-5b2e0cf9.js";import{L as C}from"./LoadingButton-2e968ec8.js";import"./index-9b86adbc.js";import"./popper-f3391c26.js";import"./Select-e75c6695.js";import"./index-e5978b8b.js";import"./Grow-3459ea54.js";import"./InputAdornment-a4d846b9.js";import"./TextField-a8016ff3.js";import"./isMuiElement-f75ebb7c.js";import"./FormControlLabel-476fd96c.js";import"./useToggle-ac777176.js";import"./TableRow-f425a931.js";import"./CircularProgress-b8ef250f.js";import"./AuthBGLayout-c5966b13.js";import"./Grid2-9337452f.js";import"./CardContent-06dac9b3.js";import"./Avatar-95a09ff6.js";import"./composeClasses-b42b2e69.js";function N(){const{loading:s}=y(t=>k(t)),a=b(),o=w(),n=L(),{enqueueSnackbar:p}=S(),[u,U]=m.useState(""),d=A({username:l().required("Please enter username"),password:l().required("Please enter password")}),{control:x,handleSubmit:g}=D({resolver:z(d),defaultValues:{}}),i=m.useMemo(()=>{var t;return(t=a.state)==null||t.from.pathname,"/dashboard"},[a.state]),h=g(async t=>{const f=v();localStorage.getItem("currentToken")&&localStorage.getItem("currentToken");const j={username:t.username,password:t.password,user_type:"User",device_uuid:f,device_name:T,device_type:3,device_fcmtoken:u};n(P({data:j,redirectUrl:i,navigate:o,enqueueSnackbar:p}))});return m.useEffect(()=>{localStorage.getItem("currentToken")&&(console.log("current token:",localStorage.getItem("currentToken")),o(i))},[localStorage.getItem("currentToken")]),{loading:s,handleLogin:h,redirectUrl:i,control:x}}const R=()=>e.jsx(r,{sx:{my:"16px",display:"flex",justifyContent:"center"},children:e.jsxs(c,{variant:"body2",color:"text.secondary",sx:{display:"flex",flexWrap:"nowrap",gap:.5},children:["Don't have an account? ",e.jsx(I,{to:"/auth/register",children:e.jsx(c,{variant:"subtitle2",component:"span",children:"Register"})})]})}),he=()=>{const{loading:s,handleLogin:a,control:o}=N();return e.jsxs(e.Fragment,{children:[e.jsx(B,{title:"Login"}),e.jsx(q,{authTitle:"",helpText:"",bottomLinks:e.jsx(R,{}),children:e.jsx(r,{sx:{px:3,height:"280px"},children:e.jsxs("form",{onSubmit:a,children:[e.jsx(r,{sx:{mt:5},children:e.jsx(E,{name:"username",type:"text",label:"User Name",placeholder:"Enter your user name",control:o})}),e.jsx(r,{sx:{mt:3},children:e.jsx(_,{name:"password",type:"password",label:"Password",placeholder:"Enter your password",control:o})}),e.jsxs(r,{sx:{display:"flex",justifyContent:"space-between",mt:5},children:[e.jsx(C,{loading:s,variant:"contained",sx:{bgcolor:"#0E484C"},type:"submit",disabled:s,size:"small",children:"Login"}),e.jsx(F,{variant:"text",sx:n=>({color:n.palette.text.primary}),size:"large",children:"Forget your Password ?"})]})]})})})]})};export{he as default};
