import{L as j,V as q,s as A}from"./ListviewItem-2c46c8ee.js";/* empty css                             */import{l as G,a6 as J,e as X,r as n,c as w,w as M,o as K,b as O,v,A as f,j as s,y as u,N as x,J as d,I as g,F,B as L,x as y,D as k,q as Q,k as W,E as Y,H as Z,X as z}from"./index-dcf0de03.js";import{_ as ee}from"./PanelviewItem.vue_vue_type_style_index_0_lang-44df1bef.js";import{e as S}from"./eventbus-d154090d.js";import{V as T}from"./VToolbar-dfba6de4.js";import{b as te}from"./VMenu-3bdd1b96.js";import{V as ae}from"./VTextField-f81f9175.js";import{a as le,V as se}from"./VCheckboxBtn-d54a899d.js";import{V as re,a as oe}from"./VRow-73379099.js";import{V as ie}from"./VSpacer-4e341220.js";import{V as ue,k as ne}from"./VBtn-a0da5efe.js";import"./MediaItemThumb.vue_vue_type_style_index_0_lang-b38d9ae1.js";import"./ListItem-6dad7331.js";import"./VListItem-943ee224.js";import"./VCard-111cabcf.js";import"./index-0afee102.js";/* empty css              */const ve={key:2},me={style:{"margin-left":"15px"}},Fe=G({__name:"Search",props:{initSearch:{}},setup(N){const b=N,P=J(),{mobile:R}=X(),r=n("list"),p=n(0),o=n(""),m=n(!1),l=n(),h=n(!1),_=n(),$=["topresult","artists","albums","tracks","playlists","radios"],D=w(()=>R.value?140:150),E=function(){r.value==="panel"?r.value="list":r.value="panel",localStorage.setItem(`viewMode.search.${i.value}`,r.value)},C=function(e){S.emit("playdialog",{items:[e],showContextMenuItems:!0})},B=function(e){var t;["artist","album","playlist"].includes(e.media_type)||!((t=Y.selectedPlayer)!=null&&t.available)?P.push({name:e.media_type,params:{itemId:e.item_id,provider:e.provider}}):S.emit("playdialog",{items:[e],showContextMenuItems:!1})};M(()=>o.value,()=>{clearTimeout(_.value),_.value=setTimeout(()=>{H()},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},H=async function(){h.value=!0,localStorage.setItem("globalsearch",o.value),o.value?l.value=await Z.search(o.value):l.value=void 0,h.value=!1},i=w(()=>$[p.value]),V=w(()=>{if(!l.value)return[];if(i.value=="artists")return l.value.artists;if(i.value=="albums")return l.value.albums;if(i.value=="tracks")return l.value.tracks;if(i.value=="playlists")return l.value.playlists;if(i.value=="radios")return l.value.radio;if(i.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[]});M(()=>i.value,e=>{if(e){const t=localStorage.getItem(`viewMode.search.${i.value}`);t?r.value=t:i.value=="artists"||i.value=="albums"?r.value="panel":r.value="list"}},{immediate:!0}),K(()=>{if(b.initSearch)o.value=b.initSearch;else{const e=localStorage.getItem("globalsearch");e&&e!=="null"&&(o.value=e)}});const I=function(e){!m.value&&e.key=="Backspace"?o.value=o.value.slice(0,-1):!m.value&&e.key.length==1&&(o.value+=e.key)};return document.addEventListener("keydown",I),O(()=>{document.removeEventListener("keydown",I)}),(e,t)=>(v(),f("section",null,[s(T,{variant:"flat",color:"transparent",style:{height:"50px"}},{title:u(()=>[x(d(e.$t("search")),1)]),_:1}),s(te),s(ae,{id:"searchInput",modelValue:o.value,"onUpdate:modelValue":t[0]||(t[0]=a=>o.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"]),g("div",null,[s(le,{modelValue:p.value,"onUpdate:modelValue":t[3]||(t[3]=a=>p.value=a),column:"",style:{"margin-top":"15px","margin-left":"10px"}},{default:u(()=>[(v(),f(F,null,L($,a=>s(se,{key:a,filter:"",outlined:""},{default:u(()=>[x(d(e.$t(a)),1)]),_:2},1024)),64))]),_:1},8,["modelValue"]),h.value?(v(),y(ne,{key:0,indeterminate:""})):k("",!0),r.value=="panel"?(v(),y(re,{key:1},{default:u(()=>[(v(!0),f(F,null,L(V.value,a=>(v(),y(oe,{key:a.uri,class:z(`col-${U(e.$vuetify.display.width)}`)},{default:u(()=>[s(ee,{item:a,size:D.value,"is-selected":!1,"show-checkboxes":!1,onMenu:C,onClick:B},null,8,["item","size"])]),_:2},1032,["class"]))),128))]),_:1})):k("",!0),r.value=="list"?(v(),f("div",ve,[s(Q(A),{items:V.value,"item-size":60,"key-field":"item_id","page-mode":""},{default:u(({item:a})=>[s(j,{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:C,onClick:B},null,8,["item"])]),_:1},8,["items"])])):k("",!0),s(T,{density:"compact",variant:"flat",color:"transparent",height:"45"},{default:u(()=>[g("span",me,d(e.$t("items_total",[V.value.length])),1),s(ie),s(q,{location:"bottom"},{activator:u(({props:a})=>[s(ue,W(a,{icon:r.value=="panel"?"mdi-view-list":"mdi-grid",variant:"plain",onClick:t[4]||(t[4]=c=>E())}),null,16,["icon"])]),default:u(()=>[g("span",null,d(e.$t("tooltip.toggle_view_mode")),1)]),_:1})]),_:1})])]))}});export{Fe as default};
