import{o as e,w as D,B as R,a as f,A as P}from"./chunk-NL6KNZEE-DfxmOBHd.js";import{i as u}from"./api-BuTqLiNI.js";import{g}from"./utils-BqohOHgI.js";import{a as C}from"./color.esm-brSKLyvp.js";import{c as $}from"./createLucideIcon-Bp-vR5YK.js";/**
 * @license lucide-react v0.513.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const F=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],v=$("chevron-left",F);/**
 * @license lucide-react v0.513.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const L=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],_=$("chevron-right",L);function o(t){return e.jsxs("div",{className:"flex items-baseline gap-1.5",children:[e.jsx("div",{className:"w-23 text-end shrink-0",children:e.jsxs("span",{className:`
            relative inline-block
            text-2xl font-semibold
          `,children:[e.jsx("span",{className:`
              absolute inset-0
              -translate-x-2 translate-y-8
              bg-(--color-primary)
              z-0
              h-1
            `,"aria-hidden":!0}),e.jsx("span",{className:"relative z-1",children:t.figure})]})}),e.jsx("span",{className:"text-sm",children:t.text})]})}function j({title:t,imageSrc:c,items:a,getLabel:s,includeTime:l}){const[n,...m]=a;return n?e.jsxs("div",{className:"flex flex-col sm:flex-row gap-5",children:[e.jsx("div",{className:"rewind-top-item-image",children:e.jsx("img",{className:"max-w-48 max-h-48",src:c})}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("h4",{className:"-mb-1",children:t}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("div",{className:"flex flex-col items-start mb-2",children:[e.jsx("h2",{children:s(n.item)}),e.jsxs("span",{className:"text-(--color-fg-tertiary) -mt-3 text-sm",children:[`${n.item.listen_count} plays`,l?` (${Math.floor(n.item.time_listened/60)} minutes)`:""]})]})}),m.map(i=>e.jsxs("div",{className:"text-sm",children:[s(i.item),e.jsxs("span",{className:"text-(--color-fg-tertiary)",children:[` - ${i.item.listen_count} plays`,l?` (${Math.floor(i.item.time_listened/60)} minutes)`:""]})]},i.item.id))]})]}):null}function M(t){var l,n,m;const c=(l=t.stats.top_artists[0])==null?void 0:l.item.image,a=(n=t.stats.top_albums[0])==null?void 0:n.item.image,s=(m=t.stats.top_tracks[0])==null?void 0:m.item.image;return!t.stats.top_artists[0]||!t.stats.top_albums[0]||!t.stats.top_tracks[0]?e.jsx("p",{children:"Not enough data exists to create a Rewind for this period :("}):e.jsxs("div",{className:"flex flex-col gap-7",children:[e.jsx("h2",{children:t.stats.title}),e.jsx(j,{title:"Top Artist",imageSrc:u(c,"medium"),items:t.stats.top_artists,getLabel:i=>i.name,includeTime:t.includeTime}),e.jsx(j,{title:"Top Album",imageSrc:u(a,"medium"),items:t.stats.top_albums,getLabel:i=>i.title,includeTime:t.includeTime}),e.jsx(j,{title:"Top Track",imageSrc:u(s,"medium"),items:t.stats.top_tracks,getLabel:i=>i.title,includeTime:t.includeTime}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-y-5",children:[e.jsx(o,{figure:`${t.stats.minutes_listened}`,text:"Minutes listened"}),e.jsx(o,{figure:`${t.stats.unique_tracks}`,text:"Tracks"}),e.jsx(o,{figure:`${t.stats.new_tracks}`,text:"New tracks"}),e.jsx(o,{figure:`${t.stats.plays}`,text:"Plays"}),e.jsx(o,{figure:`${t.stats.unique_albums}`,text:"Albums"}),e.jsx(o,{figure:`${t.stats.new_albums}`,text:"New albums"}),e.jsx(o,{figure:`${t.stats.avg_plays_per_day.toFixed(1)}`,text:"Plays per day"}),e.jsx(o,{figure:`${t.stats.unique_artists}`,text:"Artists"}),e.jsx(o,{figure:`${t.stats.new_artists}`,text:"New artists"})]})]})}const k=["Full Year","January","February","March","April","May","June","July","August","September","October","November","December"];async function U({request:t}){const c=new URL(t.url),a=parseInt(c.searchParams.get("year")||g().year.toString()),s=parseInt(c.searchParams.get("month")||g().month.toString()),l=await fetch(`/apis/web/v1/summary?year=${a}&month=${s}`);if(!l.ok)throw new Response("Failed to load summary",{status:500});const n=await l.json();return n.title=`Your ${s===0?"":k[s]} ${a} Rewind`,{stats:n}}const E=D(function(){const c=new URLSearchParams(location.search);let a=parseInt(c.get("year")||g().year.toString()),s=parseInt(c.get("month")||g().month.toString());const l=R(),[n,m]=f.useState(!1),{stats:i}=P(),[S,T]=f.useState("(--color-bg)");f.useEffect(()=>{var x;if(!i.top_artists[0])return;const r=(x=i.top_artists[0])==null?void 0:x.item.image;r&&C(u(r,"small"),{amount:1}).then(d=>{T(`rgba(${d[0]},${d[1]},${d[2]},0.4)`)})},[i]);const w=r=>{const x=new URLSearchParams(location.search);for(const p in r){const N=r[p];N!==null&&x.set(p,N)}const d=`/rewind?${x.toString()}`;l(d,{replace:!1})},b=r=>{r==="next"?s===12?s=0:s+=1:s===0?s=12:s-=1,console.log(`Month: ${s}`),w({year:a.toString(),month:s.toString()})},y=r=>{r==="next"?a+=1:a-=1,w({year:a.toString(),month:s.toString()})},h=`${i.title} - Koito`;return e.jsx("div",{className:"w-full min-h-screen",style:{background:`linear-gradient(to bottom, ${S}, var(--color-bg) 500px)`,transition:"1000"},children:e.jsxs("div",{className:"flex flex-col items-start sm:items-center gap-4",children:[e.jsx("title",{children:h}),e.jsx("meta",{property:"og:title",content:h}),e.jsx("meta",{name:"description",content:h}),e.jsxs("div",{className:"flex flex-col lg:flex-row items-start lg:mt-15 mt-5 gap-10 w-19/20 px-5 md:px-20",children:[e.jsxs("div",{className:"flex flex-col items-start gap-4",children:[e.jsxs("div",{className:"flex flex-col items-start gap-4 py-8",children:[e.jsxs("div",{className:"flex items-center gap-6 justify-around",children:[e.jsx("button",{onClick:()=>b("prev"),className:"p-2 disabled:text-(--color-fg-tertiary)",disabled:new Date(a,s-2)>new Date||new Date().getFullYear()===a&&s===1,children:e.jsx(v,{size:20})}),e.jsx("p",{className:"font-medium text-xl text-center w-30",children:k[s]}),e.jsx("button",{onClick:()=>b("next"),className:"p-2 disabled:text-(--color-fg-tertiary)",disabled:s>=new Date().getMonth()&&a>=new Date().getFullYear(),children:e.jsx(_,{size:20})})]}),e.jsxs("div",{className:"flex items-center gap-6 justify-around",children:[e.jsx("button",{onClick:()=>y("prev"),className:"p-2 disabled:text-(--color-fg-tertiary)",disabled:new Date(a-1,s)>new Date,children:e.jsx(v,{size:20})}),e.jsx("p",{className:"font-medium text-xl text-center w-30",children:a}),e.jsx("button",{onClick:()=>y("next"),className:"p-2 disabled:text-(--color-fg-tertiary)",disabled:new Date(a+1,s-1)>new Date||s==0&&new Date().getFullYear()===a+1||new Date().getMonth()===s-1&&new Date().getFullYear()===a+1,children:e.jsx(_,{size:20})})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("label",{htmlFor:"show-time-checkbox",children:"Show time listened?"}),e.jsx("input",{type:"checkbox",name:"show-time-checkbox",checked:n,onChange:r=>m(!n)})]})]}),i!==void 0&&e.jsx(M,{stats:i,includeTime:n})]})]})})});export{U as clientLoader,E as default};
