import{n as e}from"./rolldown-runtime-CMxvf4Kt.js";import{An as t,Fr as n,Ht as r,Nn as i,gn as a,ut as o}from"./ws-JRT2XE7Y.js";async function s(e,t={}){let r=i(),o=new URL(e),s=o.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(o.pathname===`/deeplink`)switch(o.searchParams.get(`p`)){case`library`:return r.push(`/am/recently-added`);case`radio`:return r.push(`/am/radio`);case`listenNow`:return r.push(`/am/listen-now`);default:return r.push(`/am/browse`)}if(u(`home`)||u(`listen-now`))return r.push(`/am/listen-now`);if(u(`browse`)||u(`new`))return r.push(`/am/browse`);if(u(`radio`))return r.push(`/am/radio`);if(u(`/library/recently-added`))return r.push(`/am/recently-added`);if(u(`/library/artists`))return r.push(`/am/artists`);if(u(`/library/albums`))return r.push(`/am/albums`);if(u(`/library/songs`))return r.push(`/am/songs`);if(l?.[0]===`library`&&l.length===3){let[e,r,i]=l;if(r===`playlist`){let e=(await n(`/v1/me/library/playlists/${i}`)).data.data[0];return a(e,t.play,{skipQueueWarning:t.skipQueueWarning})}else if(r===`album`){let e=(await n(`/v1/me/library/albums/${i}`)).data.data[0];return a(e,t.play,{skipQueueWarning:t.skipQueueWarning})}else if(r===`artist`){let e=(await n(`/v1/me/library/artists/${i}/catalog`)).data.data[0];return a(e,t.play,{skipQueueWarning:t.skipQueueWarning})}}if(l?.[0]?.length===2){if((e=>c.includes(e))(l?.[1]??``)){let[e,i,s,c,u]=l;if(o.searchParams.get(`i`)&&t.play){let r=(await n(`/v1/catalog/${e}/songs/${o.searchParams.get(`i`)}`)).data.data[0];return a(r,t.play,{skipQueueWarning:!0})}switch(i){case`albums`:case`album`:let i=(await n(`/v1/catalog/${e}/albums/${c}`)).data.data[0];return a(i,t.play,{containerSongId:o.searchParams.get(`i`)??void 0});case`playlists`:case`playlist`:let s=(await n(`/v1/catalog/${e}/playlists/${c}`)).data.data[0];return a(s,t.play,{containerSongId:o.searchParams.get(`i`)??void 0,skipQueueWarning:t.skipQueueWarning});case`artists`:case`artist`:let l=o.searchParams.get(`section`);if(u&&l)return r.push(`/am/artist/${c}/view/${l}`);let d=(await n(`/v1/catalog/${e}/artists/${c}`)).data.data[0];return a(d,t.play,{skipQueueWarning:t.skipQueueWarning});case`songs`:case`song`:let f=(await n(`/v1/catalog/${e}/songs/${c}`)).data.data[0];return a(f,t.play,{skipQueueWarning:!0});case`curators`:case`curator`:return r.push(`/am/curator/${c}`)}}if(l.length===3){let[e,t,n]=l;switch(t){case`room`:return r.push(`/am/room/${n}`);case`multi-room`:return r.push(`/am/multi-room/${n}`);case`grouping`:return r.push(`/am/grouping/${n}`)}}}if(l[0]===`profile`)return r.push(`/am/profile/${l[1]}`);if(o.hostname===`replay.music.apple.com`)return window.open(e);if(l?.[0]===`WebObjects`&&l?.[1]===`MZStore.woa`)switch(l[3]){case`viewMultiRoom`:return r.push(`/am/multi-room/${o.searchParams.get(`fcId`)}`);case`viewTop`:return r.push(`/am/charts/${o.searchParams.get(`genreId`)}`);case`viewFeature`:let{id:e}=(await n(`/v1/editorial/$STOREFRONT/multiplex/${o.searchParams.get(`id`)}?art[url]=f&format[resources]=map&platform=web`)).data.results.target;r.push(`/am/multi-room/${e}`)}}var c,l=e((()=>{t(),o(),r(),c=[`album`,`artist`,`playlist`,`song`,`curator`]}));export{s as n,l as t};