PageSourceSearch

https://www.dealtrail.ai/assets/AdminBusinessPage-CmlyHGJb.js

js dealtrail.ai collected 2026-09-24 14:29:42 UTC 47,118 bytes, 6 lines download raw bytes

1import{s as je,r as u,bm as pe,j as e,E as ge,G as fe,J as Ne,K as Q,g as N,N as be,c as V,bn as ve,an as ae,x as W,i as ye,ag as X,ad as we,F as Ce,L as J,C as D,o as k,m as $,n as U,U as Te,S as Se,I as Ae,_ as O,$ as z,a0 as H,a1 as G,y as le,ab as M,az as De,w as ke,bo as ie,a5 as Le,am as Ee}from"./index-Cm2t7kDb.js";import{P as Pe}from"./PageLayout-BVLvt_xh.js";import{T as Fe,a as $e,b as B,c as I}from"./tabs-Cgg6vDst.js";import{T as y,a as w,b as m,c as a,d as C,e as r}from"./table-BwKB9oyj.js";import{A}from"./AdminClient-DJwiQ1KV.js";import{S as F}from"./skeleton-BO8Y2G0C.js";import{C as ne,B as Ue,a as ce,X as de,Y as oe,b as xe,c as me}from"./chart-B0UY3-ZQ.js";import{U as q}from"./user-7WIW5dlK.js";import{C as Me}from"./circle-DFFywZX8.js";import{M as Z,A as Be}from"./AreaChart-P8bHGsby.js";import{B as Ie}from"./generateCategoricalChart-M9nhDa6S.js";import{S as he}from"./sparkles-Cz-PmMwU.js";import{A as Re}from"./activity-j42SnRDk.js";import{C as Oe}from"./chevron-up-ClFueLu7.js";import{T as Y}from"./trending-up-BZbjZ4tp.js";import{M as ue}from"./megaphone-CmY0r0gU.js";import{A as _}from"./Area-Dl53fZDz.js";import"./index-Dv-nw5np.js";import"./index-D1aO_FJ8.js";import"./isPlainObject-BZh_putz.js";import"./tiny-invariant-CopsF_GD.js";import"./index-Dh4i1-J3.js";import"./value-DqH_WevB.js";/**
2 * @license lucide-react v0.294.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const ze=je("Ghost",[["path",{d:"M9 10h.01",key:"qbtxuw"}],["path",{d:"M15 10h.01",key:"1qmjsl"}],["path",{d:"M12 2a8 8 0 0 0-8 8v12l3-3 2.5 2.5L12 19l2.5 2.5L17 19l3 3V10a8 8 0 0 0-8-8z",key:"uwwb07"}]]);function ee(s){if(!s)return"Never";const j=Date.now()-new Date(s).getTime(),h=Math.floor(j/6e4);if(h<1)return"Just now";if(h<60)return`${h}m ago`;const t=Math.floor(h/60);if(t<24)return`${t}h ago`;const i=Math.floor(t/24);return i<30?`${i}d ago`:`${Math.floor(i/30)}mo ago`}function P(s){return s?new Date(s).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"—"}function se(s){return s?new Date(s).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"}):"—"}function He(s){if(!s)return"";const j=Math.floor((Date.now()-new Date(s).getTime())/864e5);return j===0?"(today)":j===1?"(1 day ago)":`(${j} days ago)`}function K(s){switch(s){case"founding":return"default";case"free_trial":return"outline";case"expired":return"destructive";default:return"outline"}}function Ge(s){return s.replace(/_/g," ").replace(/\b\w/g,j=>j.toUpperCase())}const R=[{key:"profileCompletedAt",label:"Profile completed"},{key:"copiedEmailAt",label:"Copied DealTrail email"},{key:"smsConsentedAt",label:"SMS consent"},{key:"zipformLinkedAt",label:"zipForm linked"},{key:"firstDealAt",label:"First deal created"},{key:"firstEmailAt",label:"First email forwarded"}];function _e({agentId:s,open:j,onOpenChange:h}){var f;const[t,i]=u.useState(null),[o,v]=u.useState(null),[S,p]=u.useState([]),[x,T]=u.useState(!1),[n,c]=u.useState(null),{startImpersonation:b}=pe();u.useEffect(()=>{if(!s||!j){i(null),v(null),p([]),c(null);return}T(!0),c(null),Promise.all([A.getAgentDetail(s),A.getAgentUsage(s),A.getAgentNurturing(s)]).then(([l,g,E])=>{i(l),v(g),p(E.emails||[])}).catch(l=>{console.error("Failed to load agent detail:",l),c((l==null?void 0:l.message)||"Failed to load user details")}).finally(()=>T(!1))},[s,j]);const L=t?R.filter(l=>t.onboarding[l.key]!=null).length:0,d=t?[t.profile.firstName,t.profile.lastName].filter(Boolean).join(" ")||t.profile.email:"";return e.jsx(ge,{open:j,onOpenChange:h,children:e.jsxs(fe,{className:"sm:max-w-3xl max-h-[85vh] overflow-y-auto","aria-describedby":x||n?void 0:"user-detail-desc",children:[e.jsx(Ne,{children:e.jsx("div",{className:"flex items-center gap-3",children:!x&&!n&&t?e.jsxs(e.Fragment,{children:[t.profile.avatarUrl?e.jsx("img",{src:t.profile.avatarUrl,alt:"",className:"h-10 w-10 rounded-full object-cover"}):e.jsx("div",{className:"h-10 w-10 rounded-full bg-muted flex items-center justify-center",children:e.jsx(q,{className:"h-5 w-5 text-muted-foreground"})}),e.jsxs("div",{children:[e.jsxs(Q,{className:"flex items-center gap-2",children:[d,t.subscription&&e.jsx(N,{variant:K(t.subscription.planTier),children:t.subscription.planTier})]}),e.jsxs(be,{id:"user-detail-desc",children:[t.profile.email," · Signed up ",P(t.profile.createdAt)," ",He(t.profile.createdAt)]}),e.jsxs(V,{variant:"outline",size:"sm",className:"mt-1 gap-1.5",onClick:()=>{b(s,d),h(!1),window.location.href="/"},children:[e.jsx(ve,{className:"h-3.5 w-3.5"}),"Impersonate"]})]})]}):e.jsx("div",{children:e.jsx(Q,{children:x?"Loading user...":"User Detail"})})})}),x&&e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsx(F,{className:"h-8 w-64"}),e.jsx(F,{className:"h-4 w-48"}),e.jsx(F,{className:"h-48 w-full"}),e.jsx(F,{className:"h-32 w-full"})]}),n&&e.jsx("div",{className:"py-8 text-center text-destructive",children:n}),!x&&!n&&t&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"space-y-6 mt-2",children:[e.jsxs("section",{children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-1.5 mb-3",children:[e.jsx(ae,{className:"h-4 w-4"})," Signup & Subscription"]}),t.subscription?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Plan:"})," ",e.jsx(N,{variant:K(t.subscription.planTier),children:t.subscription.planTier})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Status:"}
6)," ",e.jsx("span",{className:t.subscription.status==="active"?"text-green-600 font-medium":"",children:t.subscription.status})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Subscribed:"})," ",P(t.subscription.createdAt)]}),t.subscription.freeTrialStartedAt&&e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Trial started:"})," ",P(t.subscription.freeTrialStartedAt)]}),t.subscription.trialCompletedAt&&e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Trial completed:"})," ",P(t.subscription.trialCompletedAt)]}),t.subscription.stripeCustomerId&&e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Stripe:"})," ",e.jsx("span",{className:"font-mono text-xs",children:t.subscription.stripeCustomerId})]}),t.subscription.currentPeriodEnd&&e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Period ends:"})," ",P(t.subscription.currentPeriodEnd)]})]}),t.subscriptionEvents.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-1.5",children:"Timeline"}),e.jsx("div",{className:"space-y-1 max-h-32 overflow-y-auto",children:t.subscriptionEvents.map((l,g)=>e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"text-muted-foreground whitespace-nowrap",children:P(l.createdAt)}),e.jsx("span",{className:"font-medium",children:Ge(l.eventType)}),l.newPlanTier&&e.jsx(N,{variant:"outline",className:"text-[10px] px-1 py-0",children:l.newPlanTier})]},g))})]})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No subscription record"})]}),e.jsxs("section",{children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-1.5 mb-3",children:[e.jsx(W,{className:"h-4 w-4"})," Onboarding Progress (",L,"/",R.length,")"]}),e.jsx("div",{className:"h-2 w-full rounded-full bg-muted overflow-hidden mb-3",children:e.jsx("div",{className:"h-full rounded-full bg-primary transition-all",style:{width:`${L/R.length*100}%`}})}),e.jsx("div",{className:"space-y-1.5",children:R.map(l=>{const g=t.onboarding[l.key];return e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[g?e.jsx(W,{className:"h-4 w-4 text-green-600 shrink-0"}):e.jsx(Me,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx("span",{className:g?"":"text-muted-foreground",children:l.label}),g&&e.jsx("span",{className:"text-xs text-muted-foreground ml-auto",children:se(g)})]},l.key)})})]}),S.length>0&&e.jsxs("section",{children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-1.5 mb-3",children:[e.jsx(ye,{className:"h-4 w-4"})," Nurturing Emails (",S.length,")"]}),e.jsx("div",{className:"rounded-md border",children:e.jsxs(y,{children:[e.jsx(w,{children:e.jsxs(m,{children:[e.jsx(a,{children:"Template"}),e.jsx(a,{children:"Sequence"}),e.jsx(a,{children:"Status"}),e.jsx(a,{children:"Scheduled"}),e.jsx(a,{className:"text-center",children:"Opened"}),e.jsx(a,{className:"text-center",children:"Clicked"})]})}),e.jsx(C,{children:S.map(l=>e.jsxs(m,{children:[e.jsx(r,{className:"font-mono text-xs",children:l.templateKey}),e.jsx(r,{children:e.jsx(N,{variant:"outline",className:"text-[10px]",children:l.sequenceId})}),e.jsx(r,{children:e.jsx(N,{className:l.status==="sent"?"bg-green-100 text-green-800 border-green-200 hover:bg-green-100":l.status==="cancelled"?"bg-gray-100 text-gray-600 border-gray-200 hover:bg-gray-100":"bg-yellow-100 text-yellow-800 border-yellow-200 hover:bg-yellow-100",children:l.status})}),e.jsx(r,{className:"text-xs text-muted-foreground whitespace-nowrap",children:se(l.scheduledAt)}),e.jsx(r,{className:"text-center",children:l.openedAt?e.jsx(X,{className:"h-4 w-4 text-green-600 inline-block"}):e.jsx(Z,{className:"h-4 w-4 text-gray-300 inline-block"})}),e.jsx(r,{className:"text-center",children:l.clickedAt?e.jsx(X,{className:"h-4 w-4 text-green-600 inline-block"}):e.jsx(Z,{className:"h-4 w-4 text-gray-300 inline-block"})})]},l.id))})]})})]}),e.jsxs("section",{children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-1.5 mb-3",children:[e.jsx(q,{className:"h-4 w-4"})," Profile Details"]}
6),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Name:"})," ",d]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Email:"})," ",t.profile.email]}),t.profile.userEmail&&t.profile.userEmail!==t.profile.email&&e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Personal:"})," ",t.profile.userEmail]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Phone:"})," ",t.profile.phone||"—"]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Brokerage:"})," ",t.profile.brokerageName||"—"]}),t.profile.brokerageDreNumber&&e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Brokerage DRE:"})," ",t.profile.brokerageDreNumber]}),t.profile.specializations.length>0&&e.jsxs("div",{className:"col-span-2",children:[e.jsx("span",{className:"text-muted-foreground",children:"Specializations:"})," ",t.profile.specializations.map((l,g)=>e.jsx(N,{variant:"outline",className:"mr-1 mb-1",children:l},g))]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"SMS consent:"})," ",t.profile.smsConsent?e.jsx("span",{className:"text-green-600",children:"Yes"}):e.jsx("span",{className:"text-muted-foreground",children:"No"})]})]}),t.licenses.length>0&&e.jsxs("div",{className:"mt-3",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-1.5",children:"Licenses"}),e.jsx("div",{className:"rounded-md border",children:e.jsxs(y,{children:[e.jsx(w,{children:e.jsxs(m,{children:[e.jsx(a,{children:"State"}),e.jsx(a,{children:"License #"}),e.jsx(a,{children:"Expiration"}),e.jsx(a,{children:"Primary"})]})}),e.jsx(C,{children:t.licenses.map(l=>e.jsxs(m,{children:[e.jsx(r,{className:"font-medium",children:l.stateCode}),e.jsx(r,{className:"font-mono text-xs",children:l.licenseNumber}),e.jsx(r,{className:"text-sm",children:P(l.expiration)}),e.jsx(r,{children:l.isPrimary?e.jsx(N,{variant:"default",children:"Primary"}):"—"})]},l.id))})]})})]})]}),e.jsxs("section",{children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-1.5 mb-3",children:[e.jsx(we,{className:"h-4 w-4"})," Engagement Summary"]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3 mb-3",children:[e.jsxs("div",{className:"rounded-lg border p-2.5",children:[e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Total Events"}),e.jsx("p",{className:"text-lg font-semibold",children:t.engagement.totalEvents})]}),e.jsxs("div",{className:"rounded-lg border p-2.5",children:[e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"First Active"}),e.jsx("p",{className:"text-sm font-medium",children:ee(t.engagement.firstActiveAt)})]}),e.jsxs("div",{className:"rounded-lg border p-2.5",children:[e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Last Active"}),e.jsx("p",{className:"text-sm font-medium",children:ee(t.engagement.lastActiveAt)})]}),e.jsxs("div",{className:"rounded-lg border p-2.5",children:[e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Deals / Emails / Docs"}),e.jsxs("p",{className:"text-sm font-medium",children:[t.counts.deals," / ",t.counts.emails," / ",t.counts.documents]})]})]}),t.engagement.eventsByCategory.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-1.5",children:"Activity by category"}),e.jsx("div",{className:"space-y-1",children:t.engagement.eventsByCategory.map(l=>{var E;const g=((E=t.engagement.eventsByCategory[0])==null?void 0:E.count)||1;return e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"w-28 truncate text-muted-foreground",children:l.category}),e.jsx("div",{className:"flex-1 h-2 rounded-full bg-muted overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-primary",style:{width:`${l.count/g*100}%`}})}),e.jsx("span",{className:"text-xs font-mono w-10 text-right",children:l.count})]},l.category)})})]})]}),o&&e.jsxs("section",{children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-1.5 mb-3",children:[e.jsx(Ce,{className:"h-4 w-4"})," Usage & Costs"]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3 mb-3",children:[e.jsxs("div",{className:"rounded-lg border p-2.5",children:[e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Cost this month vs cap"}),e.jsxs("p",{className:"text-lg font-semibold",children:["$",o.costCap.currentCost.toFixed(2),o.costCap.limit>0&&e.jsxs("span",{className:"text-muted-foreground text-sm font-normal",children:[" / $",o.costCap.limit.toFixed(2)]})]}),o.costCap.limit>0&&e.jsx("div",{className:"h-1.5 rounded-full bg-muted mt-1 overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-primary",style:{width:`${Math.min(100,o.costCap.currentCost/o.costCap.limit*100)}%`}})})]}),e.jsxs("div",{className:"rounded-lg border p-2.5",children:[e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Budget Extension"}),e.jsx("p",{className:"text-lg font-semibold",children:(o.costCap.extensionUsd??0)>0?`$${(o.costCap.extensionUsd??0).toFixed(2)}`:((f=o.credits)==null?void 0:f.balance)>0?`${o.credits.balance} credits`:"$0.00"})]}),e.jsxs("div",{className:"rounded-lg border p-2.5",children:[e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Plan"}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[e.jsx(N,{variant:K(o.subscription.planTier),children:o.subscription.planTier}),e.jsx("span",{className:"text-xs text-muted-foreground",children:o.subscription.status})]})]})]}),Object.keys(o.featureUsage).length>0&&e.jsxs("div",{className:"mb-3",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-1.5",children:"Feature usage"}),e.jsx("div",{className:"rounded-md border",children:e.jsxs(y,{children:[e.jsx(w,{children:e.jsxs(m,{children:[e.jsx(a,{children:"Feature"}),e.jsx(a,{className:"text-right",children:"Current"}),e.jsx(a,{className:"text-right",children:"Limit"}),e.jsx(a,{className:"w-[100px]",children:"Usage"})]})}),e.jsx(C,{children:Object.entries(o.featureUsage).map(([l,g])=>{const E=g.limit?Math.min(100,g.current/g.limit*100):0;return e.jsxs(m,{children:[e.jsx(r,{className:"font-medium text-xs",children:l}),e.jsx(r,{className:"text-right text-xs",children:g.current}),e.jsx(r,{className:"text-right text-xs",children:g.limit??"---"}),e.jsx(r,{children:g.limit?e.jsx("div",{className:"h-1.5 rounded-full bg-muted overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full ${E>=90?"bg-destructive":"bg-primary"}`,style:{width:`${E}%`}})}):e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"---"})})]},l)})})]})})]}),o.costByDay.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-1.5",children:"Daily cost (last 30 days)"}),e.jsx(ne,{config:{cost:{label:"Cost",color:"hsl(var(--primary))"}},className:"w-full h-[150px]",children:e.jsxs(Ue,{accessibilityLayer:!0,data:o.costByDay.map(l=>({date:new Date(l.date).toLocaleDateString("en-US",{month:"short",day:"numeric"}),cost:l.totalCost})),barSize:6,margin:{top:4,left:4,right:0,bottom:0},children:[e.jsx(ce,{vertical:!1}
6),e.jsx(de,{dataKey:"date",tickLine:!1,tickMargin:6,axisLine:!1,fontSize:9}),e.jsx(oe,{width:40,tickSize:0,tickLine:!1,axisLine:!1,tickFormatter:l=>`$${l.toFixed(2)}`,fontSize:9}),e.jsx(xe,{cursor:!1,content:e.jsx(me,{formatter:l=>`$${Number(l).toFixed(4)}`})}),e.jsx(Ie,{dataKey:"cost",fill:"hsl(var(--primary))",radius:[2,2,0,0]})]})})]})]})]})})]})})}const te=6,Ke=30;function Ve(s){switch(s){case"founding":return"default";case"free_trial":return"outline";case"expired":return"destructive";default:return"outline"}}function We(s){if(!s)return"Never";const j=Date.now()-new Date(s).getTime(),h=Math.floor(j/6e4);if(h<1)return"Just now";if(h<60)return`${h}m ago`;const t=Math.floor(h/60);if(t<24)return`${t}h ago`;const i=Math.floor(t/24);return i<30?`${i}d ago`:`${Math.floor(i/30)}mo ago`}function qe(s){return s?new Date(s).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"—"}function Ye(s){if(!s)return null;const j=(Date.now()-new Date(s).getTime())/864e5;return Math.max(0,Math.ceil(Ke-j))}function re(s){return s<=3?"text-red-600":s<=7?"text-amber-600":"text-muted-foreground"}function Je(){const[s,j]=u.useState([]),[h,t]=u.useState(!0),[i,o]=u.useState(""),[v,S]=u.useState(null),[p,x]=u.useState(!1);u.useEffect(()=>{(async()=>{t(!0);try{const f=await A.getAgents();j(f.agents||[])}catch(f){console.warn("Failed to load agents:",f)}finally{t(!1)}})()},[]);const T=d=>{S(d),x(!0)},n=u.useMemo(()=>{if(!i.trim())return s;const d=i.toLowerCase();return s.filter(f=>f.name&&f.name.toLowerCase().includes(d)||f.email.toLowerCase().includes(d)||f.planTier&&f.planTier.toLowerCase().includes(d))},[s,i]),c=s.filter(d=>d.planTier==="free_trial").length,b=s.filter(d=>d.planTier==="founding").length,L=s.filter(d=>d.planTier==="expired").length;return h?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(J,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsx(D,{children:e.jsxs(k,{className:"pt-4 pb-3 px-4",children:[e.jsx("div",{className:"text-2xl font-bold",children:s.length}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Users"})]})}),e.jsx(D,{children:e.jsxs(k,{className:"pt-4 pb-3 px-4",children:[e.jsx("div",{className:"text-2xl font-bold",children:c}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Active Trials"})]})}),e.jsx(D,{children:e.jsxs(k,{className:"pt-4 pb-3 px-4",children:[e.jsx("div",{className:"text-2xl font-bold text-green-600",children:b}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Paid Members"})]})}),e.jsx(D,{children:e.jsxs(k,{className:"pt-4 pb-3 px-4",children:[e.jsx("div",{className:"text-2xl font-bold text-red-600",children:L}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Expired"})]})})]}),e.jsxs(D,{children:[e.jsx($,{children:e.jsxs("div",{className:"flex items-center justify-between gap-4 flex-wrap",children:[e.jsxs(U,{className:"flex items-center gap-2",children:[e.jsx(Te,{className:"h-5 w-5"}),"Users (",s.length,")"]}),e.jsxs("div",{className:"relative w-full max-w-xs",children:[e.jsx(Se,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(Ae,{placeholder:"Search by name or email...",value:i,onChange:d=>o(d.target.value),className:"pl-8"})]})]})}),e.jsx(k,{children:e.jsx("div",{className:"rounded-md border",children:e.jsxs(y,{children:[e.jsx(w,{children:e.jsxs(m,{children:[e.jsx(a,{children:"Name"}),e.jsx(a,{children:"Email"}),e.jsx(a,{children:"Plan"}),e.jsx(a,{children:"Trial"}),e.jsx(a,{children:"Onboarding"}),e.jsx(a,{children:"Last Active"}),e.jsx(a,{className:"text-right",children:"Deals"}),e.jsx(a,{className:"text-right",children:"Credits"})]})}),e.jsx(C,{children:n.length===0?e.jsx(m,{children:e.jsx(r,{colSpan:8,className:"text-center text-muted-foreground py-8",children:i?"No users match your search":"No users found"})}):n.map(d=>{var g;const f=Ye(d.freeTrialStartedAt),l=d.planTier==="free_trial";return e.jsxs(m,{className:"cursor-pointer hover:bg-muted/50",onClick:()=>T(d.agentId),children:[e.jsx(r,{className:"font-medium",children:((g=d.name)==null?void 0:g.trim())||"—"}),e.jsx(r,{className:"text-sm text-muted-foreground max-w-[200px] truncate",children:d.email}),e.jsx(r,{children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(N,{variant:Ve(d.planTier),children:d.planTier==="founding"?"member":d.planTier||"none"}),d.overrideCount>0&&e.jsx(O,{children:e.jsxs(z,{children:[e.jsx(H,{asChild:!0,children:e.jsx(he,{className:"h-3.5 w-3.5 text-amber-500"})}),e.jsx(G,{children:e.jsxs("p",{children:[d.overrideCount," custom limit override",d.overrideCount>1?"s":""]})})]})}),d.hasStripeCustomer&&e.jsx(O,{children:e.jsxs(z,{children:[e.jsx(H,{asChild:!0,children:e.jsx(ae,{className:"h-3.5 w-3.5 text-blue-500"})}),e.jsx(G,{children:e.jsx("p",{children:"Stripe customer created"})})]})})]})}),e.jsx(r,{className:"whitespace-nowrap",children:l&&f!==null?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(le,{className:`h-3.5 w-3.5 ${re(f)}`}),e.jsxs("span",{className:`text-sm font-medium ${re(f)}`,children:[f,"d left"]}),d.trialCompletedAt&&e.jsx(O,{children:e.jsxs(z,{children:[e.jsx(H,{asChild:!0,children:e.jsx(W,{className:"h-3.5 w-3.5 text-green-500"})}),e.jsx(G,{children:e.jsxs("p",{children:["Quickstart completed ",qe(d.trialCompletedAt)]})})]})})]}):d.planTier==="founding"?e.jsx("span",{className:"text-xs text-green-600",children:"Paid"}):d.planTier==="expired"?e.jsx("span",{className:"text-xs text-red-600",children:"Expired"}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"—"})}),e.jsx(r,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-1.5 w-16 rounded-full bg-muted overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-primary transition-all",style:{width:`${d.onboardingSteps/te*100}%`}})}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[d.onboardingSteps,"/",te]})]})}),e.jsx(r,{className:"text-sm text-muted-foreground whitespace-nowrap",children:We(d.lastActiveAt)}),e.jsx(r,{className:"text-right text-sm",children:d.dealCount}),e.jsx(r,{className:"text-right text-sm font-mono",children:Math.round(d.costThisMonth*100).toLocaleStr
6ing()})]},d.agentId)})})]})})})]}),e.jsx(_e,{agentId:v,open:p,onOpenChange:x})]})}const Qe=s=>{switch(s){case"healthy":return e.jsx(N,{className:"bg-green-100 text-green-800 hover:bg-green-100",children:"healthy"});case"ghost":return e.jsx(N,{className:"bg-red-100 text-red-800 hover:bg-red-100",children:"ghost"});case"warning":return e.jsx(N,{className:"bg-yellow-100 text-yellow-800 hover:bg-yellow-100",children:"warning"});case"expiring":return e.jsx(N,{className:"bg-orange-100 text-orange-800 hover:bg-orange-100",children:"expiring"});default:return e.jsx(N,{variant:"secondary",children:s})}};function Xe({data:s,onRefresh:j}){const{summary:h,config:t,trials:i,reaperLog:o}=s,[v,S]=u.useState(!1),[p,x]=u.useState(null),T=async c=>{x(c);try{await A.extendTrial(c),j()}catch(b){console.error("Failed to extend trial:",b)}finally{x(null)}},n=async c=>{if(confirm("Expire this trial? The slot will be reclaimed.")){x(c);try{await A.expireTrial(c),j()}catch(b){console.error("Failed to expire trial:",b)}finally{x(null)}}};return e.jsxs(D,{children:[e.jsxs($,{children:[e.jsxs(U,{className:"flex items-center gap-2",children:[e.jsx(Re,{className:"h-5 w-5"}),"Trial Health"]}),e.jsx(M,{children:"Active trial monitoring and reaper status"})]}),e.jsxs(k,{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-4",children:[e.jsxs("div",{className:"rounded-lg border p-3 border-green-200 bg-green-50",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Active Trials"}),e.jsx("p",{className:"text-2xl font-bold mt-1 text-green-700",children:h.activeTrials})]}),e.jsxs("div",{className:"rounded-lg border p-3 border-red-200 bg-red-50",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ze,{className:"h-3 w-3 text-red-500"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Ghosts"})]}),e.jsx("p",{className:"text-2xl font-bold mt-1 text-red-700",children:h.ghosts})]}),e.jsxs("div",{className:"rounded-lg border p-3 border-yellow-200 bg-yellow-50",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(De,{className:"h-3 w-3 text-yellow-600"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Warning Zone"})]}),e.jsx("p",{className:"text-2xl font-bold mt-1 text-yellow-700",children:h.warningZone})]}),e.jsxs("div",{className:"rounded-lg border p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Reaped This Week"}),e.jsx("p",{className:"text-2xl font-bold mt-1",children:h.reapedThisWeek}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[h.backfilledThisWeek," backfilled"]})]})]}),e.jsx("div",{className:"rounded-md bg-gray-50 border px-4 py-3",children:e.jsxs("p",{className:"text-xs text-muted-foreground",children:[e.jsx(le,{className:"h-3 w-3 inline-block mr-1"}),"Expire after ",e.jsxs("strong",{children:[t.inactivityExpireDays," days"]})," inactive, warn at ",e.jsx("strong",{children:t.inactivityWarningDays})," & ",e.jsxs("strong",{children:[t.inactivityFinalDays," days"]}),t.hardCapDays>0&&e.jsxs(e.Fragment,{children:[" | Hard cap: ",e.jsxs("strong",{children:[t.hardCapDays," days"]})," (warn ",t.hardCapWarningDays,"d before)"]})]})}),i.length>0&&e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-medium mb-2",children:["Active trials (",i.length,")"]}),e.jsx("div",{className:"rounded-md border max-h-96 overflow-auto",children:e.jsxs(y,{children:[e.jsx(w,{children:e.jsxs(m,{children:[e.jsx(a,{children:"Name"}),e.jsx(a,{children:"Email"}),e.jsx(a,{children:"Started"}),e.jsx(a,{children:"Last Active"}),e.jsx(a,{className:"text-right",children:"Days Inactive"}),e.jsx(a,{children:"Status"}),e.jsx(a,{children:"Expires In"}),e.jsx(a,{children:"Actions"})]})}),e.jsx(C,{children:i.map(c=>e.jsxs(m,{children:[e.jsxs(r,{className:"font-medium text-sm",children:[c.name||"(no name)",c.hasOverrides&&e.jsx(he,{className:"h-3 w-3 inline-block ml-1 text-primary"}),c.trialCompleted&&e.jsx("span",{className:"text-xs text-green-600 ml-1",children:"(completed)"})]}),e.jsx(r,{className:"text-xs truncate max-w-[160px]",title:c.email,children:c.email}),e.jsx(r,{className:"text-xs text-muted-foreground whitespace-nowrap",children:new Date(c.trialStarted).toLocaleDateString(void 0,{month:"short",day:"numeric"})}),e.jsx(r,{className:"text-xs text-muted-foreground whitespace-nowrap",children:c.lastActive?new Date(c.lastActive).toLocaleDateString(void 0,{month:"short",day:"numeric"}):"never"}),e.jsx(r,{className:"text-right",children:c.daysInactive}),e.jsx(r,{children:Qe(c.status)}),e.jsx(r,{className:"text-xs text-muted-foreground",children:c.expiresIn}),e.jsx(r,{children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx(V,{size:"sm",variant:"outline",className:"h-7 text-xs",disabled:p===c.agentId,onClick:()=>T(c.agentId),children:"Extend"}),e.jsx(V,{size:"sm",variant:"outline",className:"h-7 text-xs text-red-600 hover:text-red-700",disabled:p===c.agentId,onClick:()=>n(c.agentId),children:"Expire"})]})})]},c.agentId))})]})})]}),o.length>0&&e.jsxs("div",{children:[e.jsxs("button",{className:"flex items-center gap-1 text-sm font-medium text-muted-foreground hover:text-foreground",onClick:()=>S(!v),children:[v?e.jsx(Oe,{className:"h-4 w-4"}):e.jsx(ke,{className:"h-4 w-4"}),"Reaper log (",o.length,")"]}),v&&e.jsx("div",{className:"rounded-md border max-h-64 overflow-auto mt-2",children:e.jsxs(y,{children:[e.jsx(w,{children:e.jsxs(m,{children:[e.jsx(a,{children:"Action"}),e.jsx(a,{children:"Email"}),e.jsx(a,{children:"Reason"}),e.jsx(a,{children:"Time"})]})}),e.jsx(C,{children:o.map((c,b)=>e.jsxs(m,{children:[e.jsx(r,{children:e.jsx(N,{variant:"secondary",children:c.action})}),e.jsx(r,{className:"text-xs truncate max-w-[160px]",title:c.email,children:c.email}),e.jsx(r,{className:"text-xs text-muted-foreground",children:c.reason||"-"}),e.jsx(r,{className:"text-xs text-muted-foreground whitespace-nowrap",children:new Date(c.timestamp).toLocaleDateString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})})]},b))})]})})]})]})]})}function Ze(){const[s,j]=u.useState(null),[h,t]=u.useState(null),[i,o]=u.useState(null),[v,S]=u.useState(null),[p,x]=u.useState(!0),T=u.useCallback(async()=>{try{const n=await A.getTrialHealth();S(n)}catch(n){console.warn("Failed to load trial health:",n)}},[]);return u.useEffect(()=>{(async()=>{x(!0);try{const[c,b,L]=await Promise.all([A.getSubscriptionFunnel(),A.getSubscriptionLimits(),A.getEstimatedMaxCost()]);j(c),t(b),o(L.tiers||null)}catch(c){console.warn("Failed to load subscription data:",c)}finally{x(!1)}})(),T()},[T]),p?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(J,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-6",children:[v&&e.jsx(Xe,{data:v,onRefresh:T}),s&&e.jsxs(D,{children:[e.jsxs($,{children:[e.jsxs(U,{className:"flex items-center gap-2",children:[e.jsx(Y,{className:"h-5 w-5"}),"Subscription Funnel"]}),e.jsx(M,{children:"Trial-to-paid conversion analysis"})]}),e.jsxs(k,{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-4",children:[e.jsxs("div",{className:"rounded-lg border p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Trials"}),e.jsx("p",{className:"text-2xl font-bold mt-1",children:s.cohorts.totalTrials})]}),e.jsxs("div",{className:"rounded-lg border p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Conversions"}),e.jsx("p",{className:"text-2xl font-bold mt-1",children:s.cohorts.trialUpgraded})]}),e.jsxs("div",{className:"rounded-lg border p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Conversion Rate"}),e.jsxs("p",{className:"text-2xl font-bold mt-1",children:[s.conversionRate,"%"]})]}),e.jsxs("div",{className:"rounded-lg border p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Avg Days to Upgrade"}),e.jsx("p",{className:"text-2xl font-bold mt-1",children:s.avgDaysToConversion})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium mb-2",children:"Cohort breakdown"}),e.jsx("div",{className:"rounded-md border",children:e.jsxs(y,{children:[e.jsx(w,{children:e.jsxs(m,{children:[e.jsx(a,{children:"Cohort"}),e.jsx(a,{className:"text-right",children:"Count"}),e.jsx(a,{className:"text-right",children:"% of Trials"})]})}),e.jsx(C,{children:[{label:"Trial → Upgraded",count:s.cohorts.trialUpgraded},{label:"Trial Only (active)",count:s.cohorts.trialOnly},{label:"Direct Buy",count:s.cohorts.directBuy},{label:"Active Trials",count:s.cohorts.activeTrials},{label:"Expired",count:s.cohorts.expiredTrials}].map(n=>e.jsxs(m,{children:[e.jsx(r,{className:"font-medium",children:n.label}),e.jsx(r,{className:"text-right",children:n.count}),e.jsx(r,{className:"text-right",children:s.cohorts.totalTrials>0?(n.count/s.cohorts.totalTrials*100).toFixed(1)+"%":"—"})]},n.label))})]})})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Trial pool: ",s.trialPool.available," available of ",s.trialPool.maxPool," total (",s.trialPool.totalIssued," issued, ",s.trialPool.conversions," conversions)"]}),s.recentEvents.length>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium mb-2",children:"Recent events"}),e.jsx("div",{className:"rounded-md border max-h-64 overflow-auto",children:e.jsxs(y,{children:[e.jsx(w,{children:e.jsxs(m,{children:[e.jsx(a,{children:"Event"}),e.jsx(a,{children:"Agent"}),e.jsx(a,{children:"Transition"}),e.jsx(a,{children:"Source"}),e.jsx(a,{children:"Time"})]})}),e.jsx(C,{children:s.recentEvents.map(n=>e.jsxs(m,{children:[e.jsx(r,{children:e.jsx(N,{variant:"secondary",children:n.eventType})}),e.jsx(r,{className:"text-xs truncate max-w-[140px]",title:n.agentEmail,children:n.agentEmail}),e.jsxs(r,{className:"text-xs",children:[n.oldPlanTier&&n.newPlanTier?`${n.oldPlanTier} → ${n.newPlanTier}`:n.newPlanTier||"—",n.oldStatus!==n.newStatus&&n.oldStatus&&n.newStatus&&e.jsxs("span",{className:"text-muted-foreground ml-1",children:["(",n.oldStatus," → ",n.newStatus,")"]})]}),e.jsx(r,{className:"text-xs text-muted-foreground",children:n.source||"—"}),e.jsx(r,{className:"text-xs text-muted-foreground whitespace-nowrap",children:new Date(n.createdAt).toLocaleDateString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})})]},n.id))})]})})]})]})]}),h&&e.jsxs(D,{children:[e.jsxs($,{children:[e.jsx(U,{children:"Subscription config"}),e.jsx(M,{children:"Cost cap is the sole usage gate. Per-feature limits are retained for analytics only."})]}),e.jsxs(k,{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium mb-2",children:"Monthly cost cap per tier (enforced)"}),e.jsx("div",{className:"rounded-md border overflow-x-auto",children:e.jsxs(y,{children:[e.jsx(w,{children:e.jsxs(m,{children:[e.jsx(a,{children:"Tier"}),e.jsx(a,{className:"text-right",children:"Cost Cap"}),e.jsx(a,{className:"text-right",children:"Product Limits"})]})}),e.jsxs(C,{children:[e.jsxs(m,{children:[e.jsx(r,{className:"font-medium",children:"Free Trial"}),e.jsx(r,{className:"text-right",children:"$1.00"}),e.jsx(r,{className:"text-right text-xs text-muted-foreground",children:"Cost cap only"})]}),e.jsxs(m,{children:[e.jsx(r,{className:"font-medium",children:"Founding ($39/mo)"}),e.jsx(r,{className:"text-right",children:"$25.00"}),e.jsx(r,{className:"text-right text-xs text-muted-foreground",children:"No per-feature limits"})]}),e.jsxs(m,{children:[e.jsx(r,{className:"font-medium",children:"Starter ($35/mo)"}),e.jsx(r,{className:"text-right",children:"$5.00"}),e.jsx(r,{className:"text-right text-xs text-muted-foreground",children:"Cost cap only"})]})]})]})})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium mb-1",children:"Per-feature analytics reference (not enforced)"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"These values are no longer enforced. Usage is tracked for analytics only."}),e.jsx("div",{className:"rounded-md border overflow-x-auto",children:e.jsxs(y,{children:[e.jsx(w,{children:e.jsxs(m,{children:[e.jsx(a,{children:"Feature"}),e.jsx(a,{className:"text-right",children:"Free Trial"}),e.jsx(a,{className:"text-right",children:"Founding"})]})}),e.jsx(C,{children:[["deals","Deals"],["docsPerDeal","Docs per deal"],["pagesPerDoc","Pages per document"],["comps","Comps"],["emails","Emails"],["summaries","Summaries"],["documentAiEnhances","Document AI enhances"],["ragQueries","RAG queries"],["storageGb","Storage (GB)"]].map(([n,c])=>{var f,l;const b=h.limits,L=((f=b.free_trial)==null?void 0:f[n])??"—",d=((l=b.founding)==null?void 0:l[n])??"—";return e.jsxs(m,{children:[e.jsx(r,{className:"font-medium",children:c}),e.jsx(r,{className:"text-right",children:L}),e.jsx(r,{className:"text-right",children:d})]},n)})})]})})]}),i&&e.jsxs(e.Fragment,{children:[e.jsx("h4",{className:"text-sm font-medium",children:"Estimated cost at max usage (this month)"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"If each tier uses all allowed deals, docs, c
6omps, emails, summaries, Doc AI enhances, and RAG queries."}),e.jsx("div",{className:"rounded-md border overflow-x-auto",children:e.jsxs(y,{children:[e.jsx(w,{children:e.jsxs(m,{children:[e.jsx(a,{children:"Tier"}),e.jsx(a,{className:"text-right",children:"Est. cost at max"})]})}),e.jsx(C,{children:["free_trial","founding"].map(n=>{const c=i[n];if(!c)return null;const b=c.estimatedCostUsd;return e.jsxs(m,{children:[e.jsx(r,{className:"font-medium capitalize",children:n}),e.jsxs(r,{className:"text-right",children:["$",b.toFixed(2)]})]},n)})})]})})]})]})]})]})}function es(){const[s,j]=u.useState(null),[h,t]=u.useState(!0);return u.useEffect(()=>{(async()=>{t(!0);try{const o=await A.getUsageBreakdown(500);j(o)}catch(o){console.warn("Failed to load usage breakdown:",o)}finally{t(!1)}})()},[]),h?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(J,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):s?e.jsx("div",{className:"space-y-6",children:e.jsxs(D,{children:[e.jsxs($,{children:[e.jsxs(U,{className:"flex items-center gap-2",children:[e.jsx(ie,{className:"h-5 w-5"}),"API usage by service"]}),e.jsxs(M,{children:["Service, model, purpose, API key name, and usage this month (",s.month,")"]})]}),e.jsxs(k,{className:"space-y-4",children:[e.jsx("div",{className:"rounded-md border",children:e.jsxs(y,{children:[e.jsx(w,{children:e.jsxs(m,{children:[e.jsx(a,{children:"Service"}),e.jsx(a,{children:"Model"}),e.jsx(a,{children:"Purpose"}),e.jsx(a,{children:"API key name"}),e.jsx(a,{className:"text-right",children:"Calls"}),e.jsx(a,{className:"text-right",children:"Cost"})]})}),e.jsx(C,{children:s.serviceSummary.map((i,o)=>e.jsxs(m,{children:[e.jsx(r,{className:"font-medium",children:i.service}),e.jsx(r,{children:i.model}),e.jsx(r,{className:"max-w-[220px] truncate",title:i.purpose,children:i.purpose}),e.jsx(r,{className:"text-muted-foreground text-xs",children:i.apiKeyHints.length>0?i.apiKeyHints.join(", "):"—"}),e.jsx(r,{className:"text-right",children:i.totalCalls}),e.jsxs(r,{className:"text-right",children:["$",i.totalCostUsd.toFixed(4)]})]},o))})]})}),s.detail.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("h4",{className:"text-sm font-medium",children:"Usage by agent & doc (this month)"}),e.jsx("div",{className:"rounded-md border max-h-64 overflow-auto",children:e.jsxs(y,{children:[e.jsx(w,{children:e.jsxs(m,{children:[e.jsx(a,{children:"Agent email"}),e.jsx(a,{children:"Service"}),e.jsx(a,{children:"Doc"}),e.jsx(a,{children:"API key"}),e.jsx(a,{className:"text-right",children:"Cost"}),e.jsx(a,{children:"Date"})]})}),e.jsx(C,{children:s.detail.slice(0,100).map(i=>e.jsxs(m,{children:[e.jsx(r,{className:"text-xs truncate max-w-[140px]",title:i.agentEmail,children:i.agentEmail}),e.jsx(r,{children:i.service}),e.jsx(r,{className:"text-xs truncate max-w-[120px]",title:i.docFilename||i.documentId||"—",children:i.docFilename||i.documentId||"—"}),e.jsx(r,{className:"text-xs text-muted-foreground",children:i.apiKeyHint||"—"}),e.jsxs(r,{className:"text-right text-xs",children:["$",i.totalCostUsd.toFixed(4)]}),e.jsx(r,{className:"text-xs text-muted-foreground",children:i.createdAt?new Date(i.createdAt).toLocaleDateString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}):"—"})]},i.id))})]})}),s.detail.length>100&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Showing first 100 of ",s.detail.length," rows."]})]})]})]})}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No usage data available."})}const ss={visitors:{label:"Visitors",color:"hsl(var(--primary))"},clicks:{label:"CTA Clicks",color:"hsl(210 100% 50%)"},signups:{label:"Signups",color:"hsl(142 76% 36%)"}};function ts(){const[s,j]=u.useState(null),[h,t]=u.useState(!0),[i,o]=u.useState(30);if(u.useEffect(()=>{t(!0),A.getLandingFunnel(i).then(j).catch(x=>console.error("Failed to load landing funnel:",x)).finally(()=>t(!1))},[i]),h)return e.jsxs("div",{className:"space-y-6",children:[e.jsx(F,{className:"h-8 w-48"}),e.jsx(F,{className:"h-[300px]"})]});if(!s)return e.jsx(D,{children:e.jsx(k,{className:"py-8 text-center text-muted-foreground",children:"No landing funnel data yet. Events will appear once visitors hit the landing page."})});const{timeline:v,sources:S,totals:p}=s;return e.jsx("div",{className:"space-y-6",children:e.jsxs(D,{children:[e.jsx($,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs(U,{className:"flex items-center gap-2",children:[e.jsx(ue,{className:"h-5 w-5"})," Landing Page Funnel"]}),e.jsx(M,{children:"Ad spend visibility: visitors, CTA clicks, and signups"})]}),e.jsx("div",{className:"flex gap-1",children:[7,14,30,60].map(x=>e.jsxs("button",{onClick:()=>o(x),className:`px-3 py-1 text-xs rounded-md border transition-colors ${i===x?"bg-primary text-primary-foreground":"hover:bg-muted"}`,children:[x,"d"]},x))})]})}),e.jsxs(k,{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-5",children:[e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Visitors"}),e.jsx("p",{className:"text-2xl font-bold",children:p.visitors.toLocaleStr
6ing()})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"CTA Clicks"}),e.jsx("p",{className:"text-2xl font-bold",children:p.clicks.toLocaleString()})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Signups"}),e.jsx("p",{className:"text-2xl font-bold",children:p.signups.toLocaleString()})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Click Rate"}),e.jsxs("p",{className:"text-2xl font-bold",children:[p.clickRate,"%"]})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Signup Rate"}),e.jsxs("p",{className:"text-2xl font-bold",children:[p.signupRate,"%"]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold mb-3",children:"Conversion Funnel"}),e.jsx("div",{className:"space-y-2",children:[{label:"Visitors",count:p.visitors,pct:100},{label:"CTA Clicks",count:p.clicks,pct:p.visitors>0?Math.round(p.clicks/p.visitors*100):0},{label:"Signups",count:p.signups,pct:p.visitors>0?Math.round(p.signups/p.visitors*100):0}].map((x,T,n)=>{const c=T>0?n[T-1].count-x.count:0;return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs text-muted-foreground w-24 truncate",children:x.label}),e.jsxs("div",{className:"flex-1 h-6 bg-muted rounded-full overflow-hidden relative",children:[e.jsx("div",{className:"h-full bg-primary rounded-full transition-all duration-500",style:{width:`${x.pct}%`}}),e.jsxs("span",{className:"absolute inset-0 flex items-center justify-center text-xs font-medium",children:[x.count.toLocaleString()," (",x.pct,"%)"]})]}),c>0&&e.jsxs("span",{className:"text-xs text-destructive w-20 text-right flex items-center justify-end gap-1",children:[e.jsx(Le,{className:"size-3"})," -",c.toLocaleString()]})]},x.label)})})]}),v.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold mb-3",children:"Daily Timeline"}),e.jsx(ne,{config:ss,className:"h-[250px]",children:e.jsxs(Be,{data:v.map(x=>({...x,date:new Date(x.date).toLocaleDateString("en-US",{month:"short",day:"numeric"})})),children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{id:"fillVisitors",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"var(--color-visitors)",stopOpacity:.3}),e.jsx("stop",{offset:"95%",stopColor:"var(--color-visitors)",stopOpacity:0})]}),e.jsxs("linearGradient",{id:"fillClicks",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"var(--color-clicks)",stopOpacity:.3}),e.jsx("stop",{offset:"95%",stopColor:"var(--color-clicks)",stopOpacity:0})]}),e.jsxs("linearGradient",{id:"fillSignups",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"var(--color-signups)",stopOpacity:.3}),e.jsx("stop",{offset:"95%",stopColor:"var(--color-signups)",stopOpacity:0})]})]}),e.jsx(ce,{strokeDasharray:"3 3"}),e.jsx(de,{dataKey:"date",tick:{fontSize:10}}),e.jsx(oe,{tick:{fontSize:10}}),e.jsx(xe,{content:e.jsx(me,{})}),e.jsx(_,{type:"monotone",dataKey:"visitors",stroke:"var(--color-visitors)",fill:"url(#fillVisitors)",strokeWidth:2}),e.jsx(_,{type:"monotone",dataKey:"clicks",stroke:"var(--color-clicks)",fill:"url(#fillClicks)",strokeWidth:2}),e.jsx(_,{type:"monotone",dataKey:"signups",stroke:"var(--color-signups)",fill:"url(#fillSignups)",strokeWidth:2})]})})]}),S.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold mb-3",children:"Traffic Sources"}),e.jsxs(y,{children:[e.jsx(w,{children:e.jsxs(m,{children:[e.jsx(a,{children:"Source"}),e.jsx(a,{className:"text-right",children:"Visitors"}),e.jsx(a,{className:"text-right",children:"% of Total"})]})}),e.jsx(C,{children:S.map(x=>e.jsxs(m,{children:[e.jsx(r,{children:e.jsx(N,{variant:"outline",className:"text-xs",children:x.source})}),e.jsx(r,{className:"text-right",children:x.visitors.toLocaleString()}),e.jsxs(r,{className:"text-right",children:[p.visitors>0?Math.round(x.visitors/p.visitors*100):0,"%"]})]},x.source))})]})]})]})]})})}const rs=["users","subscriptions","costs","funnel"];function As(){const[s,j]=Ee(),h=s.get("tab"),t=rs.includes(h)?h:"users",i=o=>{o==="users"?s.delete("tab"):s.set("tab",o),j(s,{replace:!0})};return e.jsx(Pe,{icon:Y,title:"Business",subheader:"Users, subscriptions, costs, and conversion funnel",children:e.jsx("div",{className:"p-6",children:e.jsxs(Fe,{value:t,onValueChange:i,children:[e.jsxs($e,{children:[e.jsxs(B,{value:"users",children:[e.jsx(q,{className:"h-4 w-4"})," Users"]}),e.jsxs(B,{value:"subscriptions",children:[e.jsx(Y,{className:"h-4 w-4"})," Subscriptions"]}),e.jsxs(B,{value:"costs",children:[e.jsx(ie,{className:"h-4 w-4"})," Costs & API"]}),e.jsxs(B,{value:"funnel",children:[e.jsx(ue,{className:"h-4 w-4"})," Funnel"]})]}),e.jsx(I,{value:"users",children:e.jsx(Je,{})}),e.jsx(I,{value:"subscriptions",children:e.jsx(Ze,{})}),e.jsx(I,{value:"costs",children:e.jsx(es,{})}),e.jsx(I,{value:"funnel",children:e.jsx(ts,{})})]})})})}export{As as AdminBusinessPage};

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.