1import{g as C,Z as F,r as o,n as l,j as s,L as q,A as _}from"./index-DJx_SGrm.js";import{l as z,u as G}from"./editalCargoAdminApi-DfhELNAi.js";import{b as X,c as $}from"./editalExtractorApi-t1wfCmgM.js";const O=F();async function I(a,t){if(!a.ok){const n=await a.json().catch(()=>({}));throw new Error(n.message||t)}return a.json()}async function H(a){const t=await fetch(`${O}/gestao/site/editais/${a}/generate`,{method:"POST",headers:C()});return I(t,"Erro ao enfileirar a geração do conteúdo.")}async function J(a,t){const n=await fetch(`${O}/gestao/site/editais/${a}/slug`,{method:"PATCH",headers:{...C(),"Content-Type":"application/json"},body:JSON.stringify({slug:t})});return I(n,"Erro ao salvar slug.")}const V={PUBLICADO:{tone:"green",label:"Publicado"},PRONTO:{tone:"indigo",label:"Pronto para publicar"},INCOMPLETO:{tone:"gold",label:"Incompleto"},NAO_EXTRAIDO:{tone:"slate",label:"Não extraÃdo"},EXTRAINDO:{tone:"indigo",label:"Extraindo..."},FALHA_EXTRACAO:{tone:"red",label:"Falha na extração"},SEM_PDF:{tone:"slate",label:"Sem PDF"}};function S(a){const t=a.publishState,n=V[t]??{tone:"slate",label:t},b=t==="EXTRAINDO"||a.concursoDataStatus==="RUNNING";let i;return t==="PUBLICADO"?i={kind:"open",label:"Abrir no site",href:a.publicUrl,disabled:!a.publicUrl,confirm:!1}:t==="PRONTO"?i={kind:"publish",label:"Publicar",disabled:!1,confirm:!1}:b?i={kind:"extracting",label:"Extraindo...",disabled:!0,confirm:!1}:t==="NAO_EXTRAIDO"?i={kind:"extract",label:"Extrair e publicar",disabled:!a.pdfPresent,confirm:!0}:t==="INCOMPLETO"||t==="FALHA_EXTRACAO"?i={kind:"reextract",label:"Extrair novamente",disabled:!a.pdfPresent,confirm:!0}:i={kind:"none",label:"Sem PDF para extrair",disabled:!0,confirm:!1},{id:a.id,badge:n,isExtracting:b,primaryAction:i,missingChips:Array.isArray(a.missingRequirements)?a.missingRequirements:[],publicUrl:a.publicUrl??null,errorMessage:a.concursoDataError??null}}function K(a=[]){return a.reduce((t,n)=>(n.publishState==="PUBLICADO"?t.publicados+=1:n.publishState==="INCOMPLETO"?t.incompletos+=1:(n.publishState==="NAO_EXTRAIDO"||n.publishState==="SEM_PDF")&&(t.naoExtraidos+=1),t),{publicados:0,incompletos:0,naoExtraidos:0})}function Q(a){return a==="green"?"border-ds-success-border bg-ds-success-surface text-ds-success-text":a==="red"?"border-ds-danger-border bg-ds-danger-surface text-ds-danger-text":a==="indigo"?"border-ds-accent-border bg-ds-accent-surface text-ds-accent-text":a==="slate"?"border-ds-border-subtle bg-ds-surface-subtle text-ds-text-secondary":"border-ds-warning-border bg-ds-warning-surface text-ds-warning-text"}function Z({tone:a,children:t}){return s.jsx("span",{className:`inline-flex items-center rounded-full border px-2.5 py-1 text-[11px] font-semibold ${Q(a)}`,children:t})}function j({label:a,value:t}){return s.jsxs("div",{className:"rounded-[var(--ds-radius-card)] border border-ds-border-subtle bg-ds-panel p-4",children:[s.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-ds-text-tertiary",children:a}),s.jsx("p",{className:"mt-2 text-2xl font-semibold text-ds-text-primary ",children:t})]})}function v({onClick:a,children:t}){return s.jsx("button",{type:"button",onClick:a,className:"block w-full rounded-[var(--ds-radius-control)] px-3 py-2 text-left text-xs text-ds-text-secondary transition hover:bg-ds-surface-hover hover:text-ds-text-primary",children:t})}function W({item:a,kind:t,onCancel:n,onConfirm:b}){const i=t==="reextract"?"Extrair novamente":"Extrair e publicar",p=_(n);return o.useEffect(()=>{const x=h=>{h.key==="Escape"&&n()};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[n]),s.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4",...p,children:s.jsxs("div",{role:"dialog","aria-modal":"true",className:"w-full max-w-md rounded-[var(--ds-radius-card)] border border-ds-border bg-ds-panel p-6 shadow-[var(--ds-shadow-3)]",onClick:x=>x.stopPropagation(),children:[s.jsxs("h2",{className:"text-lg font-semibold text-ds-text-primary ",children:[i,"?"]}),s.jsxs("p",{className:"mt-2 text-sm text-ds-text-secondary",children:["Isto roda uma extração de IA sobre o PDF de ",s.jsx("span",{className:"font-medium text-ds-text-primary",children:a.nome})," (custo por execução). Se os dados ficarem completos, a página pública é publicada automaticamente."]}),s.jsxs("div",{className:"mt-5 flex justify-end gap-2",children:[s.jsx("button",{type:"button",onClick:n,className:"rounded-[var(--ds-radius-control)] border border-ds-border-subtle px-4 py-2 text-sm font-semibold text-ds-text-secondary transition hover:text-ds-text-primary",children:"Cancelar"}),s.jsx("button",{type:"button",onClick:b,className:"rounded-full shadow-[var(--ds-shadow-accent)] bg-ds-accent px-4 py-2 text-sm font-semibold text-white transition hover:bg-[var(--ds-accent-solid-hover)]",children:i})]})]})})}function re(){const[a,t]=o.useState([]),[n,b]=o.useState(!0),[i,p]=o.use
1State(null),[x,h]=o.useState(""),[N,D]=o.useState(""),[T,c]=o.useState({}),[w,m]=o.useState(null),[f,y]=o.useState(null),g=o.useRef(0);o.useEffect(()=>{const e=setTimeout(()=>D(x),300);return()=>clearTimeout(e)},[x]);const u=o.useCallback(async()=>{const e=g.current+=1;p(null);try{const r=await z({page:1,pageSize:200,q:N});if(e!==g.current)return;t(r.items??[])}catch(r){if(e!==g.current)return;p(r.message||"Erro ao carregar a publicação dos editais.")}finally{e===g.current&&b(!1)}},[N]);o.useEffect(()=>{u()},[u]);const A=o.useMemo(()=>a.some(e=>S(e).isExtracting),[a]);o.useEffect(()=>{if(!A)return;const e=setInterval(()=>{u()},4e3);return()=>clearInterval(e)},[A,u]);const E=o.useMemo(()=>K(a),[a]),k=o.useCallback(async e=>{c(r=>({...r,[e.id]:!0}));try{const r=await X(e.id);(r==null?void 0:r.started)===!1?l.success("Extração já está em andamento para este edital."):l.success("Extração iniciada. A publicação acontece automaticamente se os dados ficarem completos."),await u()}catch(r){l.error(r.message||"Erro ao iniciar a extração.")}finally{c(r=>({...r,[e.id]:!1}))}},[u]),M=o.useCallback(async e=>{c(r=>({...r,[e.id]:!0}));try{await $(e.id),l.success("Edital publicado."),await u()}catch(r){l.error(r.message||"Erro ao publicar o edital.")}finally{c(r=>({...r,[e.id]:!1}))}},[u]),R=(e,r)=>{const d=r.primaryAction;if(d.kind==="open"){window.open(d.href,"_blank","noreferrer");return}if(d.kind==="publish"){M(e);return}if(d.kind==="extract"||d.kind==="reextract"){if(d.confirm){y({item:e,kind:d.kind});return}k(e)}},L=async e=>{c(r=>({...r,[e.id]:!0}));try{await G(e.id,{siteExibido:!e.siteExibido}),l.success(e.siteExibido?"Edital ocultado do site.":"Edital liberado para o site."),await u()}catch(r){l.error(r.message||"Erro ao atualizar a visibilidade.")}finally{c(r=>({...r,[e.id]:!1})),m(null)}},B=async e=>{m(null);const r=window.prompt("Novo slug público:",e.slug??"");if(r){c(d=>({...d,[e.id]:!0}));try{await J(e.id,r.trim()),l.success("Slug atualizado."),await u()}catch(d){l.error(d.message||"Erro ao salvar slug.")}finally{c(d=>({...d,[e.id]:!1}))}}},U=async e=>{m(null),c(r=>({...r,[e.id]:!0}));try{await H(e.id),l.success("Geração de conteúdo enfileirada.")}catch(r){l.error(r.message||"Erro ao enfileirar a geração do conteúdo.")}finally{c(r=>({...r,[e.id]:!1}))}};return n?s.jsx("div",{className:"flex justify-center py-16",children:s.jsx(q,{})}):i?s.jsx("div",{className:"rounded-[var(--ds-radius-control)] border border-ds-danger-border bg-ds-danger-surface px-4 py-3 text-sm text-ds-danger-text",children:i}):s.jsxs("div",{className:"space-y-6",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx("h1",{className:"text-2xl font-semibold text-ds-text-primary ",children:"Publicação dos Editais"}),s.jsx("p",{className:"max-w-3xl text-sm text-ds-text-secondary",children:'Pós-editais ordenados por mais recentes. Clique em "Extrair e publicar" para extrair os dados do concurso: se ficar completo (órgão, banca, slug e ao menos um cargo), a página pública vai ao ar na hora. Quando faltar algum dado, o edital fica sinalizado para import manual, reaproveitando a extração já feita.'})]}),s.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[s.jsx(j,{label:"Publicados",value:E.publicados}),s.jsx(j,{label:"Incompletos",value:E.incompletos}),s.jsx(j,{label:"Ainda sem dados",value:E.naoExtraidos})]}),s.jsx("input",{type:"text",value:x,onChange:e=>h(e.target.value),placeholder:"Buscar por edital, banca, órgão ou slug...",className:"w-full rounded-[var(--ds-radius-control)] border border-ds-border bg-ds-surface px-3 py-2 text-sm text-ds-text-primary outline-none transition focus:border-ds-accent-border"}),s.jsx("div",{className:"overflow-visible rounded-[var(--ds-radius-control)] border border-ds-border-subtle bg-ds-panel",children:s.jsxs("table",{className:"w-full text-left text-sm",children:[s.jsx("thead",{className:"border-b border-ds-border-subtle text-[11px] uppercase tracking-[0.14em] text-ds-text-tertiary",children:s.jsxs("tr",{children:[s.jsx("th",{className:"px-4 py-3 font-semibold",children:"Edital"}),s.jsx("th",{className:"px-4 py-3 font-semibold",children:"Estado"}),s.jsx("th",{className:"px-4 py-3 text-right font-semibold",children:"Ações"})]})}),s.jsxs("tbody",{children:[a.map(e=>{const r=S(e),d=!!T[e.id];return s.jsxs("tr",{className:"border-b border-ds-border-subtle align-top last:border-0",children:[s.jsxs("td",{className:"px-4 py-3",children:[s.jsx("p",{className:"font-medium text-ds-text-primary",children:e.nome}),s.jsx("p",{className:"text-xs text-ds-text-secondary",children:[e.orgaoNome,e.bancaNome,e.ano].filter(
1Boolean).join(" · ")})]}),s.jsx("td",{className:"px-4 py-3",children:s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx("div",{children:s.jsx(Z,{tone:r.badge.tone,children:r.badge.label})}),r.missingChips.length>0&&s.jsx("div",{className:"flex flex-wrap gap-1",children:r.missingChips.map(P=>s.jsx("span",{className:"rounded-full border border-ds-warning-border bg-ds-warning-surface px-2 py-0.5 text-[10px] font-medium text-ds-warning-text",children:P},P))}),r.errorMessage&&s.jsx("p",{className:"text-[11px] text-ds-danger-text",children:r.errorMessage})]})}),s.jsx("td",{className:"px-4 py-3",children:s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsx("button",{type:"button",disabled:r.primaryAction.disabled||d||r.isExtracting,onClick:()=>R(e,r),title:r.primaryAction.disabled&&r.primaryAction.kind==="none"?"Sem PDF para extrair":void 0,className:"rounded-[var(--ds-radius-control)] border border-ds-accent-border bg-ds-accent-surface px-3 py-1.5 text-xs font-semibold text-ds-accent-text transition hover:bg-ds-accent-surface disabled:cursor-not-allowed disabled:opacity-50",children:r.isExtracting?"Extraindo...":r.primaryAction.label}),s.jsxs("div",{className:"relative",children:[s.jsx("button",{type:"button",onClick:()=>m(w===e.id?null:e.id),className:"rounded-[var(--ds-radius-control)] border border-ds-border-subtle px-2 py-1.5 text-xs text-ds-text-secondary transition hover:text-ds-text-primary","aria-label":"Mais ações",children:"..."}),w===e.id&&s.jsxs("div",{className:"absolute right-0 z-10 mt-1 w-52 rounded-[var(--ds-radius-control)] border border-ds-border-subtle bg-ds-panel p-1 shadow-[var(--ds-shadow-3)]",children:[s.jsx(v,{onClick:()=>L(e),children:e.siteExibido?"Ocultar do site":"Exibir no site"}),s.jsx(v,{onClick:()=>B(e),children:"Editar slug"}),s.jsx(v,{onClick:()=>U(e),children:"Gerar conteúdo do site"})]})]})]})})]},e.id)}),a.length===0&&s.jsx("tr",{children:s.jsx("td",{colSpan:3,className:"px-4 py-8 text-center text-sm text-ds-text-secondary",children:"Nenhum pós-edital encontrado para esse filtro."})})]})]})}),f&&s.jsx(W,{item:f.item,kind:f.kind,onCancel:()=>y(null),onConfirm:async()=>{const e=f.item;y(null),await k(e)}})]})}export{re as GestaoPublicacaoEditaisPage};
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.