1import{j as e}from"./react-vendor-DUhHROXo.js";import{P as E}from"./PortalLayout-BUxGSFei.js";import{C as n,b as l,c as o,a as d,d as c}from"./card-9IoFUltb.js";import{T as k,a as F,b as x,c as p}from"./tabs-B9G-WuXr.js";import{J as h,p as N,a6 as g,aM as K,ab as v,aa as B}from"./index-BLtzf0SR.js";import{s as j}from"./client-DTel1CZI.js";import{U}from"./users-CIwSfVhi.js";import{R as w,X as V,Y as $,T as b,y as z}from"./generateCategoricalChart-DgLZc9AV.js";import{L as I,a as X}from"./LineChart-kThqkfAO.js";import{C as Y}from"./CartesianGrid-Xczk_Kbb.js";import{P as G,a as J}from"./PieChart-CXHfFAt0.js";import{f as C}from"./format-DGzj7MEM.js";import{s as _}from"./subDays-Cc0kVtWU.js";import"./AdminLayout-4AAuHeAU.js";import"./router-vendor-Dz9PdDzH.js";import"./NavLink-CsyG-eHO.js";import"./badge-BsE4KYIf.js";import"./scroll-area-BdyOmc9o.js";import"./index-BdQq_4o_.js";import"./collapsible-BAD8kbtc.js";import"./index-CMI-ZfmW.js";import"./arrow-left-CRb8P6iH.js";import"./globe-CQ83QW2m.js";import"./activity-CwFToTs3.js";import"./list-todo-BR3jv1RJ.js";import"./calendar-BDETTnfZ.js";import"./users-round-CCw5yxW7.js";import"./radio-BQgeDg5T.js";import"./clapperboard-BvstouST.js";import"./clipboard-list-CQJ-vJ2y.js";import"./image-arBWrt3y.js";import"./folder-open-CIWhCFhy.js";import"./pencil-C2cyk8cg.js";import"./message-square-BDdDilNB.js";import"./ticket-l9bl0kcm.js";import"./megaphone-DpQsxotQ.js";import"./package-DKB1lvtO.js";import"./circle-user-BeB3uaA1.js";import"./folder-kanban-B8jlMC6s.js";import"./settings-Baim_Eei.js";import"./briefcase-CdSp4ViD.js";import"./chart-line-ohAz7u_s.js";import"./HostOwnerLayout-PM2-LrXf.js";import"./layers-CvbkNa7J.js";import"./dollar-sign-D3lTBfQm.js";import"./index-f8ec2rGh.js";import"./index-Dh4i1-J3.js";import"./en-US-Bfz1jvxT.js";import"./differenceInCalendarDays-D4nmWE3G.js";import"./getTimezoneOffsetInMilliseconds-DsfBWtEI.js";import"./addDays-BhORGywK.js";const L=["hsl(var(--primary))","hsl(var(--accent))","#10B981","#F59E0B","#8B5CF6"];function Ye(){const{data:a}=h({queryKey:["content-analytics"],queryFn:async()=>{const s=_(new Date,30),{data:t,error:i}=await j.from("content_analytics").select("*").gte("created_at",s.toISOString()).order("created_at",{ascending:!1});if(i)throw i;return t}}),{data:r}=h({queryKey:["listening-history-analytics"],queryFn:async()=>{const s=_(new Date,30),{data:t,error:i}=await j.from("listening_history").select("*, podcast_episodes(title)").gte("listened_at",s.toISOString()).order("listened_at",{ascending:!1});if(i)throw i;return t}});h({queryKey:["episodes-for-analytics"],queryFn:async()=>{const{data:s,error:t}=await j.from("podcast_episodes").select("*").eq("is_published",!0).order("published_at",{ascending:!1}).limit(10);if(t)throw t;return s}});const T=(a==null?void 0:a.filter(s=>s.event_type==="play").length)||0,D=(a==null?void 0:a.filter(s=>s.event_type==="view").length)||0,P=new Set(r==null?void 0:r.map(s=>s.user_id)).size,q=(r==null?void 0:r.filter(s=>s.completed).length)||0,M=r!=null&&r.length?Math.round(q/r.length*100):0,O=a==null?void 0:a.filter(s=>s.event_type==="play").reduce((s,t)=>{const i=C(new Date(t.created_at),"MMM d");return s[i]=(s[i]||0)+1,s},{}),u=Object.entries(O||{}).map(([s,t])=>({date:s,plays:t})).reverse().slice(-14),R=a==null?void 0:a.reduce((s,t)=>(s[t.content_type]=(s[t.content_type]||0)+1,s),{}),m=Object.entries(R||{}).map(([s,t])=>({name:s,value:t})),S=r==null?void 0:r.reduce((s,t)=>{var y;const i=((y=t.podcast_episodes)==null?void 0:y.title)||"Unknown";return s[i]=(s[i]||0)+1,s},{}),f=Object.entries(S||{}).map(([s,t])=>({title:s,count:t})).sort((s,t)=>t.count-s.count).slice(0,5);return e.jsx(E,{children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-display font-bold",children:"Analytics"}),e.jsx("p",{className:"text-muted-foreground",children:"Content performance and engagement metrics"})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-4",children:[e.jsxs(n,{children:[e.jsxs(l,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(o,{className:"text-sm font-medium",children:"Total Plays"}),e.jsx(N,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(d,{children:[e.jsx("div",{className:"text-2xl font-bold",children:T.toLocaleStr
1ing()}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Last 30 days"})]})]}),e.jsxs(n,{children:[e.jsxs(l,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(o,{className:"text-sm font-medium",children:"Content Views"}),e.jsx(g,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(d,{children:[e.jsx("div",{className:"text-2xl font-bold",children:D.toLocaleString()}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Last 30 days"})]})]}),e.jsxs(n,{children:[e.jsxs(l,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(o,{className:"text-sm font-medium",children:"Unique Listeners"}),e.jsx(U,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(d,{children:[e.jsx("div",{className:"text-2xl font-bold",children:P}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Last 30 days"})]})]}),e.jsxs(n,{children:[e.jsxs(l,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(o,{className:"text-sm font-medium",children:"Completion Rate"}),e.jsx(K,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(d,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:[M,"%"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Episodes finished"})]})]})]}),e.jsxs(k,{defaultValue:"overview",children:[e.jsxs(F,{children:[e.jsx(x,{value:"overview",children:"Overview"}),e.jsx(x,{value:"podcasts",children:"Podcasts"}),e.jsx(x,{value:"content",children:"Content"})]}),e.jsx(p,{value:"overview",className:"space-y-6",children:e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsxs(n,{children:[e.jsxs(l,{children:[e.jsx(o,{children:"Plays Over Time"}),e.jsx(c,{children:"Daily content plays"})]}),e.jsx(d,{children:u.length>0?e.jsx(w,{width:"100%",height:300,children:e.jsxs(I,{data:u,children:[e.jsx(Y,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(V,{dataKey:"date",className:"text-xs"}),e.jsx($,{className:"text-xs"}),e.jsx(b,{}),e.jsx(X,{type:"monotone",dataKey:"plays",stroke:"hsl(var(--primary))",strokeWidth:2,dot:!1})]})}):e.jsx("div",{className:"h-[300px] flex items-center justify-center text-muted-foreground",children:"No data available"})})]}),e.jsxs(n,{children:[e.jsxs(l,{children:[e.jsx(o,{children:"Content Type Distribution"}),e.jsx(c,{children:"Engagement by content type"})]}),e.jsx(d,{children:m.length>0?e.jsx(w,{width:"100%",height:300,children:e.jsxs(G,{children:[e.jsx(J,{data:m,cx:"50%",cy:"50%",labelLine:!1,outerRadius:100,fill:"#8884d8",dataKey:"value",label:({name:s,percent:t})=>`${s} ${(t*100).toFixed(0)}%`,children:m.map((s,t)=>e.jsx(z,{fill:L[t%L.length]},`cell-${t}`))}),e.jsx(b,{})]})}):e.jsx("div",{className:"h-[300px] flex items-center justify-center text-muted-foreground",children:"No data available"})})]})]})}),e.jsx(p,{value:"podcasts",className:"space-y-6",children:e.jsxs(n,{children:[e.jsxs(l,{children:[e.jsx(o,{children:"Top Episodes"}),e.jsx(c,{children:"Most listened episodes"})]}),e.jsx(d,{children:f.length>0?e.jsx("div",{className:"space-y-4",children:f.map((s,t)=>e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("span",{className:"text-2xl font-bold text-muted-foreground w-8",children:t+1}),e.jsx("div",{className:"flex-1",children:e.jsx("p",{className:"font-medium",children:s.title})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(v,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"font-semibold",children:s.count})]})]},s.title))}):e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(v,{className:"h-12 w-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"No listening data yet"})]})})]})}),e.jsx(p,{value:"content",className:"space-y-6",children:e.jsxs(n,{children:[e.jsxs(l,{children:[e.jsx(o,{children:"Recent Activity"}),e.jsx(c,{children:"Latest content engagement events"})]}),e.jsx(d,{children:a&&a.length>0?e.jsx("div",{className:"space-y-3",children:a.slice(0,20).map(s=>e.jsxs("div",{className:"flex items-center gap-3 text-sm",children:[e.jsx("div",{className:"p-2 rounded-full bg-muted",children:s.event_type==="play"?e.jsx(N,{className:"h-3 w-3"}):e.jsx(g,{className:"h-3 w-3"})}),e.jsx("span",{className:"capitalize font-medium",children:s.event_type}),e.jsx("span",{className:"text-muted-foreground",children:s.content_type}),e.jsx("span",{className:"text-muted-foreground ml-auto",children:C(new Date(s.created_at),"MMM d, h:mm a")})]},s.id))}):e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(B,{className:"h-12 w-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"No activity data yet"})]})})]})})]})]})})}export{Ye 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.