import{I as v}from"./ItemsListing-08846369.js";import{d as h,a5 as T,r as u,s as p,o as k,b as a,a7 as n,a as g,c as w,e as E,M as d,ac as I}from"./index-a1b8d248.js";import{s as l}from"./VCheckbox-5797eb11.js";import"./eventbus-142801ce.js";import"./VListItem-99589506.js";import"./ListItem-8ce3726a.js";import"./Button-36db0a16.js";import"./_plugin-vue_export-helper-c27b6911.js";import"./VMenu-a4b04473.js";import"./VCard-62364c90.js";import"./VCardText-426e9876.js";import"./VSpacer-c665d1ef.js";/* empty css              */import"./PanelviewItemCompact-412c96c5.js";import"./VAlert-11c8d9d0.js";import"./Container-6ba8cd4d.js";import"./Toolbar-e7daca02.js";import"./VList-db9ad95c.js";import"./VToolbar-69b0039c.js";import"./VTextField-11675678.js";import"./VCheckboxBtn-b34ea085.js";import"./VInfiniteScroll-b88bd748.js";import"./layout-2c6f8b0d.js";import"./VVirtualScroll-abd3c2c6.js";const X=h({name:"Tracks",__name:"LibraryTracks",setup(D){const{t:r}=T(),o=u(!1),i=u(p.libraryTracksCount),_=["name","name_desc","sort_name","sort_name_desc","duration","duration_desc","timestamp_added","timestamp_added_desc","last_played","last_played_desc","play_count","play_count_desc"];k(()=>{const t=a.subscribe_multi([n.MEDIA_ITEM_ADDED,n.MEDIA_ITEM_UPDATED,n.MEDIA_ITEM_DELETED],e=>{var s;(s=e.object_id)!=null&&s.startsWith("library://track")&&(o.value=!0)});g(t)});const f=async function(t){if(t.favoritesOnly=t.favoritesOnly||void 0,t.refresh&&!o.value){for(a.startSync([d.TRACK]),await l(250);a.syncTasks.value.length>0&&a.syncTasks.value.filter(e=>e.media_types.includes(d.TRACK)).length!=0;)await l(500);await l(500)}return o.value=!1,y(t),await a.getLibraryTracks(t.favoritesOnly,t.search,t.limit,t.offset,t.sortBy)},y=async function(t){if(!t.favoritesOnly){i.value=p.libraryTracksCount;return}i.value=await a.getLibraryTracksCount(t.favoritesOnly||!1)},b=async function(){const t=prompt(r("enter_url"));if(t){if(!(t!=null&&t.startsWith("http"))){alert(r("invalid_input"));return}a.getTrack(t,"builtin").then(e=>{var m;const s=prompt(r("enter_name"),e.name);e.name=s||e.name,delete e.sort_name;const c=prompt(r("image_url"),(m=e.metadata.images)!=null&&m.length?e.metadata.images[0].path:"");c&&(e.metadata.images=[{type:I.THUMB,path:c,provider:"builtin",remotely_accessible:!0}]),a.addItemToLibrary(e).then(()=>window.location.reload())}).catch(e=>alert(e))}};return(t,e)=>(w(),E(v,{itemtype:"tracks","show-provider":!1,"show-favorites-only-filter":!0,"show-track-number":!1,"load-paged-data":f,"sort-keys":_,"show-album":!0,"update-available":o.value,title:t.$t("tracks"),"show-search-button":!0,"allow-key-hooks":!0,"context-menu-items":[{label:"add_url_item",labelArgs:[],action:()=>{b()},icon:"mdi-link-plus"}],icon:"mdi-music-note","restore-state":!0,total:i.value},null,8,["update-available","title","context-menu-items","total"]))}});export{X as default};
