PageSourceSearch

https://institutoshamma.com.br/assets/AdminNewsletter-B9TfZ5Nz.js

js institutoshamma.com.br collected 2026-10-10 02:11:48 UTC 36,896 bytes, 42 lines download raw bytes

1import{j as e}from"./ui-btqpfyNG.js";import{r as j}from"./vendor-CqDko4ft.js";import{C as N,g as b,h as C,i as K,d as w,L as S,B as o,D as ne,dq as Z,e3 as H,b_ as ie,f as h,ai as we,aU as gs,u as vs,bI as fs,W as I,bJ as U,s as d,aM as Pe,e5 as ge,am as Ns,b8 as ws,ao as ys,ap as bs,aq as L,cw as Be,ei as ve,ej as Ue,bV as fe,as as F,dW as Cs,I as Ne,S as Ke,ek as Ss,el as _s,aE as He,aH as As,cJ as Es,dJ as ks,dM as Ts,dN as qs,dO as $s,dP as Ds,dQ as Is,dR as Ls,dS as Fs,dT as Rs,N as zs,O as Os,P as Ms,R as Ps,U as Bs,o as te,z as Us,T as Ks,em as Hs,aD as Qs,b2 as Vs,a3 as Ws}from"./index-Dkxve5aJ.js";import{A as Gs}from"./AdminLayout-BPr026bf.js";import{T as J,a as X,b as A,c as l,d as Y,e as c}from"./table-dknoDbOx.js";import{S as Js,a as Xs,b as Ys,c as Zs,d as ea}from"./select-DeN1dNMp.js";import"./AdminSidebar-CSRA0t9v.js";import"./sheet-DKkVoy75.js";const v={navy:"#0e2335",ivory:"#f3efe7",card:"#fcfbf8",gold:"#d8ac5a",mutedForeground:"#4f6572",border:"#d2cabc"},Qe="Georgia, 'Times New Roman', serif",sa="Helvetica, Arial, sans-serif",aa="https://institutoshamma.com.br/logo.png";function ta({title:n,excerpt:E,featuredImage:f,articleUrl:g}){const t=new Date().getFullYear();return`
2<!DOCTYPE html>
3<html lang="pt-BR">
4<head>
5<meta charset="UTF-8">
6<meta name="viewport" content="width=device-width, initial-scale=1.0">
7<title>${n}</title>
8</head>
9<body style="margin:0;padding:0;background-color:${v.ivory};font-family:${sa};">
10<table role="presentation" width="100%" cellspacing="0" cellpadding="0" style="background-color:${v.ivory};">
11<tr><td align="center" style="padding:32px 16px;">
12<table role="presentation" width="100%" style="max-width:560px;margin:0 auto;">
13
14<tr><td align="center" style="background-color:${v.navy};border-radius:16px 16px 0 0;padding:32px 24px;">
15<img src="${aa}" width="56" height="56" alt="Instituto SHAMMA" style="display:block;border-radius:50%;margin:0 auto 12px;">
16<p style="margin:0;color:${v.gold};font-size:11px;letter-spacing:4px;text-transform:uppercase;">Instituto</p>
17<p style="margin:2px 0 0;color:#ffffff;font-size:20px;letter-spacing:2px;font-weight:700;font-family:${Qe};">SHAMMA</p>
18</td></tr>
19
20<tr><td style="background-color:${v.card};border:1px solid ${v.border};border-top:none;overflow:hidden;">
21${f?`<img src="${f}" alt="${n}" style="width:100%;height:220px;object-fit:cover;display:block;">`:""}
22<div style="padding:32px;">
23<p style="margin:0 0 12px;color:${v.gold};font-size:12px;letter-spacing:2px;text-transform:uppercase;font-weight:700;">Novo artigo</p>
24<h1 style="margin:0 0 16px;color:${v.navy};font-size:24px;font-weight:700;font-family:${Qe};line-height:1.3;">${n}</h1>
25<p style="margin:0 0 24px;color:${v.mutedForeground};font-size:15px;line-height:1.7;">${E}</p>
26<table role="presentation" cellspacing="0" cellpadding="0"><tr><td style="background-color:${v.gold};border-radius:999px;">
27<a href="${g}" target="_blank" style="display:inline-block;padding:14px 32px;color:${v.navy};font-size:15px;font-weight:700;text-decoration:none;">Continuar lendo</a>
28</td></tr></table>
29</div>
30</td></tr>
31
32<tr><td align="center" style="border-radius:0 0 16px 16px;background-color:${v.card};border:1px solid ${v.border};border-top:none;padding:20px 16px;">
33<p style="margin:0;color:${v.mutedForeground};font-size:12px;">© ${t} Instituto SHAMMA</p>
34</td></tr>
35
36</table>
37</td></tr>
38</table>
39</body>
40</html>`}const re=["agendada","enviando"];function na({itens:n,carregando:E,onCancelar:f,cancelando:g}){return e.jsxs(N,{children:[e.jsxs(b,{children:[e.jsx(C,{children:"Artigos a caminho da lista"}),e.jsxs(K,{children:["Todo artigo publicado vira newsletter sozinho ",e.jsx("strong",{children:"1 hora depois"}),". Nessa hora você pode corrigir o texto (a correção vai junto) ou cancelar o envio. Passado o prazo, sai para todos os inscritos — sem precisar clicar em nada."]})]}),e.jsx(w,{className:"p-0",children:E?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(S,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):n.length>0?e.jsxs(J,{children:[e.jsx(X,{children:e.jsxs(A,{children:[e.jsx(l,{children:"Artigo"}),e.jsx(l,{className:"hidden md:table-cell",children:"Sai em"}),e.jsx(l,{children:"Situação"}),e.jsx(l,{className:"text-right w-[120px]",children:"Ações"})]})}),e.jsx(Y,{children:n.map(t=>e.jsxs(A,{children:[e.jsx(c,{className:"font-medium max-w-xs truncate",children:t.titulo}),e.jsx(c,{className:"hidden md:table-cell text-muted-foreground",children:new Date(t.agendado_para).toLocaleStr
40ing("pt-BR",{day:"2-digit",month:"2-digit",hour:"2-digit",minute:"2-digit",timeZone:"America/Sao_Paulo"})}),e.jsxs(c,{children:[t.status==="agendada"&&e.jsxs(o,{variant:"secondary",className:"gap-1",children:[e.jsx(ne,{className:"h-3 w-3"})," Aguardando"]}),t.status==="enviando"&&e.jsxs(o,{className:"gap-1",children:[e.jsx(Z,{className:"h-3 w-3"})," Enviando ",t.enviados,"/",t.total_ativos]}),t.status==="enviada"&&e.jsxs(o,{variant:"outline",className:"gap-1 text-green-700 border-green-700",children:[e.jsx(H,{className:"h-3 w-3"})," Enviada para ",t.enviados]}),t.status==="cancelada"&&e.jsx(o,{variant:"outline",children:"Cancelada"}),t.status==="falhou"&&e.jsxs(o,{variant:"destructive",className:"gap-1",children:[e.jsx(ie,{className:"h-3 w-3"})," Falhou"]}),t.erro&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1 max-w-xs truncate",children:t.erro})]}),e.jsx(c,{className:"text-right",children:re.includes(t.status)&&e.jsx(h,{variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>f(t.id),disabled:g,children:"Cancelar"})})]},t.id))})]}):e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(ne,{className:"h-12 w-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:"Nenhum artigo na fila"}),e.jsx("p",{className:"text-xs mt-1",children:"Quando você publicar um artigo, ele aparece aqui com 1 hora de janela."})]})})]})}function ia({edicoes:n,carregando:E,onCancelar:f,cancelando:g}){return e.jsxs(N,{children:[e.jsxs(b,{children:[e.jsxs(C,{className:"flex items-center gap-2",children:[e.jsx(we,{className:"h-5 w-5"})," Leituras da semana"]}),e.jsxs(K,{children:["Toda ",e.jsx("strong",{children:"quinta-feira às 9h"})," o site escolhe ",e.jsx("strong",{children:"5 artigos do acervo"}),", de temas variados e sem repetir os que já saíram, e envia para a lista. O e-mail pede que cada pessoa compartilhe no WhatsApp, no Facebook e no Instagram — é assim que o acervo chega em quem ainda não conhece o Instituto."]})]}),e.jsx(w,{className:"p-0",children:E?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(S,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):n.length>0?e.jsx("div",{className:"divide-y",children:n.map(t=>e.jsxs("div",{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"font-medium",children:["Semana de"," ",new Date(`${t.semana_inicio}T12:00:00`).toLocaleDateString("pt-BR",{day:"2-digit",month:"long"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:new Date(t.agendado_para).toLocaleString("pt-BR",{day:"2-digit",month:"2-digit",hour:"2-digit",minute:"2-digit",timeZone:"America/Sao_Paulo"})})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[t.status==="agendada"&&e.jsxs(o,{variant:"secondary",className:"gap-1",children:[e.jsx(ne,{className:"h-3 w-3"})," Aguardando"]}),t.status==="enviando"&&e.jsxs(o,{className:"gap-1",children:[e.jsx(Z,{className:"h-3 w-3"})," Enviando ",t.enviados,"/",t.total_ativos]}),t.status==="enviada"&&e.jsxs(o,{variant:"outline",className:"gap-1 text-green-700 border-green-700",children:[e.jsx(H,{className:"h-3 w-3"})," Enviada para ",t.enviados]}),t.status==="cancelada"&&e.jsx(o,{variant:"outline",children:"Cancelada"}),t.status==="falhou"&&e.jsxs(o,{variant:"destructive",className:"gap-1",children:[e.jsx(ie,{className:"h-3 w-3"})," Falhou"]}),re.includes(t.status)&&e.jsx(h,{variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>f(t.id),disabled:g,children:"Cancelar"})]})]}),e.jsx("ol",{className:"text-sm text-muted-foreground space-y-1 list-decimal list-inside",children:t.titulos.map(k=>e.jsx("li",{className:"truncate",children:k},k))}),t.erro&&e.jsx("p",{className:"text-xs text-destructive",children:t.erro})]},t.id))}):e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(we,{className:"h-12 w-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:"Nenhuma edição ainda"}),e.jsx("p",{className:"text-xs mt-1",children:"A primeira sai na próxima quinta-feira, às 9h, com 5 artigos escolhidos na hora."})]})})]})}const ua=()=>{const{toast:n}=gs(),{isAdmin:E,user:f}=vs(),g=fs(),t=j.useRef(null),[k,Ve]=j.useState(""),[le,ce]=j.useState(null),[We,R]=j.useState(!1),[$,Q]=j.useState(""),[D,z]=j.useState(""),[oe,Ge]=j.useState(""),[ee,ye]=j.useState(!1),[de,me]=j.useState(null),[Je,be]=j.useState(null),[Xe,Ye]=j.useState("subscribers"),[_,xe]=j.useState([]),[V,Ce]=j.useState(!1),[Se,he]=j.useState(""),[_e,se]=j.useState(""),[T,O]=j.useState(null),{data:u,isLoading:Ze}=I({queryKey:["admin-newsletter-subscribers",k],queryFn:async()=>{let s=d.from("newsletter_subscribers").select("*").order("created_at",{ascending:!1});k&&(s=s.or(`name.ilike.%${k}%,email.ilike.%${k}%`));const{data:a,error:i}=await s;if(i)throw i;return a}}),{data:y,isLoading:es}=I({queryKey:["admin-newsletter-campaigns"],queryFn:async()=>{const{data:s,error:a}=await d.from("newsletter_campaigns").select("*").order("sent_at",{ascending:!1});if(a)throw a;return await Promise.all((s||[]).map(async m=>{const{data:p}=await d.from("newsletter_tracking").select("event_type, email").eq("campaign_id",m.id),q=new Set(p==null?void 0:p.filter(r=>r.event_type==="opened").map(r=>r.email)).size,x=new Set(p==null?void 0:p.filter(r=>r.event_type==="clicked").map(r=>r.email)).size;return{...m,uniqueOpens:q,uniqueClicks:x}}))}}),{data:Ae,isLoading:ss}=I({queryKey:["admin-newsletter-fila"],queryFn:async()=>{const{data:s,error:a}=await d.rpc("shan_newsletter_na_fila");if(a)throw a;return s??[]},refetchInterval:3e4}),Ee=(Ae??[]).filter(s=>re.includes(s.status)),ke=U({mutationFn:async s=>{const{error:a}=await d.from("shan_newsletter_agendada").update({status:"cancelada",cancelada_por:(f==null?void 0:f.id)??null}).eq("id",s);if(a)throw a},onSuccess:()=>{g.invalidateQueries({queryKey:["admin-newsletter-fila"]}),n({title:"Envio cancelado",description:"Este artigo não será enviado para a lista."})},onError:s=>n({title:"Não deu para cancelar",description:s.message,variant:"destructive"})}),{data:Te,isLoading:as}=I({queryKey:["admin-newsletter-digest"],queryFn:async()=>{const{data:s,error:a}=await d.rpc("shan_digest_na_fila");if(a)throw a;return s??[]},refetchInterval:3e4}),qe=(Te??[]).filter(s=>re.includes(s.status)),$e=U({mutationFn:async s=>{const{error:a}=await d.from("shan_digest_semanal").update({status:"cancelada",cancelada_por:(f==null?void 0:f.id)??null}).eq("id",s);if(a)throw a},onSuccess:()=>{g.invalidateQueries({queryKey:["admin-newsletter-digest"]}),n({title:"Edição cancelada",description:"Esta semana não sai o e-mail de leituras."})},onError:s=>n({title:"Não deu para cancelar",description:s.message,variant:"destructive"})}),{data:M,isLoading:ts}=I({queryKey:["admin-newsletter-templates"],queryFn:async()=>{const{data:s,error:a}=await d.from("newsletter_templates").select("*").order("is_default",{ascending:!1});if(a)throw a;return s}}),{data:P,isLoading:ns}=I({queryKey:["admin-newsletter-drafts"],queryFn:async()=>{const{data:s,error:a}=await d.from("newsletter_campaign_drafts").select("id, subject, html_content, article_id, updated_at").order("updated_at",{ascending:!1});if(a)throw a;return s}}),{data:B}=I({queryKey:["admin-newsletter-articles"],queryFn:async()=>{const{data:s,error:a}=await d.from("articles").select("id, title, slug, excerpt, featured_image").eq("status","published").order("published_at",{ascending:!1}).limit(50);if(a)throw a;return s}}),is=U({mutationFn:async({id:s,isActive:a})=>{const{error:i}=await d.from("newsletter_subscribers").update({is_active:!a,unsubscribed_at:a?new Date().toISOString():null}).eq("id",s);if(i)throw i},onSuccess:()=>{g.invalidateQueries({queryKey:["admin-newsletter-subscribers"]}
40),n({title:"Status atualizado"})},onError:()=>{n({title:"Erro ao atualizar status",variant:"destructive"})}}),rs=U({mutationFn:async s=>{const{error:a}=await d.from("newsletter_subscribers").delete().eq("id",s);if(a)throw a},onSuccess:()=>{g.invalidateQueries({queryKey:["admin-newsletter-subscribers"]}),n({title:"Inscrito removido"}),ce(null)},onError:()=>{n({title:"Erro ao remover inscrito",variant:"destructive"})}}),ue=U({mutationFn:async()=>{if(!$.trim()||!D.trim())throw new Error("Preencha o assunto e o conteúdo antes de salvar");const s={subject:$,html_content:D,article_id:_e||null};if(T){const{error:m}=await d.from("newsletter_campaign_drafts").update(s).eq("id",T);if(m)throw m;return T}const{data:a,error:i}=await d.from("newsletter_campaign_drafts").insert(s).select("id").single();if(i)throw i;return a.id},onSuccess:s=>{O(s),g.invalidateQueries({queryKey:["admin-newsletter-drafts"]}),n({title:"Rascunho salvo"})},onError:s=>{n({title:"Erro ao salvar rascunho",description:s instanceof Error?s.message:"Tente novamente",variant:"destructive"})}}),ls=U({mutationFn:async s=>{const{error:a}=await d.from("newsletter_campaign_drafts").delete().eq("id",s);if(a)throw a;return s},onSuccess:s=>{g.invalidateQueries({queryKey:["admin-newsletter-drafts"]}),T===s&&O(null),n({title:"Rascunho removido"})},onError:()=>{n({title:"Erro ao remover rascunho",variant:"destructive"})}}),cs=()=>{O(null),Q(""),z(""),se(""),be(null),R(!0)},os=s=>{O(s.id),Q(s.subject),z(s.html_content),se(s.article_id||""),R(!0),n({title:"Rascunho carregado"})},ds=s=>{const a=window.location.origin;return ta({title:s.title,excerpt:(s.excerpt||"Confira este novo artigo do Instituto SHAMMA.").substring(0,300),featuredImage:s.featured_image,articleUrl:`${a}/${s.slug}`})},ms=s=>{se(s);const a=B==null?void 0:B.find(i=>i.id===s);a&&(Q(`✨ Novo Artigo: ${a.title}`),z(ds(a)),n({title:`Artigo "${a.title}" selecionado`}))},De=async s=>{if(!$.trim()||!D.trim()){n({title:"Preencha o assunto e conteúdo",variant:"destructive"});return}if(s&&!oe.trim()){n({title:"Informe o email de teste",variant:"destructive"});return}ye(!0),me(null);try{let a,i=0,m=0,p=0;const q=60;for(;;){const x=await d.functions.invoke("send-newsletter",{body:{subject:$,htmlContent:D,testEmail:s?oe:void 0,campaignId:a}});if(x.error)throw new Error(x.error.message);const r=x.data;if(!(r!=null&&r.success))throw new Error((r==null?void 0:r.error)||"Erro ao enviar");if(i+=r.sent??0,m+=r.failed??0,a=r.campaignId??a,!(r.remaining>0)||s)break;if(++p>=q)throw new Error(`Envio interrompido por segurança após ${i} e-mails; reabra e envie de novo para continuar de onde parou.`);me({enviados:i,restantes:r.remaining})}n({title:s?"Email de teste enviado!":"Newsletter enviada!",description:`${i} email(s) enviado(s)${m?`, ${m} falhou`:""}`}),s||(T&&(await d.from("newsletter_campaign_drafts").delete().eq("id",T),g.invalidateQueries({queryKey:["admin-newsletter-drafts"]})),R(!1),Q(""),z(""),se(""),O(null),g.invalidateQueries({queryKey:["admin-newsletter-campaigns"]}))}catch(a){console.error("Send newsletter error:",a),n({title:"Erro ao enviar newsletter",description:a instanceof Error?a.message:"Tente novamente",variant:"destructive"})}finally{ye(!1),me(null)}},Ie=s=>{z(s.html_content),be(s.id),n({title:`Template "${s.name}" aplicado`})},xs=()=>{if(!u||u.length===0)return;const s=["Nome","Email","Ativo","Confirmado","Origem","Data de Inscrição"],a=u.map(x=>[x.name,x.email,x.is_active?"Sim":"Não",x.is_confirmed?"Sim":"Não",x.source||"website",new Date(x.subscribed_at).toLocaleDateString("pt-BR")]),i=[s.join(","),...a.map(x=>x.map(r=>`"${r}"`).join(","))].join(`
41`),m=new Blob([i],{type:"text/csv;charset=utf-8;"}),p=URL.createObjectURL(m),q=document.createElement("a");q.href=p,q.download=`newsletter-inscritos-${new Date().toISOString().split("T")[0]}.csv`,q.click(),URL.revokeObjectURL(p)},hs=s=>{var m;const a=(m=s.target.files)==null?void 0:m[0];if(!a)return;he(a.name);const i=new FileReader;i.onload=p=>{var Oe;const x=((Oe=p.target)==null?void 0:Oe.result).split(`
42`).filter(G=>G.trim()),r=x[0].toLowerCase().includes("nome")||x[0].toLowerCase().includes("email")?1:0,ze=[];for(let G=r;G<x.length;G++){const je=x[G].split(/[,;]/).map(ae=>ae.trim().replace(/^["']|["']$/g,""));if(je.length>=2){const ae=je[0],Me=je[1].toLowerCase(),js=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;ze.push({name:ae,email:Me,valid:js.test(Me)&&ae.length>=2})}}xe(ze)},i.readAsText(a)},Le=async(s=!1)=>{const a=_.filter(i=>i.valid);if(a.length===0){n({title:"Nenhum inscrito válido para importar",variant:"destructive"});return}Ce(!0);try{const i=await d.functions.invoke("import-subscribers",{body:{subscribers:a.map(p=>({name:p.name,email:p.email})),markAsConfirmed:!0,source:"import"}});if(i.error)throw new Error(i.error.message);const m=i.data;
42n({title:"Importação concluída!",description:`${m.imported} importados, ${m.duplicates} duplicados, ${m.errors} erros`}),s&&m.imported>0&&(n({title:"Enviando emails de boas-vindas...",description:"Isso pode levar alguns minutos."}),await d.functions.invoke("send-welcome-email",{body:{sendToAll:!0}}),n({title:"Emails de boas-vindas enviados!"})),xe([]),he(""),t.current&&(t.current.value=""),g.invalidateQueries({queryKey:["admin-newsletter-subscribers"]})}catch(i){console.error("Import error:",i),n({title:"Erro na importação",description:i instanceof Error?i.message:"Tente novamente",variant:"destructive"})}finally{Ce(!1)}},us=async()=>{try{n({title:"Enviando emails de boas-vindas...",description:"Isso pode levar alguns minutos."});const{data:s,error:a}=await d.functions.invoke("send-welcome-email",{body:{sendToAll:!0}});if(a)throw a;n({title:"Emails enviados!",description:`${s.sent} emails de boas-vindas enviados`})}catch(s){n({title:"Erro ao enviar",description:s instanceof Error?s.message:"Tente novamente",variant:"destructive"})}},pe=(u==null?void 0:u.filter(s=>s.is_active).length)||0,ps=(u==null?void 0:u.filter(s=>s.is_confirmed).length)||0,W=(y==null?void 0:y.reduce((s,a)=>s+a.total_sent,0))||0,Fe=(y==null?void 0:y.reduce((s,a)=>s+(a.uniqueOpens||0),0))||0,Re=(y==null?void 0:y.reduce((s,a)=>s+(a.uniqueClicks||0),0))||0;return e.jsxs(Gs,{title:"Newsletter",description:"Gerencie inscritos, envie newsletters e acompanhe estatísticas",actions:e.jsxs("div",{className:"admin-actions",children:[e.jsxs(h,{size:"sm",onClick:cs,className:"whitespace-nowrap",children:[e.jsx(Z,{className:"h-4 w-4 mr-1 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Enviar Newsletter"}),e.jsx("span",{className:"sm:hidden",children:"Enviar"})]}),e.jsxs(h,{size:"sm",onClick:xs,variant:"outline",disabled:!(u!=null&&u.length),className:"whitespace-nowrap",children:[e.jsx(Ws,{className:"h-4 w-4 mr-1 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Exportar CSV"}),e.jsx("span",{className:"sm:hidden",children:"CSV"})]})]}),children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"admin-grid-stats",children:[e.jsxs(N,{children:[e.jsx(b,{className:"pb-2",children:e.jsxs(C,{className:"text-sm font-medium text-muted-foreground flex items-center gap-2",children:[e.jsx(Pe,{className:"h-4 w-4"}),"Total Inscritos"]})}),e.jsx(w,{children:e.jsx("p",{className:"text-2xl font-bold",children:(u==null?void 0:u.length)||0})})]}),e.jsxs(N,{children:[e.jsx(b,{className:"pb-2",children:e.jsxs(C,{className:"text-sm font-medium text-muted-foreground flex items-center gap-2",children:[e.jsx(ge,{className:"h-4 w-4"}),"Ativos / Confirmados"]})}),e.jsx(w,{children:e.jsxs("p",{className:"text-2xl font-bold text-green-600",children:[pe," / ",ps]})})]}),e.jsxs(N,{children:[e.jsx(b,{className:"pb-2",children:e.jsxs(C,{className:"text-sm font-medium text-muted-foreground flex items-center gap-2",children:[e.jsx(Z,{className:"h-4 w-4"}),"Emails Enviados"]})}),e.jsx(w,{children:e.jsx("p",{className:"text-2xl font-bold",children:W})})]}),e.jsxs(N,{children:[e.jsx(b,{className:"pb-2",children:e.jsxs(C,{className:"text-sm font-medium text-muted-foreground flex items-center gap-2",children:[e.jsx(Ns,{className:"h-4 w-4"}),"Aberturas"]})}),e.jsxs(w,{children:[e.jsx("p",{className:"text-2xl font-bold text-blue-600",children:Fe}),W>0&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[(Fe/W*100).toFixed(1),"% taxa"]})]})]}),e.jsxs(N,{children:[e.jsx(b,{className:"pb-2",children:e.jsxs(C,{className:"text-sm font-medium text-muted-foreground flex items-center gap-2",children:[e.jsx(ws,{className:"h-4 w-4"}),"Cliques"]})}),e.jsxs(w,{children:[e.jsx("p",{className:"text-2xl font-bold text-purple-600",children:Re}),W>0&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[(Re/W*100).toFixed(1),"% taxa"]})]})]})]}),e.jsxs(ys,{value:Xe,onValueChange:Ye,children:[e.jsx("div",{className:"overflow-x-auto scrollbar-hide -mx-3 px-3 sm:mx-0 sm:px-0",children:e.jsxs(bs,{className:"w-max sm:w-auto",children:[e.jsxs(L,{value:"subscribers",className:"gap-1 sm:gap-2 text-xs sm:text-sm",children:[e.jsx(ge,{className:"h-3 w-3 sm:h-4 sm:w-4"}),e.jsx("span",{className:"hidden xs:inline",children:"Inscritos"})]}),e.jsxs(L,{value:"fila",className:"gap-1 sm:gap-2 text-xs sm:text-sm",children:[e.jsx(ne,{className:"h-3 w-3 sm:h-4 sm:w-4"}),e.jsx("span",{className:"hidden xs:inline",children:"Na fila"}),Ee.length>0&&e.jsx(o,{variant:"secondary",className:"ml-1 h-5 min-w-5 px-1",children:Ee.length})]}),e.jsxs(L,{value:"digest",className:"gap-1 sm:gap-2 text-xs sm:text-sm",children:[e.jsx(we,{className:"h-3 w-3 sm:h-4 sm:w-4"}),e.jsx("span",{className:"hidden xs:inline",children:"Semanal"}),qe.length>0&&e.jsx(o,{variant:"secondary",className:"ml-1 h-5 min-w-5 px-1",children:qe.length})]}),e.jsxs(L,{value:"campaigns",className:"gap-1 sm:gap-2 text-xs sm:text-sm",children:[e.jsx(Be,{className:"h-3 w-3 sm:h-4 sm:w-4"}),e.jsx("span",{className:"hidden xs:inline",children:"Campanhas"})]}),e.jsxs(L,{value:"drafts",className:"gap-1 sm:gap-2 text-xs sm:text-sm",children:[e.jsx(ve,{className:"h-3 w-3 sm:h-4 sm:w-4"}),e.jsx("span",{className:"hidden xs:inline",children:"Rascunhos"}),P&&P.length>0&&e.jsx(o,{variant:"secondary",className:"ml-1 h-5 min-w-5 px-1",children:P.length})]}),e.jsxs(L,{value:"templates",className:"gap-1 sm:gap-2 text-xs sm:text-sm",children:[e.jsx(Ue,{className:"h-3 w-3 sm:h-4 sm:w-4"}),e.jsx("span",{className:"hidden xs:inline",children:"Templates"})]}),e.jsxs(L,{value:"import",className:"gap-1 sm:gap-2 text-xs sm:text-sm",children:[e.jsx(fe,{className:"h-3 w-3 sm:h-4 sm:w-4"}),e.jsx("span",{className:"hidden xs:inline",children:"Importar"})]})]})}),e.jsxs(F,{value:"subscribers",className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row gap-4 items-start sm:items-center justify-between",children:[e.jsxs("div",{className:"relative max-w-md flex-1",children:[e.jsx(Cs,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(Ne,{placeholder:"Buscar por nome ou email...",value:k,onChange:s=>Ve(s.target.value),className:"pl-10"})]}),e.jsxs(h,{variant:"outline",onClick:us,size:"sm",children:[e.jsx(Ke,{className:"h-4 w-4 mr-2"}),"Enviar Boas-Vindas Pendentes"]})]}),e.jsx(N,{children:e.jsx(w,{className:"p-0",children:Ze?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(S,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):u&&u.length>0?e.jsx("div",{className:"table-responsive",children:e.jsxs(J,{children:[e.jsx(X,{children:e.jsxs(A,{children:[e.jsx(l,{className:"min-w-[100px]",children:"Nome"}),e.jsx(l,{className:"min-w-[150px]",children:"Email"}),e.jsx(l,{children:"Status"}),e.jsx(l,{className:"hidden md:table-cell",children:"Origem"}),e.jsx(l,{className:"hidden lg:table-cell",children:"Data"}),E&&e.jsx(l,{className:"text-right w-[80px]",children:"Ações"})]})}),e.jsx(Y,{children:u.map(s=>e.jsxs(A,{children:[e.jsx(c,{className:"font-medium",children:s.name}),e.jsx(c,{children:e.jsxs("a",{href:`mailto:${s.email}`,className:"text-primary hover:underline flex items-center gap-1",children:[e.jsx(Ss,{className:"h-3 w-3"}),s.email]})}),e.jsx(c,{children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx(o,{variant:s.is_active?"default":"secondary",className:s.is_active?"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400":"",children:s.is_active?"Ativo":"Inativo"}),s.is_confirmed&&e.jsxs(o,{variant:"outline",className:"text-xs",children:[e.jsx(H,{className:"h-3 w-3 mr-1"}),"Confirmado"]})]})}),e.jsx(c,{className:"text-muted-foreground capitalize",children:s.source||"website"}),e.jsx(c,{className:"text-muted-foreground",children:new Date(s.subscribed_at).toLocaleDateString("pt-BR")}),E&&e.jsxs(c,{className:"text-right space-x-2",children:[e.jsx(h,{variant:"ghost",size:"sm",onClick:()=>is.mutate({id:s.id,isActive:s.is_active}),children:s.is_active?e.jsx(_s,{className:"h-4 w-4"}):e.jsx(ge,{className:"h-4 w-4"})}),e.jsx(h,{variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>ce(s.id),children:e.jsx(He,{className:"h-4 w-4"})})]})]},s.id))})]})}):e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(Pe,{className:"h-12 w-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:"Nenhum inscrito encontrado"})]})})})]}),e.jsx(F,{value:"fila",className:"space-y-4",children:e.jsx(na,{itens:Ae??[],carregando:ss,onCancelar:s=>ke.mutate(s),cancelando:ke.isPending})}),e.jsx(F,{value:"digest",className:"space-y-4",children:e.jsx(ia,{edicoes:Te??[],carregando:as,onCancelar:s=>$e.mutate(s),cancelando:$e.isPending})}),e.jsx(F,{value:"campaigns",className:"space-y-4",children:e.jsxs(N,{children:[e.jsxs(b,{children:[e.jsx(C,{children:"Histórico de Campanhas"}),e.jsx(K,{children:"Acompanhe o desempenho das newsletters enviadas"})]}),e.jsx(w,{className:"p-0",children:es?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(S,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):y&&y.length>0?e.jsxs(J,{children:[e.jsx(X,{children:e.jsxs(A,{children:[e.jsx(l,{children:"Assu
42nto"}),e.jsx(l,{children:"Data"}),e.jsx(l,{className:"text-center",children:"Enviados"}),e.jsx(l,{className:"text-center",children:"Aberturas"}),e.jsx(l,{className:"text-center",children:"Cliques"}),e.jsx(l,{className:"text-center",children:"Taxa Abertura"}),e.jsx(l,{className:"text-center",children:"Taxa Clique"})]})}),e.jsx(Y,{children:y.map(s=>{const a=s.total_sent>0?(s.uniqueOpens||0)/s.total_sent*100:0,i=s.total_sent>0?(s.uniqueClicks||0)/s.total_sent*100:0;return e.jsxs(A,{children:[e.jsx(c,{className:"font-medium max-w-xs truncate",children:s.subject}),e.jsx(c,{className:"text-muted-foreground",children:new Date(s.sent_at).toLocaleDateString("pt-BR",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"})}),e.jsx(c,{className:"text-center",children:e.jsx(o,{variant:"outline",children:s.total_sent})}),e.jsx(c,{className:"text-center",children:e.jsx(o,{variant:"secondary",className:"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",children:s.uniqueOpens||0})}),e.jsx(c,{className:"text-center",children:e.jsx(o,{variant:"secondary",className:"bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400",children:s.uniqueClicks||0})}),e.jsx(c,{className:"text-center",children:e.jsxs("span",{className:`font-medium ${a>20?"text-green-600":"text-muted-foreground"}`,children:[a.toFixed(1),"%"]})}),e.jsx(c,{className:"text-center",children:e.jsxs("span",{className:`font-medium ${i>5?"text-green-600":"text-muted-foreground"}`,children:[i.toFixed(1),"%"]})})]},s.id)})})]}):e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(Be,{className:"h-12 w-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:"Nenhuma campanha enviada ainda"})]})})]})}),e.jsx(F,{value:"drafts",className:"space-y-4",children:e.jsxs(N,{children:[e.jsxs(b,{children:[e.jsx(C,{children:"Rascunhos salvos"}),e.jsx(K,{children:"Campanhas em preparação, ainda não enviadas — salve pelo compositor sem disparar nada."})]}),e.jsx(w,{className:"p-0",children:ns?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(S,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):P&&P.length>0?e.jsxs(J,{children:[e.jsx(X,{children:e.jsxs(A,{children:[e.jsx(l,{children:"Assunto"}),e.jsx(l,{className:"hidden md:table-cell",children:"Atualizado"}),e.jsx(l,{className:"text-right w-[140px]",children:"Ações"})]})}),e.jsx(Y,{children:P.map(s=>e.jsxs(A,{children:[e.jsx(c,{className:"font-medium max-w-xs truncate",children:s.subject}),e.jsx(c,{className:"hidden md:table-cell text-muted-foreground",children:new Date(s.updated_at).toLocaleDateString("pt-BR",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"})}),e.jsxs(c,{className:"text-right space-x-1",children:[e.jsx(h,{variant:"ghost",size:"sm",onClick:()=>os(s),children:e.jsx(ve,{className:"h-4 w-4"})}),e.jsx(h,{variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>ls.mutate(s.id),children:e.jsx(He,{className:"h-4 w-4"})})]})]},s.id))})]}):e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(ve,{className:"h-12 w-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:"Nenhum rascunho salvo"})]})})]})}),e.jsx(F,{value:"templates",className:"space-y-4",children:e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:ts?e.jsx("div",{className:"col-span-full flex items-center justify-center py-12",children:e.jsx(S,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):M&&M.length>0?M.map(s=>e.jsxs(N,{className:"relative overflow-hidden",children:[s.is_default&&e.jsx(o,{className:"absolute top-2 right-2 bg-primary",children:"Padrão"}),e.jsxs(b,{children:[e.jsxs(C,{className:"flex items-center gap-2",children:[e.jsx(As,{className:"h-5 w-5"}),s.name]}),s.description&&e.jsx(K,{children:s.description})]}),e.jsxs(w,{children:[e.jsx("div",{className:"border rounded-lg p-2 bg-muted/30 h-32 overflow-hidden mb-4",style:{fontSize:"6px"},children:e.jsx("div",{dangerouslySetInnerHTML:{__html:Es.sanitize(s.html_content.substring(0,1e3))},className:"transform scale-[0.15] origin-top-left w-[600%]"})}),e.jsxs(h,{className:"w-full",onClick:()=>{O(null),Ie(s),R(!0)},children:[e.jsx(H,{className:"h-4 w-4 mr-2"}),"Usar Template"]})]})]},s.id)):e.jsxs("div",{className:"col-span-full text-center py-12 text-muted-foreground",children:[e.jsx(Ue,{className:"h-12 w-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:"Nenhum template disponível"})]})})}),e.jsx(F,{value:"import",className:"space-y-4",children:e.jsxs(N,{children:[e.jsxs(b,{children:[e.jsxs(C,{className:"flex items-center gap-2",children:[e.jsx(fe,{className:"h-5 w-5"}),"Importar Inscritos (CSV)"]}),e.jsx(K,{children:"Faça upload de um arquivo CSV com os inscritos do blog anterior. O arquivo deve conter colunas: nome, email (separados por vírgula ou ponto-e-vírgula)."})]}),e.jsxs(w,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("input",{ref:t,type:"file",accept:".csv,.txt",onCh
42ange:hs,className:"hidden"}),e.jsxs(h,{variant:"outline",onClick:()=>{var s;return(s=t.current)==null?void 0:s.click()},disabled:V,children:[e.jsx(ks,{className:"h-4 w-4 mr-2"}),"Selecionar Arquivo CSV"]}),Se&&e.jsx("span",{className:"text-sm text-muted-foreground",children:Se})]}),_.length>0&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[e.jsxs(o,{variant:"outline",className:"text-green-600",children:[e.jsx(H,{className:"h-3 w-3 mr-1"}),_.filter(s=>s.valid).length," válidos"]}),_.filter(s=>!s.valid).length>0&&e.jsxs(o,{variant:"outline",className:"text-destructive",children:[e.jsx(ie,{className:"h-3 w-3 mr-1"}),_.filter(s=>!s.valid).length," inválidos"]})]}),e.jsxs("div",{className:"border rounded-lg max-h-60 overflow-y-auto",children:[e.jsxs(J,{children:[e.jsx(X,{children:e.jsxs(A,{children:[e.jsx(l,{children:"Nome"}),e.jsx(l,{children:"Email"}),e.jsx(l,{children:"Status"})]})}),e.jsx(Y,{children:_.slice(0,50).map((s,a)=>e.jsxs(A,{children:[e.jsx(c,{children:s.name}),e.jsx(c,{children:s.email}),e.jsx(c,{children:s.valid?e.jsx(H,{className:"h-4 w-4 text-green-600"}):e.jsx(ie,{className:"h-4 w-4 text-destructive"})})]},a))})]}),_.length>50&&e.jsxs("p",{className:"text-center text-sm text-muted-foreground py-2",children:["... e mais ",_.length-50," registros"]})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs(h,{onClick:()=>Le(!1),disabled:V||_.filter(s=>s.valid).length===0,children:[V?e.jsx(S,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(fe,{className:"h-4 w-4 mr-2"}),"Importar"]}),e.jsxs(h,{variant:"secondary",onClick:()=>Le(!0),disabled:V||_.filter(s=>s.valid).length===0,children:[V?e.jsx(S,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(Ke,{className:"h-4 w-4 mr-2"}),"Importar + Enviar Boas-Vindas"]}),e.jsx(h,{variant:"outline",onClick:()=>{xe([]),he(""),t.current&&(t.current.value="")},children:"Cancelar"})]})]})]})]})})]})]}),e.jsx(Ts,{open:!!le,onOpenChange:()=>ce(null),children:e.jsxs(qs,{children:[e.jsxs($s,{children:[e.jsx(Ds,{children:"Remover inscrito?"}),e.jsx(Is,{children:"Esta ação não pode ser desfeita. O inscrito será permanentemente removido da lista."})]}),e.jsxs(Ls,{children:[e.jsx(Fs,{children:"Cancelar"}),e.jsx(Rs,{onClick:()=>le&&rs.mutate(le),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Remover"})]})]})}),e.jsx(zs,{open:We,onOpenChange:R,children:e.jsxs(Os,{preventOutsideClose:!0,className:"max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(Ms,{children:[e.jsx(Ps,{children:T?"Editar Rascunho":"Compor Newsletter"}),e.jsxs(Bs,{children:["Envie uma newsletter para ",pe," inscrito(s) ativo(s), ou salve como rascunho para enviar depois. Use ","{{name}}"," para personalizar."]})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[B&&B.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(te,{className:"flex items-center gap-2",children:[e.jsx(Us,{className:"h-4 w-4"}),"Selecionar Artigo (opcional)"]}),e.jsxs(Js,{value:_e,onValueChange:ms,children:[e.jsx(Xs,{children:e.jsx(Ys,{placeholder:"Escolha um artigo para enviar..."})}),e.jsx(Zs,{children:B.map(s=>e.jsx(ea,{value:s.id,children:s.title},s.id))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:'Ao selecionar um artigo, o conteúdo será preenchido automaticamente com preview e botão "Continue Lendo".'})]}),M&&M.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(te,{children:"Template (opcional)"}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:M.map(s=>e.jsx(h,{variant:Je===s.id?"default":"outline",size:"sm",onClick:()=>Ie(s),children:s.name},s.id))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(te,{htmlFor:"subject",children:"Assunto"}),e.jsx(Ne,{id:"subject",placeholder:"Assunto do email...",value:$,onChange:s=>Q(s.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(te,{htmlFor:"content",children:"Conteúdo (HTML)"}),e.jsx(Ks,{id:"content",placeholder:"<h1>Olá {{name}}!</h1><p>Confira as novidades...</p>",value:D,onChange:s=>z(s.target.value),rows:16,className:"font-mono text-sm"})]}),e.jsxs(N,{className:"bg-muted/50",children:[e.jsx(b,{className:"pb-2",children:e.jsxs(C,{className:"text-sm flex items-center gap-2",children:[e.jsx(Hs,{className:"h-4 w-4"}),"Teste antes de enviar"]})}),e.jsx(w,{className:"space-y-2",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ne,{placeholder:"Email para teste...",value:oe,onChange:s=>Ge(s.target.value),className:"flex-1"}),e.jsx(h,{variant:"secondary",onClick:()=>De(!0),disabled:ee,children:ee?e.jsx(S,{className:"h-4 w-4 animate-spin"}):"Enviar Teste"})]})})]})]}),e.jsxs(Qs,{children:[e.jsx(h,{variant:"outline",onClick:()=>R(!1),children:"Cancelar"}),e.jsxs(h,{variant:"secondary",onClick:()=>ue.mutate(),disabled:ue.isPending||!$.trim()||!D.trim(),children:[ue.isPending?e.jsx(S,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(Vs,{className:"h-4 w-4 mr-2"}),T?"Atualizar Rascunho":"Salvar Rascunho"]}),e.jsx(h,{onClick:()=>De(!1),disabled:ee||!$.trim()||!D.trim(),children:ee?e.jsxs(e.Fragment,{children:[e.jsx(S,{className:"h-4 w-4 mr-2 animate-spin"}),de?`Enviando… ${de.enviados}
42 enviados, ${de.restantes} restantes`:"Enviando..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Z,{className:"h-4 w-4 mr-2"}),"Enviar para ",pe," inscrito(s)"]})})]})]})})]})};export{ua as AdminNewsletter,ua 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.