1import{y as P,O as Q,r as g,j as e,U as Y,o as K,ae as C,L as V,E as A,aG as ce,ag as ie,aK as T,aL as I,aM as E,N as J,R as X,a9 as de,a$ as D,s as W,v as S,bR as B,M as Z,V as ee,a1 as xe,ba as pe,bk as te,bp as ue,bz as me,bA as he,bS as ge,bT as ye,m as fe}from"./index-BNrdOJig.js";import{g as be,a as je}from"./data-warehouse.functions-ChhcivSw.js";import{G as se}from"./GeoPlayMap-DHynfgXZ.js";import{C as Ne}from"./compass-ChIeWnEA.js";import{M as ae}from"./map-pin-BRjVggch.js";import{C as ve}from"./chevron-down-Bsk54EUt.js";import{P as we}from"./plus-BewcIKll.js";function U(s){const l=typeof s=="number"?s:Number(s);return Number.isFinite(l)?l:null}function G(s){const l=new Date(String(s??""));return Number.isNaN(l.getTime())?"â":l.toLocaleString()}function ke(s){return typeof s=="string"&&s.length>0?s:""}function _e(s,l){const n=U(s),p=U(l);return n!=null&&p!=null?`${n.toFixed(3)}, ${p.toFixed(3)}`:"â"}function Se({days:s}){const l=P(be),{data:n,isLoading:p}=Q({queryKey:["fan-sources",s],queryFn:()=>l({data:{days:s}}),refetchInterval:3e4}),x=n?.channels??[],h=n?.fans??[],f=n?.top_sharers??[],y=x.reduce((t,a)=>t+a.plays,0),[b,k]=g.useState(null),[_,j]=g.useState(new Set),w=t=>j(a=>{const c=new Set(a);return c.has(t)?c.delete(t):c.add(t),c}),o=g.useMemo(()=>{const t=b?h.filter(c=>c.fan_key===b):h,a=new Map;for(const c of t)for(const d of c.events??[]){const m=U(d.lat),v=U(d.lng);if(m==null||v==null)continue;const N=`${m.toFixed(2)}|${v.toFixed(2)}`,u=a.get(N)??{city:d.city??"Unknown",country:d.country??"",country_code:d.country_code,region:d.region,lat:m,lng:v,plays:0,listeners:new Set,events:[]};u.plays+=1,u.listeners.add(c.fan_key),u.events.push({kind:d.kind,title:d.title,who:c.display_name,ip:d.ip_hash?d.ip_hash.slice(0,10)+"â¦":null,city:d.city,region:d.region,country:d.country,country_code:d.country_code,seconds:d.listened_seconds,qualified:d.qualified,at:ke(d.played_at)}),a.set(N,u)}return Array.from(a.values()).map(c=>({...c,listeners:c.listeners.size,events:c.events.sort((d,m)=>m.at.localeCompare(d.at)).slice(0,12)}))},[h,b]);if(p&&!n)return e.jsx("div",{className:"rounded-2xl border border-border bg-card p-5 text-sm text-muted-foreground",children:"Loading fan sourcesâ¦"});const r={Social:"bg-pink-500/20 text-pink-300",Search:"bg-emerald-500/20 text-emerald-300",Email:"bg-sky-500/20 text-sky-300",Ads:"bg-amber-500/20 text-amber-300",Direct:"bg-zinc-500/20 text-zinc-300",Internal:"bg-primary/20 text-primary",Web:"bg-violet-500/20 text-violet-300",Offline:"bg-orange-500/20 text-orange-300",Campaign:"bg-fuchsia-500/20 text-fuchsia-300",Other:"bg-muted-foreground/20 text-muted-foreground"};return e.jsxs("section",{className:"rounded-2xl border border-border bg-card overflow-hidden",children:[e.jsxs("div",{className:"px-5 py-4 border-b border-border flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-bold uppercase tracking-wider text-muted-foreground",children:"Where every fan is coming from"}),e.jsx("div",{className:"font-display text-lg font-black",children:"Fan-Source Breakdown"})]}),e.jsxs("div",{className:"text-[10px] uppercase tracking-wider text-muted-foreground inline-flex items-center gap-1.5",children:[e.jsx(Y,{className:"w-3 h-3"})," ",n?.total_fans??0," fans"]})]}),e.jsxs("div",{className:"p-5 space-y-5",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"text-[10px] font-bold uppercase tracking-wider text-muted-foreground mb-2 inline-flex items-center gap-1.5",children:[e.jsx(Ne,{className:"w-3 h-3"})," Traffic by channel"]}),x.length===0?e.jsx("div",{className:"text-xs text-muted-foreground italic",children:"No referrer data yet. Share your tracks anywhere with a link and we'll attribute the listeners."}):e.jsx("div",{className:"space-y-1.5",children:x.slice(0,10).map(t=>{const a=y?Math.round(t.plays/y*100):0;return e.jsxs("div",{className:"flex items-center gap-3 text-xs",children:[e.jsx("span",{className:`shrink-0 px-2 py-0.5 rounded-full text-[10px] font-bold uppercase tracking-wider ${r[t.group]??r.Other}`,children:t.group}),e.jsx("span",{className:"font-semibold truncate w-32",children:t.channel}),e.jsx("div",{className:"flex-1 h-2 rounded-full bg-secondary/40 overflow-hidden",children:e.jsx("div",{className:"h-full bg-primary",style:{width:`${a}%`}})}),e.jsxs("span",{className:"font-mono tabular-nums text-muted-foreground w-10 text-right",children:[a,"%"]}),e.jsx("span",{className:"font-mono tabular-nums w-16 text-right",children:t.plays.toLocaleStr
1ing()}),e.jsxs("span",{className:"font-mono tabular-nums text-muted-foreground w-12 text-right",children:[t.fans," fans"]})]},`${t.group}-${t.channel}`)})})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"text-[10px] font-bold uppercase tracking-wider text-muted-foreground mb-2 inline-flex items-center gap-1.5",children:[e.jsx(K,{className:"w-3 h-3"})," Top referring fans (word-of-mouth)"]}),f.length===0?e.jsx("div",{className:"text-xs text-muted-foreground italic",children:"No fan shares yet."}):e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:f.slice(0,8).map(t=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl border border-border bg-secondary/20 px-3 py-2",children:[t.country&&e.jsx(C,{code:t.country,size:"xs"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[t.handle?e.jsx(V,{to:"/network/u/$handle",params:{handle:t.handle},className:"text-xs font-bold truncate hover:text-primary",children:t.display_name}):e.jsx("div",{className:"text-xs font-bold truncate",children:t.display_name}),e.jsx("div",{className:"text-[10px] text-muted-foreground truncate",children:t.platforms.join(" · ")||"share link"})]}),e.jsx("div",{className:"font-mono text-sm font-black tabular-nums",children:t.shares})]},t.user_id))})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"text-[10px] font-bold uppercase tracking-wider text-muted-foreground mb-2 inline-flex items-center gap-1.5",children:[e.jsx(A,{className:"w-3 h-3"})," Per-fan source attribution"]}),h.length===0?e.jsx("div",{className:"text-xs text-muted-foreground italic",children:"No listeners yet in this window."}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"text-[10px] uppercase tracking-wider text-muted-foreground inline-flex items-center gap-1.5",children:[e.jsx(ae,{className:"w-3 h-3"})," ",b?"Showing selected fan only":`${o.length} locations · click a row to focus`]}),b&&e.jsx("button",{onClick:()=>k(null),className:"text-[10px] uppercase tracking-wider font-bold text-primary hover:underline",children:"Show all"})]}),e.jsx("div",{className:"mb-4",children:o.length>0?e.jsx(se,{points:o,height:360}):e.jsx("div",{className:"text-xs text-muted-foreground italic mb-4",children:"No geo-located plays yet in this window."})}),e.jsx("div",{className:"overflow-x-auto rounded-xl border border-border",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-secondary/30 text-[10px] uppercase tracking-wider text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"w-6"}),e.jsx("th",{className:"text-left px-4 py-2",children:"Fan"}),e.jsx("th",{className:"text-left px-4 py-2 hidden sm:table-cell",children:"Where"}),e.jsx("th",{className:"text-left px-4 py-2",children:"Source"}),e.jsx("th",{className:"text-left px-4 py-2 hidden md:table-cell",children:"Campaign"}),e.jsx("th",{className:"text-right px-4 py-2",children:"Plays"}),e.jsx("th",{className:"text-right px-4 py-2 hidden sm:table-cell",children:"Qualified"}),e.jsx("th",{className:"text-right px-4 py-2 hidden md:table-cell",children:"Seconds"}),e.jsx("th",{className:"text-right px-4 py-2 hidden lg:table-cell",children:"Cities"}),e.jsx("th",{className:"text-left px-4 py-2 hidden lg:table-cell",children:"Last seen"})]})}),e.jsx("tbody",{children:h.slice(0,50).map(t=>e.jsxs(ce.Fragment,{children:[e.jsxs("tr",{className:`border-t border-border cursor-pointer hover:bg-secondary/20 ${b===t.fan_key?"bg-primary/10":""}`,onClick:()=>{k(a=>a===t.fan_key?null:t.fan_key),w(t.fan_key)},children:[e.jsx("td",{className:"px-2 py-2 text-muted-foreground",children:_.has(t.fan_key)?e.jsx(ve,{className:"w-3.5 h-3.5"}):e.jsx(ie,{className:"w-3.5 h-3.5"})}),e.jsx("td",{className:"px-4 py-2 truncate max-w-[220px]",children:t.handle?e.jsx(V,{to:"/network/u/$handle",params:{handle:t.handle},className:"font-semibold hover:text-primary",children:t.display_name}):e.jsx("span",{className:"text-muted-foreground",children:t.display_name})}),e.jsx("td",{className:"px-4 py-2 hidden sm:table-cell",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-muted-foreground",children:[t.country&&e.jsx(C,{code:t.country,size:"xs"}),e.jsx("span",{className:"truncate",children:[t.city,t.country].filter(
1Boolean).join(", ")||"â"})]})}),e.jsx("td",{className:"px-4 py-2",children:e.jsx("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[10px] font-bold uppercase tracking-wider ${r[t.source_group]??r.Other}`,children:t.source_channel})}),e.jsx("td",{className:"px-4 py-2 hidden md:table-cell text-xs text-muted-foreground truncate max-w-[180px]",children:t.utm_campaign??"â"}),e.jsx("td",{className:"px-4 py-2 text-right font-mono",children:t.plays}),e.jsx("td",{className:"px-4 py-2 text-right font-mono hidden sm:table-cell",children:t.qualified}),e.jsxs("td",{className:"px-4 py-2 text-right font-mono hidden md:table-cell",children:[t.total_seconds??0,"s"]}),e.jsx("td",{className:"px-4 py-2 text-right font-mono hidden lg:table-cell",children:t.cities??0}),e.jsx("td",{className:"px-4 py-2 hidden lg:table-cell text-xs text-muted-foreground",children:G(t.last_at)})]}),_.has(t.fan_key)&&e.jsx("tr",{className:"border-t border-border bg-background/40",children:e.jsxs("td",{colSpan:10,className:"px-4 py-3",children:[e.jsxs("div",{className:"text-[10px] uppercase tracking-wider text-muted-foreground mb-2",children:["Per-click detail · ",(t.events??[]).length," events · IPs are anonymized (one-way hash) for GDPR/CCPA compliance"]}),e.jsx("div",{className:"rounded-lg border border-border overflow-hidden",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"bg-secondary/30 text-[10px] uppercase tracking-wider text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left px-3 py-1.5",children:"When"}),e.jsx("th",{className:"text-left px-3 py-1.5",children:"What"}),e.jsx("th",{className:"text-left px-3 py-1.5",children:"City / Region"}),e.jsx("th",{className:"text-left px-3 py-1.5 hidden sm:table-cell",children:"Lat, Lng"}),e.jsx("th",{className:"text-right px-3 py-1.5",children:"Seconds"}),e.jsx("th",{className:"text-right px-3 py-1.5",children:"Qual."}),e.jsx("th",{className:"text-left px-3 py-1.5 hidden md:table-cell",children:"Visitor hash"})]})}),e.jsx("tbody",{children:(t.events??[]).slice(0,50).map((a,c)=>e.jsxs("tr",{className:"border-t border-border",children:[e.jsx("td",{className:"px-3 py-1.5 text-muted-foreground whitespace-nowrap",children:G(a.played_at)}),e.jsxs("td",{className:"px-3 py-1.5",children:[a.kind==="song"?"ðµ":"ð¬"," ",e.jsx("span",{className:"truncate",children:a.title})]}),e.jsx("td",{className:"px-3 py-1.5",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[a.country_code&&e.jsx(C,{code:a.country_code,size:"xs"}),[a.city,a.region,a.country].filter(Boolean).join(", ")||"â"]})}),e.jsx("td",{className:"px-3 py-1.5 font-mono text-muted-foreground hidden sm:table-cell",children:_e(a.lat,a.lng)}),e.jsxs("td",{className:"px-3 py-1.5 text-right font-mono",children:[a.listened_seconds??0,"s"]}),e.jsx("td",{className:"px-3 py-1.5 text-right",children:a.qualified?"â":"·"}),e.jsx("td",{className:"px-3 py-1.5 font-mono text-muted-foreground hidden md:table-cell",children:a.ip_hash?a.ip_hash.slice(0,12)+"â¦":"â"})]},c))})]})})]})})]},t.fan_key))})]})})]})]})]})]})}const Ce=T({method:"GET"}).middleware([I]).handler(E("2bf57f85259a000c7b14910e423ba6f7de3db79b974fe4527ce1a5bfd158b435")),Le=T({method:"GET"}).middleware([I]).handler(E("04a6006779fc360ade078e717a54fc35098a143d2b51e1bb77295d7b37cab4a4")),qe=T({method:"POST"}).middleware([I]).handler(E("4696d8a77a07f9bd3f93b2a491efa0c80c3df85cdad86d7d6db020913a636fa0")),Re=T({method:"POST"}).middleware([I]).handler(E("908dc441f5f4cb5987c831ef2d71c78fc440f2323247e98c0008743a885698f9")),$e=T({method:"POST"}).middleware([I]).handler(E("eaf0f27411669b32e347d1376409d8a854eb246138b2cca776beb2ea9b95b9bb"));function Fe({days:s}){const l=P(Ce),n=J(),{data:p,isLoading:x}=Q({queryKey:["radio-airplay",s],queryFn:()=>l({data:{days:s}}),refetchInterval:6e4}),[h,f]=g.useState(null),y=p?.points??[],b=p?.kpis??{total_spins:0,stations:0,countries:0,tracks:0},k=p?.top_stations??[],_=p?.top_markets??[],j=p?.recent??[],w=p?.timeline??[],o=g.useMemo(()=>Math.max(1,...w.map(t=>t.spins)),[w]),r=()=>{const a=[["played_at","station","callsign","country","track","method","confidence","source"],...j.map(m=>[m.played_at,m.station?.name??"",m.station?.callsign??"",m.station?.country_code??"",m.track?.title??m.now_playing_title??"",m.detection_method,m.confidence,m.source??""])].map(m=>m.map(v=>`"${String(v??"").replace(/"/g,'""')}"`).join(",")).join(` 2`),c=new Blob([a],{type:"text/csv"}),d=document.createElement("a");d.href=URL.createObjectURL(c),d.download=`radio-airplay-${new Date().toISOString().slice(0,10)}.csv`,d.click()};return e.jsxs("section",{className:"rounded-2xl border border-border bg-card overflow-hidden",children:[e.jsxs("div",{className:"px-5 py-4 border-b border-border flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl bg-primary/15 text-primary grid place-items-center",children:e.jsx(X,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-bold uppercase tracking-wider text-muted-foreground",children:"US + International airplay"}),e.jsx("div",{className:"font-display text-lg font-black",children:"Radio Airplay"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("button",{onClick:()=>f("log"),className:"text-xs px-3 py-1.5 rounded-full border border-border hover:bg-secondary/40 inline-flex items-center gap-1.5",children:[e.jsx(we,{className:"w-3.5 h-3.5"})," Log a spin"]}),e.jsxs("button",{onClick:()=>f("csv"),className:"text-xs px-3 py-1.5 rounded-full border border-border hover:bg-secondary/40 inline-flex items-center gap-1.5",children:[e.jsx(de,{className:"w-3.5 h-3.5"})," Import CSV"]}),e.jsxs("button",{onClick:()=>f("new-station"),className:"text-xs px-3 py-1.5 rounded-full border border-border hover:bg-secondary/40 inline-flex items-center gap-1.5",children:[e.jsx(ae,{className:"w-3.5 h-3.5"})," Add station"]}),e.jsxs("button",{onClick:r,disabled:!j.length,className:"text-xs px-3 py-1.5 rounded-full border border-border hover:bg-secondary/40 disabled:opacity-40 inline-flex items-center gap-1.5",children:[e.jsx(D,{className:"w-3.5 h-3.5"})," Export"]})]})]}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-px bg-border/60",children:[{label:"Spins",v:b.total_spins},{label:"Stations",v:b.stations},{label:"Countries",v:b.countries},{label:"Tracks played",v:b.tracks}].map(t=>e.jsxs("div",{className:"bg-card px-5 py-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-muted-foreground font-bold",children:t.label}),e.jsx("div",{className:"font-mono text-2xl font-black tabular-nums",children:t.v.toLocaleStr
2ing()})]},t.label))}),x&&!p?e.jsx("div",{className:"p-5 text-sm text-muted-foreground",children:"Loading radio dataâ¦"}):b.total_spins===0?e.jsxs("div",{className:"p-8 text-center",children:[e.jsx(A,{className:"w-8 h-8 mx-auto mb-2 text-muted-foreground"}),e.jsx("div",{className:"font-bold mb-1",children:"No spins detected yet"}),e.jsx("div",{className:"text-xs text-muted-foreground max-w-md mx-auto",children:"Our background monitor scans internet radio streams for your tracks. You can also log a spin manually when a station tells you, or upload a station's playlist CSV to backfill history."})]}):e.jsxs("div",{className:"p-5 space-y-5",children:[e.jsx("div",{className:"rounded-xl overflow-hidden border border-border",children:e.jsx(se,{points:y,height:420})}),w.length>1&&e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-bold uppercase tracking-wider text-muted-foreground mb-2",children:"Spins per day"}),e.jsx("div",{className:"flex items-end gap-0.5 h-20",children:w.map(t=>e.jsx("div",{className:"flex-1 bg-primary/70 hover:bg-primary rounded-sm",style:{height:`${t.spins/o*100}%`},title:`${t.day}: ${t.spins} spins`},t.day))})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-5",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-bold uppercase tracking-wider text-muted-foreground mb-2",children:"Top stations"}),e.jsx("div",{className:"space-y-1",children:k.map(t=>e.jsxs("div",{className:"flex items-center gap-2 text-xs px-3 py-2 rounded-lg bg-secondary/20 border border-border/60",children:[t.country_code&&e.jsx(C,{code:t.country_code,size:"xs"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"font-bold truncate",children:[t.callsign?`${t.callsign} · `:"",t.name]}),e.jsx("div",{className:"text-[10px] text-muted-foreground truncate",children:[t.frequency,t.band?.toUpperCase(),t.format].filter(Boolean).join(" · ")})]}),e.jsx("div",{className:"font-mono text-sm font-black tabular-nums",children:t.spins})]},t.station_id))})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-bold uppercase tracking-wider text-muted-foreground mb-2",children:"Top markets"}),e.jsx("div",{className:"space-y-1",children:_.map((t,a)=>e.jsxs("div",{className:"flex items-center gap-2 text-xs px-3 py-2 rounded-lg bg-secondary/20 border border-border/60",children:[t.country_code&&e.jsx(C,{code:t.country_code,size:"xs"}),e.jsx("div",{className:"flex-1 min-w-0 font-semibold truncate",children:t.city}),e.jsx("div",{className:"font-mono text-sm tabular-nums",children:t.spins})]},a))})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-bold uppercase tracking-wider text-muted-foreground mb-2",children:"Recent spins"}),e.jsx("div",{className:"overflow-x-auto rounded-xl border border-border",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-secondary/30 text-[10px] uppercase tracking-wider text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left px-4 py-2",children:"When"}),e.jsx("th",{className:"text-left px-4 py-2",children:"Station"}),e.jsx("th",{className:"text-left px-4 py-2 hidden sm:table-cell",children:"Where"}),e.jsx("th",{className:"text-left px-4 py-2",children:"Track"}),e.jsx("th",{className:"text-left px-4 py-2 hidden md:table-cell",children:"Method"})]})}),e.jsx("tbody",{children:j.slice(0,30).map(t=>e.jsxs("tr",{className:"border-t border-border hover:bg-secondary/20",children:[e.jsx("td",{className:"px-4 py-2 text-xs text-muted-foreground whitespace-nowrap",children:new Date(t.played_at).toLocaleString()}),e.jsxs("td",{className:"px-4 py-2 truncate max-w-[180px] font-semibold",children:[t.station?.callsign?`${t.station.callsign} · `:"",t.station?.name]}),e.jsx("td",{className:"px-4 py-2 hidden sm:table-cell text-xs",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[t.station?.country_code&&e.jsx(C,{code:t.station.country_code,size:"xs"}),e.jsx("span",{className:"truncate",children:t.station?.city??t.station?.country_code??"â"})]})}),e.jsx("td",{className:"px-4 py-2 truncate max-w-[220px]",children:t.track?.title??t.now_playing_title??"â"}),e.jsx("td",{className:"px-4 py-2 hidden md:table-cell",children:e.jsx("span",{className:"text-[10px] uppercase tracking-wider px-2 py-0.5 rounded-full bg-primary/15 text-primary font-bold",children:t.detection_method})})]},t.id))})]})})]})]}),h&&e.jsx(Pe,{mode:h,onClose:()=>f(null),onDone:()=>{f(null),n.invalidateQueries({queryKey:["radio-airplay"]})}})]})}function Pe({mode:s,onClose:l,onDone:n}){const p=P(Le),x=P(Re),h=P($e),f=P(qe),[y,b]=g.useState(!1),[k,_]=g.useState(""),[j,w]=g.useState([]),[o,r]=g.useState(null),[t,a]=g.useState(""),[c,d]=g.useState([]),[m,v]=g.useState(null),N=g.useRef(null),[u,L]=g.useState({band:"fm",country_code:"US"});g.useEffect(()=>{s==="log"&&W.from("tracks").select("id, title, cover_url").order("created_at",{ascending:!1}).limit(50).then(({data:i})=>d(i??[]))},[s]);const re=async i=>{if(_(i),i.length<2){w([]);return}const z=await p({data:{q:i}});w(z)},ne=async()=>
2{if(!o||!m)return S.error("Pick a station and a track");b(!0);try{await x({data:{station_id:o,track_id:m}}),S.success("Spin logged"),n()}catch(i){S.error(i.message)}finally{b(!1)}},le=async()=>{const i=N.current?.files?.[0];if(!i)return S.error("Pick a file");const z=await i.text();b(!0);try{const M=await h({data:{csv:z}});S.success(`Imported ${M.inserted} spins (${M.skipped} skipped)`),M.errors.length&&S.warning(M.errors.slice(0,3).join("; ")),n()}catch(M){S.error(M.message)}finally{b(!1)}},oe=async()=>{if(!u.name)return S.error("Station name is required");b(!0);try{await f({data:u}),S.success("Station added"),n()}catch(i){S.error(i.message)}finally{b(!1)}};return e.jsx("div",{className:"fixed inset-0 z-50 grid place-items-center bg-background/80 backdrop-blur p-4",onClick:l,children:e.jsxs("div",{className:"w-full max-w-lg rounded-2xl border border-border bg-card p-5 space-y-4",onClick:i=>i.stopPropagation(),children:[e.jsxs("div",{className:"font-display text-lg font-black",children:[s==="log"&&"Log a radio spin",s==="csv"&&"Import station playlist CSV",s==="new-station"&&"Add a radio station"]}),s==="log"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider font-bold text-muted-foreground mb-1",children:"Station"}),o?e.jsxs("div",{className:"flex items-center justify-between p-2 rounded-lg border border-border bg-secondary/30",children:[e.jsx("span",{className:"text-sm font-semibold",children:t}),e.jsx("button",{className:"text-xs underline",onClick:()=>{r(null),a("")},children:"change"})]}):e.jsxs(e.Fragment,{children:[e.jsx("input",{value:k,onChange:i=>re(i.target.value),placeholder:"Callsign or name (e.g. WQHT, Kiss FM)",className:"w-full px-3 py-2 rounded-lg bg-secondary/40 border border-border text-sm"}),e.jsxs("div",{className:"mt-1 max-h-40 overflow-y-auto space-y-1",children:[j.map(i=>e.jsxs("button",{onClick:()=>{r(i.id),a(`${i.callsign??""} ${i.name}`.trim())},className:"block w-full text-left text-xs px-2 py-1.5 rounded hover:bg-secondary/50",children:[e.jsxs("span",{className:"font-bold",children:[i.callsign??""," "]}),i.name," ",e.jsxs("span",{className:"text-muted-foreground",children:["· ",i.country_code??""]})]},i.id)),k.length>=2&&j.length===0&&e.jsx("div",{className:"text-xs text-muted-foreground italic px-2 py-1",children:'No match. Click "Add station" first.'})]})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider font-bold text-muted-foreground mb-1",children:"Track"}),e.jsxs("select",{value:m??"",onChange:i=>v(i.target.value||null),className:"w-full px-3 py-2 rounded-lg bg-secondary/40 border border-border text-sm",children:[e.jsx("option",{value:"",children:"Chooseâ¦"}),c.map(i=>e.jsx("option",{value:i.id,children:i.title},i.id))]})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{onClick:l,className:"text-xs px-3 py-1.5 rounded-full border border-border",children:"Cancel"}),e.jsx("button",{disabled:y,onClick:ne,className:"text-xs px-3 py-1.5 rounded-full bg-primary text-primary-foreground font-bold disabled:opacity-50",children:"Log spin"})]})]}),s==="csv"&&e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:["CSV columns: ",e.jsx("code",{children:"callsign, station, country, track, played_at"}),". Either ",e.jsx("code",{children:"callsign"})," or ",e.jsx("code",{children:"station"})," is required. Tracks are matched by title against your catalog."]}),e.jsx("input",{ref:N,type:"file",accept:".csv,text/csv",className:"text-xs w-full"}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{onClick:l,className:"text-xs px-3 py-1.5 rounded-full border border-border",children:"Cancel"}),e.jsx("button",{disabled:y,onClick:le,className:"text-xs px-3 py-1.5 rounded-full bg-primary text-primary-foreground font-bold disabled:opacity-50",children:"Import"})]})]}),s==="new-station"&&e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsx("input",{placeholder:"Station name *",className:"w-full px-3 py-2 rounded-lg bg-secondary/40 border border-border text-sm",onChange:i=>L({...u,name:i.target.value})}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("input",{placeholder:"Callsign (e.g. WQHT)",className:"px-3 py-2 rounded-lg bg-secondary/40 border border-border text-sm",onChange:i=>L({...u,callsign:i.target.value})}),e.jsx("input",{placeholder:"Frequency (e.g. 97.1)",className:"px-3 py-2 rounded-lg bg-secondary/40 border border-border text-sm",onChange:i=>L({...u,frequency:i.target.value})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("select",{value:u.band,onChange:i=>L({...u,band:i.target.value}),className:"px-3 py-2 rounded-lg bg-secondary/40 border border-border text-sm",children:[e.jsx("option",{value:"fm",children:"FM"}),e.jsx("option",{value:"am",children:"AM"}),e.jsx("option",{value:"internet",children:"Internet"}),e.jsx("option",{value:"satellite",children:"Satellite"}),e.jsx("option",{value:"dab",children:"DAB"})]}),e.jsx("input",{placeholder:"City",className:"px-3 py-2 rounded-lg bg-secondary/40 border border-border text-sm",onChange:i=>L({...u,city:i.target.value})}),e.jsx("input",{placeholder:"Country (US)",maxLength:2,defaultValue:"US",className:"px-3 py-2 rounded-lg bg-secondary/40 border border-border text-sm uppercase",onChange:i=>L({...u,country_code:i.target.value.toUpperCase()})})]}),e.jsx("input",{placeholder:"Format (e.g. Hip-Hop, Top 40)",className:"w-full px-3 py-2 rounded-lg bg-secondary/40 border border-border text-sm",onChange:i=>L({...u,format:i.target.value})}),e.jsx("input",{placeholder:"Stream URL (helps live monitoring)",className:"w-full px-3 py-2 rounded-lg bg-secondary/40 border border-border text-sm",onChange:i=>L({...u,stream_url:i.target.value||null})}),e.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[e.jsx("button",{onClick:l,className:"text-xs px-3 py-1.5 rounded-full border border-border",children:"Cancel"}),e.jsx("button",{disabled:y,onClick:oe,className:"text-xs px-3 py-1.5 rounded-full bg-primary text-primary-foreground font-bold disabled:opacity-50",children:"Add station"})]})]})]})})}const Me=[{d:7,label:"7d"},{d:30,label:"30d"},{d:90,label:"90d"},{d:365,label:"12mo"}];function Ye(){const s=me(),[l,n]=g.useState(30),p=P(je),x=J(),{data:h,isLoading:f}=Q({queryKey:["my-data",l],queryFn:()=>p({data:{days:l}}),enabled:!!s,refetchInterval:1e4,refetchOnWindowFocus:!0});return g.useEffect(()=>{if(!s)return;const y=W.channel("data-warehouse-live").on("postgres_changes",{event:"INSERT",schema:"public",table:"track_plays"},()=>x.invalidateQueries({queryKey:["my-data"]})).on("postgres_changes",{event:"INSERT",schema:"public",table:"video_plays"},()=>x.invalidateQueries({queryKey:["my-data"]})).on("postgres_changes",{event:"INSERT",schema:"public",table:"content_clicks"},()=>x.invalidateQueries({queryKey:["my-data"]})).subscribe();return()=>{W.removeChannel(y)}},[s,x]),e.jsx(he,{profile:s,title:"Data",subtitle:"Every play, click, share, and listener â anywhere in the world.",children:e.jsx(Te,{data:h,loading:f,days:l,setDays:n,adminLink:s?.role==="super_admin",afterKpis:e.jsxs(e.Fragment,{children:[e.jsx(Se,{days:l}),e.jsx(Fe,{days:l})]})})})}function Te({data:s,loading:l,days:n,setDays:p,adminLink:x,scopeBar:h,afterKpis:f}){const y=s?.kpis??{total_plays:0,video_plays:0,qualified:0,unique_listeners:0,repeats:0,shares:0,clicks:0},b=g.useMemo(()=>{const o=s?.geo??[],r=new Map;for(const c of o)r.set(c.country_code??"?",(r.get(c.country_code??"?")??0)+c.plays);let t=null,a=0;for(const[c,d]of r)d>a&&(a=d,t=c);return t},[s]),k=g.useMemo(()=>{const o=new Map,r=(t,a)=>{const c=t.country||t.country_code;if(!c)return;const d=B(c);if(!d)return;const m=t.city||d.name,v=`${c}|${m}`,N=ge(v),u=o.get(v)??{country_code:c,country_name:d.name,region:t.region??null,city:m,plays:0,events:[],lat:d.lat+N.dLat,lng:d.lng+N.dLng,listeners:new Set,shares:0,repeats:0};u.plays+=1,u.events.push(a),a.who&&u.listeners.add(a.who),o.set(v,u)};for(const t of s?.play_log??[])r(t,{kind:"song",title:t.title,who:t.listener,ip:t.ip_hash??null,region:t.region??null,city:t.city,country:t.country,country_code:t.country,seconds:t.seconds,qualified:t.qualified,at:t.played_at});for(const t of s?.video_log??[])r(t,{kind:"video",title:t.title,who:t.viewer,ip:t.ip_hash,region:t.region??null,city:t.city,country:t.country,country_code:t.country,seconds:t.seconds,qualified:t.qualified,at:t.played_at});for(const t of s?.click_log??[]){const a=t.target_type==="video"?"video":t.target_type==="podcast"?"podcast":t.target_type==="track"?"song":"click";r(t,{kind:a,title:t.title,ip:t.ip_hash,region:t.region??null,city:t.city,country:t.country,country_code:t.country,at:t.created_at})}for(const t of o.values())t.events.sort((a,c)=>c.at.localeCompare(a.at));return Array.from(o.values()).map(t=>({city:t.city,country:t.country_name,country_code:t.country_code,region:t.region,plays:t.plays,listeners:t.listeners.size,shares:t.shares,repeats:t.repeats,lat:t.lat,lng:t.lng,events:t.events}))},[s]),_=g.useMemo(()=>{const o=s?.geo??[],r=new Map;for(const t of o){if(!t.country_code)continue;const a=t.country_code,c=r.get(a)??{code:a,name:t.country_name||B(a)?.name||a,plays:0,listeners:0};c.plays+=Number(t.plays||0),c.listeners+=Number(t.unique_listeners||0),r.set(a,c)}return Array.from(r.values()).sort((t,a)=>a.plays-t.plays)},[s]);function j(o,r){if(!r.length)return;const t=Object.keys(r[0]),a=N=>{const u=N==null?"":String(N);return/[",\n]/.test(u)?`"${u.replace(/"/g,'""')}"`:u},c=[t.join(","),...r.map(N=>t.map(u=>a(N[u])).join(","))].join(`
3`),d=new Blob([c],{type:"text/csv;charset=utf-8"}),m=URL.createObjectURL(d),v=document.createElement("a");v.href=m,v.download=`mostreams-${o}-${n}d-${new Date().toISOString().slice(0,10)}.csv`,v.click(),URL.revokeObjectURL(m)}function w(){const o=[{name:"kpis",rows:[y]},{name:"tracks",rows:s?.tracks??[]},{name:"videos",rows:s?.videos??[]},{name:"geo",rows:s?.geo??[]},{name:"play_log",rows:s?.play_log??[]},{name:"video_log",rows:s?.video_log??[]},{name:"share_log",rows:s?.share_log??[]},{name:"click_log",rows:s?.click_log??[]}],r=[];for(const d of o){if(r.push(`# ${d.name}`),!d.rows.length){r.push("");continue}const m=Object.keys(d.rows[0]),v=N=>{const u=N==null?"":String(N);return/[",\n]/.test(u)?`"${u.replace(/"/g,'""')}"`:u};r.push(m.join(","));for(const N of d.rows)r.push(m.map(u=>v(N[u])).join(","));r.push("")}const t=new Blob([r.join(` 4`)],{type:"text/csv;charset=utf-8"}),a=URL.createObjectURL(t),c=document.createElement("a");c.href=a,c.download=`mostreams-data-report-${n}d-${new Date().toISOString().slice(0,10)}.csv`,c.click(),URL.revokeObjectURL(a)}return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"inline-flex rounded-full border border-border bg-card p-1",children:Me.map(o=>e.jsx("button",{onClick:()=>p(o.d),className:`px-3 h-8 rounded-full text-xs font-bold uppercase tracking-wider transition-colors ${n===o.d?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"}`,children:o.label},o.d))}),e.jsxs("div",{className:"flex items-center gap-2",children:[h,e.jsxs("button",{onClick:w,className:"inline-flex items-center gap-2 px-3 h-9 rounded-full bg-primary text-primary-foreground text-xs font-bold uppercase tracking-wider hover:opacity-90",children:[e.jsx(D,{className:"w-3.5 h-3.5"})," Download report"]}),x&&e.jsx(V,{to:"/mc-60e9ca6cf6/data-warehouse",className:"text-xs font-bold uppercase tracking-wider text-primary",children:"Data Warehouse â"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(q,{icon:Z,label:"Song plays",value:y.total_plays,sub:`${n}d`}),e.jsx(q,{icon:ee,label:"Video plays",value:y.video_plays}),e.jsx(q,{icon:xe,label:"Qualified (30s+)",value:y.qualified}),e.jsx(q,{icon:Y,label:"Unique listeners",value:y.unique_listeners}),e.jsx(q,{icon:pe,label:"Repeats",value:y.repeats}),e.jsx(q,{icon:K,label:"Shares",value:y.shares}),e.jsx(q,{icon:te,label:"Clicks",value:y.clicks}),e.jsx(q,{icon:A,label:"Top country",value:b??"â"})]}),f,e.jsx(R,{title:"Worldwide listeners",subtitle:"Live globe â every play, plotted by satellite IP · auto-refresh 10s",children:k.length===0?e.jsxs("div",{className:"px-5 py-12 text-center text-sm text-muted-foreground",children:[e.jsx(A,{className:"w-8 h-8 mx-auto mb-3 text-muted-foreground/50"}),"No geo-tagged plays yet. As listeners stream, their countries will light up here."]}):e.jsxs("div",{className:"p-3",children:[e.jsx(ue,{points:k.map(o=>({city:o.city,country:o.country,country_code:o.country_code,region:o.region,plays:o.plays,lat:o.lat,lng:o.lng,listeners:o.listeners,latest_asset:o.events?.[0]?.title??null,latest_at:o.events?.[0]?.at??null,ip_raw:o.events?.[0]?.ip??null})),height:560,defaultMode:"satellite",showIp:!!x}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-3 text-[10px] uppercase tracking-wider text-muted-foreground",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-[#f97316]"})," Song play"]}),e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-[#fb923c]"})," Video play"]}),e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-[#fbbf24]"})," Podcast click"]}),e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-[#fde047]"})," Other click"]})]}),_.length>0&&e.jsx("div",{className:"mt-4 grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-2",children:_.slice(0,12).map(o=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl border border-border bg-secondary/20 px-3 py-2",children:[e.jsx(C,{code:o.code,name:o.name,size:"md"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-bold truncate",children:o.name}),e.jsxs("div",{className:"text-[10px] uppercase tracking-wider text-muted-foreground",children:[o.listeners," listeners"]})]}),e.jsx("div",{className:"font-mono text-sm font-black tabular-nums",children:o.plays.toLocaleStr
4ing()})]},o.code))})]})}),e.jsx(ze,{plays:s?.play_log??[],videos:s?.video_log??[],clicks:s?.click_log??[]}),e.jsx(Oe,{rows:s?.share_log??[],onCsv:()=>j("social_shares",s?.share_log??[])}),l&&e.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading dataâ¦"}),e.jsx(R,{title:"Songs",subtitle:"Per-track performance",action:e.jsx(F,{onClick:()=>j("tracks",s?.tracks??[])}),children:e.jsx(H,{rows:s?.tracks??[],kind:"track"})}),e.jsx(R,{title:"Videos",subtitle:"Per-video performance",action:e.jsx(F,{onClick:()=>j("videos",s?.videos??[])}),children:e.jsx(H,{rows:s?.videos??[],kind:"video"})}),e.jsx(R,{title:"Geography",subtitle:"State, region, and city â where your fans are",action:e.jsx(F,{onClick:()=>j("geo",s?.geo??[])}),children:e.jsx(Ie,{rows:s?.geo??[]})}),e.jsx(R,{title:"Recent plays",subtitle:"Every play, timestamped",action:e.jsx(F,{onClick:()=>j("play_log",s?.play_log??[])}),children:e.jsx(Ee,{rows:s?.play_log??[]})}),e.jsx(R,{title:"Recent video plays",subtitle:"Watch sessions with IP hash",action:e.jsx(F,{onClick:()=>j("video_log",s?.video_log??[])}),children:e.jsx(Ae,{rows:s?.video_log??[]})}),e.jsx(R,{title:"Shares",subtitle:"Where your music is getting pushed",action:e.jsx(F,{onClick:()=>j("share_log",s?.share_log??[])}),children:e.jsx(Ue,{rows:s?.share_log??[]})}),e.jsx(R,{title:"Clicks",subtitle:"Every click on your tracks, beats, videos",action:e.jsx(F,{onClick:()=>j("click_log",s?.click_log??[])}),children:e.jsx(De,{rows:s?.click_log??[]})})]})}function q({icon:s,label:l,value:n,sub:p}){return e.jsxs("div",{className:"rounded-2xl border border-border bg-card p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.18em] text-muted-foreground",children:[e.jsx(s,{className:"w-3.5 h-3.5 text-primary"})," ",l]}),e.jsx("div",{className:"mt-2 font-display text-2xl font-black truncate",children:typeof n=="number"?n.toLocaleString():n||"â"}),p&&e.jsx("div",{className:"text-[10px] text-muted-foreground mt-0.5",children:p})]})}function R({title:s,subtitle:l,action:n,children:p}){return e.jsxs("div",{className:"rounded-2xl border border-border bg-card overflow-hidden",children:[e.jsxs("div",{className:"px-5 py-4 border-b border-border flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-bold uppercase tracking-wider text-muted-foreground",children:l}),e.jsx("div",{className:"font-display text-lg font-black",children:s})]}),n]}),p]})}function F({onClick:s}){return e.jsxs("button",{onClick:s,className:"inline-flex items-center gap-1.5 px-3 h-8 rounded-full border border-border text-[11px] font-bold uppercase tracking-wider hover:bg-secondary/40",children:[e.jsx(D,{className:"w-3.5 h-3.5"})," CSV"]})}function H({rows:s,kind:l}){return s.length?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-secondary/30 text-[10px] uppercase tracking-wider text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left px-5 py-3",children:"Title"}),e.jsx("th",{className:"text-right px-5 py-3",children:"Plays"}),e.jsx("th",{className:"text-right px-5 py-3 hidden sm:table-cell",children:"Qualified"}),e.jsx("th",{className:"text-right px-5 py-3 hidden sm:table-cell",children:"Repeats"}),e.jsx("th",{className:"text-right px-5 py-3 hidden md:table-cell",children:"Shares"}),e.jsx("th",{className:"text-right px-5 py-3 hidden md:table-cell",children:"Clicks"}),e.jsx("th",{className:"text-left px-5 py-3 hidden lg:table-cell",children:"Top country"}),e.jsx("th",{className:"text-left px-5 py-3 hidden lg:table-cell",children:"Last play"})]})}),e.jsx("tbody",{children:s.map(n=>e.jsxs("tr",{className:"border-t border-border hover:bg-secondary/20",children:[e.jsx("td",{className:"px-5 py-3 truncate max-w-[260px]",children:n.title}),e.jsx("td",{className:"px-5 py-3 text-right font-mono",children:Number(n.plays||0).toLocaleString()}),e.jsx("td",{className:"px-5 py-3 text-right font-mono hidden sm:table-cell",children:Number(n.qualified||0).toLocaleStr
4ing()}),e.jsx("td",{className:"px-5 py-3 text-right font-mono hidden sm:table-cell",children:Number(n.repeats||0).toLocaleString()}),e.jsx("td",{className:"px-5 py-3 text-right font-mono hidden md:table-cell",children:Number(n.shares||0).toLocaleString()}),e.jsx("td",{className:"px-5 py-3 text-right font-mono hidden md:table-cell",children:Number(n.clicks||0).toLocaleString()}),e.jsx("td",{className:"px-5 py-3 text-muted-foreground hidden lg:table-cell",children:n.top_country??"â"}),e.jsx("td",{className:"px-5 py-3 text-muted-foreground hidden lg:table-cell",children:n.last_played_at?new Date(n.last_played_at).toLocaleString():"â"})]},n.id))})]})}):e.jsx($,{children:`No ${l} plays yet.`})}function Ie({rows:s}){return s.length?e.jsx("div",{className:"overflow-x-auto max-h-[420px] overflow-y-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-secondary/30 text-[10px] uppercase tracking-wider text-muted-foreground sticky top-0",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left px-5 py-3",children:"Country"}),e.jsx("th",{className:"text-left px-5 py-3 hidden md:table-cell",children:"State / Region"}),e.jsx("th",{className:"text-left px-5 py-3",children:"City"}),e.jsx("th",{className:"text-right px-5 py-3",children:"Plays"}),e.jsx("th",{className:"text-right px-5 py-3",children:"Unique listeners"})]})}),e.jsx("tbody",{children:s.map((l,n)=>e.jsxs("tr",{className:"border-t border-border",children:[e.jsx("td",{className:"px-5 py-3",children:e.jsxs("span",{className:"inline-flex items-center gap-2",children:[l.country_code&&e.jsx(C,{code:l.country_code,name:l.country_name,size:"sm"}),l.country_name||l.country_code||"â"]})}),e.jsx("td",{className:"px-5 py-3 text-muted-foreground hidden md:table-cell",children:l.region||"â"}),e.jsx("td",{className:"px-5 py-3 text-muted-foreground",children:l.city||"â"}),e.jsx("td",{className:"px-5 py-3 text-right font-mono",children:Number(l.plays).toLocaleString()}),e.jsx("td",{className:"px-5 py-3 text-right font-mono",children:Number(l.unique_listeners).toLocaleString()})]},n))})]})}):e.jsx($,{children:"No geo data yet."})}function Ee({rows:s}){return s.length?e.jsx(O,{rows:s,cols:["played_at","title","listener","country","region","city","ip_hash","seconds","qualified"]}):e.jsx($,{children:"No plays yet."})}function Ae({rows:s}){return s.length?e.jsx(O,{rows:s,cols:["played_at","title","viewer","country","region","city","ip_hash","seconds","qualified"]}):e.jsx($,{children:"No video plays yet."})}function Ue({rows:s}){return s.length?e.jsx(O,{rows:s,cols:["created_at","platform","target_type","title"]}):e.jsx($,{children:"No shares yet."})}function De({rows:s}){return s.length?e.jsx(O,{rows:s,cols:["created_at","target_type","title","country","region","city","ip_hash"]}):e.jsx($,{children:"No clicks yet."})}function O({rows:s,cols:l}){return e.jsx("div",{className:"overflow-x-auto max-h-[480px] overflow-y-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"bg-secondary/30 text-[10px] uppercase tracking-wider text-muted-foreground sticky top-0",children:e.jsx("tr",{children:l.map(n=>e.jsx("th",{className:"text-left px-4 py-2 whitespace-nowrap",children:n.replace(/_/g," ")},n))})}),e.jsx("tbody",{children:s.map((n,p)=>e.jsx("tr",{className:"border-t border-border",children:l.map(x=>e.jsx("td",{className:"px-4 py-2 whitespace-nowrap text-muted-foreground",children:x==="played_at"||x==="created_at"?n[x]?new Date(n[x]).toLocaleString():"â":n[x]===!0?"yes":n[x]===!1?"no":n[x]??"â"},x))},p))})]})})}function $({children:s}){return e.jsx("div",{className:"px-5 py-10 text-center text-sm text-muted-foreground",children:s})}function Oe({rows:s,onCsv:l}){const n=g.useMemo(()=>{const x=new Map;for(const h of s){const f=(h.platform||"other").toLowerCase();x.set(f,(x.get(f)??0)+1)}return Array.from(x.entries()).map(([h,f])=>({platform:h,count:f})).sort((h,f)=>f.count-h.count)}
4,[s]),p=s.length;return e.jsxs("div",{className:"rounded-2xl border border-border bg-card overflow-hidden",children:[e.jsxs("div",{className:"px-5 py-4 border-b border-border flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"text-xs font-bold uppercase tracking-wider text-muted-foreground",children:[p.toLocaleString()," shares â by social platform"]}),e.jsxs("div",{className:"font-display text-lg font-black flex items-center gap-2",children:[e.jsx(K,{className:"w-4 h-4 text-primary"})," Social shares"]})]}),e.jsxs("button",{onClick:l,className:"inline-flex items-center gap-1.5 px-3 h-8 rounded-full border border-border text-[11px] font-bold uppercase tracking-wider hover:bg-secondary/40",children:[e.jsx(D,{className:"w-3.5 h-3.5"})," CSV"]})]}),n.length?e.jsx("div",{className:"p-4 grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-5 gap-2",children:n.map(x=>e.jsxs("div",{className:"rounded-xl border border-border bg-secondary/20 px-3 py-2",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-muted-foreground truncate",children:x.platform}),e.jsx("div",{className:"font-mono text-lg font-black tabular-nums",children:x.count.toLocaleString()}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[p?Math.round(x.count/p*100):0,"% of shares"]})]},x.platform))}):e.jsx($,{children:"No shares yet."})]})}function ze({plays:s,videos:l,clicks:n}){const[p,x]=g.useState("all"),h=g.useMemo(()=>{const r=[],t=a=>a?B(a)?.name??a:null;for(const a of s)r.push({at:a.played_at,kind:"song",title:a.title,who:a.listener,place:[a.city,a.region].filter(Boolean).join(", ")||t(a.country)||"â",country_code:a.country??null,country_name:t(a.country),ip:a.ip_hash??null,seconds:a.seconds,qualified:a.qualified});for(const a of l)r.push({at:a.played_at,kind:"video",title:a.title,who:a.viewer,place:[a.city,a.region].filter(Boolean).join(", ")||t(a.country)||"â",country_code:a.country??null,country_name:t(a.country),ip:a.ip_hash,seconds:a.seconds,qualified:a.qualified});for(const a of n){const c=a.target_type==="video"?"video":a.target_type==="podcast"?"podcast":a.target_type==="track"?"song":"click";r.push({at:a.created_at,kind:c,title:a.title,who:"guest",place:[a.city,a.region].filter(Boolean).join(", ")||t(a.country)||"â",country_code:a.country??null,country_name:t(a.country),ip:a.ip_hash})}return r.sort((a,c)=>(c.at||"").localeCompare(a.at||"")),r.slice(0,200)},[s,l,n]),f=g.useMemo(()=>p==="all"?h:h.filter(r=>r.kind===p),[h,p]),y=g.useMemo(()=>{const r={all:h.length,song:0,video:0,podcast:0,click:0};for(const t of h)r[t.kind]++;return r},[h]),[b,k]=g.useState(0);g.useEffect(()=>{const r=setInterval(()=>k(t=>t+1),1e3);return()=>clearInterval(r)},[]);const _=b%30,j={song:"bg-orange-500",video:"bg-orange-400",podcast:"bg-amber-300",click:"bg-yellow-300"},w={song:Z,video:ee,podcast:fe,click:te},o={song:"ðµ",video:"ð¬",podcast:"ðï¸",click:"ð"};return e.jsxs("div",{className:"rounded-2xl border border-primary/30 bg-gradient-to-br from-black via-card to-black overflow-hidden shadow-[0_0_40px_-15px_rgba(249,115,22,0.4)]",children:[e.jsxs("div",{className:"px-5 py-4 border-b border-primary/30 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"text-[10px] font-bold uppercase tracking-[0.2em] text-primary flex items-center gap-2",children:[e.jsx(X,{className:"w-3 h-3 animate-pulse"})," Live worldwide stream · realtime"]}),e.jsx("div",{className:"font-display text-lg font-black",children:"Every play, click & stream â as it happens"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"text-[10px] uppercase tracking-wider text-muted-foreground inline-flex items-center gap-1.5",children:[e.jsx(ye,{className:"w-3 h-3 text-primary animate-pulse"})," Live · ",h.length," events"]}),e.jsx("div",{className:"h-1.5 w-24 rounded-full bg-secondary/40 overflow-hidden",children:e.jsx("div",{className:"h-full bg-primary transition-all",style:{width:`${_/30*100}%`}})})]})]}),e.jsx("div",{className:"px-5 py-2 border-b border-border/50 flex flex-wrap gap-1.5",children:[{v:"all",label:"All",n:y.all},{v:"song",label:"ðµ Songs",n:y.song},{v:"video",label:"ð¬ Videos",n:y.video},{v:"podcast",label:"ðï¸ Podcasts",n:y.podcast},{v:"click",label:"ð Clicks",n:y.click}].map(r=>e.jsxs("button",{onClick:()=>x(r.v),className:`px-2.5 h-7 rounded-full text-[10px] font-bold uppercase tracking-wider transition ${p===r.v?"bg-primary text-primary-foreground":"bg-secondary/40 text-muted-foreground hover:text-foreground"}`,children:[r.label," ",e.jsx("span",{className:"opacity-70 ml-1",children:r.n})]},r.v))}),f.length===0?e.jsx($,{children:"Waiting on the first listenerâ¦"}):e.jsx("div",{className:"max-h-[440px] overflow-y-auto divide-y divide-border/50",children:f.map((r,t)=>{const a=w[r.kind];return e.jsxs("div",{className:"px-5 py-3 flex items-center gap-3 hover:bg-secondary/20",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${j[r.kind]} animate-pulse shrink-0`}),e.jsx(a,{className:"w-3.5 h-3.5 text-primary shrink-0"}),e.jsx("span",{className:"text-base leading-none shrink-0","aria-hidden":!0,
4children:o[r.kind]}),r.country_code&&e.jsx(C,{code:r.country_code,name:r.country_name??void 0,size:"sm"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-bold truncate",children:r.title}),e.jsxs("div",{className:"text-[10px] uppercase tracking-wider text-muted-foreground truncate",children:[r.who," · ",r.place,r.country_name&&!r.place.includes(r.country_name)?`, ${r.country_name}`:"",r.ip?` · IP ${r.ip}`:"",r.seconds?` · ${r.seconds}s`:"",r.qualified?" · â":""]})]}),e.jsx("div",{className:"text-[10px] font-mono tabular-nums text-muted-foreground shrink-0",children:r.at?new Date(r.at).toLocaleTimeString():"â"})]},t)})})]})}export{Te as DataView,Ye as component};
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.