import{a as N,j as e}from"./api.IptZkPtc.js";import{r as t}from"./index.DC1_V0l1.js";const g={"auth.login":"Inicio de sesión","auth.logout":"Cierre de sesión","usuario.crear":"Crear usuario","usuario.actualizar":"Actualizar usuario","usuario.desactivar":"Desactivar usuario","usuario.restablecer_contrasena":"Restablecer contraseña","empresa.crear":"Crear empresa","empresa.actualizar":"Actualizar empresa","empresa.desactivar":"Desactivar empresa"};function f(r){return new Date(r).toLocaleString("es-CL",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"})}function C(){const[r,p]=t.useState([]),[d,j]=t.useState(0),[s,c]=t.useState(1),[b,o]=t.useState(!0),[x,u]=t.useState(""),[i,y]=t.useState(""),h=50,m=t.useCallback(async()=>{o(!0),u("");try{const a=new URLSearchParams({pagina:String(s),por_pagina:String(h)});i&&a.set("accion",i);const n=await N.get(`/auditoria?${a}`);p(n.datos),j(n.total)}catch(a){u(a instanceof Error?a.message:"Error al cargar auditoría")}finally{o(!1)}},[s,i]);t.useEffect(()=>{m()},[m]);const l=Math.ceil(d/h);return e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap gap-3 mb-4 items-center justify-between",children:[e.jsxs("select",{value:i,onChange:a=>{y(a.currentTarget.value),c(1)},className:"input w-auto text-sm",children:[e.jsx("option",{value:"",children:"Todas las acciones"}),Object.entries(g).map(([a,n])=>e.jsx("option",{value:a,children:n},a))]}),e.jsxs("span",{className:"text-sm text-gray-500",children:[d," registros"]})]}),x&&e.jsx("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-lg text-sm text-red-700",children:x}),e.jsx("div",{className:"table-container",children:e.jsxs("table",{className:"table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Fecha"}),e.jsx("th",{children:"Acción"}),e.jsx("th",{className:"hidden sm:table-cell",children:"Usuario ID"}),e.jsx("th",{className:"hidden md:table-cell",children:"Entidad"}),e.jsx("th",{className:"hidden lg:table-cell",children:"IP"})]})}),e.jsx("tbody",{children:b?e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"text-center py-10 text-gray-400",children:"Cargando..."})}):r.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"text-center py-10 text-gray-400",children:"No hay registros"})}):r.map(a=>e.jsxs("tr",{children:[e.jsx("td",{className:"text-xs text-gray-500 whitespace-nowrap",children:f(a.creado_en)}),e.jsx("td",{children:e.jsx("span",{className:"badge badge-info text-xs",children:g[a.accion]||a.accion})}),e.jsxs("td",{className:"hidden sm:table-cell text-gray-600 text-sm",children:["#",a.usuario_id??"—"]}),e.jsx("td",{className:"hidden md:table-cell text-gray-600 text-sm",children:a.entidad_tipo?`${a.entidad_tipo} #${a.entidad_id}`:"—"}),e.jsx("td",{className:"hidden lg:table-cell text-gray-400 text-xs font-mono",children:a.ip_origen||"—"})]},a.id))})]})}),l>1&&e.jsxs("div",{className:"flex items-center justify-between mt-4 text-sm text-gray-600",children:[e.jsxs("span",{children:["Página ",s," de ",l]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{disabled:s===1,onClick:()=>c(a=>a-1),className:"btn-secondary py-1 px-3 text-xs disabled:opacity-50",children:"← Anterior"}),e.jsx("button",{disabled:s===l,onClick:()=>c(a=>a+1),className:"btn-secondary py-1 px-3 text-xs disabled:opacity-50",children:"Siguiente →"})]})]})]})}export{C as default};
