1import{a as te,b as Q,j as e,u as Z}from"./vendor-query-CmFN4-M1.js";import{r as y}from"./vendor-react-7PyNDetJ.js";import{l as X,b as w,I as U,r as H,v as W,x as J,y as Y,z as x,p as L,aL as re,at as pe,ab as ee,aM as ce,aw as fe,ax as je,ay as ye,az as ve,aA as q,aK as _e}from"./index-BZSaBQD0.js";import{T as be,a as Ne,b as K,c as O,d as we,e as R}from"./table-BEgIk-tI.js";import{Y as Ce,bw as de,C as ke,a4 as Se,d0 as me,bD as qe,br as Te,u as ue,L as se,ah as he,S as Ee,D as ne,d1 as Re,aR as Le,bd as Fe}from"./vendor-ui-DjI1iuvA.js";import{b as Oe}from"./index.esm-DjhE5twy.js";import{T as Ae}from"./textarea-Bw8y9bs3.js";import{compressToWebP as De}from"./imageCompression-DJQX-S_h.js";import{A as $e}from"./learningPathsConfig-FXX-qurp.js";import{U as ze}from"./leagueConfig-CXK-5Xsj.js";import{L as Ve}from"./educationStore-BhsXwjSc.js";import"./vendor-supabase-BfoV2C50.js";const Be={common:"bg-muted text-muted-foreground",rare:"bg-blue-500/20 text-blue-400 border-blue-500/30",epic:"bg-purple-500/20 text-purple-400 border-purple-500/30",legendary:"bg-yellow-500/20 text-yellow-400 border-yellow-500/30"},Ie={league:"bg-emerald-500/20 text-emerald-400 border-emerald-500/30",blog:"bg-sky-500/20 text-sky-400 border-sky-500/30",education:"bg-orange-500/20 text-orange-400 border-orange-500/30",achievement:"bg-blue-700/20 text-blue-600 border-blue-700/30",level:"bg-violet-500/20 text-violet-400 border-violet-500/30",event:"bg-red-500/20 text-red-400 border-red-500/30"};function oe(n){return!!(n.image_url&&n.description)}const Ue=({items:n,isLoading:v,onEdit:i,onDelete:z,onSelectionChange:f})=>{const[A,u]=y.useState(""),[j,T]=y.useState("all"),[V,_]=y.useState("all"),[C,k]=y.useState(new Set),{toast:b}=X(),B=te(),S=t=>{k(t),f==null||f(Array.from(t))},F=t=>{const p=new Set(C);p.has(t)?p.delete(t):p.add(t),S(p)},d=()=>{C.size===g.length&&g.length>0?S(new Set):S(new Set(g.map(t=>t.id)))},N=()=>{const t=g.filter(p=>!!p.image_url);S(new Set(t.map(p=>p.id)))},E=Q({mutationFn:async({id:t,is_active:p})=>{const{error:s}=await w.from("nft_catalog").update({is_active:p}).eq("id",t);if(s)throw s},onSuccess:()=>{B.invalidateQueries({queryKey:["nft-catalog"]})},onError:t=>{b({title:"Erro ao atualizar status",description:t.message,variant:"destructive"})}}),g=n.filter(t=>!(A&&!t.name.toLowerCase().includes(A.toLowerCase())&&!t.code.toLowerCase().includes(A.toLowerCase())||j!=="all"&&t.category!==j||V!=="all"&&t.rarity!==V)),D=n.filter(oe).length,I=n.length-D;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-4 text-sm font-mono",children:[e.jsxs("span",{className:"text-muted-foreground",children:[n.length," tÃtulos"]}),e.jsxs("span",{className:"text-emerald-400",children:[D," cadastrados"]}),e.jsxs("span",{className:"text-yellow-400",children:[I," pendentes"]})]}),e.jsxs("div",{className:"flex gap-3 flex-wrap",children:[e.jsxs("div",{className:"relative flex-1 min-w-[200px]",children:[e.jsx(Ce,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(U,{placeholder:"Buscar por nome ou código...",value:A,onChange:t=>u(t.target.value),className:"pl-9 font-mono"})]}),e.jsxs(H,{value:j,onValueChange:T,children:[e.jsx(W,{className:"w-[160px] font-mono",children:e.jsx(J,{placeholder:"Categoria"})}),e.jsxs(Y,{children:[e.jsx(x,{value:"all",children:"Todas Categorias"}),e.jsx(x,{value:"league",children:"League"}),e.jsx(x,{value:"blog",children:"Blog"}),e.jsx(x,{value:"education",children:"Education"}),e.jsx(x,{value:"achievement",children:"Achievement"}),e.jsx(x,{value:"level",children:"Level"}),e.jsx(x,{value:"event",children:"Event"})]})]}),e.jsxs(H,{value:V,onValueChange:_,children:[e.jsx(W,{className:"w-[160px] font-mono",children:e.jsx(J,{placeholder:"Raridade"})}),e.jsxs(Y,{children:[e.jsx(x,{value:"all",children:"Todas Raridades"}),e.jsx(x,{value:"common",children:"Common"}),e.jsx(x,{value:"rare",children:"Rare"}),e.jsx(x,{value:"epic",children:"Epic"}),e.jsx(x,{value:"legendary",children:"Legendary"})]})]}),e.jsxs(L,{variant:"outline",size:"sm",onClick:N,className:"font-mono gap-1",children:[e.jsx(de,{className:"h-4 w-4"})," Só com imagem"]})]}),C.size>0&&e.jsxs("div",{className:"flex items-center gap-3 text-sm font-mono bg-muted/50 rounded-md px-3 py-2",children:[e.jsxs("span",{className:"text-foreground font-medium",children:[C.size," selecionado(s)"]}),e.jsx(L,{variant:"ghost",size:"sm",onClick:()=>S(new Set),className:"text-xs",children:"Limpar seleção"})]}),e.jsx("div",{className:"rounded-md border border-border overflow-hidden",children:e.jsxs(be,{children:[e.jsx(Ne,{children:e.jsxs(K,{children:[e.jsx(O,{className:"w-[40px]",children:e.jsx(re,{checked:g.length>0&&C.size===g.length,onCheckedChange:d})}),e.jsx(O,{className:"font-mono w-[40px]",children:"Status"}),e.jsx(O,{className:"font-mono w-[50px]",children:"MÃdia"}),e.jsx(O,{className:"font-mono",children:"Nome"}),e.jsx(O,{className:"font-mono",children:"Código"}),e.jsx(O,{className:"font-mono",children:"Categoria"}),e.jsx(O,{className:"font-mono",children:"Raridade"}),e.jsx(O,{className:"font-mono text-right",children:"Supply"}
1),e.jsx(O,{className:"font-mono text-right",children:"Preço RADC"}),e.jsx(O,{className:"font-mono text-center",children:"Token ID"}),e.jsx(O,{className:"font-mono text-center",children:"Ativo"}),e.jsx(O,{className:"font-mono text-right",children:"Ações"})]})}),e.jsx(we,{children:v?Array.from({length:5}).map((t,p)=>e.jsx(K,{children:Array.from({length:12}).map((s,m)=>e.jsx(R,{children:e.jsx(pe,{className:"h-4 w-full"})},m))},p)):g.length===0?e.jsx(K,{children:e.jsx(R,{colSpan:12,className:"text-center text-muted-foreground font-mono py-8",children:"Nenhum item encontrado"})}):g.map(t=>{const p=oe(t);return e.jsxs(K,{"data-state":C.has(t.id)?"selected":void 0,children:[e.jsx(R,{children:e.jsx(re,{checked:C.has(t.id),onCheckedChange:()=>F(t.id)})}),e.jsx(R,{className:"text-center",children:p?e.jsx(ke,{className:"h-4 w-4 text-emerald-400 mx-auto"}):e.jsx(Se,{className:"h-4 w-4 text-muted-foreground/40 mx-auto"})}),e.jsx(R,{children:t.image_url?/\.(mp4|webm|mov)(\?|$)/i.test(t.image_url)?e.jsx("div",{className:"h-10 w-10 rounded bg-muted flex items-center justify-center",children:e.jsx(me,{className:"h-5 w-5 text-muted-foreground"})}):e.jsx("img",{src:t.image_url,alt:t.name,className:"h-10 w-10 rounded object-cover"}):e.jsx("div",{className:"h-10 w-10 rounded bg-muted flex items-center justify-center",children:e.jsx(qe,{className:"h-4 w-4 text-muted-foreground/50"})})}),e.jsx(R,{className:"font-mono font-medium",children:t.name}),e.jsx(R,{className:"font-mono text-xs text-muted-foreground",children:t.code}),e.jsx(R,{children:e.jsx(ee,{variant:"outline",className:Ie[t.category]??"",children:t.category})}),e.jsx(R,{children:e.jsx(ee,{variant:"outline",className:Be[t.rarity]??"",children:t.rarity})}),e.jsx(R,{className:"font-mono text-right",children:t.max_supply!=null?t.max_supply.toLocaleString("pt-BR"):"â"}),e.jsx(R,{className:"font-mono text-right",children:t.radc_price}),e.jsx(R,{className:"text-center font-mono text-xs",children:t.onchain_token_id!=null?e.jsxs(ee,{variant:"outline",className:"bg-emerald-500/10 text-emerald-400 border-emerald-500/30 text-[10px]",children:["#",t.onchain_token_id]}):e.jsx("span",{className:"text-muted-foreground/40",children:"â"})}),e.jsx(R,{className:"text-center",children:e.jsx(ce,{checked:t.is_active,onCheckedChange:s=>E.mutate({id:t.id,is_active:s}),disabled:E.isPending})}),e.jsx(R,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-1",children:[e.jsx(L,{variant:"ghost",size:"icon",onClick:()=>i(t),children:e.jsx(Te,{className:"h-4 w-4"})}),e.jsx(L,{variant:"ghost",size:"icon",onClick:()=>z(t.id),children:e.jsx(ue,{className:"h-4 w-4 text-destructive"})})]})})]},t.id)})})]})}),e.jsxs("p",{className:"text-xs text-muted-foreground font-mono",children:[g.length," de ",n.length," itens"]})]})},Pe=50*1024*1024,P="nft-assets";function Me(n){return/\.(mp4|webm|mov)(\?|$)/i.test(n)}function ie(n){const v=`/object/public/${P}/`,i=n.indexOf(v);return i===-1?null:decodeURIComponent(n.substring(i+v.length))}const Ke=({value:n,category:v,rarity:i,code:z,onUploaded:f,onRemoved:A,itemId:u})=>{const{toast:j}=X(),T=y.useRef(null),[V,_]=y.useState(!1),[C,k]=y.useState(!1),b=y.useCallback(async d=>{var E;if(!z){j({title:"Preencha o código antes de fazer upload",variant:"destructive"});return}const N=d.type.startsWith("video/");if(N&&d.size>Pe){j({title:"VÃdeo excede 50 MB",variant:"destructive"});return}_(!0);try{if(n){const s=ie(n);s&&await w.storage.from(P).remove([s])}let g=d,D=((E=d.name.split(".").pop())==null?void 0:E.toLowerCase())??"bin";N||(g=await De(d,{mode:"photo",maxWidth:1e3}),D="webp");const I=`${v}/${i}/${z}.${D}`,{error:t}=await w.storage.from(P).upload(I,g,{upsert:!0,contentType:g.type});if(t)throw t;const{data:p}=w.storage.from(P).getPublicUrl(I);f(`${p.publicUrl}?t=${Date.now()}`),j({title:"Upload concluÃdo"})}catch(g){j({title:"Erro no upload",description:g.message,variant:"destructive"})}finally{_(!1)}},[n,v,i,z,f,j]),B=y.useCallback(async()=>{if(n){k(!0);try{const d=ie(n);d&&await w.storage.from(P).remove([d]),u&&await w.from("nft_catalog").update({image_url:null}).eq("id",u),A(),j({title:"MÃdia removida"})}catch(d){j({title:"Erro ao remover",description:d.message,variant:"destructive"})}finally{k(!1)}}},[n,u,A,j]),S=y.useCallback(d=>{d.preventDefault();const N=d.dataTransfer.files[0];N&&b(N)},[b]),F=n?Me(n):!1;return e.jsxs("div",{className:"space-y-2",children:[n?e.jsxs("div",{className:"relative rounded-md border border-border overflow-hidden bg-muted",children:[F?e.jsx("video",{src:n,controls:!0,className:"w-full max-h-48 object-contain bg-black"}):e.jsx("div",{className:"aspect-square w-full",children:e.jsx("img",{src:n,alt:"NFT media",className:"w-full h-full object-cover"})}),e.jsx("div",{className:"absolute top-2 right-2",children:e.jsx(L,{type:"button",size:"icon",variant:"destructive",className:"h-7 w-7",onClick:B,disabled:C,children:C?e.jsx(se,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(ue,{className:"h-3.5 w-3.5"})})}),e.jsx("div",{className:"absolute bottom-2 left-2",children:e.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-background/80 px-2 py-0.5 text-xs font-mono text-foreground",children:[F?e.jsx(me,{className:"h-3 w-3"}):e.jsx(de,{className:"h-3 w-3"}),F?"VÃdeo":"Imagem"]})})]}):e.jsx("div",{onDrop:S,onDragOver:d=>d.preventDefault(),onClick:()=>{var d;return(d=T.current)==null?void 0:d.click()},className:"flex flex-col items-center justify-center gap-2 rounded-md border-2 border-dashed border-border p-6 cursor-pointer hover:border-primary/50 transition-colors",children:V?e.jsx(se,{className:"h-8 w-8 animate-spin text-muted-foreground"}):e.jsxs(e.Fragment,{children:[e.jsx(he,{className:"h-8 w-8 text-muted-foreground"}),e.jsxs("p",{className:"text-xs text-muted-foreground font-mono text-center",children:["Arraste imagem ou vÃdeo aqui",e.jsx("br",{}),"ou clique para selecionar"]}
1),e.jsx("p",{className:"text-[10px] text-muted-foreground/60 font-mono",children:"Imagem: auto WebP 1000px · VÃdeo: max 50MB"})]})}),e.jsx("input",{ref:T,type:"file",accept:"image/*,video/*,.mp4,.webm,.mov",className:"hidden",onChange:d=>{var E;const N=(E=d.target.files)==null?void 0:E[0];N&&b(N),d.target.value=""}})]})};function Ge(n){return n.normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_|_$/g,"")}const Qe=({open:n,onOpenChange:v,editingItem:i,allItems:z=[]})=>{const{toast:f}=X(),A=te(),u=!!i,j=!!(i!=null&&i.image_url),[T,V]=y.useState(!1),{register:_,handleSubmit:C,setValue:k,watch:b,reset:B}=Oe({defaultValues:{name:"",code:"",description:"",category:"achievement",rarity:"common",max_supply:"",radc_price:"0",background_color:"",is_active:!0,eligibility_requirement:"",eligibility_threshold:"",image_url:"",onchain_token_id:"",contract_address:""}});y.useEffect(()=>{var a,h,o;if(i){const c=i.eligibility_rules;B({name:i.name,code:i.code,description:i.description??"",category:i.category,rarity:i.rarity,max_supply:((a=i.max_supply)==null?void 0:a.toString())??"",radc_price:i.radc_price.toString(),background_color:i.background_color??"",is_active:i.is_active,eligibility_requirement:(c==null?void 0:c.requirement)??"",eligibility_threshold:((h=c==null?void 0:c.threshold)==null?void 0:h.toString())??"",image_url:i.image_url??"",onchain_token_id:((o=i.onchain_token_id)==null?void 0:o.toString())??"",contract_address:i.contract_address??""})}else B({name:"",code:"",description:"",category:"achievement",rarity:"common",max_supply:"",radc_price:"0",background_color:"",is_active:!0,eligibility_requirement:"",eligibility_threshold:"",image_url:"",onchain_token_id:"",contract_address:""})},[i,B]);const S=b("name");y.useEffect(()=>{!u&&S&&k("code",Ge(S))},[S,u,k]);const F=Q({mutationFn:async a=>{const h=a.eligibility_requirement&&a.eligibility_threshold?{requirement:a.eligibility_requirement,threshold:Number(a.eligibility_threshold)}:null,o={name:a.name,code:a.code,description:a.description||null,category:a.category,rarity:a.rarity,max_supply:a.max_supply?Number(a.max_supply):null,radc_price:Number(a.radc_price),background_color:a.background_color||null,is_active:a.is_active,eligibility_rules:h,image_url:a.image_url||null,onchain_token_id:a.onchain_token_id?Number(a.onchain_token_id):null,contract_address:a.contract_address||null};if(u){const{error:c}=await w.from("nft_catalog").update(o).eq("id",i.id);if(c)throw c}else{const{error:c}=await w.from("nft_catalog").insert(o);if(c)throw c}},onSuccess:()=>{A.invalidateQueries({queryKey:["nft-catalog"]}),f({title:u?"Item atualizado":"Item criado"}),v(!1)},onError:a=>{f({title:"Erro",description:a.message,variant:"destructive"})}}),d=b("category"),N=b("rarity"),E=b("code"),g=b("image_url"),D=b("name"),I=b("eligibility_requirement"),t=b("eligibility_threshold"),p=E?`${d}/${N}/${E}.webp`:"",s=async()=>{if(!D){f({title:"Preencha o nome primeiro",variant:"destructive"});return}V(!0);try{const a=z.filter(r=>r.description&&r.id!==(i==null?void 0:i.id)).slice(-5).map(r=>r.description),h=a.length>0?`NÃO repita estas descrições já existentes: 2${a.map((r,l)=>`${l+1}. ${r}`).join(` 3`)}`:"",{data:o,error:c}=await w.functions.invoke("ai-nft-description",{body:{name:D,category:d,rarity:N,requirement:I||void 0,threshold:t?Number(t):void 0,previous_descriptions:h}});if(c)throw c;o!=null&&o.description?(k("description",o.description),f({title:"Descrição gerada com IA"})):f({title:"IA retornou descrição vazia",description:"Verifique o prompt configurado e tente novamente",variant:"destructive"})}catch(a){f({title:"Erro ao gerar descrição",description:a.message,variant:"destructive"})}finally{V(!1)}},m=u?j?"Editar NFT":"Cadastrar NFT":"Novo Item";return e.jsx(fe,{open:n,onOpenChange:v,children:e.jsxs(je,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[e.jsx(ye,{children:e.jsx(ve,{className:"font-mono",children:m})}),e.jsxs("form",{onSubmit:C(a=>F.mutate(a)),className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(q,{className:"font-mono text-xs",children:"Nome *"}),e.jsx(U,{..._("name",{required:!0}),className:"font-mono",readOnly:u})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(q,{className:"font-mono text-xs",children:"Código *"}),e.jsx(U,{..._("code",{required:!0}),className:"font-mono",readOnly:u})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(q,{className:"font-mono text-xs",children:"Categoria"}),e.jsxs(H,{value:d,onValueChange:a=>k("category",a),disabled:u,children:[e.jsx(W,{className:"font-mono",children:e.jsx(J,{})}),e.jsxs(Y,{children:[e.jsx(x,{value:"league",children:"League"}),e.jsx(x,{value:"blog",children:"Blog"}),e.jsx(x,{value:"education",children:"Education"}),e.jsx(x,{value:"achievement",children:"Achievement"}),e.jsx(x,{value:"level",children:"Level"}),e.jsx(x,{value:"event",children:"Event"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(q,{className:"font-mono text-xs",children:"Raridade"}),e.jsxs(H,{value:N,onValueChange:a=>k("rarity",a),disabled:u,children:[e.jsx(W,{className:"font-mono",children:e.jsx(J,{})}),e.jsxs(Y,{children:[e.jsx(x,{value:"common",children:"Common"}),e.jsx(x,{value:"rare",children:"Rare"}),e.jsx(x,{value:"epic",children:"Epic"}),e.jsx(x,{value:"legendary",children:"Legendary"})]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(q,{className:"font-mono text-xs",children:"Max Supply"}),e.jsx(U,{..._("max_supply"),type:"number",placeholder:"â",className:"font-mono"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(q,{className:"font-mono text-xs",children:"Preç
3o RADC"}),e.jsx(U,{..._("radc_price"),type:"number",className:"font-mono"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(q,{className:"font-mono text-xs",children:"Bg Color"}),e.jsx(U,{..._("background_color"),placeholder:"#FFD700",className:"font-mono"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(q,{className:"font-mono text-xs",children:"Descrição"}),e.jsxs(L,{type:"button",variant:"ghost",size:"sm",className:"h-6 px-2 text-xs gap-1",onClick:s,disabled:T,children:[T?e.jsx(se,{className:"h-3 w-3 animate-spin"}):e.jsx(Ee,{className:"h-3 w-3"}),"Gerar com IA"]})]}),e.jsx(Ae,{..._("description"),className:"font-mono",rows:3})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(q,{className:"font-mono text-xs",children:"Imagem (thumbnail)"}),e.jsx(Ke,{value:g||null,category:d,rarity:N,code:E,itemId:i==null?void 0:i.id,onUploaded:a=>k("image_url",a),onRemoved:()=>k("image_url","")}),p&&e.jsxs("p",{className:"text-[10px] text-muted-foreground/60 font-mono",children:["Path: ",p]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(q,{className:"font-mono text-xs",children:"Requisito (eligibility)"}),e.jsx(U,{..._("eligibility_requirement"),placeholder:"ex: first_places",className:"font-mono",readOnly:u})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(q,{className:"font-mono text-xs",children:"Threshold"}),e.jsx(U,{..._("eligibility_threshold"),type:"number",className:"font-mono",readOnly:u})]})]}),u&&e.jsxs("div",{className:"space-y-3 pt-2 border-t border-border/40",children:[e.jsx(q,{className:"font-mono text-xs text-muted-foreground uppercase tracking-wider",children:"On-Chain"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(q,{className:"font-mono text-xs",children:"Token ID"}),e.jsx(U,{..._("onchain_token_id"),type:"number",placeholder:"â",className:"font-mono"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(q,{className:"font-mono text-xs",children:"Contract Address"}),e.jsx(U,{..._("contract_address"),placeholder:"0x...",className:"font-mono text-xs"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ce,{checked:b("is_active"),onCheckedChange:a=>k("is_active",a)}),e.jsx(q,{className:"font-mono text-xs",children:"Ativo"})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(L,{type:"button",variant:"outline",onClick:()=>v(!1),children:"Cancelar"}),e.jsx(L,{type:"submit",disabled:F.isPending,children:F.isPending?"Salvando...":u?"Salvar":"Criar"})]})]})]})})},He=[{id:"blog_author_1",name:"Autor Estreante",icon:"BookOpen",requirement:"blog_posts",threshold:1},{id:"blog_author_5",name:"Autor Ativo",icon:"BookOpen",requirement:"blog_posts",threshold:5},{id:"blog_author_10",name:"Autor Dedicado",icon:"BookOpen",requirement:"blog_posts",threshold:10},{id:"blog_author_25",name:"Autor Expert",icon:"BookOpen",requirement:"blog_posts",threshold:25},{id:"blog_author_50",name:"Autor Lenda",icon:"BookOpen",requirement:"blog_posts",threshold:50}];function We(n){return n>=1e3?"legendary":n>=500?"epic":n>=100?"rare":"common"}function le(n,v){return["catedratico_4","first_place_10","blog_author_50"].includes(v)||n>=25?"legendary":n>=10?"epic":n>=5?"rare":"common"}function Je(n){return n>=11?"legendary":n>=8?"epic":n>=5?"rare":"common"}function G(n){return n==="legendary"?100:n==="epic"?1e3:n==="rare"?5e3:1e4}const cs=()=>{const[n,v]=y.useState(!1),[i,z]=y.useState(null),[f,A]=y.useState([]),{toast:u}=X(),j=te();y.useState(null);const{data:T=[],isLoading:V}=Z({queryKey:["nft-catalog"],queryFn:async()=>{const{data:s,error:m}=await w.from("nft_catalog").select("*").order("category").order("rarity").order("name");if(m)throw m;return s??[]},staleTime:6e4}),_=Q({mutationFn:async s=>{if(s.image_url){const a="/object/public/nft-assets/",h=s.image_url.indexOf(a);if(h!==-1){const o=decodeURIComponent(s.image_url.substring(h+a.length));await w.storage.from("nft-assets").remove([o])}}const{error:m}=await w.from("nft_catalog").delete().eq("id",s.id);if(m)throw m},onSuccess:()=>{j.invalidateQueries({queryKey:["nft-catalog"]}),u({title:"Item removido"})}}),C=Q({mutationFn:async()=>{const s=new Set(T.map(r=>r.code)),m={},a=(r,l)=>{m[r]||(m[r]=[]),m[r].push(l)};for(const r of $e){if(s.has(r.type))continue;const l=We(r.xp);a("achievement",{code:r.type,name:r.name,description:r.description,category:"achievement",rarity:l,radc_price:0,max_supply:G(l),is_active:!0,eligibility_rules:{requirement:r.type,threshold:1}})}for(const r of ze){if(s.has(r.id))continue;const l=le(r.threshold,r.id);a("league",{code:r.id,name:r.name,description:`Conquista de liga: ${r.name}`,category:"league",rarity:l,radc_price:0,max_supply:G(l),is_active:!0,eligibility_rules:{requirement:r.requirement,threshold:r.threshold}})}for(const r of He){if(s.has(r.id))continue;const l=le(r.threshold,r.id);a("blog",{code:r.id,name:r.name,description:`Conquista de blog: ${r.name}`,category:"blog",rarity:l,radc_price:0,max_supply:G(l),is_active:!0,eligibility_rules:{requirement:r.requirement,threshold:r.threshold}})}for(const r of Ve){const l=`level_${r.level}`;if(s.has(l))continue;const $=Je(r.level);a("level",{code:l,name:r.name,description:`NÃvel ${r.level}: ${r.name}`,category:"level",rarity:$,radc_price:0,max_supply:G($),is_active:!0,eligibility_rules:{requirement:"level",threshold:r.level}})}const h=Object.keys(m);if(h.length===0)return 0;let o=0;const c=[];for(const r of h){const l=m[r],{error:$}=await w.from("nft_catalog").insert(l);$?(console.error(`[NFT Import] Falha na categoria "${r}":`,$.message),c.push(`${r}: ${$.message}`)):o+=l.length}if(c.length>0&&o===0)throw new Error(c.join("; "));return o},onSuccess:s=>{j.invalidateQueries({queryKey:["nft-catalog"]}),u({title:s?`${s} conquistas importadas`:"Todas as conquistas já estão no catálogo"})},onError:s=>{u({title:"Erro ao importar",description:s.message,variant:"destructive"})}}),k=s=>{z(s),v(!0)},b=()=>{z(null),v(!0)},B=s=>
3s.includes(",")||s.includes('"')||s.includes(` 4`)?`"${s.replace(/"/g,'""')}"`:s,S=s=>/\.(mp4|webm|mov)(\?|$)/i.test(s),F=()=>{if(f.length>0){const s=new Set(f);return T.filter(m=>s.has(m.id))}return T.filter(s=>s.is_active)},d=()=>{const s=F(),m="name,description,image,animation_url,background_color,Code,Rarity,Category,price_amount,price_currency,supply",a=s.map(l=>{const $=l.image_url&&!S(l.image_url)?l.image_url:"",M=l.image_url&&S(l.image_url)?l.image_url:"";return[B(l.name),B(l.description??""),$,M,l.background_color??"",l.code,l.rarity,l.category,"0","",l.max_supply!=null?String(l.max_supply):""].join(",")}),h=[m,...a].join(` 5`),o=new Blob([h],{type:"text/csv"}),c=URL.createObjectURL(o),r=document.createElement("a");r.href=c,r.download="nft-catalog.csv",r.click(),URL.revokeObjectURL(c)},N=()=>{const s=F().map(o=>{const c={name:o.name,description:o.description??"",background_color:o.background_color??"",attributes:[{trait_type:"Code",value:o.code},{trait_type:"Rarity",value:o.rarity},{trait_type:"Category",value:o.category}],supply:o.max_supply??void 0,price:0};return o.image_url&&(S(o.image_url)?c.animation_url=o.image_url:c.image=o.image_url),c}),m=new Blob([JSON.stringify(s,null,2)],{type:"application/json"}),a=URL.createObjectURL(m),h=document.createElement("a");h.href=a,h.download="nft-catalog-export.json",h.click(),URL.revokeObjectURL(a)},E=async s=>{var c;const m=(c=s.target.files)==null?void 0:c[0];if(!m)return;const h=(await m.text()).trim().split(` 6`).slice(1);let o=0;for(const r of h){const[l,$,M]=r.split(",").map(ge=>ge.trim());if(!l||!$)continue;const ae={onchain_token_id:Number($)};M&&(ae.contract_address=M);const{error:xe}=await w.from("nft_catalog").update(ae).eq("code",l);xe||o++}j.invalidateQueries({queryKey:["nft-catalog"]}),u({title:`${o} token IDs importados`}),s.target.value=""},[g,D]=y.useState(!1),{data:I}=Z({queryKey:["titles-nft-config"],queryFn:async()=>{const{data:s}=await w.from("system_settings").select("setting_value").eq("setting_key","titles_nft_config").single();return s?typeof s.setting_value=="string"?JSON.parse(s.setting_value):s.setting_value:null},staleTime:5*60*1e3}),{data:t}=Z({queryKey:["web3-chain-config-sync"],queryFn:async()=>{const{data:s}=await w.from("system_settings").select("setting_value").eq("setting_key","web3_chains").single();return s?typeof s.setting_value=="string"?JSON.parse(s.setting_value):s.setting_value:null},staleTime:5*60*1e3}),p=async()=>{var a,h;const s=(I==null?void 0:I.contract_address)||"0xcBA5FF261508fFba2737D26290043BA5Cda89f91",m=(t==null?void 0:t.default_chain_id)||84532;if(!s){u({title:"Contrato não configurado",description:"Configure o endereço do contrato em Admin > Web3 > TÃtulos NFT",variant:"destructive"});return}D(!0);try{const{data:o,error:c}=await w.functions.invoke("web3-sync-token-ids",{body:{contractAddress:s,chainId:m}});if(c)throw c;j.invalidateQueries({queryKey:["nft-catalog"]});const r=(a=o==null?void 0:o.errors)!=null&&a.length?`Erros: ${o.errors.slice(0,3).join("; ")}`:void 0;u({title:(o==null?void 0:o.message)||"Sincronização concluÃda",description:r,variant:(h=o==null?void 0:o.errors)!=null&&h.length?"destructive":"default"})}catch(o){u({title:"Erro ao sincronizar",description:o.message,variant:"destructive"})}finally{D(!1)}};return e.jsx(_e,{children:e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold font-mono text-foreground",children:"NFT Catalog"}),e.jsx("p",{className:"text-sm text-muted-foreground font-mono",children:"Gerencie tÃtulos e conquistas mintáveis como NFTs"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(L,{variant:"outline",size:"sm",onClick:()=>C.mutate(),disabled:C.isPending,children:[e.jsx(he,{className:"h-4 w-4 mr-1"}),C.isPending?"Importando...":"Importar Conquistas"]}),e.jsxs(L,{variant:"outline",size:"sm",onClick:d,children:[e.jsx(ne,{className:"h-4 w-4 mr-1"})," Exportar CSV",f.length>0?` (${f.length})`:""]}),e.jsxs(L,{variant:"outline",size:"sm",onClick:N,children:[e.jsx(ne,{className:"h-4 w-4 mr-1"})," JSON",f.length>0?` (${f.length})`:""]}),e.jsxs("label",{children:[e.jsx(L,{variant:"outline",size:"sm",asChild:!0,children:e.jsxs("span",{children:[e.jsx(Re,{className:"h-4 w-4 mr-1"})," Importar Token IDs"]})}),e.jsx("input",{type:"file",accept:".csv",className:"hidden",onChange:E})]}),e.jsxs(L,{variant:"outline",size:"sm",onClick:p,disabled:g,children:[e.jsx(Le,{className:`h-4 w-4 mr-1 ${g?"animate-spin":""}`}),g?"Sincronizando...":"Sync Token IDs"]}),e.jsxs(L,{size:"sm",onClick:b,children:[e.jsx(Fe,{className:"h-4 w-4 mr-1"})," Novo Item"]})]})]}),e.jsx(Ue,{items:T,isLoading:V,onEdit:k,onSelectionChange:A,onDelete:s=>{const m=T.find(a=>a.id===s);m&&_.mutate(m)}}),e.jsx(Qe,{open:n,onOpenChange:v,editingItem:i,allItems:T})]})})};export{cs 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.