%PDF- %PDF-
| Direktori : /home2/rezakur1/ai.rezakurnia.com/assets/ |
| Current File : //home2/rezakur1/ai.rezakurnia.com/assets/AdminUsersPage-CejAyFm3.js |
import{r as a,c as v,a as L,j as e}from"./index-CnB9nKbp.js";import{B as r}from"./Button-RaC0qoA7.js";import{C as P,d as U,e as R,c as $,a as C,g as q}from"./format-B8Won_Te.js";import{B as w}from"./Badge-CXRzVGa3.js";import{I as z}from"./Input-B7FggKMg.js";import{M as H}from"./Modal-BQ95Cl32.js";import"./index-BjE9Ehy3.js";function I(){const[l,f]=a.useState([]),[c,m]=a.useState(!0),[j,o]=a.useState(null),[d,g]=a.useState(0),i=a.useCallback(()=>g(n=>n+1),[]);a.useEffect(()=>{let n=!1;return m(!0),v("/admin/users?days=30").then(t=>{n||(f(t.users),o(null))}).catch(t=>{n||o(t.message)}).finally(()=>{n||m(!1)}),()=>{n=!0}},[d]);const x=a.useCallback(async(n,t)=>{const h=`/admin/users/${n}/${t?"reactivate":"suspend"}`;await v(h,{method:"POST"}),i()},[i]),b=a.useCallback(async n=>{await v(`/admin/users/${n}`,{method:"DELETE"}),i()},[i]);return{users:l,loading:c,error:j,refresh:i,setActive:x,removeUser:b}}function Y(){const{users:l,loading:f,error:c,setActive:m,removeUser:j}=I(),o=L(),[d,g]=a.useState(""),[i,x]=a.useState(null),[b,n]=a.useState(!1),[t,h]=a.useState(null),[k,N]=a.useState(""),[y,S]=a.useState(!1),[A,u]=a.useState(null),D=async()=>{if(t){S(!0),u(null);try{await j(t.id),n(!1),h(null),N("")}catch(s){u(s instanceof Error?s.message:"Gagal menghapus akun"),S(!1)}}},B=s=>{h(s),N(""),u(null),n(!0)},E=a.useMemo(()=>{const s=d.trim().toLowerCase();return s?l.filter(p=>p.email.toLowerCase().includes(s)||p.name.toLowerCase().includes(s)):l},[l,d]),_=async s=>{x(s.id);try{await m(s.id,s.is_active!==1)}catch{}finally{x(null)}};return e.jsxs(e.Fragment,{children:[e.jsxs(P,{children:[e.jsx(U,{title:"Daftar Pengguna",subtitle:"Akun & pemakaian 30 hari terakhir",action:e.jsx("input",{type:"search",placeholder:"Cari nama / email…",value:d,onChange:s=>g(s.target.value),className:"input-solid w-56"})}),e.jsxs(R,{className:"p-0",children:[c&&e.jsxs("div",{className:"p-5 text-sm text-red-300",children:["Gagal memuat: ",c]}),f?e.jsx("div",{className:"space-y-3 p-5",children:[...Array(3)].map((s,p)=>e.jsx("div",{className:"h-16 animate-pulse rounded-xl bg-white/[0.02]"},p))}):E.length===0?e.jsx("div",{className:"px-5 py-10 text-center text-sm text-slate-500",children:"Tidak ada pengguna yang cocok."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[820px] text-left text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-white/[0.06] bg-white/[0.02] text-[11px] uppercase tracking-wider text-slate-500",children:[e.jsx("th",{className:"px-5 py-3 font-semibold",children:"Pengguna"}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold",children:"Saldo"}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold",children:"Requests"}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold",children:"Input"}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold",children:"Cached"}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold",children:"Output"}),e.jsx("th",{className:"px-4 py-3 font-semibold",children:"Status"}),e.jsx("th",{className:"px-4 py-3 font-semibold",children:"Terdaftar"}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold",children:"Aksi"})]})}),e.jsx("tbody",{children:E.map(s=>e.jsxs("tr",{className:"border-b border-white/[0.04] transition-colors last:border-0 hover:bg-white/[0.02]",children:[e.jsx("td",{className:"px-5 py-3.5",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-ink-700 text-xs font-semibold text-white",children:s.name.charAt(0).toUpperCase()}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"flex items-center gap-2 font-medium text-white",children:[s.name,Number(s.is_admin)===1&&e.jsx(w,{tone:"info",children:"Admin"})]}),e.jsx("p",{className:"truncate text-xs text-slate-500",children:s.email})]})]})}),e.jsx("td",{className:"px-4 py-3.5 text-right font-medium tabular-nums text-slate-300",children:$(s.balance)}),e.jsx("td",{className:"px-4 py-3.5 text-right font-medium tabular-nums text-slate-300",children:s.requests}),e.jsx("td",{className:"px-4 py-3.5 text-right font-medium tabular-nums text-slate-400",children:C(s.input_tokens)}),e.jsx("td",{className:"px-4 py-3.5 text-right font-medium tabular-nums text-slate-500",children:C(s.cached_tokens)}),e.jsx("td",{className:"px-4 py-3.5 text-right font-medium tabular-nums text-slate-400",children:C(s.output_tokens)}),e.jsx("td",{className:"px-4 py-3.5",children:Number(s.is_active)===1?e.jsx(w,{tone:"success",children:"Aktif"}):e.jsx(w,{tone:"danger",children:"Suspend"})}),e.jsx("td",{className:"px-4 py-3.5 text-xs tabular-nums text-slate-500",children:q(s.created_at)}),e.jsx("td",{className:"px-5 py-3.5 text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(r,{variant:"ghost",size:"sm",onClick:()=>o(`/admin/analytics?user=${s.id}`),children:"Analisa"}),Number(s.is_admin)===1?e.jsx("span",{className:"text-xs text-slate-600",children:"—"}):Number(s.is_active)===1?e.jsx(r,{variant:"danger",size:"sm",isLoading:i===s.id,onClick:()=>_(s),children:"Suspend"}):e.jsx(r,{variant:"ghost",size:"sm",isLoading:i===s.id,onClick:()=>_(s),children:"Reaktivasi"}),Number(s.is_admin)!==1&&e.jsx(r,{variant:"subtle",size:"sm",onClick:()=>B(s),className:"text-red-400 hover:bg-red-500/10 hover:text-red-300",children:"Hapus"})]})})]},s.id))})]})})]})]}),e.jsx(H,{open:b,onClose:()=>{y||n(!1)},title:"Hapus Akun Permanen",subtitle:"Tindakan ini tidak dapat dibatalkan",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-xl border border-red-500/25 bg-red-500/10 px-4 py-3 text-xs leading-relaxed text-red-300",children:["Anda akan ",e.jsx("strong",{children:"menghapus permanen"})," akun"," ",e.jsx("strong",{children:t==null?void 0:t.name})," (",e.jsx("strong",{children:t==null?void 0:t.email}),"). Semua data akan hilang: saldo, transaksi, API key, riwayat pemakaian, paket, dan sesi. Tindakan ini tidak bisa dikembalikan."]}),e.jsx(z,{label:`Ketik email untuk konfirmasi: ${(t==null?void 0:t.email)??""}`,value:k,onChange:s=>{N(s.target.value),u(null)},placeholder:(t==null?void 0:t.email)??"",autoFocus:!0}),A&&e.jsx("p",{className:"text-xs font-medium text-red-400",children:A}),e.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[e.jsx(r,{variant:"ghost",onClick:()=>n(!1),disabled:y,children:"Batal"}),e.jsx(r,{variant:"danger",isLoading:y,disabled:k.trim()!==(t==null?void 0:t.email),onClick:D,children:"Ya, Hapus Permanen"})]}),k.trim()!==(t==null?void 0:t.email)&&e.jsx("p",{className:"text-right text-[11px] text-slate-500",children:"Ketik email lengkap untuk mengaktifkan tombol."})]})})]})}export{Y as default};