import{r as s,j as e,L as N}from"./index-BMcVAjQW.js";import{s as n}from"./client-BVfsVemL.js";function w(){const[l,b]=s.useState([]),[h,j]=s.useState(!0),[a,o]=s.useState(""),[m,u]=s.useState(""),[c,d]=s.useState(!1),[i,r]=s.useState(null),x=async()=>{const{data:t}=await n.from("user_roles").select("*").eq("role","admin").order("created_at",{ascending:!1});b(t??[]),j(!1)};s.useEffect(()=>{x()},[]);const y=async t=>{t.preventDefault(),r(null),d(!0);const{data:p,error:g}=await n.auth.signUp({email:a,password:m,options:{emailRedirectTo:`${window.location.origin}/admin/login`}});if(g||!p.user){d(!1),r({type:"err",text:g?.message??"Gagal membuat akun"});return}const{error:f}=await n.from("user_roles").insert({user_id:p.user.id,role:"admin"});if(d(!1),f){r({type:"err",text:"Akun dibuat tapi role gagal: "+f.message});return}r({type:"ok",text:`Admin baru ditambahkan: ${a}. Email konfirmasi mungkin perlu diaktifkan.`}),o(""),u(""),x()};return e.jsxs("div",{children:[e.jsx(N,{to:"/adminpergam",className:"text-xs text-muted-foreground hover:text-foreground",children:"← Kembali"}),e.jsx("h1",{className:"font-display text-3xl font-bold mt-2 mb-6",children:"Akun Admin"}),e.jsxs("div",{className:"grid lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"card-surface rounded-2xl p-6",children:[e.jsx("h2",{className:"font-display font-bold text-lg mb-4",children:"Tambah Admin Baru"}),e.jsxs("form",{onSubmit:y,className:"space-y-3",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:a,onChange:t=>o(t.target.value),className:"input mt-1"})]}),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:t=>u(t.target.value),className:"input mt-1"})]}),i&&e.jsx("div",{className:`text-sm rounded-xl px-4 py-2 ${i.type==="ok"?"bg-primary/10 text-primary-glow border border-primary/30":"bg-destructive/10 text-destructive border border-destructive/30"}`,children:i.text}),e.jsx("button",{disabled:c,className:"px-5 py-2.5 rounded-full bg-primary text-primary-foreground text-sm font-semibold disabled:opacity-60",children:c?"Memproses...":"Tambah Admin"})]})]}),e.jsxs("div",{className:"card-surface rounded-2xl p-6",children:[e.jsx("h2",{className:"font-display font-bold text-lg mb-4",children:"Daftar Admin Aktif"}),h?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Memuat..."}):l.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Belum ada admin."}):e.jsx("ul",{className:"space-y-2",children:l.map(t=>e.jsxs("li",{className:"flex items-center justify-between p-3 rounded-xl bg-muted/30 border border-border",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"text-xs font-mono text-muted-foreground",children:[t.user_id.slice(0,8),"..."]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground mt-0.5",children:["Sejak ",new Date(t.created_at).toLocaleDateString("id-ID")]})]}),e.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded-full bg-primary/15 text-primary border border-primary/30",children:"admin"})]},t.id))})]})]})]})}export{w as component};
