import{N as e,k as t,t as n}from"./jsx-runtime-ktpX_HJe.js";import{t as r}from"./TopItemList-anbyJ0nZ.js";import{t as i}from"./ChartLayout-D5wlQ5mJ.js";var a=n();async function o({request:e}){let t=new URL(e.url),n=t.searchParams.get(`page`)||`0`;t.searchParams.set(`page`,n);let r=await fetch(`/apis/web/v1/top/tracks?${t.searchParams.toString()}`);if(!r.ok)throw new Response(`Failed to load top tracks`,{status:500});return{top_tracks:await r.json()}}var s=e(function(){let{top_tracks:e}=t();return(0,a.jsx)(i,{title:`Top Tracks`,initialData:e,endpoint:`chart/top/tracks`,render:({data:e,page:t,onNext:n,onPrev:i})=>(0,a.jsxs)(`div`,{className:`flex flex-col gap-5 text-sm md:text-[16px] w-11/12 max-w-[1000px]`,children:[(0,a.jsxs)(`div`,{className:`flex gap-15 mx-auto`,children:[(0,a.jsx)(`button`,{className:`default`,onClick:i,disabled:t<=1,children:`Prev`}),(0,a.jsx)(`button`,{className:`default`,onClick:n,disabled:!e.has_next_page,children:`Next`})]}),(0,a.jsx)(r,{ranked:!0,separators:!0,data:e,className:`w-full`,type:`track`,slug:``}),(0,a.jsxs)(`div`,{className:`flex gap-15 mx-auto`,children:[(0,a.jsx)(`button`,{className:`default`,onClick:i,disabled:t<=1,children:`Prev`}),(0,a.jsx)(`button`,{className:`default`,onClick:n,disabled:!e.has_next_page,children:`Next`})]})]})})});export{o as clientLoader,s as default};