import{I as y}from"./ItemsListing-7bf0c0b0.js";import{d as b,a5 as h,r as p,s as v,o as T,b as a,a7 as i,a as k,c as g,e as w,M as n,ac as I}from"./index-103db515.js";import{s as l}from"./VCheckbox-ddd5d7c4.js";import"./eventbus-6e1536e2.js";import"./VListItem-ab7a82e2.js";import"./ListItem-91f42136.js";import"./Button-412f73ce.js";import"./_plugin-vue_export-helper-c27b6911.js";import"./VMenu-482e7fbc.js";import"./VCard-d4f085fd.js";import"./VCardText-1a59cac1.js";import"./VSpacer-adcb10ea.js";/* empty css              */import"./PanelviewItemCompact-5ede3757.js";import"./VAlert-4165d2e6.js";import"./Container-d98651c4.js";import"./Toolbar-908bc969.js";import"./VList-cac73f62.js";import"./VToolbar-dcf67568.js";import"./VTextField-73438668.js";import"./VCheckboxBtn-19bafbc9.js";import"./VInfiniteScroll-c2610a44.js";import"./layout-e7ad5131.js";import"./VVirtualScroll-b23fb9a8.js";const V=b({name:"Tracks",__name:"LibraryTracks",setup(E){const{t:r}=h(),o=p(!1),m=p(v.libraryTracksCount),d=["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"];T(()=>{const t=a.subscribe_multi([i.MEDIA_ITEM_ADDED,i.MEDIA_ITEM_UPDATED,i.MEDIA_ITEM_DELETED],e=>{var s;(s=e.object_id)!=null&&s.startsWith("library://track")&&(o.value=!0)});k(t)});const _=async function(t){if(t.favoritesOnly=t.favoritesOnly||void 0,t.refresh&&!o.value){for(a.startSync([n.TRACK]),await l(250);a.syncTasks.value.length>0&&a.syncTasks.value.filter(e=>e.media_types.includes(n.TRACK)).length!=0;)await l(500);await l(500)}return o.value=!1,m.value=await a.getLibraryTracksCount(t.favoritesOnly||!1),await a.getLibraryTracks(t.favoritesOnly,t.search,t.limit,t.offset,t.sortBy)},f=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 u;const s=prompt(r("enter_name"),e.name);e.name=s||e.name,delete e.sort_name;const c=prompt(r("image_url"),(u=e.metadata.images)!=null&&u.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)=>(g(),w(y,{itemtype:"tracks","show-provider":!1,"show-favorites-only-filter":!0,"show-track-number":!1,"load-paged-data":_,"sort-keys":d,"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:()=>{f()},icon:"mdi-link-plus"}],icon:"mdi-music-note","restore-state":!0,total:m.value},null,8,["update-available","title","context-menu-items","total"]))}});export{V as default};
