var GlobalEventBus=GlobalEventBus||new Vue();var vcSearchResult={template:'#vc-component-site-search-result',data:function(){return{searchResult:null,searchProductOptions:{slidesToShow:5,slidesToScroll:1,infinite:!1,mobileFirst:!0,arrows:!1,responsive:[{breakpoint:0,settings:'unslick',},{breakpoint:ps.breakpoints.md,settings:{slidesToShow:3,slidesToScroll:3,},},{breakpoint:ps.breakpoints.lg,settings:{slidesToShow:4,slidesToScroll:4,},},{breakpoint:ps.breakpoints.xl,settings:{slidesToShow:6,slidesToScroll:6,},},],},}},computed:{viewAllUrl:function(){return'/search?q='+(this.searchResult.query||'')},},methods:{setResults:function(searchResult){this.resetResults();this.searchResult=searchResult;this.$nextTick(function(){GlobalEventBus.$emit('search-results:show')})},resetResults:function(){this.searchResult=null;if(this.$refs.searchProducts&&this.$refs.searchProducts.$el.classList.contains('slick-initialized')){this.$refs.searchProducts.destroy()}},initSlider:function(){if(this.$refs.searchProducts&&!this.$refs.searchProducts.$el.classList.contains('slick-initialized')){this.$refs.searchProducts.create();$(this.$refs.searchProducts.$el).verticallyPosition({elem:'.s-slider-arrow',position:'centre',})}},},mounted:function(){GlobalEventBus.$on('search:results',this.setResults);GlobalEventBus.$on('search:hide',this.resetResults)},updated:function(){this.initSlider()},beforeDestroy:function(){GlobalEventBus.$off('search-result:show',this.setResults);GlobalEventBus.$off('search:hide',this.resetResults);GlobalEventBus.$emit('search-results:hide');this.resetResults()},};Vue.component('mobile-search-button',{template:'#vc-component-mobile-search-button',data:function(){return{active:!1,}},methods:{showSearch:function(){GlobalEventBus.$emit('search:show');this.active=!0},hideSearch:function(){this.active=!1},},mounted:function(){GlobalEventBus.$on('search:hide',this.hideSearch)},beforeDestroy:function(){GlobalEventBus.$off('search:hide',this.hideSearch)},});Vue.component('search-input',{template:'#vc-component-site-search-input',name:'Search',data:function(){return{searchTerm:'',searchResult:null,timer:null,}},computed:{suggestedTerm:function(){var _self=this;if(typeof _self.searchResult.completion!=='string')return'';return _self.searchResult.completion.split('').map(function(char,index){return _self.searchTerm.charAt(index)!==''?_self.searchTerm.charAt(index):char}).join('')},},methods:{autofill:function(){this.searchTerm=this.searchResult.completion||this.searchTerm},doSearch:function(){var _self=this;if(this.searchTerm.length<2){return}
clearTimeout(this.timer);this.timer=setTimeout(function(){_self.getSearchResult(_self.searchTerm).done(function(response){if(_self.searchTerm!==response.query)return;_self.searchResult=response;if(response.emptyresult){var gaData={eventCategory:'Home Page',eventAction:'Search',eventLabel:'No Result',};$(document).trigger('psevent',['searchNoResults',gaData])}
GlobalEventBus.$emit('search:results',_self.searchResult)})},300)},getSearchResult:function(searchTerm){return $.get('/typeahead/'+encodeURIComponent(searchTerm))},resetSearch:function(){this.searchTerm='';this.searchResult={};this.hideSearch()},hideSearch:function(){GlobalEventBus.$emit('search:hide');GlobalEventBus.$emit('search-results:hide');this.searchTerm='';this.$emit('hide')},},mounted:function(){this.$refs.input.focus()},})