PageSourceSearch

https://brainbaby.ai/assets/ExecutiveDashboard-D5D6QNpi.js

js brainbaby.ai collected 2026-10-05 11:56:28 UTC 15,475 bytes, 6 lines download raw bytes

1import{r as o,j as e}from"./vendor-react-DMVi3k1U.js";import{C as i,a as l,b as c,c as d,d as T}from"./card-D7K5bvn2.js";import{B as U}from"./badge-DM7W5mOu.js";import{B}from"./button-BW86p14d.js";import{S as oe}from"./scroll-area-ByFxNVkH.js";import{e as u,d as E,l as F}from"./LanguageContext-_oPxm_ww.js";import{b as ie,c as I}from"./utils-996tuyy-.js";import{f as N,s as le}from"./format-DNISlAjS.js";import{L as ce}from"./loader-circle-HmeT5FoD.js";import{T as de}from"./triangle-alert-B6SlrLfG.js";import{R as O}from"./refresh-cw-Ct45fRK2.js";import{U as me}from"./users-B5rhFthL.js";import{C as xe}from"./crown-f9vL4lro.js";import{B as ue}from"./brain-C384vunX.js";import{I as pe}from"./image-DMsbdnGs.js";import{V as he}from"./video-Cm0sRd-q.js";import{D as fe}from"./dollar-sign-CalYULUZ.js";import{M as je}from"./mail-HUDI0KBF.js";import{T as ge}from"./trending-up-BlqavKET.js";import{R as be,C as ye,X as Ne,Y as ve,T as we,B as Ce}from"./generateCategoricalChart--ayi8LND.js";import{B as ke}from"./BarChart-CeB8VYxO.js";import{L as Se}from"./layers-OfG7hw3t.js";import{s as z}from"./subDays-paxFEHkL.js";import{f as De}from"./formatDistanceToNow-CQjDAnD2.js";import"./vendor-radix-CtLlOcvJ.js";import"./index-BJ1m5ntQ.js";import"./en-US-rgpu1GwE.js";import"./isValid-DuinJWsd.js";import"./string-Dx7P_S-w.js";import"./linear-DGECpK-G.js";import"./init-Dmth1JHB.js";import"./defaultLocale-C4B-KCzX.js";import"./time-ByyzYylg.js";import"./band-CquvqAHh.js";import"./ordinal-DILIJJjt.js";import"./addDays-DpVWU7sk.js";import"./constructNow-BM8iyyMc.js";import"./endOfMonth-DUKlH1j9.js";/**
2 * @license lucide-react v0.462.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 $=ie("ShoppingCart",[["circle",{cx:"8",cy:"21",r:"1",key:"jimo8o"}],["circle",{cx:"19",cy:"21",r:"1",key:"13723u"}],["path",{d:"M2.05 2.05h2l2.66 12.42a2 2 0 0 0 2 1.58h9.78a2 2 0 0 0 1.95-1.57l1.65-7.43H5.12",key:"9zh506"}]]);function xs(){const[g,v]=o.useState(!0),[w,C]=o.useState(null),[p,H]=o.useState({totalUsers:0,activeSubs:0,abandonedCheckouts:0,totalMemories:0}),[k,P]=o.useState([]),[S,V]=o.useState([]),[D,K]=o.useState([]),[s,Y]=o.useState(null),h=o.useCallback(async()=>{var t,m;v(!0),C(null);try{const f=z(new Date,30).toISOString(),[X,G,b,q,Q]=await Promise.all([u.from("profiles").select("id",{count:"exact",head:!0}),u.from("user_subscriptions").select("id",{count:"exact",head:!0}).in("status",["active","trialing"]).gte("current_period_end",new Date().toISOString()),(async()=>{var M,R,A;const r=(M=(await u.auth.getSession()).data.session)==null?void 0:M.access_token;if(!r)return{data:null,problems:["Not signed in."]};const n=await fetch(E("admin-data"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`},body:JSON.stringify({type:"abandoned_checkouts",limit:50})});if(!n.ok)return{data:null,problems:[`Abandoned checkouts unavailable (${n.status}).`]};const x=await n.json();return{data:((R=x.data)==null?void 0:R.rows)??[],problems:((A=x.data)==null?void 0:A.problems)??[]}})(),u.from("weighted_memories").select("memory_layer, importance, recency").limit(1e4),u.from("profiles").select("created_at").gte("created_at",f).order("created_at",{ascending:!1}).limit(1e4)]),W=X.count??0,Z=G.count??0,L=b.data??[],ee=L.length;(t=b.problems)!=null&&t.length&&console.warn("[ExecutiveDashboard] abandoned checkouts:",b.problems.join(" "));const se=L.map(a=>({id:a.id,user_id:a.user_id,email:a.user_email||"Unknown",amount:a.amount??0,currency:a.currency??"TRY",status:a.status,created_at:a.created_at})),_=q.data??[],ae=_.length,y=new Map;for(const a of _){const r=a.memory_layer??"unknown",n=y.get(r)||{count:0,impSum:0,recSum:0};n.count++,n.impSum+=Number(a.importance??0),n.recSum+=Number(a.recency??0),y.set(r,n)}const te=Array.from(y.entries()).map(([a,r])=>({layer:a,count:r.count,avgImportance:r.count>0?+(r.impSum/r.count).toFixed(2):0,avgRecency:r.count>0?+(r.recSum/r.count).toFixed(2):0})),re=Q.data??[],j=new Map;for(let a=29;a>=0;a--){const r=N(le(z(new Date,a)),"yyyy-MM-dd");j.set(r,0)}for(const a of re){const r=N(new Date(a.created_at),"yyyy-MM-dd");j.set(r,(j.get(r)||0)+1)}const ne=Array.from(j.entries()).sort(([a],[r])=>a.localeCompare(r)).map(([a,r])=>({date:N(new Date(a),"MMM dd"),count:r}));H({totalUsers:W,activeSubs:Z,abandonedCheckouts:ee,totalMemories:ae}),P(se),V(ne),K(te);try{const{data:a}=await u.auth.getSession(),r=(m=a.session)==null?void 0:m.access_token;if(r){const n=await fetch(E("admin-data"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`},body:JSON.stringify({type:"credit_stats"})});if(n.ok){const x=await n.json();Y((x==null?void 0:x.data)||null)}}}catch(a){F("credit_stats fetch failed",a)}}catch(f){F("Executive dashboard error",f),C(f.message||"Failed to load dashboard data")}finally{v(!1)}},[]);if(o.useEffect(()=>{h()}
6,[h]),g)return e.jsx("div",{className:"flex items-center justify-center py-24",children:e.jsx(ce,{className:"h-8 w-8 animate-spin text-primary"})});if(w)return e.jsxs("div",{className:"text-center py-24 space-y-4",children:[e.jsx(de,{className:"h-10 w-10 text-destructive mx-auto"}),e.jsx("p",{className:"text-muted-foreground",children:w}),e.jsxs(B,{onClick:h,variant:"outline",size:"sm",children:[e.jsx(O,{className:"h-4 w-4 mr-2"})," Retry"]})]});const J=[{label:"Total Users",value:p.totalUsers,icon:me,color:"text-blue-500"},{label:"Active Subscriptions",value:p.activeSubs,icon:xe,color:"text-amber-500"},{label:"Unfinished Checkouts",value:p.abandonedCheckouts,icon:$,color:"text-red-500"},{label:"Total Memories",value:p.totalMemories,icon:ue,color:"text-violet-500"}];return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Executive Overview"}),e.jsx("p",{className:"text-muted-foreground",children:"Platform health at a glance"})]}),e.jsx(B,{onClick:h,variant:"ghost",size:"sm",disabled:g,children:e.jsx(O,{className:I("h-4 w-4",g&&"animate-spin")})})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4",children:J.map(t=>{const m=t.icon;return e.jsx(i,{children:e.jsxs(l,{className:"p-5 flex items-center gap-4",children:[e.jsx("div",{className:I("p-3 rounded-xl bg-muted",t.color),children:e.jsx(m,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:t.label}),e.jsx("p",{className:"text-2xl font-bold",children:t.value.toLocaleString()})]})]})},t.label)})}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsxs(i,{children:[e.jsx(c,{className:"pb-2",children:e.jsxs(d,{className:"text-sm flex items-center gap-2 text-muted-foreground font-medium",children:[e.jsx(pe,{className:"h-4 w-4 text-pink-500"}),"Image Credits"]})}),e.jsxs(l,{className:"pt-0 space-y-1.5",children:[e.jsxs("div",{className:"flex items-baseline justify-between",children:[e.jsx("span",{className:"text-2xl font-bold tabular-nums",children:((s==null?void 0:s.imageCredits.balanceOutstanding)??0).toLocaleString()}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"outstanding"})]}),e.jsxs("div",{className:"text-xs text-muted-foreground space-y-0.5",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:"Used (lifetime)"}),e.jsx("span",{className:"tabular-nums",children:((s==null?void 0:s.imageCredits.usedHistorical)??0).toLocaleString()})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:"Comped (bonus)"}),e.jsx("span",{className:"tabular-nums",children:((s==null?void 0:s.imageCredits.comped)??0).toLocaleString()})]}),e.jsxs("div",{className:"flex justify-between font-medium text-foreground",children:[e.jsx("span",{children:"Cost lost"}),e.jsxs("span",{className:"tabular-nums",children:["$",((s==null?void 0:s.imageCredits.costLost)??0).toFixed(2)]})]})]})]})]}),e.jsxs(i,{children:[e.jsx(c,{className:"pb-2",children:e.jsxs(d,{className:"text-sm flex items-center gap-2 text-muted-foreground font-medium",children:[e.jsx(he,{className:"h-4 w-4 text-purple-500"}),"Video Credits"]})}),e.jsxs(l,{className:"pt-0 space-y-1.5",children:[e.jsxs("div",{className:"flex items-baseline justify-between",children:[e.jsx("span",{className:"text-2xl font-bold tabular-nums",children:((s==null?void 0:s.videoCredits.balanceOutstanding)??0).toLocaleString()}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"outstanding"})]}),e.jsxs("div",{className:"text-xs text-muted-foreground space-y-0.5",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:"Used (lifetime)"}),e.jsx("span",{className:"tabular-nums",children:((s==null?void 0:s.videoCredits.usedHistorical)??0).toLocaleString()})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:"Comped (bonus)"}),e.jsx("span",{className:"tabular-nums",children:((s==null?void 0:s.videoCredits.comped)??0).toLocaleStr
6ing()})]}),e.jsxs("div",{className:"flex justify-between font-medium text-foreground",children:[e.jsx("span",{children:"Cost lost"}),e.jsxs("span",{className:"tabular-nums",children:["$",((s==null?void 0:s.videoCredits.costLost)??0).toFixed(2)]})]})]})]})]}),e.jsxs(i,{children:[e.jsx(c,{className:"pb-2",children:e.jsxs(d,{className:"text-sm flex items-center gap-2 text-muted-foreground font-medium",children:[e.jsx(fe,{className:"h-4 w-4 text-emerald-500"}),"Revenue vs Loss"]})}),e.jsxs(l,{className:"pt-0 space-y-1.5",children:[e.jsxs("div",{className:"flex items-baseline justify-between",children:[e.jsxs("span",{className:"text-2xl font-bold tabular-nums text-emerald-600 dark:text-emerald-400",children:["$",((s==null?void 0:s.revenue.paidUSD)??0).toLocaleString(void 0,{maximumFractionDigits:0})]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"paid"})]}),(s==null?void 0:s.partialAggregates)&&s.partialAggregates.length>0&&e.jsxs("div",{className:"rounded border border-amber-500/40 bg-amber-500/10 px-2 py-1.5 text-[11px] leading-snug text-amber-700 dark:text-amber-400",children:[e.jsx("span",{className:"font-medium",children:"Understated —"})," these reads were truncated, so the figures below are lower than reality:"," ",s.partialAggregates.join(", ")]}),e.jsxs("div",{className:"text-xs text-muted-foreground space-y-0.5",children:[e.jsxs("div",{className:"flex justify-between font-medium text-foreground",children:[e.jsx("span",{children:"Total cost lost"}),e.jsxs("span",{className:"tabular-nums",children:["$",((s==null?void 0:s.totalCostLostUSD)??0).toFixed(2)]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:"Image op-cost"}),e.jsxs("span",{className:"tabular-nums",children:["$",((s==null?void 0:s.imageCredits.operationalCost)??0).toFixed(2)]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:"Video op-cost"}),e.jsxs("span",{className:"tabular-nums",children:["$",((s==null?void 0:s.videoCredits.operationalCost)??0).toFixed(2)]})]})]})]})]}),e.jsxs(i,{children:[e.jsx(c,{className:"pb-2",children:e.jsxs(d,{className:"text-sm flex items-center gap-2 text-muted-foreground font-medium",children:[e.jsx(je,{className:"h-4 w-4 text-sky-500"}),"Email"]})}),e.jsxs(l,{className:"pt-0 space-y-1.5",children:[e.jsxs("div",{className:"flex items-baseline justify-between",children:[e.jsx("span",{className:"text-2xl font-bold tabular-nums",children:((s==null?void 0:s.email.sentLast30Days)??0).toLocaleString()}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"last 30d"})]}),e.jsxs("div",{className:"text-xs text-muted-foreground space-y-0.5",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:"Sent (all time)"}),e.jsx("span",{className:"tabular-nums",children:((s==null?void 0:s.email.sentTotal)??0).toLocaleString()})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:"Baby credits out"}),e.jsx("span",{className:"tabular-nums",children:((s==null?void 0:s.babyCredits.balanceOutstanding)??0).toLocaleString()})]})]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs(i,{children:[e.jsxs(c,{className:"pb-3",children:[e.jsxs(d,{className:"text-lg flex items-center gap-2",children:[e.jsx($,{className:"h-5 w-5 text-red-500"}),"Unfinished Checkouts"]}),e.jsx(T,{children:"Unpaid or failed Revolut attempts from the last 30 days. Successful payments are shown in Invoices."})]}),e.jsx(l,{children:k.length===0?e.jsx("p",{className:"text-muted-foreground text-center py-8 text-sm",children:"No abandoned checkouts found"}):e.jsx(oe,{className:"h-[300px]",children:e.jsx("div",{className:"space-y-2",children:k.map(t=>e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg border bg-card hover:bg-muted/50 transition-colors text-sm",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"font-medium truncate",children:t.email}),e.jsx("p",{className:"text-xs text-muted-foreground",children:De(new Date(t.created_at),{addSuffix:!0})})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsxs("span",{className:"font-mono text-xs",children:[Number(t.amount).toFixed(2)," ",t.currency]}),e.jsx(U,{variant:t.status==="failed"?"destructive":"secondary",className:"text-xs",children:t.status==="pending"?"Not completed":t.status.replace("3ds_","3DS ")})]})]},t.id))})})})]}),e.jsxs(i,{children:[e.jsx(c,{className:"pb-3",children:e.jsxs(d,{className:"text-lg flex items-center gap-2",children:[e.jsx(ge,{className:"h-5 w-5 text-blue-500"}),"Registrations (Last 30 Days)"]})}),e.jsx(l,{children:S.length===0?e.jsx("p",{className:"text-muted-foreground text-center py-8 text-sm",children:"No registration data"}):e.jsx(be,{width:"100%",height:300,children:e.jsxs(ke,{data:S,children:[e.jsx(ye,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(Ne,{dataKey:"date",tick:{fontSize:10},interval:4,className:"fill-muted-foreground"}),e.jsx(ve,{allowDecimals:!1,tick:{fontSize:11},className:"fill-muted-foreground"}
6),e.jsx(we,{contentStyle:{backgroundColor:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:"8px",fontSize:"12px"}}),e.jsx(Ce,{dataKey:"count",fill:"hsl(var(--primary))",radius:[4,4,0,0]})]})})})]})]}),e.jsx("div",{className:"grid grid-cols-1 gap-6",children:e.jsxs(i,{children:[e.jsxs(c,{className:"pb-3",children:[e.jsxs(d,{className:"text-lg flex items-center gap-2",children:[e.jsx(Se,{className:"h-5 w-5 text-violet-500"}),"Memory System Health"]}),e.jsx(T,{children:"Breakdown by memory layer"})]}),e.jsx(l,{children:D.length===0?e.jsx("p",{className:"text-muted-foreground text-center py-8 text-sm",children:"No memory data"}):e.jsx("div",{className:"space-y-3",children:D.sort((t,m)=>m.count-t.count).map(t=>e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg border",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium capitalize",children:t.layer.replace("_"," ")}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Avg importance: ",t.avgImportance," · Avg recency: ",t.avgRecency]})]}),e.jsx(U,{variant:"secondary",className:"text-sm font-mono",children:t.count.toLocaleString()})]},t.layer))})})]})})]})}export{xs as ExecutiveDashboard};

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.