1import{s as q,r as l,j as e,H,L as I,B as N,F as V,e as m}from"./index-Dxm6N3LP.js";import{u as G}from"./useAuth-DxZh9XUt.js";import{s as f}from"./client-QodGYSS2.js";import{s as L,b as T,l as p}from"./formSecurity-CKI6XydN.js";import{A as J}from"./arrow-left-CznwGBZ7.js";import{D as K}from"./download-BQ9pvODf.js";import{T as v}from"./trash-2-BoZcOlNn.js";import{S as z}from"./shield-alert-BNGZSkQI.js";const w=["novo","em_contato","convertido","descartado","suspected_spam","blocked"],R=n=>n.status==="suspected_spam"||n.status==="blocked"||p(n.name)||p(n.company)||p(n.email)||p(n.phone)||p(n.message),ae=()=>{const{user:n,isAdmin:h,loading:y}=G(),k=q(),[i,S]=l.useState([]),[_,C]=l.useState(!0),[E,B]=l.useState(null),[x,M]=l.useState("all"),[o,j]=l.useState(new Set);l.useEffect(()=>{document.title="Painel Admin · Contatos â TDec"},[]),l.useEffect(()=>{y||(!n||!h)&&k("/admin/login",{replace:!0})},[n,h,y,k]);const b=async()=>{C(!0);const{data:t,error:s}=await f.from("contact_submissions").select("id, name, company, email, phone, message, status, rejection_reason, ip_address, created_at").order("created_at",{ascending:!1});s?m.error(s.message):S(t??[]),j(new Set),C(!1)};l.useEffect(()=>{h&&b()},[h]);const A=async t=>{if(!window.confirm("Excluir este contato?"))return;const{error:s}=await f.from("contact_submissions").delete().eq("id",t);s?m.error(s.message):(m.success("Contato excluÃdo."),b())},F=async()=>{if(!o.size||!window.confirm(`Excluir ${o.size} contato(s)?`))return;const{error:t}=await f.from("contact_submissions").delete().in("id",Array.from(o));t?m.error(t.message):(m.success(`${o.size} contato(s) excluÃdo(s).`),b())},$=async(t,s)=>{const{error:r}=await f.from("contact_submissions").update({status:s}).eq("id",t);r?m.error(r.message):S(c=>c.map(a=>a.id===t?{...a,status:s}:a))},u=l.useMemo(()=>x==="all"?i:i.filter(t=>t.status===x),[x,i]),D=t=>{j(s=>{const r=new Set(s);return r.has(t)?r.delete(t):r.add(t),r})},O=()=>{j(new Set(u.filter(t=>t.status==="suspected_spam"||t.status==="blocked").map(t=>t.id)))},U=()=>{if(!i.length){m.info("Nada para exportar");return}const t=["Data","Nome","Empresa","E-mail","Telefone","Mensagem","Status","Motivo"],s=i.map(d=>[new Date(d.created_at).toISOString(),d.name,d.company,d.email,d.phone,d.message,d.status,d.rejection_reason??""].map(P=>`"${String(P).replace(/"/g,'""')}"`).join(",")),r=[t.join(","),...s].join(` 2`),c=new Blob([r],{type:"text/csv;charset=utf-8"}),a=URL.createObjectURL(c),g=document.createElement("a");g.href=a,g.download=`contatos-tdec-${new Date().toISOString().slice(0,10)}.csv`,g.click(),URL.revokeObjectURL(a)};return e.jsxs("div",{className:"min-h-screen bg-background text-foreground",children:[e.jsx(H,{}),e.jsx("main",{className:"pt-32 pb-24",children:e.jsxs("div",{className:"container-tdec",children:[e.jsxs(I,{to:"/admin",className:"inline-flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground mb-4",children:[e.jsx(J,{className:"w-4 h-4"})," Painel Admin"]}),e.jsxs("div",{className:"flex flex-wrap items-end justify-between gap-4 mb-6",children:[e.jsxs("div",{children:[e.jsx("div",{className:"eyebrow mb-2",children:"Painel Admin"}),e.jsx("h1",{className:"font-display text-3xl md:text-4xl font-bold",children:"Contatos re
2cebidos"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:'Formulários "Fale com um especialista"'})]}),e.jsxs(N,{onClick:U,variant:"hero",children:[e.jsx(K,{className:"w-4 h-4"})," Exportar CSV"]})]}),e.jsx("div",{className:"flex flex-wrap gap-2 mb-4",children:["all",...w].map(t=>e.jsx("button",{onClick:()=>M(t),className:`px-3 py-1.5 rounded-full text-xs font-mono uppercase tracking-[0.15em] border transition-colors ${x===t?t==="suspected_spam"||t==="blocked"?"bg-destructive/20 border-destructive/50 text-destructive":"bg-primary/15 border-primary/40 text-primary-glow":"border-border text-muted-foreground hover:text-foreground"}`,children:t==="all"?`Todas (${i.length})`:`${t} (${i.filter(s=>s.status===t).length})`},t))}),(x==="suspected_spam"||x==="blocked"||o.size>0)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-4 text-xs",children:[e.jsx(N,{size:"sm",variant:"outline",onClick:O,children:"Selecionar todos suspeitos"}),e.jsxs(N,{size:"sm",variant:"destructive",disabled:!o.size,onClick:F,children:[e.jsx(v,{className:"w-3.5 h-3.5"})," Excluir selecionados (",o.size,")"]})]}),e.jsx("div",{className:"card-tdec overflow-hidden hidden md:block",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-xs font-mono uppercase tracking-[0.15em] text-muted-foreground border-b border-border",children:[e.jsx("th",{className:"px-3 py-3 w-8"}),e.jsx("th",{className:"px-4 py-3",children:"Data"}),e.jsx("th",{className:"px-4 py-3",children:"Nome"}),e.jsx("th",{className:"px-4 py-3",children:"Empresa"}),e.jsx("th",{className:"px-4 py-3",children:"E-mail"}),e.jsx("th",{className:"px-4 py-3",children:"Telefone"}),e.jsx("th",{className:"px-4 py-3",children:"Mensagem"}),e.jsx("th",{className:"px-4 py-3",children:"Status"}),e.jsx("th",{className:"px-4 py-3 text-right",children:"Ações"})]})}),e.jsx("tbody",{children:_?e.jsx("tr",{children:e.jsx("td",{colSpan:9,className:"px-5 py-10 text-center text-muted-foreground",children:"Carregando..."})}):u.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:9,className:"px-5 py-10 text-center text-muted-foreground",children:"Nenhum contato."})}):u.map(t=>{const s=R(t),r=s?null:L(t.email),c=s?null:T(t.phone);return e.jsxs("tr",{className:`border-b border-border/60 hover:bg-muted/20 align-top ${s?"bg-destructive/5":""}`,children:[e.jsx("td",{className:"px-3 py-3",children:e.jsx("input",{type:"checkbox",checked:o.has(t.id),onChange:()=>D(t.id)})}),e.jsxs("td",{className:"px-4 py-3 text-muted-foreground font-mono text-xs whitespace-nowrap",children:[new Date(t.created_at).toLocaleString("pt-BR"),s&&t.rejection_reason&&e.jsxs("div",{className:"mt-1 text-destructive inline-flex items-center gap-1",children:[e.jsx(z,{className:"w-3 h-3"})," ",t.rejection_reason]})]}),e.jsx("td",{className:"px-4 py-3 font-medium break-all max-w-[180px]",children:t.name}),e.jsx("td",{className:"px-4 py-3 text-muted-foreground break-all max-w-[180px]",children:t.company}),e.jsx("td",{className:"px-4 py-3 text-muted-foreground break-all max-w-[220px]",children:r?e.jsx("a",{href:r,className:"hover:text-primary-glow",children:t.email}):e.jsx("span",{children:t.email})}),e.jsx("td",{className:"px-4 py-3 text-muted-foreground break-all max-w-[140px]",children:c?e.jsx("a",{href:c,className:"hover:text-primary-glow",children:t.phone}):e.jsx("span",{children:t.phone})}),e.jsx("td",{className:"px-4 py-3 text-muted-foreground max-w-[320px]",children:e.jsx("button",{onClick:()=>B(E===t.id?null:t.id),className:"text-left break-words",title:"Expandir",children:e.jsx("span",{className:E===t.id?"":"line-clamp-2",children:t.message})})}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("select",{value:t.status,onChange:a=>$(t.id,a.target.value),className:`bg-background border rounded px-2 py-1 text-xs ${s?"border-destructive/50 text-destructive":"border-border"}`,children:w.map(a=>e.jsx("option",{value:a,children:a},a))})}),e.jsx("td",{className:"px-4 py-3 text-right",children:e.jsx("button",{onClick:()=>A(t.id),className:"w-8 h-8 inline-flex items-center justify-center rounded hover:bg-destructive/20 hover:text-destructive text-muted-foreground",title:"Excluir",children:e.jsx(v,{className:"w-4 h-4"})})})]},t.id)})})]})})}),e.jsx("div",{className:"md:hidden space-y-3",children:_?e.jsx("div",{className:"card-tdec p-6 text-center text-muted-foreground text-sm",children:"Carregando..."}):u.length===0?e.jsx("div",{className:"card-tdec p-6 text-center text-muted-foreground text-sm",children:"Nenhum contato."}):u.map(t=>{const s=R(t),r=s?null:L(t.email),c=s?null:T(t.phone);return e.jsxs("div",{className:`card-tdec p-4 space-y-3 ${s?"border-destructive/40 bg-destructive/5":""}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"font-medium text-base break-all",children:t.name}),e.jsx("div",{className:"text-xs text-muted-foreground break-all",children:t.company})]}),e.jsx("input",{type:"checkbox",checked:o.has(t.id),onChange:()=>D(t.id),className:"mt-1"})]}),s&&t.rejection_reason&&e.jsxs("div",{className:"text-[10px] font-mono text-destructive inline-flex items-center gap-1",children:[e.jsx(z,{className:"w-3 h-3"})," ",t.rejection_reason]}),e.jsxs("div",{className:"text-sm space-y-1 break-all",children:[r?e.jsx("a",{href:r,className:"text-primary-glow",children:t.email}):e.jsx("div",{className:"text-muted-foreground",children:t.email}),c?e.jsx("a",{href:c,className:"block text-muted-foreground",children:t.phone}):e.jsx("div",{className:"text-muted-foreground",children:t.phone})]}),e.jsx("p",{className:"text-sm text-muted-foreground whitespace-pre-wrap break-words",children:t.message}),e.jsx("div",{className:"text-[10px] font-mono uppercase tracking-wider text-muted-foreground",children:new Date(t.created_at).toLocaleStr
2ing("pt-BR")}),e.jsxs("div",{className:"flex items-center justify-between gap-2 pt-2 border-t border-border/50",children:[e.jsx("select",{value:t.status,onChange:a=>$(t.id,a.target.value),className:`bg-background border rounded px-2 py-1 text-xs flex-1 ${s?"border-destructive/50 text-destructive":"border-border"}`,children:w.map(a=>e.jsx("option",{value:a,children:a},a))}),e.jsx("button",{onClick:()=>A(t.id),className:"w-9 h-9 inline-flex items-center justify-center rounded hover:bg-destructive/20 hover:text-destructive text-muted-foreground border border-border",title:"Excluir",children:e.jsx(v,{className:"w-4 h-4"})})]})]},t.id)})})]})}),e.jsx(V,{})]})};export{ae 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.