import{u as g,j as s}from"./query-PJ0ZdjbV.js";import{a as j}from"./vendor-CWhr2lg4.js";import{p as y,s as f,t as A,v as N,w as v,x as o,I as d,B as n,z as T}from"./index-BSPIaiZU.js";import{B as E}from"./badge-C34iUAiA.js";import{P as _}from"./page-header-D8tSLbK0.js";import{D as C}from"./data-table-D_-xOEqd.js";import{A as L}from"./activity-BBaZC8Hc.js";import{C as O}from"./chevron-left-DLFf1YD2.js";import"./ui-aO-W1bxx.js";const S="/audit",D={logs:t=>["audit","logs",t],summary:["audit","summary"]};function I(t){return g({queryKey:D.logs(t),queryFn:()=>y.get(`${S}/logs/`,{params:t}).then(a=>a.data)})}const P={CREATE:"success",UPDATE:"default",DELETE:"destructive",LOGIN:"secondary",LOGOUT:"secondary",ACTIVATE:"success",DEACTIVATE:"warning",ASSIGN:"default",EXPORT:"outline",IMPORT:"outline",UPLOAD:"outline",DOWNLOAD:"outline",VIEW:"secondary"},w=["CREATE","UPDATE","DELETE","LOGIN","LOGOUT","ACTIVATE","DEACTIVATE","ASSIGN","EXPORT","IMPORT","UPLOAD","DOWNLOAD"];function M(){const[t,a]=j.useState({page:1}),{data:r,isLoading:m}=I(t),p=(r==null?void 0:r.results)??[],l=(r==null?void 0:r.count)??0,i=Math.ceil(l/20);function c(e,x){a(h=>({...h,[e]:x,page:1}))}const u=[{key:"user_display",header:"User",render:e=>s.jsxs("div",{children:[s.jsx("p",{className:"font-medium text-slate-800 text-[13px]",children:e.user_display}),e.ip_address&&s.jsx("p",{className:"text-[11px] text-slate-400 mt-0.5 font-mono",children:e.ip_address})]})},{key:"action",header:"Action",className:"w-32",render:e=>s.jsx(E,{variant:P[e.action]??"secondary",children:e.action_display})},{key:"resource_type",header:"Resource",className:"w-40",render:e=>s.jsxs("div",{children:[s.jsx("span",{className:"text-[12px] font-medium text-slate-700 capitalize",children:e.resource_type.replace(/_/g," ")}),e.resource_repr&&s.jsx("p",{className:"text-[11px] text-slate-400 truncate max-w-[140px]",children:e.resource_repr})]})},{key:"created_at",header:"Time",className:"w-44",render:e=>s.jsx("span",{className:"text-[12px] text-slate-500 tabular-nums",children:new Date(e.created_at).toLocaleString("en-GB",{day:"numeric",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"})})}];return s.jsxs("div",{children:[s.jsx(_,{title:"Audit Log",description:"Immutable record of all actions performed across the platform."}),s.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[s.jsxs(f,{value:t.action??"all",onValueChange:e=>c("action",e==="all"?void 0:e),children:[s.jsx(A,{className:"h-8 w-44 text-[13px]",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(L,{className:"h-3.5 w-3.5 text-slate-400"}),s.jsx(N,{placeholder:"All actions"})]})}),s.jsxs(v,{children:[s.jsx(o,{value:"all",children:"All actions"}),w.map(e=>s.jsx(o,{value:e,children:e.charAt(0)+e.slice(1).toLowerCase()},e))]})]}),s.jsx(d,{type:"date",value:t.date_from??"",onChange:e=>c("date_from",e.target.value||void 0),className:"h-8",placeholder:"From"}),s.jsx(d,{type:"date",value:t.date_to??"",onChange:e=>c("date_to",e.target.value||void 0),className:"h-8",placeholder:"To"}),(t.action||t.date_from||t.date_to)&&s.jsx(n,{variant:"ghost",size:"sm",className:"h-8 text-[12px] text-slate-500",onClick:()=>a({page:1}),children:"Clear filters"}),s.jsxs("span",{className:"ml-auto text-[12px] text-slate-400",children:[l.toLocaleString()," ",l===1?"entry":"entries"]})]}),s.jsx(C,{columns:u,data:p,isLoading:m,rowKey:e=>e.id,searchKeys:["user_email","resource_type","resource_repr"],searchPlaceholder:"Search by user or resource...",emptyMessage:"No audit entries",emptyDescription:"Actions performed in the platform will appear here."}),i>1&&s.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[s.jsxs("p",{className:"text-[12px] text-slate-500 tabular-nums",children:["Page ",t.page??1," of ",i]}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(n,{variant:"outline",size:"sm",className:"h-8 w-8 p-0",disabled:(t.page??1)<=1,onClick:()=>a(e=>({...e,page:(e.page??1)-1})),children:s.jsx(O,{className:"h-4 w-4"})}),s.jsx(n,{variant:"outline",size:"sm",className:"h-8 w-8 p-0",disabled:(t.page??1)>=i,onClick:()=>a(e=>({...e,page:(e.page??1)+1})),children:s.jsx(T,{className:"h-4 w-4"})})]})]})]})}export{M as AuditLogPage};
