2026-02-12 01:15:11 +00:00
|
|
|
import{a as l,j as e}from"./vendor-react-Dkpvlwai.js";import{a as E,l as A,n as M,d as D,B as f,C as v,S as o,E as V}from"./index-jE2AGx2y.js";import{b1 as U,an as G,Z as $,E as F,x as B,aJ as z,aG as K,ax as R,n as Y,b2 as H,b3 as J,s as q}from"./vendor-icons-CbmLcMl-.js";import{S as h}from"./StatCard-5r7CYk9-.js";import"./vendor-CAoAb3tF.js";import"./vendor-router-4bycex72.js";import"./vendor-tanstack-BoI3DtL9.js";import"./vendor-utils-CDFfoeXY.js";import"./AnimatedNumber-Dt_wg-GW.js";const T={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]}},L=[{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}],g={recordEvent:async(s,a)=>{try{await E.post("/analytics/events",{event_name:s,payload:a||{}})}catch{}},getGlobalStats:async(s="30d")=>{try{const a=await E.get("/analytics",{params:{days:s.replace("d","")}});return!a.data||Object.keys(a.data).length===0?T:{...T,...a.data}}catch(a){return A.error("[Analytics] Failed to fetch global stats",{error:a}),T}},getTopTracks:async(s="30d")=>{try{const a=await E.get("/analytics/tracks/top",{params:{days:s.replace("d","")}});return!a.data||a.data.length===0?L:a.data}catch(a){return A.error("[Analytics] Failed to fetch top tracks",{error:a}),L}},getTrafficSources:async()=>[{label:"Direct",val:45,color:"bg-primary"},{label:"Social Media",val:30,color:"bg-destructive"},{label:"Search",val:15,color:"bg-success"},{label:"Referral",val:10,color:"bg-warning"}],getDeviceBreakdown:async()=>({mobile:65,desktop:35})};function Z(s="30d"){const{addToast:a}=M(),[r,i]=l.useState(s),[t,c]=l.useState({}),[d,b]=l.useState([]),[m,j]=l.useState([]),[N,u]=l.useState({mobile:0,desktop:0}),[y,p]=l.useState(!0),[O,C]=l.useState(null),[P,I]=l.useState(null),w=l.useCallback(async()=>{p(!0),C(null);try{const[n,S,k,x]=await Promise.all([g.getGlobalStats(r),g.getTopTracks(r),g.getTrafficSources(),g.getDeviceBreakdown()]);c(n),b(S??[]),j(k??[]),u(x??{mobile:0,desktop:0})}catch(n){A.error("Error loading analytics",{error:n}),C(n instanceof Error?n:new Error(String(n)))}finally{p(!1)}},[r]);l.useEffect(()=>{w()},[w]);const _=l.useCallback(n=>{a(`Building ${n.toUpperCase()} archive...`,"info"),setTimeout(()=>{const S=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),k=URL.createObjectURL(S),x=document.createElement("a");x.href=k,x.download=`veza-analytics-${r}-${new Date().toISOString().split("T")[0]}.${n}`,x.click(),a("Data packet exported successfully","success")},1500)},[t,r,a]);return{dateRange:r,setDateRange:i,stats:t,topTracks:d,trafficSources:m,deviceStats:N,loading:y,error:O,hoveredData:P,setHoveredData:I,handleExport:_,retry:w}}const Q=["7d","30d","90d","ytd"];function W({dateRange:s,onDateRangeChange:a,onExportCsv:r,onExportJson:i}){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-heading font-bold text-foreground mb-2 flex items-center gap-3",children:[e.jsx(U,{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:Q.map(t=>e.jsx("button",{type:"button",onClick:()=>a(t),className:D("px-4 py-2 rounded-lg text-xs font-bold uppercase tracking-widest transition-all",s===t?"bg-primary text-black shadow-glow-cyan":"text-muted-foreground hover:text-foreground"),
|