import{cD as t,r as g,cE as J,u as Z,cF as ee,aH as P,P as ne,cG as te,aq as re,cH as oe,j as r,b as e,F as U,q as u,B as ae,cI as ie,cJ as D,cK as se,aU as le}from"./index-DlNZgIG9.js";const ce=t.div`
  background-color: #fff;
  border-radius: 10px;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
  position: relative;
  overflow: hidden;
  width: 678px;
  max-width: 100%;
  min-height: 500px;
`,de=t.div`
  position: absolute;
  top: 0;
  height: 100%;
  transition: all 0.6s ease-in-out;
  left: 0;
  width: 50%;
  opacity: 0;
  z-index: 1;
  ${n=>!n.signinIn&&`
    transform: translateX(100%);
    opacity: 1;
    z-index: 5;
  `}
`,pe=t.div`
  position: absolute;
  top: 0;
  height: 100%;
  transition: all 0.6s ease-in-out;
  left: 0;
  width: 50%;
  z-index: 2;
  ${n=>n.signinIn?null:"transform: translateX(100%);"}
`,N=t.form`
  background-color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 0 30px;
  height: 100%;
  text-align: center;
`,l=t.h1`
  font-weight: bold;
  margin: 0;
`,a=t.input`
  background-color: #eee;
  border: none;
  padding: 12px 15px;
  margin: 8px 0;
  width: 100%;
`,m=t.button`
  border-radius: 20px;
  border: 1px solid #196ae5;
  background-color: #196ae5;
  color: #ffffff;
  font-size: 12px;
  cursor: pointer;
  font-weight: bold;
  padding: 12px 45px;
  letter-spacing: 1px;
  text-transform: uppercase;
  transition: transform 80ms ease-in;
  &:active {
    transform: scale(0.95);
  }
  &:focus {
    outline: none;
  }
`,A=t(m)`
  background-color: transparent;
  border-color: #ffffff;
  cursor: pointer;
`;t.a`
  color: #333;
  font-size: 14px;
  text-decoration: none;
  margin: 15px 0;
`;const ue=t.div`
  position: absolute;
  top: 0;
  left: 50%;
  width: 50%;
  height: 100%;
  overflow: hidden;
  transition: transform 0.6s ease-in-out;
  z-index: 100;
  ${n=>n.signinIn?null:"transform: translateX(-100%);"}
`,he=t.div`
  background: #b060bc;
  background: -webkit-linear-gradient(45deg, #b060bcba, #23a6d5c2);
  background: linear-gradient(45deg, #b060bcba, #23a6d5c2);
  background-repeat: no-repeat;
  background-size: cover;
  background-position: 0 0;
  color: #ffffff;
  position: relative;
  left: -100%;
  height: 100%;
  width: 200%;
  transform: translateX(0);
  transition: transform 0.6s ease-in-out;
  ${n=>n.signinIn?null:"transform: translateX(50%);"}
`,L=t.div`
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 0 40px;
  text-align: center;
  top: 0;
  height: 100%;
  width: 50%;
  transform: translateX(0);
  transition: transform 0.6s ease-in-out;
`,ge=t(L)`
  transform: translateX(-20%);
  ${n=>n.signinIn?null:"transform: translateX(0);"}
`,me=t(L)`
  right: 0;
  transform: translateX(0);
  ${n=>n.signinIn?null:"transform: translateX(20%);"}
`,F=t.p`
  font-size: 14px;
  font-weight: 100;
  line-height: 20px;
  letter-spacing: 0.5px;
  margin: 20px 0 30px;
`,fe=t.div`
  background-color: #fff;
  border-radius: 12px;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
  box-sizing: border-box;
  width: 100%;
  max-width: 350px;
  padding: 28px 20px 20px;
  text-align: center;
  /* Auto margins, not the parent's align-items: center. A centred flex item that grows
     taller than a scrolling container (short phone with the keyboard open) has its top
     clipped and unreachable; auto margins centre the same way but clamp at the top edge. */
  margin: auto 0;
`,E=t.form`
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  text-align: center;
`,c=t(a)`
  border-radius: 8px;
  padding: 14px 16px;
  margin: 6px 0;
  /* 16px is deliberate: iOS Safari zooms the whole page when a focused input has a
     font-size below 16px, which then leaves the form off-screen. */
  font-size: 13px;
  box-sizing: border-box;
  &:focus {
    outline: 2px solid #196ae5;
    outline-offset: -2px;
  }
`,R=t(m)`
  width: 100%;
  /* 48px keeps the primary action at/above the recommended touch-target size. */
  min-height: 48px;
  margin-top: 18px;
  font-size: 12px;
`,O=t.p`
  color: #555;
  font-size: 14px;
  margin: 22px 0 0;
`,X=t.button`
  background: none;
  border: none;
  padding: 8px 4px;
  min-height: 44px;
  color: #196ae5;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  &:focus-visible {
    outline: 2px solid #196ae5;
    border-radius: 4px;
  }
`;function w(n){return r(u,{variant:"body2",color:"text.secondary",align:"center",...n,mt:2,children:["Copyright © ",e(se,{color:"inherit",href:"https://huewine.com/",target:"_blank",children:"Huewine Technologies"})," ",new Date().getFullYear(),"."]})}const B=te();le("div")(({theme:n})=>({...n.typography.button,backgroundColor:n.palette.background.paper,padding:n.spacing(1),textAlign:"center"}));function ke(){const[n,i]=g.useState(""),h=J(),S=Z(),[M]=ee();P({userRoleDTOList:[]},{});const[o,f]=g.useState(!0),j=ne(B.breakpoints.down("md"),{noSsr:!0}),[xe,be]=g.useState({firstName:"",userName:"",phoneNumber:void 0,password:"",gender:""}),{userId:H,accessToken:ye}=re(s=>s.user),{data:x,isFetching:k,error:we}=P({userRoleDTOList:[]},{skip:!H}),I=async s=>{s.preventDefault();const T=new FormData(s.currentTarget),b=T.get("username"),y=T.get("password");if(b.trim()){if(!y.trim()){i("Please enter your password.");return}}else{i("Please enter your username.");return}const V="admin",G="admin123",q="mocked-static-token-123",K=1;if(b===V&&y===G){h(D({userId:K,accessToken:q})),S("/");return}const Q={userName:b,password:y,applicationName:"ERP"};try{const p=await M({Login:Q});if("data"in p)if(p.data&&p.data.code===200){const z=p.data,W=z.user.id,Y=z.user.token;h(D({userId:W,accessToken:Y})),S("/")}else i("Login Failed. Invalid credentials.");else i("Login Failed. Please try again.")}catch{i("Login Failed. Please try again.")}};g.useEffect(()=>{x&&!k&&h(oe(x))},[x,k,h]);const d=()=>{i("")},v=()=>{},C=s=>{d(),f(s)},_=r(fe,{children:[o?r(U,{children:[e(u,{variant:"button",display:"block",gutterBottom:!0,style:{fontSize:"1.5rem"},children:"Huewine"}),e(l,{children:"Sign in"}),r(E,{onSubmit:I,children:[e(c,{type:"text",placeholder:"Username",name:"username",autoComplete:"username",onChange:d}),e(c,{type:"password",placeholder:"Password",name:"password",autoComplete:"current-password",onChange:d}),n.length>0&&e(u,{style:{color:"red",margin:"10px 0px"},children:n}),e(R,{type:"submit",children:"Sign In"})]}),r(O,{children:["Don't have an account?"," ",e(X,{type:"button",onClick:()=>C(!1),children:"Sign Up"})]})]}):r(U,{children:[e(l,{children:"Create Account"}),r(E,{className:"no-spinner",onSubmit:v,children:[e(c,{type:"text",placeholder:"Name"}),e(c,{type:"text",placeholder:"Username"}),e(c,{type:"password",placeholder:"Password"}),e(c,{type:"number",placeholder:"Phone Number"}),e(R,{type:"submit",children:"Sign Up"})]}),r(O,{children:["Already have an account?"," ",e(X,{type:"button",onClick:()=>C(!0),children:"Sign In"})]})]}),e(w,{})]}),$=r(ce,{children:[e(de,{signinIn:o,children:r(N,{className:"no-spinner",onSubmit:v,children:[e(l,{children:"Create Account"}),e(a,{type:"text",placeholder:"Name"}),e(a,{type:"text",placeholder:"Username"}),e(a,{type:"password",placeholder:"Password"}),e(a,{type:"number",placeholder:"Phone Number"}),e(m,{children:"Sign Up"}),e(w,{})]})}),e(pe,{signinIn:o,children:r(N,{onSubmit:I,children:[e(u,{variant:"button",display:"block",gutterBottom:!0,style:{textAlign:"center",fontSize:"1.5rem"},children:"Huewine"}),e(l,{children:"Sign in"}),e(a,{type:"text",placeholder:"Username",name:"username",onChange:d}),e(a,{type:"password",autoComplete:"off",placeholder:"Password",name:"password",onChange:d}),n.length>0&&e(u,{style:{color:"red",margin:"10px 0px"},children:n}),e(m,{type:"submit",style:{marginTop:"10px"},children:"Sign In"}),e(w,{})]})}),e(ue,{signinIn:o,children:r(he,{signinIn:o,children:[r(ge,{signinIn:o,children:[e(l,{children:"Welcome Back!"}),e(F,{children:"To keep connected with us please login with your personal info"}),e(A,{onClick:()=>f(!0),children:"Sign In"})]}),r(me,{signinIn:o,children:[e(l,{children:"Hello, Friend!"}),e(F,{children:"Enter Your personal details and start a journey with us"}),e(A,{onClick:()=>f(!1),children:"Sign Up"})]})]})})]});return e(ie,{theme:B,children:e(ae,{display:"flex",justifyContent:"center",alignItems:"center",className:"loginpage",sx:{height:"100%",width:"100%",px:{xs:2,md:0},py:{xs:3,md:0}},children:j?_:$})})}export{ke as default};
