import{V as $,_ as B,a as S}from"./ItemsListing.vue_vue_type_style_index_0_lang-6fa46e09.js";import{l as F,r as o,w as I,o as _,b as C,v as i,B as m,j as c,y as v,O as L,K as x,F as y,D as V,J as D,x as b,G as E}from"./index-e5db0b73.js";import{V as N}from"./VToolbar-4e8dded4.js";import{V as R}from"./VImg-7a057c50.js";import{V as P}from"./VTextField-46667b30.js";import"./ListviewItem-7c178b7a.js";import"./VBadge-efd00f67.js";import"./ListItem-ac3869d3.js";import"./VMenu-d9833a31.js";import"./VCheckboxBtn-46446b67.js";import"./VCard-c9b9f4e9.js";import"./VTooltip-71530943.js";import"./PanelviewItem.vue_vue_type_style_index_0_lang-221d4edc.js";import"./contextmenu-8eac6b44.js";import"./Alert-1172b8fb.js";import"./Container-238e2d02.js";import"./VVirtualScroll-01555b84.js";const ee=F({__name:"Search",props:{initSearch:{}},setup(g){const p=g,t=o(""),n=o(!1),a=o(),d=o(!1),h=o();I(()=>t.value,()=>{clearTimeout(h.value),h.value=setTimeout(()=>{w()},200)});const w=async function(){d.value=!0,localStorage.setItem("globalsearch",t.value),t.value?a.value=await D.search(t.value):a.value=void 0,d.value=!1},f=function(e){if(!a.value)return[];if(e=="artists")return a.value.artists;if(e=="albums")return a.value.albums;if(e=="tracks")return a.value.tracks;if(e=="playlists")return a.value.playlists;if(e=="radio")return a.value.radio;if(e=="topresult"){const r=[];for(const s of[a.value.tracks,a.value.artists,a.value.albums,a.value.playlists,a.value.radio]){const l=[];for(const u of s)l.includes(u.provider)||(r.push(u),l.push(u.provider))}return r}return[]};_(()=>{if(p.initSearch)t.value=p.initSearch;else{const e=localStorage.getItem("globalsearch");e&&e!=="null"&&(t.value=e)}});const k=function(e){!n.value&&e.key=="Backspace"?t.value=t.value.slice(0,-1):!n.value&&e.key.length==1&&(t.value+=e.key)};return document.addEventListener("keydown",k),C(()=>{document.removeEventListener("keydown",k)}),(e,r)=>(i(),m("section",null,[c(N,{variant:"flat",color:"transparent"},{title:v(()=>[L(x(e.$t("search")),1)]),_:1}),c(R),c(P,{id:"searchInput",modelValue:t.value,"onUpdate:modelValue":r[0]||(r[0]=s=>t.value=s),clearable:"","prepend-inner-icon":"mdi-magnify",label:e.$t("type_to_search"),"hide-details":"",variant:"filled",onFocus:r[1]||(r[1]=s=>n.value=!0),onBlur:r[2]||(r[2]=s=>n.value=!1)},null,8,["modelValue","label"]),(i(),m(y,null,V([["topresult","tracks"],["artists","albums"],["playlists","radio"]],s=>c(S,{key:s[0]+s[1]},{default:v(()=>[(i(!0),m(y,null,V(s.filter(l=>f(l).length),l=>(i(),b($,{key:l},{default:v(()=>[f(l).length?(i(),b(B,{key:0,itemtype:`search.${l}`,path:`search.${t.value}`,"show-provider":!0,"show-favorites-only-filter":!1,"show-select-button":!1,"show-refresh-button":!1,"load-items":async u=>f(l),title:e.$t(l),"allow-key-hooks":!1,"show-search-button":!1,limit:8,"infinite-scroll":!1,"sort-keys":["original"]},null,8,["itemtype","path","load-items","title"])):E("",!0)]),_:2},1024))),128))]),_:2},1024)),64))]))}});export{ee as default};
