import{dr as e,sn as t}from"./vendor-Dcerr41Y.js";import{D as n,E as r,Ki as i,R as a,Ut as o,Vt as s,Wi as c,Y as l,b as u,fa as d,h as f,m as p,ma as m,ra as h,ta as g,x as _}from"./ws-DjAvcWfg.js";import{r as v,t as y}from"./PlaybackEventBus--BJS1dhm.js";import{r as b,t as x}from"./RPC-BluT8P0m.js";v(),p(),l(),o(),t(),h(),_(),m(),i(),b();async function S(){console.log(`Hello Genten!`);let t=await c.sendIZRequest(`/_/config/info`).catch(e=>(console.warn(`[Genten] Failed to load /_/config/info; continuing without host info:`,e),null));console.log(t),document.body.setAttribute(`data-os`,g()),r(()=>{c.sendJSONPost(`/_/discord-rpc/start`,{clientId:u(`connectivity.discord.client`)}).catch(e=>{console.warn(`[Genten] Discord RPC startup skipped:`,e)}),e(()=>n().visual.appearance,e=>{switch(e){case`dark`:d.window.setNativeTheme({theme:`dark`});break;case`light`:d.window.setNativeTheme({theme:`light`});break;default:case`auto`:d.window.setNativeTheme({theme:`system`});break}},{immediate:!0})},!0)}async function C(){if(f(),`mediaSession`in navigator){let e=window.navigator.mediaSession,t=(t,n)=>{e.setActionHandler(t,e=>{s(`mediaSession.action`,{action:t,hidden:document.hidden,focused:document.hasFocus()}),n(e)})};t(`play`,()=>{x.play()}),t(`pause`,()=>{x.pause()}),t(`previoustrack`,()=>{x.previous()}),t(`nexttrack`,()=>{x.next()}),t(`seekto`,e=>{let t=e?.seekTime;typeof t==`number`&&Number.isFinite(t)&&x.seekToTime(t)}),t(`seekbackward`,e=>{x.seekBy(-Math.abs(e?.seekOffset??10))}),t(`seekforward`,e=>{x.seekBy(Math.abs(e?.seekOffset??10))})}let e=null,t=null,n=null,r=null,i=()=>{t=null;let i=e;if(e=null,i)try{let e=i.item;if(!e)return;let t=i.attributes??{},o=a(t?.artwork?.url,640,640,void 0,`jpg`)??``,s={id:e.id,type:e.type,attributes:{name:t?.name??``,artistName:t?.artistName??``,albumName:t?.albumName??``,durationInMillis:t?.durationInMillis,genreNames:Array.isArray(t?.genreNames)?[...t.genreNames]:[],artwork:{url:o},personalRating:+!!i.inFavorites,inLibrary:i.inLibrary}};n=s,d.playback.setNowPlayingItem(s);try{e.id&&e.id!==r&&(r=e.id,u(`connectivity.playbackNotifications`)&&!document.hasFocus()&&d.showNotification({title:s.attributes.name||``,body:s.attributes.artistName||``}))}catch(e){console.warn(`[Genten] Failed to send track-change notification`,e)}let c=window.navigator.mediaSession;if(!c)return;c.metadata=new MediaMetadata({title:s.attributes.name,artist:s.attributes.artistName,album:s.attributes.albumName,artwork:o?[{src:o,sizes:`640x640`,type:`image/jpeg`}]:[]})}catch(e){console.error(`Error updating media session metadata`,e)}};y.on(`playbackStatus.nowPlayingItemDidChange`,n=>{e=n,t===null&&(t=setTimeout(i,120))}),y.on(`playbackStatus.nowPlayingStatusDidChange`,e=>{try{n&&(n.attributes.personalRating=+!!e.inFavorites,n.attributes.inLibrary=e.inLibrary,d.playback.setNowPlayingItem(n))}catch{}}),y.on(`playbackStatus.playbackStateDidChange`,e=>{try{let t=e.state,n=window.navigator.mediaSession;if(n&&(t===`playing`||t===`seeking`?n.playbackState=`playing`:t===`paused`?n.playbackState=`paused`:t===`stopped`&&(n.playbackState=`none`)),t!==`playing`&&t!==`paused`&&t!==`stopped`&&t!==`seeking`)return;if(d.playback.setPlaybackState({state:t}),n&&e.item&&e.attributes){let t=e.attributes,r=a(t?.artwork?.url,640,640,void 0,`jpg`)??``;n.metadata=new MediaMetadata({title:t?.name??``,artist:t?.artistName??``,album:t?.albumName??``,artwork:r?[{src:r,sizes:`640x640`,type:`image/jpeg`}]:[]})}}catch{}}),y.on(`playbackStatus.playbackTimeDidChange`,e=>{try{d.playback.setPlaybackTime({currentPlaybackDuration:e.currentPlaybackDuration,currentPlaybackTime:e.currentPlaybackTime,currentPlaybackTimeRemaining:e.currentPlaybackTimeRemaining,isPlaying:e.isPlaying,anchor:e.anchor});let t=window.navigator.mediaSession;if(!t)return;t.setPositionState?.({duration:e.currentPlaybackDuration,position:e.currentPlaybackTime,playbackRate:1})}catch{}}),y.on(`playerStatus.shuffleModeDidChange`,e=>{try{d.playback.setShuffleMode(e.shuffleMode??0)}catch{}}),y.on(`playerStatus.repeatModeDidChange`,e=>{try{d.playback.setRepeatMode(e.repeatMode??0)}catch{}}),y.on(`playerStatus.volumeDidChange`,e=>{try{d.playback.setVolume({volume:e.volume})}catch{}})}export{C as n,S as t};