1import{r as b,j as e}from"./map-context-8T8ckZq5.js";import{Y as y,a3 as w,J as I,I as C,C as k,Z as S}from"./index-BrI9cKls.js";import{u as _}from"./useMutation-D2FUPk3y.js";import{A as z,K as E}from"./AdminLayout-4hngj_-z.js";import{S as A,B as J}from"./CookieConsentBanner-Dk0RZAZR.js";import{v as h}from"./clarityTagging-DXHzvXA9.js";import{C as j}from"./circle-alert-D0AVmgFq.js";import{L as M}from"./lock-CAwDvhJz.js";import{S as O}from"./save-CQpK6x4o.js";import"./googleAdsConversion-HB9iT4cO.js";import"./badge-DBo0VhBL.js";import"./sheet--Zuvv_oc.js";import"./index-cC8qIDH2.js";import"./chevron-right-Cg221iaa.js";import"./collapsible-aVvM0VPf.js";import"./index-DQMzxqgL.js";import"./LOGO_ASAP_DARKBLUE-CkWx3GBd.js";import"./LOGO_ASAP-CiCtH8B-.js";import"./users-B7pCgje0.js";import"./chart-column-E0yg8y9o.js";import"./megaphone-Cc3EfIQF.js";import"./route-DGptyj13.js";import"./headphones-NtRkpt_B.js";import"./bell-Bhkmuj-s.js";import"./log-out-BGNcFn-_.js";import"./chevron-left-DGVZ6Z_2.js";import"./settings-BrWe72hK.js";import"./book-open-Cp01-OhB.js";import"./file-text-CMsqi63K.js";async function g(r,m){var n;const{data:l}=await S.auth.getSession(),d=(n=l.session)==null?void 0:n.access_token;if(!d)throw new Error("sessão expirada, entre novamente");const c=await fetch("https://ollzbnkfxfsusjtjssec.supabase.co/functions/v1/admin-integracoes",{method:r,headers:{Authorization:`Bearer ${d}`,apikey:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im9sbHpibmtmeGZzdXNqdGpzc2VjIiwicm9sZSI6ImFub24iLCJpYXQiOjE3ODU3MjYyMzIsImV4cCI6MjEwMTMwMjIzMn0.cJHpOt-gIlAPhNhgVwq3UlCNDsfCSRcsdkzacYVSjsQ",...m?{"Content-Type":"application/json"}:{}},...m?{body:JSON.stringify(m)}:{}}),t=await c.json().catch(()=>({}));if(!c.ok){const u={sem_autenticacao:"sua sessão expirou; entre novamente",sem_permissao:"esta tela é só para administradores",cofre_indisponivel:"o cofre ainda não está ligado neste ambiente",nome_nao_permitido:"este campo não pode ser alterado por aqui",valor_vazio:"escreva um valor antes de salvar",falha_ao_ler_cofre:"não consegui ler o cofre agora",falha_ao_gravar:"não consegui gravar no cofre agora"};throw new Error(u[t==null?void 0:t.error]??"não consegui falar com o cofre")}return t}function q({item:r}){return r.configurado?e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-full bg-emerald-500/10 px-2.5 py-1 text-xs font-medium text-emerald-600 dark:text-emerald-400",children:[e.jsx(k,{className:"h-3.5 w-3.5"}),"configurado",r.segredo?r.final&&e.jsxs("span",{className:"font-mono text-muted-foreground",children:["· termina em ",r.final]}):e.jsxs("span",{className:"font-mono text-muted-foreground",children:["· ",r.final]})]}):e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-full bg-muted px-2.5 py-1 text-xs text-muted-foreground",children:[e.jsx(j,{className:"h-3.5 w-3.5"}),"não configurado"]})}function le(){const{toast:r}=y(),m=w(),[l,d]=b.useState({}),{data:p,isLoading:c,error:t}=I({queryKey:["admin-integracoes"],queryFn:async()=>(await g("GET")).itens,staleTime:3e4}),n=_({mutationFn:async({nome:a,valor:o})=>g("POST",{nome:a,valor:o}),onSuccess:(a,o)=>{d(s=>{const i={...s};return delete i[o.nome],i}),m.invalidateQueries({queryKey:["admin-integracoes"]}),r({title:"Guardado no cofre",description:"A alteração vale na próxima chamada da integração."})},onError:a=>r({title:"Não deu certo",description:a.message,variant:"destructive"})}),u=(p??[]).reduce((a,o)=>{var s;return(a[s=o.grupo]||(a[s]=[])).push(o),a},{});return e.jsx(z,{children:e.jsxs("div",{className:"mx-auto w-full max-w-4xl space-y-6 p-4 md:p-6",children:[e.jsxs("header",{className:"space-y-2",children:[e.jsxs("h1",{className:"flex items-center gap-2 text-2xl font-semibold tracking-tight",children:[e.jsx(E,{className:"h-6 w-6"}),"Integrações"]}),e.jsx("p",{className:"max-w-2xl text-sm text-muted-foreground",children:"Senhas e endereços que o site usa para falar com Pipedrive, e-mail, ERP, Google Ads, WhatsApp, o modelo da LIA e o cofre de backup."}),e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-border bg-muted/40 p-3 text-sm",children:[e.jsx(A,{className:"mt-0.5 h-4 w-4 shrink-0 text-emerald-600"}),e.jsx("p",{className:"text-muted-foreground",children:"Os valores ficam no cofre do projeto, não no banco. Esta tela nunca mostra uma senha inteira: para trocar, escreva a
1nova por cima e salve."})]})]}),c&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(h,{className:"h-4 w-4 animate-spin"}),"lendo o cofre..."]}),t&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-destructive/40 bg-destructive/5 p-4 text-sm",children:[e.jsx(j,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-destructive",children:t.message}),e.jsx("p",{className:"mt-1 text-muted-foreground",children:"Se o cofre ainda não estiver ligado neste ambiente, é preciso configurar o acesso de administração do projeto uma vez."})]})]}),Object.entries(u).map(([a,o])=>e.jsxs("section",{className:"rounded-xl border border-border",children:[e.jsx("h2",{className:"border-b border-border px-4 py-3 text-sm font-semibold",children:a}),e.jsx("div",{className:"divide-y divide-border",children:o.map(s=>{var f;const i=l[s.nome]??"",x=n.isPending&&((f=n.variables)==null?void 0:f.nome)===s.nome;return e.jsxs("div",{className:"grid gap-3 p-4 md:grid-cols-[minmax(0,1fr)_minmax(0,1.3fr)] md:items-start",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[s.segredo&&e.jsx(M,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium",children:s.rotulo})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s.ajuda}),e.jsx(q,{item:s})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(C,{type:s.segredo?"password":"text",autoComplete:"off",placeholder:s.configurado?"escreva o valor novo para trocar":"ainda não configurado",value:i,onChange:v=>d(N=>({...N,[s.nome]:v.target.value})),className:"font-mono text-sm"}),e.jsxs(J,{size:"sm",disabled:!i.trim()||x,onClick:()=>n.mutate({nome:s.nome,valor:i.trim()}),children:[x?e.jsx(h,{className:"h-4 w-4 animate-spin"}):e.jsx(O,{className:"h-4 w-4"}),e.jsx("span",{className:"ml-1.5 hidden sm:inline",children:"Salvar"})]})]})]},s.nome)})})]},a))]})})}export{le 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.