import{d as T,r as s,I as w,o as $,s as r,a as _,c as i,h as f,f as m,w as d,m as B,t as I,u as g,F as k,i as S,b as F,e as y,j as C}from"./index-0ae84607.js";import{V as L,_ as E,a as N}from"./ItemsListing.vue_vue_type_style_index_0_lang-02893598.js";import{V as R}from"./VToolbar-b7dd8339.js";import{a as x}from"./forwardRefs-d0d7c5bd.js";import{V as D}from"./VTextField-4bf39c0d.js";import"./ListviewItem-156d947d.js";import"./VBadge-bfb26993.js";import"./Container-eb92362b.js";import"./Button-a1dfd3f5.js";import"./VMenu-f26d3a19.js";/* empty css              */import"./VInput-00e20677.js";import"./VSlideGroup-18f8a11f.js";import"./VCard-e96ab32b.js";import"./VCardText-b1a0de89.js";import"./VTooltip-054ea37d.js";import"./PanelviewItem.vue_vue_type_style_index_0_lang-a0b4c306.js";import"./contextmenu-5ae46870.js";import"./Alert-ee4ff93d.js";import"./VAlert-212471f5.js";import"./VVirtualScroll-06bbaaf5.js";import"./layout-f3684635.js";const se=T({__name:"Search",setup(U){const p=s(),n=s(!1),a=s(),h=s(!1),v=s();w(()=>r.globalSearchTerm,()=>{clearTimeout(v.value),v.value=setTimeout(()=>{V()},200)},{immediate:!0});const V=async function(){h.value=!0,localStorage.setItem("globalsearch",r.globalSearchTerm||""),r.globalSearchTerm?a.value=await F.search(r.globalSearchTerm):a.value=void 0,h.value=!1,p.value=r.globalSearchTerm},c=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 l=[];for(const o of[a.value.tracks,a.value.artists,a.value.albums,a.value.playlists,a.value.radio]){const t=[];for(const u of o)t.includes(u.provider)||(l.push(u),t.push(u.provider))}return l}return[]};$(()=>{if(!r.globalSearchTerm){const e=localStorage.getItem("globalsearch");e&&e!=="null"&&(r.globalSearchTerm=e)}});const b=function(e){!n.value&&e.key=="Backspace"&&r.globalSearchTerm?r.globalSearchTerm=r.globalSearchTerm.slice(0,-1):!n.value&&e.key.length==1&&(r.globalSearchTerm+=e.key)};return document.addEventListener("keydown",b),_(()=>{document.removeEventListener("keydown",b)}),(e,l)=>(i(),f("section",null,[m(R,{variant:"flat",color:"transparent"},{title:d(()=>[B(I(e.$t("search")),1)]),_:1}),m(x),m(D,{id:"searchInput",modelValue:g(r).globalSearchTerm,"onUpdate:modelValue":l[0]||(l[0]=o=>g(r).globalSearchTerm=o),clearable:"","prepend-inner-icon":"mdi-magnify",label:e.$t("type_to_search"),"hide-details":"",variant:"filled",onFocus:l[1]||(l[1]=o=>n.value=!0),onBlur:l[2]||(l[2]=o=>n.value=!1)},null,8,["modelValue","label"]),(i(),f(k,null,S([["topresult","tracks"],["artists","albums"],["playlists","radio"]],o=>m(N,{key:o[0]+o[1]},{default:d(()=>[(i(!0),f(k,null,S(o.filter(t=>c(t).length),t=>(i(),y(L,{key:t},{default:d(()=>[c(t).length?(i(),y(E,{key:0,itemtype:`search.${t}`,path:`search.${p.value}`,"show-provider":!0,"show-favorites-only-filter":!1,"show-select-button":!1,"show-refresh-button":!1,"load-items":async u=>c(t),title:e.$t(t),"allow-key-hooks":!1,"show-search-button":!1,limit:8,"infinite-scroll":!1,"sort-keys":["original"]},null,8,["itemtype","path","load-items","title"])):C("",!0)]),_:2},1024))),128))]),_:2},1024)),64))]))}});export{se as default};
