import{f as w,r as t,j as e,L as v}from"./index-BMcVAjQW.js";import{s as i}from"./client-BVfsVemL.js";import{c as x}from"./createLucideIcon-7qXzago0.js";import{A as S}from"./arrow-right-C3xybamR.js";import{S as A}from"./shield-check-DO8Zc_vn.js";const E=[["path",{d:"M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z",key:"3c2336"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],_=x("badge-check",E);const C=[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]],L=x("circle-check-big",C);function q(){const p=w(),[h,g]=t.useState(!0),[f,k]=t.useState(!1),[n]=t.useState("ozinpergam29@gmail.com"),[m,b]=t.useState("Ozin 1234"),[l,s]=t.useState(!1),[d,r]=t.useState(""),[j,N]=t.useState(!1);t.useEffect(()=>{(async()=>{const{count:a}=await i.from("user_roles").select("*",{count:"exact",head:!0}).eq("role","admin");k((a??0)>0),g(!1)})()},[]);const y=async a=>{a.preventDefault(),r(""),s(!0);const{data:o,error:c}=await i.auth.signUp({email:n,password:m,options:{emailRedirectTo:`${window.location.origin}/admin/login`}});if(c||!o.user){s(!1),r(c?.message??"Gagal membuat akun");return}const{error:u}=await i.from("user_roles").insert({user_id:o.user.id,role:"admin"});if(s(!1),u){r("Akun dibuat tapi role gagal disetel: "+u.message);return}N(!0),setTimeout(()=>p({to:"/admin/login"}),2e3)};return h?e.jsx("div",{className:"min-h-screen grid place-items-center text-sm text-muted-foreground",children:"Memeriksa..."}):f?e.jsx("div",{className:"min-h-screen grid place-items-center px-4",children:e.jsxs("div",{className:"card-surface rounded-3xl p-8 max-w-md text-center",children:[e.jsx(L,{className:"mx-auto mb-3 h-11 w-11 text-primary/80",strokeWidth:1.8}),e.jsx("h1",{className:"font-display font-bold text-xl",children:"Setup sudah selesai"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:"Admin sudah aktif di sistem. Silakan langsung login dengan email admin yang sudah ditentukan. Halaman setup ini terkunci untuk keamanan."}),e.jsxs(v,{to:"/admin/login",className:"group mt-5 inline-flex items-center gap-2 px-5 py-2.5 rounded-full bg-primary text-primary-foreground text-sm font-semibold",children:["Ke Halaman Login",e.jsx(S,{className:"h-4 w-4 transition-transform group-hover:translate-x-0.5"})]})]})}):j?e.jsx("div",{className:"min-h-screen grid place-items-center px-4",children:e.jsxs("div",{className:"card-surface rounded-3xl p-8 max-w-md text-center glow-purple-sm",children:[e.jsx(_,{className:"mx-auto mb-3 h-11 w-11 text-primary/80",strokeWidth:1.8}),e.jsx("h1",{className:"font-display font-bold text-xl",children:"Admin berhasil dibuat!"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:"Mengarahkan ke halaman login..."})]})}):e.jsx("div",{className:"min-h-screen grid place-items-center px-4 py-12",children:e.jsxs("div",{className:"w-full max-w-md card-surface rounded-3xl p-8 glow-purple-sm",children:[e.jsxs("div",{className:"text-center mb-6",children:[e.jsx(A,{className:"mx-auto mb-2 h-10 w-10 text-primary/80",strokeWidth:1.8}),e.jsx("h1",{className:"font-display text-2xl font-bold",children:"Setup Admin Pertama"}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-2",children:["Buat akun admin pertama untuk mengelola Pergam Store. Email admin sudah dikunci ke"," ",e.jsx("strong",{children:"ozinpergam29@gmail.com"}),". Halaman ini akan terkunci otomatis setelah admin berhasil dibuat."]})]}),e.jsxs("form",{onSubmit:y,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:n,readOnly:!0,className:"input mt-1 opacity-70 cursor-not-allowed"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs uppercase tracking-wider text-muted-foreground",children:"Password (min 6 karakter)"}),e.jsx("input",{type:"password",required:!0,minLength:6,value:m,onChange:a=>b(a.target.value),className:"input mt-1"})]}),d&&e.jsx("div",{className:"text-sm text-destructive bg-destructive/10 border border-destructive/30 rounded-xl px-4 py-2",children:d}),e.jsx("button",{disabled:l,className:"w-full py-3 rounded-full bg-primary text-primary-foreground font-semibold glow-purple-sm disabled:opacity-60",children:l?"Memproses...":"Buat Admin & Mulai"})]})]})})}export{q as component};
