import{Xn as e,hr as t,qt as n}from"./vendor-C4JLrdLj.js";import{it as r}from"./vendor-quasar-BMuYn1t2.js";import{r as i,t as a}from"./TokenManager-CyKz1gr1.js";import{Bn as o,Fr as s,Hn as c,Ir as l,K as u,Lr as d,Ni as f,Or as p,Si as m,Ti as h,V as g,X as _,Y as v,b as y,ct as b,h as x,ji as S,kr as C,m as w,st as T,ut as E,wi as D,x as O}from"./ws-JRT2XE7Y.js";import{f as k,h as A,m as j}from"./index-Dhwlon97.js";import{n as M}from"./genten-DWChswTL.js";import{n as N,t as P}from"./smart-playlist-store-DUBQztY1.js";i(),f(),D(),l(),C(),T(),k(),O(),o(),w(),P(),u(),E(),n();var F=c();async function I(e){if(localStorage.getItem(`mk-disabled`)===`true`)return;let t=x();if(!g(`no-mktasks-caching`)){await Promise.all([t.refreshPlaylists(),V().then(()=>{H()}),t.updatePinnedItems()]);try{await N().refreshDue()}catch(e){console.warn(`[MusicKit Task] smart playlist refresh failed`,e)}}}var L=null,R=t(Date.now());function z(){if(localStorage.getItem(`mk-disabled`)===`true`||L)return;let e=y(`appleMusic.backgroundRefreshTime`)??300;e<60&&(e=60),console.debug(`[MusicKit Task] Starting background refresh`),Date.now()-R.value>5*e*1e3&&(console.debug(`[MusicKit Task] Running background refresh after window focus`),I(),R.value=Date.now()),L=setInterval(()=>{console.debug(`[MusicKit Task] Running background refresh`),I(),R.value=Date.now()},e*1e3)}function B(){localStorage.getItem(`mk-disabled`)!==`true`&&(L&&=(console.debug(`[MusicKit Task] Stopping background refresh`),clearInterval(L),null))}e(()=>F.windowIsHidden,e=>{if(e){B();return}z()});async function V(){console.debug(`[MusicKit Task] Getting social badging`);let e=x();e.socialBadges=(await s(`/v1/social/badging-map`)).data.results?.badgingMap??{}}async function H(){let e=x(),t=e.socialBadges,n=[...new Set(Object.values(t).flat())],r=(await Promise.all(n.map(async e=>{try{return(await s(`/v1/social/$STOREFRONT/social-profiles/${e}`)).data.data[0]}catch(e){console.error(e)}}))).reduce((e,t)=>(e[t.id]=t,e),{});try{let e=await s(`/v1/me/social-profile/`).then(e=>e.data.data[0]);r[e.id]=e}catch{}e.cachedSocialProfiles=r}O(),o(),w(),u();var U=S(),W=r(()=>{if(localStorage.getItem(`mk-disabled`)===`true`||_())return;a.init();let e=localStorage.getItem(`music.ampwebplay.media-user-token`),t=c(),n=x(),r=d();async function i(){if(v(`MusicKit`,`boot:mklite-only`,`info`,`Setting up MKLite-only mode (skipping MusicKit.js)`),n.musicKitReady=!0,t.musicKitLoaded=!0,await a.getDeveloperToken(),n.setAuthorizedStatus(!0),m.setTokens(),await b().init(),y(`remote.enabled`)&&y(`remote.tunnelUUID`)!==``)try{let{apiTokens:e}=y(`connectivity`),{tunnelUUID:t}=y(`remote`);for(let n of e)if(n.method===`tunnel`){h(`/tunnel/open`,{method:`POST`,body:JSON.stringify({id:t})}).then(()=>{v(`MusicKit`,`boot:mklite-only:remote`,`debug`,`Opened WAN tunnel!`,t)});break}}catch(e){v(`MusicKit`,`boot:mklite-only:remote`,`debug`,`Failed to open WAN tunnel.`,e)}U===`dotnet`?await j():U===`genten`&&await M(),I(),z(),p(),U===`dotnet`&&A(!0);let e=Number(localStorage.getItem(`volume`)||1);n.normalizedVolume=Math.min(Math.max(Number.isFinite(e)?e:1,0),1),v(`MusicKit`,`boot:mklite-only`,`info`,`MKLite-only setup complete.`)}window.__BUILDINFO__.IS_PE!==`true`&&(e&&a.isAuthorized()?(v(`MusicKit`,`boot`,`info`,`User has valid music user token, using MKLite-only mode`),i().catch(e=>{v(`MusicKit`,`boot`,`warn`,`MKLite-only setup failed`,e);try{r.reportAppleIssue(`Apple Music initialization failed`,e?.message??void 0,45e3)}catch{}})):v(`MusicKit`,`boot`,`info`,`No valid tokens`))});export{W as default};