import{o as t,L as m,w as d,A as c,a as p}from"./chunk-NL6KNZEE-DfxmOBHd.js";import{T as x}from"./TopTracks-Bd_3i0l5.js";import{i as u,b as f,m as h}from"./api-BuTqLiNI.js";import{L as g,A as j}from"./LastPlays-CphKmpl1.js";import{P as _}from"./PeriodSelector-pCJGRgEO.js";import{M as w,I as A}from"./InterestGraph-DdMDFwP0.js";import{k as b}from"./useTheme-DylenN4B.js";import{t as y}from"./utils-BqohOHgI.js";import"./TopItemList-BRD-rnKC.js";import"./ArtistLinks-B4A9lGBW.js";import"./createLucideIcon-Bp-vR5YK.js";import"./AppProvider-DDBhlShu.js";import"./color.esm-brSKLyvp.js";import"./SearchResults-DjG_lSbe.js";import"./index-0dO883bS.js";import"./AsyncButton-Dzd9rf7C.js";function v({artistId:l,name:s}){const{isPending:r,isError:o,data:a,error:e}=b({queryKey:["top-albums",{limit:99,period:"all_time",artist_id:l}],queryFn:({queryKey:i})=>f(i[1])});return r?t.jsxs("div",{children:[t.jsx("h3",{children:"Albums From This Artist"}),t.jsx("p",{children:"Loading..."})]}):o?t.jsxs("div",{children:[t.jsx("h3",{children:"Albums From This Artist"}),t.jsxs("p",{className:"error",children:["Error:",e.message]})]}):t.jsxs("div",{children:[t.jsxs("h3",{children:["Albums featuring ",s]}),t.jsxs("div",{className:"flex flex-wrap gap-8",children:[a.items.length<1&&"Nothing to show",a.items.map(i=>t.jsxs(m,{to:`/album/${i.item.id}`,className:"flex gap-2 items-start",children:[t.jsx("img",{src:u(i.item.image,"medium"),alt:i.item.title,style:{width:130}}),t.jsxs("div",{className:"w-[180px] flex flex-col items-start gap-1",children:[t.jsx("p",{children:i.item.title}),t.jsxs("p",{className:"text-sm color-fg-secondary",children:[i.item.listen_count," play",i.item.listen_count>1?"s":""]})]})]}))]})]})}async function $({params:l}){const s=await fetch(`/apis/web/v1/artist?id=${l.id}`);if(!s.ok)throw new Response("Failed to load artist",{status:500});return await s.json()}const K=d(function(){const s=c(),[r,o]=p.useState("week");console.log(s.aliases);let a=s.aliases.indexOf(s.name);return a!==-1&&s.aliases.splice(a,1),t.jsxs(w,{type:"Artist",title:s.name,img:s.image,id:s.id,rank:s.all_time_rank,musicbrainzId:s.musicbrainz_id,imgItemId:s.id,mergeFunc:h,mergeCleanerFunc:(e,i)=>{e.albums=[],e.tracks=[];for(let n=0;n<e.artists.length;n++)e.artists[n].id===i&&delete e.artists[n];return e},subContent:t.jsxs("div",{className:"flex flex-col gap-2 items-start",children:[s.listen_count>0&&t.jsxs("p",{children:[s.listen_count," play",s.listen_count>1?"s":""]}),s.time_listened!==0&&t.jsx("p",{title:Math.floor(s.time_listened/60/60)+" hours",children:y(s.time_listened)}),s.first_listen>0&&t.jsxs("p",{title:new Date(s.first_listen*1e3).toLocaleString(),children:["Listening since"," ",new Date(s.first_listen*1e3).toLocaleDateString()]})]}),children:[t.jsx("div",{className:"mt-10",children:t.jsx(_,{setter:o,current:r})}),t.jsxs("div",{className:"flex flex-col gap-20",children:[t.jsxs("div",{className:"flex gap-15 mt-10 flex-wrap",children:[t.jsx(g,{limit:20,artistId:s.id}),t.jsx(x,{limit:8,period:r,artistId:s.id}),t.jsxs("div",{className:"flex flex-col items-start gap-4",children:[t.jsx(j,{configurable:!0,artistId:s.id}),t.jsx(A,{artistId:s.id})]})]}),t.jsx(v,{period:r,artistId:s.id,name:s.name})]})]})});export{$ as clientLoader,K as default};
