import{o as _,a as C,j as e}from"./api.IptZkPtc.js";import{r as t}from"./index.DC1_V0l1.js";import{a as w,d as T}from"./tipos.BUIEL7Hd.js";function O(s){if(!s)return e.jsx("span",{className:"badge badge-gray",children:"Sin clasificar"});const l={alto:"badge-danger",mediano:"badge-warning",bajo:"badge-success"},r={alto:"Alto",mediano:"Mediano",bajo:"Bajo"};return e.jsx("span",{className:`badge ${l[s]}`,children:r[s]})}function P(s){const l=s,r=T[l]??"badge-gray",d=w[l]??s;return e.jsx("span",{className:`badge ${r}`,children:d})}function y(s){const[l,r,d]=s.split("-");return`${d}/${r}/${l}`}const $=[{value:"",label:"Todos los estados"},{value:"no_iniciado",label:"No iniciado"},{value:"en_proceso",label:"En proceso"},{value:"en_revision",label:"En revisión"},{value:"pendiente_aprobacion",label:"Pend. aprobación"},{value:"completa",label:"Completa"},{value:"anulada",label:"Anulada"}];function R(){const[s,l]=t.useState(null);t.useEffect(()=>{l(_())},[]);const[r,d]=t.useState([]),[n,E]=t.useState(0),[i,x]=t.useState(1),o=20,[h,b]=t.useState(!0),[g,j]=t.useState(null),[m,S]=t.useState(""),p=t.useCallback(async(a,f)=>{b(!0),j(null);try{const c=new URLSearchParams({pagina:String(a),por_pagina:String(o)});f&&c.set("estado",f);const N=await C.get(`/actividades?${c}`);d(N.datos),E(N.total)}catch(c){j(c instanceof Error?c.message:"Error al cargar actividades")}finally{b(!1)}},[]);t.useEffect(()=>{p(i,m)},[p,i,m]);function A(a){S(a.target.value),x(1)}const u=Math.ceil(n/o),v=s?.rol==="admin"||s?.rol==="lider"||s?.rol==="colaborador";return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold text-gray-900",children:"Actividades"}),e.jsxs("p",{className:"text-sm text-gray-500 mt-0.5",children:[n," actividad",n!==1?"es":""," registrada",n!==1?"s":""]})]}),v&&e.jsx("a",{href:"/actividades/nueva",className:"btn-primary text-sm",children:"+ Nueva Actividad"})]}),e.jsx("div",{className:"flex gap-3 flex-wrap",children:e.jsx("select",{value:m,onChange:A,className:"input text-sm py-1.5 w-48",children:$.map(a=>e.jsx("option",{value:a.value,children:a.label},a.value))})}),g&&e.jsx("div",{className:"rounded-lg bg-red-50 border border-red-200 px-4 py-3 text-sm text-red-700",children:g}),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:"ID"}),e.jsx("th",{children:"Actividad"}),e.jsx("th",{children:"Área"}),e.jsx("th",{className:"hidden sm:table-cell",children:"Tipo"}),e.jsx("th",{children:"Riesgo"}),e.jsx("th",{children:"Estado"}),e.jsx("th",{className:"hidden lg:table-cell",children:"Fecha Inicio"}),e.jsx("th",{className:"hidden lg:table-cell",children:"Fecha Término"}),e.jsx("th",{children:"Acciones"})]})}),e.jsx("tbody",{children:h?e.jsx("tr",{children:e.jsx("td",{colSpan:10,className:"text-center py-12 text-gray-400",children:"Cargando actividades…"})}):r.length===0?e.jsx("tr",{children:e.jsxs("td",{colSpan:10,className:"text-center py-12 text-gray-400",children:["No hay actividades para mostrar."," ",v&&e.jsx("a",{href:"/actividades/nueva",className:"text-blue-600 hover:underline",children:"Crear la primera"})]})}):r.map(a=>e.jsxs("tr",{className:"hover:bg-gray-50 transition-colors",children:[e.jsxs("td",{className:"font-mono text-sm text-gray-500 w-16",children:["#",String(a.numero).padStart(3,"0")]}),e.jsx("td",{className:"font-medium text-gray-900 max-w-xs truncate",children:a.nombre}),e.jsx("td",{className:"text-gray-600 max-w-[120px] truncate",children:a.area}),e.jsx("td",{className:"hidden sm:table-cell",children:e.jsx("span",{className:"badge badge-gray text-xs",children:a.tipo_trabajo})}),e.jsx("td",{children:O(a.nivel_riesgo)}),e.jsx("td",{children:P(a.estado)}),e.jsx("td",{className:"hidden lg:table-cell text-gray-500 text-sm",children:y(a.fecha_inicio)}),e.jsx("td",{className:"hidden lg:table-cell text-gray-500 text-sm",children:y(a.fecha_termino)}),e.jsx("td",{children:e.jsx("a",{href:`/actividades/${a.id}`,className:"text-sm text-blue-600 hover:text-blue-800 transition-colors font-medium",children:"Ver"})})]},a.id))})]})}),u>1&&e.jsxs("div",{className:"flex items-center justify-between text-sm text-gray-500",children:[e.jsxs("span",{children:["Mostrando ",(i-1)*o+1,"–",Math.min(i*o,n)," de ",n]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>x(a=>Math.max(1,a-1)),disabled:i===1||h,className:"btn-secondary text-xs disabled:opacity-40",children:"← Anterior"}),e.jsx("button",{onClick:()=>x(a=>Math.min(u,a+1)),disabled:i===u||h,className:"btn-secondary text-xs disabled:opacity-40",children:"Siguiente →"})]})]})]})}export{R as default};
