import{aC as t,M as n,J as e,U as p,aD as f,P as c}from"./index-e5db0b73.js";function s(i){return{all:i=i||new Map,on:function(r,l){var a=i.get(r);a?a.push(l):i.set(r,[l])},off:function(r,l){var a=i.get(r);a&&(l?a.splice(a.indexOf(l)>>>0,1):i.set(r,[]))},emit:function(r,l){var a=i.get(r);a&&a.slice().map(function(o){o(l)}),(a=i.get("*"))&&a.slice().map(function(o){o(r,l)})}}}const b=s(),d=function(i){var r;if(i.media_type==n.FOLDER)return!0;if("provider_mappings"in i){for(const l of i.provider_mappings)if(l.available&&((r=e.providers[l.provider_instance])!=null&&r.available))return!0}else if("available"in i)return i.available;return!1},_=function(i){var r,l;if("provider_mappings"in i){for(const a of i.provider_mappings)if((r=e.providers[a.provider_instance])!=null&&r.supported_features.includes(c.SIMILAR_TRACKS))return!0}else if((l=e.providers[i.provider])!=null&&l.supported_features.includes(c.SIMILAR_TRACKS))return!0;return!1},y=function(i,r){const l=[];if(i.length==0||!d(i[0]))return l;let a=t.PLAY,o=t.NEXT;return(i.length>10||[n.ALBUM,n.PLAYLIST].includes(i[0].media_type))&&(a=t.REPLACE,o=t.REPLACE_NEXT),i.length==1&&r&&r.uri!=i[0].uri&&(r.media_type==n.PLAYLIST&&l.push({label:"play_playlist_from",action:()=>{e.playMedia(r.uri,t.REPLACE,!1,i[0].item_id)},icon:"mdi-play-circle-outline",labelArgs:[]}),r.media_type==n.ALBUM&&l.push({label:"play_album_from",action:()=>{e.playMedia(r.uri,t.REPLACE,!1,i[0].item_id)},icon:"mdi-play-circle-outline",labelArgs:[]})),l.push({label:"play_now",action:()=>{e.playMedia(i.map(u=>u.uri),a)},icon:"mdi-play-circle-outline",labelArgs:[]}),_(i[0])&&l.push({label:"play_radio",action:()=>{e.playMedia(i.map(u=>u.uri),a,!0)},icon:"mdi-radio-tower",labelArgs:[]}),(i.length===1||i[0].media_type===n.TRACK)&&l.push({label:"play_next",action:()=>{e.playMedia(i.map(u=>u.uri),o)},icon:"mdi-skip-next-circle-outline",labelArgs:[]}),l.push({label:"add_queue",action:()=>{e.playMedia(i.map(u=>u.uri),t.ADD)},icon:"mdi-playlist-plus",labelArgs:[]}),l},g=function(i,r){const l=[];if(i.length==0)return l;if(i.length===1&&i[0]!==r&&d(i[0])&&l.push({label:"show_info",labelArgs:[],action:()=>{var a;p.push({name:i[0].media_type,params:{itemId:i[0].item_id,provider:i[0].provider},query:{album:"album"in i[0]?(a=i[0].album)==null?void 0:a.uri:""}})},icon:"mdi-information-outline"}),i.length===1&&d(i[0])&&"artists"in i[0]&&i[0].artists.length===1)for(const a of i[0].artists)l.push({label:"goto_artist",labelArgs:[a.name],action:()=>{p.push({name:"artist",params:{itemId:a.item_id,provider:a.provider}})},icon:"mdi-account-music"});if(i.length===1&&d(i[0])&&"album"in i[0]&&i[0].album&&l.push({label:"goto_album",labelArgs:[i[0].album.name],action:()=>{p.push({name:"album",params:{itemId:i[0].album.item_id,provider:i[0].album.provider}})},icon:"mdi-album"}),i.length===1&&(i[0]==r||!d(i[0]))&&l.push({label:"refresh_item",labelArgs:[],action:async()=>{await e.refreshItem(i[0]),p.go(0)},icon:"mdi-refresh"}),i[0].provider!="library"&&d(i[0])&&l.push({label:"add_library",labelArgs:[],action:()=>{for(const a of i)e.addItemToLibrary(a)},icon:"mdi-bookshelf"}),i[0].provider=="library"&&l.push({label:"remove_library",labelArgs:[],action:()=>{if(confirm(f("confirm_library_remove"))){for(const a of i)e.removeItemFromLibrary(a.media_type,a.item_id);i[0].item_id==(r==null?void 0:r.item_id)?p.go(-1):p.go(0)}},icon:"mdi-bookshelf"}),"favorite"in i[0]&&!i[0].favorite&&l.push({label:"favorites_add",labelArgs:[],action:()=>{for(const a of i)e.addItemToFavorites(a)},icon:"mdi-heart-outline"}),"favorite"in i[0]&&i[0].favorite&&l.push({label:"favorites_remove",labelArgs:[],action:()=>{for(const a of i)e.removeItemFromFavorites(a.media_type,a.item_id),a.favorite=!1},icon:"mdi-heart"}),r&&r.media_type===n.PLAYLIST){const a=r;i[0].media_type===n.TRACK&&a.is_editable&&l.push({label:"remove_playlist",labelArgs:[],action:()=>{e.removePlaylistTracks(a.item_id,i.map(o=>o.position))},icon:"mdi-minus-circle-outline"})}return i[0].media_type==="track"&&"provider_mappings"in i[0]&&l.push({label:"add_playlist",labelArgs:[],action:()=>{b.emit("playlistdialog",{items:i,parentItem:r})},icon:"mdi-plus-circle-outline"}),l};export{g as a,b as e,y as g,d as i};
