1import{j as e,r as s}from"./vendor-react-BH6F5oQJ.js";import{A as a,P as t,a as r,b as l}from"./AdminLayout-CKCESQT6.js";import{C as n,M as i,N as c,m as d,B as o,s as x,a1 as m,H as u,f as h,S as j}from"./index-dRqPaCFl.js";import{c as p,v as g,u as v,a as b,b as N,d as f,e as y,f as w,g as _,h as D,p as S,i as k}from"./analyticsMerge-CGnw3nXh.js";import{ac as C,E as L,ad as A,H as V,ae as M,a as T,U as P,q as R,af as E,n as $,a5 as q,t as z,X as H,ag as I,ah as K,ai as W,aj as F,B,C as U,a3 as J,a2 as O}from"./vendor-icons-CaI5__By.js";import{S as G,a as X,b as Y,c as Q,d as Z}from"./select-DsVkFSYt.js";import{T as ee,a as se,b as ae,c as te}from"./tabs-Bc5GG4D6.js";import{C as re}from"./calendar-C9CRNsnp.js";import{a as le}from"./vendor-query-CC4VRGyP.js";import{f as ne}from"./format-hXGQLsWs.js";import{R as ie,L as ce,C as de,X as oe,Y as xe,T as me,c as ue,a as he,B as je,b as pe}from"./BarChart-Cif1pj26.js";import"./vendor-ui-B4WC06Sp.js";import"./separator-KtQ1mSuG.js";import"./index-CCdGLatk.js";import"./Combination-DzDAyqvK.js";import"./vendor-supabase-COwyE4EW.js";import"./index-B3FPD4RS.js";import"./en-US-DUAJ-5Wt.js";import"./index-D5Ei2fSx.js";import"./index-DE-eAtGG.js";const ge={old_deploy:"Production is using an outdated /api/vercel-stats stub. Deploy the latest api/vercel-stats.ts.",missing_env:"Vercel env vars are not set. Add VERCEL_API_TOKEN in the Vercel Dashboard (do not override VERCEL_PROJECT_ID).",api_error:"Vercel API request failed. Check your token, project ID, and that Web Analytics is enabled.",unknown:"Vercel analytics is unavailable."};function ve({vercelStats:s,vercelLoading:a,supabaseLoading:t,supabaseHasData:r}){const l=p(s),x="ok"===l,m=g(s),u=x&&!m;return e.jsxs(n,{className:"mb-6 border-border/40",children:[e.jsx(i,{className:"border-b border-border/40 pb-3",children:e.jsx(c,{className:"text-base font-medium",children:"Data sources"})}),e.jsxs(d,{className:"grid gap-4 pt-4 md:grid-cols-2",children:[e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border border-border/40 p-4",children:[e.jsx(C,{className:"mt-0.5 h-5 w-5 shrink-0 text-primary"}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:"Vercel Web Analytics"}),a?e.jsx(o,{variant:"outline",children:"Loadingâ¦"}):m?e.jsx(o,{className:"bg-green-600 hover:bg-green-600",children:"Active"}):u?e.jsx(o,{variant:"secondary",children:"Connected · no traffic"}):e.jsx(o,{variant:"destructive",children:"Unavailable"})]}),m?e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Last ",(null==s?void 0:s.rangeDays)??30," days of traffic, bounce rate, countries, and devices."]}):u?e.jsx("p",{className:"text-xs text-muted-foreground",children:"Connected, but no traffic recorded for this window. Showing Supabase analytics instead."}):"loading"!==l&&"ok"!==l?e.jsxs("p",{className:"text-xs text-muted-foreground",children:[ge["unknown"===l?"unknown":l],(null==s?void 0:s.error)?` (${s.error})`:""]}):null,e.jsxs("a",{href:"https://vercel.com/dashboard",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs font-medium text-primary hover:underline",children:["Vercel Dashboard ",e.jsx(L,{className:"h-3 w-3"})]})]})]}),e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border border-border/40 p-4",children:[e.jsx(A,{className:"mt-0.5 h-5 w-5 shrink-0 text-primary"}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:"Supabase analytics_events"}),t?e.jsx(o,{variant:"outline",children:"Loadingâ¦"}):r?e.jsx(o,{className:"bg-green-600 hover:bg-green-600",children:"Active"}):e.jsx(o,{variant:"secondary",children:"No data"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"trackPageView + filters (country, region, device). Primary fallback in production."}),!r&&!t&&e.jsxs("p",{className:"flex items-center gap-1 text-xs text-amber-600 dar
1k:text-amber-500",children:[e.jsx(V,{className:"h-3 w-3"}),"No events found for the selected period."]}),r&&e.jsxs("p",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx(M,{className:"h-3 w-3 text-green-600"}),"RPC: get_analytics_summary, get_traffic_sources, get_device_breakdown"]})]})]})]})]})}function be({source:s}){return e.jsx(o,{variant:"outline",className:"text-[10px] font-normal",children:"vercel"===s?"Vercel":"Supabase"})}const Ne=()=>{var p,C,L,A,V,M,ge,Ne,fe;const[ye,we]=s.useState({}),[_e,De]=s.useState([]),[Se,ke]=s.useState(0),[Ce,Le]=s.useState("30days"),[Ae,Ve]=s.useState(),[Me,Te]=s.useState(),Pe=s.useMemo(()=>{if("7days"===Ce)return 7;if("3months"===Ce)return 90;if("custom"===Ce&&Ae&&Me){const e=Math.ceil((Me.getTime()-Ae.getTime())/864e5);return Number.isFinite(e)&&e>0?e:30}return 30},[Ce,Ae,Me]),{data:Re,isLoading:Ee}=v(Pe),{data:$e,isLoading:qe}=b(ye),{data:ze,isLoading:He}=N(),{data:Ie,isLoading:Ke}=f(ye),{data:We,isLoading:Fe}=y(ye),{data:Be,isLoading:Ue}=w(ye),{data:Je}=_(),{data:Oe,isLoading:Ge}=D(ye),{data:Xe,isLoading:Ye}=le({queryKey:["article-stats"],queryFn:async()=>{const{data:e,error:s}=await x.from("articles").select("id, view_count, created_at, template_settings, content, published_at").eq("status","published").order("created_at",{ascending:!1});if(s)throw s;if(!e||0===e.length)return{totalViews:0,averageReadingTime:"0 min read",topCategories:[],weeklyTrends:[],totalArticles:0};const a=e.reduce((e,s)=>e+(s.view_count||0),0),t=[];e.forEach(e=>{const s=e.template_settings,a=null==s?void 0:s.readTime;if(a){const e=a.match(/(\d+)/);e&&t.push(parseInt(e[1]))}else{const s=e.content,a="string"==typeof s?s:(null==s?void 0:s.text)||"",r=m(a).match(/(\d+)/);r&&t.push(parseInt(r[1]))}});const r=`${t.length>0?Math.round(t.reduce((e,s)=>e+s,0)/t.length):0} min read`,l=new Map;e.forEach(e=>{const s=e.template_settings,a=null==s?void 0:s.category;(Array.isArray(a)?a:a?[a]:["Uncategorized"]).forEach(s=>{const a=l.get(s)||{count:0,views:0};l.set(s,{count:a.count+1,views:a.views+(e.view_count||0)})})});const n=Array.from(l.entries()).map(([e,s])=>({category:e,count:s.count,views:s.views})).sort((e,s)=>s.views-e.views).slice(0,5),i=new Date,c=[];for(let d=7;d>=0;d--){const s=new Date(i);s.setDate(i.getDate()-(7*d+7));const a=new Date(i);a.setDate(i.getDate()-7*d);const t=e.filter(e=>{const t=new Date(e.published_at||e.created_at);return t>=s&&t<a}),r=t.reduce((e,s)=>e+(s.view_count||0),0),l=`${["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][s.getMonth()]} ${s.getDate()}-${a.getDate()}`;c.push({week:l,articles:t.length,views:r})}return{totalViews:a,averageReadingTime:r,topCategories:n,weeklyTrends:c,totalArticles:e.length}}}),Qe=g(Re);s.useEffect(()=>{const e=x.channel("analytics-realtime-admin").on("postgres_changes",{event:"INSERT",schema:"public",table:"analytics_events"},e=>{ke(e=>e+1),De(s=>[{id:String(e.new.id),event_type:String(e.new.event_type),page_path:String(e.new.page_path??""),timestamp:String(e.new.created_at)},...s].slice(0,15))}).subscribe();return()=>{x.removeChannel(e)}},[]),s.useEffect(()=>{let e,s=new Date;"7days"===Ce?(e=new Date,e.setDate(e.getDate()-7)):"30days"===Ce?(e=new Date,e.setDate(e.getDate()-30)):"3months"===Ce?(e=new Date,e.setMonth(e.getMonth()-3)):"custom"===Ce&&Ae&&Me&&(e=new Date(Ae),e.setHours(0,0,0,0),s=new Date(Me),s.setHours(23,59,59,999)),we(a=>({...a,startDate:e,endDate:s}))},[Ce,Ae,Me]);const Ze=ye.country||ye.region||ye.gender||ye.deviceType,es=()=>"7days"===Ce?"Last 7 days":"30days"===Ce?"Last 30 days":"3months"===Ce?"Last 3 months":"custom"===Ce&&Ae&&Me?`${ne(Ae,"MMM dd, yyyy")} â ${ne(Me,"MMM dd, yyyy")}`:"Last 30 days",ss=S(null==Re?void 0:Re.visitors,null==$e?void 0:$e.unique_visitors,Qe),as=S(null==Re?void 0:Re.pageviews,null==$e?void 0:$e.total_page_views,Qe),ts=((null==$e?void 0:$e.total_page_views)??0)>0||((null==$e?void 0:$e.unique_visitors)??0)>0||((null==Oe?void 0:Oe.length)??0)>0,rs=s.useMemo(()=>{var e;return Qe&&(null==(e=null==Re?void 0:Re.trend)?void 0:e.length)?Re.trend.map(e=>({date:new Date(e.date).toLocaleDateString("en-US",{month:"short",day:"numeric"}),visitors:e.visitors,pageviews:e.pageviews,source:"vercel"})):(null==Oe?void 0:Oe.length)?Oe.map(e=>({...e,source:"supabase"})):[]},[Qe,Re,Oe]),ls=ss.value>0?(as.value/ss.value).toFixed(1):"0",ns=Ee||qe;return e.jsxs(a,{children:[e.jsxs(u,{children:[e.jsx("meta",{name:"robots",content:"noindex,nofollow"}),e.jsx("title",{children:"Analytics - Admin - Delphi Global Research Center"})]}),e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"mb-6 flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"mb-2 font-heading text-4xl font-bold bg-gradient-to-r from-primary to-primary/60 bg-clip-text text-transparent",children:"Analytics"}),e.jsxs("p",{className:"text-muted-foreground",children:["Vercel + Supabase unified panel · ",es()]})]}),e.jsx(n,{className:"w-auto border-border/40",children:e.jsxs(d,{className:"flex flex-wrap items-center gap-3 p-4",children:[e.jsxs(G,{value:Ce,onValueChange:e=>Le(e),children:[e.jsx(X,{className:"w-[160px]",children:e.jsx(Y,{})}),e.jsxs(Q,{children:[e.jsx(Z,{value:"7days",children:"Last 7 days"}),e.jsx(Z,{value:"30days",children:"Last 30 days"}),e.jsx(Z,{value:"3months",children:"Last 3 months"}),e.jsx(Z,{value:"custom",children:"Custom"})]})]}),"custom"===Ce&&e.jsxs(e.Fragment,{children:[e.jsxs(t,{children:[e.jsx(r,{asChild:!0,children:e.jsxs(h,{variant:"outline",className:"w-[140px] justify-start text-left font-normal",children:[e.jsx(T,{className:"mr-2 h-4 w-4"}),Ae?ne(Ae,"PP"):"Start"]})}),e.jsx(l,{className:"w-auto p-0",align:"start",children:e.jsx(re,{mode:"single",selected:Ae,onSelect:Ve,disabled:e=>e>new Date||Me&&e>Me})})]}),e.jsxs(t,{children:[e.jsx(r,{asChild:!0,children:e.jsxs(h,{variant:"outline",className:"w-[140px] justify-start text-left font-normal",children:[e.jsx(T,{className:"mr-2 h-4 w-4"}),Me?ne(Me,"PP"):"End"]})}),e.jsx(l,{className:"w-auto p-0",align:"start",children:e.jsx(re,{mode:"single",selected:Me,onSelect:Te,disabled:e=>e>new Date||Ae&&e<Ae})})]})]})]})})]}),e.jsx(ve,{vercelStats:Re,vercelLoading:Ee,supabaseLoading:qe||Ge,supabaseHasData:ts}),e.jsx("div",{className:"mb-6 grid gap-4 sm:grid-cols-2 lg:grid-cols-4",children:[{label:"Visitors",value:ss.value,source:ss.source,icon:P},{label:"Page views",value:as.value,source:as.source,icon:R},{label:"Bounce rate",value:Qe&&null!=(null==Re?void 0:Re.bounceRate)?`${Re.bounceRate}%`:"â",source:Qe?"vercel":null,icon:E},{label:"Pages / visitor",value:`${ls}`,source:as.source,icon:$}].map(s=>{const a=s.icon;return e.jsxs(n,{className:"border-border/40",children:[e.jsxs(i,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(c,{className:"text-sm font-medium text-muted-foreground",children:s.label}),e.jsx(a,{className:"h-4 w-4 text-primary"})]}),e.jsx(d,{children:ns?e.jsx(j,{className:"h-9 w-20"}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-3xl font-bold",children:"number"==typeof s.value?k(s.value):s.value}),s.source&&e.jsx(be,{source:s.source})]})})]},s.label)})}),e.jsxs(ee,{defaultValue:"overview",className:"space-y-6",children:[e.jsxs(se,{className:"flex h-auto flex-wrap gap-1",children:[e.jsx(ae,{value:"overview",children:"Overview"}),e.jsx(ae,{value:"traffic",children:"Traffic"}),e.jsx(ae,{value:"audience",children:"Audience"}),e.jsx(ae,{value:"content",children:"Content"}),e.jsx(ae,{value:"live",children:"Live"})]}),e.jsxs(te,{value:"overview",className:"space-y-6",children:[e.jsxs(n,{className:"border-border/40",children:[e.jsx(i,{className:"border-b border-border/40",children:e.jsxs(c,{className:"flex items-center gap-2",children:[e.jsx(q,{className:"h-5 w-5 text-primary"}),"Traffic trend",(null==(p=rs[0])?void 0:p.source)&&e.jsx(be,{source:rs[0].source})]})}),e.jsx(d,{className:"pt-6",children:!Ee&&!Ge||rs.length?rs.length?e.jsx(ie,{width:"100%",height:300,children:e.jsxs(ce,{data:rs,children:[e.jsx(de,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(oe,{dataKey:"date",tick:{fontSize:12}}),e.jsx(xe,{tick:{fontSize:12}}),e.jsx(me,{}),e.jsx(ue,{}),e.jsx(he,{type:"monotone",dataKey:"visitors",name:"Visitors",stroke:"hsl(var(--primary))",strokeWidth:2}),e.jsx(he,{type:"monotone",dataKey:"pageviews",name:"Views",stroke:"hsl(var(--muted-foreground))",strokeDasharray:"4 4"})]})}):e.jsx("p",{className:"py-16 text-center text-sm text-muted-foreground",children:"No trend data available"}):e.jsx(j,{className:"h-[300px] w-full"})})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsxs(n,{className:"border-border/40",children:[e.jsx(i,{className:"pb-2",children:e.jsx(c,{className:"text-sm",children:"Supabase downloads"})}),e.jsxs(d,{children:[e.jsx("div",{className:"text-2xl font-bold",children:k((null==$e?void 0:$e.total_downloads)??0)}),e.jsx(be,{source:"supabase"})]})]}),e.jsxs(n,{className:"border-border/40",children:[e.jsx(i,{className:"pb-2",children:e.jsx(c,{className:"text-sm",children:"Vercel visitors (30d)"})}),e.jsxs(d,{children:[e.jsx("div",{className:"text-2xl font-bold",children:Qe?k((null==Re?void 0:Re.visitors)??0):"â"}),Qe&&e.jsx(be,{source:"vercel"})]})]}),e.jsxs(n,{className:"border-border/40",children:[e.jsx(i,{className:"pb-2",children:e.jsx(c,{className:"text-sm",children:"Supabase visitors"})}),e.jsxs(d,{children:[e.jsx("div",{className:"text-2xl font-bold",children:k((null==$e?void 0:$e.unique_visitors)??0)}),e.jsx(be,{source:"supabase"})]})]})]})]}),e.jsxs(te,{value:"traffic",className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsxs(n,{className:"border-border/40",children:[e.jsx(i,{className:"border-b border-border/40",children:e.jsx(c,{className:"text-base",children:"Referrers â Vercel"})}),e.jsx(d,{className:"pt-4",children:Qe&&(null==(C=null==Re?void 0:Re.topSources)?void 0:C.length)?e.jsx("ul",{className:"space-y-2",children:Re.topSources.slice(0,10).map((s,a)=>e.jsxs("li",{className:"flex justify-between text-sm gap-2",children:[e.jsx("span",{className:"truncate",children:s.source||"Direct"}),e.jsx("span",{className:"tabular-nums text-muted-foreground",children:k(s.visitors)})]},a))}):e.jsx("p",{className:"py-6 text-sm text-muted-foreground text-center",children:"No Vercel data available"})})]}),e.jsxs(n,{className:"border-border/40",children:[e.jsx(i,{className:"border-b border-border/40",children:e.jsx(c,{className:"text-base",children:"Referrers â Supabase"})}),e.jsx(d,{className:"pt-4",children:Fe?e.jsx(j,{className:"h-32 w-full"}):(null==We?void 0:We.length)?e.jsx("ul",{className:"space-y-2",children:We.slice(0,10).map((s,a)=>e.jsxs("li",{className:"flex justify-between text-sm gap-2",children:[e.jsx("span",{className:"truncate",children:s.source||"Direct"}),e.jsxs("span",{className:"tabular-nums text-muted-foreground",children:[k(s.visit_count),null!=s.percentage&&` (${s.percentage}%)`]})]},a))}):e.jsx("p",{className:"py-6 text-sm text-muted-foreground text-center",children:"No data available"})})]})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsxs(n,{className:"border-border/40",children:[e.jsxs(i,{className:"border-b border-border/40",children:[e.jsxs(c,{className:"flex items-center gap-2 text-base",children:["All Pages",e.jsx(be,{source:Qe&&(null==(L=null==Re?void 0:Re.topPages)?void 0:L.length)?"vercel":"supabase"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:es()})]}),e.jsx(d,{className:"pt-4",children:Qe&&(null==(A=null==Re?void 0:Re.topPages)?void 0:A.length)?e.jsx("ul",{className:"max-h-80 space-y-2 overflow-y-auto pr-2",children:Re.topPages.map((s,a)=>e.jsxs("li",{className:"flex justify-between gap-2 text-sm",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:s.path}),e.jsx("span",{className:"tabular-nums text-muted-foreground shrink-0",children:k(s.pageviews)})]},a))}):Ke?e.jsx(j,{className:"h-32 w-full"}):(null==Ie?void 0:Ie.length)?e.jsx("ul",{className:"max-h-80 space-y-2 overflow-y-auto pr-2",children:Ie.map((s,a)=>e.jsxs("li",{className:"flex justify-between gap-2 text-sm",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:s.page_path}),e.jsx("span",{className:"tabular-nums text-muted-foreground shrink-0",children:k(s.view_count)})]},a))}):e.jsx("p",{className:"py-6 text-sm text-muted-foreground text-center",children:"No page data for the selected period"})})]}),e.jsxs(n,{className:"border-border/40",children:[e.jsx(i,{className:"border-b border-border/40",children:e.jsx(c,{className:"text-base",children:"Top Articles â Supabase"})}),e.jsx(d,{className:"pt-4",children:He?e.jsx(j,{className:"h-32 w-full"}):(null==ze?void 0:ze.length)?e.jsx("ul",{className:"space-y-2",children:ze.map(s=>e.jsxs("li",{className:"flex justify-between text-sm gap-2",children:[e.jsx("span",{className:"truncate",children:s.title}),e.jsx("span",{className:"tabular-nums text-muted-foreground shrink-0",children:k(s.view_count)})]},s.article_id))}):e.jsx("p",{className:"py-6 text-sm text-muted-foreground text-center",children:"No data available"})})]})]})]}),e.jsxs(te,{value:"audience",className:"space-y-6",children:[e.jsxs(n,{className:"border-border/40",children:[e.jsx(i,{children:e.jsxs(c,{className:"flex items-center gap-2",children:[e.jsx(z,{className:"h-5 w-5"}),"Supabase filters"]})}),e.jsxs(d,{children:[e.jsx("div",{className:"grid gap-4 md:grid-cols-4",children:[["country","Country",null==Je?void 0:Je.countries],["region","Region",null==Je?void 0:Je.regions],["gender","Gender",null==Je?void 0:Je.genders],["deviceType","Device",null==Je?void 0:Je.device_types]].map(([s,a,t])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:a}),e.jsxs(G,{value:ye[s]||"all",onValueChange:e=>((e,s)=>{we(a=>({...a,[e]:"all"===s?void 0:s}))})(s,e),children:[e.jsx(X,{children:e.jsx(Y,{})}),e.jsxs(Q,{children:[e.jsx(Z,{value:"all",children:"All"}),null==t?void 0:t.map(s=>e.jsx(Z,{value:s,children:s},s))]})]})]},s))}),Ze&&e.jsxs(h,{variant:"outline",size:"sm",className:"mt-4",onClick:()=>{we({}),Le("30days"),Ve(void 0),Te(void 0)},children:[e.jsx(H,{className:"mr-2 h-4 w-4"}),"Clear filters"]})]})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsxs(n,{className:"border-border/40",children:[e.jsx(i,{children:e.jsxs(c,{className:"flex items-center gap-2",children:[e.jsx(I,{className:"h-5 w-5"}),"Countries â Vercel"]})}),e.jsx(d,{children:Qe&&(null==(V=null==Re?void 0:Re.topCountries)?void 0:V.length)?e.jsx(ie,{width:"100%",height:220,children:e.jsxs(je,{data:Re.topCountries.slice(0,8),layout:"vertical",margin:{left:8,right:16},children:[e.jsx(oe,{type:"number",hide:!0}),e.jsx(xe,{type:"category",dataKey:"country",width:72,tick:{fontSize:11}}),e.jsx(me,{}),e.jsx(pe,{dataKey:"visitors",fill:"hsl(var(--primary))",radius:4})]})}):e.jsx("p",{className:"py-8 text-center text-sm text-muted-foreground",children:"â"})})]}),e.jsxs(n,{className:"border-border/40",children:[e.jsx(i,{children:e.jsxs(c,{className:"flex items-center gap-2",children:[e.jsx(K,{className:"h-5 w-5"}),"Devices"]})}),e.jsxs(d,{className:"space-y-4",children:[Qe&&(null==(M=null==Re?void 0:Re.topDevices)?void 0:M.length)?e.jsxs("div",{children:[e.jsx("p",{className:"mb-2 text-xs text-muted-foreground",children:"Vercel"}),e.jsx("ul",{className:"space-y-1",children:Re.topDevices.slice(0,6).map((s,a)=>e.jsxs("li",{className:"flex justify-between text-sm capitalize",children:[e.jsx("span",{children:s.device}),e.jsx("span",{className:"text-muted-foreground",children:k(s.visitors)})]},a))})]}):null,Ue?e.jsx(j,{className:"h-20 w-full"}):(null==Be?void 0:Be.length)?e.jsxs("div",{children:[e.jsx("p",{className:"mb-2 text-xs text-muted-foreground",children:"Supabase (filtered)"}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-3",children:Be.map(s=>{const a="mobile"===s.device_type?W:"tablet"===s.device_type?F:K;return e.jsxs("div",{className:"rounded-lg border p-3 text-center",children:[e.jsx(a,{className:"mx-auto mb-1 h-5 w-5 text-primary"}),e.jsx("p",{className:"text-xs capitalize",children:s.device_type}),e.jsx("p",{className:"font-bold",children:k(s.visit_count)}
1),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[s.percentage,"%"]})]},s.device_type)})})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No Supabase device data"})]})]})]})]}),e.jsxs(te,{value:"content",className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-4",children:[e.jsxs(n,{children:[e.jsxs(i,{className:"pb-2",children:[e.jsx(c,{className:"text-sm",children:"Articles"}),e.jsx(B,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(d,{className:"text-2xl font-bold",children:Ye?"â¦":(null==Xe?void 0:Xe.totalArticles)??0})]}),e.jsxs(n,{children:[e.jsxs(i,{className:"pb-2",children:[e.jsx(c,{className:"text-sm",children:"Total views"}),e.jsx(R,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(d,{className:"text-2xl font-bold",children:Ye?"â¦":k((null==Xe?void 0:Xe.totalViews)??0)})]}),e.jsxs(n,{children:[e.jsxs(i,{className:"pb-2",children:[e.jsx(c,{className:"text-sm",children:"Avg. reading time"}),e.jsx(U,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(d,{className:"text-lg font-bold",children:Ye?"â¦":(null==Xe?void 0:Xe.averageReadingTime)??"â"})]}),e.jsxs(n,{children:[e.jsxs(i,{className:"pb-2",children:[e.jsx(c,{className:"text-sm",children:"Categories"}),e.jsx(J,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(d,{className:"text-2xl font-bold",children:Ye?"â¦":(null==(ge=null==Xe?void 0:Xe.topCategories)?void 0:ge.length)??0})]})]}),e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsxs(n,{children:[e.jsx(i,{children:e.jsx(c,{children:"Popular categories"})}),e.jsx(d,{children:(null==(Ne=null==Xe?void 0:Xe.topCategories)?void 0:Ne.map((s,a)=>e.jsxs("div",{className:"flex justify-between border-b py-2 text-sm last:border-0",children:[e.jsxs("span",{children:[a+1,". ",s.category]}),e.jsxs("span",{className:"text-muted-foreground",children:[s.count," articles"]})]},s.category)))??e.jsx("p",{className:"text-sm text-muted-foreground",children:"â"})})]}),e.jsxs(n,{children:[e.jsx(i,{children:e.jsx(c,{children:"Weekly trend"})}),e.jsx(d,{children:(null==(fe=null==Xe?void 0:Xe.weeklyTrends)?void 0:fe.map(s=>{var a;return e.jsxs("div",{className:"mb-3",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("span",{children:["Week ",s.week]}),e.jsxs("span",{className:"text-muted-foreground",children:[s.articles," published"]})]}),e.jsx("div",{className:"mt-1 h-2 rounded-full bg-muted",children:e.jsx("div",{className:"h-full rounded-full bg-primary",style:{width:`${Math.min(100,s.articles/Math.max(1,(null==(a=Xe.weeklyTrends[0])?void 0:a.articles)??1)*100)}%`}})})]},s.week)}))??e.jsx("p",{className:"text-sm text-muted-foreground",children:"â"})})]})]})]}),e.jsx(te,{value:"live",children:e.jsxs(n,{className:"border-border/40",children:[e.jsx(i,{children:e.jsxs(c,{className:"flex items-center gap-2",children:[e.jsx(O,{className:"h-5 w-5 text-primary"}),"Real-time (Supabase)",Se>0&&e.jsxs(o,{className:"bg-green-600",children:["+",Se," this session"]})]})}),e.jsx(d,{children:_e.length?e.jsx("ul",{className:"space-y-2",children:_e.map(s=>e.jsxs("li",{className:"flex justify-between border-b border-border/40 py-2 text-sm last:border-0",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:s.page_path}),e.jsx("span",{className:"text-xs text-muted-foreground shrink-0 ml-2",children:new Date(s.timestamp).toLocaleTimeString()})]},s.id))}):e.jsx("p",{className:"py-12 text-center text-sm text-muted-foreground",children:"Waiting for new page_view eventsâ¦"})})]})})]})]})]})};export{Ne 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.