1 line
14 KiB
JavaScript
1 line
14 KiB
JavaScript
import{a as l,j as e}from"./vendor-react-YMhRUmcb.js";import{a as y,l as S,m as I,d as E,B as u,C as g}from"./index-D2uzyr9g.js";import{aW as _,al as M,Y as V,D as U,w as $,aC as G,az as z,au as D,m as B,aX as F,aY as Y,r as K}from"./vendor-icons-DINCNwpk.js";import{S as h}from"./StatCard-Xzk79Siz.js";import{S as i}from"./skeleton-BPDNnZ8E.js";import"./vendor-fFnFILYR.js";import"./vendor-router-DX94Iu-2.js";import"./vendor-tanstack-CoFNL2zy.js";import"./vendor-utils-4BWoYre8.js";const k={total_users:12500,total_tracks:3420,total_plays:1205430,total_revenue:14250.5,followers:24500,profile_views:45200,trends:{plays:8.2,revenue:12.5,followers:2.1,views:-2.4},sparklines:{plays:[40,35,50,60,55,70,80,75,90],revenue:[10,12,15,14,18,20,22,25,28],followers:[20,21,21,22,22,23,23,24,24],views:[50,48,45,42,40,43,41,40,38]}},C=[{id:"t1",title:"Neon Nights",plays:15420,change:12,revenue:145.5},{id:"t2",title:"Cyber City",plays:12100,change:-5,revenue:98.2},{id:"t3",title:"System Failure",plays:8500,change:24,revenue:65},{id:"t4",title:"Mainframe",plays:6200,change:8,revenue:42.1}],p={recordEvent:async(s,a)=>{try{await y.post("/analytics/events",{event_name:s,payload:a||{}})}catch{}},getGlobalStats:async(s="30d")=>{try{const a=await y.get("/analytics",{params:{days:s.replace("d","")}});return!a.data||Object.keys(a.data).length===0?k:{...k,...a.data}}catch(a){return S.error("[Analytics] Failed to fetch global stats",{error:a}),k}},getTopTracks:async(s="30d")=>{try{const a=await y.get("/analytics/tracks/top",{params:{days:s.replace("d","")}});return!a.data||a.data.length===0?C:a.data}catch(a){return S.error("[Analytics] Failed to fetch top tracks",{error:a}),C}},getTrafficSources:async()=>[{label:"Direct",val:45,color:"bg-kodo-cyan"},{label:"Social Media",val:30,color:"bg-kodo-magenta"},{label:"Search",val:15,color:"bg-kodo-lime"},{label:"Referral",val:10,color:"bg-kodo-gold"}],getDeviceBreakdown:async()=>({mobile:65,desktop:35})};function H(s="30d"){const{addToast:a}=I(),[t,o]=l.useState(s),[r,n]=l.useState({}),[c,f]=l.useState([]),[b,v]=l.useState([]),[m,j]=l.useState({mobile:0,desktop:0}),[R,T]=l.useState(!0),[L,O]=l.useState(null),A=l.useCallback(async()=>{T(!0);try{const[d,w,N,x]=await Promise.all([p.getGlobalStats(t),p.getTopTracks(t),p.getTrafficSources(),p.getDeviceBreakdown()]);n(d),f(w??[]),v(N??[]),j(x??{mobile:0,desktop:0})}catch(d){S.error("Error loading analytics",{error:d})}finally{T(!1)}},[t]);l.useEffect(()=>{A()},[A]);const P=l.useCallback(d=>{a(`Building ${d.toUpperCase()} archive...`,"info"),setTimeout(()=>{const w=new Blob([JSON.stringify(r,null,2)],{type:"application/json"}),N=URL.createObjectURL(w),x=document.createElement("a");x.href=N,x.download=`veza-analytics-${t}-${new Date().toISOString().split("T")[0]}.${d}`,x.click(),a("Data packet exported successfully","success")},1500)},[r,t,a]);return{dateRange:t,setDateRange:o,stats:r,topTracks:c,trafficSources:b,deviceStats:m,loading:R,hoveredData:L,setHoveredData:O,handleExport:P}}const J=["7d","30d","90d","ytd"];function q({dateRange:s,onDateRangeChange:a,onExportCsv:t,onExportJson:o}){return e.jsxs("div",{className:"flex flex-col lg:flex-row justify-between items-start lg:items-end gap-6 border-b border-white/5 pb-8",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-4xl font-display font-bold text-white mb-2 flex items-center gap-3",children:[e.jsx(_,{className:"text-primary w-8 h-8"})," NEURAL ANALYTICS"]}),e.jsx("p",{className:"text-muted-foreground font-mono text-xs tracking-wide",children:"DEEP PACKET INSPECTION • AUDIENCE METRICS"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("div",{className:"bg-black/40 p-1 rounded-xl border border-white/10 backdrop-blur-md flex",children:J.map(r=>e.jsx("button",{type:"button",onClick:()=>a(r),className:E("px-4 py-2 rounded-lg text-xs font-bold uppercase tracking-widest transition-all",s===r?"bg-primary text-black shadow-glow-cyan":"text-muted-foreground hover:text-white"),children:r},r))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(u,{variant:"outline",size:"sm",onClick:t,className:"border-white/10 hover:border-primary/50",children:[e.jsx(M,{className:"w-4 h-4 mr-2"})," CSV"]}),e.jsx(u,{variant:"primary",size:"sm",onClick:o,className:"shadow-glow-cyan",children:"REPORT"})]})]})]})}function W({stats:s}){return e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6",children:[e.jsx(h,{label:"Network Plays",value:s.total_plays?.toLocaleString()??"—",icon:e.jsx(V,{className:"w-4 h-4"}),trend:s.trends?.plays,color:"cyan",sparklineData:s.sparklines?.plays}),e.jsx(h,{label:"Gross Revenue",value:s.total_revenue!=null?`$${s.total_revenue.toLocaleString()}`:"—",icon:e.jsx(U,{className:"w-4 h-4"}),trend:s.trends?.revenue,color:"gold",sparklineData:s.sparklines?.revenue}),e.jsx(h,{label:"Active Nodes",value:s.followers?.toLocaleString()??"—",icon:e.jsx($,{className:"w-4 h-4"}),trend:s.trends?.followers,color:"magenta",sparklineData:s.sparklines?.followers}),e.jsx(h,{label:"Profile Pulse",value:s.profile_views?.toLocaleString()??"—",icon:e.jsx(G,{className:"w-4 h-4"}),trend:s.trends?.views,color:"red",sparklineData:s.sparklines?.views})]})}function X({dateRange:s,hoveredData:a,onHover:t}){return e.jsxs(g,{variant:"glass",className:"lg:col-span-2 p-8 bg-black/40 border-white/5 relative overflow-hidden group",children:[e.jsxs("div",{className:"flex justify-between items-center mb-8 relative z-10",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-bold text-white mb-1",children:"Performance Dynamics"}),e.jsx("p",{className:"text-xs text-muted-foreground font-mono",children:"SCALAR TEMPORAL RESOLUTION"})]}),e.jsxs("div",{className:"flex gap-6 text-xs font-mono uppercase tracking-widest",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-primary"})," Plays"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-gold-500"})," Revenue"]})]})]}),e.jsxs("div",{className:"h-64 relative flex items-end",children:[e.jsx("div",{className:"absolute inset-0 grid grid-rows-4 w-full h-full pointer-events-none opacity-20",children:[...Array(5)].map((o,r)=>e.jsx("div",{className:"border-b border-white/10 w-full"},r))}),e.jsx("div",{className:"flex-1 flex items-end gap-1 h-full z-10 px-2",children:Array.from({length:30}).map((o,r)=>{const n=Math.random()*60+20,c=Math.random()*40+10;return e.jsxs("div",{className:"flex-1 group/bar relative h-full flex flex-col justify-end gap-0.5 cursor-pointer",onMouseEnter:()=>t({index:r,val1:n,val2:c}),onMouseLeave:()=>t(null),children:[e.jsx("div",{className:"w-full bg-gold-500/20 group-hover/bar:bg-gold-500/60 rounded-t-sm transition-all",style:{height:`${c}%`}}),e.jsx("div",{className:"w-full bg-primary/20 group-hover/bar:bg-primary/60 rounded-t-sm transition-all shadow-glow-cyan",style:{height:`${n}%`}}),a?.index===r&&e.jsxs("div",{className:"absolute bottom-full left-1/2 -translate-x-1/2 mb-4 bg-black/90 border border-white/20 p-2 rounded text-xs font-mono whitespace-nowrap z-50 animate-fadeIn backdrop-blur-xl",children:[e.jsxs("div",{className:"text-primary",children:["PLAYS: ",Math.floor(n*1230)]}),e.jsxs("div",{className:"text-gold-500",children:["REV: $",(c*42).toFixed(2)]})]})]},r)})})]}),e.jsxs("div",{className:"flex justify-between text-xs font-mono text-muted-foreground mt-4 px-2 uppercase tracking-tighter",children:[e.jsxs("span",{children:[s," AGO"]}),e.jsx("span",{children:"REALTIME FEED"}),e.jsx("span",{children:"PRESENT"})]})]})}function Q({sources:s}){return e.jsxs(g,{variant:"glass",className:"p-6 bg-black/40 border-white/5",children:[e.jsxs("h3",{className:"font-bold text-white mb-6 text-sm uppercase tracking-widest flex items-center gap-2",children:[e.jsx(z,{className:"w-4 h-4 text-magenta-500"})," Origins"]}),e.jsx("div",{className:"space-y-5",children:s.map(a=>e.jsxs("div",{className:"group cursor-default",children:[e.jsxs("div",{className:"flex justify-between text-xs mb-2",children:[e.jsx("span",{className:"text-muted-foreground group-hover:text-white transition-colors uppercase font-mono",children:a.label}),e.jsxs("span",{className:"text-white font-bold",children:[a.val,"%"]})]}),e.jsx("div",{className:"h-1.5 bg-white/5 rounded-full overflow-hidden",children:e.jsx("div",{className:E("h-full transition-all duration-1000",a.color.replace(/^bg-kodo-/,"bg-")),style:{width:`${a.val}%`}})})]},a.label))})]})}function Z({deviceStats:s}){return e.jsxs(g,{variant:"glass",className:"p-6 bg-black/40 border-white/5",children:[e.jsxs("h3",{className:"font-bold text-white mb-6 text-sm uppercase tracking-widest flex items-center gap-2",children:[e.jsx(D,{className:"w-4 h-4 text-cyan-500"})," Platforms"]}),e.jsxs("div",{className:"flex items-center justify-between gap-8 px-4",children:[e.jsxs("div",{className:"text-center group flex-1",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-white/5 flex items-center justify-center mx-auto mb-3 group-hover:bg-primary/10 transition-all border border-transparent group-hover:border-primary/20",children:e.jsx(D,{className:"w-6 h-6 text-muted-foreground group-hover:text-primary transition-colors"})}),e.jsxs("div",{className:"text-2xl font-bold text-white",children:[s.mobile,"%"]}),e.jsx("div",{className:"text-xs text-muted-foreground uppercase font-mono mt-1",children:"MOBILE"})]}),e.jsx("div",{className:"w-px h-12 bg-white/10"}),e.jsxs("div",{className:"text-center group flex-1",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-white/5 flex items-center justify-center mx-auto mb-3 group-hover:bg-magenta-500/10 transition-all border border-transparent group-hover:border-magenta-500/20",children:e.jsx(B,{className:"w-6 h-6 text-muted-foreground group-hover:text-magenta-500 transition-colors"})}),e.jsxs("div",{className:"text-2xl font-bold text-white",children:[s.desktop,"%"]}),e.jsx("div",{className:"text-xs text-muted-foreground uppercase font-mono mt-1",children:"NODE"})]})]})]})}function ee({tracks:s,onNavigateTrack:a}){return e.jsxs(g,{variant:"glass",className:"bg-black/40 border-white/5 overflow-hidden p-0 relative group",children:[e.jsx("div",{className:"absolute inset-x-0 bottom-0 h-px bg-gradient-to-r from-transparent via-primary/40 to-transparent group-hover:via-primary transition-all opacity-50"}),e.jsxs("div",{className:"flex justify-between items-center p-6 border-b border-white/5 bg-white/2",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-bold text-white",children:"Top Frequency Nodes"}),e.jsx("p",{className:"text-xs text-muted-foreground font-mono",children:"SORTED BY PEAK VOLTAGE"})]}),e.jsx(u,{variant:"ghost",size:"sm",className:"hover:bg-white/5",children:"FULL FEED"})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-left",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-xs text-muted-foreground uppercase tracking-wider border-b border-white/5 bg-black/20",children:[e.jsx("th",{className:"py-4 pl-8",children:"SIGNAL IDENTITY"}),e.jsx("th",{className:"py-4",children:"PLAYS"}),e.jsx("th",{className:"py-4",children:"DELTA"}),e.jsx("th",{className:"py-4",children:"REVENUE"}),e.jsx("th",{className:"py-4 text-right pr-8",children:"PROTOCOL"})]})}),e.jsx("tbody",{className:"text-sm divide-y divide-white/5",children:s.map(t=>e.jsxs("tr",{className:"hover:bg-white/5 transition-all group",children:[e.jsxs("td",{className:"py-5 pl-8",children:[e.jsx("div",{className:"font-bold text-white group-hover:text-primary transition-colors",children:t.title}),e.jsxs("div",{className:"text-xs text-muted-foreground font-mono",children:["TRACK_ID: ",t.id.toUpperCase()]})]}),e.jsx("td",{className:"py-5 text-white font-mono",children:t.plays.toLocaleString()}),e.jsx("td",{className:"py-5",children:e.jsxs("span",{className:E("inline-flex items-center gap-1.5 px-2 py-0.5 rounded text-xs font-bold uppercase tracking-wider border",t.change>=0?"text-lime-500 border-lime-500/20 bg-lime-500/10":"text-red-500 border-red-500/20 bg-red-500/10"),children:[t.change>=0?e.jsx(F,{className:"w-3 h-3"}):e.jsx(Y,{className:"w-3 h-3"}),Math.abs(t.change),"%"]})}),e.jsxs("td",{className:"py-5 font-bold text-gold-500",children:["$",t.revenue.toFixed(2)]}),e.jsx("td",{className:"py-5 text-right pr-8",children:e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>a(t.id),className:"bg-black/40 border-white/10 hover:border-primary/50 group-hover:shadow-glow-cyan transition-all",children:["INSPECT ",e.jsx(K,{className:"w-4 h-4 ml-1"})]})})]},t.id))})]})})]})}function se(){return e.jsxs("div",{className:"space-y-8 pb-24 container py-8 animate-fadeIn",children:[e.jsxs("div",{className:"flex flex-col lg:flex-row justify-between items-start lg:items-end gap-6 border-b border-white/5 pb-8",children:[e.jsxs("div",{children:[e.jsx(i,{className:"h-10 w-64 mb-2"}),e.jsx(i,{className:"h-4 w-80"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx(i,{className:"h-10 w-48 rounded-[var(--radius-xl)]"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(i,{className:"h-9 w-20"}),e.jsx(i,{className:"h-9 w-20"})]})]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6",children:[1,2,3,4].map(s=>e.jsx(i,{className:"h-28 w-full rounded-[var(--radius-xl)]"},s))}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-8",children:[e.jsx(i,{className:"lg:col-span-2 h-80 rounded-[var(--radius-xl)]"}),e.jsxs("div",{className:"space-y-6",children:[e.jsx(i,{className:"h-56 rounded-[var(--radius-xl)]"}),e.jsx(i,{className:"h-44 rounded-[var(--radius-xl)]"})]})]}),e.jsx(i,{className:"h-96 w-full rounded-[var(--radius-xl)]"})]})}function xe({onNavigateTrack:s}){const{dateRange:a,setDateRange:t,stats:o,topTracks:r,trafficSources:n,deviceStats:c,loading:f,hoveredData:b,setHoveredData:v,handleExport:m}=H("30d");return f?e.jsx(se,{}):e.jsxs("div",{className:"space-y-8 pb-24 animate-fadeIn container py-8 min-h-layout-page",children:[e.jsx(q,{dateRange:a,onDateRangeChange:j=>t(j),onExportCsv:()=>m("csv"),onExportJson:()=>m("json")}),e.jsx(W,{stats:o}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-8",children:[e.jsx(X,{dateRange:a,hoveredData:b,onHover:v}),e.jsxs("div",{className:"space-y-6",children:[e.jsx(Q,{sources:n}),e.jsx(Z,{deviceStats:c})]})]}),e.jsx(ee,{tracks:r,onNavigateTrack:s})]})}export{xe as AnalyticsView};
|