1import{ap as k,r as c,c as g,j as e,K as L,U as I,h}from"./index-D8aFWAV7.js";import{l as T}from"./useAuditLog-DIN-o5Cu.js";import{u as U,U as q}from"./UnauthorizedPage-B-bZ1nRn.js";import{D as z}from"./download-aRrUzKAr.js";import{S as R}from"./search-BqUAIhnb.js";import{T as O}from"./trash-2-CH55cono.js";import"./lock-C-4tRXYI.js";const H=()=>{const{showSuccess:N,showError:C}=k(),[a,v]=c.useState("all"),[i,w]=c.useState(""),[r,d]=c.useState(null),[u,y]=c.useState(!1),{canViewRegistrations:b}=U(),{data:o}=g({queryKey:["admin-events-list"],queryFn:async()=>{const{data:s}=await h.from("events").select("id, title, date").order("date",{ascending:!1});return s??[]}}),{data:x,refetch:A}=g({queryKey:["admin-registrations",a],queryFn:async()=>{let s=h.from("event_registrations").select("*").order("registered_at",{ascending:!1});a!=="all"&&(s=s.eq("event_id",a));const{data:l}=await s;return l??[]}});if(!b)return e.jsx(q,{});const n=(x==null?void 0:x.filter(s=>{if(!i)return!0;const l=i.toLowerCase();return s.nombre.toLowerCase().includes(l)||s.email.toLowerCase().includes(l)||(s.institucion??"").toLowerCase().includes(l)}))??[],E=async()=>{if(!r)return;y(!0);const{error:s}=await h.from("event_registrations").delete().eq("id",r.id);y(!1),s?C("Error al eliminar inscripción"):(N("Inscripción eliminada"),T({action:"delete",entity_type:"event_registration",entity_id:r.id,entity_label:r.nombre}),A()),d(null)},j=s=>{var l;return((l=o==null?void 0:o.find(m=>m.id===s))==null?void 0:l.title)??"Evento desconocido"},F=()=>{if(!n.length)return;const s=["Nombre","Email","Teléfono","Edad","Género","Ciudad","Departamento","Ocupación","Institución","Ãrea de formación","Nivel","Experiencia IA","Intereses","Cómo se enteró","Mensaje","Acepta comunicaciones","Fecha","Evento"],l=n.map(t=>[t.nombre,t.email,t.telefono??"",t.edad??"",t.genero??"",t.ciudad??"",t.departamento??"",t.ocupacion??"",t.institucion??"",t.area_formacion??"",t.nivel_formacion??"",t.experiencia_ia??"",(t.intereses??[]).join("; "),t.como_se_entero??"",(t.mensaje??"").replace(/\n/g," "),t.acepta_comunicaciones?"SÃ":"No",new Date(t.registered_at).toLocaleDateString("es-BO"),j(t.event_id)]),m=[s,...l].map(t=>t.map(S=>`"${S}"`).join(",")).join(` 2`),_=new Blob(["\uFEFF"+m],{type:"text/csv;charset=utf-8;"}),f=URL.createObjectURL(_),p=document.createElement("a");p.href=f,p.download=`inscripciones-${a==="all"?"todos":a}.csv`,p.click(),URL.revokeObjectURL(f)},B=n.length,D=n.filter(s=>s.acepta_comunicaciones).length;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"font-heading text-2xl font-bold",style:{color:"#021526"},children:"Inscripciones a eventos"}),e.jsx("p",{className:"text-sm",style:{color:"#8FA8BB"},children:"Gestiona los registros de participantes"})]}),e.jsxs("button",{onClick:F,disabled:!n.length,className:"flex items-center gap-2 rounded-lg px-4 py-2.5 text-sm font-semibold transition-opacity hover:opacity-90 disabled:opacity-40",style:{backgroundColor:"#059669",color:"#FFFFFF"},children:[e.jsx(z,{size:16})," Exportar CSV"]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-xl bg-white p-4 shadow-sm border",style:{borderColor:"#C5D9E5"},children:[e.jsx("p",{className:"text-2xl font-bold",style:{color:"#0A4C7A"},children:B}),e.jsx("p",{className:"text-xs",style:{color:"#8FA8BB"},children:"Inscripciones totales"})]}),e.jsxs("div",{className:"rounded-xl bg-white p-4 shadow-sm border",style:{borderColor:"#C5D9E5"},children:[e.jsx("p",{className:"text-2xl font-bold",style:{color:"#059669"},children:D}),e.jsx("p",{className:"text-xs",style:{color:"#8FA8BB"},children:"Aceptan comunicaciones"})]}),e.jsxs("div",{className:"rounded-xl bg-white p-4 shadow-sm border",style:{borderColor:"#C5D9E5"},children:[e.jsx("p",{className:"text-2xl font-bold",style:{color:"#FFD700"},children:(o==null?void 0:o.length)??0}),e.jsx("p",{className:"text-xs",style:{color:"#8FA8BB"},children:"Eventos con formulario"})]})]}),e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(R,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2",style:{color:"#8FA8BB"}}),e.jsx("input",{type:"text",value:i,onChange:s=>w(s.target.value),placeholder:"Buscar por nombre, email o institución...",className:"w-full rounded-lg border bg-white py-2.5 pl-10 pr-4 text-sm",style:{borderColor:"#C5D9E5"}})]}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:a,onChange:s=>v(s.target.value),className:"appearance-none rounded-lg border bg-white py-2.5 pl-4 pr-10 text-sm min-w-[220px]",style:{borderColor:"#C5D9E5"},children:[e.jsx("option",{value:"all",children:"Todos los eventos"}),o==null?void 0:o.map(s=>e.jsx("option",{value:s.id,children:s.title},s.id))]}),e.jsx(L,{size:14,className:"absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none",style:{color:"#8FA8BB"}})]})]}),n.length===0?e.jsxs("div",{className:"rounded-xl border bg-white p-12 text-center",style:{borderColor:"#C5D9E5"},children:[e.jsx(I,{size:40,className:"mx-auto",style:{color:"#C5D9E5"}}),e.jsxs("p",{className:"mt-3 text-sm",style:{color:"#8FA8BB"},children:["No hay inscripciones",a!=="all"?" para este evento":""]})]}):e.jsx("div",{className:"overflow-x-auto rounded-xl border bg-white shadow-sm",style:{borderColor:"#C5D9E5"},children:e.jsxs("table",{className:"w-full text-left text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{style:{backgroundColor:"#F0F4F8"},children:[e.jsx("th",{className:"px-4 py-3 font-semibold text-xs uppercase",style:{color:"#0A4C7A"},children:"Nombre"}),e.jsx("th",{className:"px-4 py-3 font-semibold text-xs uppercase",style:{color:"#0A4C7A"},children:"Email"}),e.jsx("th",{className:"px-4 py-3 font-semibold text-xs uppercase hidden md:table-cell",style:{color:"#0A4C7A"},children:"Edad"}),e.jsx("th",{className:"px-4 py-3 font-semibold text-xs uppercase hidden md:table-cell",style:{color:"#0A4C7A"},children:"Ocupación"}),e.jsx("th",{className:"px-4 py-3 font-semibold text-xs uppercase hidden lg:table-cell",style:{color:"#0A4C7A"},children:"Institución"}),e.jsx("th",{className:"px-4 py-3 font-semibold text-xs uppercase hidden lg:table-cell",style:{color:"#0A4C7A"},children:"Evento"}),e.jsx("th",{className:"px-4 py-3 font-semibold text-xs uppercase",style:{color:"#0A4C7A"},children:"Fecha"}),e.jsx("th",{className:"px-4 py-3"})]})}),e.jsx("tbody",{children:n.map(s=>e.jsxs("tr",{className:"border-t hover:bg-gray-50",style:{borderColor:"#C5D9E5"},children:[e.jsx("td",{className:"px-4 py-3 font-medium",style:{color:"#021526"},children:s.nombre}),e.jsx("td",{className:"px-4 py-3",style:{color:"#0A4C7A"},children:s.email}),e.jsx("td",{className:"px-4 py-3 hidden md:table-cell",style:{color:"#8FA8BB"},children:s.edad??"â"}),e.jsx("td",{className:"px-4 py-3 hidden md:table-cell",style:{color:"#8FA8BB"},children:s.ocupacion??"â"}),e.jsx("td",{className:"px-4 py-3 hidden lg:table-cell",style:{color:"#8FA8BB"},children:s.institucion??"â"}),e.jsx("td",{className:"px-4 py-3 hidden lg:table-cell text-xs",style:{color:"#8FA8BB"},children:j(s.event_id)}),e.jsx("td",{className:"px-4 py-3 text-xs",style:{color:"#8FA8BB"},children:new Date(s.registered_at).toLocaleDateString("es-BO")}),e.jsx("td",{className:"px-4 py-3",children:b&&e.jsx("button",{onClick:()=>d(s),className:"text-destructive hover:opacity-70",children:e.jsx(O,{size:14})})})]},s.id))})]})}),r&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",children:e.jsxs("div",{className:"w-full max-w-sm rounded-xl bg-white p-6 shadow-xl",children:[e.jsx("h3",{className:"font-heading text-lg font-bold",style:{color:"#021526"},children:"Eliminar inscripción"}),e.jsxs("p",{className:"mt-2 text-sm",style:{color:"#8FA8BB"},children:["¿Eliminar la inscripción de ",e.jsx("strong",{children:r.nombre}),"?"]}),e.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[e.jsx("button",{onClick:()=>d(null),className:"rounded-lg border px-4 py-2 text-sm",style:{borderColor:"#C5D9E5"},children:"Cancelar"}),e.jsx("button",{onClick:E,disabled:u,className:"rounded-lg px-4 py-2 text-sm text-white disabled:opacity-50",style:{backgroundColor:"#EF4444"},children:u?"Eliminando...":"Eliminar"})]})]})})]})};export{H 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.