import{n as e}from"./rolldown-runtime-DAXXjFlN.js";import{Sa as t,Zn as n,da as r,si as i,wa as a,zi as o}from"./ws-Dl8XkIy4.js";async function s(e,t={}){let n=a(),i=new URL(e),s=i.pathname,l=s.split(`/`).filter(Boolean);console.debug(`Opening Apple Music URL:`,e);function u(e){return s.match(RegExp(`^/([a-zA-Z]{2})/${e}`))}if(i.pathname===`/deeplink`)switch(i.searchParams.get(`p`)){case`library`:return n.push(`/am/recently-added`);case`radio`:return n.push(`/am/radio`);case`listenNow`:return n.push(`/am/listen-now`);default:return n.push(`/am/browse`)}if(u(`home`)||u(`listen-now`))return n.push(`/am/listen-now`);if(u(`browse`)||u(`new`))return n.push(`/am/browse`);if(u(`radio`))return n.push(`/am/radio`);if(u(`replay`)&&l.length===2)return n.push(`/am/replay`);if(u(`/library/recently-added`))return n.push(`/am/recently-added`);if(u(`/library/artists`))return n.push(`/am/artists`);if(u(`/library/albums`))return n.push(`/am/albums`);if(u(`/library/songs`))return n.push(`/am/songs`);if(l?.[0]===`library`&&l.length===3){let[e,n,i]=l;if(n===`playlist`){let e=(await r(`/v1/me/library/playlists/${i}`)).data.data[0];return o(e,t.play,{skipQueueWarning:t.skipQueueWarning})}else if(n===`album`){let e=(await r(`/v1/me/library/albums/${i}`)).data.data[0];return o(e,t.play,{skipQueueWarning:t.skipQueueWarning})}else if(n===`artist`){let e=(await r(`/v1/me/library/artists/${i}/catalog`)).data.data[0];return o(e,t.play,{skipQueueWarning:t.skipQueueWarning})}}if(l?.[0]?.length===2){if((e=>c.includes(e))(l?.[1]??``)){let[e,a,s,c,u]=l;if(i.searchParams.get(`i`)&&t.play){let n=(await r(`/v1/catalog/${e}/songs/${i.searchParams.get(`i`)}`)).data.data[0];return o(n,t.play,{skipQueueWarning:!0})}switch(a){case`albums`:case`album`:let a=(await r(`/v1/catalog/${e}/albums/${c}`)).data.data[0];return o(a,t.play,{containerSongId:i.searchParams.get(`i`)??void 0});case`playlists`:case`playlist`:let s=(await r(`/v1/catalog/${e}/playlists/${c}`)).data.data[0];return o(s,t.play,{containerSongId:i.searchParams.get(`i`)??void 0,skipQueueWarning:t.skipQueueWarning});case`artists`:case`artist`:let l=i.searchParams.get(`section`);if(u&&l)return n.push(`/am/artist/${c}/view/${l}`);let d=(await r(`/v1/catalog/${e}/artists/${c}`)).data.data[0];return o(d,t.play,{skipQueueWarning:t.skipQueueWarning});case`songs`:case`song`:let f=(await r(`/v1/catalog/${e}/songs/${c}`)).data.data[0];return o(f,t.play,{skipQueueWarning:!0});case`curators`:case`curator`:return n.push(`/am/curator/${c}`)}}if(l.length===3){let[e,t,r]=l;switch(t){case`room`:return n.push(`/am/room/${r}`);case`multi-room`:return n.push(`/am/multi-room/${r}`);case`grouping`:return n.push(`/am/grouping/${r}`)}}}if(l[0]===`profile`)return n.push(`/am/profile/${l[1]}`);if(i.hostname===`replay.music.apple.com`&&l.length<=1)return n.push(`/am/replay`);if(l?.[0]===`WebObjects`&&l?.[1]===`MZStore.woa`)switch(l[3]){case`viewMultiRoom`:return n.push(`/am/multi-room/${i.searchParams.get(`fcId`)}`);case`viewTop`:return n.push(`/am/charts/${i.searchParams.get(`genreId`)}`);case`viewFeature`:let{id:e}=(await r(`/v1/editorial/$STOREFRONT/multiplex/${i.searchParams.get(`id`)}?art[url]=f&format[resources]=map&platform=web`)).data.results.target;n.push(`/am/multi-room/${e}`)}}var c,l=e((()=>{t(),n(),i(),c=[`album`,`artist`,`playlist`,`song`,`curator`]}));export{s as n,l as t};