import{d as se,w as S,a3 as ne,c as v,G as re,K,r as b,J as j,e as k,u as x,a4 as L,g as _,ag as le,H as Q,n as $,F as N,O as V,ae as J,a2 as oe,a_ as ce,b as m,j as D,m as ue,W as de}from"./lucide-C_a_D9Y7.js";import{_ as me}from"./ScrollArea.vue_vue_type_script_setup_true_lang-iXoaSSYB.js";import{_ as fe}from"./Spinner.vue_vue_type_script_setup_true_lang-DzvzwhdE.js";import{$ as H,_ as ve,P as Z,s as P}from"./index-Cc0s9xHj.js";const ye=c=>{const e=c.match(/\[(\d+):(\d+)([.:]\d+)?\](.*)/);if(e){const s=parseInt(e[1]),y=parseInt(e[2]);let l=0;if(e[3]){const p=e[3].replace(/[.:]/,".");l=Math.round(parseFloat(p)*1e3)}return{time:(s*60*1e3+y*1e3+l)/1e3,text:e[4].trim()||" "}}return{time:0,text:c.trim()||" "}},pe={class:"lyrics-container"},he={key:0,class:"lyrics-loading"},ge={key:1,class:"lyrics-empty"},_e={key:0,class:"lyrics-intro"},ke={class:"artist-name"},Le={class:"lyrics-coming-soon"},be={class:"lyrics-content"},W=5,Ie=5,I=7,X=.5,xe=se({__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(c){ce(t=>({v3677615e:ie.value,v58a94341:t.textColor}));const e=c,s=b([]),y=b(!1),l=b(-1),f=b(null),u=new Map,p=b(0),d=b(!1),C=(t,i)=>{t?u.set(i,t):u.delete(i)},T=_(()=>{if(!w.value||!s.value.length)return!1;const t=s.value[0].time;return t<2?!1:(e.position||0)<t-e.anticipation}),ee=_(()=>{if(!e.mediaItem)return"";if("media_type"in e.mediaItem&&e.mediaItem.media_type==="track"){const t=e.mediaItem;if(t.artists?.length)return t.artists.map(i=>i.name).join(", ")}return"media_type"in e.mediaItem&&e.mediaItem.media_type==="artist"?e.mediaItem.name:""}),O=()=>e.lyrics??e.mediaItem?.metadata?.lyrics??null,Y=()=>e.lrcLyrics??e.mediaItem?.metadata?.lrc_lyrics??null,w=_(()=>{if(s.value.some(a=>a.time>0))return!0;const t=Y(),i=O();return!!(t&&t.includes("[")||i&&/\[\d+:\d+[.:]?\d*\]/.test(i))}),te=()=>{y.value=!0;try{const t=Y()||"",i=O()||"";let a="",n=!1;if(t?(a=t,n=!0):i&&/\[\d+:\d+[.:]?\d*\]/.test(i)?(a=i,n=!0):i&&(a=i,n=!1),n){const o=a.split(`
`).filter(r=>r.trim()).map(r=>ye(r)).sort((r,B)=>r.time-B.time),g=new Set;for(const r of o)!r.text.trim()&&r.time>0&&g.add(r.time);const h=o.filter(r=>r.text.trim()),E=[];if(h.length>0){const r=h[0].time;r>=W&&E.push({time:r-W,text:"",isBreak:!0,breakEnd:r})}for(let r=0;r<h.length;r++)if(E.push({time:h[r].time,text:h[r].text,isBreak:!1}),r<h.length-1){const B=h[r].time,F=h[r+1].time;let M=null;for(const R of g)if(R>B&&R<F){M=R;break}M!==null&&F-M>=Ie&&E.push({time:M,text:"",isBreak:!0,breakEnd:F})}s.value=E}else a?s.value=a.split(`
`).filter(o=>o.trim()).map(o=>({time:0,text:o.trim(),isBreak:!1})).filter(o=>o.text):s.value=[]}catch(t){console.error(`[LyricsViewer] Error processing lyrics: ${t}`),s.value=[]}finally{y.value=!1}},U=_(()=>{const t=l.value;if(t<0)return{filled:I,percent:100};const i=s.value[t];if(!i?.isBreak||!i.breakEnd)return{filled:I,percent:100};const a=e.position||0,n=i.breakEnd-z.value-i.time;if(n<=0)return{filled:I,percent:100};const g=Math.max(0,a-i.time)/n*I;return{filled:Math.min(I,Math.floor(g)),percent:Math.round((g-Math.floor(g))*100)}}),A=_(()=>U.value.filled),q=_(()=>U.value.percent),ie=_(()=>`${X}s`),z=_(()=>e.highlightAhead?X:0),ae=t=>{let i=-1;for(let a=0;a<s.value.length&&Math.round(s.value[a].time*1e3)<=t;a++)i=a;return i},G=t=>{const i=u.get(t),a=f.value;if(!i||!a)return;const o=a.clientHeight*(e.anticipation>0?.5:.35),g=i.offsetTop,h=i.offsetHeight;p.value=o-g-h/2};return S([()=>e.mediaItem?.item_id,()=>e.lyrics,()=>e.lrcLyrics],()=>{l.value=-1,p.value=99999,d.value=!1,u.clear(),te(),D(()=>{const t=u.get(0),i=f.value;t&&i&&(p.value=i.clientHeight-t.offsetTop+40)})},{immediate:!0}),S(()=>e.position,t=>{if(t===void 0||!s.value.length||!w.value)return;const i=Math.round((t+z.value)*1e3),a=ae(i);if(a!==l.value)if(a>=0)d.value=!0,l.value=a,D(()=>G(a));else{l.value=-1,d.value=!0;const n=u.get(0),o=f.value;n&&o&&(p.value=o.clientHeight-n.offsetTop+40)}}),S(T,t=>{!t&&s.value.length&&(d.value=!0,D(()=>G(0)))}),ne(()=>{u.clear()}),(t,i)=>(m(),v("div",pe,[y.value||c.externalLoading?(m(),v("div",he,[j(x(fe),{class:"size-6"}),k("div",null,L(x(H)("loading_lyrics")),1)])):s.value.length?w.value?(m(),v("div",{key:2,ref_key:"syncedContainerRef",ref:f,class:"synced-container"},[j(le,{name:"intro-fade"},{default:Q(()=>[T.value?(m(),v("div",_e,[k("div",{class:"song-title",style:$({color:c.textColor})},L(e.mediaItem?.name),5),k("div",ke,L(ee.value),1),k("div",Le,L(x(H)("lyrics_will_appear_soon")),1)])):K("",!0)]),_:1}),k("div",{class:"synced-content",style:$({transform:`translateY(${p.value}px)`,transition:d.value?void 0:"none"})},[(m(!0),v(N,null,V(s.value,(a,n)=>(m(),v("div",{key:n,ref_for:!0,ref:o=>C(o,n),class:J(["lyrics-line",{active:l.value===n,"lyrics-line--hidden":l.value>=0?n<l.value-1||n>l.value+2:n>2}])},[a.isBreak?(m(),v(N,{key:1},V(I,o=>k("span",{key:o,class:J(["break-note",{"break-note--filled":l.value===n&&o<=A.value,"break-note--filling":l.value===n&&o===A.value+1}]),style:$(l.value===n&&o===A.value+1?{backgroundImage:`linear-gradient(to right, ${c.textColor} ${q.value}%, color-mix(in srgb, ${c.textColor} 35%, transparent) ${q.value}%)`,backgroundClip:"text","-webkit-background-clip":"text","-webkit-text-fill-color":"transparent"}:void 0)},"♫",6)),64)):(m(),v(N,{key:0},[oe(L(a.text),1)],64))],2))),128))],4)],512)):e.anticipation?K("",!0):(m(),re(x(me),{key:3,class:"h-full w-full static-lyrics"},{default:Q(()=>[k("div",be,[(m(!0),v(N,null,V(s.value,(a,n)=>(m(),v("div",{key:n,class:"lyrics-line active"},L(a.text),1))),128))])]),_:1})):(m(),v("div",ge,L(x(H)("no_lyrics_available")),1))]))}}),Ce=ve(xe,[["__scopeId","data-v-828b10ea"]]);function Te(c,e,s){if(c===void 0||e===void 0||s!==void 0&&s!==Z.PLAYING)return c;const y=e*1e3,l=Date.now(),u=Math.max(0,l-y)/1e3;return c+u}function we(c){const e=b(0);let s=null;const y=()=>{const d=P.activePlayerQueue;d?.elapsed_time!=null&&d?.elapsed_time_last_updated!=null&&(e.value=Te(d.elapsed_time,d.elapsed_time_last_updated,P.activePlayer?.playback_state)??0),s=requestAnimationFrame(y)},l=()=>{s||(s=requestAnimationFrame(y))},f=()=>{s&&(cancelAnimationFrame(s),s=null)};let u=!1;const p=()=>{document.visibilityState==="visible"&&u?l():f()};return document.addEventListener("visibilitychange",p),ue(()=>{const d=P.activePlayer?.playback_state===Z.PLAYING,C=P.activePlayerQueue,T=c?c.value:!0;u=d&&!!C?.active&&T,u&&document.visibilityState==="visible"?l():f()}),de(()=>{f(),document.removeEventListener("visibilitychange",p)}),{elapsedTime:e,start:l,stop:f}}export{Ce as L,Te as c,we as u};
