import{w as m,A as d,a as p,o as e,L as o}from"./chunk-NL6KNZEE-DfxmOBHd.js";import{f as u}from"./api-BuTqLiNI.js";import{L as f,A as x}from"./LastPlays-CphKmpl1.js";import{P as h}from"./PeriodSelector-pCJGRgEO.js";import{M as k,I as j}from"./InterestGraph-DdMDFwP0.js";import{t as g}from"./utils-BqohOHgI.js";import"./useTheme-DylenN4B.js";import"./AppProvider-DDBhlShu.js";import"./createLucideIcon-Bp-vR5YK.js";import"./ArtistLinks-B4A9lGBW.js";import"./color.esm-brSKLyvp.js";import"./SearchResults-DjG_lSbe.js";import"./index-0dO883bS.js";import"./AsyncButton-Dzd9rf7C.js";async function $({params:l}){let t=await fetch(`/apis/web/v1/track?id=${l.id}`);if(!t.ok)throw new Response("Failed to load track",{status:t.status});const i=await t.json();if(t=await fetch(`/apis/web/v1/album?id=${i.album_id}`),!t.ok)throw new Response("Failed to load album for track",{status:t.status});const r=await t.json();return{track:i,album:r}}const C=m(function(){const{track:t,album:i}=d(),[r,c]=p.useState("week");return e.jsxs(k,{type:"Track",title:t.title,img:t.image,id:t.id,rank:t.all_time_rank,musicbrainzId:t.musicbrainz_id,imgItemId:t.album_id,mergeFunc:u,mergeCleanerFunc:(s,n)=>{s.albums=[],s.artists=[];for(let a=0;a<s.tracks.length;a++)s.tracks[a].id===n&&delete s.tracks[a];return s},subContent:e.jsxs("div",{className:"flex flex-col gap-2 items-start",children:[t.artists.length>0&&e.jsx("p",{children:t.artists.map((s,n)=>e.jsxs("span",{children:[n>0&&", ",e.jsx(o,{className:"hover:underline",to:`/artist/${s.id}`,children:s.name})]},s.id))}),e.jsxs("p",{children:["Appears on"," ",e.jsx(o,{className:"hover:underline",to:`/album/${t.album_id}`,children:i.title})]}),t.listen_count!==0&&e.jsxs("p",{children:[t.listen_count," play",t.listen_count>1?"s":""]}),t.time_listened!==0&&e.jsx("p",{title:Math.floor(t.time_listened/60/60)+" hours",children:g(t.time_listened)}),t.first_listen>0&&e.jsxs("p",{title:new Date(t.first_listen*1e3).toLocaleString(),children:["Listening since"," ",new Date(t.first_listen*1e3).toLocaleDateString()]})]}),children:[e.jsx("div",{className:"mt-10",children:e.jsx(h,{setter:c,current:r})}),e.jsxs("div",{className:"flex flex-wrap gap-20 mt-10",children:[e.jsx(f,{limit:20,trackId:t.id}),e.jsxs("div",{className:"flex flex-col items-start gap-4",children:[e.jsx(x,{configurable:!0,trackId:t.id}),e.jsx(j,{trackId:t.id})]})]})]})});export{$ as clientLoader,C as default};
