import{a as v,b as w,j as s,A as b,T as u,o as d,p as x,al as L,q as k,aL as M,Y as N,ap as I,r as l,d as y}from"./main-D6SjkSWq.js";import{u as S,M as C,a as A}from"./use-current-time-DUvmqASk.js";import{u as f}from"./use-player-store-_08VVZOs.js";import{M as P}from"./MusicNote-B50jw5lh.js";import{S as T}from"./skeleton-3NNrk_-o.js";import"./is-ctrl-or-shift-pressed-CY4knlcl.js";import"./middleware-BLXTWOs6.js";import"./traditional-GTMgz7Xu.js";function q(e,t){return v({queryKey:["lyrics",e],queryFn:()=>E(e,t)})}function E(e,t){return w.get(`tracks/${e}/lyrics`,{params:t}).then(i=>i.data)}function _(){const e=S();return s.jsx(b,{initial:!1,mode:"wait",children:s.jsx("div",{children:e?s.jsx($,{track:e}):s.jsx(p,{title:s.jsx(u,{message:"Play a song in order to view lyrics."})})})})}function $({track:e}){const t=f(o=>o.mediaDuration),{data:i,isLoading:n}=q(e.id,{duration:t});let a=null;return i?a=s.jsx(K,{data:i}):n?a=s.jsx(W,{}):a=s.jsx(p,{title:s.jsx(u,{message:"We do not have lyrics for this song yet"}),description:s.jsx(u,{message:"Please try again later"})}),s.jsxs("div",{className:"relative isolate",children:[s.jsx(z,{}),a]})}function z(){const{key:e}=k(),t=e!=="default",i=M();return s.jsx(N,{className:"absolute right-0 top-0 z-10",onClick:()=>{t&&i(-1)},children:s.jsx(I,{})})}const D=(e,t)=>{var i;for(let n=0;n<e.lines.length;n++)if(e.lines[n].time<=t&&((i=e.lines[n+1])==null?void 0:i.time)>t)return n;return null};function K({data:e}){const t=f(r=>r.mediaDuration),i=e.duration,n=e.is_synced&&(!i||Math.abs(i-t)<=12),a=A({precision:"seconds",disabled:!n}),o=l.useMemo(()=>n?D(e,a):null,[e,a,n]);return l.useEffect(()=>{setTimeout(()=>{var r;(r=document.querySelector('[data-line-index="0"]'))==null||r.scrollIntoView({behavior:"smooth",block:"center"})})},[e]),l.useEffect(()=>{var r;o!=null&&((r=document.querySelector(`[data-line-index="${o}"]`))==null||r.scrollIntoView({behavior:"smooth",block:"center"}))},[o]),s.jsx(h,{animationKey:"synced-lyrics",children:e.lines.map((r,c)=>{const j=o&&c<o,g=o===c;return s.jsx("div",{"data-line-index":c,className:y("max-md:mb-18 md:leading-[48px]",j&&"opacity-40",g&&"text-primary"),children:r.text||s.jsx(P,{})},r.time||c)})})}const m=[40,55,70,80,90,100];function W(){return s.jsx(h,{animationKey:"skeletons",width:"min-w-[70%]",children:[...new Array(12).keys()].map(e=>s.jsx(T,{variant:"rect",className:"mb-14",size:"h-48 w-full",style:{maxWidth:`${m[e%m.length]}%`}},e))})}function h({children:e,animationKey:t,width:i="w-max"}){return s.jsx(d.div,{...x,className:"flex-col items-center justify-start md:flex",children:s.jsx("div",{className:y("max-w-full flex-auto text-2xl md:mx-64 md:text-3xl",i),children:e})},t)}function p({title:e,description:t}){return s.jsx(d.div,{...x,children:s.jsx(L,{image:s.jsx(C,{size:"xl"}),imageHeight:"h-auto",title:e,description:t})},"no-lyrics-message")}export{_ as Component};
