import{c as j,j as e}from"./index-D9pJRAs5.js";import{r}from"./vendor-D6aTFYy9.js";import{a2 as v}from"./ui-CtYVlq7P.js";import"./pdf-Bz_mU5mG.js";const w=()=>{const{auditLogs:c,users:x}=j(),[a,o]=r.useState(""),[s,m]=r.useState("all"),[l,p]=r.useState("all"),[d,g]=r.useState(""),n=r.useMemo(()=>c.filter(t=>{const i=t.details.toLowerCase().includes(a.toLowerCase())||t.entity.toLowerCase().includes(a.toLowerCase())||t.userName.toLowerCase().includes(a.toLowerCase()),u=s==="all"||t.userId===s,y=l==="all"||t.action===l,h=!d||new Date(t.timestamp).toLocaleDateString()===new Date(d+"T00:00:00").toLocaleDateString();return i&&u&&y&&h}).sort((t,i)=>new Date(i.timestamp).getTime()-new Date(t.timestamp).getTime()),[c,a,s,l,d]);return e.jsxs("div",{className:"space-y-6",children:[e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"Audit Trail"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Track all significant activities and changes within the system."}),e.jsx("div",{className:"p-4 bg-gray-50 dark:bg-gray-700/50 rounded-lg border dark:border-gray-700",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(v,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-5 w-5 text-gray-400"}),e.jsx("input",{type:"text",placeholder:"Search logs...",value:a,onChange:t=>o(t.target.value),className:"w-full pl-10 pr-4 py-2 border rounded-lg dark:bg-gray-700 dark:border-gray-600"})]}),e.jsx("div",{children:e.jsxs("select",{value:s,onChange:t=>m(t.target.value),className:"w-full p-2 border rounded-lg dark:bg-gray-700 dark:border-gray-600",children:[e.jsx("option",{value:"all",children:"All Users"}),x.map(t=>e.jsx("option",{value:t.id,children:t.name},t.id))]})}),e.jsx("div",{children:e.jsxs("select",{value:l,onChange:t=>p(t.target.value),className:"w-full p-2 border rounded-lg dark:bg-gray-700 dark:border-gray-600",children:[e.jsx("option",{value:"all",children:"All Actions"}),e.jsx("option",{value:"create",children:"Create"}),e.jsx("option",{value:"update",children:"Update"}),e.jsx("option",{value:"delete",children:"Delete"}),e.jsx("option",{value:"login",children:"Login"})]})}),e.jsx("div",{children:e.jsx("input",{type:"date",value:d,onChange:t=>g(t.target.value),className:"w-full p-2 border rounded-lg dark:bg-gray-700 dark:border-gray-600"})})]})}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full divide-y divide-gray-200 dark:divide-gray-700",children:[e.jsx("thead",{className:"bg-gray-50 dark:bg-gray-700",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase",children:"Timestamp"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase",children:"User"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase",children:"Action"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase",children:"Entity"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase",children:"Details"})]})}),e.jsx("tbody",{className:"bg-white dark:bg-gray-800 divide-y divide-gray-200 dark:divide-gray-700",children:n.map(t=>e.jsxs("tr",{children:[e.jsx("td",{className:"px-6 py-4 text-sm text-gray-500 dark:text-gray-400",children:new Date(t.timestamp).toLocaleString()}),e.jsx("td",{className:"px-6 py-4 text-sm font-medium text-gray-900 dark:text-white",children:t.userName}),e.jsx("td",{className:"px-6 py-4",children:e.jsx("span",{className:`px-2 py-1 text-xs font-medium rounded-full capitalize ${t.action==="create"?"bg-green-100 text-green-800":t.action==="update"?"bg-yellow-100 text-yellow-800":t.action==="delete"?"bg-red-100 text-red-800":"bg-blue-100 text-blue-800"}`,children:t.action})}),e.jsxs("td",{className:"px-6 py-4 text-sm text-gray-900 dark:text-gray-300",children:[t.entity," (#",t.entityId.slice(0,8),"...)"]}),e.jsx("td",{className:"px-6 py-4 text-sm text-gray-600 dark:text-gray-400",children:t.details})]},t.id))})]})}),n.length===0&&e.jsx("p",{className:"text-center py-8 text-gray-500 dark:text-gray-400",children:"No logs found for the selected filters."})]})};export{w as default};
