import{r as n,g as c,y as r,j as e}from"./index-HUEYA8gO.js";function N(){const[o,d]=n.useState(""),[p,m]=n.useState(!1),[a,u]=n.useState(null),[i,h]=n.useState(null),[x,g]=n.useState(!0);n.useEffect(()=>{b()},[]);const b=async()=>{try{const s=await(await fetch(c("/impersonate.php"),{method:"GET",credentials:"include"})).json();s.success?(m(s.data.is_impersonating),u(s.data.current_user),h(s.data.original_admin)):r.error(s.error||"Failed to check impersonation status")}catch(t){console.error("Error checking impersonation status:",t),r.error("Failed to check impersonation status")}finally{g(!1)}},f=async t=>{if(t.preventDefault(),!o.trim()){r.error("Please enter a username");return}try{const l=await(await fetch(c("/impersonate.php"),{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:o.trim()})})).json();if(l.success){r.success(`Now impersonating ${o}`);try{window.open("/dashboard","_blank")}catch{}setTimeout(()=>{try{window.location.reload()}catch{}},300)}else r.error(l.error||"Failed to impersonate user")}catch(s){console.error("Error impersonating user:",s),r.error("Failed to impersonate user")}},y=async()=>{try{const s=await(await fetch(c("/impersonate.php"),{method:"DELETE",credentials:"include"})).json();s.success?(r.success("Stopped impersonating user"),window.location.reload()):r.error(s.error||"Failed to stop impersonation")}catch(t){console.error("Error stopping impersonation:",t),r.error("Failed to stop impersonation")}};return x?e.jsxs("section",{className:"py-8",children:[e.jsx("h2",{className:"text-3xl font-extrabold mb-6 text-accent",children:"Impersonate User"}),e.jsx("div",{className:"bg-gray-900/80 rounded-2xl p-6 shadow-xl text-center",children:e.jsx("p",{className:"text-gray-400",children:"Loading impersonation status..."})})]}):e.jsxs("section",{className:"py-8",children:[e.jsx("h2",{className:"text-3xl font-extrabold mb-6 text-accent",children:"Impersonate User"}),e.jsxs("div",{className:"bg-gray-900/80 rounded-2xl p-6 shadow-xl",children:[e.jsx("p",{className:"text-gray-400 mb-4",children:"Temporarily act as a user for troubleshooting or support."}),p?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"bg-gray-800/80 p-4 rounded-xl",children:[e.jsx("h3",{className:"text-accent font-bold mb-2",children:"Currently Impersonating"}),e.jsxs("p",{className:"text-gray-300",children:[e.jsx("span",{className:"font-semibold",children:"User:"})," ",a==null?void 0:a.username," (ID: ",a==null?void 0:a.id,")"]}),e.jsxs("p",{className:"text-gray-300",children:[e.jsx("span",{className:"font-semibold",children:"Original Admin:"})," ",i==null?void 0:i.username]})]}),e.jsx("button",{onClick:y,className:"bg-red-600 text-white font-bold px-4 py-2 rounded-lg shadow hover:bg-red-700 transition w-full md:w-auto",children:"Stop Impersonating"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("form",{onSubmit:f,className:"mb-4 flex flex-col md:flex-row gap-4",children:[e.jsx("input",{type:"text",value:o,onChange:t=>d(t.target.value),className:"flex-1 rounded-lg px-3 py-2 bg-gray-800 text-white border border-accent/40 focus:outline-accent",placeholder:"Enter username...",required:!0}),e.jsx("button",{type:"submit",className:"bg-accent text-gray-900 font-bold px-4 py-2 rounded-lg shadow hover:bg-sui transition",children:"Impersonate"})]}),e.jsxs("div",{className:"bg-gray-800/80 p-4 rounded-xl text-gray-300",children:[e.jsx("p",{className:"font-semibold text-accent",children:"Note:"}),e.jsx("p",{className:"text-sm",children:'You will be able to navigate the site as the selected user. To stop impersonating, use the "Stop Impersonating" button that will appear.'})]})]})]})]})}export{N as default};
