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