1import{r as o,s as B,b as G,t as K,j as e}from"./vendor-react-core-_0sZDOLQ.js";import{B as i,b as O}from"./index-j07E1qHv.js";import{I as W}from"./input-rti45mgP.js";import{C as J,a as H}from"./card-DHmBnTdH.js";import{B as N}from"./badge-BXqwvh8U.js";import{T as V,a as X,b as v}from"./tabs-BUF6w8PE.js";import{t as c}from"./index-CDqomOa1.js";import{u as Y}from"./playerPhotoUpload-CFYZxVol.js";import{r as L,Q as A,am as E,an as Z,E as F,a2 as ee,ag as U,ao as ae,ap as se,aq as te,a4 as re,ar as oe,q as ie}from"./vendor-lucide-Ddz0eB7N.js";import{A as le,m as w}from"./vendor-framer-motion-C1oRD-X5.js";import"./vendor-radix-CFmJ1img.js";import"./vendor-utils-BRu4i-LD.js";import"./vendor-supabase-Ca6cp8v2.js";var de={};function ve(){const[l,_]=o.useState("jogadores"),[m,k]=o.useState(""),[I,C]=o.useState(null),x=B(),[d,Q]=o.useState([]),[h,T]=o.useState(""),{data:g=[],isLoading:q}=G({queryKey:["admin-players"],queryFn:()=>O.entities.Player.list("-created_date")}),n=K({mutationFn:({player:a,file:s})=>Y(a,s),onMutate:({player:a})=>{C(a.id)},onSuccess:(a,{player:s})=>{c.success(`Fotografia de ${s.name} carregada com sucesso!`),x.invalidateQueries({queryKey:["admin-players"]}),x.invalidateQueries({queryKey:["players"]}),x.invalidateQueries({queryKey:["player"]})},onError:a=>{c.error(`Erro ao carregar fotografia: ${a.message}`)},onSettled:()=>{C(null)}}),$=(a,s)=>{var r;const t=(r=s.target.files)==null?void 0:r[0];s.target.value="",t&&n.mutate({player:a,file:t})},S=a=>a.normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/[^a-z0-9]/g,""),z=a=>a?a.includes("wikimedia")||a.includes("wikipedia")?{type:"green",label:"Real (Wiki)",icon:oe,color:"text-emerald-600",bg:"bg-emerald-50",border:"border-emerald-200"}:a.includes("unsplash")||a.includes("source.unsplash")?{type:"orange",label:"Gerada IA",icon:ie,color:"text-amber-500",bg:"bg-amber-50",border:"border-amber-200"}:{type:"blue",label:"Local / FAF",icon:A,color:"text-blue-500",bg:"bg-blue-50",border:"border-blue-200"}:{type:"red",label:"Sem Foto",icon:re,color:"text-red-500",bg:"bg-red-50",border:"border-red-200"},R=a=>{const t=Array.from(a.target.files).filter(r=>r.type.startsWith("image/")).map(r=>{const p=r.name.replace(/\.[^/.]+$/,""),u=S(p);let b=null,f="Não encontrado";for(const j of g){const y=S(j.name);if(y===u){b=j,f="Identificado";break}else(y.includes(u)||u.includes(y))&&(b=j,f="AmbÃguo")}return{file:r,rawName:p,fileName:r.name,player:b,score:f,slug:p.normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/\s+/g,"-")}});Q(t),P(t)},P=a=>{const s=a.map(t=>!t.player||t.score==="Não encontrado"?`-- Skipped: ${t.fileName} (No Match)`:`UPDATE public.players SET photo_url = '${`${de.NEXT_PUBLIC_SUPABASE_URL||"https://[PROJECT_ID].supabase.co"}/storage/v1/object/public/players/${t.slug}.jpg`}' WHERE id = '${t.player.id}'; -- Matched: ${t.player.name}`);T(s.join(` 2`)),c.success("SQL Gerado com sucesso!")},M=a=>{navigator.clipboard.writeText(a),c.success("Copiado para a área de transferência!")},D=o.useMemo(()=>g.filter(a=>{var s;return(s=a.name)==null?void 0:s.toLowerCase().includes(m.toLowerCase())}),[g,m]);return q?e.jsx("div",{className:"min-h-screen flex items-center justify-center",children:e.jsx(L,{className:"w-8 h-8 animate-spin text-indigo-600"})}):e.jsxs("div",{className:"min-h-screen bg-gray-50 pb-20 font-sans",children:[e.jsx("header",{className:"bg-white border-b border-gray-200 pt-10 pb-6 shadow-sm",children:e.jsxs("div",{className:"container mx-auto px-6 flex flex-col md:flex-row items-center justify-between gap-6",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 bg-indigo-600 text-white rounded-xl flex items-center justify-center shadow-md",children:e.jsx(A,{className:"w-6 h-6"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-black text-gray-900 tracking-tight",children:"Fotos dos Jogadores"}),e.jsx("p",{className:"text-sm text-gray-500 font-medium mt-1",children:"Gestão inteligente de media, matching e SQL."})]})]}),e.jsx(V,{value:l,onValueChange:_,className:"w-full md:w-auto",children:e.jsxs(X,{className:"bg-gray-100 p-1 rounded-xl h-auto",children:[e.jsxs(v,{value:"jogadores",className:"rounded-lg px-6 py-2.5 font-bold data-[state=active]:bg-white data-[state=active]:text-indigo-600 data-[state=active]:shadow-sm",children:[e.jsx(E,{className:"w-4 h-4 mr-2"})," Jogadores"]}),e.jsxs(v,{value:"upload",className:"rounded-lg px-6 py-2.5 font-bold data-[state=active]:bg-white data-[state=active]:text-indigo-600 data-[state=active]:shadow-sm",children:[e.jsx(Z,{className:"w-4 h-4 mr-2"})," Upload de Pasta"]}),e.jsxs(v,{value:"sql",className:"rounded-lg px-6 py-2.5 font-bold data-[state=active]:bg-white data-[state=active]:text-indigo-600 data-[state=active]:shadow-sm",children:[e.jsx(F,{className:"w-4 h-4 mr-2"})," SQL / Migração"]})]})})]})}),e.jsx("main",{className:"container mx-auto px-6 mt-8",children:e.jsxs(le,{mode:"wait",children:[l==="jogadores"&&e.jsxs(w.div,{initial:{opacity:0}
2,animate:{opacity:1},exit:{opacity:0},children:[e.jsxs("div",{className:"mb-6 relative",children:[e.jsx(ee,{className:"absolute left-4 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400"}),e.jsx(W,{placeholder:"Pesquisar por nome do jogador...",value:m,onChange:a=>k(a.target.value),className:"pl-12 h-14 rounded-2xl bg-white border-gray-200 shadow-sm text-lg font-medium"})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-6",children:D.map(a=>{const s=z(a.photo_url),t=s.icon;return e.jsxs(J,{className:"overflow-hidden border border-gray-200 shadow-sm hover:shadow-md transition-shadow rounded-2xl bg-white group",children:[e.jsxs("div",{className:"aspect-[4/5] bg-gray-100 relative",children:[a.photo_url?e.jsx("img",{src:a.photo_url,alt:a.name,className:"w-full h-full object-cover"}):e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx(E,{className:"w-16 h-16 text-gray-300"})}),e.jsx("div",{className:"absolute top-3 right-3",children:e.jsxs("div",{className:`flex items-center gap-1.5 px-2.5 py-1 rounded-full backdrop-blur-md bg-white/90 border ${s.border} ${s.color} shadow-sm`,children:[e.jsx(t,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"text-[10px] font-black uppercase tracking-wider",children:s.label})]})})]}
2),e.jsxs(H,{className:"p-4",children:[e.jsx("h3",{className:"font-bold text-gray-900 truncate",title:a.name,children:a.name}),e.jsx("p",{className:"text-xs text-gray-500 mt-1 uppercase font-semibold tracking-wider",children:a.position}),e.jsx(i,{asChild:!0,variant:"outline",size:"sm",className:`mt-4 w-full cursor-pointer border-dashed ${n.isPending?"pointer-events-none opacity-50":""}`,children:e.jsxs("label",{"aria-disabled":n.isPending,children:[I===a.id?e.jsxs(e.Fragment,{children:[e.jsx(L,{className:"w-4 h-4 mr-2 animate-spin"}),"A carregar..."]}):e.jsxs(e.Fragment,{children:[e.jsx(U,{className:"w-4 h-4 mr-2"}),a.photo_url?"Substituir foto":"Carregar foto"]}),e.jsx("input",{type:"file",accept:"image/jpeg,image/png,image/webp",className:"sr-only",disabled:n.isPending,onChange:r=>$(a,r)})]})})]})]},a.id)})})]},"jogadores"),l==="upload"&&e.jsxs(w.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0},children:[e.jsxs("div",{className:"bg-white rounded-3xl shadow-sm border border-gray-200 p-8 mb-8 text-center",children:[e.jsx("div",{className:"w-20 h-20 bg-indigo-50 text-indigo-600 rounded-full flex items-center justify-center mx-auto mb-6",children:e.jsx(U,{className:"w-10 h-10"})}),e.jsx("h2",{className:"text-2xl font-black text-gray-900 mb-3",children:"Upload de Pasta de Fotos"}),e.jsxs("p",{className:"text-gray-500 mb-8 max-w-lg mx-auto",children:["Selecione a pasta do seu computador contendo as fotos dos jogadores. O sistema fará o matching automático baseado no nome do f
2icheiro (ex: ",e.jsx("code",{className:"bg-gray-100 px-1 rounded text-sm",children:"Gelson_Dala.jpg"}),")."]}),e.jsxs("div",{className:"relative inline-block",children:[e.jsx(i,{className:"h-14 px-8 rounded-2xl bg-indigo-600 hover:bg-indigo-700 text-white font-bold text-lg shadow-lg shadow-indigo-600/20",children:"Selecionar Pasta..."}),e.jsx("input",{type:"file",webkitdirectory:"",multiple:!0,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer",onChange:R})]})]}),d.length>0&&e.jsxs("div",{className:"bg-white rounded-3xl shadow-sm border border-gray-200 overflow-hidden",children:[e.jsxs("div",{className:"p-6 border-b border-gray-100 flex items-center justify-between",children:[e.jsxs("h3",{className:"text-xl font-bold text-gray-900",children:["Resultados do Matching (",d.length,")"]}),e.jsxs(i,{onClick:()=>P(d),variant:"outline",className:"font-bold",children:[e.jsx(ae,{className:"w-4 h-4 mr-2"})," Atualizar SQL"]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-left",children:[e.jsx("thead",{className:"bg-gray-50 text-xs uppercase font-bold text-gray-500 tracking-wider",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-6 py-4",children:"Ficheiro Analisado"}),e.jsx("th",{className:"px-6 py-4",children:"Jogador Identificado"}),e.jsx("th",{className:"px-6 py-4",children:"Confiança"}),e.jsx("th",{className:"px-6 py-4 text-right",children:"Ações"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-100 text-sm",children:d.map((a,s)=>e.jsxs("tr",{className:"hover:bg-gray-50/50",children:[e.jsx("td",{className:"px-6 py-4 font-mono text-xs text-gray-600",children:a.fileName}),e.jsx("td",{className:"px-6 py-4 font-bold text-gray-900",children:a.player?a.player.name:e.jsx("span",{className:"text-gray-400 italic",children:"Nenhum match"})}),e.jsxs("td",{className:"px-6 py-4",children:[a.score==="Identificado"&&e.jsx(N,{className:"bg-emerald-100 text-emerald-700 border-emerald-200",children:"Identificado"}),a.score==="AmbÃguo"&&e.jsx(N,{className:"bg-amber-100 text-amber-700 border-amber-200",children:"AmbÃguo"}),a.score==="Não encontrado"&&e.jsx(N,{className:"bg-red-100 text-red-700 border-red-200",children:"Não encontrado"})]}),e.jsx("td",{className:"px-6 py-4 text-right",children:e.jsx(i,{size:"sm",variant:"ghost",className:"text-indigo-600 hover:text-indigo-700 hover:bg-indigo-50",children:"Corrigir"})})]},s))})]})})]})]},"upload"),l==="sql"&&e.jsxs(w.div,{initial:{opacity:0}
2,animate:{opacity:1},exit:{opacity:0},className:"space-y-8",children:[e.jsxs("div",{className:"bg-white rounded-3xl shadow-sm border border-gray-200 p-8",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-xl font-bold text-gray-900 flex items-center gap-2",children:[e.jsx(F,{className:"w-5 h-5 text-indigo-500"})," SQL de Atualização em Lote"]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Gere queries automaticamente com base nos ficheiros de upload."})]}),e.jsxs(i,{variant:"outline",onClick:()=>M(h),disabled:!h,children:[e.jsx(se,{className:"w-4 h-4 mr-2"})," Copiar SQL"]})]}),e.jsx("div",{className:"relative",children:e.jsx("textarea",{readOnly:!0,className:"w-full h-64 bg-gray-900 text-green-400 font-mono text-sm p-6 rounded-2xl focus:outline-none focus:ring-2 focus:ring-indigo-500 resize-none",value:h||'-- Nenhum ficheiro carregado. Vá para a aba "Upload de Pasta" para gerar este script.'})})]}),e.jsxs("div",{className:"bg-white rounded-3xl shadow-sm border border-gray-200 p-8",children:[e.jsx("div",{className:"flex items-center justify-between mb-4",children:e.jsx("div",{children:e.jsxs("h3",{className:"text-xl font-bold text-gray-900 flex items-center gap-2",children:[e.jsx(te,{className:"w-5 h-5 text-amber-500"})," Scripts de Auditoria Ãteis"]})})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-gray-700 mb-2",children:"Encontrar jogadores com fotos de Inteligência Artificial (Para limpar):"}),e.jsx("div",{className:"relative group",children:e.jsx("pre",{className:"bg-gray-50 p-4 rounded-xl border border-gray-200 text-sm font-mono text-gray-800 overflow-x-auto",children:"SELECT id, name, photo_url FROM public.players WHERE photo_url LIKE '%unsplash%';"})})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-gray-700 mb-2",children:"Resetar todas as fotos de IA para NULL (Para forçar novas fotos):"}),e.jsx("div",{className:"relative group",children:e.jsx("pre",{className:"bg-gray-50 p-4 rounded-xl border border-gray-200 text-sm font-mono text-gray-800 overflow-x-auto",children:"UPDATE public.players SET photo_url = NULL WHERE photo_url LIKE '%unsplash%';"})})]})]})]})]},"sql")]})})]})}export{ve 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.