1import{r as s,j as e}from"./vendor-react-CT5JKzvF.js";import{u as h}from"./useServerFn-kxjkcKU-.js";import{r as O}from"./auth-middleware-TVS-M506.js";import{k as W,O as D,Q as q,al as z,B as G,cx as ee,cy as H,cz as ae,cA as Q}from"./index-DfbM6LlC.js";import{t as R}from"./index-DI3WHhBW.js";import{g as se,u as te,L as re,h as oe}from"./brand-logo.functions-BxDbSaOB.js";import{L as C}from"./loader-circle-n1NcZTn_.js";import{C as P}from"./circle-check-BvBa-t2C.js";import{l as le,s as ne,d as ie,e as de,r as ce}from"./alerts.functions-DqXAz70-.js";import{R as F}from"./refresh-cw-CKfeTUSA.js";import{P as me}from"./plus-_aDNsBVA.js";import{T as xe}from"./trash-2-t6p8QWDn.js";import{g as pe,s as ge,a as ue,p as fe}from"./creative-config.functions-DPhQyRpp.js";import"./vendor-router-DnYuAPye.js";const he=[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326",key:"11g9vi"}]],be=W("bell",he),ve=D({method:"POST"}).middleware([O]).handler(q("b7119f4d5219a83601b8ffbcc8b3bf0c64402fa44f68430ece558139c6322690")),je=D({method:"POST"}).middleware([O]).handler(q("c42fbdb3ce9b12d8ae71d46119d27aebc00c16c4a564a2bec1b53d69a5ff63fd")),Ne=D({method:"POST"}).middleware([O]).handler(q("61b2bf9fa5c7797c802fff0086890fec4c540ef23feedba9b7c1c658561fb16f"));function ye(){const r=h(se),l=h(te),o=s.useRef(null),[d,f]=s.useState(null),[b,i]=s.useState(null),[v,y]=s.useState(!0),[j,w]=s.useState(!1),x=s.useCallback(async()=>{y(!0);try{const c=await r({data:void 0});f(c.logoUrl),i(c.atualizadoEm)}catch(c){console.error("[brand logo]",c)}finally{y(!1)}},[r]);s.useEffect(()=>{x()},[x]);async function m(c){if(c.type!=="image/png"){R.error("Envie um PNG com fundo transparente.");return}if(c.size>4*1024*1024){R.error("Arquivo muito grande. Limite de 4 MB.");return}w(!0);try{const p=await c.arrayBuffer();let g="";const S=new Uint8Array(p);for(let n=0;n<S.length;n+=8192)g+=String.fromCharCode(...S.subarray(n,n+8192));const N=await l({data:{b64:btoa(g)}});f(N.logoUrl),i(N.atualizadoEm),R.success("Logo atualizado.")}catch(p){R.error(p instanceof Error?p.message:"Falha ao enviar a logo.")}finally{w(!1),o.current&&(o.current.value="")}}return e.jsxs("div",{className:"mt-4 rounded-xl border border-adm-fg/10 p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[v?e.jsx(C,{size:18,className:"animate-spin text-adm-fg/60"}):d?e.jsx(P,{size:18,className:"text-emerald-600"}):e.jsx(z,{size:18,className:"text-amber-600"}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-[14px] font-semibold text-adm-fg",children:["Logo da marca"," ",e.jsx("span",{className:"font-normal text-adm-fg/50",children:"â brand/logo-branco.png"})]}),e.jsx("p",{className:"text-[13px] text-adm-fg/60",children:v?"Verificando o arquivoâ¦":d?`Arquivo configurado${b?` â atualizado em ${new Date(b).toLocaleString("pt-BR")}`:""}.`:"Logo não configurado â as peças serão geradas sem marca."})]})]}),e.jsxs("label",{className:"inline-flex cursor-pointer items-center gap-2 rounded-lg border border-adm-fg/15 px-3 py-1.5 text-[13px] font-semibold text-adm-fg/80 hover:text-adm-fg",children:[j?e.jsx(C,{size:14,className:"animate-spin"}):e.jsx(G,{size:14}),j?"Enviandoâ¦":d?"Substituir PNG":"Enviar PNG",e.jsx("input",{ref:o,type:"file",accept:"image/png",className:"hidden",disabled:j,onChange:c=>{const p=c.target.files?.[0];p&&m(p)}})]})]}),d&&e.jsx("div",{className:"mt-4 inline-flex items-center justify-center rounded-lg p-4",style:{background:"#0b1220"},children:e.jsx("img",{src:d,alt:"Logo da marca",className:"h-10 w-auto"})}),e.jsxs("p",{className:"mt-3 text-[12.5px] text-adm-fg/55",children:["Este é o arquivo aplicado como overlay pelas gerações de imagem e vÃdeo. No formato 9:16 o logo é posicionado pelo menos ",re,"px abaixo do topo (referência 1080x1920), fora da zona de interface do Instagram. Se o arquivo não existir, a geração continua e a peça sai sem marca, com aviso no resultado."]})]})}const M={sessions_drop:"Queda de sessões vs perÃodo anterior",contacts_drop:"Queda de contatos vs perÃodo anterior",no_contacts:"Nenhum contato em X horas (horário comercial)",event_silent:"Evento primário sem registro por X dias",channel_cpl:"CPL de um canal acima de R$ Y"},U={sessions_drop:"%",contacts_drop:"%",no_contacts:"horas",event_silent:"dias",channel_cpl:"R$"},we=Object.keys(M),Se={sessions_drop:30,contacts_drop:30,no_contacts:6,event_silent:3,channel_cpl:150};function _e(){const r=h(le),l=h(ne),o=h(ie),d=h(de),f=h(ce),[b,i]=s.useState([]),[v,y]=s.useState([]),[j,w]=s.useState(!0),[x,m]=s.useState(!1),[c,p]=s.useState(null),[g,S]=s.useState("sessions_drop"),[N,n]=s.useState(30),[_,A]=s.useState("google_ads"),[L,B]=s.useState("whatsapp_click"),[E,t]=s.useState(""),u=s.useCallback(async()=>{w(!0);try{const a=await r({data:void 0});i(a.rules),y(a.events),p(null)}catch(a){p(a instanceof Error?a.message:"Falha ao carregar alertas.")}finally{w(!1)}},[r]);s.useEffect(()=>{u()},[u]);const k=async()=>{m(!0);try{await l({data:{kind:g,enabled:!0,threshold:N,channel:g==="channel_cpl"?_:null,event_name:g==="event_silent"?L:null,email:E.trim()?E.trim():null}}),await u()}catch(a){p(a instanceof Error?a.message:"Falha ao salvar regra.")}finally{m(!1)}},I=async a=>{m(!0);try{await l({data:{id:a.id,kind:a.kind,enabled:!a.enabled,threshold:Number(a.threshold),channel:a.channel,event_name:a.event_name,email:a.email}}),await u()}finally{m(!1)}},Y=async a=>{m(!0);try{await o({data:{id:a}}),await u()}finally{m(!1)}},Z=async()=>{m(!0);try{await d({data:void 0}),await u()}finally{m(!1)}},J=async()=>{m(!0);try{await f({data:void 0}),await u()}finally{m(!1)}};return e.jsxs("section",{className:"adm-card-sm",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(be,{size:18,className:"text-indigo-600"}),e.jsx("h2",{className:"font-display text-[16px] font-semibold text-adm-fg",children:"Alertas"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:Z,disabled:x,className:"inline-flex items-center gap-1.5 rounded-[8px] border border-adm-fg/10 bg-adm-fg/5 px-2.5 py-1.5 text-[12px] font-medium text-adm-fg disabled:opacity-50",children:[x?e.jsx(C,{size:13,className:"animate-spin"}):e.jsx(F,{size:13})," Verificar agora"]}),v.some(a=>!a.resolved)&&e.jsx("button",{type:"button",onClick:J,disabled:x,className:"rounded-[8px] border border-adm-fg/10 px-2.5 py-1.5 text-[12px] text-adm-fg/70 disabled:opacity-50",children:"Marcar como resolvidos"})]})]}),e.jsx("p",{className:"mt-2 text-[13px] leading-relaxed text-adm-fg/60",children:"As regras são avalia
1das ao abrir o painel de Analytics e uma vez por dia pelo agendador. Quando disparam, geram um alerta no menu lateral e, se houver e-mail configurado, uma notificação."}),c&&e.jsx("p",{className:"mt-3 rounded-[8px] bg-red-50 px-3 py-2 text-[12.5px] text-red-700",children:c}),e.jsxs("div",{className:"mt-4 grid gap-2 rounded-[10px] border border-adm-fg/10 p-3 sm:grid-cols-[1fr_auto_auto]",children:[e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsxs("label",{className:"text-[12px] text-adm-fg/70",children:["Tipo",e.jsx("select",{value:g,onChange:a=>{const K=a.target.value;S(K),n(Se[K])},className:"mt-1 w-full rounded-[8px] border border-adm-fg/10 bg-white px-2 py-1.5 text-[13px] text-adm-fg",children:we.map(a=>e.jsx("option",{value:a,children:M[a]},a))})]}),e.jsxs("label",{className:"text-[12px] text-adm-fg/70",children:["Limite (",U[g],")",e.jsx("input",{type:"number",min:0,value:N,onChange:a=>n(Number(a.target.value)),className:"mt-1 w-full rounded-[8px] border border-adm-fg/10 bg-white px-2 py-1.5 text-[13px] text-adm-fg"})]}),g==="channel_cpl"&&e.jsxs("label",{className:"text-[12px] text-adm-fg/70",children:["Canal",e.jsx("select",{value:_,onChange:a=>A(a.target.value),className:"mt-1 w-full rounded-[8px] border border-adm-fg/10 bg-white px-2 py-1.5 text-[13px] text-adm-fg",children:ee.map(a=>e.jsx("option",{value:a,children:H[a]},a))})]}),g==="event_silent"&&e.jsxs("label",{className:"text-[12px] text-adm-fg/70",children:["Evento",e.jsx("select",{value:L,onChange:a=>B(a.target.value),className:"mt-1 w-full rounded-[8px] border border-adm-fg/10 bg-white px-2 py-1.5 text-[13px] text-adm-fg",children:ae.map(a=>e.jsx("option",{value:a,children:Q[a]??a},a))})]}),e.jsxs("label",{className:"text-[12px] text-adm-fg/70 sm:col-span-2",children:["E-mail para notificação (opcional)",e.jsx("input",{type:"email",value:E,placeholder:"[email protected]",onChange:a=>t(a.target.value),className:"mt-1 w-full rounded-[8px] border border-adm-fg/10 bg-white px-2 py-1.5 text-[13px] text-adm-fg"})]})]}),e.jsxs("button",{type:"button",onClick:k,disabled:x,className:"inline-flex h-fit items-center gap-1.5 self-end rounded-[8px] bg-indigo-600 px-3 py-2 text-[13px] font-medium text-white disabled:opacity-50",children:[e.jsx(me,{size:14})," Adicionar regra"]})]}),e.jsx("div",{className:"mt-4",children:j?e.jsx("p",{className:"text-[13px] text-adm-fg/50",children:"Carregandoâ¦"}):b.length===0?e.jsx("p",{className:"text-[13px] text-adm-fg/50",children:"Nenhuma regra configurada."}):e.jsx("ul",{className:"divide-y divide-adm-fg/10",children:b.map(a=>e.jsxs("li",{className:"flex flex-wrap items-center gap-2 py-2.5",children:[e.jsx("input",{type:"checkbox",checked:a.enabled,onChange:()=>{I(a)},className:"h-3.5 w-3.5 accent-indigo-600"}),e.jsx("span",{className:"text-[13px] text-adm-fg",children:M[a.kind]}),e.jsx("span",{className:"rounded-full bg-adm-fg/5 px-2 py-0.5 text-[12px] text-adm-fg/70",children:U[a.kind]==="R$"?`R$ ${Number(a.threshold).toLocaleString("pt-BR")}`:`${Number(a.threshold)} ${U[a.kind]}`}),a.channel&&e.jsx("span",{className:"rounded-full bg-adm-fg/5 px-2 py-0.5 text-[12px] text-adm-fg/70",children:H[a.channel]??a.channel}),a.event_name&&e.jsx("span",{className:"rounded-full bg-adm-fg/5 px-2 py-0.5 text-[12px] text-adm-fg/70",children:Q[a.event_name]??a.event_name}),a.email&&e.jsx("span",{className:"text-[12px] text-adm-fg/45",children:a.email}),e.jsx("button",{type:"button",onClick:()=>{Y(a.id)},className:"ml-auto text-adm-fg/40 hover:text-red-600","aria-label":"Excluir regra",children:e.jsx(xe,{size:15})})]},a.id))})}),v.length>0&&e.jsxs("div",{className:"mt-5",children:[e.jsx("h3",{className:"text-[13px] font-semibold text-adm-fg",children:"Ãltimos disparos"}),e.jsx("ul",{className:"mt-2 space-y-1.5",children:v.slice(0,10).map(a=>e.jsxs("li",{className:"rounded-[8px] px-2.5 py-2 text-[12.5px] leading-relaxed",style:{background:a.severity==="error"?"rgba(185,28,28,0.08)":"rgba(180,83,9,0.08)",color:a.severity==="error"?"#b91c1c":"#92400e"},children:[e.jsxs("span",{className:"opacity-70",children:[new Date(a.created_at).toLocaleStr
1ing("pt-BR",{timeZone:"America/Sao_Paulo"})," ·"," "]}),a.message,a.resolved?e.jsx("span",{className:"opacity-60",children:" (resolvido)"}):null]},a.id))})]})]})}const $="w-full rounded-lg border border-adm-fg/15 bg-white px-3 py-2 text-[13.5px] text-adm-fg outline-none focus:border-adm-accent",T=r=>r.split(` 2`).map(l=>l.trim()).filter(Boolean),X=r=>T(r).map(l=>{const[o,...d]=l.split("|"),f=d.join("|").trim();return{value:o.trim(),label:f||o.trim()}});function V(r){const l=r?.brandKit??{},o=oe;return{navy:l.cores?.navy??o.cores.navy,mint:l.cores?.mint??o.cores.mint,white:l.cores?.white??o.cores.white,marca:l.tipografia?.marca??o.tipografia.marca,impacto:l.tipografia?.impacto??o.tipografia.impacto,editorial:l.tipografia?.editorial??o.tipografia.editorial,rodape:l.rodape??o.rodape,servicos:(l.servicos??o.servicos).map(d=>`${d.value} | ${d.label}`).join(` 3`),publicos:(l.publicos??o.publicos).map(d=>`${d.value} | ${d.label}`).join(` 4`),provas:(l.provas??o.provas).join(` 5`),proibicoes:(l.proibicoes??o.proibicoes).join(` 6`),regras:(l.regras??o.regras).join(` 7`),limiteMensal:r?.limiteMensal??300}}function Ce(r){return{cores:{navy:r.navy,mint:r.mint,white:r.white},tipografia:{marca:r.marca,impacto:r.impacto,editorial:r.editorial},rodape:r.rodape,servicos:X(r.servicos),publicos:X(r.publicos),provas:T(r.provas),proibicoes:T(r.proibicoes),regras:T(r.regras)}}function Ae(){const r=h(pe),l=h(ge),o=h(ue),d=h(fe),[f,b]=s.useState(()=>V(null)),[i,v]=s.useState(null),[y,j]=s.useState(!0),[w,x]=s.useState(!1),[m,c]=s.useState(null),[p,g]=s.useState(null),[S,N]=s.useState(!1),n=(t,u)=>b(k=>({...k,[t]:u})),_=s.useCallback(async()=>{j(!0);try{const[t,u]=await Promise.all([r({data:void 0}),o({data:void 0})]);b(V(t)),v(u)}catch(t){c({ok:!1,texto:t instanceof Error?t.message:"Falha ao carregar."})}finally{j(!1)}},[r,o]);s.useEffect(()=>{_()},[_]);const A=async()=>{x(!0),c(null);try{const t=await l({data:{brandKit:Ce(f),limiteMensal:Number(f.limiteMensal)}});b(V(t)),g(null),c({ok:!0,texto:"Identidade salva. Vale para as próximas gerações."}),v(await o({data:void 0}))}catch(t){c({ok:!1,texto:t instanceof Error?t.message:"Falha ao salvar."})}finally{x(!1)}},L=async()=>{N(!0);try{const t=await d({data:{alvo:"imagem"}});g(t.prompt)}catch(t){c({ok:!1,texto:t instanceof Error?t.message:"Falha ao gerar o prompt."})}finally{N(!1)}},B=s.useMemo(()=>Math.min(100,i?.percentual??0),[i]),E=i?.status==="bloqueado"?"#dc2626":i?.status==="aviso"?"#d97706":"#059669";return e.jsxs("section",{className:"mt-7 rounded-2xl border border-adm-fg/10 bg-adm-fg/[0.02] p-5 sm:p-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(G,{size:18,className:"text-adm-accent"}),e.jsx("h2",{className:"font-semibold text-adm-fg text-[17px]",children:"Identidade dos criativos"})]}),e.jsxs("button",{type:"button",onClick:()=>{_()},className:"inline-flex items-center gap-2 rounded-lg border border-adm-fg/15 px-3 py-1.5 text-[13px] font-semibold text-adm-fg/80 hover:text-adm-fg",children:[e.jsx(F,{size:14})," Recarregar"]})]}),e.jsx("p",{className:"mt-2 text-[13px] text-adm-fg/60",children:"Estes valores alimentam o assistente criativo. Campos em branco voltam ao padrão do sistema."}),e.jsxs("div",{className:"mt-4 rounded-xl border border-adm-fg/10 bg-white p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("h3",{className:"text-[14px] font-semibold text-adm-fg",children:["Uso do assistente ",i?e.jsxs("span",{className:"font-normal text-adm-fg/50",children:["(",i.mes,")"]}):null]}),i?.status==="bloqueado"?e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[12.5px] font-semibold text-rose-600",children:[e.jsx(z,{size:14})," Limite atingido â gerações bloqueadas"]}):i?.status==="aviso"?e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[12.5px] font-semibold text-amber-600",children:[e.jsx(z,{size:14})," Acima de 80% do limite"]}):null]}),e.jsx("div",{className:"mt-3 h-2 w-full overflow-hidden rounded-full bg-adm-fg/10",children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${B}%`,background:E}})}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-4 text-[13px] text-adm-fg/70",children:[e.jsxs("span",{children:["Gerações: ",e.jsx("strong",{className:"text-adm-fg",children:i?.geracoes??0})," / ",i?.limiteMensal??"â"]}),e.jsxs("span",{children:["Tokens: ",e.jsx("strong",{className:"text-adm-fg",children:(i?.tokensEntrada??0).toLocaleStr
7ing("pt-BR")})," entrada ·"," ",e.jsx("strong",{className:"text-adm-fg",children:(i?.tokensSaida??0).toLocaleString("pt-BR")})," saÃda"]}),e.jsxs("span",{children:["Custo estimado:"," ",e.jsxs("strong",{className:"text-adm-fg",children:["R$ ",(i?.custoBrl??0).toLocaleString("pt-BR",{minimumFractionDigits:2})]})," ","(US$ ",(i?.custoUsd??0).toFixed(2),")"]}),e.jsxs("span",{children:["Falhas: ",e.jsx("strong",{className:"text-adm-fg",children:i?.falhas??0})]})]}),e.jsxs("label",{className:"mt-4 block max-w-[280px]",children:[e.jsx("span",{className:"text-[12.5px] font-semibold text-adm-fg/70",children:"Limite mensal de gerações"}),e.jsx("input",{type:"number",min:10,max:1e4,value:f.limiteMensal,onChange:t=>n("limiteMensal",Number(t.target.value)),className:`mt-1 ${$}`})]})]}),y?e.jsxs("p",{className:"mt-4 inline-flex items-center gap-2 text-[13px] text-adm-fg/60",children:[e.jsx(C,{size:14,className:"animate-spin"})," Carregando identidadeâ¦"]}):e.jsx("div",{className:"mt-4 grid gap-4 sm:grid-cols-3",children:["navy","mint","white"].map(t=>e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[12.5px] font-semibold text-adm-fg/70",children:t==="navy"?"Fundo (navy)":t==="mint"?"Destaque (menta)":"Headline (branco)"}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("input",{type:"color",value:f[t],onChange:u=>n(t,u.target.value),className:"h-9 w-10 rounded border border-adm-fg/15"}),e.jsx("input",{value:f[t],onChange:u=>n(t,u.target.value),className:$})]})]},t))}),!y&&e.jsx("div",{className:"mt-4 grid gap-4",children:[["marca","Estilo tipográfico â marca",2],["impacto","Estilo tipográfico â impacto",2],["editorial","Estilo tipográfico â editorial",2],["rodape","Assinatura de rodapé",1],["servicos","Serviços (um por linha: valor | rótulo)",5],["publicos","Públicos (um por linha: valor | rótulo)",5],["provas","Provas e selos autorizados (um por linha)",4],["proibicoes","Proibições padrão (um por linha)",4],["regras","Regras aprendidas (uma por linha)",6]].map(([t,u,k])=>e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[12.5px] font-semibold text-adm-fg/70",children:u}),e.jsx("textarea",{rows:k,value:f[t],onChange:I=>n(t,I.target.value),className:`mt-1 ${$} resize-y leading-relaxed`})]},t))}),e.jsxs("div",{className:"mt-5 flex flex-wrap items-center gap-3",children:[e.jsxs("button",{type:"button",onClick:()=>{A()},disabled:w||y,className:"inline-flex items-center gap-2 rounded-lg bg-adm-accent px-4 py-2 text-[13.5px] font-semibold text-white disabled:opacity-50",children:[w?e.jsx(C,{size:14,className:"animate-spin"}):e.jsx(P,{size:14}),"Salvar identidade"]}),e.jsxs("button",{type:"button",onClick:()=>{L()},disabled:S,className:"inline-flex items-center gap-2 rounded-lg border border-adm-fg/15 px-3.5 py-2 text-[13.5px] font-semibold text-adm-fg/80 hover:text-adm-fg disabled:opacity-50",children:[S?e.jsx(C,{size:14,className:"animate-spin"}):null,"Ver system prompt gerado"]}),m?e.jsx("span",{className:`text-[13px] ${m.ok?"text-emerald-600":"text-rose-600"}`,children:m.texto}):null]}),p?e.jsx("pre",{className:"mt-4 max-h-[360px] overflow-auto whitespace-pre-wrap rounded-xl border border-adm-fg/10 bg-white p-4 text-[12.5px] leading-relaxed text-adm-fg/80",children:p}):null]})}const Ee={estilo_auditoria:"Estilo Auditoria (reescrita de legendas)",artigo_blog:"Gerador de artigos do blog",artigo_blog_intro:"Reescrita da introdução do artigo",sugerir_textos_imagem:"Preencher com IA (gerador de imagens)",roteiro_video:"Roteiro de vÃdeo (IA)",video_social:"Gerador de vÃdeo (Veo)",teste_conexao:"Teste de conexão"},ke=["estilo_auditoria","artigo_blog","artigo_blog_intro","sugerir_textos_imagem","roteiro_video","video_social"];function qe(){const r=h(ve),l=h(Ne),o=h(je),[d,f]=s.useState(null),[b,i]=s.useState(!1),[v,y]=s.useState(null),[j,w]=s.useState(!1),[x,m]=s.useState(null),[c,p]=s.useState(!0),g=s.useCallback(async()=>{i(!0);try{f(await r({data:void 0}))}catch(n){f({ok:!1,model:"-",message:n instanceof Error?n.message:"Falha no teste."})}finally{i(!1)}},[r]),S=s.useCallback(async()=>{w(!0);try{y(await l({data:void 0}))}catch(n){y({ok:!1,model:"-",message:n instanceof Error?n.message:"Falha no teste."})}finally{w(!1)}},[l]),N=s.useCallback(async()=>{p(!0);try{m(await o({data:void 0}))}catch(n){console.error("[ai usage]",n)}finally{p(!1)}},[o]);return s.useEffect(()=>{g(),S(),N()},[g,S,N]),e.jsxs("div",{className:"p-6 sm:p-10 max-w-[1100px]",children:[e.jsx("h1",{className:"font-display font-bold text-adm-fg text-[26px] sm:text-[32px]",children:"Configurações"}),e.jsx("p",{className:"mt-2 text-adm-fg/60 text-[15px]",children:"Provedores de IA usados pela plataforma e consumo do mês."}),e.jsxs("section",{className:"mt-7 rounded-2xl border border-adm-fg/10 bg-adm-fg/[0.02] p-5 sm:p-6",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(G,{size:18,className:"text-adm-accent"}),e.jsx("h2",{className:"font-semibold text-adm-fg text-[17px]",children:"Inteligência Artificial"})]}),e.jsxs("div",{className:"mt-4 rounded-xl border border-adm-fg/10 p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[b?e.jsx(C,{size:18,className:"animate-spin text-adm-fg/60"}):d?.ok?e.jsx(P,{size:18,className:"text-emerald-600"}):e.jsx(z,{size:18,className:"text-amber-600"}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-[14px] font-semibold text-adm-fg",children:["Anthropic (Claude)"," ",e.jsxs("span",{className:"font-normal text-adm-fg/50",children:["â ",d?.model??"â¦"]})]}),e.jsx("p",{className:"text-[13px] text-adm-fg/60",children:b?"Testando conexãoâ¦":d?.message??"â"})]})]}),e.jsxs("button",{type:"button",onClick:()=>{g()},disabled:b,className:"inline-flex items-center gap-2 rounded-lg border border-adm-fg/15 px-3 py-1.5 text-[13px] font-semibold text-adm-fg/80 hover:text-adm-fg disabled:opacity-50",children:[e.jsx(F,{size:14})," Testar conexão"]})]}),e.jsx("p",{className:"mt-3 text-[12.5px] text-adm-fg/55",children:"Fallback automático: quando a Anthropic falha, a mesma tarefa é executada pelo Lovable AI com o mesmo prompt, e o provedor que respondeu fica registrado abaixo."})]}),e.jsxs("div",{className:"mt-4 rounded-xl border border-adm-fg/10 p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[j?e.jsx(C,{size:18,className:"animate-spin text-adm-fg/60"}):v?.ok?e.jsx(P,{size:18,className:"text-emerald-600"}):e.jsx(z,{size:18,className:"text-amber-600"}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-[14px] font-semibold text-adm-fg",children:["Google Veo (vÃdeo)"," ",e.jsxs("span",{className:"font-normal text-adm-fg/50",children:["â ",v?.model??"â¦"]})]}),e.jsx("p",{className:"text-[13px] text-adm-fg/60",children:j?"Testando conexãoâ¦":v?.message??"â"})]})]}),e.jsxs("button",{type:"button",onClick:()=>{S()},disabled:j,className:"inline-flex items-center gap-2 rounded-lg border border-adm-fg/15 px-3 py-1.5 text-[13px] font-semibold text-adm-fg/80 hover:text-adm-fg disabled:opacity-50",children:[e.jsx(F,{size:14})," Testar conexão"]})]}),e.jsx("p",{className:"mt-3 text-[12.5px] text-adm-fg/55",children:'Usado na aba "Gerar vÃdeo" das Publicações. O vÃdeo sai em 9:16 (Story/Reel) ou 16:9 (feed) e é salvo direto na publicação. Sem fallback: se o Veo falhar, a geração é interrompida.'})]}),e.jsx(ye,{}),e.jsxs("div",{className:"mt-5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"text-[14px] font-semibold text-adm-fg",children:["Provedor ativo por funcionalidade e chamadas do mês",x?e.jsxs("span",{className:"font-normal text-adm-fg/50",children:[" (",x.mes,")"]}):null]}),e.jsx("button",{type:"button",onClick:()=>{N()},className:"text-[13px] font-semibold text-adm-fg/60 hover:text-adm-fg",children:"Atualizar"})]}),e.jsx("div",{className:"mt-3 overflow-x-auto",children:e.jsxs("table",{className:"w-full text-[13.5px]",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-adm-fg/50",children:[e.jsx("th",{className:"py-2 pr-3 font-medium",children:"Funcionalidade"}),e.jsx("th",{className:"py-2 pr-3 font-medium",children:"Ãltimo provedor"}),e.jsx("th",{className:"py-2 pr-3 font-medium",children:"Anthropic"}),e.jsx("th",{className:"py-2 font-medium",children:"Lovable AI"})]})}),e.jsx("tbody",{children:ke.map(n=>{const _=x?.porTarefa.find(A=>A.tarefa===n);return e.jsxs("tr",{className:"border-t border-adm-fg/10 text-adm-fg",children:[e.jsx("td",{className:"py-2.5 pr-3",children:Ee[n]??n}),e.jsx("td",{className:"py-2.5 pr-3 capitalize text-adm-fg/70",children:_?.ultimoProvedor??"anthropic (padrão)"}),e.jsx("td",{className:"py-2.5 pr-3",children:_?.anthropic??0}),e.jsx("td",{className:"py-2.5",children:_?.lovable??0})]},n)})})]})}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-4 text-[13px] text-adm-fg/70",children:c?e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(C,{size:14,className:"animate-spin"})," Carregando consumoâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsxs("span",{children:["Total Anthropic: ",e.jsx("strong",{className:"text-adm-fg",children:x?.totalAnthropic??0})]}),e.jsxs("span",{children:["Total Lovable AI: ",e.jsx("strong",{className:"text-adm-fg",children:x?.totalLovable??0})]}),e.jsxs("span",{children:["Falhas registradas: ",e.jsx("strong",{className:"text-adm-fg",children:x?.falhas??0})]})]})})]})]}),e.jsx(Ae,{}),e.jsx("div",{className:"mt-7",children:e.jsx(_e,{})})]})}export{qe as component};
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.