import{V as $,_ as B,a as I}from"./ItemsListing.vue_vue_type_style_index_0_lang-cfe67ae4.js";import{v as F,r as o,w as L,o as _,b as C,y as i,E as f,l as c,A as v,Q as E,N,F as b,G as V,L as R,z as g,I as x}from"./index-5804982a.js";import{V as D}from"./VToolbar-ce6590ba.js";import{k as P}from"./forwardRefs-03519353.js";import{V as U}from"./VTextField-b58cde95.js";import"./ListviewItem-8b7ae6a6.js";import"./VBadge-3d00ada8.js";import"./Container-d5ee1f41.js";import"./VMenu-18f2572a.js";/* empty css              */import"./VInput-fe7a35fc.js";import"./VSlideGroup-711de993.js";import"./VCard-cc8044ef.js";import"./VCardText-963b2439.js";import"./VTooltip-5622a67d.js";import"./PanelviewItem.vue_vue_type_style_index_0_lang-04756f0a.js";import"./contextmenu-95007cdc.js";import"./Alert-38a1b933.js";import"./VAlert-8600f5db.js";import"./VVirtualScroll-72995e2a.js";const le=F({__name:"Search",props:{initSearch:{}},setup(w){const p=w,a=o(""),d=o(""),n=o(!1),t=o(),h=o(!1),k=o();L(()=>a.value,()=>{clearTimeout(k.value),k.value=setTimeout(()=>{S()},200)});const S=async function(){h.value=!0,localStorage.setItem("globalsearch",a.value),a.value?t.value=await R.search(a.value):t.value=void 0,h.value=!1,d.value=a.value},m=function(e){if(!t.value)return[];if(e=="artists")return t.value.artists;if(e=="albums")return t.value.albums;if(e=="tracks")return t.value.tracks;if(e=="playlists")return t.value.playlists;if(e=="radio")return t.value.radio;if(e=="topresult"){const l=[];for(const s of[t.value.tracks,t.value.artists,t.value.albums,t.value.playlists,t.value.radio]){const r=[];for(const u of s)r.includes(u.provider)||(l.push(u),r.push(u.provider))}return l}return[]};_(()=>{if(p.initSearch)a.value=p.initSearch;else{const e=localStorage.getItem("globalsearch");e&&e!=="null"&&(a.value=e)}});const y=function(e){!n.value&&e.key=="Backspace"?a.value=a.value.slice(0,-1):!n.value&&e.key.length==1&&(a.value+=e.key)};return document.addEventListener("keydown",y),C(()=>{document.removeEventListener("keydown",y)}),(e,l)=>(i(),f("section",null,[c(D,{variant:"flat",color:"transparent"},{title:v(()=>[E(N(e.$t("search")),1)]),_:1}),c(P),c(U,{id:"searchInput",modelValue:a.value,"onUpdate:modelValue":l[0]||(l[0]=s=>a.value=s),clearable:"","prepend-inner-icon":"mdi-magnify",label:e.$t("type_to_search"),"hide-details":"",variant:"filled",onFocus:l[1]||(l[1]=s=>n.value=!0),onBlur:l[2]||(l[2]=s=>n.value=!1)},null,8,["modelValue","label"]),(i(),f(b,null,V([["topresult","tracks"],["artists","albums"],["playlists","radio"]],s=>c(I,{key:s[0]+s[1]},{default:v(()=>[(i(!0),f(b,null,V(s.filter(r=>m(r).length),r=>(i(),g($,{key:r},{default:v(()=>[m(r).length?(i(),g(B,{key:0,itemtype:`search.${r}`,path:`search.${d.value}`,"show-provider":!0,"show-favorites-only-filter":!1,"show-select-button":!1,"show-refresh-button":!1,"load-items":async u=>m(r),title:e.$t(r),"allow-key-hooks":!1,"show-search-button":!1,limit:8,"infinite-scroll":!1,"sort-keys":["original"]},null,8,["itemtype","path","load-items","title"])):x("",!0)]),_:2},1024))),128))]),_:2},1024)),64))]))}});export{le as default};
