var GlobalEventBus=GlobalEventBus||new Vue();Vue.component('search-result',{template:'#vc-component-site-search-result',data:function(){return{searchResult:null,searchProductOptions:{arrows:!1,slidesToShow:1.5,slidesToScroll:1,infinite:!1,mobileFirst:!0,responsive:[{breakpoint:ps.breakpoints.sm,settings:{slidesToShow:2.5,slidesToScroll:2,}},{breakpoint:ps.breakpoints.lg,settings:{slidesToShow:5,slidesToScroll:5,}}]}}},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('search-button',{template:'#vc-component-site-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(e){var _self=this;_self.searchTerm=e.target.value;if(_self.searchTerm.length<2){return}
clearInterval(this.timer);this.timer=setTimeout(function(){_self.getSearchResult(_self.searchTerm).done(function(response){_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')},},mounted:function(){this.$refs.input.focus()}})