import{d as q,G as z,u as d,D as te,H as A,J as T,e as u,h as ce,w as D,a3 as ue,b as p,K as W,r as L,f as k,a4 as x,c as b,ag as de,n as O,F as E,O as V,a$ as fe,ae as X,a2 as me,j as H,m as ve,W as pe}from"./lucide-yedcb7T6.js";import{S as ye,q as he,r as ge,s as _e,t as be}from"./reka-ui-C6KTf88c.js";import{e as ae,$ as Y,_ as ke,P as se,s as w}from"./index-CARX9j7k.js";import{l as ie}from"./vueuse-BRFAEesk.js";import{_ as xe}from"./Spinner.vue_vue_type_script_setup_true_lang-DsRPGwJ5.js";const Le=q({__name:"ScrollBar",props:{orientation:{default:"vertical"},forceMount:{type:Boolean},asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array],default:void 0}},setup(n){const e=n,s=ie(e,"class");return(f,l)=>(u(),z(d(ye),te({"data-slot":"scroll-area-scrollbar"},d(s),{class:d(ae)("flex touch-none p-px transition-colors select-none",n.orientation==="vertical"&&"h-full w-2.5 border-l border-l-transparent",n.orientation==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent",e.class)}),{default:A(()=>[T(d(he),{"data-slot":"scroll-area-thumb",class:"bg-border relative flex-1 rounded-full"})]),_:1},16,["class"]))}}),Ie=q({__name:"ScrollArea",props:{type:{},dir:{},scrollHideDelay:{},asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]}},setup(n){const e=n,s=ie(e,"class");return(f,l)=>(u(),z(d(ge),te({"data-slot":"scroll-area"},d(s),{class:d(ae)("relative",e.class)}),{default:A(()=>[T(d(_e),{"data-slot":"scroll-area-viewport",class:"focus-visible:ring-ring/50 size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1"},{default:A(()=>[ce(f.$slots,"default")]),_:3}),T(Le),T(d(be))]),_:3},16,["class"]))}}),Te=n=>{const e=n.match(/\[(\d+):(\d+)([.:]\d+)?\](.*)/);if(e){const s=parseInt(e[1]),f=parseInt(e[2]);let l=0;if(e[3]){const g=e[3].replace(/[.:]/,".");l=Math.round(parseFloat(g)*1e3)}return{time:(s*60*1e3+f*1e3+l)/1e3,text:e[4].trim()||" "}}return{time:0,text:n.trim()||" "}},Ae={class:"lyrics-container"},Se={key:0,class:"lyrics-loading"},Me={key:1,class:"lyrics-empty"},Be={key:0,class:"lyrics-intro"},Ee={class:"artist-name"},we={class:"lyrics-coming-soon"},Ce={class:"lyrics-content"},Z=5,Pe=5,I=7,ee=.5,Ne=q({__name:"LyricsViewer",props:{mediaItem:{default:void 0},position:{default:void 0},streamDetails:{default:void 0},textColor:{default:"#FFFFFF"},lyrics:{default:void 0},lrcLyrics:{default:void 0},anticipation:{default:0},externalLoading:{type:Boolean,default:!1},highlightAhead:{type:Boolean,default:!0}},setup(n){fe(a=>({v5950c76d:ne.value,v3f950052:a.textColor}));const e=n,s=L([]),f=L(!1),l=L(-1),y=L(null),m=new Map,g=L(0),v=L(!1),C=(a,t)=>{a?m.set(t,a):m.delete(t)},S=b(()=>{if(!P.value||!s.value.length)return!1;const a=s.value[0].time,t=e.position||0;return l.value===-1&&t<a-e.anticipation}),le=b(()=>{if(!e.mediaItem)return"";if("media_type"in e.mediaItem&&e.mediaItem.media_type==="track"){const a=e.mediaItem;if(a.artists?.length)return a.artists.map(t=>t.name).join(", ")}return"media_type"in e.mediaItem&&e.mediaItem.media_type==="artist"?e.mediaItem.name:""}),U=()=>e.lyrics??e.mediaItem?.metadata?.lyrics??null,j=()=>e.lrcLyrics??e.mediaItem?.metadata?.lrc_lyrics??null,P=b(()=>{if(s.value.some(i=>i.time>0))return!0;const a=j(),t=U();return!!(a&&a.includes("[")||t&&/\[\d+:\d+[.:]?\d*\]/.test(t))}),re=()=>{f.value=!0;try{const a=j()||"",t=U()||"";let i="",o=!1;if(a?(i=a,o=!0):t&&/\[\d+:\d+[.:]?\d*\]/.test(t)?(i=t,o=!0):t&&(i=t,o=!1),o){const c=i.split(`
`).filter(r=>r.trim()).map(r=>Te(r)).sort((r,F)=>r.time-F.time),_=new Set;for(const r of c)!r.text.trim()&&r.time>0&&_.add(r.time);const h=c.filter(r=>r.text.trim()),M=[];if(h.length>0){const r=h[0].time;r>=Z&&M.push({time:r-Z,text:"",isBreak:!0,breakEnd:r})}for(let r=0;r<h.length;r++)if(M.push({time:h[r].time,text:h[r].text,isBreak:!1}),r<h.length-1){const F=h[r].time,$=h[r+1].time;let B=null;for(const R of _)if(R>F&&R<$){B=R;break}B!==null&&$-B>=Pe&&M.push({time:B,text:"",isBreak:!0,breakEnd:$})}s.value=M}else i?s.value=i.split(`
`).filter(c=>c.trim()).map(c=>({time:0,text:c.trim(),isBreak:!1})).filter(c=>c.text):s.value=[]}catch(a){console.error(`[LyricsViewer] Error processing lyrics: ${a}`),s.value=[]}finally{f.value=!1}},G=b(()=>{const a=l.value;if(a<0)return{filled:I,percent:100};const t=s.value[a];if(!t?.isBreak||!t.breakEnd)return{filled:I,percent:100};const i=e.position||0,o=t.breakEnd-Q.value-t.time;if(o<=0)return{filled:I,percent:100};const _=Math.max(0,i-t.time)/o*I;return{filled:Math.min(I,Math.floor(_)),percent:Math.round((_-Math.floor(_))*100)}}),N=b(()=>G.value.filled),K=b(()=>G.value.percent),ne=b(()=>`${ee}s`),Q=b(()=>e.highlightAhead?ee:0),oe=a=>{let t=-1;for(let i=0;i<s.value.length&&Math.round(s.value[i].time*1e3)<=a;i++)t=i;return t},J=a=>{const t=m.get(a),i=y.value;if(!t||!i)return;const c=i.clientHeight*(e.anticipation>0?.5:.35),_=t.offsetTop,h=t.offsetHeight;g.value=c-_-h/2};return D([()=>e.mediaItem?.item_id,()=>e.lyrics,()=>e.lrcLyrics],()=>{l.value=-1,g.value=99999,v.value=!1,m.clear(),re(),H(()=>{const a=m.get(0),t=y.value;a&&t&&(g.value=t.clientHeight-a.offsetTop+40)})},{immediate:!0}),D(()=>e.position,a=>{if(a===void 0||!s.value.length||!P.value)return;const t=Math.round((a+Q.value)*1e3),i=oe(t);i!==l.value&&i>=0&&(v.value=!0,l.value=i,H(()=>J(i)))}),D(S,a=>{!a&&s.value.length&&(v.value=!0,H(()=>J(0)))}),ue(()=>{m.clear()}),(a,t)=>(u(),p("div",Ae,[f.value||n.externalLoading?(u(),p("div",Se,[T(d(xe),{class:"size-6"}),k("div",null,x(d(Y)("loading_lyrics")),1)])):s.value.length?P.value?(u(),p("div",{key:2,ref_key:"syncedContainerRef",ref:y,class:"synced-container"},[T(de,{name:"intro-fade"},{default:A(()=>[S.value?(u(),p("div",Be,[k("div",{class:"song-title",style:O({color:n.textColor})},x(e.mediaItem?.name),5),k("div",Ee,x(le.value),1),k("div",we,x(d(Y)("lyrics_will_appear_soon")),1)])):W("",!0)]),_:1}),k("div",{class:"synced-content",style:O({transform:`translateY(${g.value}px)`,transition:v.value?void 0:"none"})},[(u(!0),p(E,null,V(s.value,(i,o)=>(u(),p("div",{key:o,ref_for:!0,ref:c=>C(c,o),class:X(["lyrics-line",{active:l.value===o,"lyrics-line--hidden":l.value>=0?o<l.value-1||o>l.value+2:o>2}])},[i.isBreak?(u(),p(E,{key:1},V(I,c=>k("span",{key:c,class:X(["break-note",{"break-note--filled":l.value===o&&c<=N.value,"break-note--filling":l.value===o&&c===N.value+1}]),style:O(l.value===o&&c===N.value+1?{backgroundImage:`linear-gradient(to right, ${n.textColor} ${K.value}%, color-mix(in srgb, ${n.textColor} 35%, transparent) ${K.value}%)`,backgroundClip:"text","-webkit-background-clip":"text","-webkit-text-fill-color":"transparent"}:void 0)},"♫",6)),64)):(u(),p(E,{key:0},[me(x(i.text),1)],64))],2))),128))],4)],512)):e.anticipation?W("",!0):(u(),z(d(Ie),{key:3,class:"h-full w-full static-lyrics"},{default:A(()=>[k("div",Ce,[(u(!0),p(E,null,V(s.value,(i,o)=>(u(),p("div",{key:o,class:"lyrics-line active"},x(i.text),1))),128))])]),_:1})):(u(),p("div",Me,x(d(Y)("no_lyrics_available")),1))]))}}),He=ke(Ne,[["__scopeId","data-v-e20bbab2"]]);function Fe(n,e,s){if(n===void 0||e===void 0||s!==void 0&&s!==se.PLAYING)return n;const f=e*1e3,l=Date.now(),m=Math.max(0,l-f)/1e3;return n+m}function Ye(n){const e=L(0);let s=null;const f=()=>{const v=w.activePlayerQueue;v?.elapsed_time!=null&&v?.elapsed_time_last_updated!=null&&(e.value=Fe(v.elapsed_time,v.elapsed_time_last_updated,w.activePlayer?.playback_state)??0),s=requestAnimationFrame(f)},l=()=>{s||(s=requestAnimationFrame(f))},y=()=>{s&&(cancelAnimationFrame(s),s=null)};let m=!1;const g=()=>{document.visibilityState==="visible"&&m?l():y()};return document.addEventListener("visibilitychange",g),ve(()=>{const v=w.activePlayer?.playback_state===se.PLAYING,C=w.activePlayerQueue,S=n?n.value:!0;m=v&&!!C?.active&&S,m&&document.visibilityState==="visible"?l():y()}),pe(()=>{y(),document.removeEventListener("visibilitychange",g)}),{elapsedTime:e,start:l,stop:y}}export{He as L,Ie as _,Fe as c,Ye as u};
