1import{j as e}from"./vendor-motion-C5FObYmw.js";import{a as z}from"./vendor-query-S2mA_Wh8.js";import{bm as P,B as f,b0 as S,bf as I,K as D,L as F,M as E,j as b,C as d,bt as H,H as o,R as x,V as u,aZ as L,J as h,k as m,bu as g,aE as R,ab as T,b3 as p}from"./index-D5Z3iEdy.js";import{s as y}from"./ArrowLeft.es-jcOm_wmj.js";import{c as U}from"./SignIn.es-BMUaCg_7.js";import{d as V,u as B}from"./vendor-react-B8Ra2ABZ.js";import"./vendor-helmet-C1O7rrm-.js";import"./vendor-ui-DH9CwqBQ.js";import"./vendor-charts-sgZODtTB.js";import"./vendor-flow-4lyVEpXM.js";import"./vendor-dnd-BVlXN6uJ.js";function O(i,c){return i?i.split(" ").map(a=>a[0]).join("").slice(0,2).toUpperCase():c?c.slice(0,2).toUpperCase():"??"}function l({label:i,value:c,mono:a}){return e.jsxs("div",{className:"flex items-center justify-between py-1",children:[e.jsx("span",{className:"text-muted-foreground text-sm",children:i}),e.jsx("span",{className:`text-sm text-right truncate max-w-[60%] ${a?"font-mono text-xs":""}`,children:c})]})}function K(i){const c={active:{label:"Ativo",className:"bg-emerald-500/15 text-emerald-400 border-emerald-500/30"},trialing:{label:"Trial",className:"bg-sky-500/15 text-sky-400 border-sky-500/30"},past_due:{label:"Inadimplente",className:"bg-amber-500/15 text-amber-400 border-amber-500/30"},canceled:{label:"Cancelado",className:"bg-red-500/15 text-red-400 border-red-500/30"},inactive:{label:"Inativo",className:"bg-muted text-muted-foreground border-border"}},a=c[i]||c.inactive;return e.jsx(b,{variant:"outline",className:a.className,children:a.label})}function le(){var _;const{id:i}=V(),c=B(),{data:a,isLoading:w,isFetching:v,refetch:C}=z({queryKey:["admin-customer-view",i],queryFn:async()=>{if(!i)return null;const[s,M,$,A,q]=await Promise.all([p("profiles",`select=*&id=eq.${i}&limit=1`),p("user_credits",`select=*&user_id=eq.${i}&limit=1`),p("subscriptions",`select=*&user_id=eq.${i}&order=created_at.desc&limit=1`),p("offers",`select=id,title,status,is_archived,url,created_at&user_id=eq.${i}&order=created_at.desc&limit=100`),p("board_members",`select=id,user_id,role,is_owner&board_owner_id=eq.${i}`)]);return{profile:s[0]??null,credits:M[0]??null,subscription:$[0]??null,offers:A,members:q}},enabled:!!i,staleTime:3e4,refetchInterval:6e4});if(w)return e.jsx("div",{className:"flex items-center justify-center min-h-[50vh]",children:e.jsx(P,{size:40})});const r=a==null?void 0:a.profile;if(!r)return e.jsxs("div",{className:"p-6",children:[e.jsxs(f,{variant:"ghost",onClick:()=>c(-1),children:[e.jsx(y,{className:"h-4 w-4 mr-2"})," Voltar"]}),e.jsx("p",{className:"text-center text-muted-foreground mt-8",children:"Cliente não encontrado"})]});const t=a==null?void 0:a.credits,n=a==null?void 0:a.subscription,j=(a==null?void 0:a.offers)??[],N=(a==null?void 0:a.members)??[],k=j.filter(s=>!s.is_archived);return e.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[e.jsx(S,{title:"Visualização do Cliente",subtitle:r.full_name||r.email||"Cliente"}),e.jsx("div",{className:"flex-1 overflow-auto p-4 md:p-6",children:e.jsxs("div",{className:"max-w-4xl mx-auto space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(f,{variant:"ghost",size:"sm",onClick:()=>c(-1),children:[e.jsx(y,{className:"h-4 w-4 mr-1.5"})," Voltar"]}),e.jsx(f,{variant:"outline",size:"icon",onClick:()=>C(),disabled:v,title:"Atualizar dados",className:"h-8 w-8",children:e.jsx(I,{className:`h-4 w-4 ${v?"animate-spin":""}`})})]}),e.jsxs("div",{className:"flex items-center gap-4 p-4 border rounded-lg bg-card",children:[e.jsxs(D,{className:"h-16 w-16",children:[e.jsx(F,{src:r.avatar_url??void 0}),e.jsx(E,{className:"text-lg",children:O(r.full_name,r.email)})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h2",{className:"text-xl font-semibold truncate",children:r.full_name||"Sem nome"}),e.jsx("p",{className:"text-sm text-muted-foreground truncate",children:r.email}),e.jsx("p",{className:"text-xs text-muted-foreground font-mono mt-1",children:r.id})]}),e.jsxs("div",{className:"flex flex-col items-end gap-2",children:[n&&K(n.status),e.jsx(b,{variant:"secondary",children:(t==null?void 0:t.plan_name)||"Free"}),e.jsxs(f,{size:"sm",variant:"outline",onClick:async()=>{try{d.loading("Gerando acesso...",{id:"impersonate"});const s=await H("impersonate",r.id);d.dismiss("impersonate"),s!=null&&s.url?(window.open(s.url,"_blank"),d.success("Aba aberta com a conta do cliente")):d.error("Não foi possÃvel gerar o link de acesso")}catch(s){d.dismiss("impersonate"),d.error((s==null?void 0:s.message)||"Erro ao acessar conta")}},children:[e.jsx(U,{className:"h-3.5 w-3.5 mr-1.5"}
1)," Entrar como Cliente"]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs(o,{children:[e.jsx(x,{className:"pb-3",children:e.jsxs(u,{className:"text-sm flex items-center gap-2",children:[e.jsx(L,{className:"h-4 w-4"})," Perfil"]})}),e.jsxs(h,{className:"space-y-1",children:[e.jsx(l,{label:"Nome",value:r.full_name||"-"}),e.jsx(l,{label:"Email",value:r.email||"-"}),e.jsx(l,{label:"Idioma",value:((_=r.preferred_language)==null?void 0:_.toUpperCase())||"-"}),e.jsx(l,{label:"Timezone",value:r.timezone||"-"}),e.jsx(l,{label:"Cadastro",value:r.created_at?m(new Date(r.created_at),"dd/MM/yyyy HH:mm"):"-"})]})]}),e.jsxs(o,{children:[e.jsx(x,{className:"pb-3",children:e.jsxs(u,{className:"text-sm flex items-center gap-2",children:[e.jsx(g,{className:"h-4 w-4"})," Plano & Créditos"]})}),e.jsxs(h,{className:"space-y-1",children:[e.jsx(l,{label:"Plano",value:(t==null?void 0:t.plan_name)||"Free"}),e.jsx(l,{label:"Ofertas",value:t?`${t.offers_used} / ${t.offers_limit}`:"-"}),e.jsx(l,{label:"Créditos IA",value:t?`${t.tokens_used} / ${t.tokens_limit}`:"-"}),e.jsx(l,{label:"Ciclo inÃcio",value:t!=null&&t.cycle_start?m(new Date(t.cycle_start),"dd/MM/yyyy"):"-"}),e.jsx(l,{label:"Ciclo fim",value:t!=null&&t.cycle_end?m(new Date(t.cycle_end),"dd/MM/yyyy"):"-"})]})]}),n&&e.jsxs(o,{children:[e.jsx(x,{className:"pb-3",children:e.jsxs(u,{className:"text-sm flex items-center gap-2",children:[e.jsx(R,{className:"h-4 w-4"})," Assinatura"]})}),e.jsxs(h,{className:"space-y-1",children:[e.jsx(l,{label:"Status",value:n.status}),e.jsx(l,{label:"Plano",value:n.plan_name}),n.current_period_start&&e.jsx(l,{label:"InÃcio perÃodo",value:m(new Date(n.current_period_start),"dd/MM/yyyy")}),n.current_period_end&&e.jsx(l,{label:"Fim perÃodo",value:m(new Date(n.current_period_end),"dd/MM/yyyy")}),e.jsx(l,{label:"Cancela no fim?",value:n.cancel_at_period_end?"Sim":"Não"}),e.jsx(l,{label:"Stripe Customer",value:n.stripe_customer_id,mono:!0}),n.stripe_subscription_id&&e.jsx(l,{label:"Stripe Sub",value:n.stripe_subscription_id,mono:!0})]})]}),e.jsxs(o,{children:[e.jsx(x,{className:"pb-3",children:e.jsxs(u,{className:"text-sm flex items-center gap-2",children:[e.jsx(T,{className:"h-4 w-4"})," Membros (",N.length,")"]})}),e.jsx(h,{children:N.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Nenhum membro"}):e.jsx("div",{className:"space-y-1.5",children:N.map(s=>e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"font-mono text-xs truncate flex-1 mr-2",children:s.user_id}),e.jsx(b,{variant:"outline",className:"text-xs",children:s.is_owner?"Owner":s.role})]},s.id))})})]})]}),e.jsxs(o,{children:[e.jsx(x,{className:"pb-3",children:e.jsxs(u,{className:"text-sm flex items-center gap-2",children:[e.jsx(g,{className:"h-4 w-4"})," Ofertas (",k.length," ativas / ",j.length," total)"]})}),e.jsx(h,{children:j.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Nenhuma oferta"}):e.jsx("div",{className:"border rounded-lg overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b bg-muted/50",children:[e.jsx("th",{className:"text-left p-2.5 font-medium",children:"TÃtulo"}),e.jsx("th",{className:"text-left p-2.5 font-medium hidden sm:table-cell",children:"URL"}),e.jsx("th",{className:"text-left p-2.5 font-medium",children:"Status"}),e.jsx("th",{className:"text-left p-2.5 font-medium hidden md:table-cell",children:"Criada"})]})}),e.jsx("tbody",{children:j.map(s=>e.jsxs("tr",{className:"border-b last:border-0",children:[e.jsx("td",{className:"p-2.5 truncate max-w-[200px]",children:s.title}),e.jsx("td",{className:"p-2.5 hidden sm:table-cell",children:s.url?e.jsx("a",{href:s.url,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-primary hover:underline truncate block max-w-[200px]",children:new URL(s.url).hostname}):"-"}),e.jsx("td",{className:"p-2.5",children:e.jsx(b,{variant:"outline",className:"text-xs",children:s.is_archived?"Arquivada":s.status})}),e.jsx("td",{className:"p-2.5 hidden md:table-cell text-muted-foreground",children:s.created_at?m(new Date(s.created_at),"dd/MM/yy"):"-"})]},s.id))})]})})})]})]})})]})}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.