import{l as H,a3 as q,e as A,r as n,c as g,w as B,o as G,b as J,y as v,I as w,j as i,A as u,R as F,N as f,D as y,F as L,J as S,z as p,H as k,k as X,q as K,L as O,X as Q}from"./index-c2905444.js";import{L as W}from"./ListviewItem-90d92dc7.js";import{_ as Y}from"./PanelviewItem.vue_vue_type_style_index_0_lang-74d21d61.js";import{e as x}from"./eventbus-d154090d.js";import{V as R}from"./VToolbar-0b568cf9.js";import{V as Z,j as z,r as ee}from"./VImg-ee22af0e.js";import{V as te}from"./VTextField-b3baf9d7.js";import{a as ae,V as le}from"./VCheckboxBtn-020d02eb.js";import{V as se,a as re}from"./VRow-a177c0dd.js";import{V as oe}from"./VVirtualScroll-da9f2ada.js";import{V as ie}from"./VSpacer-001a30a9.js";import{V as ue}from"./VTooltip-54e33c2a.js";import"./utils-a855eb36.js";import"./ListItem-e72ce29c.js";import"./VMenu-8ba8f078.js";import"./VCard-a2a52f2b.js";/* empty css              */const ne={style:{"margin-left":"15px"}},Me=H({__name:"Search",props:{initSearch:{}},setup(T){const b=T,N=q(),{mobile:P}=A(),s=n("list"),d=n(0),r=n(""),m=n(!1),l=n(),h=n(!1),$=n(),C=["topresult","artists","albums","tracks","playlists","radios"],D=g(()=>P.value?140:150),E=function(){s.value==="panel"?s.value="list":s.value="panel",localStorage.setItem(`viewMode.search.${o.value}`,s.value)},_=function(e){x.emit("playdialog",{items:[e],showContextMenuItems:!0})},I=function(e){var t;["artist","album","playlist"].includes(e.media_type)||!((t=K.selectedPlayer)!=null&&t.available)?N.push({name:e.media_type,params:{itemId:e.item_id,provider:e.provider}}):x.emit("playdialog",{items:[e],showContextMenuItems:!1})};B(()=>r.value,()=>{clearTimeout($.value),$.value=setTimeout(()=>{j()},200)});const U=function(e){return e<500?2:e<=500?3:e<=700?4:e<=1e3?5:e<=1200?6:e<=1500?7:e<=1700?8:e>1700?9:0},j=async function(){h.value=!0,localStorage.setItem("globalsearch",r.value),r.value?l.value=await O.search(r.value):l.value=void 0,h.value=!1},o=g(()=>C[d.value]),V=g(()=>{if(!l.value)return[];if(o.value=="artists")return l.value.artists;if(o.value=="albums")return l.value.albums;if(o.value=="tracks")return l.value.tracks;if(o.value=="playlists")return l.value.playlists;if(o.value=="radios")return l.value.radio;if(o.value=="topresult"){const e=[];for(const t of[l.value.tracks,l.value.artists,l.value.albums,l.value.playlists,l.value.radio]){const a=[];for(const c of t)a.includes(c.provider)||(e.push(c),a.push(c.provider))}return e}return[]});B(()=>o.value,e=>{if(e){const t=localStorage.getItem(`viewMode.search.${o.value}`);t?s.value=t:o.value=="artists"||o.value=="albums"?s.value="panel":s.value="list"}},{immediate:!0}),G(()=>{if(b.initSearch)r.value=b.initSearch;else{const e=localStorage.getItem("globalsearch");e&&e!=="null"&&(r.value=e)}});const M=function(e){!m.value&&e.key=="Backspace"?r.value=r.value.slice(0,-1):!m.value&&e.key.length==1&&(r.value+=e.key)};return document.addEventListener("keydown",M),J(()=>{document.removeEventListener("keydown",M)}),(e,t)=>(v(),w("section",null,[i(R,{variant:"flat",color:"transparent",style:{height:"50px"}},{title:u(()=>[F(f(e.$t("search")),1)]),_:1}),i(Z),i(te,{id:"searchInput",modelValue:r.value,"onUpdate:modelValue":t[0]||(t[0]=a=>r.value=a),clearable:"","prepend-inner-icon":"mdi-magnify",label:e.$t("type_to_search"),"hide-details":"",variant:"filled",onFocus:t[1]||(t[1]=a=>m.value=!0),onBlur:t[2]||(t[2]=a=>m.value=!1)},null,8,["modelValue","label"]),y("div",null,[i(ae,{modelValue:d.value,"onUpdate:modelValue":t[3]||(t[3]=a=>d.value=a),column:"",style:{"margin-top":"15px","margin-left":"10px"}},{default:u(()=>[(v(),w(L,null,S(C,a=>i(le,{key:a,filter:"",outlined:""},{default:u(()=>[F(f(e.$t(a)),1)]),_:2},1024)),64))]),_:1},8,["modelValue"]),h.value?(v(),p(ee,{key:0,indeterminate:""})):k("",!0),s.value=="panel"?(v(),p(se,{key:1},{default:u(()=>[(v(!0),w(L,null,S(V.value,a=>(v(),p(re,{key:a.uri,class:Q(`col-${U(e.$vuetify.display.width)}`)},{default:u(()=>[i(Y,{item:a,size:D.value,"is-selected":!1,"show-checkboxes":!1,onMenu:_,onClick:I},null,8,["item","size"])]),_:2},1032,["class"]))),128))]),_:1})):k("",!0),s.value=="list"?(v(),p(oe,{key:2,height:60,items:V.value,style:{height:"100%"}},{default:u(({item:a})=>[i(W,{item:a,"show-track-number":!1,"show-duration":!0,"show-library":!1,"show-menu":!0,"show-provider":!0,"show-checkboxes":!1,"is-selected":!1,"show-details":!0,onMenu:_,onClick:I},null,8,["item"])]),_:1},8,["items"])):k("",!0),i(R,{density:"compact",variant:"flat",color:"transparent",height:"45"},{default:u(()=>[y("span",ne,f(e.$t("items_total",[V.value.length])),1),i(ie),i(ue,{location:"bottom"},{activator:u(({props:a})=>[i(z,X(a,{icon:s.value=="panel"?"mdi-view-list":"mdi-grid",variant:"plain",onClick:t[4]||(t[4]=c=>E())}),null,16,["icon"])]),default:u(()=>[y("span",null,f(e.$t("tooltip.toggle_view_mode")),1)]),_:1})]),_:1})])]))}});export{Me as default};
