import{d as w,r as s,J as V,o as I,s as a,a as $,c as i,g as f,f as m,w as p,u as g,F as k,h as S,b as B,e as y,j as C}from"./index-2dd0c7d2.js";import{V as F,a as L,I as _}from"./ItemsListing-db2c60f3.js";import{C as E}from"./Container-fdf4c1f5.js";import{T as R}from"./Toolbar-1720c469.js";import{V as N}from"./VTextField-de7279c6.js";import"./ListviewItem-a6570b10.js";import"./helpers-4d7c5bf6.js";import"./VLabel-1f522f96.js";import"./VListItem-cb387084.js";import"./VList-d110868a.js";import"./VCard-907b4685.js";import"./VCardText-0ed41581.js";import"./VMenu-97c1c955.js";import"./_plugin-vue_export-helper-c27b6911.js";import"./ListItem-87435fbb.js";import"./Button-69b906cf.js";import"./VTooltip-e62b61bd.js";import"./VCheckboxBtn-c3f9b6ff.js";import"./PanelviewItem-68416368.js";import"./VSpacer-e11897c6.js";/* empty css              */import"./Alert-65a1093b.js";import"./VAlert-4eed3112.js";import"./ItemContextMenu.vue_vue_type_style_index_0_scoped_7aadaa8c_lang-7ff19a96.js";import"./eventbus-d154090d.js";import"./VVirtualScroll-660ff9a6.js";import"./VSnackbar-6950ff68.js";import"./layout-42d7f450.js";import"./VBadge-91055b8b.js";import"./VToolbar-6047eebf.js";const fe=w({__name:"Search",setup(U){const d=s(),n=s(!1),t=s(),h=s(!1),v=s();V(()=>a.globalSearchTerm,()=>{clearTimeout(v.value),v.value=setTimeout(()=>{T()},200)},{immediate:!0});const T=async function(){h.value=!0,localStorage.setItem("globalsearch",a.globalSearchTerm||""),a.globalSearchTerm?t.value=await B.search(a.globalSearchTerm):t.value=void 0,h.value=!1,d.value=a.globalSearchTerm},c=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 o of[t.value.tracks,t.value.artists,t.value.albums,t.value.playlists,t.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(!a.globalSearchTerm){const e=localStorage.getItem("globalsearch");e&&e!=="null"&&(a.globalSearchTerm=e)}});const b=function(e){!n.value&&e.key=="Backspace"&&a.globalSearchTerm?a.globalSearchTerm=a.globalSearchTerm.slice(0,-1):!n.value&&e.key.length==1&&(a.globalSearchTerm+=e.key)};return document.addEventListener("keydown",b),$(()=>{document.removeEventListener("keydown",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(a).globalSearchTerm,"onUpdate:modelValue":l[0]||(l[0]=o=>g(a).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(L,{key:r},{default:p(()=>[c(r).length?(i(),y(_,{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{fe as default};
