var GlobalEventBus=GlobalEventBus||new Vue();Vue.component('site-search-result',{template:'#vc-component-site-search-result',data(){return{searchResult:null,searchProductOptions:{arrows:!1,slidesToShow:1.5,slidesToScroll:1,infinite:!1,mobileFirst:!0,responsive:[{breakpoint:ps.breakpoints.sm,settings:{slidesToShow:1.5,slidesToScroll:1,},},{breakpoint:ps.breakpoints.lg,settings:{slidesToShow:6,slidesToScroll:6,},},],},}},computed:{viewAllUrl(){if(!this.searchResult.query)return'/search';return `/search?q=${this.searchResult.query}`},},methods:{setResults(searchResult){this.resetResults();this.searchResult=searchResult;this.$nextTick(()=>{GlobalEventBus.$emit('search-results:show')})},resetResults(){this.searchResult=null;if(this.$refs.searchProducts&&this.$refs.searchProducts.$el.classList.contains('slick-initialized')){this.$refs.searchProducts.destroy()}},initSlider(){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(){GlobalEventBus.$on('search:results',this.setResults);GlobalEventBus.$on('search:hide',this.resetResults)},updated(){this.initSlider()},beforeDestroy(){GlobalEventBus.$off('search-result:show',this.setResults);GlobalEventBus.$off('search:hide',this.resetResults);GlobalEventBus.$emit('search-results:hide');this.resetResults()},});Vue.component('site-search-button',{template:'#vc-component-site-search-button',data(){return{active:!1,}},methods:{showSearch(){GlobalEventBus.$emit('search:show');this.active=!0},hideSearch(){this.active=!1},},mounted(){GlobalEventBus.$on('search:hide',this.hideSearch)},beforeDestroy(){GlobalEventBus.$off('search:hide',this.hideSearch)},});Vue.component('site-search-input',{template:'#vc-component-site-search-input',name:'Search',props:{active:{type:Boolean,default:!1,},},data(){return{searchTerm:'',searchResult:null,timer:null,}},computed:{suggestedTerm(){const self=this;if(typeof self.searchResult.completion!=='string')return'';return self.searchResult.completion.split('').map((char,index)=>(self.searchTerm.charAt(index)!==''?self.searchTerm.charAt(index):char)).join('')},},methods:{autofill(){this.searchTerm=this.searchResult.completion||this.searchTerm},doSearch(fromKeyPress=!0){if(this.searchTerm.length<2){return}
clearInterval(this.timer);this.timer=setTimeout(()=>{this.getSearchResult(this.searchTerm).done((response)=>{if(this.searchTerm!==response.query&&response.query!==''&&fromKeyPress){this.doSearch(!1);return}
this.searchResult=response;if(response.emptyresult){const gaData={eventCategory:'Home Page',eventAction:'Search',eventLabel:'No Result',};$(document).trigger('psevent',['searchNoResults',gaData])}
GlobalEventBus.$emit('search:results',this.searchResult);GlobalEventBus.$emit('search:term',this.searchTerm)})},300)},getSearchResult(searchTerm){return $.ajax({url:`/typeahead/${encodeURIComponent(searchTerm)}`,method:'GET',})},resetSearch(){this.searchTerm='';this.searchResult={};this.hideSearch()},hideSearch(){GlobalEventBus.$emit('search:hide');GlobalEventBus.$emit('search-results:hide')},},mounted(){this.$refs.input.focus()},})