!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.merchandizingBanner=t():e.merchandizingBanner=t()}(window,(function(){return function(e){var t={};function n(i){if(t[i])return t[i].exports;var a=t[i]={i:i,l:!1,exports:{}};return e[i].call(a.exports,a,a.exports,n),a.l=!0,a.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)n.d(i,a,function(t){return e[t]}.bind(null,a));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t,n){},function(e,t,n){},function(e,t,n){"use strict";n.r(t);n(0),n(1);const i=flash_fe_core_tool.$util.$coreMethods.getRequestPrefix();class a{constructor(e){this.ele=e,this._timer=null,this.carsouelLink=$(this.ele).find(".carsouelLink")}showPreInfo(e){this.stopCarousel();let t=$(e).siblings(".merchandizingInfo").find("li"),n=$(e).siblings(".merchandizingInfo").find(".active").index();t.removeClass("active"),n--,n<0?$(t[t.length-1]).addClass("active"):$(t[n]).addClass("active"),this.setBannerLink(),this.carousel()}showNextInfo(e){this.stopCarousel();let t=$(e).siblings(".merchandizingInfo").find("li"),n=$(e).siblings(".merchandizingInfo").find(".active").index();t.removeClass("active"),n++,n==t.length?$(t[0]).addClass("active"):$(t[n]).addClass("active"),this.setBannerLink(),this.carousel()}carousel(){let e=this;window.clearInterval(this._timer),$(this.ele).find(".merchandizingBanner .merchandizingInfo").removeClass("static");let t=$(this.ele).find(".merchandizingInfo li");0==$(this.ele).find(".active").length&&$(t[0]).addClass("active"),$(this.ele).find(".slideBtn").toggle(t.length>1),this._timer=setInterval(function(){let n=$(e.ele).find(".merchandizingInfo .active").index(),i=-1!=document.activeElement.className.indexOf("merchandizingItem");t.removeClass("active"),n++,n==t.length?($(t[0]).addClass("active"),i&&$(t[0]).focus()):($(t[n]).addClass("active"),i&&$(t[n]).focus()),this.setBannerLink()}.bind(this),6e3)}setBannerLink(){const e=this.carsouelLink,t=e.find(".merchandizingItem.active a").first();if(t.length>0){const n=t.attr("href");e.attr("data-tooltip",n)}else e.removeAttr("data-tooltip");e.find(".merchandizingItem a,.slideBtn,.alwaysFree a").hover((function(){e.removeAttr("data-tooltip")}),(function(t){const n=$(t.relatedTarget).closest(".carsouelLink");if(n.length>0){const t=n.find(".merchandizingItem.active a").first().attr("href");if(!t)return;e.attr("data-tooltip",t)}}))}setBannerLinkClick(){const e=this.carsouelLink;e.on("click",(function(t){const n=e.find(".merchandizingItem.active a").first(),i=n.attr("href"),a=n.attr("target")||"_self";n.length>0&&(t.preventDefault(),t.stopPropagation(),window.open(i,a))})),e.find(".slideBtn").on("click",(function(t){e.removeAttr("data-tooltip")})),e.on("click",".merchandizingItem.active a:not(:first)",(function(e){e.stopPropagation()})),e.find(".alwaysFree a").on("click",(function(e){"2"!=__TERMINAL__&&e.stopPropagation()}))}setStackBannerLink(){const e=this.carsouelLink;e.find(".noAutoRun").on("click",(function(t){t.preventDefault(),t.stopPropagation();const n=$(this).find("li:first a:first");if(n.length>0){const e=n.attr("href"),t=n.attr("target")||"_self";window.open(e,t)}e.find(".merchandizingItem a").not(":first").on("click",(function(e){e.stopPropagation()}))}))}hoverStackBannerLink(){const e=this.carsouelLink;e.find(".noAutoRun").hover((function(){const t=$(this).find("li:first a:first");if(t.length>0){const n=t.attr("href");e.attr("data-tooltip",n)}else e.removeAttr("data-tooltip")}),(function(){e.removeAttr("data-tooltip")})),e.find(".merchandizingItem a").hover((function(){e.removeAttr("data-tooltip")}),(function(t){const n=$(t.relatedTarget).closest(".noAutoRun");if(n.length>0){const t=n.find("li:first a:first").attr("href");e.attr("data-tooltip",t)}}))}notcarousel(){$(this.ele).find(".merchandizingBanner .merchandizingInfo").addClass("static"),window.clearInterval(this._timer),$(this.ele).find(".slideBtn").hide(),$(this.ele).find(".merchandizingItem").show()}stopCarousel(){window.clearInterval(this._timer)}getProductById(e,t){t.find(".filterText").each((e,t)=>{let n=$(t).html();n&&(n.includes("{savingPercent}")||n.includes("{savingAmount}"))&&(void 0===$(t).attr("original_text")&&$(t).attr("original_text",n),n=n.replace(/{savingPercent}|{savingAmount}/gi,""),$(t).html(n))});const n=e.formData&&e.formData.facetId;if(n){const e={pageFilterId:n,pageSize:1,page:1};try{(e=>{let t=i+"/ofp/search/dlp/cache/maxSave/get/_tsc";return flash_fe_core_tool.$http.jsonp(t,"",e)})({params:encodeURIComponent(JSON.stringify(e)),pageFilterId:n}).then(e=>{const{data:n,status:i}=e;if(200==i){let{maxSavingPercent:e,maxSavingAmount:i}=n,a=flash_fe_core_tool.$util.$coreMethods.getMetaContent("currencycode")||"USD";this.setDynamicParamMerchaBanner(t,e,i,a)}else t.find(".merchandizingBanner-shine").hide(),t.find(".merchandizingBanner").addClass("show")})}catch(e){console.log(e),t.find(".merchandizingBanner-shine").hide(),t.find(".merchandizingBanner").addClass("show")}}else flash_fe_core_tool.$event_publisher.on($CONSTANT.EVENT_PUBLISHER_KEY.DLP.UPDATE_DLP_HERO_SAVING,e=>{this.setDynamicParamMerchaBanner(t,e.maxSavingPercent,e.maxSavingAmount,e.currencyCode)});t.find(".merchandizingBanner-shine").hide(),t.find(".merchandizingBanner").addClass("show")}alignHeights(){const e=$(this.ele).find(".merchandizingItem");let t=50;e.each((function(e,n){"none"===window.getComputedStyle(n).display?(n.style.display="flex",n.style.height="auto",t=Math.max(t,n.offsetHeight),n.style.display="none"):(n.style.height="auto",t=Math.max(t,n.offsetHeight))})),t&&(e.each((e,n)=>{n.style.height="".concat(t,"px")}),t>59&&e.addClass("zoomOutPadding"))}setDynamicParamMerchaBanner(e,t,n,i){(t||n)&&e.find(".filterText").each((e,a)=>{let o=$(a).attr("original_text");o&&(o.includes("{savingPercent}")&&t&&Number(t)>=1&&(o=o.replace(/{savingPercent}/gi,t+"%"),$(a).html(o)),o.includes("{savingAmount}")&&n&&Number(n)>=1&&i&&(o=o.replace(/{savingAmount}/gi,flash_fe_core_tool.$priceFormat.split3(n,i)),$(a).html(o)))}),e.find(".merchandizingBanner-shine").hide(),e.find(".merchandizingBanner").addClass("show")}}class o{constructor(e,t){this.init(e,t)}init(e,t){var n;null===(n=t.merchandizingBannerData)||void 0===n||n.displayTerminal;this.el=e,this.datas=t||{},this.commonHelper=new a(this.el),this.registerEvent(),this.maxCharacter(),this.setLinkAndTip(),this.commonHelper.getProductById(t,e),this.addNotCarselStyle();try{this.onloadAdobeFile()}catch(e){console.log("merchandizingBanner adobe error:",e)}}onloadAdobeFile(){const e=this;flash_fe_core_tool.$AsyncLoadFileManagement.load(merchandizingBannerAdobePath,{isLastest:!0,cache:!1}).then(t=>{window._merchandizingBanner_adobe_tool&&window._merchandizingBanner_adobe_tool.init(null==e?void 0:e.el)}).catch(e=>{console.log("adobe load error",e)})}checkCarousel(){this.datas.merchandizingBannerData.autoRun?this.commonHelper.carousel():this.commonHelper.notcarousel()}registerEvent(){let e=this;flash_fe_core_tool.$event_publisher.on("merchandizingBanner_carousal_start",()=>{this.checkCarousel()}),this.checkCarousel(),this.el.find("#preInfoBtn").on("click keydown",(function(t){t.stopPropagation();try{_merchandizingBanner_adobe_tool.preInfoBtn()}catch(e){console.log("merchandizingBanner adobe error:",e)}t.keyCode&&13!=t.keyCode||e.commonHelper.showPreInfo(t.target)})),this.el.find("#nextInfoBtn").on("click keydown",(function(t){t.stopPropagation();try{_merchandizingBanner_adobe_tool.nextInfoBtn()}catch(e){console.log("merchandizingBanner adobe error:",e)}t.keyCode&&13!=t.keyCode||e.commonHelper.showNextInfo(t.target)})),this.el.find(".merchandizingItem.filterText a").on("click",(function(){let e=$(this).attr("textvalue")||"",t=$(this).attr("href")||"";try{_merchandizingBanner_adobe_tool.bannerLink(e,t,this)}catch(e){console.warn(e)}})),this.datas.merchandizingBannerData.autoRun&&(this.el.on("focusin",".merchandizingItem",(function(){e.commonHelper.stopCarousel()})),this.el.on("focusout",".merchandizingItem",(function(){e.commonHelper.carousel()}))),e.commonHelper.alignHeights()}maxCharacter(){let e=this,t=window.screen.width,n=this.datas.merchandizingBannerData.data;null!==n&&n.forEach((n,i)=>{var a,o;t>=1920&&null!==(a=n.gInfo)&&void 0!==a&&a.t_id?e.el.find(".item".concat(i)).html(this.replaceAll(window.decodeURIComponent(n.gInfo.t_id||""))):t>=1179&&t<1920&&null!==(o=n.pcInfo)&&void 0!==o&&o.t_id&&e.el.find(".item".concat(i)).html(this.replaceAll(window.decodeURIComponent(n.pcInfo.t_id||"")))})}setLinkAndTip(){this.datas.merchandizingBannerData.autoRun?this.commonHelper.setBannerLinkClick():(this.commonHelper.setStackBannerLink(),this.commonHelper.hoverStackBannerLink())}replaceAll(e){if(!e)return;let t=flash_fe_core_tool.$util.$coreMethods.getURIPrefix(),n=document.createElement("div");n.innerHTML=e;let i=n.getElementsByTagName("a");for(let e of i){let n=e.getAttribute("href");!n||n.includes("https://")||n.includes("http://")||e.setAttribute("href",t+n)}return n.innerHTML}addNotCarselStyle(){const e=this.datas.merchandizingBannerData.data.length>1?"94px":"47px";this.datas.merchandizingBannerData.autoRun||(this.el.find(".alwaysFree").css({display:"none"}),this.el.css({height:e}).find(".merchandizingBanner ").css({height:e,backgroundColor:this.datas.merchandizingBannerData.backgroundColor||"#fff"}).find(".content").css({width:"100%"}).find(".merchandizingInfo").css({height:e,maxHeight:e}).find(".merchandizingItem").css({maxHeight:e}))}}t.default=function(e,t){let n=flash_fe_core_tool.$util.$coreMethods.randomNum(0,999999);flash_fe_core_tool[n]=new o(e,t)}}]).default}));