1import{r as ve,j as e}from"./vendor-react-4XT1lARu.js";import{d as h}from"./i18n-VRKNFYnf.js";import{g as ye,B as x,e as we,an as ke,t as Ce,S as R,am as j,Z as Se,w as Fe,V as Qe,cS as Ae,a2 as Je,G as Ye,cf as Ze,aH as es,aX as ss}from"./index-BbITdBcD.js";import{S as g}from"./skeleton-D1wkMCFi.js";import{T as ts,a as as,b as Le,c as y,d as rs,e as w}from"./table-BZjB4EZ4.js";import{D as K}from"./dollar-sign-Dxg8JRQM.js";import{D as W}from"./database-BPyLDctl.js";import{R as F,X as A,Y as L,T,B as k,E as Te,C as ds}from"./generateCategoricalChart-D4_HxV2D.js";import{B as M}from"./BarChart-KEpxrgF2.js";import{C as P}from"./CartesianGrid-Dt0tuRQc.js";import{C as Me}from"./circle-x-Dbk1Yor9.js";import{f as B}from"./format-DLgXQaDi.js";import"./vendor-radix-CyRj67ay.js";import"./index-Dh4i1-J3.js";import"./en-US-DVlPbiiU.js";import"./constructFrom-rJN6zrQ_.js";import"./startOfDay-BKq3QRE6.js";const ls=[{value:"1h",label:"1 Hour"},{value:"12h",label:"12 Hours"},{value:"24h",label:"24 Hours"},{value:"7d",label:"7 Days"},{value:"14d",label:"14 Days"},{value:"30d",label:"30 Days"},{value:"3m",label:"3 Months"},{value:"6m",label:"6 Months"},{value:"1y",label:"1 Year"}],Be=[{key:"dictionary",label:"Dictionary Lookup",colour:"#3B82F6",description:"AI-powered word definitions when not found in local dictionaries",model:"GPT-4o-mini"},{key:"content_completion",label:"Content Completion",colour:"#8B5CF6",description:"Generates missing article keywords and grammar points",model:"GPT-4o-mini"},{key:"meta_tags",label:"Meta Tags",colour:"#EC4899",description:"Creates SEO meta descriptions for articles",model:"GPT-4o-mini"},{key:"duplicate_detection",label:"Duplicate Detection",colour:"#F59E0B",description:"Checks for similar articles before ingestion",model:"GPT-4o-mini"},{key:"daily_message",label:"Daily Message",colour:"#10B981",description:"Personalised welcome messages for returning users",model:"GPT-4o-mini"},{key:"answer_verification",label:"Answer Verification",colour:"#6366F1",description:"Validates quiz answers with semantic understanding",model:"GPT-4o-mini"},{key:"quiz_generation",label:"Quiz Generation",colour:"#EF4444",description:"Creates comprehension questions for articles",model:"GPT-4o"},{key:"article_grading",label:"Article Grading",colour:"#14B8A6",description:"Assigns CEFR difficulty levels to articles",model:"GPT-4o"},{key:"sentence_writing",label:"Sentence Writing",colour:"#F97316",description:"Evaluates user-written sentences in revision practice",model:"GPT-4o-mini"},{key:"social_post",label:"Social Post",colour:"#06B6D4",description:"Generates social media posts for new articles",model:"GPT-4o-mini"},{key:"tts",label:"Text-to-Speech",colour:"#84CC16",description:"Native audio narration for articles and vocabulary",model:"OpenAI TTS"},{key:"dalle",label:"DALL-E Image",colour:"#A855F7",description:"Generates unique cover images for articles",model:"DALL-E 3"},{key:"interest_scoring",label:"Interest Scoring",colour:"#0EA5E9",description:"Scores article quality using 9 criteria (0-100)",model:"GPT-4o"},{key:"difficulty_grading",label:"Difficulty Grading",colour:"#22C55E",description:"Vocabulary-based CEFR level assignment",model:"GPT-4o"},{key:"summary_generation",label:"Summary Generation",colour:"#7C3AED",description:"Creates article summaries for homepage cards",model:"GPT-4o-mini"},{key:"content_validation",label:"Content Validation",colour:"#DC2626",description:"Pre-ingestion quality control for articles",model:"GPT-4o-mini"},{key:"article_qa",label:"Article QA",colour:"#0D9488",description:"Title cleaning and paragraph formatting",model:"GPT-4o-mini"},{key:"gemini_image",label:"Gemini Image",colour:"#4F46E5",description:"Alternative image generation using xAI Grok",model:"Grok-2-Image"},{key:"video_call_realtime",label:"Video Call (Realtime)",colour:"#E11D48",description:"AI tutor conversations using OpenAI Realtime API (high cost)",model:"GPT-4o Realtime"},{key:"sage_assist_translate",label:"Sage Assist (Translate)",colour:"#059669",description:"AI-powered sentence translation in articles",model:"GPT-4o-mini"},{key:"sage_assist_chat",label:"Sage Assist (Chat)",colour:"#10B981",description:"Follow-up questions about sentences",model:"GPT-4o-mini"},{key:"sage_assist_word_insight",label:"Sage Assist: Word Insights",colour:"#7C3AED",description:"In-context word explanations from the live dictionary panel",model:"GPT-4o-mini"},{key:"dictionary_contextual",label:"Dictionary (Contextual)",colour:"#2563EB",description:"Context-aware word definitions using sentence disambiguation",model:"GPT-4o-mini"}],Pe=Object.fromEntries(Be.map(r=>[r.key,r.label])),$e=Object.fromEntries(Be.map(r=>[r.key,r.colour])),Ie={es:"Espanol Spanish",de:"Deutsch German",ja:"Japanese",fr:"Francais French",zh:"Chinese",en:"English",mandarin:"Mandarin Chinese",japanese:"Japanese",spanish:"Espanol Spanish",german:"Deutsch German",french:"Francais French",english:"English"},Ue={mandarin:"Mandarin Chinese",japanese:"Japanese",spanish:"Espanol Spanish",german:"Deutsch German",french:"Francais French",english:"English"};function c({children:r,className:p="",testId:m}){return e.jsxs("div",{className:`relative overflow-hidden rounded-2xl border border-border/40 bg-gradient-to-br from-card/80 via-card/60 to-card/40 backdrop-blur-xl shadow-xl ${p}`,"data-testid":m,children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-primary/5 via-trans
1parent to-primary/3 pointer-events-none"}),e.jsx("div",{className:"relative",children:r})]})}function f(r){return r<.01?`$${r.toFixed(4)}`:`$${r.toFixed(2)}`}function Re(r){return r<1e3?`${Math.round(r)}ms`:`${(r/1e3).toFixed(1)}s`}function is(r,p){const m=new Date(r);return p==="hour"?B(m,"HH:mm"):p==="day"?B(m,"dd MMM"):p==="week"?B(m,"dd MMM"):B(m,"MMM yyyy")}function Cs(){var Q,J,Y,Z,ee,se,te,ae,re,de,le,ie,ne,oe,ce,me,xe,ue,he,ge,pe,be,je,fe,Ne;const[r,p]=ve.useState("24h"),[m,De]=ve.useState(30),{data:D,isLoading:b}=h({queryKey:["/api/admin/ai-usage/stats",{range:r}],refetchInterval:6e4}),{data:q,isLoading:V}=h({queryKey:["/api/admin/ai-usage/by-function",{range:r}],refetchInterval:6e4}),{data:N,isLoading:H}=h({queryKey:["/api/admin/ai-usage/time-series",{range:r}],refetchInterval:6e4}),{data:l,isLoading:v}=h({queryKey:["/api/dictionary/ai-stats"],queryFn:async()=>{const s=await fetch("/api/dictionary/ai-stats",{credentials:"include"});if(!s.ok)throw new Error("Failed to fetch AI dictionary stats");return s.json()},refetchInterval:6e4}),{data:u,isLoading:qe}=h({queryKey:["/api/pronunciations/stats"],queryFn:async()=>{const s=await fetch("/api/pronunciations/stats",{credentials:"include"});if(!s.ok)throw new Error("Failed to fetch pronunciation stats");return s.json()},refetchInterval:6e4}),{data:a,isLoading:Ee}=h({queryKey:["/api/admin/ai-usage/video-call-per-user",{range:r,activeWindow:m}],refetchInterval:6e4}),{data:n,isLoading:Ge}=h({queryKey:["/api/admin/ai-usage/sage-assist-per-user",{range:r}],refetchInterval:6e4}),{data:o,isLoading:Oe}=h({queryKey:["/api/admin/sage-welcome/stats",{range:r}],refetchInterval:6e4}),{data:E,isLoading:_e}=h({queryKey:["/api/admin/video-call/sessions-by-mode-timeseries",{range:r}],refetchInterval:6e4}),{data:G,isLoading:ze}=h({queryKey:["/api/admin/ai-usage/by-model",{range:r}],refetchInterval:6e4}),{data:d,isLoading:Ke}=h({queryKey:["/api/admin/ai-usage/monthly-average"],refetchInterval:6e4}),X=(E==null?void 0:E.timeSeries)||[],$=(G==null?void 0:G.byModel)||[],i=D==null?void 0:D.stats,O=(q==null?void 0:q.byFunction)||[],We=(N==null?void 0:N.timeSeries)||[],_=(N==null?void 0:N.bucketSize)||"hour",I=We.map(s=>({...s,label:is(s.timestamp,_)})),z=O.map(s=>({name:Pe[s.functionType]||s.functionType,requests:s.requestCount,cost:s.totalCost,colour:$e[s.functionType]||"#6B7280"}));return e.jsx("div",{className:"min-h-screen",children:e.jsxs("div",{className:"container mx-auto px-4 py-8 max-w-7xl pb-24 space-y-8",children:[e.jsxs("div",{className:"relative overflow-hidden rounded-3xl bg-gradient-to-br from-violet-600 via-purple-600 to-indigo-700 p-8 text-white shadow-2xl",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-r from-black/10 via-trans
1parent to-black/10"}),e.jsx("div",{className:"absolute top-0 right-0 w-96 h-96 bg-white/10 rounded-full blur-3xl -translate-y-1/2 translate-x-1/2"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-64 h-64 bg-purple-300/20 rounded-full blur-2xl translate-y-1/2 -translate-x-1/2"}),e.jsx("div",{className:"relative z-10",children:e.jsx("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-3 rounded-2xl bg-white/20 backdrop-blur-sm",children:e.jsx(ye,{className:"h-8 w-8"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h1",{className:"text-3xl font-bold tracking-tight","data-testid":"heading-ai-usage",children:"AI Usage"}),e.jsx(x,{variant:"secondary",className:"bg-white/20 text-white border-white/30 hover:bg-white/30",children:"Super Admin"})]}),e.jsx("p",{className:"text-purple-100 mt-1",children:"Monitor AI function usage, costs, and performance across the platform"})]})]})})})]}),e.jsx(c,{className:"p-4",children:e.jsx("div",{className:"flex flex-wrap gap-2",children:ls.map(s=>e.jsx(we,{variant:r===s.value?"default":"outline",size:"sm",onClick:()=>p(s.value),className:r===s.value?"bg-gradient-to-r from-violet-600 to-purple-600 hover:from-violet-700 hover:to-purple-700":"","data-testid":`button-range-${s.value}`,children:s.label},s.value))})}),e.jsxs("div",{className:"grid gap-4 grid-cols-2 lg:grid-cols-4",children:[e.jsxs(c,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Total Requests"}),e.jsx("div",{className:"p-2 rounded-lg bg-gradient-to-br from-violet-500/20 to-purple-500/20",children:e.jsx(ye,{className:"h-4 w-4 text-violet-500"})})]}),b?e.jsx(g,{className:"h-8 w-24"}):e.jsx("p",{className:"text-2xl font-bold","data-testid":"stat-total-requests",children:((Q=i==null?void 0:i.totalRequests)==null?void 0:Q.toLocaleString())||0})]}),e.jsxs(c,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Total Spend"}),e.jsx("div",{className:"p-2 rounded-lg bg-gradient-to-br from-emerald-500/20 to-teal-500/20",children:e.jsx(K,{className:"h-4 w-4 text-emerald-500"})})]}),b?e.jsx(g,{className:"h-8 w-24"}):e.jsx("p",{className:"text-2xl font-bold","data-testid":"stat-total-spend",children:f((i==null?void 0:i.totalCost)||0)})]}),e.jsxs(c,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Cache Hit Rate"}),e.jsx("div",{className:"p-2 rounded-lg bg-gradient-to-br from-blue-500/20 to-indigo-500/20",children:e.jsx(W,{className:"h-4 w-4 text-blue-500"})})]}),b?e.jsx(g,{className:"h-8 w-24"}):e.jsxs("p",{className:"text-2xl font-bold","data-testid":"stat-cache-hit-rate",children:[((i==null?void 0:i.cacheHitRate)||0).toFixed(1),"%"]})]}),e.jsxs(c,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Success Rate"}),e.jsx("div",{className:"p-2 rounded-lg bg-gradient-to-br from-amber-500/20 to-orange-500/20",children:e.jsx(ke,{className:"h-4 w-4 text-amber-500"})})]}),b?e.jsx(g,{className:"h-8 w-24"}):e.jsxs("p",{className:"text-2xl font-bold","data-testid":"stat-success-rate",children:[((i==null?void 0:i.successRate)||0).toFixed(1),"%"]})]})]}),e.jsxs(c,{className:"p-6",testId:"panel-monthly-average",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx("div",{className:"p-2 rounded-xl bg-gradient-to-br from-cyan-500/20 to-blue-500/20",children:e.jsx(Ce,{className:"h-5 w-5 text-cyan-500"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Monthly Token Usage"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Average usage based on ",(d==null?void 0:d.monthsAnalyzed)||0," months of data"]})]})]}),Ke?e.jsx("div",{className:"grid gap-4 grid-cols-2 lg:grid-cols-4",children:[1,2,3,4].map(s=>e.jsx(g,{className:"h-24"},s))}):e.jsxs("div",{className:"grid gap-4 grid-cols-2 lg:grid-cols-4",children:[e.jsxs("div",{className:"p-4 rounded-xl bg-gradient-to-br from-cyan-500/10 to-blue-500/10 border border-cyan-500/20",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Avg Monthly Tokens"}),e.jsxs("p",{className:"text-2xl font-bold text-cyan-600 dark:text-cyan-400","data-testid":"stat-avg-monthly-tokens",children:[(((d==null?void 0:d.avgMonthlyTokens)||0)/1e6).toFixed(2),"M"]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[((J=d==null?void 0:d.avgMonthlyRequests)==null?void 0:J.toLocaleStr
1ing())||0," requests/mo"]})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-gradient-to-br from-emerald-500/10 to-teal-500/10 border border-emerald-500/20",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Avg Monthly Cost"}),e.jsxs("p",{className:"text-2xl font-bold text-emerald-600 dark:text-emerald-400","data-testid":"stat-avg-monthly-cost",children:["$",((d==null?void 0:d.avgMonthlyCost)||0).toFixed(2)]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["~$",(((d==null?void 0:d.avgMonthlyCost)||0)/30).toFixed(2),"/day avg"]})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-gradient-to-br from-violet-500/10 to-purple-500/10 border border-violet-500/20",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Current Month"}),e.jsxs("p",{className:"text-2xl font-bold text-violet-600 dark:text-violet-400","data-testid":"stat-current-month-cost",children:["$",(((Y=d==null?void 0:d.currentMonth)==null?void 0:Y.cost)||0).toFixed(2)]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Day ",((Z=d==null?void 0:d.currentMonth)==null?void 0:Z.daysElapsed)||0," of month"]})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-gradient-to-br from-amber-500/10 to-orange-500/10 border border-amber-500/20",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Projected This Month"}),e.jsxs("p",{className:"text-2xl font-bold text-amber-600 dark:text-amber-400","data-testid":"stat-projected-monthly-cost",children:["$",(((ee=d==null?void 0:d.projections)==null?void 0:ee.projectedMonthlyCost)||0).toFixed(2)]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:((se=d==null?void 0:d.projections)==null?void 0:se.vsAverage)!==void 0&&e.jsxs("span",{className:d.projections.vsAverage>=0?"text-red-500":"text-green-500",children:[d.projections.vsAverage>=0?"+":"",d.projections.vsAverage,"% vs avg"]})})]})]})]}),e.jsxs(c,{className:"p-6",testId:"panel-cost-by-model",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx("div",{className:"p-2 rounded-xl bg-gradient-to-br from-pink-500/20 to-rose-500/20",children:e.jsx(R,{className:"h-5 w-5 text-pink-500"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Cost by Model"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"AI spending breakdown by model for selected time range"})]})]}),ze?e.jsx("div",{className:"space-y-2",children:[1,2,3,4,5].map(s=>e.jsx(g,{className:"h-10"},s))}):$.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"No model data available for this range"}):e.jsxs("div",{className:"space-y-3",children:[$.map((s,t)=>{const U=$.reduce((He,Xe)=>He+Xe.totalCost,0),C=U>0?s.totalCost/U*100:0,S=["#8B5CF6","#3B82F6","#10B981","#F59E0B","#EF4444","#EC4899","#06B6D4","#84CC16"],Ve=S[t%S.length];return e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-32 truncate text-sm font-medium",title:s.model,children:s.model}),e.jsx("div",{className:"flex-1 h-6 bg-muted/30 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${C}%`,backgroundColor:Ve}})}),e.jsx("div",{className:"w-20 text-right text-sm font-semibold",children:f(s.totalCost)}),e.jsxs("div",{className:"w-16 text-right text-xs text-muted-foreground",children:[C.toFixed(1),"%"]}),e.jsxs("div",{className:"w-20 text-right text-xs text-muted-foreground",children:[s.requestCount.toLocaleString()," reqs"]})]},s.model)}),e.jsxs("div",{className:"pt-3 mt-3 border-t border-border/50 flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium",children:"Total"}),e.jsx("span",{className:"text-lg font-bold","data-testid":"stat-total-model-cost",children:f($.reduce((s,t)=>s+t.totalCost,0))})]})]})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsxs(c,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx("div",{className:"p-2 rounded-xl bg-gradient-to-br from-violet-500/20 to-purple-500/20",children:e.jsx(Ce,{className:"h-5 w-5 text-violet-500"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Requests Over Time"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Number of AI requests per ",_]})]})]}),H?e.jsx("div",{className:"flex items-center justify-center h-[280px]",children:e.jsx(j,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):I.length===0?e.jsx("div",{className:"flex items-center justify-center h-[280px] text-muted-foreground",children:"No data available for this time range"}):e.jsx(F,{width:"100%",height:280,children:e.jsxs(M,{data:I,margin:{top:10,right:10,left:0,bottom:0},children:[e.jsx(P,{strokeDasharray:"3 3",vertical:!1,className:"stroke-muted/30"}),e.jsx(A,{dataKey:"label",tick:{fontSize:11}
1,tickLine:!1,axisLine:!1}),e.jsx(L,{tick:{fontSize:11},tickLine:!1,axisLine:!1,width:40}),e.jsx(T,{contentStyle:{backgroundColor:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:"12px"},labelStyle:{fontWeight:600}}),e.jsx(k,{dataKey:"requestCount",name:"Requests",fill:"#8b5cf6",radius:[4,4,0,0]})]})})]}),e.jsxs(c,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx("div",{className:"p-2 rounded-xl bg-gradient-to-br from-emerald-500/20 to-teal-500/20",children:e.jsx(K,{className:"h-5 w-5 text-emerald-500"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Cost Over Time"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["AI spending per ",_]})]})]}),H?e.jsx("div",{className:"flex items-center justify-center h-[280px]",children:e.jsx(j,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):I.length===0?e.jsx("div",{className:"flex items-center justify-center h-[280px] text-muted-foreground",children:"No data available for this time range"}):e.jsx(F,{width:"100%",height:280,children:e.jsxs(M,{data:I,margin:{top:10,right:10,left:0,bottom:0},children:[e.jsx(P,{strokeDasharray:"3 3",vertical:!1,className:"stroke-muted/30"}),e.jsx(A,{dataKey:"label",tick:{fontSize:11},tickLine:!1,axisLine:!1}),e.jsx(L,{tick:{fontSize:11},tickLine:!1,axisLine:!1,width:50,tickFormatter:s=>`$${s.toFixed(2)}`}),e.jsx(T,{contentStyle:{backgroundColor:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:"12px"},labelStyle:{fontWeight:600},formatter:s=>[f(s),"Cost"]}),e.jsx(k,{dataKey:"totalCost",name:"Cost",fill:"#10b981",radius:[4,4,0,0]})]})})]})]}),e.jsxs(c,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx("div",{className:"p-2 rounded-xl bg-gradient-to-br from-amber-500/20 to-orange-500/20",children:e.jsx(Se,{className:"h-5 w-5 text-amber-500"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Usage by Function"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Breakdown of AI requests and costs by function type"})]})]}),V?e.jsx("div",{className:"flex items-center justify-center h-[350px]",children:e.jsx(j,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):z.length===0?e.jsx("div",{className:"flex items-center justify-center h-[350px] text-muted-foreground",children:"No data available for this time range"}):e.jsx(F,{width:"100%",height:350,children:e.jsxs(M,{data:z,layout:"vertical",margin:{top:10,right:30,left:120,bottom:10},children:[e.jsx(P,{strokeDasharray:"3 3",horizontal:!1,className:"stroke-muted/30"}),e.jsx(A,{type:"number",tick:{fontSize:12},tickLine:!1,axisLine:!1}),e.jsx(L,{type:"category",dataKey:"name",tick:{fontSize:12},tickLine:!1,axisLine:!1,width:110}),e.jsx(T,{contentStyle:{backgroundColor:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:"12px"},labelStyle:{fontWeight:600},formatter:(s,t)=>t==="cost"?[f(s),"Cost"]:[s.toLocaleString(),"Requests"]}),e.jsx(Te,{}),e.jsx(k,{dataKey:"requests",name:"Requests",fill:"hsl(var(--primary))",radius:[0,4,4,0],children:z.map((s,t)=>e.jsx(ds,{fill:s.colour},`cell-${t}`))})]})})]}),e.jsxs(c,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx("div",{className:"p-2 rounded-xl bg-gradient-to-br from-blue-500/20 to-indigo-500/20",children:e.jsx(W,{className:"h-5 w-5 text-blue-500"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Detailed Function Breakdown"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Complete statistics for each AI function"})]})]}),V?e.jsx("div",{className:"space-y-4",children:[1,2,3,4].map(s=>e.jsx(g,{className:"h-20 w-full"},s))}):O.length===0?e.jsx("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:"No data available for this time range"}):e.jsx("div",{className:"space-y-3",children:O.map(s=>e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-4 p-4 rounded-xl bg-muted/30 border border-border/30","data-testid":`function-row-${s.functionType}`,children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[e.jsx("div",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:$e[s.functionType]||"#6B7280"}}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium truncate",children:Pe[s.functionType]||s.functionType}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:[s.requestCount.toLocaleStr
1ing()," requests"]})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 sm:gap-3",children:[e.jsxs(x,{variant:"secondary",className:"whitespace-nowrap",children:[e.jsx(K,{className:"h-3 w-3 mr-1"}),f(s.totalCost)]}),e.jsxs(x,{variant:"outline",className:"whitespace-nowrap",children:[e.jsx(Se,{className:"h-3 w-3 mr-1"}),(s.totalInputTokens+s.totalOutputTokens).toLocaleString()," tokens"]}),e.jsxs(x,{variant:"outline",className:"whitespace-nowrap",children:[e.jsx(Fe,{className:"h-3 w-3 mr-1"}),Re(s.averageDurationMs)," avg"]}),s.cacheHits>0&&e.jsxs(x,{variant:"outline",className:"whitespace-nowrap text-emerald-600 dark:text-emerald-400",children:[e.jsx(W,{className:"h-3 w-3 mr-1"}),s.cacheHits," cache hits"]}),s.failures>0&&e.jsxs(x,{variant:"destructive",className:"whitespace-nowrap",children:[e.jsx(Me,{className:"h-3 w-3 mr-1"}),s.failures," failures"]})]})]},s.functionType))})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-3",children:[e.jsxs(c,{className:"p-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Total Tokens"}),b?e.jsx(g,{className:"h-7 w-24 mt-1"}):e.jsx("p",{className:"text-xl font-semibold","data-testid":"stat-total-tokens",children:((i==null?void 0:i.totalTokens)||0).toLocaleString()})]}),e.jsxs(c,{className:"p-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Average Duration"}),b?e.jsx(g,{className:"h-7 w-24 mt-1"}):e.jsx("p",{className:"text-xl font-semibold","data-testid":"stat-avg-duration",children:Re((i==null?void 0:i.averageDurationMs)||0)})]}),e.jsxs(c,{className:"p-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Cost per Request"}),b?e.jsx(g,{className:"h-7 w-24 mt-1"}):e.jsx("p",{className:"text-xl font-semibold","data-testid":"stat-cost-per-request",children:i!=null&&i.totalRequests?f(((i==null?void 0:i.totalCost)||0)/i.totalRequests):"$0.00"})]})]}),e.jsxs(c,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx("div",{className:"p-2 rounded-xl bg-gradient-to-br from-violet-500/20 to-purple-500/20",children:e.jsx(R,{className:"h-5 w-5 text-violet-500"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold",children:"AI Dictionary Fallback"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"AI-generated definitions when local dictionary lacks entries"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 mb-6",children:[e.jsxs("div",{className:"p-4 rounded-xl bg-gradient-to-br from-violet-500/10 to-purple-500/10 border border-violet-500/20",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Total AI Lookups"}),e.jsx("p",{className:"text-2xl font-bold",children:v?"...":((te=l==null?void 0:l.totalRequests)==null?void 0:te.toLocaleString())||"0"})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-gradient-to-br from-emerald-500/10 to-teal-500/10 border border-emerald-500/20",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Total Cost"}),e.jsxs("p",{className:"text-2xl font-bold",children:["$",v?"...":((ae=l==null?void 0:l.totalCost)==null?void 0:ae.toFixed(4))||"0.0000"]})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-gradient-to-br from-blue-500/10 to-indigo-500/10 border border-blue-500/20",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Avg Cost/Request"}),e.jsxs("p",{className:"text-2xl font-bold",children:["$",v?"...":((re=l==null?void 0:l.costPerRequest)==null?void 0:re.toFixed(5))||"0.00000"]})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-gradient-to-br from-amber-500/10 to-orange-500/10 border border-amber-500/20",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Memory Cache"}),e.jsx("p",{className:"text-2xl font-bold",children:v?"...":((de=l==null?void 0:l.memoryCacheSize)==null?void 0:de.toLocaleString())||"0"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold mb-3",children:"Usage by Language"}),v?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading..."}):l!=null&&l.byLanguage&&Object.keys(l.byLanguage).length>0?e.jsx("div",{className:"space-y-2",children:Object.entries(l.byLanguage).map(([s,t])=>e.jsxs("div",{className:"flex items-center justify-between p-2 rounded-lg bg-muted/30",children:[e.jsx("span",{className:"text-sm",children:Ie[s]||s}),e.jsxs("div",{className:"flex items-center gap-3 text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:[t.count," requests"]}),e.jsxs(x,{variant:"secondary",children:["$",t.cost.toFixed(4)]})]})]},s))}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No AI dictionary requests yet"})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold mb-3",children:"Daily Usage (Last 30 Days)"}),v?e.jsx("div",{className:"h-48 flex items-center justify-center",children:e.jsx("p",{className:"text-muted-foreground",children:"Loading..."})}):l!=null&&l.dailyStats&&l.dailyStats.length>0?e.jsx(F,{width:"100%",height:180,children:e.jsxs(M,{data:l.dailyStats,children:[e.jsx(P,{strokeDasharray:"3 3",className:"stroke-muted/30"}),e.jsx(A,{dataKey:"date",tickFormatter:s=>new Date(s).toLocaleDateString("en-US",{month:"short",day:"numeric"}
1),fontSize:10,axisLine:!1,tickLine:!1}),e.jsx(L,{fontSize:10,axisLine:!1,tickLine:!1}),e.jsx(T,{labelFormatter:s=>new Date(s).toLocaleDateString(),contentStyle:{backgroundColor:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:"8px"}}),e.jsx(k,{dataKey:"count",fill:"#8b5cf6",name:"Requests",radius:[4,4,0,0]})]})}):e.jsx("div",{className:"h-48 flex items-center justify-center",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"No data yet"})})]})]}),(l==null?void 0:l.recentRequests)&&l.recentRequests.length>0&&e.jsxs("div",{className:"mt-6",children:[e.jsx("h4",{className:"text-sm font-semibold mb-3",children:"Recent Lookups"}),e.jsx("div",{className:"max-h-64 overflow-auto rounded-lg border",children:e.jsxs(ts,{children:[e.jsx(as,{children:e.jsxs(Le,{children:[e.jsx(y,{children:"Word"}),e.jsx(y,{children:"Language"}),e.jsx(y,{className:"text-right",children:"Tokens"}),e.jsx(y,{className:"text-right",children:"Cost"}),e.jsx(y,{className:"text-right",children:"Time"}),e.jsx(y,{children:"Status"})]})}),e.jsx(rs,{children:l.recentRequests.slice(0,20).map(s=>e.jsxs(Le,{children:[e.jsx(w,{className:"font-medium",children:s.word}),e.jsx(w,{children:Ie[s.language]||s.language}),e.jsx(w,{className:"text-right text-muted-foreground",children:s.cachedHit?"-":`${s.inputTokens}+${s.outputTokens}`}),e.jsx(w,{className:"text-right",children:s.cachedHit?"-":`$${s.costUsd.toFixed(5)}`}),e.jsx(w,{className:"text-right text-muted-foreground",children:s.cachedHit?"-":`${s.durationMs}ms`}),e.jsx(w,{children:s.cachedHit?e.jsx(x,{variant:"secondary",children:"Cached"}):s.success?e.jsx(x,{className:"bg-emerald-500/20 text-emerald-600 hover:bg-emerald-500/30",children:"Success"}):e.jsx(x,{variant:"destructive",children:"Failed"})})]},s.id))})]})})]})]}),e.jsxs(c,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx("div",{className:"p-2 rounded-xl bg-gradient-to-br from-rose-500/20 to-pink-500/20",children:e.jsx(Qe,{className:"h-5 w-5 text-rose-500"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold",children:"Keyword Audio Generation"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"OpenAI TTS audio files generated for keyword pronunciations"})]})]}),qe?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx("p",{className:"text-muted-foreground",children:"Loading pronunciation stats..."})}):u?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 mb-6",children:[e.jsxs("div",{className:"p-4 rounded-xl bg-gradient-to-br from-rose-500/10 to-pink-500/10 border border-rose-500/20",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Total Audio Files"}),e.jsx("p",{className:"text-2xl font-bold",children:Object.values(u.byLanguage).reduce((s,t)=>s+t.count,0).toLocaleString()})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-gradient-to-br from-blue-500/10 to-indigo-500/10 border border-blue-500/20",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Total Plays"}),e.jsx("p",{className:"text-2xl font-bold",children:Object.values(u.byLanguage).reduce((s,t)=>s+t.totalPlays,0).toLocaleString()})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-gradient-to-br from-amber-500/10 to-orange-500/10 border border-amber-500/20",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Characters Billed"}),e.jsx("p",{className:"text-2xl font-bold",children:Object.values(u.byLanguage).reduce((s,t)=>s+t.charactersBilled,0).toLocaleString()})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-gradient-to-br from-emerald-500/10 to-teal-500/10 border border-emerald-500/20",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Est. Cost"}),e.jsxs("p",{className:"text-2xl font-bold",children:["$",(Object.values(u.byLanguage).reduce((s,t)=>s+t.charactersBilled,0)/1e3*.015).toFixed(2)]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold mb-3",children:"Audio by Language"}),Object.keys(u.byLanguage).length>0?e.jsx("div",{className:"space-y-2",children:Object.entries(u.byLanguage).map(([s,t])=>e.jsxs("div",{className:"flex items-center justify-between p-2 rounded-lg bg-muted/30",children:[e.jsx("span",{className:"text-sm",children:Ue[s]||s}),e.jsxs("div",{className:"flex items-center gap-3 text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:[t.count," files"]}),e.jsxs(x,{variant:"secondary",children:[t.totalPlays," plays"]})]})]},s))}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No pronunciation audio generated yet"})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold mb-3",children:"Voice Configuration"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between p-2 rounded-lg bg-muted/30",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Provider"}),e.jsx(x,{variant:"secondary",children:u.provider})]}),e.jsxs("div",{className:"flex items-center justify-between p-2 rounded-lg bg-muted/30",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Model"}),e.jsx(x,{variant:"secondary",children:u.model})]}),u.voices&&Object.keys(u.voices).length>0&&e.jsxs("div",{className:"pt-2 border-t border-border/50",children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:"Language Voices"}),e.jsx("div",{className:"space-y-1",children:Object.entries(u.voices).map(([s,t])=>e.jsxs("div",{className:"flex items-center justify-between text-sm p-2 rounded-lg bg-muted/20",children:[e.jsx("span",{className:"text-muted-foreground",children:Ue[s]||s}),e.jsx("code",{className:"text-xs bg-muted px-1.5 py-0.5 rounded",children:t})]},s))})]})]})]})]})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No pronunciation data available"})]}),e.jsxs(c,{className:"p-6",testId:"panel-video-call-pricing",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx("div",{className:"p-2 rounded-xl bg-gradient-to-br from-rose-600/20 to-red-500/20",children:e.jsx(Ae,{className:"h-5 w-5 text-rose-600"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold",children:"AI Tutor Pricing Analytics"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Per-user cost breakdown for subscription pricing (excludes admin users)"})]})]}),Ee?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(j,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):a?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground mb-3",children:"Monthly Usage Projections (Per User)"}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"p-4 rounded-xl bg-gradient-to-br from-emerald-500/10 to-green-500/10 border border-emerald-500/20",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Avg Monthly Minutes"}),e.jsx("p",{className:"text-2xl font-bold text-emerald-600","data-testid":"stat-monthly-minutes-per-user",children:((le=a.avgMonthlyMinutesPerUser)==null?void 0:le.toFixed(1))||"0"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"per user/month"})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-gradient-to-br from-rose-500/10 to-red-500/10 border border-rose-500/20",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Avg Monthly Cost"}),e.jsxs("p",{className:"text-2xl font-bold text-rose-600","data-testid":"stat-monthly-cost-per-user",children:["$",((ie=a.avgMonthlyCostPerUser)==null?void 0:ie.toFixed(2))||"0.00"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"per user/month"})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-gradient-to-br from-blue-500/10 to-indigo-500/10 border border-blue-500/20",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Avg Daily Minutes"}),e.jsx("p",{className:"text-2xl font-bold","data-testid":"stat-daily-minutes-per-user",children:((ne=a.avgMinutesPerDayPerUser)==null?void 0:ne.toFixed(2))||"0"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"per user/day"})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-gradient-to-br from-purple-500/10 to-violet-500/10 border border-purple-500/20",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Cost Per Minute"}),e.jsxs("p",{className:"text-2xl font-bold","data-testid":"stat-cost-per-minute",children:["$",((oe=a.avgCostPerMinute)==null?void 0:oe.toFixed(4))||"0.18"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"actual avg"})]})]})]}),a.pricing&&e.jsxs("div",{className:"mb-6 p-4 rounded-xl bg-gradient-to-br from-amber-500/10 to-orange-500/10 border border-amber-500/20",children:[e.jsx("h3",{className:"text-sm font-medium text-amber-600 dar
1k:text-amber-400 mb-3",children:"Subscription Pricing Calculator"}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"text-center p-3 rounded-lg bg-background/50",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Breakeven"}),e.jsxs("p",{className:"text-xl font-bold text-red-500",children:["$",a.pricing.breakeven.toFixed(2)]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"0% margin"})]}),e.jsxs("div",{className:"text-center p-3 rounded-lg bg-background/50",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Low Margin"}),e.jsxs("p",{className:"text-xl font-bold text-amber-500",children:["$",a.pricing.margin20.toFixed(2)]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"20% margin"})]}),e.jsxs("div",{className:"text-center p-3 rounded-lg bg-background/50",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Standard"}),e.jsxs("p",{className:"text-xl font-bold text-emerald-500",children:["$",a.pricing.margin30.toFixed(2)]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"30% margin"})]}),e.jsxs("div",{className:"text-center p-3 rounded-lg bg-background/50",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Premium"}),e.jsxs("p",{className:"text-xl font-bold text-blue-500",children:["$",a.pricing.margin50.toFixed(2)]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"50% margin"})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-3",children:["Based on avg user spending ",e.jsxs("strong",{children:[((ce=a.avgMonthlyMinutesPerUser)==null?void 0:ce.toFixed(1))||"0"," min/month"]})," at ",e.jsxs("strong",{children:["$",((me=a.avgCostPerMinute)==null?void 0:me.toFixed(4))||"0.18","/min"]})]})]}),a.modeBreakdown&&e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground mb-3",children:"Usage by Mode"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"p-4 rounded-xl bg-muted/30 border border-border/30",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Ae,{className:"h-4 w-4 text-blue-500"}),e.jsx("p",{className:"text-sm font-medium",children:"Video Call (Practice)"})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 text-center",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-semibold",children:a.modeBreakdown.videoCall.sessions}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Sessions"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-semibold",children:a.modeBreakdown.videoCall.minutes}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Minutes"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-semibold",children:a.modeBreakdown.videoCall.users}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Users"})]})]})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-muted/30 border border-border/30",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(R,{className:"h-4 w-4 text-purple-500"}),e.jsx("p",{className:"text-sm font-medium",children:"Discuss with Sage (Articles)"})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 text-center",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-semibold",children:a.modeBreakdown.articleDiscussion.sessions}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Sessions"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-semibold",children:a.modeBreakdown.articleDiscussion.minutes}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Minutes"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-semibold",children:a.modeBreakdown.articleDiscussion.users}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Users"})]})]})]})]})]}),e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground mb-3",children:"Sessions Over Time by Mode"}),_e?e.jsx("div",{className:"h-64 flex items-center justify-center",children:e.jsx(j,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):X.length>0?e.jsx("div",{className:"h-64",children:e.jsx(F,{width:"100%",height:"100%",children:e.jsxs(M,{data:X,margin:{top:10,right:10,left:0,bottom:20},children:[e.jsx(P,{strokeDasharray:"3 3",className:"stroke-border/30"}),e.jsx(A,{dataKey:"date",tick:{fontSize:11},className:"text-muted-foreground",tickFormatter:s=>{if(s.includes("-W"))return`W${s.split("-W")[1]}`;if(s.length===7)return s.slice(5);const t=s.split("-");return t.length===3?`${t[1]}/${t[2]}`:s}}),e.jsx(L,{tick:{fontSize:11},className:"text-muted-foreground"}),e.jsx(T,{content:({active:s,payload:t,label:U})=>{var C,S;return s&&t&&t.length?e.jsxs("div",{className:"bg-popover border rounded-lg shadow-lg p-3 text-sm",children:[e.jsx("p",{className:"font-medium mb-2",children:U}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-3 h-3 rounded-sm bg-blue-500"}),e.jsx("span",{className:"text-muted-foreground",children:"Video Call:"}),e.jsxs("span",{className:"font-medium",children:[((C=t[0])==null?void 0:C.value)||0," sessions"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-3 h-3 rounded-sm bg-purple-500"}),e.jsx("span",{className:"text-muted-foreground",children:"Discuss with Sage:"}),e.jsxs("span",{className:"font-medium",children:[((S=t[1])==null?void 0:S.value)||0," sessions"]})]})]})]}):null}}),e.jsx(Te,{wrapperStyle:{fontSize:"12px"},formatter:s=>s==="videoCallSessions"?"Video Call":"Discuss with Sage"}),e.jsx(k,{dataKey:"videoCallSessions",name:"Video Call",fill:"#3B82F6",stackId:"sessions",radius:[0,0,0,0]}),e.jsx(k,{dataKey:"articleDiscussionSessions",name:"Discuss with Sage",fill:"#8B5CF6",stackId:"sessions",radius:[4,4,0,0]})]})})}):e.jsx("div",{className:"h-64 flex items-center justify-center text-muted-foreground",children:e.jsx("p",{children:"No session data available for this time range"})})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-muted/30 border border-border/30 mb-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Je,{className:"h-5 w-5 text-primary"}),e.jsx("h4",{className:"font-medium",children:"Active Sage Users"})]}),e.jsx("div",{className:"flex gap-1 bg-muted/50 p-1 rounded-lg",children:[7,30,90].map(s=>e.jsxs(we,{size:"sm",variant:m===s?"default":"ghost",onClick:()=>De(s),className:"text-xs px-3","data-testid":`button-active-window-${s}`,children:[s,"d"]},s))})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{className:`p-3 rounded-lg border ${m===7?"bg-primary/10 border-primary/30":"bg-background/50 border-border/30"}`,children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"7 Days (Weekly)"}),e.jsx("p",{className:"text-2xl font-bold","data-testid":"stat-active-users-7d",children:a.activeUsers7Days})]}),e.jsxs("div",{className:`p-3 rounded-lg border ${m===30?"bg-primary/10 border-primary/30":"bg-background/50 border-border/30"}`,children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"30 Days (Monthly)"}),e.jsx("p",{className:"text-2xl font-bold","data-testid":"stat-active-users-30d",children:a.activeUsers30Days})]}),e.jsxs("div",{className:`p-3 rounded-lg border ${m===90?"bg-primary/10 border-primary/30":"bg-background/50 border-border/30"}`,children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"90 Days (Quarterly)"}),e.jsx("p",{className:"text-2xl font-bold","data-testid":"stat-active-users-90d",children:a.activeUsers90Days})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-3",children:["Averages below are calculated using ",e.jsxs("strong",{children:[m,"-day active users (",a.activeUsersForCalc,")"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-4 mb-6",children:[e.jsxs("div",{className:"p-4 rounded-xl bg-muted/30 border border-border/30",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Total Sessions"}),e.jsx("p",{className:"text-xl font-semibold","data-testid":"stat-total-sessions",children:a.totalSessions})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-muted/30 border border-border/30",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Total Minutes"}),e.jsx("p",{className:"text-xl font-semibold","data-testid":"stat-total-minutes",children:a.totalMinutes.toFixed(1)})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-muted/30 border border-border/30",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Total Cost"}),e.jsxs("p",{className:"text-xl font-semibold","data-testid":"stat-total-cost",children:["$",a.totalCost.toFixed(4)]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 mb-6",children:[e.jsxs("div",{className:"p-4 rounded-xl bg-muted/20 border border-border/20",children:[e.jsxs("p",{className:"text-sm text-muted-foreground mb-1",children:["Avg Cost/User (",r,")"]}),e.jsxs("p",{className:"text-lg font-semibold","data-testid":"stat-avg-cost-per-user",children:["$",a.avgCostPerUser.toFixed(4)]})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-muted/20 border border-border/20",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Avg Sessions/User"}),e.jsx("p",{className:"text-lg font-semibold","data-testid":"stat-avg-sessions-per-user",children:a.avgSessionsPerUser.toFixed(1)})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-muted/20 border border-border/20",children:[e.jsxs("p",{className:"text-sm text-muted-foreground mb-1",children:["Avg Minutes/User (",r,")"]}),e.jsx("p",{className:"text-lg font-semibold","data-testid":"stat-avg-minutes-per-user",children:a.avgMinutesPerUser.toFixed(1)})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-muted/20 border border-border/20",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Avg Session Length"}),e.jsxs("p",{className:"text-lg font-semibold","data-testid":"stat-avg-session-length",children:[((xe=a.avgSessionLength)==null?void 0:xe.toFixed(1))||"0"," min"]})]})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-blue-500/10 border border-blue-500/20",children:[e.jsx("h4",{className:"text-sm font-medium text-blue-600 dar
1k:text-blue-400 mb-2",children:"Understanding These Metrics"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[e.jsx("strong",{children:"Active Sage Users"}),': Users who have used Sage at least once within the selected window (7/30/90 days). This defines who is considered an "active" Sage user.',e.jsx("br",{}),e.jsx("strong",{children:"Per-user averages"}),": Calculated by dividing totals by the ",m,"-day active users count (",a.activeUsersForCalc," users).",e.jsx("br",{}),e.jsx("strong",{children:"Monthly projections"}),": Based on ",a.numDays<1?`${(a.numDays*24).toFixed(1)} hours`:`${a.numDays.toFixed(1)} days`," of data, normalized to 30-day estimates.",e.jsx("br",{}),e.jsx("strong",{children:"Breakeven pricing"}),": Minimum subscription add-on price to cover AI costs with specified margins."]})]})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No video call usage data yet"})]}),e.jsxs(c,{className:"p-6",testId:"panel-sage-assist-analytics",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx("div",{className:"p-2 rounded-xl bg-gradient-to-br from-emerald-600/20 to-green-500/20",children:e.jsx(R,{className:"h-5 w-5 text-emerald-600"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold",children:"Sage Assist Analytics"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Sentence assists, follow-up chats, and word assists â excludes admin users"})]})]}),Ge?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(j,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):n?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground mb-3",children:"Key Usage Metrics"}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"p-4 rounded-xl bg-gradient-to-br from-emerald-500/10 to-green-500/10 border border-emerald-500/20",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Avg Sentence Assists/User"}),e.jsx("p",{className:"text-2xl font-bold text-emerald-600","data-testid":"stat-sage-avg-assists-per-user",children:((ue=n.avgAssistsPerUser)==null?void 0:ue.toFixed(1))||"0"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"translations per user"})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-gradient-to-br from-blue-500/10 to-indigo-500/10 border border-blue-500/20",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Avg Chats per Sentence"}),e.jsx("p",{className:"text-2xl font-bold text-blue-600","data-testid":"stat-sage-avg-msgs-per-assist",children:((he=n.avgMsgsPerAssist)==null?void 0:he.toFixed(2))||"0"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"follow-up questions"})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-gradient-to-br from-rose-500/10 to-red-500/10 border border-rose-500/20",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Avg Cost/Sentence"}),e.jsxs("p",{className:"text-2xl font-bold text-rose-600","data-testid":"stat-sage-avg-cost-per-assist",children:["$",((ge=n.avgCostPerAssist)==null?void 0:ge.toFixed(4))||"0.0000"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"per translation"})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-gradient-to-br from-purple-500/10 to-violet-500/10 border border-purple-500/20",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Avg Sentences/User/Mo"}),e.jsx("p",{className:"text-2xl font-bold text-purple-600","data-testid":"stat-sage-avg-assists-per-user-month",children:((pe=n.avgAssistsPerUserPerMonth)==null?void 0:pe.toFixed(1))||"0"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"monthly rate"})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-gradient-to-br from-amber-500/10 to-orange-500/10 border border-amber-500/20",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Avg Sentences/User/Day"}),e.jsx("p",{className:"text-2xl font-bold text-amber-600","data-testid":"stat-sage-avg-assists-per-user-day",children:((be=n.avgAssistsPerUserPerDay)==null?void 0:be.toFixed(2))||"0"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"daily rate"})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-gradient-to-br from-teal-500/10 to-cyan-500/10 border border-teal-500/20",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Avg Cost/User/Month"}),e.jsxs("p",{className:"text-2xl font-bold text-teal-600","data-testid":"stat-sage-avg-cost-per-user-month",children:["$",((je=n.avgCostPerUserPerMonth)==null?void 0:je.toFixed(4))||"0.0000"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"monthly cost"})]})]})]}),n.breakdown&&e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground mb-3",children:"Usage Breakdown"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"p-4 rounded-xl bg-muted/30 border border-border/30",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Ye,{className:"h-4 w-4 text-emerald-500"}),e.jsx("p",{className:"text-sm font-medium",children:"Translations"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-center",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-semibold","data-testid":"stat-sage-translate-count",children:n.breakdown.translate.count}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Requests"})]}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-lg font-semibold","data-testid":"stat-sage-translate-cost",children:["$",Number(n.breakdown.translate.cost).toFixed(4)]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Cost"})]})]})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-muted/30 border border-border/30",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Ze,{className:"h-4 w-4 text-blue-500"}),e.jsx("p",{className:"text-sm font-medium",children:"Follow-up Chats"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-center",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-semibold","data-testid":"stat-sage-chat-count",children:n.breakdown.chat.count}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Messages"})]}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-lg font-semibold","data-testid":"stat-sage-chat-cost",children:["$",Number(n.breakdown.chat.cost).toFixed(4)]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Cost"})]})]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-4 mb-6",children:[e.jsxs("div",{className:"p-4 rounded-xl bg-muted/30 border border-border/30",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Sentence Assists"}),e.jsx("p",{className:"text-xl font-semibold","data-testid":"stat-sage-total-assists",children:n.totalAssists})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-muted/30 border border-border/30",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Chat Messages"}),e.jsx("p",{className:"text-xl font-semibold","data-testid":"stat-sage-total-chats",children:n.totalChatMessages})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-muted/30 border border-border/30",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Word Assists"}),e.jsx("p",{className:"text-xl font-semibold","data-testid":"stat-sage-total-word-insights",children:n.totalWordInsights??0})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-muted/30 border border-border/30",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Unique Users"}),e.jsx("p",{className:"text-xl font-semibold","data-testid":"stat-sage-unique-users",children:n.uniqueUsers})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-muted/30 border border-border/30",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Total Cost"}),e.jsxs("p",{className:"text-xl font-semibold","data-testid":"stat-sage-total-cost",children:["$",n.totalCost.toFixed(4)]})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-muted/30 border border-border/30",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Word Assists Cost"}),e.jsxs("p",{className:"text-xl font-semibold","data-testid":"stat-sage-word-insights-cost",children:["$",(((Ne=(fe=n.breakdown)==null?void 0:fe.wordInsight)==null?void 0:Ne.cost)??0).toFixed(4)]})]})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-emerald-500/10 border border-emerald-500/20",children:[e.jsx("h4",{className:"text-sm font-medium text-emerald-600 dark:text-emerald-400 mb-2",children:"Understanding Sage Assist Metrics"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[e.jsx("strong",{children:"Sentence Assists"}),": User taps the translate icon on a sentence in an article. Each translation is one assist.",e.jsx("br",{}),e.jsx("strong",{children:"Chat Messages"}),": Follow-up questions users ask after translating (grammar, vocabulary, context).",e.jsx("br",{}),e.jsx("strong",{children:"Word Assists"}
1),": User taps a word in the dictionary panel to get an in-context word explanation. Tracked separately from sentence assists.",e.jsx("br",{}),e.jsx("strong",{children:"Avg Msgs per Assist"}),": How many follow-up chat messages per sentence translation.",e.jsx("br",{}),e.jsx("strong",{children:"Data range"}),": ",n.numDays<1?`${(n.numDays*24).toFixed(1)} hours`:`${n.numDays.toFixed(1)} days`," (",n.range,")"]})]})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No Sage Assist usage data yet"})]}),e.jsxs(c,{className:"p-6",testId:"panel-sage-welcome-analytics",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx("div",{className:"p-2 rounded-xl bg-gradient-to-br from-pink-600/20 to-rose-500/20",children:e.jsx(es,{className:"h-5 w-5 text-pink-600"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold",children:"Sage Welcome Popup Analytics"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Tracking welcome call popup views, accepts, and declines"})]})]}),Oe?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(j,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):o?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground mb-3",children:"Conversion Rates"}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"p-4 rounded-xl bg-gradient-to-br from-pink-500/10 to-rose-500/10 border border-pink-500/20",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Total Views"}),e.jsx("p",{className:"text-2xl font-bold text-pink-600","data-testid":"stat-sage-welcome-views",children:o.totalViews}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"popup impressions"})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-gradient-to-br from-emerald-500/10 to-green-500/10 border border-emerald-500/20",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Answer Rate"}),e.jsxs("p",{className:"text-2xl font-bold text-emerald-600","data-testid":"stat-sage-welcome-answer-rate",children:[(o.answerRate*100).toFixed(1),"%"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"responded to popup"})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-gradient-to-br from-blue-500/10 to-indigo-500/10 border border-blue-500/20",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Accept Rate"}),e.jsxs("p",{className:"text-2xl font-bold text-blue-600","data-testid":"stat-sage-welcome-accept-rate",children:[(o.acceptRate*100).toFixed(1),"%"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"answered call"})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-gradient-to-br from-rose-500/10 to-red-500/10 border border-rose-500/20",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Decline Rate"}),e.jsxs("p",{className:"text-2xl font-bold text-rose-600","data-testid":"stat-sage-welcome-decline-rate",children:[(o.declineRate*100).toFixed(1),"%"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"declined call"})]})]})]}),e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground mb-3",children:"Event Breakdown"}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"p-4 rounded-xl bg-muted/30 border border-border/30",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(ke,{className:"h-4 w-4 text-emerald-500"}),e.jsx("p",{className:"text-sm font-medium",children:"Accepts"})]}),e.jsx("p",{className:"text-xl font-semibold","data-testid":"stat-sage-welcome-accepts",children:o.totalAccepts})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-muted/30 border border-border/30",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Me,{className:"h-4 w-4 text-rose-500"}),e.jsx("p",{className:"text-sm font-medium",children:"Declines"})]}),e.jsx("p",{className:"text-xl font-semibold","data-testid":"stat-sage-welcome-declines",children:o.totalDeclines})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-muted/30 border border-border/30",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(ss,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("p",{className:"text-sm font-medium",children:"Dismissed"})]}),e.jsx("p",{className:"text-xl font-semibold","data-testid":"stat-sage-welcome-dismisses",children:o.totalDismisses})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-muted/30 border border-border/30",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Fe,{className:"h-4 w-4 text-blue-500"}),e.jsx("p",{className:"text-sm font-medium",children:"Avg Call Duration"})]}),e.jsx("p",{className:"text-xl font-semibold","data-testid":"stat-sage-welcome-avg-duration",children:o.avgCallDurationSeconds>0?`${Math.floor(o.avgCallDurationSeconds/60)}:${String(Math.floor(o.avgCallDurationSeconds%60)).padStart(2,"0")}`:"-"})]})]})]}),Object.keys(o.byLanguage||{}).length>0&&e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground mb-3",children:"By Language"}
1),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-3",children:Object.entries(o.byLanguage).map(([s,t])=>e.jsxs("div",{className:"p-3 rounded-xl bg-muted/30 border border-border/30",children:[e.jsx("p",{className:"text-sm font-medium capitalize mb-2",children:s}),e.jsxs("div",{className:"space-y-1 text-xs",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Views:"}),e.jsx("span",{children:t.views})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Accepts:"}),e.jsx("span",{className:"text-emerald-600",children:t.accepts})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Declines:"}),e.jsx("span",{className:"text-rose-600",children:t.declines})]})]})]},s))})]}),Object.keys(o.byLevel||{}).length>0&&e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground mb-3",children:"By CEFR Level"}),e.jsx("div",{className:"grid grid-cols-3 md:grid-cols-6 gap-3",children:Object.entries(o.byLevel).map(([s,t])=>e.jsxs("div",{className:"p-3 rounded-xl bg-muted/30 border border-border/30",children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:s}),e.jsxs("div",{className:"space-y-1 text-xs",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Views:"}),e.jsx("span",{children:t.views})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Accepts:"}),e.jsx("span",{className:"text-emerald-600",children:t.accepts})]})]})]},s))})]}),Object.keys(o.byProvider||{}).length>0&&e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground mb-3",children:"By AI Provider"}),e.jsx("div",{className:"grid grid-cols-2 gap-4",children:Object.entries(o.byProvider).map(([s,t])=>e.jsxs("div",{className:"p-4 rounded-xl bg-muted/30 border border-border/30",children:[e.jsx("p",{className:"text-sm font-medium capitalize mb-2",children:s}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 text-center",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-semibold",children:t.views}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Views"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-semibold text-emerald-600",children:t.accepts}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Accepts"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-semibold text-rose-600",children:t.declines}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Declines"})]})]})]},s))})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-pink-500/10 border border-pink-500/20",children:[e.jsx("h4",{className:"text-sm font-medium text-pink-600 dark:text-pink-400 mb-2",children:"Understanding Sage Welcome Metrics"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[e.jsx("strong",{children:"Answer Rate"}),": Percentage of users who responded (accept or decline) vs dismissed/ignored.",e.jsx("br",{}),e.jsx("strong",{children:"Accept Rate"}),": Percentage of views that resulted in accepting the call.",e.jsx("br",{}),e.jsx("strong",{children:"Decline Rate"}),": Percentage of views where users explicitly clicked decline.",e.jsx("br",{}),e.jsx("strong",{children:"Data range"}),": ",o.range," (",o.rangeStart," to ",o.rangeEnd,")"]})]})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No Sage Welcome popup data yet"})]})]})})}export{Cs 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.