1import{r as a,g as B,a as X,n as d,A as Y,j as e,L as U,z as se,m as te}from"./index-DJx_SGrm.js";var Q;const G=((Q=X.api)==null?void 0:Q.baseUrl)||"https://api.bizzu.ai";function ae({onClose:m,onSuccess:u}){const[A,c]=a.useState("selection"),[i,v]=a.useState([]),[k,C]=a.useState(!0),[l,N]=a.useState([]),[y,h]=a.useState(""),[o,b]=a.useState(!1),[g,w]=a.useState(null);a.useEffect(()=>{const s=B();C(!0),fetch(`${G}/bancas`,{headers:s}).then(r=>r.ok?r.json():Promise.reject(r)).then(r=>v(Array.isArray(r)?r:[])).catch(()=>d.error("Erro ao carregar bancas.")).finally(()=>C(!1))},[]);const F=s=>{N(r=>r.includes(s)?r.filter(S=>S!==s):[...r,s]),s===y&&h("")},P=s=>{const r=s.target.value;h(r),N(S=>S.filter(I=>I!==r))},z=l.length>=1&&y!=="",E=async()=>{b(!0);try{const s=B(),r=await fetch(`${G}/admin/bancas/merge/preview`,{method:"POST",headers:{...s,"Content-Type":"application/json"},body:JSON.stringify({sourceIds:l,targetId:y})});if(!r.ok){const I=await r.json().catch(()=>({}));d.error(I.message||"Erro ao calcular impacto.");return}const S=await r.json();w(S),c("confirmation")}catch{d.error("Falha ao conectar. Tente novamente.")}finally{b(!1)}},T=async()=>{b(!0);try{const s=B(),r=await fetch(`${G}/admin/bancas/merge`,{method:"POST",headers:{...s,"Content-Type":"application/json"},body:JSON.stringify({sourceIds:l,targetId:y})});if(!r.ok){const S=await r.json().catch(()=>({}));d.error(S.message||"Erro ao unificar bancas.");return}d.success("Bancas unificadas com sucesso."),u(),m()}catch{d.error("Falha ao conectar. Tente novamente.")}finally{b(!1)}},j=i.find(s=>s.id===y),M=i.filter(s=>l.includes(s.id)),D=Y(o?void 0:m);return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",...D,children:e.jsxs("div",{className:"relative w-full max-w-lg rounded-[var(--ds-radius-card)] border border-ds-border bg-ds-panel p-6 shadow-[var(--ds-shadow-3)]",onClick:s=>s.stopPropagation(),children:[e.jsx("h2",{className:"text-lg font-bold text-ds-text-primary",children:"Unificar bancas"}),k?e.jsx("div",{className:"mt-6 flex justify-center py-8",children:e.jsx(U,{size:"lg"})}):i.length===0?e.jsxs("div",{className:"mt-6",children:[e.jsx("p",{className:"text-sm text-ds-text-secondary",children:"Não foi possÃvel carregar as bancas. Feche e tente novamente."}),e.jsx("div",{className:"mt-4 flex justify-end",children:e.jsx("button",{type:"button",onClick:m,className:"rounded-[var(--ds-radius-control)] border border-ds-border bg-ds-panel px-4 py-2 text-sm font-medium text-ds-text-secondary hover:bg-ds-surface-hover hover:text-ds-text-primary",children:"Fechar"})})]}):A==="selection"?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mt-2 text-sm text-ds-text-secondary",children:"Selecione as bancas duplicadas (origens) e a banca canônica (destino)."}),e.jsxs("div",{className:"mt-4",children:[e.jsx("p",{className:"mb-2 text-xs font-medium uppercase tracking-wide text-ds-text-tertiary",children:"Bancas de origem (duplicatas)"}),e.jsxs("div",{className:"max-h-48 overflow-y-auto rounded-[var(--ds-radius-control)] border border-ds-border bg-ds-surface p-2",children:[i.length===0&&e.jsx("p",{className:"text-sm text-ds-text-tertiary",children:"Nenhuma banca disponÃvel."}),i.map(s=>e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded px-2 py-1.5 text-sm text-ds-text-primary hover:bg-ds-surface-hover",children:[e.jsx("input",{type:"checkbox",checked:l.includes(s.id),onChange:()=>F(s.id),disabled:o||s.id===y,className:"accent-[var(--ds-accent-solid)]"}),e.jsxs("span",{children:[s.nome," ",e.jsxs("span",{className:"text-ds-text-tertiary",children:["(",s.sigla,")"]})]})]},s.id))]})]}),e.jsxs("div",{className:"mt-4",children:[e.jsx("label",{htmlFor:"merge-target",className:"mb-1 block text-xs font-medium uppercase tracking-wide text-ds-text-tertiary",children:"Banca destino (canônica)"}),e.jsxs("select",{id:"merge-target",value:y,onChange:P,disabled:o,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 [font-family:var(--ds-font-metric)]",children:[e.jsx("option",{value:"",children:"Selecione a banca destino"}),i.filter(s=>
1!l.includes(s.id)).map(s=>e.jsxs("option",{value:s.id,children:[s.nome," (",s.sigla,")"]},s.id))]})]}),e.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[e.jsx("button",{type:"button",onClick:m,disabled:o,className:"rounded-[var(--ds-radius-control)] border border-transparent px-3 py-2 text-sm font-medium text-ds-text-secondary hover:text-ds-text-primary disabled:opacity-50",children:"Cancelar"}),e.jsx("button",{type:"button",onClick:E,disabled:!z||o,className:"flex items-center gap-2 rounded-[var(--ds-radius-control)] border border-ds-border bg-ds-panel px-4 py-2 text-sm font-medium text-ds-text-secondary hover:bg-ds-surface-hover hover:text-ds-text-primary disabled:cursor-not-allowed disabled:opacity-50",children:o?e.jsxs(e.Fragment,{children:[e.jsx(U,{size:"sm"}),"Calculando..."]}):"Ver impacto"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"mt-4 text-sm text-ds-text-secondary",children:[e.jsxs("strong",{className:"text-ds-text-primary",children:[(g==null?void 0:g.questoesCount)??0," questões"]})," ","e"," ",e.jsxs("strong",{className:"text-ds-text-primary",children:[(g==null?void 0:g.editaisCount)??0," editais"]})," ","serão movidos para"," ",e.jsxs("strong",{className:"text-ds-text-primary",children:[j==null?void 0:j.nome," (",j==null?void 0:j.sigla,")"]}),"."]}),e.jsxs("div",{className:"mt-3",children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-ds-text-tertiary",children:"Bancas que serão desativadas:"}),e.jsx("ul",{className:"mt-1 list-inside list-disc text-sm text-ds-text-secondary",children:M.map(s=>e.jsxs("li",{children:[s.nome," (",s.sigla,")"]},s.id))})]}),e.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[e.jsx("button",{type:"button",onClick:()=>c("selection"),disabled:o,className:"rounded-[var(--ds-radius-control)] border border-transparent px-3 py-2 text-sm font-medium text-ds-text-secondary hover:text-ds-text-primary disabled:opacity-50",children:"Voltar"}),e.jsx("button",{type:"button",onClick:T,disabled:o,className:"flex items-center gap-2 rounded-[var(--ds-radius-control)] border border-ds-danger-border bg-ds-danger-surface px-4 py-2 text-sm font-medium text-ds-danger-text hover:bg-ds-danger-border disabled:cursor-not-allowed disabled:opacity-50",children:o?e.jsxs(e.Fragment,{children:[e.jsx(U,{size:"sm"}),"Unificando..."]}):"Confirmar fusão"})]})]})]})})}var W;const O=((W=X.api)==null?void 0:W.baseUrl)||"https://api.bizzu.ai",$="w-full rounded-[var(--ds-radius-control)] border border-ds-border bg-ds-surface px-3 py-2 text-sm text-ds-text-primary placeholder:text-ds-text-tertiary [font-family:var(--ds-font-metric)]";function K({label:m,children:u}){return e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-xs font-medium uppercase tracking-wide text-ds-text-tertiary",children:m}),u]})}function re({item:m,onClose:u,onSaved:A}){const[c,i]=a.useState({nome:m.nome||"",sigla:m.sigla||""}),[v,k]=a.useState(!1),C=a.useRef(null),l=Y(u);a.useEffect(()=>{const h=o=>{o.key==="Escape"&&u()};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[u]);const N=h=>o=>i(b=>({...b,[h]:o.target.value})),y=async h=>{h.preventDefault();const o=c.nome.trim(),b=c.sigla.trim();if(!o||!b){d.error("Informe o nome e a sigla da banca.");return}const g=B();k(!0);try{const w=await fetch(`${O}/admin/bancas/${m.id}`,{method:"PATCH",headers:{...g,"Content-Type":"application/json"},body:JSON.stringify({nome:o,sigla:b})});if(!w.ok){const P=await w.json().catch(()=>({}));d.error(P.message||"Erro ao salvar banca.");return}const F=await w.json();d.success("Banca atualizada com sucesso."),A(F),u()}catch{d.error("Falha ao conectar. Tente novamente.")}finally{k(!1)}};return e.jsx("div",{ref:C,className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4 backdrop-blur-sm",...l,children:e.jsxs("div",{className:"w-full max-w-lg rounded-[var(--ds-radius-card)] border border-ds-border bg-ds-panel shadow-[var(--ds-shadow-3)]",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-ds-border-subtle px-6 py-4",children:[e.jsx("h2",{className:"text-base font-semibold text-ds-text-primary",children:"Editar banca"}),e.jsx("button",{type:"button",onClick:u,className:"text-xl leading-none text-ds-text-tertiary hover:text-ds-text-primary",children:"Ã"})]}),e.jsxs("form",{onSubmit:y,className:"space-y-4 px-6 py-5",children:[e.jsx(K,{label:"Nome da banca",children:e.jsx("input",{type:"text",value:c.nome,onChange:N("nome"),className:$,disabled:v,autoFocus:!0})}),e.jsx(K,{label:"Sigla",children:e.jsx("input",{type:"text",value:c.sigla,onChange:N("sigla"),className:$,disabled:v})}),e.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[e.jsx("button",{type:"button",onClick:u,disabled:v,className:"rounded-[var(--ds-radius-control)] border border-ds-border px-4 py-2 text-sm text-ds-text-secondary hover:text-ds-text-primary",children:"Cancelar"}),e.jsx(te,{type:"submit",disabled:v||!c.nome.trim()||!c.sigla.trim(),children:v?"Salvandoâ¦":"Salvar alterações"})]})]})]})})}function de(){const[m,u]=se(),[A,c]=a.useState([]),[i,v]=a.useState(1),[k]=a.useState(20),[C,l]=a.useState(0),[N,y]=a.useState(""),[h,o]=a.use
1State("nome"),[b,g]=a.useState("ASC"),[w,F]=a.useState(!0),[P,z]=a.useState(null),[E,T]=a.useState({nome:"",sigla:""}),[j,M]=a.useState(!1),[D,s]=a.useState(!1),r=m.get("edit"),S=r?A.find(t=>t.id===r)??null:null,I=t=>{const n=new URLSearchParams(m);n.set("edit",t.id),u(n)},Z=()=>{const t=new URLSearchParams(m);t.delete("edit"),u(t)},R=a.useCallback(async()=>{const t=B();if(!t.Authorization){z("Não autenticado."),F(!1);return}F(!0),z(null);try{const n=new URLSearchParams;n.set("page",String(i)),n.set("pageSize",String(k)),N.trim()&&n.set("search",N.trim()),n.set("sortBy",h),n.set("sortDirection",b);const p=await fetch(`${O}/admin/bancas?${n.toString()}`,{headers:t});if(!p.ok){const f=await p.json().catch(()=>({}));z(f.message||"Erro ao carregar bancas."),c([]),l(0);return}const x=await p.json();c(Array.isArray(x.items)?x.items:x),Array.isArray(x.items)&&typeof x.total=="number"?l(x.total):Array.isArray(x)?l(x.length):l(0)}catch{z("Falha ao conectar. Tente novamente."),c([]),l(0)}finally{F(!1)}},[i,k,N,h,b]);a.useEffect(()=>{R()},[R]);const _=async t=>{t.preventDefault();const n=E.nome.trim(),p=E.sigla.trim();if(!n||!p){d.error("Informe o nome e a sigla da banca.");return}const x=B();if(!x.Authorization){d.error("Não autenticado.");return}M(!0);try{const f=await fetch(`${O}/admin/bancas`,{method:"POST",headers:{...x,"Content-Type":"application/json"},body:JSON.stringify({nome:n,sigla:p})});if(!f.ok){const L=await f.json().catch(()=>({}));d.error(L.message||"Erro ao criar banca.");return}const J=await f.json();c(L=>[J,...L]),l(L=>L+1),d.success("Banca criada com sucesso."),T({nome:"",sigla:""})}catch{d.error("Falha ao conectar. Tente novamente.")}finally{M(!1)}},ee=async t=>{if(!window.confirm("Tem certeza que deseja excluir esta banca?"))return;const n=B();if(!n.Authorization){d.error("Não autenticado.");return}try{const p=await fetch(`${O}/admin/bancas/${t}`,{method:"DELETE",headers:n});if(!p.ok){const f=await p.json().catch(()=>({}));d.error(f.message||"Erro ao excluir banca.");return}const x=await p.json().catch(()=>({}));if(x&&x.deleted===!1){d.error("Não foi possÃvel excluir a banca.");return}c(f=>f.filter(J=>J.id!==t)),l(f=>f>0?f-1:0),d.success("Banca excluÃda com sucesso.")}catch{d.error("Falha ao conectar. Tente novamente.")}},H=t=>{if(h===t){g(n=>n==="ASC"?"DESC":"ASC");return}o(t),g("ASC")},q=Math.max(1,Math.ceil(C/k)),V=t=>{t<1||t>q||v(t)};return e.jsxs("div",{className:"max-w-4xl",children:[e.jsx("h1",{className:"text-2xl font-bold text-ds-text-primary",children:"Bancas"}),e.jsx("p",{className:"mt-2 text-sm text-ds-text-secondary",children:"Gerencie as bancas de concurso utilizadas nos editais."}),e.jsxs("form",{onSubmit:_,className:"mt-6 flex flex-wrap items-end gap-3",children:[e.jsxs("div",{className:"min-w-[200px] flex-1",children:[e.jsx("label",{htmlFor:"gestao-bancas-nome",className:"mb-1 block text-xs font-medium uppercase tracking-wide text-ds-text-tertiary",children:"Nome da banca"}),e.jsx("input",{id:"gestao-bancas-nome",type:"text",value:E.nome,onChange:t=>T(n=>({...n,nome:t.target.value})),placeholder:"Ex.: CESPE / CEBRASPE",className:$,disabled:j})]}),e.jsxs("div",{className:"w-40",children:[e.jsx("label",{htmlFor:"gestao-bancas-sigla",className:"mb-1 block text-xs font-medium uppercase tracking-wide text-ds-text-tertiary",children:"Sigla"}),e.jsx("input",{id:"gestao-bancas-sigla",type:"text",value:E.sigla,onChange:t=>T(n=>({...n,sigla:t.target.value})),placeholder:"Ex.: CESPE",className:$,disabled:j})]}),e.jsx("button",{type:"submit",disabled:j||!E.nome.trim()||!E.sigla.trim(),className:"rounded-[var(--ds-radius-control)] border border-ds-border bg-ds-panel px-4 py-2 text-sm font-medium text-ds-text-secondary hover:bg-ds-surface-hover hover:text-ds-text-primary disabled:cursor-not-allowed disabled:opacity-50",children:j?"Criando...":"Criar banca"})]}),e.jsxs("div",{className:"mt-6 flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"min-w-[200px]",children:[e.jsx("label",{htmlFor:"gestao-bancas-search",className:"mb-1 block text-xs font-medium uppercase tracking-wide text-ds-text-tertiary",children:"Buscar"}),e.jsx("input",{id:"gestao-bancas-search",type:"text",value:N,onChange:t=>{y(t.target.value),v(1)},placeholder:"Filtrar por nome",className:$})]}),e.jsx("div",{className:"flex items-end pb-0.5",children:e.jsx("button",{type:"button",onClick:()=>s(!0),className:"rounded-[var(--ds-radius-control)] border border-ds-border bg-ds-panel px-4 py-2 text-sm font-medium text-ds-text-secondary hover:bg-ds-surface-hover hover:text-ds-text-primary",children:"Unificar bancas"})})]}),w&&e.jsxs("div",{className:"mt-8 flex flex-col items-center gap-3 py-8",children:[e.jsx(U,{size:"lg"}),e.jsx("p",{className:"text-sm text-ds-text-secondary",children:"Carregando bancas..."})]}),!w&&P&&e.jsx("div",{className:"mt-8 rounded-[var(--ds-radius-control)] border border-ds-border-subtle bg-ds-panel px-4 py-3 text-sm text-ds-text-secondary",children:P}),!w&&!P&&e.jsxs("div",{className:"mt-8",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsxs("p",{className:"text-sm text-ds-text-secondary",children:[C," ",C===1?"banca encontrada":"bancas encontradas"]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-ds-text-tertiary",children:[e.jsx("button",{type:"button",onClick:()=>
1V(i-1),disabled:i<=1,className:"rounded-[var(--ds-radius-chip)] border border-ds-border px-2 py-1 disabled:cursor-not-allowed disabled:opacity-50",children:"Anterior"}),e.jsxs("span",{className:"[font-family:var(--ds-font-metric)]",children:["Página ",i," de ",q]}),e.jsx("button",{type:"button",onClick:()=>V(i+1),disabled:i>=q,className:"rounded-[var(--ds-radius-chip)] border border-ds-border px-2 py-1 disabled:cursor-not-allowed disabled:opacity-50",children:"Próxima"})]})]}),A.length===0?e.jsx("p",{className:"mt-4 text-sm text-ds-text-secondary",children:"Nenhuma banca cadastrada."}):e.jsx("div",{className:"mt-2 overflow-x-auto rounded-[var(--ds-radius-card)] border border-ds-border bg-ds-panel",children:e.jsxs("table",{className:"w-full min-w-[480px] text-left text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-ds-border-subtle",children:[e.jsx("th",{className:"cursor-pointer px-4 py-3 font-medium text-ds-text-primary",onClick:()=>H("nome"),children:"Nome"}),e.jsx("th",{className:"cursor-pointer px-4 py-3 font-medium text-ds-text-primary",onClick:()=>H("sigla"),children:"Sigla"}),e.jsx("th",{className:"px-4 py-3 font-medium text-ds-text-primary",children:"Ações"})]})}),e.jsx("tbody",{children:A.map(t=>e.jsxs("tr",{className:"border-b border-ds-border-subtle last:border-0 hover:bg-ds-surface-hover",children:[e.jsx("td",{className:"px-4 py-3 text-ds-text-secondary",children:t.nome}),e.jsx("td",{className:"px-4 py-3 text-ds-text-secondary",children:t.sigla}),e.jsx("td",{className:"px-4 py-3 text-ds-text-secondary",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:()=>I(t),className:"text-xs font-medium text-ds-accent-text hover:underline",children:"Editar"}),e.jsx("button",{type:"button",onClick:()=>ee(t.id),className:"text-xs font-medium text-ds-danger-text hover:underline",children:"Excluir"})]})})]},t.id))})]})})]}),S&&e.jsx(re,{item:S,onClose:Z,onSaved:t=>c(n=>n.map(p=>p.id===t.id?t:p))}),D&&e.jsx(ae,{onClose:()=>s(!1),onSuccess:R})]})}export{de as GestaoBancasPage};
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.