var GlobalEventBus=GlobalEventBus||new Vue();Vue.component('search-result',{template:'#vc-component-search-result',props:['showresult','searchresult'],data:function(){return{timer:null}},computed:{seeallurl:function(){return'/search?q='+(this.searchresult.query||'')},seealljournalurl:function(){return'/journals?q='+(this.searchresult.query||'')},categorycount:function(){if(typeof this.searchresult.categories!=='undefined'){return this.searchresult.categories.length}
return 0},pagescount:function(){if(typeof this.searchresult.pages!=='undefined'){return this.searchresult.pages.length}
return 0}},methods:{updateterm:function(term){var _self=this;clearInterval(this.timer);this.timer=setTimeout(function(){_self.$emit('updateterm',term)},300)},}});Vue.component('search-button',{template:'#vc-component-search-button',name:'SearchButton',data:function(){return{showsearch:!1}},methods:{hidesearch:function(){this.showsearch=!1;$('.j-site-search-form').removeClass('is-active');$('body').removeClass('has-search-active')},togglesearch:function(){this.showsearch=!0;GlobalEventBus.$emit('showsearch')}},mounted:function(){GlobalEventBus.$on('hidesearch',this.hidesearch)}});Vue.component('search-input',{template:'#vc-component-search-input',name:'Search',data:function(){return{searchresult:{},searchterm:'',show:!1,showclosebutton:!1,timer:null}},computed:{showresult:function(){return this.searchresult.status||!1},suggestedterm:function(){var _self=this;if(typeof _self.searchresult.completion!=='string')return'';return _self.searchresult.completion.split('').map(function(po_char,pi_index){return _self.searchterm.charAt(pi_index)!==''?_self.searchterm.charAt(pi_index):po_char}).join('')}},methods:{autofill:function(){this.searchterm=this.searchresult.completion||this.searchterm},dosearch:function(){var _self=this;clearInterval(this.timer);this.timer=setTimeout(function(){_self.getsearchresult(_self.searchterm).done(function(po_response){_self.searchresult=po_response})},300)},doproductsearch:function(ps_searchterm){var _self=this;_self.getsearchresult(ps_searchterm).done(function(po_response){var lo_newresult=$.extend({},_self.searchresult,po_response);lo_newresult.completion=ps_searchterm;delete lo_newresult.suggestedsearches;_self.searchresult=$.extend({},_self.searchresult,lo_newresult)})},getsearchresult:function(ps_searchterm){return $.get('/_ps/api/sitepeppersearchapi/dosearch/'+ps_searchterm)},hidesearchresult:function(){this.show=!1;this.searchterm='';this.searchresult={};$('.s-overlay').removeClass('is-active');GlobalEventBus.$emit('hidesearch');$('body').removeClass('is-hiding-hubspot')},resetsearch:function(){this.searchterm='';this.hidesearchresult()},showsearch:function(){var _self=this;this.show=!0;$('.j-overlay').addClass('is-active');$('.j-site-search-form').addClass('is-active');$('body').addClass('has-search-active');$('body').addClass('is-hiding-hubspot');$('.search-trigger-button').on('click',function(){$('#search').focus()});_self.$nextTick(function(){$('.search-trigger-button').trigger('click')})},toggleclosebutton:function(){this.showclosebutton=!this.showclosebutton},},watch:{showresult:function(pb_show){if(pb_show){$('body').addClass('j-open-search')}else{$('body').removeClass('j-open-search')}}},mounted:function(){GlobalEventBus.$on('showsearch',this.showsearch);GlobalEventBus.$on('hidesearchresult',this.hidesearchresult)},})