import{r as s,j as e,g as p}from"./index-HUEYA8gO.js";function P(){const[c,b]=s.useState([]),[v,o]=s.useState(!0),[x,r]=s.useState(""),[i,m]=s.useState(""),[a,N]=s.useState(1),[h,y]=s.useState(25),[g,f]=s.useState(0);async function l(t=a,u=i){o(!0),r("");try{const n=new URL(p("/admin_get_registration_audit.php"),window.location.origin);n.searchParams.set("page",String(t)),n.searchParams.set("limit",String(h)),u&&n.searchParams.set("q",u);const d=await(await fetch(n.toString(),{credentials:"include"})).json();d.success?(b(d.items||[]),f(d.total||0),N(d.page||1)):r(d.error||"Failed to load audit")}catch{r("Network error")}finally{o(!1)}}s.useEffect(()=>{l(1,"")},[]);const j=Math.max(1,Math.ceil(g/h));return e.jsxs("section",{className:"py-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h2",{className:"text-2xl font-bold text-accent",children:"Registration Audit"}),e.jsx("a",{href:p("/admin_download_registration_log.php"),className:"px-4 py-2 bg-slate-700 hover:bg-slate-600 rounded-lg text-white",children:"Download Raw .txt"})]}),e.jsxs("div",{className:"flex gap-2 mb-4",children:[e.jsx("input",{className:"input text-black flex-1",placeholder:"Search name, username, email, IP, location",value:i,onChange:t=>m(t.target.value)}),e.jsx("button",{onClick:()=>l(1,i),className:"btn btn-accent",children:"Search"}),e.jsx("button",{onClick:()=>{m(""),l(1,"")},className:"btn btn-gray",children:"Reset"})]}),v?e.jsx("div",{className:"text-accent",children:"Loading..."}):x?e.jsx("div",{className:"text-red-500",children:x}):e.jsxs("div",{className:"bg-gray-900 rounded-xl border border-slate-700 overflow-hidden",children:[e.jsxs("div",{className:"grid grid-cols-7 gap-2 px-3 py-2 text-sm text-slate-400 border-b border-slate-700",children:[e.jsx("div",{children:"Date"}),e.jsx("div",{children:"User ID"}),e.jsx("div",{children:"Name"}),e.jsx("div",{children:"Username"}),e.jsx("div",{children:"Email"}),e.jsx("div",{children:"IP"}),e.jsx("div",{children:"Location"})]}),c.length===0?e.jsx("div",{className:"p-4 text-slate-400",children:"No records"}):c.map(t=>e.jsxs("div",{className:"grid grid-cols-7 gap-2 px-3 py-2 border-b border-slate-800 text-sm",children:[e.jsx("div",{className:"text-slate-300",children:new Date(t.created_at).toLocaleString()}),e.jsxs("div",{children:["#",t.user_id]}),e.jsx("div",{children:t.name||"-"}),e.jsx("div",{children:t.username||"-"}),e.jsx("div",{children:t.email||"-"}),e.jsx("div",{children:t.ip_address||"-"}),e.jsx("div",{children:t.location||"-"})]},t.id))]}),e.jsxs("div",{className:"flex items-center justify-between mt-4",children:[e.jsxs("div",{className:"text-sm text-slate-400",children:["Total: ",g]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{disabled:a<=1,onClick:()=>l(a-1,i),className:"px-3 py-1 bg-slate-800 text-white rounded disabled:opacity-50",children:"Prev"}),e.jsxs("span",{className:"text-slate-300 text-sm",children:["Page ",a," / ",j]}),e.jsx("button",{disabled:a>=j,onClick:()=>l(a+1,i),className:"px-3 py-1 bg-slate-800 text-white rounded disabled:opacity-50",children:"Next"})]})]})]})}export{P as default};
