import{I as f}from"./ItemsListing-db2c60f3.js";import{d as b,ae as h,r as d,o as k,b as a,af as i,a as v,c as E,e as D,M as n,ag as m,a3 as T,D as g}from"./index-2dd0c7d2.js";import"./ListviewItem-a6570b10.js";import"./helpers-4d7c5bf6.js";import"./Container-fdf4c1f5.js";import"./VListItem-cb387084.js";import"./_plugin-vue_export-helper-c27b6911.js";/* empty css              */import"./VLabel-1f522f96.js";import"./VList-d110868a.js";import"./VCard-907b4685.js";import"./VCardText-0ed41581.js";import"./VMenu-97c1c955.js";import"./ListItem-87435fbb.js";import"./Button-69b906cf.js";import"./VTooltip-e62b61bd.js";import"./VCheckboxBtn-c3f9b6ff.js";import"./PanelviewItem-68416368.js";import"./VSpacer-e11897c6.js";import"./Alert-65a1093b.js";import"./VAlert-4eed3112.js";import"./Toolbar-1720c469.js";import"./VBadge-91055b8b.js";import"./VToolbar-6047eebf.js";import"./ItemContextMenu.vue_vue_type_style_index_0_scoped_7aadaa8c_lang-7ff19a96.js";import"./eventbus-d154090d.js";import"./VTextField-de7279c6.js";import"./VVirtualScroll-660ff9a6.js";import"./VSnackbar-6950ff68.js";import"./layout-42d7f450.js";const at=b({name:"Tracks",__name:"LibraryTracks",setup(I){const{t:r}=h(),u=d([]),s=d(!1),l={name:"name",name_desc:"name DESC",sort_name:"sort_name",sort_name_desc:"sort_name DESC",artist:"artists.name, name",year:"year",year_desc:"year DESC",album:"albums.name, tracks.name",duration:"duration",duration_desc:"duration DESC",timestamp_added:"timestamp_added",timestamp_added_desc:"timestamp_added DESC",last_played:"last_played",last_played_desc:"last_played DESC",play_count:"play_count",play_count_desc:"play_count DESC"};k(()=>{const t=a.subscribe_multi([i.MEDIA_ITEM_ADDED,i.MEDIA_ITEM_UPDATED,i.MEDIA_ITEM_DELETED],e=>{var o;(o=e.object_id)!=null&&o.startsWith("library://track")&&(s.value=!0)});v(t)});const _=async function(t){if(t.favoritesOnly=t.favoritesOnly||void 0,t.refresh&&!s.value){for(a.startSync([n.TRACK]),await m(250);a.syncTasks.value.length>0&&a.syncTasks.value.filter(e=>e.media_types.includes(n.TRACK)).length!=0;)await m(500);await m(500)}return s.value=!1,await a.getLibraryTracks(t.favoritesOnly,t.search,t.limit,t.offset,l[t.sortBy])},y=async function(){const t=prompt(r("enter_url"));if(t){if(!(t!=null&&t.startsWith("http"))){alert(r("invalid_input"));return}a.getItem(n.TRACK,t,"builtin").then(e=>{var c;const o=prompt(r("enter_name"),e.name);e.name=o||e.name,delete e.sort_name;const p=prompt(r("image_url"),(c=e.metadata.images)!=null&&c.length?e.metadata.images[0].path:"");p&&(e.metadata.images=[{type:T.THUMB,path:p,provider:"builtin",remotely_accessible:!0}]),a.addItemToLibrary(e).then(()=>g.go(0))}).catch(e=>alert(e))}};return(t,e)=>(E(),D(f,{itemtype:"tracks",items:u.value,"show-provider":!1,"show-favorites-only-filter":!0,"show-track-number":!1,"load-paged-data":_,"sort-keys":Object.keys(l),"show-album":!0,"update-available":s.value,title:t.$t("tracks"),"show-search-button":!0,"allow-key-hooks":!0,"context-menu-items":[{label:"add_url_item",labelArgs:[],action:()=>{y()},icon:"mdi-link-plus"}],icon:"mdi-music-note"},null,8,["items","sort-keys","update-available","title","context-menu-items"]))}});export{at as default};
