1import{a as $,b as l,j as e,B as y,t as n,d as B}from"./index-BbKxumrM.js";import{r as t}from"./react-vendor-DT1_wbt4.js";import{a2 as z,ai as j,b4 as W,K as A,ad as q,X as G,b7 as K}from"./ui-vendor-BfDHuItz.js";import"./firebase-vendor-CSkRnVBi.js";const H=()=>{const{isAdmin:I}=$(),[g,M]=t.useState([]),[c,N]=t.useState(""),[u,v]=t.useState(""),[h,w]=t.useState(""),[k,C]=t.useState(!0),[r,o]=t.useState(!1),[d,x]=t.useState(null),[m,S]=t.useState(""),[f,E]=t.useState(""),[b,Y]=t.useState("");t.useEffect(()=>{p()},[]);const p=async()=>{C(!0);try{const a=await l.getCategories();M(a)}catch(a){console.error(a)}finally{C(!1)}},D=async a=>{if(a.preventDefault(),c.trim()){o(!0);try{await l.saveCategory({name:c.trim(),minYear:u?parseInt(u):void 0,maxYear:h?parseInt(h):void 0}),N(""),v(""),w(""),await p()}catch{n.error("Erro ao salvar categoria.")}finally{o(!1)}}},F=a=>{var s,i;x(a),S(a.name),E(((s=a.minYear)==null?void 0:s.toString())||""),Y(((i=a.maxYear)==null?void 0:i.toString())||"")},U=async a=>{if(a.preventDefault(),d&&m.trim()){o(!0);try{await l.saveCategory({id:d.id,name:m.trim(),minYear:f?parseInt(f):void 0,maxYear:b?parseInt(b):void 0}),x(null),await p()}catch{n.error("Erro ao atualizar categoria.")}finally{o(!1)}}},L=async a=>{const s=g.find(i=>String(i.id)===String(a));if(s)try{if(await l.checkCategoryInUse(s.name)){n.error(`Não é possÃvel excluir a categoria "${s.name}" pois ela está vinculada a uma ou mais disputas de competições existentes.`);return}await B({title:"Excluir Categoria",message:"Você está prestes a excluir definitivamente esta categoria do Firebase. Isso não pode ser desfeito.",isSecurity:!0,entityName:s.name})&&(await l.deleteCategory(a),await p(),n.success("Categoria excluÃda com sucesso."))}catch(i){console.error("Erro ao verificar/excluir categoria:",i),n.error("Erro ao processar a exclusão.")}};return e.jsxs("div",{className:"max-w-4xl mx-auto pb-20",children:[e.jsxs("h1",{className:"text-2xl font-black text-gray-900 mb-6 flex items-center gap-3 uppercase tracking-tighter",children:[e.jsx("div",{className:"p-2 bg-fedeesp-red rounded-xl",children:e.jsx(z,{className:"text-white",size:24})}),"Gerenciar Categorias"]}),e.jsxs("div",{className:"bg-white rounded-3xl shadow-xl shadow-gray-200/50 border border-gray-100 overflow-hidden mb-8",children:[e.jsxs("div",{className:"p-8 border-b border-gray-50 bg-gray-50/50",children:[e.jsx("h2",{className:"text-xs font-black uppercase tracking-widest text-gray-400 mb-6",children:"Adicionar Nova Categoria"}),e.jsxs("form",{onSubmit:D,className:"grid grid-cols-1 md:grid-cols-4 gap-4 items-end",children:[e.jsxs("div",{className:"md:col-span-2",children:[e.jsx("label",{className:"block text-[10px] font-black uppercase tracking-widest text-gray-400 mb-2 pl-1",children:"Nome da Categoria"}),e.jsx("input",{type:"text",value:c,onChange:a=>N(a.target.value),className:"w-full px-5 py-3 border-none bg-white rounded-2xl shadow-sm focus:ring-2 focus:ring-fedeesp-red text-sm font-bold placeholder:text-gray-300 transition-all",placeholder:"Ex: Sub-13, Mirim...",disabled:r})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] font-black uppercase tracking-widest text-gray-400 mb-2 pl-1",children:"Ano Inicial"}),e.jsx("input",{type:"number",value:u,onChange:a=>v(a.target.value),className:"w-full px-5 py-3 border-none bg-white rounded-2xl shadow-sm focus:ring-2 focus:ring-fedeesp-red text-sm font-bold placeholder:text-gray-300 transition-all",placeholder:"Ex: 2010",disabled:r})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] font-black uppercase tracking-widest text-gray-400 mb-2 pl-1",children:"Ano Final"}),e.jsx("input",{type:"number",value:h,onChange:a=>w(a.target.value),className:"w-full px-5 py-3 border-none bg-white rounded-2xl shadow-sm focus:ring-2 focus:ring-fedeesp-red text-sm font-bold placeholder:text-gray-300 transition-all",placeholder:"Ex: 2012",disabled:r})]}),e.jsx("div",{className:"md:col-span-4 mt-2",children:e.jsxs(y,{type:"submit",disabled:r||!c.trim(),className:"w-full md:w-auto bg-fedeesp-red hover:bg-red-700 text-white rounded-2xl px-10 h-12 gap-2 font-black uppercase tracking-widest text-xs",children:[r?e.jsx(j,{size:18,className:"animate-spin"}):e.jsx(W,{size:18}),"Adicionar Categoria"]})})]})]}),e.jsx("div",{className:"p-0",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-gray-50",children:[e.jsx("thead",{className:"bg-gray-50/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-8 py-4 text-left text-[10px] font-black text-gray-400 uppercase tracking-widest",children:"Nome da Categoria"}),e.jsx("th",{className:"px-8 py-4 text-left text-[10px] font-black text-gray-400 uppercase tracking-widest",children:"Ano Inicial"}),e.jsx("th",{className:"px-8 py-4 text-left text-[10px] font-black text-gray-400 uppercase tracking-widest",children:"Ano Final"}),e.jsx("th",{className:"px-8 py-4 text-right text-[10px] font-black text-gray-400 uppercase tracking-widest",children:"Ações"})]})}),e.jsxs("tbody",{className:"bg-white divide-y divide-gray-50",children:[k?e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"p-20 text-center",children:e.jsx(j,{className:"animate-spin text-fedeesp-red mx-auto",size:32})})}):g.map(a=>e.jsxs("tr",{className:"hover:bg-gray-50 transition-colors group",children:[e.jsxs("td",{className:"px-8 py-5",children:[e.jsx("div",{className:"text-sm font-black text-gray-900 uppercase",children:a.name}),e.jsx("div",{className:"text-[10px] text-gray-400 font-bold uppercase tracking-widest italic",children:a.minYear&&a.maxYear?`${a.minYear} a ${a.maxYear}`:"Sem restrição"})]}),e.jsx("td",{className:"px-8 py-5 text-sm font-black text-gray-600",children:a.minYear||"-"}),e.jsx("td",{className:"px-8 py-5 text-sm font-black text-gray-600",children:a.maxYear||"-"}),e.jsx("td",{className:"px-8 py-5 text-right",children:e.jsxs("div",{className:"flex justify-end gap-4",children:[e.jsx("button",{title:"Editar Categoria",className:"text-gray-400 hover:text-blue-600 transition-colors flex items-center justify-center p-1",onClick:()=>F(a),children:e.jsx(A,{size:20,strokeWidth:1.5})}),I&&e.jsx("button",{onClick:()=>L(a.id),className:"text-gray-400 hover:text-red-500 transition-colors flex items-center justify-center p-1",title:"Excluir Categoria",children:e.jsx(q,{size:20,strokeWidth:1.5})})]})})]},a.id)),!k&&g.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"p-20 text-center",children:e.jsxs("div",{className:"flex flex-col items-center justify-center text-gray-300",children:[e.jsx(z,{size:48,className:"opacity-20 mb-4"}),e.jsx("p",{className:"font-black uppercase tracking-[0.2em] text-[10px]",children:"Nenhuma categoria cadastrada"})]})})})]})]})})})]}),d&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 bg-gray-900/60 backdrop-blur-sm",children:e.jsxs("div",{className:"bg-white rounded-[40px] shadow-2xl w-full max-w-lg max-h-[90vh] overflow-y-auto animate-in fade-in zoom-in duration-200",children:[e.jsxs("div",{className:"bg-gray-900 p-8 text-white relative",children:[e.jsx("button",{onClick:()=>x(null),className:"absolute top-6 right-6 text-gray-400 hover:text-white transition-colors",children:e.jsx(G,{size:24})}),e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:"p-2 bg-fedeesp-red rounded-xl",children:e.jsx(A,{size:20,className:"text-white"})}),e.jsx("h2",{className:"text-xl font-black uppercase tracking-tighter",children:"Editar Categoria"})]}),e.jsxs("p",{className:"text-gray-400 text-[10px] font-bold uppercase tracking-widest",children:["ID: ",d.id]})]}),e.jsxs("form",{onSubmit:U,className:"p-8",children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] font-black uppercase tracking-widest text-gray-400 mb-2 pl-1",children:"Nome da Categoria"}),e.jsx("input",{type:"text",value:m,onChange:a=>S(a.target.value),className:"w-full px-6 py-4 border-none bg-gray-50 rounded-2xl shadow-inner focus:ring-2 focus:ring-fedeesp-red text-sm font-bold transition-all",required:!0})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] font-black uppercase tracking-widest text-gray-400 mb-2 pl-1",children:"Ano Inicial"}),e.jsx("input",{type:"number",value:f,onChange:a=>E(a.target.value),className:"w-full px-6 py-4 border-none bg-gray-50 rounded-2xl shadow-inner focus:ring-2 focus:ring-fedeesp-red text-sm font-bold transition-all"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] font-black uppercase tracking-widest text-gray-400 mb-2 pl-1",children:"Ano Final"}),e.jsx("input",{type:"number",value:b,onChange:a=>Y(a.target.value),className:"w-full px-6 py-4 border-none bg-gray-50 rounded-2xl shadow-inner focus:ring-2 focus:ring-fedeesp-red text-sm font-bold transition-all"})]})]})]}),e.jsxs("div",{className:"mt-10 flex gap-3",children:[e.jsx(y,{type:"button",variant:"outline",className:"flex-1 rounded-2xl py-4 font-black uppercase tracking-widest text-xs h-14",onClick:()=>x(null),children:"Cancelar"}),e.jsxs(y,{type:"submit",disabled:r||!m.trim(),className:"flex-[2] bg-fedeesp-red hover:bg-red-700 text-white rounded-2xl py-4 font-black uppercase tracking-widest text-xs h-14 gap-2",children:[r?e.jsx(j,{size:18,className:"animate-spin"}):e.jsx(K,{size:18}),"Salvar Alterações"]})]})]})]})})]})};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.