import{f as N,r as a,j as e}from"./index-BMcVAjQW.js";import{l as k}from"./logo-XDEmBYwz.js";import{s as r}from"./client-BVfsVemL.js";import{c as f}from"./createLucideIcon-7qXzago0.js";import{E as S}from"./eye-F1_964_T.js";import{A}from"./arrow-left-B2H7_Afe.js";const E=[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],L=f("eye-off",E);const M=[["circle",{cx:"12",cy:"16",r:"1",key:"1au0dj"}],["rect",{x:"3",y:"10",width:"18",height:"12",rx:"2",key:"6s8ecr"}],["path",{d:"M7 10V7a5 5 0 0 1 10 0v3",key:"1pqi11"}]],_=f("lock-keyhole",M),P="ozinpergam29@gmail.com";async function h(s){if(!s?.user||!((s.user.email??"").toLowerCase()===P.toLowerCase()))return!1;const{data:d}=await r.from("user_roles").select("role").eq("user_id",s.user.id).eq("role","admin").maybeSingle();return!!d}function z(){const s=N(),[l,d]=a.useState(""),[u,g]=a.useState(""),[i,w]=a.useState(!1),[p,c]=a.useState(!1),[b,y]=a.useState(!0),[x,m]=a.useState("");if(a.useEffect(()=>{let t=!0;return r.auth.getSession().then(async({data:{session:o}})=>{const n=await h(o);t&&(n?s({to:"/adminpergam"}):(o&&await r.auth.signOut(),y(!1)))}),()=>{t=!1}},[s]),b)return null;const j=async t=>{t.preventDefault(),m(""),c(!0);const{data:o,error:n}=await r.auth.signInWithPassword({email:l,password:u});if(n){c(!1),m(n.message);return}const v=await h(o.session);if(c(!1),!v){await r.auth.signOut(),m("Akun ini tidak memiliki izin admin.");return}s({to:"/adminpergam"})};return e.jsx("div",{className:"page-shell grid min-h-screen place-items-center px-4 py-12",children:e.jsxs("div",{className:"w-full max-w-md rounded-[2rem] border border-border bg-card/80 p-5 shadow-card backdrop-blur-2xl sm:p-8",children:[e.jsxs("div",{className:"mb-7 text-center",children:[e.jsx("div",{className:"mx-auto mb-4 grid h-16 w-16 shrink-0 place-items-center overflow-hidden",children:e.jsx("img",{src:k,alt:"Pergam Store",className:"h-full w-full object-contain drop-shadow-sm"})}),e.jsxs("div",{className:"mx-auto mb-3 inline-flex items-center gap-2 rounded-full border border-primary/20 bg-primary/10 px-3 py-1 text-xs font-bold text-primary",children:[e.jsx(_,{className:"h-3.5 w-3.5"}),"Secure Admin"]}),e.jsx("h1",{className:"font-display text-2xl font-bold text-foreground",children:"Admin Pergam Store"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Masuk untuk mengelola katalog"})]}),e.jsxs("form",{onSubmit:j,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs uppercase tracking-wider text-muted-foreground",children:"Email"}),e.jsx("input",{type:"email",required:!0,value:l,onChange:t=>d(t.target.value),className:"input mt-1",placeholder:"admin@pergam.store"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs uppercase tracking-wider text-muted-foreground",children:"Password"}),e.jsxs("div",{className:"relative mt-1",children:[e.jsx("input",{type:i?"text":"password",required:!0,value:u,onChange:t=>g(t.target.value),className:"input pr-12",placeholder:"••••••••"}),e.jsx("button",{type:"button",onClick:()=>w(!i),className:"absolute right-3 top-1/2 -translate-y-1/2 p-1.5 text-muted-foreground hover:text-primary transition-colors focus:outline-none","aria-label":i?"Hide password":"Show password",children:i?e.jsx(L,{className:"h-4 w-4"}):e.jsx(S,{className:"h-4 w-4"})})]})]}),x&&e.jsx("div",{className:"text-sm text-destructive bg-destructive/10 border border-destructive/30 rounded-xl px-4 py-2",children:x}),e.jsx("button",{type:"submit",disabled:p,className:"btn-primary w-full disabled:opacity-60",children:p?"Memproses...":"Masuk"})]}),e.jsx("div",{className:"mt-6 text-center",children:e.jsxs("a",{href:"/",className:"inline-flex items-center gap-1.5 text-xs font-bold text-muted-foreground hover:text-foreground",children:[e.jsx(A,{className:"h-3.5 w-3.5"}),"Kembali ke website"]})})]})})}export{z as component};
