1import{j as e}from"./query-CHDd9xWM.js";import{u as Ie,f as Ee,r as c}from"./react-vendor-iR8l3MlE.js";import{r as oe,F as Ue}from"./Audience-Dv69Bjeq.js";import{S as Oe,a as Be,b as $e,c as Ge,d as ce}from"./select-BwrT_wcJ.js";import{a as qe,d as ze,u as Ke,s as y,F as We,v as Ye}from"./index-QkQHgx4Z.js";import{u as Xe}from"./useTargetUser-CxFQnumS.js";import{P as Qe}from"./PaidFeatureGate-BJjPxAmd.js";import{s as O,A as Ve}from"./AppLayout3-CTI9xvYs.js";import{u as He}from"./useAccountType-DdZ4Ahti.js";import{m as T}from"./motion--e7AmMHx.js";import{M as Je}from"./mouse-pointer-click-DYa40T-f.js";import{R as Q,A as Ze,X as de,Y as me,T as fe,a as es,P as ss,e as ts,d as as,B as ls,b as is}from"./charts-ROjd8s19.js";import{U as ns}from"./users-jRa2RaTL.js";import{G as ue}from"./globe-B0b3nacl.js";import{T as rs}from"./trending-up-DTCiipq2.js";import{s as os,f as B}from"./format-CZaY-Cw5.js";import"./feature-gates-CK3Zovmi.js";import"./arrow-up-CAO02EsK.js";import"./arrow-down-Db3t7Va9.js";import"./chart-column-B7crDsh2.js";import"./radix-DFsJdaPX.js";import"./supabase-92svyh75.js";import"./chevron-up-C1fRqr1H.js";import"./useAdmin-B76xPrYc.js";import"./scroll-area-WFUhVwGV.js";import"./ThemeToggle-1m08e_W7.js";import"./sun-GqUDPmK2.js";import"./bell-DvlGxNjD.js";import"./megaphone-Bc-bPFYk.js";import"./settings-B-Ekg2Wq.js";import"./Messenger-C1LAec33.js";import"./textarea-V3ptMj4z.js";import"./message-square-DUJyyXLe.js";import"./en-US-C5RZswbt.js";import"./file-text-BPfaR0N5.js";import"./index-Dzzq0hvN.js";import"./trash-2-BaJzVAPR.js";import"./external-link-yZcfNfn1.js";import"./gift-B6BXdscY.js";import"./user-h38L-V2d.js";import"./folder-open-0lJ3znjg.js";import"./plus-bkD7-Vn4.js";import"./link-CBUaYhHk.js";import"./search-Cr-fd5Qe.js";import"./disc-3-CK__ICjk.js";import"./calendar-BqiZCOQP.js";import"./list-music-BRblp0st.js";import"./image-BWSpvyh2.js";import"./message-circle-DahbXiEe.js";import"./circle-help-BhYL9tyG.js";const u="#1DB954",m={fontFamily:"'General Sans', system-ui, sans-serif",letterSpacing:"-0.02em"},cs={Spotify:"#1DB954","Apple Music":"#FC3C44",YouTube:"#FF0000",SoundCloud:"#FF5500",Deezer:"#A238FF",Tidal:"#9CA3AF","Amazon Music":"#00A8E1","Pre-save":"#1DB954"},I={hidden:{opacity:0,y:12},visible:{opacity:1,y:0,transition:{duration:.45,ease:[.22,1,.36,1]}}};function nt({embedded:v=!1,rosterScope:x=null}){const{user:p,subscription:V}=qe(),{targetUserId:H}=Xe(),{theme:xe}=ze(),f=xe==="dark",pe=f?"#121212":"#f6f6f4",g=f?"#181818":"#ffffff",w=f?"#282828":"#ececea",i=f?"#b3b3b3":"#5f5f5f",j=f?"#ffffff":"#0a0a0a",E=Ie(),[J]=Ee(),[_,he]=c.useState(null),[C,ye]=c.useState([]),[r,A]=c.useState("all"),[N,Z]=c.useState([]),[$,ee]=c.useState([]),[ge,G]=c.useState(!0),[se,je]=c.useState(new Set),[q,be]=c.useState(null);c.useState(!1);const{toast:ke}=Ke(),{isCollaborator:te,loading:ve}=He(),we=x?x.selectedArtistId:"none",L=c.useMemo(()=>x?C.filter(s=>oe(x,s.id)):C,[C,x,we]);c.useEffect(()=>{r!=="all"&&x&&!L.some(s=>s.id===r)&&A("all")},[L]),c.useEffect(()=>{if(!p){E("/auth");return}Ne()},[p,H]);const Ne=async()=>{const s=J.get("release");let t=H||p.id;if(s){const{data:a}=await y.from("releases").select("user_id").eq("id",s).single();a&&(t=a.user_id)}he(t),Se(t)};c.useEffect(()=>{!p||!_||Ce()},[p,r,_,L]);const Se=async s=>{const t=s||_||p.id,[a,l]=await Promise.all([y.from("release_collaborators").select("release_id").eq("user_id",p.id).eq("status","accepted"),y.from("account_collaborators").select("owner_id").eq("user_id",p.id).eq("status","accepted")]),n=Array.from(new Set((l.data||[]).map(d=>d.owner_id).filter(Boolean))),o=n.length?(await y.from("releases").select("id, song_title, artwork_url, slug").in("user_id",n).order("release_date",{ascending:!1})).data||[]:[],h=Array.from(new Set([...(a.data||[]).map(d=>d.release_id).filter(Boolean),...o.map(d=>d.id)]));be(h);const F=y.from("releases").select("id, song_title, artwork_url, slug").eq("user_id",t).order("release_date",{ascending:!1}),D=h.length?y.from("releases").select("id, song_title, artwork_url, slug").in("id",h).order("release_date",{ascending:!1}):null,[Pe,Y]=await Promise.all([F,D]),ne=[...Pe.data||[],...(Y==null?void 0:Y.data)||[]],re=ne.filter((d,M)=>ne.findIndex(P=>P.id===d.id)===M);{ye(re);const d=re.map(X=>X.id),M=J.get("release"),P=localStorage.getItem("lastSelectedRelease");if(P&&d.includes(P)?A(P):M&&d.includes(M)?A(M):A("all"),d.length>0){const{data:X}=await y.from("smart_links").select("release_id").in("release_id",d);
1je(new Set((X||[]).map(Te=>Te.release_id)))}}},_e=()=>{if(r==="all"){E("/my-releases");return}const s=C.find(t=>t.id===r);se.has(r)&&(s!=null&&s.slug)?(navigator.clipboard.writeText(`https://releasejet.ai/r/${s.slug}`),ke({title:"Smart Link copied!"})):E(`/release/${r}/smart-link`)},Ce=async()=>{if(!p||!_)return;G(!0);const s=_;let t=y.from("link_clicks").select("platform, clicked_at, release_id, country").order("clicked_at",{ascending:!0});if(r!=="all")t=t.eq("release_id",r);else{const o=L.map(h=>h.id);if(o.length===0){Z([]),ee([]),G(!1);return}t=t.in("release_id",o)}const{data:a}=await t,l=()=>y.from("fan_subscribers").select("created_at, country, release_id").order("created_at",{ascending:!0});let n=[];if(r!=="all"){const{data:o}=await l().eq("release_id",r);n=o||[]}else{const o=q||[],[h,F]=await Promise.all([te?Promise.resolve({data:[]}):l().eq("artist_user_id",s),o.length?l().in("release_id",o):Promise.resolve({data:[]})]);n=[...h.data||[],...F.data||[]]}x&&x.selectedArtistId!=="all"&&(n=n.filter(o=>oe(x,o.release_id))),Z(a||[]),ee(n),G(!1)},Ae=()=>{const t=[];for(let a=29;a>=0;a--){const l=os(O(new Date,a)),n=B(l,"yyyy-MM-dd"),o=B(l,"MMM d"),h=N.filter(D=>B(new Date(D.clicked_at),"yyyy-MM-dd")===n).length,F=$.filter(D=>B(new Date(D.created_at),"yyyy-MM-dd")===n).length;t.push({label:o,clicks:h,fans:F})}return t},Le=()=>{const s={};return N.forEach(t=>{s[t.platform]=(s[t.platform]||0)+1}),Object.entries(s).map(([t,a])=>({name:t,value:a,fill:cs[t]||u})).sort((t,a)=>a.value-t.value)},Re=()=>{const s={};N.forEach(l=>{const n=l.country||"Unknown";s[n]=(s[n]||0)+1});const t={};$.forEach(l=>{const n=l.country||"Unknown";t[n]=(t[n]||0)+1});const a=new Set([...Object.keys(s),...Object.keys(t)]);return Array.from(a).map(l=>({name:l,clicks:s[l]||0,fans:t[l]||0})).sort((l,n)=>n.clicks+n.fans-(l.clicks+l.fans))},ae=Ae(),S=Le(),z=Re(),b=N.length,k=$.length,K=N.filter(s=>new Date(s.clicked_at)>O(new Date,7)).length,W=N.filter(s=>{const t=new Date(s.clicked_at);return t>O(new Date,14)&&t<=O(new Date,7)}).length,U=W===0?K>0?100:0:Math.round((K-W)/W*100),le=S.reduce((s,t)=>s+t.value,0),R=S[0],Fe=Math.max(1,...z.map(s=>s.clicks+s.fans));if(ge&&C.length===0||q===null)return e.jsx(We,{label:"Loading analyticsâ¦"});const De=te||q.length>0;if(!V.loading&&!ve&&V.plan==="free"&&!De)return e.jsx("div",{className:"min-h-screen flex flex-col items-center justify-center text-center px-6",children:e.jsx(Qe,{featureName:"Analytics Dashboard"})});const ie={background:w,border:"none",borderRadius:"8px",fontSize:12,boxShadow:"0 10px 30px rgba(0,0,0,0.5)",color:j},Me=({children:s})=>v?e.jsx(e.Fragment,{children:s}):e.jsx(Ve,{title:"Analytics",titleIcon:e.jsx(Ue,{className:"h-5 w-5",strokeWidth:1.5}),fullWidth:!0,hideRightPanel:!0,children:s});return e.jsx(Me,{children:e.jsx("div",{className:"min-h-full",style:{background:v?"transparent":pe,fontFamily:m.fontFamily,color:j},children:e.jsxs("div",{className:v?"space-y-6":"max-w-[1280px] mx-auto px-4 md:px-8 py-6 md:py-8 space-y-6",children:[e.jsxs(T.div,{variants:I,initial:"hidden",animate:"visible",className:v?"flex items-center":"flex items-center gap-4",children:[!v&&e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"font-medium leading-tight",style:{...m,fontSize:"17px",letterSpacing:"-0.01em",color:j},children:"Analytics"}),e.jsx("div",{className:"text-[12px] mt-0.5",style:{color:i},children:"See how your Smart Links perform"})]}),e.jsx("div",{className:v?"flex items-center gap-3 w-full sm:w-auto":"flex items-center gap-3 ml-0 sm:ml-auto",children:e.jsxs(Oe,{value:r,onValueChange:s=>{A(s),s&&s!=="all"&&localStorage.setItem("lastSelectedRelease",s)},children:[e.jsx(Be,{className:"w-full sm:w-[220px] rounded-md text-[13px] font-normal h-9 border",style:{background:g,color:j,borderColor:f?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.08)"},children:e.jsx($e,{placeholder:"All releases"})}),e.jsxs(Ge,{style:{background:g,color:j,border:`1px solid ${f?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.08)"}`},children:[e.jsx(ce,{value:"all",children:"All releases"}),L.map(s=>e.jsx(ce,{value:s.id,children:s.song_title},s.id))]})]})})]}),e.jsx(T.div,{variants:I,initial:"hidden",animate:"visible",className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[{label:"Total Clicks",value:b.toLocaleStr
1ing(),delta:b>0?`${b}`:null,deltaLabel:b>0?"all-time":null},{label:"Last 7 Days",value:K.toLocaleString(),delta:U!==0?`${U>0?"+":""}${U}%`:null,deltaPositive:U>=0},{label:"Fan Subscribers",value:k.toLocaleString(),delta:k>0?`+${k}`:null,onClick:()=>E(r!=="all"?`/subscribers?release=${r}`:"/subscribers")}].map((s,t)=>e.jsxs("div",{onClick:s.onClick,className:`rounded-lg p-6 transition-colors ${s.onClick?"cursor-pointer":""}`,style:{background:g},onMouseEnter:a=>{a.currentTarget.style.background=w},onMouseLeave:a=>{a.currentTarget.style.background=g},children:[e.jsx("p",{className:"text-[11px] font-normal mb-3",style:{color:i},children:s.label}),e.jsxs("div",{className:"flex items-baseline gap-3",children:[e.jsx("span",{className:"text-[28px] font-medium leading-none tabular-nums",style:m,children:s.value}),s.delta&&e.jsxs("span",{className:"text-[13px] font-medium",style:{color:s.deltaPositive===!1?"#FC3C44":u},children:[s.delta,s.deltaLabel?` ${s.deltaLabel}`:""]})]})]},t))}),e.jsxs(T.div,{variants:I,initial:"hidden",animate:"visible",className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"lg:col-span-2 rounded-lg p-6",style:{background:g},children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h3",{className:"text-[18px] font-medium",style:m,children:"Clicks Over Time"}),e.jsx("span",{className:"text-[11px] font-normal",style:{color:i},children:"Last 30 days"})]}),b===0?(()=>{const s=r!=="all"&&!se.has(r),t="#FC3C44",a=f?"rgba(252,60,68,0.14)":"rgba(252,60,68,0.10)";return e.jsxs("div",{className:"flex flex-col items-center justify-center text-center py-16",children:[e.jsx("div",{className:"w-14 h-14 rounded-full flex items-center justify-center mb-4",style:{background:s?a:w},children:e.jsx(Je,{className:"h-6 w-6",style:{color:s?t:i}})}),e.jsx("p",{className:"text-[14px] font-medium mb-1",style:{...m,color:s?t:j},children:s?"No Smart Link set up for this release":"No clicks yet"}),e.jsx("p",{className:"text-[13px] mb-5",style:{color:i},children:s?"Set one up to start tracking clicks and conversions.":"Share your smart link to start tracking."}),e.jsxs("button",{onClick:_e,className:"inline-flex items-center gap-1.5 px-4 py-2 rounded-lg text-[13px] font-medium transition-transform hover:scale-[1.04]",style:s?{background:t,color:"#fff"}:{background:f?"#fff":"#0a0a0a",color:f?"#000":"#fff"},children:[s?"Set Up Smart Link":"Share Smart Link"," ",e.jsx(Ye,{className:"h-3.5 w-3.5"})]})]})})():e.jsx(Q,{width:"100%",height:260,children:e.jsxs(Ze,{data:ae,margin:{top:4,right:4,left:-10,bottom:0},children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"clickGrad",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:u,stopOpacity:.45}),e.jsx("stop",{offset:"100%",stopColor:u,stopOpacity:0})]})}),e.jsx(de,{dataKey:"label",tick:{fontSize:10,fill:i},tickLine:!1,axisLine:!1,interval:4}),e.jsx(me,{tick:{fontSize:10,fill:i},tickLine:!1,axisLine:!1,allowDecimals:!1,width:30}),e.jsx(fe,{contentStyle:ie,labelStyle:{color:j,fontWeight:700},cursor:{stroke:u,strokeOpacity:.3}}),e.jsx(es,{type:"monotone",dataKey:"clicks",stroke:u,strokeWidth:3,fill:"url(#clickGrad)",dot:!1,activeDot:{r:5,fill:u,stroke:"#fff",strokeWidth:2}})]})})]}),e.jsxs("div",{className:"rounded-lg p-6 flex flex-col",style:{background:g},children:[e.jsx("h3",{className:"text-[18px] font-medium mb-4",style:m,children:"Platform Breakdown"}),S.length===0?e.jsx("div",{className:"flex-1 flex items-center justify-center py-10",children:e.jsx("p",{className:"text-[13px]",style:{color:i},children:"No data yet"})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex justify-center py-2",children:e.jsxs("div",{className:"relative w-40 h-40",children:[e.jsx(Q,{width:"100%",height:"100%",children:e.jsx(ss,{children:e.jsx(ts,{data:S,dataKey:"value",innerRadius:52,outerRadius:72,paddingAngle:3,strokeWidth:0,startAngle:90,endAngle:-270,children:S.map((s,t)=>e.jsx(as,{fill:s.fill},t))})})}),e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center pointer-events-none",children:[e.jsxs("span",{className:"text-[26px] font-medium tabular-nums",style:m,children:[R?Math.round(R.value/le*100):0,"%"]}),e.jsx("span",{className:"text-[10px] font-normal",style:{color:i},children:(R==null?void 0:R.name)||""})]})]})}),e.jsx("div",{className:"space-y-2.5 mt-4",children:S.map(s=>e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full shrink-0",style:{background:s.fill}}),e.jsx("span",{className:"text-[13px] font-normal truncate",children:s.name})]}),e.jsxs("span",{className:"text-[13px] font-medium tabular-nums",style:{color:i},children:[Math.round(s.value/le*100),"%"]})]},s.name))})]})]})]}),e.jsxs(T.div,{variants:I,initial:"hidden",animate:"visible",className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[!(r==="all"&&k===0)&&e.jsxs("div",{className:"rounded-lg p-6",style:{background:g},children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h3",{className:"text-[18px] font-medium",style:m,children:"Fan Growth"}),e.jsx("span",{className:"text-[11px] font-normal",style:{color:i},children:"Last 30 days"})]}),k===0?e.jsxs("div",{className:"flex flex-col items-center justify-center text-center py-10",children:[e.jsx("div",{className:"w-14 h-14 roun
1ded-full flex items-center justify-center mb-4",style:{background:w},children:e.jsx(ns,{className:"h-6 w-6",style:{color:i}})}),e.jsx("p",{className:"text-[14px] font-medium mb-1",style:m,children:"No fan growth data yet"}),e.jsx("p",{className:"text-[13px] max-w-xs",style:{color:i},children:"Keep sharing your link to start seeing audience growth insights."})]}):e.jsx(Q,{width:"100%",height:200,children:e.jsxs(ls,{data:ae,margin:{top:4,right:4,left:-10,bottom:0},children:[e.jsx(de,{dataKey:"label",tick:{fontSize:10,fill:i},tickLine:!1,axisLine:!1,interval:4}),e.jsx(me,{tick:{fontSize:10,fill:i},tickLine:!1,axisLine:!1,allowDecimals:!1,width:28}),e.jsx(fe,{contentStyle:ie,cursor:{fill:"rgba(255,255,255,0.04)"}}),e.jsx(is,{dataKey:"fans",fill:u,radius:[4,4,0,0]})]})})]}),e.jsxs("div",{className:"rounded-lg p-6",style:{background:g},children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h3",{className:"text-[18px] font-medium",style:m,children:"Top Countries"}),e.jsx(ue,{className:"h-4 w-4",style:{color:i}})]}),z.length===0||b===0&&k===0?e.jsxs("div",{className:"flex flex-col items-center justify-center text-center py-10",children:[e.jsx("div",{className:"w-14 h-14 rounded-full flex items-center justify-center mb-4",style:{background:w},children:e.jsx(ue,{className:"h-6 w-6",style:{color:i}})}),e.jsx("p",{className:"text-[14px] font-medium mb-1",style:m,children:"No location data yet"}),e.jsx("p",{className:"text-[13px]",style:{color:i},children:"Country tracking starts with new clicks and signups."})]}):e.jsx("div",{className:"space-y-4",children:z.slice(0,6).map((s,t)=>{const a=s.clicks+s.fans,l=Math.max(4,Math.round(a/Fe*100));return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("span",{className:"text-[11px] font-medium tabular-nums w-6",style:{color:i},children:String(t+1).padStart(2,"0")}),e.jsx("span",{className:"text-[14px] font-medium truncate",children:s.name})]}),e.jsx("span",{className:"text-[13px] font-medium tabular-nums",children:a.toLocaleString()})]}),e.jsx("div",{className:"h-1.5 rounded-full overflow-hidden",style:{background:w},children:e.jsx("div",{className:"h-full rounded-full transition-all duration-700",style:{width:`${l}%`,background:u,opacity:Math.max(.4,1-t*.12)}})})]},s.name)})})]})]}),(b>0||k>0)&&e.jsxs(T.div,{variants:I,initial:"hidden",animate:"visible",className:"flex items-center gap-2 text-[11px] font-normal pt-2",style:{color:i},children:[e.jsx(rs,{className:"h-3.5 w-3.5",style:{color:u}}),"Live · updated just now"]})]})})})}export{nt 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.