import{V as $,_ as S,a as B}from"./ItemsListing.vue_vue_type_style_index_0_lang-8114fc79.js";import{v as I,r as o,w as F,o as L,b as _,y as i,E as f,l as c,A as v,R as C,N as E,F as y,G as V,L as N,z as b,I as R}from"./index-20675090.js";import{V as x}from"./VToolbar-7174c765.js";import{V as D}from"./forwardRefs-67412654.js";import{V as P}from"./VTextField-8bb22937.js";import"./ListviewItem-ea07a19b.js";import"./VBadge-778cac01.js";import"./ListItem-e092a77b.js";import"./VMenu-ae4158ef.js";import"./VCheckboxBtn-bbfa74a1.js";import"./VSlideGroup-14bb6bf6.js";import"./VCard-30020028.js";import"./VCardText-5e149cd1.js";import"./VTooltip-cf009865.js";import"./PanelviewItem.vue_vue_type_style_index_0_lang-4e768a3d.js";import"./contextmenu-ec90c658.js";import"./Alert-daf9024b.js";import"./Container-e8fef44d.js";/* empty css              */import"./VVirtualScroll-b47ffb64.js";const re=I({__name:"Search",props:{initSearch:{}},setup(g){const p=g,a=o(""),n=o(!1),t=o(),d=o(!1),h=o();F(()=>a.value,()=>{clearTimeout(h.value),h.value=setTimeout(()=>{w()},200)});const w=async function(){d.value=!0,localStorage.setItem("globalsearch",a.value),a.value?t.value=await N.search(a.value):t.value=void 0,d.value=!1},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[]};L(()=>{if(p.initSearch)a.value=p.initSearch;else{const e=localStorage.getItem("globalsearch");e&&e!=="null"&&(a.value=e)}});const k=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",k),_(()=>{document.removeEventListener("keydown",k)}),(e,l)=>(i(),f("section",null,[c(x,{variant:"flat",color:"transparent"},{title:v(()=>[C(E(e.$t("search")),1)]),_:1}),c(D),c(P,{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(y,null,V([["topresult","tracks"],["artists","albums"],["playlists","radio"]],s=>c(B,{key:s[0]+s[1]},{default:v(()=>[(i(!0),f(y,null,V(s.filter(r=>m(r).length),r=>(i(),b($,{key:r},{default:v(()=>[m(r).length?(i(),b(S,{key:0,itemtype:`search.${r}`,path:`search.${a.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"])):R("",!0)]),_:2},1024))),128))]),_:2},1024)),64))]))}});export{re as default};
