1import{r as l,j as e,L as f,U as o,C as x}from"./index-DUOydnzc.js";import{R as w}from"./refresh-cw-BIcaMscV.js";import{D as b}from"./download-Dj1X0RE3.js";import{H as v}from"./hash-B04ZW6ZJ.js";import{M as E}from"./mail-Da6uiiP_.js";import{P as k}from"./phone-Brqow9rt.js";const D=()=>{const[t,N]=l.useState([]),[n,m]=l.useState(!0),[p,h]=l.useState(!1),[g,d]=l.useState(null),j=async()=>{m(!0),d(null);try{const s=localStorage.getItem("auth_token"),a=await(await fetch("/api/participantes",{headers:{Authorization:`Bearer ${s}`}})).json();if(a.success)N(a.participantes);else{const c=a.details?`${a.error}: ${a.details}`:a.error;d(c||"Error al cargar participantes"),console.error("[AdminParticipantes] Error response:",a)}}catch(s){console.error("[AdminParticipantes] Error al cargar participantes:",s),d(`Error al cargar participantes: ${s}`)}finally{m(!1)}},u=async()=>{h(!0);try{const s=localStorage.getItem("auth_token"),r=await fetch("/api/participantes/export-csv",{headers:{Authorization:`Bearer ${s}`}});if(r.ok){const a=await r.blob(),c=window.URL.createObjectURL(a),i=document.createElement("a");i.href=c,i.download=`participantes_sorteo_${new Date().toISOString().split("T")[0]}.csv`,document.body.appendChild(i),i.click(),window.URL.revokeObjectURL(c),document.body.removeChild(i)}else alert("Error al exportar CSV")}catch(s){console.error("Error al exportar CSV:",s),alert("Error al exportar CSV")}finally{h(!1)}};l.useEffect(()=>{j()},[]);const y=s=>new Date(s).toLocaleDateString("es-CL",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"});return n?e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(f,{className:"h-8 w-8 animate-spin text-primary-600"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"bg-white rounded-lg shadow-lg p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx("div",{className:"bg-primary-100 rounded-lg p-3",children:e.jsx(o,{className:"h-6 w-6 text-primary-600"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:"Participantes del Sorteo"}),e.jsxs("p",{className:"text-sm text-gray-600",children:[t.length," ",t.length===1?"participante registrado":"participantes registrados"]})]})]}),e.jsxs("div",{className:"flex space-x-3",children:[e.jsxs("button",{onClick:j,disabled:n,className:"flex items-center space-x-2 px-4 py-2 bg-gray-100 hover:bg-gray-200 text-gray-700 rounded-lg transition-colors disabled:opacity-50",children:[e.jsx(w,{className:`h-4 w-4 ${n?"animate-spin":""}`}),e.jsx("span",{children:"Actualizar"})]}),e.jsx("button",{onClick:u,disabled:p||t.length===0,className:"flex items-center space-x-2 px-4 py-2 bg-primary-600 hover:bg-primary-700 text-white rounded-lg transition-colors disabled:opacity-50",children:p?e.jsxs(e.Fragment,{children:[e.jsx(f,{className:"h-4 w-4 animate-spin"}),e.jsx("span",{children:"Exportando..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(b,{className:"h-4 w-4"}),e.jsx("span",{children:"Exportar CSV"})]})})]})]}),g&&e.jsx("div",{className:"bg-red-50 border border-red-200 rounded-lg p-4 text-red-700",children:g})]}),t.length===0?e.jsxs("div",{className:"bg-white rounded-lg shadow-lg p-12 text-center",children:[e.jsx(o,{className:"h-16 w-16 text-gray-300 mx-auto mb-4"}),e.jsx("h3",{className:"text-xl font-semibold text-gray-900 mb-2",children:"No hay participantes registrados"}),e.jsx("p",{className:"text-gray-600",children:"Los participantes aparecerán aquà cuando se registren a través de la página de participación"})]}):e.jsx("div",{className:"bg-white rounded-lg shadow-lg overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-gray-200",children:[e.jsx("thead",{className:"bg-gray-50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(v,{className:"h-4 w-4"}),e.jsx("span",{children:"ID"})]})}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Nombre Completo"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"RUT"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(E,{className:"h-4 w-4"}),e.jsx("span",{children:"Email"})]})}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Edad"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(k,{className:"h-4 w-4"}),e.jsx("span",{children:"Teléfono"})]})}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(x,{className:"h-4 w-4"}),e.jsx("span",{children:"Registro"})]})})]})}),e.jsx("tbody",{className:"bg-white divide-y divide-gray-200",children:t.map(s=>e.jsxs("tr",{className:"hover:bg-gray-50 transition-colors",children:[e.jsxs("td",{className:"px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900",children:["#",s.id]}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsxs("div",{className:"text-sm font-medium text-gray-900",children:[s.nombre," ",s.apellido]})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-600 font-mono",children:s.rut}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-600",children:e.jsx("a",{href:`mailto:${s.email}`,className:"text-primary-600 hover:text-primary-700",children:s.email})}),e.jsxs("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-600",children:[s.edad," años"]}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-600",children:e.jsx("a",{href:`tel:${s.telefono}`,className:"text-primary-600 hover:text-primary-700",children:s.telefono})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-500",children:y(s.created_at)})]},s.id))})]})})}),t.length>0&&e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6",children:[e.jsx("div",{className:"bg-white rounded-lg shadow-lg p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-600",children:"Total Participantes"}),e.jsx("p",{className:"text-3xl font-bold text-gray-900",children:t.length})]}),e.jsx(o,{className:"h-12 w-12 text-primary-600 opacity-20"})]})}),e.jsx("div",{className:"bg-white rounded-lg shadow-lg p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-600",children:"Edad Promedio"}),e.jsxs("p",{className:"text-3xl font-bold text-gray-900",children:[Math.round(t.reduce((s,r)=>s+r.edad,0)/t.length)," años"]})]}),e.jsx(x,{className:"h-12 w-12 text-primary-600 opacity-20"})]})}),e.jsx("div",{className:"bg-white rounded-lg shadow-lg p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-600",children:"Ãltimo Registro"}),e.jsx("p",{className:"text-lg font-bold text-gray-900",children:t[0]?y(t[0].created_at):"-"})]}),e.jsx(x,{className:"h-12 w-12 text-primary-600 opacity-20"})]})})]})]})};export{D as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.