var __extends=this&&this.__extends||function(){var n=function(t,i){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,t){n.__proto__=t}||function(n,t){for(var i in t)t.hasOwnProperty(i)&&(n[i]=t[i])},n(t,i)};return function(t,i){function r(){this.constructor=t}n(t,i);t.prototype=i===null?Object.create(i):(r.prototype=i.prototype,new r)}}(),Search,relatedTastingLoadedEvent;(function(n){var t=function(n){function t(i,r,u){var f=n.call(this,i,t.ID,u)||this,e,o;f.element=i;f.options=r;f.bindings=u;f.searchElem=$abc(i);f._userAcknowledgedLocationPermissions=!1;f._$abcEventCard=$abc(".abc-event-card");f._$loadingAnimation=f.searchElem.find(f.searchElem.data("first-loading-animation-selector"));f._$viewMoreTastingsButton=f.searchElem.find("#view-more-tastings");f._$chooseMyStorePrompt=f.searchElem.find(".related-tastings-choose-store-prompt");f._$noTastingsPrompt=f.searchElem.find(".related-tastings-no-tastings-prompt");f._defaultPosition=new google.maps.LatLng(37.540725,-77.436048);f._defaultTastingsUrl=f._$viewMoreTastingsButton.attr("data-default-tastings-url");f._isOnStoreDetailPage=f.searchElem.attr("data-on-store-detail-page").toLowerCase()==="true";f._sortOrder=f.searchElem.attr("data-sort-order");f._storeId=f.searchElem.attr("data-store");f._$tastingsOptions=f.searchElem.find(".abc-tasting-info");f.fieldMap=JSON.parse(f._$tastingsOptions.attr("data-field-map"));f._coveoLatitudeFieldName=CoveoForSitecore.Context.fields.toCoveo(f.fieldMap.lat);f._coveoLongitudeFieldName=CoveoForSitecore.Context.fields.toCoveo(f.fieldMap.lng);f._coveoDistanceFieldName=CoveoForSitecore.Context.fields.toCoveo(f.fieldMap.distance);f._coveoStoreIdFieldName=CoveoForSitecore.Context.fields.toCoveo(f.fieldMap.storeId);f._coveoStoreCityFieldName=CoveoForSitecore.Context.fields.toCoveo(f.fieldMap.storeCity);f.bind.onRootElement(Coveo.QueryEvents.buildingQuery,function(n){return f.handleBuildingQuery(n)});f.bind.onRootElement(Coveo.QueryEvents.doneBuildingQuery,function(n){return f.calculateDistance(n)});f.bind.onRootElement(Coveo.QueryEvents.querySuccess,function(n){return f.showSeeMoreTastingsButton(n)});f.bind.onRootElement(Coveo.QueryEvents.querySuccess,function(n){return f.showTastings(n)});f.bind.onRootElement(Coveo.QueryEvents.querySuccess,function(n){return f.createResults(n)});e=$abc(".CoveoStoresModalSearch")[0];o=Coveo.get(e);f._$chooseMyStorePrompt.click(function(){o.openModal()});$abc(window).on("myStoreChanged",function(){f._isOnStoreDetailPage||(f.usageAnalytics.logSearchEvent(Coveo.analyticsActionCauseList.advancedSearch,null),Coveo.executeQuery(f.root))});return f}return __extends(t,n),t.prototype.buildQuery=function(n){var u=new Date,f=new Date,e=new Date,r=new Coveo.ExpressionBuilder,o=new Coveo.ExpressionBuilder,t=CoveoForSitecore.Context.fields.toCoveo("@End Time"),i="";f=u;e.setDate(u.getDate()+13);r.addFieldExpression(t,">=",[Coveo.DateUtils.dateForQuery(f)]);o.addFieldExpression(t,"<=",[Coveo.DateUtils.dateForQuery(e)]);n.queryBuilder.advancedExpression.addFieldExpression(CoveoForSitecore.Context.fields.toCoveo("@_template"),"=",["8AAF20AF0E594B9EBDC3C59D6136D5D0"]);this._isOnStoreDetailPage?(n.queryBuilder.advancedExpression.add(r.build()),n.queryBuilder.advancedExpression.addFieldExpression(this._coveoStoreIdFieldName,"==",[this._storeId]),i=t+" ascending, "+this._coveoStoreCityFieldName+" ascending ",n.queryBuilder.sortCriteria=i):(n.queryBuilder.advancedExpression.add(r.build()),n.queryBuilder.advancedExpression.add(o.build()),i=this._coveoDistanceFieldName+" ascending, "+t+" ascending ",n.queryBuilder.sortCriteria=i);return},t.prototype.handleBuildingQuery=function(n){this.buildQuery(n);var t=CoveoForSitecore.Context.element.getAttribute("data-sc-index-source-name");n.queryBuilder.constantExpression.addFieldExpression("@source","==",[t]);n.queryBuilder.constantExpression.addFieldExpression(CoveoForSitecore.Context.fields.toCoveo("@_language"),"==",["en"]);n.queryBuilder.constantExpression.addFieldExpression(CoveoForSitecore.Context.fields.toCoveo("@_latestversion"),"==",["1"]);n.queryBuilder.numberOfResults=3;return},t.prototype.truncateProducts=function(){$abc(".clamp").dotdotdot({height:36,watch:"window"})},t.prototype.showTastings=function(n){n.results.totalCount==0?this._isOnStoreDetailPage?this.showTastingsCard(!1,!0):this.showTastingsCard(!1,!1):this.showTastingsCard(!1,!1)},t.prototype.showSeeMoreTastingsButton=function(n){n.results.totalCount>0?this._$viewMoreTastingsButton.removeClass("hidden"):this._isOnStoreDetailPage&&(this._$viewMoreTastingsButton.attr("href",this._defaultTastingsUrl),this._$viewMoreTastingsButton.removeClass("hidden"))},t.prototype.showTastingsCard=function(n,t){this._$loadingAnimation.addClass("hidden");n?this._$chooseMyStorePrompt.removeClass("hidden"):this._$chooseMyStorePrompt.addClass("hidden");t?this._$noTastingsPrompt.removeClass("hidden"):this._$noTastingsPrompt.addClass("hidden");this._$abcEventCard.removeClass("hidden")},t.prototype.calculateDistance=function(n){var t=this,r=function(i){var r="$qf(function:'dist("+t._coveoLatitudeFieldName+","+t._coveoLongitudeFieldName+","+i.lat()+","+i.lng()+")', fieldName: "+t._coveoDistanceFieldName+")";n.queryBuilder.advancedExpression.add(r)},i,u;this._isOnStoreDetailPage||(i=ResultDisplayHelper.getMyStore(),i?(u=new google.maps.LatLng(i.latitude,i.longitude),r(u)):this._refPosition!=null?r(this._refPosition):(n.cancel=!0,navigator.geolocation?(setTimeout(function(){t._userAcknowledgedLocationPermissions||t.showTastingsCard(!0,!1)},3e3),navigator.geolocation.getCurrentPosition(function(n){t._userAcknowledgedLocationPermissions=!0;t._refPosition=new google.maps.LatLng(n.coords.latitude,n.coords.longitude);t.usageAnalytics.logSearchEvent(Coveo.analyticsActionCauseList.advancedSearch,null);Coveo.executeQuery(t.root)},function(){t._userAcknowledgedLocationPermissions=!0;t.showTastingsCard(!0,!1)})):this.showTastingsCard(!0,!1)))},t.prototype.createResults=function(n){var r=this,u=$abc(".abc-result-template").data("date-field"),f=$abc(".abc-result-template").data("start-time-field"),e=$abc(".abc-result-template").data("end-time-field"),t=$abc(".abc-result-template").data("store-address-field"),o=$abc(".abc-result-template").data("store-city-field"),s=$abc(".abc-result-template").data("store-zip-field"),h=$abc(".abc-result-template").data("product-names-field"),c=$abc(".abc-result-template").data("product-urls-field");_.templateSettings={evaluate:/(?:<%|{{)([\s\S]+?)(?:%>|}})/g,interpolate:/(?:<%|{{)=([\s\S]+?)(?:%>|}})/g,escape:/(?:<%|{{)-([\s\S]+?)(?:%>|}})/g};var l=$abc(".abc-result-template").html(),a=_.template(l),i=$abc(".abcResultContainer");i.empty();n.results.results.forEach(function(n){var l={tastingDate:Coveo.DateUtils.dateToString(n.raw[CoveoForSitecore.Context.fields.toCoveo(u)],{predefinedFormat:"dddd, MMMM D"}),tastingStartTime:ResultDisplayHelper.displayHour(n.raw[CoveoForSitecore.Context.fields.toCoveo(f)]),tastingEndTime:ResultDisplayHelper.displayHour(n.raw[CoveoForSitecore.Context.fields.toCoveo(e)]),directionsLink:ResultDisplayHelper.generateGoogleMapsUrl(n.raw[CoveoForSitecore.Context.fields.toCoveo(t)],n.raw[CoveoForSitecore.Context.fields.toCoveo(o)],n.raw[CoveoForSitecore.Context.fields.toCoveo(s)]),storeAddress:n.raw[CoveoForSitecore.Context.fields.toCoveo(t)],products:ResultDisplayHelper.printProducts(n.raw[CoveoForSitecore.Context.fields.toCoveo(h)],n.raw[CoveoForSitecore.Context.fields.toCoveo(c)])},v=a(l);i.append($abc(v.trim()));r.truncateProducts()})},t.ID="RelatedTastings",t}(Coveo.Component);n.RelatedTastingSearch=t})(Search||(Search={}));relatedTastingLoadedEvent=document.createEvent("CustomEvent");relatedTastingLoadedEvent.initEvent("RelatedTastingLoadedEvent",!0,!0);isCoveoSearchEndpointInitialized?document.dispatchEvent(relatedTastingLoadedEvent):document.addEventListener("CoveoSearchEndpointInitialized",function(){document.dispatchEvent(relatedTastingLoadedEvent)})