2 lines
14 KiB
JavaScript
2 lines
14 KiB
JavaScript
|
|
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 b,S as n,E as V}from"./index-VJPzCABl.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 u}from"./StatCard-DSHXVTeQ.js";import"./vendor-CAoAb3tF.js";import"./vendor-router-4bycex72.js";import"./vendor-tanstack-BoI3DtL9.js";import"./vendor-utils-CDFfoeXY.js";import"./AnimatedNumber-Bn2Qf9FV.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-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 Z(s="30d"){const{addToast:a}=M(),[t,i]=l.useState(s),[r,c]=l.useState({}),[d,v]=l.useState([]),[m,j]=l.useState([]),[w,h]=l.useState({mobile:0,desktop:0}),[N,p]=l.useState(!0),[O,C]=l.useState(null),[P,I]=l.useState(null),y=l.useCallback(async()=>{p(!0),C(null);try{const[o,k,S,x]=await Promise.all([g.getGlobalStats(t),g.getTopTracks(t),g.getTrafficSources(),g.getDeviceBreakdown()]);c(o),v(k??[]),j(S??[]),h(x??{mobile:0,desktop:0})}catch(o){A.error("Error loading analytics",{error:o}),C(o instanceof Error?o:new Error(String(o)))}finally{p(!1)}},[t]);l.useEffect(()=>{y()},[y]);const _=l.useCallback(o=>{a(`Building ${o.toUpperCase()} archive...`,"info"),setTimeout(()=>{const k=new Blob([JSON.stringify(r,null,2)],{type:"application/json"}),S=URL.createObjectURL(k),x=document.createElement("a");x.href=S,x.download=`veza-analytics-${t}-${new Date().toISOString().split("T")[0]}.${o}`,x.click(),a("Data packet exported successfully","success")},1500)},[r,t,a]);return{dateRange:t,setDateRange:i,stats:r,topTracks:d,trafficSources:m,deviceStats:w,loading:N,error:O,hoveredData:P,setHoveredData:I,handleExport:_,retry:y}}const Q=["7d","30d","90d","ytd"];function W({dateRange:s,onDateRangeChange:a,onExportCsv:t,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-display font-bold text-white 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(r=>e.jsx("button",{type:"button",onClick:()=>a(r),className:D("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"),chi
|