import{p as v,r as d,j as e,f as x,a2 as y,al as S,am as E}from"./vendor-DyCecx-5.js";import{a as I,u as k}from"./index-BFnDPF9i.js";const R=()=>{const t=v(),{showToast:p}=k(),[o,w]=d.useState({email:"",password:""}),[m,N]=d.useState(!1),[u,f]=d.useState(!1),[g,l]=d.useState(""),b=n=>{w({...o,[n.target.name]:n.target.value}),l("")},j=async n=>{n.preventDefault(),f(!0),l("");try{const r=await I.login(o);if(r.success){const i=r.data,c=(i==null?void 0:i.data)||i,s=(c==null?void 0:c.user)||c;let a=s==null?void 0:s.role;typeof a=="string"&&(a=a.toUpperCase().trim()),a&&localStorage.setItem("user_role",a),s!=null&&s.name&&localStorage.setItem("user_name",s.name),p(`Welcome back, ${(s==null?void 0:s.name)||"User"}!`,"success"),setTimeout(()=>{switch(a){case"ADMIN":case"SUPER_ADMIN":t("/admin");break;case"HOTEL_OWNER":case"HOTEL_ADMIN":t("/hoteladmin");break;case"FRANCHISEE":case"FRANCHISE":t("/franchise/dashboard");break;default:const h=o.email.toLowerCase().trim();h==="admin@smart-hotel.com"?(localStorage.setItem("user_role","ADMIN"),t("/admin")):h==="hotel@smart-hotel.com"?(localStorage.setItem("user_role","HOTEL_OWNER"),t("/hoteladmin")):h==="franchise@smart-hotel.com"?(localStorage.setItem("user_role","FRANCHISEE"),t("/franchise/dashboard")):(localStorage.setItem("user_role","USER"),t("/customer"));break}},500)}else l(r.message||"Invalid email or password")}catch(r){l(r.message||"Something went wrong. Please try again.")}finally{f(!1)}};return e.jsx("div",{className:"min-h-screen bg-slate-50 flex items-center justify-center p-4",children:e.jsx("div",{className:"max-w-md w-full bg-white rounded-lg shadow-sm border border-slate-100 overflow-hidden",children:e.jsxs("div",{className:"p-8",children:[e.jsx("div",{className:"mb-8",children:e.jsxs(x,{to:"/",className:"group inline-flex items-center gap-3 px-8 py-3 bg-slate-900 text-white rounded-full font-bold text-xs uppercase tracking-[0.2em] shadow-lg shadow-slate-200 hover:bg-indigo-600 hover:shadow-2xl hover:shadow-indigo-200 hover:-translate-y-1 active:scale-95 transition-all duration-300 ease-out border border-slate-800 hover:border-indigo-400",children:[e.jsx(y,{className:"w-4 h-4 rotate-180 transition-transform duration-300 group-hover:-translate-x-1"}),e.jsx("span",{children:"Back to Home"})]})}),e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("h1",{className:"text-2xl font-bold text-slate-900 mb-2",children:"Welcome Back"}),e.jsx("p",{className:"text-slate-500 text-sm",children:"Sign in to access your account"})]}),g&&e.jsx("div",{className:"mb-6 p-3 bg-rose-50 border border-rose-100 rounded text-rose-600 text-xs font-bold",children:g}),e.jsxs("form",{onSubmit:j,className:"space-y-4 text-left",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"block text-sm font-bold text-slate-700",children:"Email Address"}),e.jsx("input",{type:"email",name:"email",value:o.email,onChange:b,required:!0,className:"w-full px-4 py-2 border border-slate-200 rounded text-sm focus:outline-none focus:ring-1 focus:ring-slate-900",placeholder:"john@example.com"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("label",{className:"block text-sm font-bold text-slate-700",children:"Password"}),e.jsx(x,{to:"/reset-password",className:"text-xs font-bold text-indigo-600 hover:text-indigo-700",children:"Forgot Password?"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:m?"text":"password",name:"password",value:o.password,onChange:b,required:!0,className:"w-full px-4 py-2 border border-slate-200 rounded text-sm focus:outline-none focus:ring-1 focus:ring-slate-900",placeholder:"••••••••"}),e.jsx("button",{type:"button",onClick:()=>N(!m),className:"absolute inset-y-0 right-0 pr-3 flex items-center text-slate-400 hover:text-slate-600",children:m?e.jsx(S,{className:"w-4 h-4"}):e.jsx(E,{className:"w-4 h-4"})})]})]}),e.jsx("button",{type:"submit",disabled:u,className:"w-full py-2.5 bg-slate-900 text-white rounded font-bold hover:bg-slate-800 disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2",children:u?"Signing in...":"Sign In"})]}),e.jsx("div",{className:"mt-8 text-center",children:e.jsxs("p",{className:"text-slate-500 font-medium",children:["Don't have an account?"," ",e.jsx(x,{to:"/signup",className:"text-indigo-600 font-bold hover:text-indigo-700",children:"Create Account"})]})})]})})})};export{R as default};
