(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[928],{6279:function(e,t,a){Promise.resolve().then(a.bind(a,1042))},1042:function(e,t,a){"use strict";a.r(t);var s=a(7437),l=a(2265);t.default=function(){let[e,t]=(0,l.useState)([]),[a,n]=(0,l.useState)([]),[r,d]=(0,l.useState)(""),[i,c]=(0,l.useState)(""),[o,u]=(0,l.useState)(""),[h,m]=(0,l.useState)("Staff"),[p,x]=(0,l.useState)("");(0,l.useEffect)(()=>{(async function(){try{let e=await fetch("/api/admins"),a=await e.json();t(a.admins),n(a.admins)}catch(e){x("Failed to fetch data")}})()},[]),(0,l.useEffect)(()=>{n(e.filter(e=>e.name.toLowerCase().includes(r.toLowerCase())||e.email.toLowerCase().includes(r.toLowerCase())))},[r,e]);let f=async a=>{a.preventDefault();try{let a=await fetch("/api/admins",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:i,email:o,role:h})}),s=await a.json();t([...e,s]),c(""),u(""),m("Staff"),x("")}catch(e){x("Error adding admin")}};return(0,s.jsxs)("div",{className:"p-8 bg-white shadow-md rounded-lg text-black",children:[(0,s.jsx)("h1",{className:"text-2xl font-bold mb-6",children:"Admin Management"}),(0,s.jsx)("input",{type:"text",placeholder:"Search admins...",className:"border p-2 rounded w-full mb-6",onChange:e=>d(e.target.value)}),p&&(0,s.jsx)("div",{className:"bg-red-100 text-red-700 p-3 rounded mb-5",children:p}),(0,s.jsxs)("form",{onSubmit:f,className:"grid grid-cols-3 gap-4 mb-4",children:[(0,s.jsx)("input",{type:"text",value:i,onChange:e=>c(e.target.value),placeholder:"Name",className:"border p-2 rounded"}),(0,s.jsx)("input",{type:"email",value:o,onChange:e=>u(e.target.value),placeholder:"Email",className:"border p-2 rounded"}),(0,s.jsxs)("select",{value:h,onChange:e=>m(e.target.value),className:"border p-2 rounded",children:[(0,s.jsx)("option",{value:"Staff",children:"Staff"}),(0,s.jsx)("option",{value:"Administrator",children:"Administrator"}),(0,s.jsx)("option",{value:"Supervisor",children:"Supervisor"})]}),(0,s.jsx)("button",{type:"submit",className:"col-span-3 bg-blue-500 text-white px-6 py-2 rounded hover:bg-blue-600",children:"Add Admin"})]}),(0,s.jsx)("div",{className:"overflow-x-auto",children:(0,s.jsxs)("table",{className:"w-full",children:[(0,s.jsx)("thead",{className:"bg-gray-100",children:(0,s.jsxs)("tr",{children:[(0,s.jsx)("th",{className:"text-left p-4",children:"Name"}),(0,s.jsx)("th",{className:"text-left p-4",children:"Email"}),(0,s.jsx)("th",{className:"text-left p-4",children:"Role"}),(0,s.jsx)("th",{className:"text-left p-4",children:"Actions"})]})}),(0,s.jsx)("tbody",{children:a.map((e,t)=>(0,s.jsxs)("tr",{className:"border-t",children:[(0,s.jsx)("td",{className:"p-4",children:e.name}),(0,s.jsx)("td",{className:"p-4",children:e.email}),(0,s.jsx)("td",{className:"p-4",children:e.role}),(0,s.jsxs)("td",{className:"p-4",children:[(0,s.jsx)("button",{className:"bg-red-500 text-white px-4 py-1 rounded hover:bg-red-600 mr-2",children:"Disable"}),(0,s.jsx)("button",{className:"bg-green-500 text-white px-4 py-1 rounded hover:bg-green-600",children:"Edit"})]})]},t))})]})})]})}}},function(e){e.O(0,[971,69,744],function(){return e(e.s=6279)}),_N_E=e.O()}]);