1import{ad as j,ah as C,r as m,c as F,j as e,F as N,h as u}from"./index-D8aFWAV7.js";import{u as v}from"./useMutation-BiAgjwu9.js";import{l as A}from"./useAuditLog-DIN-o5Cu.js";import{u as w,U as B}from"./UnauthorizedPage-B-bZ1nRn.js";import{P as k}from"./plus-D9gEL-RT.js";import{S as D}from"./search-BqUAIhnb.js";import{P as E}from"./pencil-BxjZT4z5.js";import{T as _}from"./trash-2-CH55cono.js";import{f as S,e as P}from"./es-A0OTDyw4.js";import"./lock-C-4tRXYI.js";const h={investigacion:{label:"Investigación",bg:"#E1F3F9",text:"#0A4C7A"},bolivia_ia:{label:"Bolivia y IA",bg:"#FFF3CD",text:"#856404"},etica_politica:{label:"Ãtica y polÃtica",bg:"#F8D7DA",text:"#721C24"},desde_el_equipo:{label:"Desde el equipo",bg:"#D4EDDA",text:"#2A9D5C"},recursos_tecnicos:{label:"Recursos técnicos",bg:"#E2D9F3",text:"#5B2C8F"}},$=()=>{const a=j(),p=C(),[r,g]=m.useState(""),[i,b]=m.useState(""),[n,c]=m.useState(null),{canManageBlog:o}=w(),{data:y=[],isLoading:f}=F({queryKey:["admin-blog"],queryFn:async()=>{const{data:t,error:l}=await u.from("blog_posts").select("id, title, slug, category, author, published_at").order("published_at",{ascending:!1});if(l)throw l;return t}}),d=v({mutationFn:async t=>{const{error:l}=await u.from("blog_posts").delete().eq("id",t.id);if(l)throw l;await A({action:"delete",entity_type:"blog_post",entity_id:t.id,entity_label:t.title})},onSuccess:()=>{p.invalidateQueries({queryKey:["admin-blog"]}),c(null)}});if(!o)return e.jsx(B,{});const x=y.filter(t=>{const l=!r||t.title.toLowerCase().includes(r.toLowerCase()),s=!i||t.category===i;return l&&s});return e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-6",children:[e.jsx("h1",{className:"font-heading text-[28px] font-bold",style:{color:"#021526"},children:"Blog â ArtÃculos"}),o&&e.jsxs("button",{onClick:()=>a("/admin/blog/nuevo"),className:"flex items-center gap-2 rounded-md px-5 py-2.5 text-sm font-semibold transition-colors",style:{backgroundColor:"#FFD700",color:"#021526"},children:[e.jsx(k,{size:18})," Nuevo artÃculo"]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 mb-6",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(D,{size:18,className:"absolute left-3 top-1/2 -translate-y-1/2",style:{color:"#8FA8BB"}}),e.jsx("input",{type:"text",placeholder:"Buscar artÃculo...",value:r,onChange:t=>g(t.target.value),className:"w-full rounded-md border pl-10 pr-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-[#0A4C7A]",style:{borderColor:"#C5D9E5"}})]}),e.jsxs("select",{value:i,onChange:t=>b(t.target.value),className:"rounded-md border px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-[#0A4C7A]",style:{borderColor:"#C5D9E5",color:"#021526"},children:[e.jsx("option",{value:"",children:"Todas las categorÃas"}),Object.entries(h).map(([t,l])=>e.jsx("option",{value:t,children:l.label},t))]})]}),!f&&x.length===0?e.jsxs("div",{className:"bg-white rounded-lg p-16 text-center",style:{boxShadow:"0 1px 8px rgba(0,0,0,0.06)"},children:[e.jsx(N,{size:48,className:"mx-auto mb-4",style:{color:"#C5D9E5"}}),e.jsx("p",{className:"font-heading font-semibold mb-1",style:{color:"#021526"},children:"No hay artÃculos publicados aún."}),e.jsx("p",{className:"text-sm mb-6",style:{color:"#8FA8BB"},children:"Crea tu primer artÃculo para el blog."}),o&&e.jsx("button",{onClick:()=>a("/admin/blog/nuevo"),className:"rounded-md px-5 py-2.5 text-sm font-semibold",style:{backgroundColor:"#FFD700",color:"#021526"},children:"Crear primer artÃculo"})]}):e.jsx("div",{className:"bg-white rounded-lg overflow-hidden",style:{boxShadow:"0 1px 8px rgba(0,0,0,0.06)"},children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{style:{backgroundColor:"#F8FAFC"},children:[e.jsx("th",{className:"text-left px-5 py-3 font-medium text-xs uppercase tracking-wider",style:{color:"#8FA8BB"},children:"TÃtulo"}),e.jsx("th",{className:"text-left px-5 py-3 font-medium text-xs uppercase tracking-wider hidden md:table-cell",style:{color:"#8FA8BB"},children:"CategorÃa"}),e.jsx("th",{className:"text-left px-5 py-3 font-medium text-xs uppercase tracking-wider hidden lg:table-cell",style:{color:"#8FA8BB"},children:"Autor"}),e.jsx("th",{className:"text-left px-5 py-3 font-medium text-xs uppercase tracking-wider hidden sm:table-cell",style:{color:"#8FA8BB"},children:"Fecha"}),e.jsx("th",{className:"text-right px-5 py-3 font-medium text-xs uppercase tracking-wider",style:{color:"#8FA8BB"},children:"Acciones"})]})}),e.jsx("tbody",{children:x.map((t,l)=>{const s=h[t.category??""];return e.jsxs("tr",{style:{backgroundColor:l%2===0?"#FFFFFF":"#F8FAFC"},children:[e.jsx("td",{className:"px-5 py-3",children:e.jsx("button",{onClick:()=>a(`/admin/blog/editar/${t.id}`),className:"font-heading font-medium text-left hover:underline",style:{color:"#021526"},children:t.title.length>60?t.title.slice(0,60)+"...":t.title})}),e.jsx("td",{className:"px-5 py-3 hidden md:table-cell",children:s&&e.jsx("span",{className:"text-xs font-medium px-2.5 py-1 rounded-full",style:{backgroundColor:s.bg,color:s.text},children:s.label})}),e.jsx("td",{className:"px-5 py-3 hidden lg:table-cell",style:{color:"#8FA8BB"},children:t.author??"â"}),e.jsx("td",{className:"px-5 py-3 hidden sm:table-cell whitespace-nowrap",style:{color:"#8FA8BB"},children:t.published_at?S(new Date(t.published_at),"d MMM yyyy",{locale:P}):"â"}),e.jsx("td",{className:"px-5 py-3 text-right",children:o&&e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("button",{onClick:()=>a(`/admin/blog/editar/${t.id}`),className:"p-1.5 rounded hover:bg-gray-100 transition-colors",title:"Editar",children:e.jsx(E,{size:16,style:{color:"#0A4C7A"}})}),e.jsx("button",{onClick:()=>c(t),className:"p-1.5 rounded hover:bg-red-50 transition-colors",title:"Eliminar",children:e.jsx(_,{size:16,style:{color:"#E74C3C"}})})]})})]},t.id)})})]})}),n&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",children:e.jsxs("div",{className:"bg-white rounded-xl p-8 max-w-md w-full mx-4",children:[e.jsx("h3",{className:"font-heading text-lg font-semibold mb-2",style:{color:"#021526"},children:"¿Eliminar este artÃculo?"}),e.jsxs("p",{className:"text-sm mb-6",style:{color:"#8FA8BB"},children:['Esta acción no se puede deshacer. El artÃculo "',e.jsx("strong",{children:n.title}),'" será eliminado permanentemente.']}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx("button",{onClick:()=>c(null),className:"px-4 py-2 rounded-md text-sm font-medium border",style:{borderColor:"#C5D9E5",color:"#021526"},children:"Cancelar"}),e.jsx("button",{onClick:()=>d.mutate(n),disabled:d.isPending,className:"px-4 py-2 rounded-md text-sm font-medium text-white disabled:opacity-50",style:{backgroundColor:"#E74C3C"},children:d.isPending?"Eliminando...":"SÃ, eliminar"})]})]})})]})};export{$ 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.