PageSourceSearch

https://www.xpark.ai/assets/AdminViajantes-DlvmljyI.js

js xpark.ai collected 2026-10-05 14:02:39 UTC 29,101 bytes, 3 lines download raw bytes

1import{r as x,j as e,f as Q,B as v,d as E,g as T,a4 as te,I as U,Q as ae,V as re,X as ne,Y as ie,M as oe,a8 as le}from"./index-FWKSGZPO.js";import{C as R,a as M,b as $,c as q}from"./card-DTQVPU97.js";import{A as ce,a as de,b as me,c as pe,d as ue,e as xe,f as he,g as fe}from"./alert-dialog-Ch5-74qd.js";import{B as V}from"./badge-Cpd-8HxK.js";import{D as ee}from"./download-D6yxZerY.js";import{R as je}from"./refresh-cw-CD2FjEhk.js";import{M as ge}from"./message-circle-D33wQSco.js";const A=E;function _e(){const[a,p]=x.useState(!0),[l,m]=x.useState([]),[h,k]=x.useState([]),[t,n]=x.useState([]),[u,j]=x.useState(0),i=async()=>{p(!0);const[o,w,g,s]=await Promise.all([A.from("community_members").select("*").order("created_at",{ascending:!1}).limit(1e3),A.from("community_posts").select("*").order("created_at",{ascending:!1}).limit(200),A.from("community_reports").select("*").eq("status","open").order("created_at",{ascending:!1}),A.from("community_connections").select("id",{count:"exact",head:!0}).eq("status","accepted")]);m(o.data??[]),k(w.data??[]),n(g.data??[]),j(s.count??0),p(!1)};x.useEffect(()=>{i()},[]);const c=o=>{var w;return((w=l.find(g=>g.user_id===o))==null?void 0:w.display_name)??"Viajante"},b=async(o,w)=>{await A.from("community_posts").update({hidden:w}).eq("id",o),i()},y=async o=>{await A.from("community_reports").update({status:"resolved"}).eq("id",o),i()},D=async o=>{await A.from("community_members").update({left_at:new Date().toISOString()}).eq("user_id",o),i()},N=l.filter(o=>!o.left_at);return e.jsxs(R,{children:[e.jsx(M,{children:e.jsx($,{className:"text-base",children:"Wanderlust · uma comunidade xpark"})}),e.jsx(q,{className:"space-y-6 text-sm",children:a?e.jsx(Q,{className:"h-4 w-4 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{children:["Membros ativos: ",e.jsx("strong",{children:N.length})," · Conexões: ",e.jsx("strong",{children:u})," · Posts: ",e.jsx("strong",{children:h.length})," · Denúncias abertas: ",e.jsx("strong",{children:t.length})]}),t.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-semibold",children:"Denúncias abertas"}),t.map(o=>{const w=h.find(g=>g.id===o.post_id);return e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded border p-2",children:[e.jsx("span",{className:"truncate",children:w?`Post de ${c(w.author_id)}: ${w.body}`:"Comentário denunciado"}),e.jsxs("span",{className:"flex gap-2",children:[w&&!w.hidden&&e.jsx(v,{size:"sm",variant:"outline",onClick:()=>b(w.id,!0),children:"Ocultar"}),e.jsx(v,{size:"sm",onClick:()=>y(o.id),children:"Resolver"})]})]},o.id)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-semibold",children:"Posts recentes"}),h.slice(0,30).map(o=>e.jsxs("div",{className:"flex items-center justify-between gap-2 border-t pt-2",children:[e.jsxs("span",{className:"truncate",children:[c(o.author_id)," · ",o.destination,": ",o.body]}),e.jsx(v,{size:"sm",variant:"ghost",onClick:()=>b(o.id,!o.hidden),children:o.hidden?"Mostrar":"Ocultar"})]},o.id)),!h.length&&e.jsx("p",{className:"text-muted-foreground",children:"Nenhum post ainda."})]}),e.jsxs("div",{className:"overflow-x-auto",children:[e.jsx("p",{className:"mb-2 font-semibold",children:"Membros"}),e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-muted-foreground",children:[e.jsx("th",{className:"py-2 pr-4",children:"Nome"}),e.jsx("th",{className:"pr-4",children:"Destino"}),e.jsx("th",{className:"pr-4",children:"Entrada"}),e.jsx("th",{className:"pr-4",children:"Situação"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:l.slice(0,300).map(o=>e.jsxs("tr",{className:"border-t",children:[e.jsx("td",{className:"py-2 pr-4",children:o.display_name}),e.jsx("td",{className:"pr-4",children:o.destination??"-"}),e.jsx("td",{className:"pr-4",children:new Date(o.created_at).toLocaleDateString("pt-BR")}),e.jsx("td",{className:"pr-4",children:o.left_at?"saiu":o.visible?"ativo":"oculto"}),e.jsx("td",{children:!o.left_at&&e.jsx(v,{size:"sm",variant:"ghost",onClick:()=>D(o.user_id),children:"Remover"})})]}
1,o.user_id))})]})]})]})})]})}const z=E;function be(){const[a,p]=x.useState([]),[l,m]=x.useState([]),[h,k]=x.useState([]),t=async()=>{const[i,c,b]=await Promise.all([z.from("wanderlust_questions").select("*").eq("status","pending").order("created_at"),z.from("wanderlust_comments").select("*").eq("status","pending").order("created_at"),z.from("wanderlust_reports").select("*").eq("status","open").order("created_at",{ascending:!1})]);p(i.data??[]),m(c.data??[]),k(b.data??[])};x.useEffect(()=>{t()},[]);const n=async(i,c,b)=>{var D;const{data:y}=await E.auth.getUser();await z.from(i).update({status:b,moderated_by:(D=y.user)==null?void 0:D.id,moderated_at:new Date().toISOString()}).eq("id",c),t()},u=async(i,c)=>{c&&await n(i.target_table,i.target_id,"rejected"),await z.from("wanderlust_reports").update({status:"resolved"}).eq("id",i.id),t()},j=({row:i,table:c})=>e.jsxs("div",{className:"flex items-start justify-between gap-3 border-b py-2 text-sm",children:[e.jsxs("div",{children:[e.jsxs("p",{children:[e.jsx("strong",{children:i.public_name})," ",i.airport&&e.jsx(V,{variant:"outline",children:i.airport})," ",i.target_type&&e.jsxs(V,{variant:"outline",children:[i.target_type,": ",i.target_key]})]}),e.jsx("p",{className:"whitespace-pre-wrap",children:i.body})]}),e.jsxs("div",{className:"flex shrink-0 gap-1",children:[e.jsx(v,{size:"sm",onClick:()=>n(c,i.id,"approved"),children:"Aprovar"}),e.jsx(v,{size:"sm",variant:"outline",onClick:()=>n(c,i.id,"rejected"),children:"Recusar"})]})]});return e.jsxs(R,{children:[e.jsx(M,{children:e.jsx($,{className:"text-base",children:"Wanderlust: fila de moderação"})}),e.jsxs(q,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"font-semibold",children:["Posts pendentes (",a.length,")"]}),a.map(i=>e.jsx(j,{row:i,table:"wanderlust_questions"},i.id))]}),e.jsxs("div",{children:[e.jsxs("p",{className:"font-semibold",children:["Comentários pendentes (",l.length,")"]}),l.map(i=>e.jsx(j,{row:i,table:"wanderlust_comments"},i.id))]}),e.jsxs("div",{children:[e.jsxs("p",{className:"font-semibold",children:["Denúncias abertas (",h.length,")"]}),h.map(i=>e.jsxs("div",{className:"flex items-center justify-between gap-2 border-b py-2 text-sm",children:[e.jsxs("span",{children:[i.target_table==="wanderlust_comments"?"Comentário":"Post"," ",i.target_id.slice(0,8)]}),e.jsxs("span",{className:"flex gap-1",children:[e.jsx(v,{size:"sm",variant:"destructive",onClick:()=>u(i,!0),children:"Ocultar"}),e.jsx(v,{size:"sm",variant:"outline",onClick:()=>u(i,!1),children:"Manter"})]})]},i.id))]})]})]})}const P=E,ve={post:"Publicação",comment:"Comentário",profile:"Perfil"};function Ne(){const[a,p]=x.useState([]),l=async()=>{const{data:n}=await P.from("wl_reports").select("*").eq("status","open").order("created_at",{ascending:!1}).limit(100),u=await Promise.all((n??[]).map(async j=>{if(j.target_type==="post"){const{data:c}=await P.from("wl_posts").select("body, author_id, status").eq("id",j.target_id).maybeSingle();return{...j,preview:c?`[${c.status}] ${c.body}`:"(apagada)",author:c==null?void 0:c.author_id}}if(j.target_type==="comment"){const{data:c}=await P.from("wl_post_comments").select("body, author_id, status").eq("id",j.target_id).maybeSingle();return{...j,preview:c?`[${c.status}] ${c.body}`:"(apagado)",author:c==null?void 0:c.author_id}}const{data:i}=await P.from("wl_profiles").select("display_name, bio, blocked").eq("user_id",j.target_id).maybeSingle();return{...j,preview:i?`${i.display_name}${i.blocked?" [bloqueado]":""}: ${i.bio??""}`:"(sem perfil)",author:j.target_id}}));p(u)};x.useEffect(()=>{l()},[]);const m=n=>n==="post"?"wl_posts":"wl_post_comments",h=async(n,u)=>{const{error:j}=await P.from(m(n.target_type)).update({status:u}).eq("id",n.target_id);if(j)return T.error(j.message);await t(n)},k=async(n,u)=>{if(!n||!confirm("Bloquear este usuário na Wanderlust?"))return;const{error:j}=await P.from("wl_profiles").update({blocked:!0}).eq("user_id",n);if(j)return T.error(j.message);T.success("Usuário bloqueado."),u?await t(u):l()},t=async n=>{await P.from("wl_reports").update({status:"resolved"}).eq("id",n.id),l()};return e.jsxs(R,{children:[e.jsx(M,{children:e.jsxs($,{className:"text-base",children:["Wanderlust: denúncias da rede (",a.length,")"]})}),e.jsxs(q,{className:"space-y-2",children:[a.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Nenhuma de
1núncia aberta."}),a.map(n=>e.jsxs("div",{className:"flex flex-col gap-2 border-b py-2 text-sm md:flex-row md:items-start md:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{children:[e.jsx(V,{variant:"outline",children:ve[n.target_type]})," ",e.jsx("span",{className:"text-xs text-muted-foreground",children:new Date(n.created_at).toLocaleString("pt-BR")})]}),e.jsx("p",{className:"mt-1 line-clamp-3 whitespace-pre-wrap",children:n.preview}),n.reason&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Motivo: ",n.reason]})]}),e.jsxs("div",{className:"flex shrink-0 flex-wrap gap-1",children:[n.target_type!=="profile"&&e.jsxs(e.Fragment,{children:[e.jsx(v,{size:"sm",variant:"outline",onClick:()=>h(n,"hidden"),children:"Ocultar"}),e.jsx(v,{size:"sm",variant:"destructive",onClick:()=>h(n,"removed"),children:"Remover"})]}),e.jsx(v,{size:"sm",variant:"destructive",onClick:()=>k(n.author,n),children:"Bloquear usuário"}),e.jsx(v,{size:"sm",variant:"ghost",onClick:()=>t(n),children:"Manter"})]})]},n.id))]})]})}const B="não informado",we=a=>(a||"").split(/[,/(-]/)[0].normalize("NFD").replace(/[\u0300-\u036f]/g,"").trim().toLowerCase(),F=a=>(a||"").replace(/\D/g,"").slice(-8),ye=a=>a.toLocaleString("pt-BR",{style:"currency",currency:"BRL"}),H=a=>a?new Date(a).toLocaleDateString("pt-BR"):"-";function S(a,p){const l=new Map;return a.forEach(m=>{const h=p(m)||B;l.set(h,(l.get(h)??0)+1)}),[...l.entries()].sort((m,h)=>h[1]-m[1])}function Ce({title:a,rows:p}){const[l,m]=x.useState(!1),h=p.reduce((t,[,n])=>t+n,0)||1,k=l?p:p.slice(0,6);return e.jsxs(R,{className:"flex h-80 flex-col",children:[e.jsx(M,{className:"pb-2",children:e.jsx($,{className:"text-base",children:a})}),e.jsxs(q,{className:"flex min-h-0 flex-1 flex-col text-sm",children:[e.jsxs("div",{className:"min-h-0 flex-1 space-y-2 overflow-y-auto pr-1",children:[k.map(([t,n])=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between gap-2",children:[e.jsx("span",{className:"truncate capitalize",title:t,children:t}),e.jsxs("span",{className:"shrink-0 font-medium",children:[n," · ",Math.round(n/h*100),"%"]})]}),e.jsx("div",{className:"mt-1 h-1.5 rounded-full bg-muted",children:e.jsx("div",{className:"h-1.5 rounded-full bg-primary",style:{width:`${n/h*100}%`}})})]},t)),!p.length&&e.jsx("p",{className:"text-muted-foreground",children:"Sem respostas com esses filtros."})]}),p.length>6&&e.jsx("button",{type:"button",onClick:()=>m(!l),className:"mt-2 self-start text-xs font-medium text-primary underline",children:l?"Mostrar menos":`Ver todas (${p.length})`})]})]})}function ke(a){if(!a.length)return"";const p=Object.keys(a[0]),l=m=>`"${String(m??"").replace(/"/g,'""')}"`;return[p.join(";"),...a.map(m=>p.map(h=>l(m[h])).join(";"))].join(`
2`)}function Se(a,p){const l=new Blob(["\uFEFF"+p],{type:"text/csv;charset=utf-8"}),m=document.createElement("a");m.href=URL.createObjectURL(l),m.download=a,m.click()}const X=[{label:"Quando é a viagem",get:a=>a.booking_timing},{label:"Aeroporto",get:a=>a.airport||""},{label:"Profissão",get:a=>a.profession==="Outra"&&a.profession_other?`Outra: ${a.profession_other}`:a.profession},{label:"Voos por ano",get:a=>a.flights_per_year},{label:"Tipo de viagem",get:a=>a.trip_scope},{label:"Motivo",get:a=>a.trip_reason},{label:"Destino",get:a=>a.destination||""},{label:"Companhia aérea",get:a=>a.airline},{label:"Voo de volta",get:a=>a.return_flight||""},{label:"Com quem viaja",get:a=>a.companions||""},{label:"Crianças",get:a=>a.kids_count?`${a.kids_count}${a.kids_ages?` (${a.kids_ages})`:""}`:""},{label:"Pet",get:a=>a.has_pet==null?"":a.has_pet?"sim":"não"},{label:"Faixa etária",get:a=>a.age_range||""},{label:"Estilo de viagem",get:a=>a.travel_style||""},{label:"Interesses",get:a=>(a.interests??[]).join(", ")},{label:"Próximos destinos",get:a=>a.next_destinations||""},{label:"Próxima viagem",get:a=>a.next_trip_when||""},{label:"Aceita marketing",get:a=>a.consent_marketing?"sim":"não"},{label:"Aceita comunidade",get:a=>a.consent_community?"sim":"não"}],G={q:"",airport:"",profession:"",trip_reason:"",flights:"",travel_style:"",interest:"",age:"",companions:"",next_trip:"",credit:"",from:"",to:"",marketing:!1,community:!1};function Ee({resps:a,credits:p}){const[l,m]=x.useState([]),[h,k]=x.useState([]),[t,n]=x.useState(G),[u,j]=x.useState(null);x.useEffect(()=>{(async()=>{const[{data:s},{data:r}]=await Promise.all([E.from("profiles").select("id, full_name, email, phone").limit(5e3),E.from("bookings").select("id, customer_name, customer_email, customer_phone, start_date, status, total_amount").order("start_date",{ascending:!1}).limit(5e3)]);m(s??[]),k(r??[])})()},[]);const i=x.useMemo(()=>{const s=new Map;l.forEach(d=>{const _=F(d.phone);_&&s.set(_,{full_name:d.full_name,email:d.email})});const r=new Map;h.forEach(d=>{const _=F(d.customer_phone);_&&r.set(_,[...r.get(_)??[],d])});const f=new Map;p.forEach(d=>{const _=F(d.phone);f.set(_,[...f.get(_)??[],d])});const C=new Map;return a.forEach(d=>{const _=F(d.phone)||d.id;C.set(_,[...C.get(_)??[],d])}),[...C.entries()].map(([d,_])=>{var Y,J;const W=_.slice().sort((O,se)=>se.created_at.localeCompare(O.created_at)),I=r.get(d)??[],L=s.get(d);return{key:d,name:(L==null?void 0:L.full_name)||((Y=I.find(O=>O.customer_name))==null?void 0:Y.customer_name)||B,email:(L==null?void 0:L.email)||((J=I.find(O=>O.customer_email))==null?void 0:J.customer_email)||B,phone:W[0].phone,resp:W[0],answers:W,bookings:I,credits:f.get(d)??[]}}).sort((d,_)=>_.resp.created_at.localeCompare(d.resp.created_at))},[a,p,l,h]),c=s=>{if(!s.credits.length)return"";const r=s.credits[0];return r.status==="issued"&&new Date(r.expires_at).getTime()<Date.now()?"expirado":{issued:"emitido",reserved:"reservado",used:"usado",expired:"expirado"}[r.status]??r.status},b=x.useMemo(()=>i.filter(s=>{const r=s.resp,f=t.q.trim().toLowerCase();return!(f&&![s.name,s.email,s.phone].join(" ").toLowerCase().includes(f)||t.airport&&(r.airport||"")!==t.airport||t.profession&&r.profession!==t.profession||t.trip_reason&&r.trip_reason!==t.trip_reason||t.flights&&r.flights_per_year!==t.flights||t.travel_style&&(r.travel_style||"")!==t.travel_style||t.interest&&!(r.interests??[]).includes(t.interest)||t.age&&(r.age_range||"")!==t.age||t.companions&&(r.companions||"")!==t.companions||t.next_trip&&(r.next_trip_when||"")!==t.next_trip||t.credit&&c(s)!==t.credit||t.from&&r.created_at.slice(0,10)<t.from||t.to&&r.created_at.slice(0,10)>t.to||t.marketing&&!r.consent_marketing||t.community&&!r.consent_community)}),[i,t]),y=s=>[...new Set(i.map(r=>
2(s(r.resp)||"").trim()).filter(Boolean))].sort(),D=[...new Set(i.flatMap(s=>s.resp.interests??[]))].sort(),N=b.map(s=>s.resp),o=[{title:"Pautas: companhia x aeroporto",rows:S(N,s=>`${s.airline} em ${s.airport||B}`)},{title:"Pautas: motivo x aeroporto",rows:S(N,s=>`${s.trip_reason} em ${s.airport||B}`)},{title:"Profissões",rows:S(N,s=>s.profession==="Outra"&&s.profession_other?`Outra: ${s.profession_other}`:s.profession)},{title:"Destinos",rows:S(N,s=>we(s.destination))},{title:"Companhias",rows:S(N,s=>s.airline)},{title:"Viagens por ano",rows:S(N,s=>s.flights_per_year)},{title:"Motivo",rows:S(N,s=>s.trip_reason)},{title:"Com quem viaja",rows:S(N.filter(s=>s.companions),s=>s.companions)},{title:"Faixa etária",rows:S(N.filter(s=>s.age_range),s=>s.age_range)},{title:"Estilo",rows:S(N.filter(s=>s.travel_style),s=>s.travel_style)},{title:"Interesses",rows:S(N.flatMap(s=>(s.interests??[]).map(r=>({i:r}))),s=>s.i)},{title:"Próxima viagem",rows:S(N.filter(s=>s.next_trip_when),s=>s.next_trip_when)}],w=()=>{const s=b.map(r=>{const f={nome:r.name,email:r.email,telefone:r.phone,respondido_em:new Date(r.resp.created_at).toLocaleString("pt-BR"),reservas:r.bookings.length,credito:c(r)||"sem crédito"};return X.forEach(C=>{f[C.label]=C.get(r.resp)||B}),f});Se("viajantes-respostas.csv",ke(s))},g=(s,r,f,C)=>e.jsxs("label",{className:"text-xs",children:[e.jsx("span",{className:"mb-1 block text-muted-foreground",children:s}),e.jsxs("select",{value:r,onChange:d=>f(d.target.value),className:"h-9 w-full rounded-md border bg-background px-2 text-sm",children:[e.jsx("option",{value:"",children:"Todos"}),C.map(d=>e.jsx("option",{value:d,children:d},d))]})]});return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(R,{children:[e.jsx(M,{className:"pb-3",children:e.jsx($,{className:"text-base",children:"Respostas por viajante"})}),e.jsxs(q,{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-4",children:[e.jsxs("label",{className:"text-xs sm:col-span-2",children:[e.jsx("span",{className:"mb-1 block text-muted-foreground",children:"Buscar por nome, telefone ou e-mail"}),e.jsxs("span",{className:"relative block",children:[e.jsx(te,{className:"absolute left-2 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(U,{className:"pl-8",value:t.q,onChange:s=>n({...t,q:s.target.value}),placeholder:"Buscar"})]})]}),g("Aeroporto",t.airport,s=>n({...t,airport:s}),y(s=>s.airport)),g("Profissão",t.profession,s=>n({...t,profession:s}),y(s=>s.profession)),g("Motivo",t.trip_reason,s=>n({...t,trip_reason:s}),y(s=>s.trip_reason)),g("Voos por ano",t.flights,s=>n({...t,flights:s}),y(s=>s.flights_per_year)),g("Estilo",t.travel_style,s=>n({...t,travel_style:s}),y(s=>s.travel_style)),g("Interesse",t.interest,s=>n({...t,interest:s}),D),g("Faixa etária",t.age,s=>n({...t,age:s}),y(s=>s.age_range)),g("Com quem viaja",t.companions,s=>n({...t,companions:s}),y(s=>s.companions)),g("Próxima viagem",t.next_trip,s=>n({...t,next_trip:s}),y(s=>s.next_trip_when)),g("Crédito",t.credit,s=>n({...t,credit:s}),["emitido","reservado","usado","expirado"]),e.jsxs("label",{className:"text-xs",children:[e.jsx("span",{className:"mb-1 block text-muted-foreground",children:"Respondeu de"}),e.jsx(U,{type:"date",value:t.from,onChange:s=>n({...t,from:s.target.value})})]}),e.jsxs("label",{className:"text-xs",children:[e.jsx("span",{className:"mb-1 block text-muted-foreground",children:"até"}),e.jsx(U,{type:"date",value:t.to,onChange:s=>n({...t,to:s.target.value})})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-4 text-sm",children:[e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:t.marketing,onChange:s=>n({...t,marketing:s.target.checked})}),"Só quem aceitou marketing"]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:t.community,onChange:s=>n({...t,community:s.target.checked})}),"Só quem aceitou a comunidade"]}),e.jsx(v,{variant:"ghost",size:"sm",onClick:()=>n(G),children:"Limpar filtros"}),e.jsxs("span",{className:"text-muted-foreground",children:[b.length," de ",i.length," viajantes"]}),e.jsxs(v,{variant:"outline",size:"sm",disabled:!b.length,onClick:w,children:[e.jsx(ee,{className:"mr-2 h-4 w-4"}),"Exportar o que está filtrado"]})]}),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-muted-foreground",children:[e.jsx("th",{className:"py-2 pr-4",children:"Nome"}),e.jsx("th",{className:"pr-4",children:"Telefone"}),e.jsx("th",{className:"pr-4",children:"E-mail"}),e.jsx("th",{className:"pr-4",children:"Aeroporto"}),e.jsx("th",{className:"pr-4",children:"Respondeu em"}),e.jsx("th",{className:"pr-4",children:"Reservas"}),e.jsx("th",{children:"Crédito"})]})}),e.jsxs("tbody",{children:[b.slice(0,300).map(s=>e.jsxs("tr",{className:"cursor-pointer border-t hover:bg-muted/40",onClick:()=>j(s),children:[e.jsxs("td",{className:"py-2 pr-4 font-medium",children:[s.name,s.answers.length>1&&e.jsxs(V,{variant:"outline",className:"ml-2",children:[s.answers.length," respostas"]})]}),e.jsx("td",{className:"pr-4",children:s.phone}),e.jsx("td",{className:"pr-4",children:s.email}),e.jsx("td",{className:"pr-4",children:s.resp.airport||"-"}),e.jsx("td",{className:"pr-4",children:H(s.resp.created_at)}),e.jsx("td",{className:"pr-4",children:s.bookings.length||"-"}),e.jsx("td",{children:c(s)||"-"})]},s.key)),!b.length&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"py-4 text-muted-foreground",children:"Nenhum viajante com esses filtros."})})]})]})}),b.length>300&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Mostrando os 300 mais recentes. Use os filtros ou exporte para ver o resto."})]})]}),e.jsx("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-3",children:o.map(s=>e.jsx(Ce,{title:s.title,rows:s.rows},s.title))}),e.jsx(ae,{open:!!u,onOpenChange:s=>!s&&j(null),children:e.jsx(re,{className:"w-full overflow-y-auto sm:max-w-xl",children:u&&e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:e.jsx(ie,{children:u.name})}),e.jsxs("div",{className:"mt-4 space-y-5 text-sm",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Telefone:"})," ",u.phone]}
2),e.jsxs("p",{children:[e.jsx("span",{className:"text-muted-foreground",children:"E-mail:"})," ",u.email]})]}),u.answers.map((s,r)=>e.jsxs("div",{className:"space-y-1 rounded-md border p-3",children:[e.jsxs("p",{className:"font-medium",children:["Resposta ",u.answers.length>1?`${r+1} `:"","de ",new Date(s.created_at).toLocaleString("pt-BR")]}),X.map(f=>e.jsxs("div",{className:"flex justify-between gap-3 border-t py-1",children:[e.jsx("span",{className:"text-muted-foreground",children:f.label}),e.jsx("span",{className:"text-right",children:f.get(s)||B})]},f.label))]},s.id)),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"font-medium",children:["Reservas (",u.bookings.length,")"]}),u.bookings.length?u.bookings.slice(0,20).map(s=>e.jsxs("div",{className:"flex justify-between gap-3 border-t py-1",children:[e.jsxs("span",{children:[H(s.start_date)," · ",s.status]}),e.jsx("span",{children:ye(Number(s.total_amount)||0)})]},s.id)):e.jsx("p",{className:"text-muted-foreground",children:"Nenhuma reserva ligada a este telefone."})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"font-medium",children:["Créditos (",u.credits.length,")"]}),u.credits.length?u.credits.map(s=>e.jsxs("div",{className:"flex justify-between gap-3 border-t py-1",children:[e.jsx("span",{className:"font-mono",children:s.code}),e.jsxs("span",{children:[c(u)," · vence ",H(s.expires_at)]})]},s.id)):e.jsx("p",{className:"text-muted-foreground",children:"Nenhum crédito emitido."})]})]})]})})})]})}const K=a=>a.toLocaleString("pt-BR",{style:"currency",currency:"BRL"}),Z={issued:"Emitidos",reserved:"Reservados",used:"Usados",expired:"Expirados"};function De(a){if(!a.length)return"";const p=Object.keys(a[0]),l=m=>`"${String(m??"").replace(/"/g,'""')}"`;return[p.join(";"),...a.map(m=>p.map(h=>l(m[h])).join(";"))].join(`
3`)}function Re(a,p){const l=new Blob(["\uFEFF"+p],{type:"text/csv;charset=utf-8"}),m=document.createElement("a");m.href=URL.createObjectURL(l),m.download=a,m.click()}function Oe(){const[a,p]=x.useState([]),[l,m]=x.useState([]),[h,k]=x.useState(!0),[t,n]=x.useState(null),[u,j]=x.useState(!1),[i,c]=x.useState(null),[b,y]=x.useState(!1),D=async()=>{k(!0);const[{data:r},{data:f}]=await Promise.all([E.from("traveler_responses").select("*").order("created_at",{ascending:!1}).limit(5e3),E.from("traveler_credits").select("id, code, phone, status, expires_at, used_amount, created_at").order("created_at",{ascending:!1}).limit(5e3)]);p(r??[]),m(f??[]),k(!1)},N=async()=>{const{data:r,error:f}=await E.functions.invoke("admin-traveler-broadcast",{body:{action:"preview"}});f||n(r)};x.useEffect(()=>{D(),N()},[]);const o=x.useMemo(()=>{const r=Date.now(),f={issued:0,reserved:0,used:0,expired:0};let C=0;return l.forEach(d=>{const _=d.status==="issued"&&new Date(d.expires_at).getTime()<r?"expired":d.status;f[_]=(f[_]??0)+1,d.status==="used"&&(C+=Number(d.used_amount)||0)}),{s:f,total:C}},[l]),w=async()=>{if(!i)return;y(!0);const{data:r,error:f}=await E.functions.invoke("admin-traveler-broadcast",{body:{action:i,confirm:!0}});if(y(!1),c(null),f){T.error("Falha no envio");return}T.success(`${r.sent??0} convites enviados`),n(r)},g=t?Math.min(t.whatsappPending,t.whatsappLeftToday):0,s=t?Math.min(t.emailPending,t.emailBatch):0;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-semibold",children:"Programa de Viajantes"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Respostas do questionário e diárias grátis."})]}),e.jsxs(v,{variant:"outline",size:"sm",onClick:()=>{D(),N()},children:[e.jsx(je,{className:"mr-2 h-4 w-4"}),"Atualizar"]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-5",children:[e.jsx(R,{children:e.jsxs(q,{className:"p-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Respostas"}),e.jsx("p",{className:"text-2xl font-semibold",children:a.length})]})}),["issued","reserved","used","expired"].map(r=>e.jsx(R,{children:e.jsxs(q,{className:"p-4",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Créditos ",Z[r].toLowerCase()]}),e.jsx("p",{className:"text-2xl font-semibold",children:o.s[r]??0})]})},r))]}),e.jsxs("p",{className:"text-sm",children:["Valor total já concedido em diárias usadas: ",e.jsx("strong",{children:K(o.total)})]}),e.jsxs(R,{children:[e.jsx(M,{children:e.jsx($,{className:"text-base",children:"Convite para a base antiga (envio manual)"})}),e.jsxs(q,{className:"space-y-4 text-sm",children:[t?e.jsxs("p",{children:["Base: ",e.jsx("strong",{children:t.total})," pessoas com reserva confirmada (uma por telefone, sem descadastrados), ",e.jsx("strong",{children:t.withEmail})," com e-mail. Já responderam: ",t.responded,". Faltam receber: ",t.emailPending," por e-mail e ",t.whatsappPending," por WhatsApp."]}):e.jsx(Q,{className:"h-4 w-4 animate-spin"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs(v,{disabled:!t||s===0,onClick:()=>c("send_email"),children:[e.jsx(oe,{className:"mr-2 h-4 w-4"}),"Enviar e-mail (",s," neste lote)"]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx(le,{checked:u,onCheckedChange:j}),"WhatsApp para a base antiga"]}),e.jsxs(v,{variant:"outline",disabled:!u||!t||g===0,onClick:()=>c("send_whatsapp"),children:[e.jsx(ge,{className:"mr-2 h-4 w-4"}),"Enviar WhatsApp (",g," hoje)"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:'WhatsApp: no máximo 40 por dia, com a opção "responda SAIR". O número é o mesmo das confirmações; envios em massa podem levar ao bloqueio.'})]})]}),e.jsx(Ee,{resps:a,credits:l}),e.jsx("div",{className:"flex flex-wrap gap-2",children:e.jsxs(v,{variant:"outline",size:"sm",disabled:!l.length,onClick:()=>Re("viajantes-creditos.csv",De(l)),children:[e.jsx(ee,{className:"mr-2 h-4 w-4"}),"Créditos em CSV"]})}),e.jsxs(R,{children:[e.jsx(M,{children:e.jsx($,{className:"text-base",children:"Créditos emitidos"})}),e.jsx(q,{className:"overflow-x-auto",children:h?e.jsx(Q,{className:"h-4 w-4 animate-spin"}):e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-muted-foreground",children:[e.jsx("th",{className:"py-2 pr-4",children:"Código"}),e.jsx("th",{className:"pr-4",children:"Telefone"}),e.jsx("th",{className:"pr-4",children:"Situação"}),e.jsx("th",{className:"pr-4",children:"Validade"}),e.jsx("th",{children:"Valor usado"})]})}),e.jsx("tbody",{children:l.slice(0,200).map(r=>{var C;const f=r.status==="issued"&&new Date(r.expires_at).getTime()<Date.now()?"expired":r.status;return e.jsxs("tr",{className:"border-t",children:[e.jsx("td",{className:"py-2 pr-4 font-mono",children:r.code}),e.jsx("td",{className:"pr-4",children:r.phone}),e.jsx("td",{className:"pr-4",children:(C=Z[f])==null?void 0:C.replace(/s$/,"").toLowerCase()}),e.jsx("td",{className:"pr-4",children:new Date(r.expires_at).toLocaleDateString("pt-BR")}),e.jsx("td",{children:r.used_amount?K(Number(r.used_amount)):"-"})]},r.id)})})]})})]}),e.jsx(be,{}),e.jsx(Ne,{}),e.jsx(_e,{}),e.jsx(ce,{open:!!i,onOpenChange:r=>!r&&c(null),children:e.jsxs(de,{children:[e.jsxs(me,{children:[e.jsx(pe,{children:"Confirmar envio"}),e.jsx(ue,{children:i==="send_email"?`${s} pessoas vão receber o convite por e-mail agora.`:`${g} pessoas vão receber o convite por WhatsApp agora.`})]}),e.jsxs(xe,{children:[e.jsx(he,{disabled:b,children:"Cancelar"}),e.jsx(fe,{disabled:b,onClick:r=>{r.preventDefault(),w()},children:b?"Enviando...":"Enviar"})]})]})})]})}export{Oe 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.