import{C as I}from"./Container-ZHtGcXZO.js";import{I as $}from"./ItemsListing-D_KqSTZS.js";import{T as L}from"./Toolbar-BEJzY0mB.js";import{W as c}from"./WidgetRow-057hFDXb.js";import{u as V}from"./userPreferences-DBWZCHKf.js";import{ay as B,J as p,L as w,a3 as C,ax as t,a4 as O,az as f,aA as i,o as m,aG as b,aI as n,aB as d,bH as P,aD as l,bI as R,ah as K,aH as U,aQ as r,bJ as D,bK as F,aP as M}from"./index-BRUnowC8.js";import"./index-kQIztB-E.js";import"./Button-BKv4xLAv.js";import"./ListItem-jfbxOrad.js";import"./MediaItemThumb-CIE9_Elw.js";import"./PanelviewItemCompact-CsJmi5IT.js";import"./VInfiniteScroll-BORsRMGl.js";import"./VVirtualScroll-htzu2YXu.js";import"./VAlert-DQxypmdN.js";import"./VToolbar-DS4mUdOC.js";import"./VCheckboxBtn-D390s4L9.js";import"./VSelectionControl-Co1cRcmS.js";const E={key:1},H={key:2},oe=B({__name:"Search",setup(G){const v=p(!1),a=p(),s=p(!1),g=p(),{getPreference:S,setPreference:k}=V();w(()=>t.globalSearchTerm,()=>{clearTimeout(g.value),g.value=setTimeout(()=>{h(t.globalSearchTerm,t.globalSearchType)},1e3)},{immediate:!0}),w(()=>t.globalSearchType,()=>{h(t.globalSearchTerm,t.globalSearchType)});const h=async function(e,u){s.value=!0,k("globalSearch",e||"");const o=t.globalSearchType?50:8,A=u?[u]:void 0;e?a.value=await M.search(e,A,o):a.value=void 0,s.value=!1};C(()=>{if(!t.globalSearchTerm){const e=S("globalSearch").value;e&&e!=="null"&&(t.globalSearchTerm=e)}});const y=function(e){e.ctrlKey||e.altKey||e.metaKey||(!v.value&&e.key=="Backspace"&&t.globalSearchTerm?t.globalSearchTerm=t.globalSearchTerm.slice(0,-1):!v.value&&e.key.length==1&&(t.globalSearchTerm+=e.key))};document.addEventListener("keyup",y),O(()=>{document.removeEventListener("keyup",y)});const T=function(e){return a.value?e==r.TRACK?a.value.tracks:e==r.ARTIST?a.value.artists:e==r.ALBUM?a.value.albums:e==r.PLAYLIST?a.value.playlists:e==r.PODCAST?a.value.podcasts:e==r.AUDIOBOOK?a.value.audiobooks:e==r.RADIO?a.value.radio:[]:[]};return(e,u)=>(i(),f("section",null,[m(L,{icon:"mdi-magnify",title:e.$t("global_search")},null,8,["title"]),m(I,{variant:"default"},{default:b(()=>[m(P,{id:"searchInput",modelValue:l(t).globalSearchTerm,"onUpdate:modelValue":u[0]||(u[0]=o=>l(t).globalSearchTerm=o),clearable:"","prepend-inner-icon":"mdi-magnify",label:e.$t("type_to_search"),"hide-details":"",variant:"outlined",onFocus:u[1]||(u[1]=o=>v.value=!0),onBlur:u[2]||(u[2]=o=>v.value=!1)},null,8,["modelValue","label"]),m(R,{modelValue:l(t).globalSearchType,"onUpdate:modelValue":u[3]||(u[3]=o=>l(t).globalSearchType=o),style:{"margin-top":"10px","margin-left":"10px"}},{default:b(()=>[(i(!0),f(K,null,U([void 0,l(r).TRACK,l(r).ARTIST,l(r).ALBUM,l(r).PLAYLIST,l(r).PODCAST,l(r).AUDIOBOOK,l(r).RADIO],o=>(i(),n(F,{key:o,text:e.$t(o?o+"s":"searchtype_all"),value:o},null,8,["text","value"]))),128))]),_:1},8,["modelValue"]),s.value?(i(),n(D,{key:0,color:"accent",height:"4",indeterminate:"",rounded:"",style:{"margin-top":"15px"}})):d("",!0),l(t).globalSearchType?s.value?d("",!0):(i(),f("div",H,[m($,{itemtype:`${l(t).globalSearchType}s`,"show-provider":!0,"show-favorites-only-filter":!1,"show-select-button":!1,"show-refresh-button":!1,"load-items":async o=>T(l(t).globalSearchType),title:e.$t(`${l(t).globalSearchType}s`),"allow-key-hooks":!1,"show-search-button":!1,"infinite-scroll":!0,"sort-keys":[],style:{padding:"0"}},null,8,["itemtype","load-items","title"])])):(i(),f("div",E,[a.value&&!s.value?(i(),n(c,{key:0,"widget-row":{title:e.$t("tracks"),icon:"mdi-file-music",items:a.value.tracks},"show-provider-on-cover":!0},null,8,["widget-row"])):d("",!0),a.value&&!s.value?(i(),n(c,{key:1,"widget-row":{title:e.$t("artists"),icon:"mdi-account-music",items:a.value.artists},"show-provider-on-cover":!0},null,8,["widget-row"])):d("",!0),a.value&&!s.value?(i(),n(c,{key:2,"widget-row":{title:e.$t("albums"),icon:"mdi-album",items:a.value.albums},"show-provider-on-cover":!0},null,8,["widget-row"])):d("",!0),a.value&&!s.value?(i(),n(c,{key:3,"widget-row":{title:e.$t("playlists"),icon:"mdi-playlist-music",items:a.value.playlists},"show-provider-on-cover":!0},null,8,["widget-row"])):d("",!0),a.value&&!s.value?(i(),n(c,{key:4,"widget-row":{title:e.$t("podcasts"),icon:"mdi-podcast",items:a.value.podcasts},"show-provider-on-cover":!0},null,8,["widget-row"])):d("",!0),a.value&&!s.value?(i(),n(c,{key:5,"widget-row":{title:e.$t("audiobooks"),icon:"mdi-book-play-outline",items:a.value.audiobooks},"show-provider-on-cover":!0},null,8,["widget-row"])):d("",!0),a.value&&!s.value?(i(),n(c,{key:6,"widget-row":{title:e.$t("radios"),icon:"mdi-radio",items:a.value.radio},"show-provider-on-cover":!0},null,8,["widget-row"])):d("",!0)]))]),_:1})]))}});export{oe as default};
