1import{r as o,j as s,L as E}from"./react-vendor-CmDvLqYh.js";import{u as T,b as g}from"./query-D0CMoYem.js";import{k as q,n as B,o as L}from"./blog-Ceux0b_v.js";import{B as _}from"./input-QpRwf0di.js";import{S as Q,a as D,b as F,c as K,d as $}from"./select-CJ_84eah.js";import{u as c}from"./toast-CtpTsY3r.js";import{P as G}from"./PageHeader-CJtZzQKy.js";import"./constants-Cqh1euJZ.js";import{D as M}from"./DataTable-BekYrx9M.js";import{Q as A}from"./QueryState-BjzoBOMs.js";import"./index-C-sJpprs.js";import{al as I,a$ as J,av as V,w as z}from"./icons-Boqm7H6b.js";import"./runtime-J3_5sCTm.js";import"./ui-radix-BdW8GMCV.js";import"./index-BAPtaAyO.js";import"./tslib.es6-nRG4y2oQ.js";import"./skeleton-BYmU4FqV.js";import"./EmptyState-hmcZ0zHO.js";import"./supabase-Blo4AzbY.js";const b=["google/gemini-3-flash-preview","google/gemini-2.5-flash","google/gemini-2.5-pro","openai/gpt-5-mini","openai/gpt-5"],P=new Set(["queued","running"]),R=[{id:"",label:"Todos"},{id:"succeeded",label:"Exitosos"},{id:"failed",label:"Fallidos"},{id:"running",label:"Corriendo"},{id:"queued",label:"En cola"}];function pe(){const l=T(),[d,j]=o.useState(3),[m,y]=o.useState(b[0]),[u,p]=o.useState(!1),[v,f]=o.useState(null),[t,h]=o.useState(""),r=g({queryKey:["blog-keywords","pending"],queryFn:()=>B({status:"pending"})}),x=r.data??[],i=g({queryKey:["blog-jobs"],queryFn:L,refetchInterval:e=>(e.state.data||[]).some(C=>P.has(C.status))?4e3:!1}),n=i.data??[],w=o.useMemo(()=>{const e={"":n.length};for(const a of n)e[a.status]=(e[a.status]??0)+1;return e},[n]),N=o.useMemo(()=>t?n.filter(e=>e.status===t):n,[n,t]);async function S(){var e;p(!0);try{const a=await q({batch_size:d,model:m});c.success(`${a.generated||0} posts generados`),(e=a.errors)!=null&&e.length&&c.error(`${a.errors.length} con errores`),l.invalidateQueries({queryKey:["blog-keywords"]}),l.invalidateQueries({queryKey:["blog-posts"]}),l.invalidateQueries({queryKey:["blog-jobs"]})}catch(a){c.error(a.message)}finally{p(!1)}}const k=[{key:"status",header:"Estado",value:e=>e.status,render:e=>s.jsx("span",{className:"text-xs",children:e.status})},{key:"model",header:"Modelo",value:e=>e.model,render:e=>s.jsx("span",{className:"text-xs",children:e.model}),hideBelow:"sm"},{key:"created_at",header:"Iniciado",sortable:!0,hideBelow:"sm",value:e=>new Date(e.created_at).getTime(),render:e=>s.jsx("span",{className:"text-xs",children:new Date(e.created_at).toLocaleString()})},{key:"post",header:"Post",value:e=>e.post_id||"",render:e=>e.post_id?s.jsx(E,{to:`/admin/blog/posts/${e.post_id}`,className:"hover:underline text-primary text-xs",children:"Ver post"}):s.jsx("span",{className:"text-xs adm-muted",children:"â"})},{key:"error",header:"Error",value:e=>e.error||"",render:e=>{if(!e.error)return"";const a=v===e.id;return s.jsxs("button",{type:"button",onClick:()=>f(a?null:e.id),className:"flex items-start gap-1 text-left w-full text-xs text-destructive max-w-md",children:[s.jsx("span",{className:a?"whitespace-pre-wrap break-words":"truncate",children:e.error}),a?s.jsx(V,{className:"h-3 w-3 shrink-0 mt-0.5"}):s.jsx(z,{className:"h-3 w-3 shrink-0 mt-0.5"})]})},hideBelow:"md"}];return s.jsxs("div",{className:"p-6 max-w-5xl mx-auto",children:[s.jsx(G,{kick:"Producción · Corpus",title:"Blog · Generar",liveDot:!r.isLoading&&!r.isError,live:r.isLoading?"Contando la colaâ¦":r.isError?"No se pudo leer la cola de keywords":`${x.length} keywords pendientes en cola`}),s.jsxs("div",{className:"adm-card adm-card-pad",style:{marginBottom:24},children:[s.jsx("h3",{className:"font-medium mb-4",children:"Generación batch"}),s.jsxs("div",{className:"grid grid-cols-3 gap-3 items-end",children:[s.jsxs("label",{className:"text-sm",children:[s.jsx("div",{className:"text-xs adm-muted mb-1",children:"Tamaño del batch (1-10)"}),s.jsx("input",{type:"number",min:1,max:10,value:d,onChange:e=>j(Number(e.target.value)),className:"border px-3 py-2 w-full"})]}),s.jsxs("label",{className:"text-sm col-span-1",children:[s.jsx("div",{className:"text-xs adm-muted mb-1",children:"Modelo"}),s.jsxs(Q,{value:m,onValueChange:e=>y(e),children:[s.jsx(D,{className:"adm-input w-full",children:s.jsx(F,{})}),s.jsx(K,{className:"crm-app",children:b.map(e=>s.jsx($,{value:e,children:e},e))})]})]}),s.jsxs(_,{onClick:S,disabled:u||r.isLoading||r.isError||x.length===0,children:[s.jsx(I,{className:"h-4 w-4 mr-1"})," ",u?"Generandoâ¦":`Generar ${d}`]})]}),s.jsx("p",{className:"text-xs adm-muted mt-3",children:"Toma keywords pen
1dientes por prioridad. Cada post ~10-30 segundos. Costos: Gemini Flash es el más barato."})]}),s.jsx("div",{className:"adm-sec-head",style:{marginTop:0},children:s.jsx("h2",{children:"Trabajos"})}),s.jsx("div",{className:"adm-fchips",style:{marginTop:8},children:R.map(e=>s.jsxs("button",{type:"button",className:`adm-fchip is-btn${t===e.id?" is-on":""}`,onClick:()=>h(e.id),children:[e.label," · ",w[e.id]??0]},e.id||"all"))}),s.jsx("div",{style:{marginTop:8},children:s.jsx(A,{query:{isError:i.isError,error:i.error,refetch:i.refetch},children:s.jsx(M,{columns:k,rows:N,rowKey:e=>e.id,loading:i.isLoading,pageSize:25,empty:{title:t?"Sin trabajos con ese estado":"TodavÃa no se ha generado nada",description:t?void 0:"Corre el primer batch arriba: cada trabajo queda acá con su resultado.",icon:J,...t?{action:{label:"Ver todos",onClick:()=>h("")}}:{}}})})})]})}export{pe 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.