1import{ca as ge,_ as V,eV as h,Z as r,s as o,j as e,bF as je,bG as pe,bH as Y,aY as ve,du as Ne,bI as Z,K as J,eX as X,eY as $,eZ as g,e_ as m,e$ as W,f0 as t,I as u,B as n,f7 as ee,aA as se,z as T,A as I,F as E,G as S,H as k,aQ as j,aR as p,N as A,P as ae}from"./index-Ck3jlJIO.js";import{b as i}from"./charts-ytYDs0Yq.js";import{A as fe}from"./AdminLayout-A-6FoqBw.js";import"./collapsible-B7wC1fNx.js";import"./categorias-de-parceiro-hIbo3PEn.js";const Ie=()=>{const x=ge(),[L,re]=i.useState("tags"),[te,f]=i.useState(!1),[ne,b]=i.useState(!1),[c,F]=i.useState(null),[v,D]=i.useState(""),[ie,y]=i.useState(!1),[de,w]=i.useState(!1),[d,C]=i.useState(null),[N,M]=i.useState(""),[_,H]=i.useState(""),{data:K=[],isLoading:Q}=V({queryKey:["admin-tags"],queryFn:async()=>{const{data:s,error:a}=await o.from("product_tags").select("*").order("name");if(a)throw a;return s}}),{data:U=[],isLoading:G}=V({queryKey:["admin-interests"],queryFn:async()=>{const{data:s,error:a}=await o.from("interests").select("*").order("name");if(a)throw a;return s}}),l=s=>s.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,""),q=h({mutationFn:async s=>{const{error:a}=await o.from("product_tags").insert({name:s,slug:l(s)});if(a)throw a},onSuccess:()=>{x.invalidateQueries({queryKey:["admin-tags"]}),D(""),f(!1),r({title:"Tag criada com sucesso!"})},onError:()=>{r({title:"Erro ao criar tag.",variant:"destructive"})}}),O=h({mutationFn:async s=>{const{error:a}=await o.from("product_tags").update({name:s.name,slug:l(s.name)}).eq("id",s.id);if(a)throw a},onSuccess:()=>{x.invalidateQueries({queryKey:["admin-tags"]}),F(null),b(!1),r({title:"Tag atualizada com sucesso!"})},onError:()=>{r({title:"Erro ao atualizar tag.",variant:"destructive"})}}),oe=h({mutationFn:async s=>{const{error:a}=await o.from("product_tags").delete().eq("id",s);if(a)throw a},onSuccess:()=>{x.invalidateQueries({queryKey:["admin-tags"]}),r({title:"Tag removida com sucesso!"})},onError:()=>{r({title:"Erro ao remover tag.",variant:"destructive"})}}),z=h({mutationFn:async({name:s,icon:a})=>{const B=l(s),{data:he}=await o.from("interests").select("id").eq("slug",B).maybeSingle();if(he)throw new Error("DUPLICATE_SLUG");const{error:R}=await o.from("interests").insert({name:s,slug:B,icon:a||null});if(R)throw R},onSuccess:()=>{x.invalidateQueries({queryKey:["admin-interests"]}),M(""),H(""),y(!1),r({title:"Interesse criado com sucesso!"})},onError:s=>{s.message==="DUPLICATE_SLUG"?r({title:"Erro ao criar interesse",description:"J
1á existe um interesse com esse nome.",variant:"destructive"}):r({title:"Erro ao criar interesse.",variant:"destructive"})}}),P=h({mutationFn:async s=>{const{error:a}=await o.from("interests").update({name:s.name,slug:l(s.name),icon:s.icon||null}).eq("id",s.id);if(a)throw a},onSuccess:()=>{x.invalidateQueries({queryKey:["admin-interests"]}),C(null),w(!1),r({title:"Interesse atualizado com sucesso!"})},onError:()=>{r({title:"Erro ao atualizar interesse.",variant:"destructive"})}}),le=h({mutationFn:async s=>{const{error:a}=await o.from("interests").delete().eq("id",s);if(a)throw a},onSuccess:()=>{x.invalidateQueries({queryKey:["admin-interests"]}),r({title:"Interesse removido com sucesso!"})},onError:()=>{r({title:"Erro ao remover interesse.",variant:"destructive"})}}),ce=()=>{if(!v.trim()){r({title:"Erro",description:"O nome da tag é obrigatório.",variant:"destructive"});return}q.mutate(v.trim())},me=()=>{if(!c||!c.name.trim()){r({title:"Erro",description:"O nome da tag é obrigatório.",variant:"destructive"});return}O.mutate(c)},ue=()=>{if(!N.trim()){r({title:"Erro",description:"O nome do interesse é obrigatório.",variant:"destructive"});return}z.mutate({name:N.trim(),icon:_.trim()})},xe=()=>{if(!d||!d.name.trim()){r({title:"Erro",description:"O nome do interesse é obrigatório.",variant:"destructive"});return}P.mutate(d)};return e.jsxs(fe,{title:"Tags e Interesses",subtitle:"Gerencie tags e interesses para classificar produtos",actions:L==="tags"?e.jsxs(n,{onClick:()=>f(!0),className:"gap-2",children:[e.jsx(ae,{className:"w-4 h-4"}),"Nova Tag"]}):e.jsxs(n,{onClick:()=>y(!0),className:"gap-2",children:[e.jsx(ae,{className:"w-4 h-4"}),"Novo Interesse"]}),children:[e.jsxs(je,{value:L,onValueChange:re,className:"w-full",children:[e.jsxs(pe,{className:"grid w-full max-w-md grid-cols-2 mb-6",children:[e.jsxs(Y,{value:"tags",className:"gap-2",children:[e.jsx(ve,{className:"w-4 h-4"}),"Tags"]}),e.jsxs(Y,{value:"interests",className:"gap-2",children:[e.jsx(Ne,{className:"w-4 h-4"}),"Interesses"]})]}),e.jsxs(Z,{value:"tags",children:[e.jsxs("div",{className:"bg-primary/10 border border-primary/20 rounded-xl p-4 mb-6 flex items-start gap-3",children:[e.jsx(J,{className:"w-5 h-5 text-deep mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"text-sm text-foreground",children:[e.jsx("p",{className:"font-medium mb-1",children:"Como funcionam as tags?"}),e.jsxs("p",{className:"text-muted-foreground",children:["Tags são usadas para ativar funções especiais. Por exemplo, adicionar a tag",e.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded mx-1",children:"atracoes-imperdiveis"}),'a um produto fará com que ele apareça na seção "Atrações ImperdÃveis" da página inicial.']})]})]}),e.jsxs("div",{className:"bg-card border border-border rounded-xl overflow-hidden",children:[e.jsx("div",{className:"overflow-x-auto -mx-3 sm:mx-0",children:e.jsxs(X,{children:[e.jsx($,{children:e.jsxs(g,{className:"border-border",children:[e.jsx(m,{className:"text-foreground",children:"Nome"}),e.jsx(m,{className:"text-foreground",children:"Slug"}),e.jsx(m,{className:"text-foreground text-right",children:"Ações"})]})}),e.jsx(W,{children:Q?Array.from({length:3}).map((s,a)=>e.jsxs(g,{children:[e.jsx(t,{children:e.jsx(u,{className:"w-32 h-4"})}),e.jsx(t,{children:e.jsx(u,{className:"w-24 h-4"})}),e.jsx(t,{children:e.jsx(u,{className:"w-20 h-8 ml-auto"})})]},a)):K.map(s=>e.jsxs(g,{className:"border-border",children:[e.jsx(t,{className:"font-medium text-foreground",children:s.name}),e.jsx(t,{className:"text-muted-foreground",children:e.jsx("code",{className:"bg-muted px-2 py-1 rounded text-sm",children:s.slug})}),e.jsx(t,{className:"text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(n,{variant:"ghost",size:"icon",onClick:()=>{F(s),b(!0)},children:e.jsx(ee,{className:"w-4 h-4"})}),e.jsx(n,{variant:"ghost",size:"icon",className:"text-destructive-ink hover:text-destructive-ink",onClick:()=>oe.mutate(s.id),children:e.jsx(se,{className:"w-4 h-4"})})]})})]},s.id))})]})}),!Q&&K.length===0&&e.jsx("div",{className:"p-12 text-center text-muted-foreground",children:"Nenhuma tag cadastrada."})]})]}),e.jsxs(Z,{value:"interests",children:[e.jsxs("div",{className:"bg-primary/10 border border-primary/20 rounded-xl p-4 mb-6 flex items-start gap-3",children:[e.jsx(J,{className:"w-5 h-5 text-deep mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"text-sm text-foreground",children:[e.jsx("p",{className:"font-medium mb-1",children:"Como funcionam os interesses?"}),e.jsx("p",{className:"text-muted-foreground",children:"Interesses são usados para filtrar produtos por perfil de cliente. Exemplos: Casais, FamÃlia, Aventura, Natureza. Você pode atribuir interesses aos produtos para ajudar os clientes a encontrar atrações adequadas."})]})]}),e.jsxs("div",{className:"bg-card border border-border rounded-xl overflow-hidden",children:[e.jsx("div",{className:"overflow-x-auto -mx-3 sm:mx-0",children:e.jsxs(X,{children:[e.jsx($,{children:e.jsxs(g,{className:"border-border",children:[e.jsx(m,{className:"text-foreground",children:"Nome"}),e.jsx(m,{className:"text-foreground",children:"Slug"}),e.jsx(m,{className:"text-foreground",children:"Ãcone"}),e.jsx(m,{className:"text-foreground text-right",children:"Ações"})]})}),e.jsx(W,{children:G?Array.from({length:3}).map((s,a)=>e.jsxs(g,{children:[e.jsx(t,{children:e.jsx(u,{className:"w-32 h-4"})}),e.jsx(t,{children:e.jsx(u,{className:"w-24 h-4"})}),e.jsx(t,{children:e.jsx(u,{className:"w-16 h-4"})}),e.jsx(t,{children:e.jsx(u,{className:"w-20 h-8 ml-auto"})})]},a)):U.map(s=>e.jsxs(g,{className:"border-border",children:[e.jsx(t,{className:"font-medium text-foreground",children:s.name}),e.jsx(t,{className:"text-muted-foreground",children:e.jsx("code",{className:"bg-muted px-2 py-1 rounded text-sm",children:s.slug})}),e.jsx(t,{className:"text-muted-foreground",children:s.icon||"-"}),e.jsx(t,{className:"text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(n,{variant:"ghost",size:"icon",onClick:()=>{C(s),w(!0)},children:e.jsx(ee,{className:"w-4 h-4"})}),e.jsx(n,{variant:"ghost",size:"icon",className:"text-destructive-ink hover:text-destructive-ink",onClick:()=>le.mutate(s.id),children:e.jsx(se,{className:"w-4 h-4"})})]})})]},s.id))})]})}),!G&&U.length===0&&e.jsx("div",{className:"p-12 text-center text-muted-foreground",children:"Nenhum interesse cadastrado."})]})]})]}),e.jsx(T,{open:te,onOpenChange:f,children:e.jsxs(I,{className:"bg-background border-border",children:[e.jsxs(E,{children:[e.jsx(S,{children:"Nova Tag"}),e.jsx(k,{children:"Crie uma nova tag para ativar funções especiais em produtos."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{htmlFor:"tag-name",children:"Nome da Tag"}
1),e.jsx(p,{id:"tag-name",value:v,onChange:s=>D(s.target.value),placeholder:"Ex: Atrações ImperdÃveis"})]}),v&&e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Slug: ",e.jsx("code",{className:"bg-muted px-2 py-1 rounded",children:l(v)})]})]}),e.jsxs(A,{children:[e.jsx(n,{variant:"outline",onClick:()=>f(!1),children:"Cancelar"}),e.jsx(n,{onClick:ce,disabled:q.isPending,children:q.isPending?"Salvando...":"Salvar"})]})]})}),e.jsx(T,{open:ne,onOpenChange:b,children:e.jsxs(I,{className:"bg-background border-border",children:[e.jsxs(E,{children:[e.jsx(S,{children:"Editar Tag"}),e.jsx(k,{children:"Atualize as informações da tag."})]}),c&&e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{htmlFor:"edit-tag-name",children:"Nome da Tag"}),e.jsx(p,{id:"edit-tag-name",value:c.name,onChange:s=>F({...c,name:s.target.value})})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Slug: ",e.jsx("code",{className:"bg-muted px-2 py-1 rounded",children:l(c.name)})]})]}),e.jsxs(A,{children:[e.jsx(n,{variant:"outline",onClick:()=>b(!1),children:"Cancelar"}),e.jsx(n,{onClick:me,disabled:O.isPending,children:O.isPending?"Salvando...":"Salvar"})]})]})}),e.jsx(T,{open:ie,onOpenChange:y,children:e.jsxs(I,{className:"bg-background border-border",children:[e.jsxs(E,{children:[e.jsx(S,{children:"Novo Interesse"}),e.jsx(k,{children:"Crie um novo interesse para classificar produtos por perfil de cliente."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{htmlFor:"interest-name",children:"Nome do Interesse"}),e.jsx(p,{id:"interest-name",value:N,onChange:s=>M(s.target.value),placeholder:"Ex: Casais, FamÃlia, Aventura"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{htmlFor:"interest-icon",children:"Ãcone (opcional)"}),e.jsx(p,{id:"interest-icon",value:_,onChange:s=>H(s.target.value),placeholder:"Ex: Heart, Users, Mountain"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Nome do Ãcone Lucide (ex: Heart, Users, Mountain)"})]}),N&&e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Slug: ",e.jsx("code",{className:"bg-muted px-2 py-1 rounded",children:l(N)})]})]}),e.jsxs(A,{children:[e.jsx(n,{variant:"outline",onClick:()=>y(!1),children:"Cancelar"}),e.jsx(n,{onClick:ue,disabled:z.isPending,children:z.isPending?"Salvando...":"Salvar"})]})]})}),e.jsx(T,{open:de,onOpenChange:w,children:e.jsxs(I,{className:"bg-background border-border",children:[e.jsxs(E,{children:[e.jsx(S,{children:"Editar Interesse"}),e.jsx(k,{children:"Atualize as informações do interesse."})]}),d&&e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{htmlFor:"edit-interest-name",children:"Nome do Interesse"}),e.jsx(p,{id:"edit-interest-name",value:d.name,onChange:s=>C({...d,name:s.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{htmlFor:"edit-interest-icon",children:"Ãcone (opcional)"}),e.jsx(p,{id:"edit-interest-icon",value:d.icon||"",onChange:s=>C({...d,icon:s.target.value}),placeholder:"Ex: Heart, Users, Mountain"})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Slug: ",e.jsx("code",{className:"bg-muted px-2 py-1 rounded",children:l(d.name)})]})]}),e.jsxs(A,{children:[e.jsx(n,{variant:"outline",onClick:()=>w(!1),children:"Cancelar"}),e.jsx(n,{onClick:xe,disabled:P.isPending,children:P.isPending?"Salvando...":"Salvar"})]})]})})]})};export{Ie 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.