import{d as V,r as s,K as w,o as I,s as t,a as $,c as i,h as f,f as m,w as p,b as B,u as g,F as k,i as S,e as y,j as C}from"./index-CLKg64ON.js";import{V as F,I as L,a as _}from"./ItemsListing-BwjD1tmq.js";import{C as E}from"./Container-ZPskS02H.js";import{T as R}from"./Toolbar-BaIn3BvJ.js";import{V as N}from"./VTextField-C1QkMZRy.js";import"./VCheckbox-CpTv3BhW.js";import"./eventbus-D-xzWv8v.js";import"./VListItem-B_TSjQ1y.js";import"./VCheckboxBtn-DXJHHMHd.js";import"./VList-BvG6-yh2.js";import"./VCardText-BAUfdzDA.js";import"./VCard-BaRPabiE.js";import"./VMenu-CLSWQG_U.js";import"./_plugin-vue_export-helper-DlAUqK2U.js";import"./ListItem-f79Nhqh7.js";import"./Button-F8l3l_P8.js";import"./VSpacer-CqqJVVs3.js";/* empty css              */import"./PanelviewItemCompact-CM48-dMH.js";import"./VAlert-CCGDAWu2.js";import"./VInfiniteScroll-pn5EaZ8a.js";import"./layout-CYdR31l5.js";import"./VVirtualScroll-DKBgr9yN.js";import"./VToolbar-DSn0RyUD.js";const se=V({__name:"Search",setup(U){const d=s(),n=s(!1),a=s(),h=s(!1),v=s();w(()=>t.globalSearchTerm,()=>{clearTimeout(v.value),v.value=setTimeout(()=>{T()},200)},{immediate:!0});const T=async function(){h.value=!0,localStorage.setItem("globalsearch",t.globalSearchTerm||""),t.globalSearchTerm?a.value=await B.search(t.globalSearchTerm):a.value=void 0,h.value=!1,d.value=t.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 r=[];for(const u of o)r.includes(u.provider)||(l.push(u),r.push(u.provider))}return l}return[]};I(()=>{if(!t.globalSearchTerm){const e=localStorage.getItem("globalsearch");e&&e!=="null"&&(t.globalSearchTerm=e)}});const b=function(e){!n.value&&e.key=="Backspace"&&t.globalSearchTerm?t.globalSearchTerm=t.globalSearchTerm.slice(0,-1):!n.value&&e.key.length==1&&(t.globalSearchTerm+=e.key)};return document.addEventListener("keyup",b),$(()=>{document.removeEventListener("keyup",b)}),(e,l)=>(i(),f("section",null,[m(R,{icon:"mdi-magnify",title:e.$t("search")},null,8,["title"]),m(E,{variant:"default"},{default:p(()=>[m(N,{id:"searchInput",modelValue:g(t).globalSearchTerm,"onUpdate:modelValue":l[0]||(l[0]=o=>g(t).globalSearchTerm=o),clearable:"","prepend-inner-icon":"mdi-magnify",label:e.$t("type_to_search"),"hide-details":"",variant:"outlined",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(F,{key:o[0]+o[1]},{default:p(()=>[(i(!0),f(k,null,S(o.filter(r=>c(r).length),r=>(i(),y(_,{key:r},{default:p(()=>[c(r).length?(i(),y(L,{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=>c(r),title:e.$t(r),"allow-key-hooks":!1,"show-search-button":!1,limit:8,"infinite-scroll":!1,"sort-keys":[]},null,8,["itemtype","path","load-items","title"])):C("",!0)]),_:2},1024))),128))]),_:2},1024)),64))]),_:1})]))}});export{se as default};
