define(["knockout","ccConstants","notifications","pubsub","CCi18n","swmRestClient","spinner","ccStoreConfiguration","ccRestClient","navigation","ccResourceLoader!global/frigelarGlobalUtils","storageApi"],function(e,t,n,r,i,s,o,u,a,f,l,c){"use strict";function h(e,t,n){var r="";for(var i=t;i1169?this.isMobile(!1):e<=1169&&this.isMobile(!0)},categoriesChildren:function(e){var t=this,n=t.menuTexts().split(","),r=!1;for(var i=0;io&&s>=o||u>o&&s=s||s==o&&u==o)t.showPix(!1),t.showCartao(!0),t.showBoleto(!1);s>u&&s>o&&(t.showPix(!1),t.showCartao(!1),t.showBoleto(!0)),t.searchText.subscribe(function(e){e.length==0&&$(".header-space, .without-fixed-message").removeClass("search-open"),e.length>=1?(window.scrollTo(0,0),t.search(e)):t.closeSearch(l)}),t.vectorizedMenuTexts=e.observableArray(t.menuTexts().split(",")),t.vectorizedMenuLinks=e.observableArray(t.menuLinks().split(",")),$.Topic("CLOSE_CATEGORY_MENU").subscribe(t.closeAllMenus.bind(t)),$.Topic("OPEN_CATEGORY_MENU").subscribe(t.openSideMenu.bind(t,["mobile-category-menu"])),t.menuName="CC-CategoryNav",t.isMobile=e.observable(!1),c.getInstance().getItem("removeDownloadApp")&&t.hideDownloadApp(!0),$(document).on("click","li.desktop-dropdown",function(){t.closeAllMenus(),$(".dropdown-menu *").removeClass("hide-side-bar"),t.mouseEnteredCategoryMenu&&($(this).css({display:"none"}),$(".category-item").removeClass("active-category"),$(".active-arrow").addClass("hidden"),$(".category-subitem").addClass("hidden"),t.mouseEnteredCategoryMenu=!1),$(".dropdown-menu").css({display:"block"}),navigator.userAgent.indexOf("Firefox")!=-1?$("#CC-product-listing-sortby-controls select.form-control").hide():$("#CC-product-listing-sortby-controls select.form-control").css("visibility","hidden")}),$(document).on("mouseover",".top-items-list .menu-item a.open-menu, .desktop-dropdown",function(){$(".dropdown-menu").css({display:"block"}),$(".fade-category").css({display:"block"}),t.parentCategoryEntered({}),$(".dropdown-menu *").removeClass("hide-side-bar");if(!$(this).hasClass("desktop-dropdown")){var e=$(this).attr("title").toLowerCase(),n=$(".dropdown-menu .category-list:not(.category-subitem) .category-item a");$(".category-list:not(.category-subitem)").addClass("hide-side-bar");for(var r=0;r320?$("html").css("height","auto"):$("html").css("height","100%"),$(document).on("click",".search-close",function(e){t.closeSearch(l),header.searchText("")}),$(document).on("click",".search-close-mobile",function(e){t.closeSearch(l),header.searchText(""),$(".header-space, .without-fixed-message").removeClass("search-open")}),$(document).on("click",".header-logout",function(e){t.currentPage()&&t.currentPage().pageId==="confirmation"&&c.getInstance().setItem("pageToRedirect","/"),(t.currentPage()&&t.currentPage().pageId==="orderHistory"||t.currentPage()&&t.currentPage().pageId==="profile"||t.currentPage()&&t.currentPage().pageId==="wishlist"||t.currentPage()&&t.currentPage().pageId==="addressbook"||t.currentPage()&&t.currentPage().pageId==="updatepassword"||t.currentPage()&&t.currentPage().pageId==="ordersOld")&&c.getInstance().setItem("pageToRedirect","/"),$.Topic(r.topicNames.USER_LOGOUT_SUBMIT).publishWith([{message:"success"}])}),window.addEventListener("scroll",function(e){$(window).scrollTop()>1&&!t.searchOpen()?(t.blackFridayActive()?$(".header-container").addClass("min-black-friday"):$(".header-container").addClass("min"),$("#desktop-category-menu").addClass("hide-menu")):(t.blackFridayActive()?$(".header-container").removeClass("min-black-friday"):$(".header-container").removeClass("min"),$("#desktop-category-menu").removeClass("hide-menu")),window.innerWidth<1024&&!t.searchOpen()&&($(window).scrollTop()>10?$(".header-container, .search-box").addClass("reduced"):$(".header-container, .search-box").removeClass("reduced"))}),document.body.onresize=function(e){t.searchOpen()?t.openSearch():null},$(".header-top").length>0&&($(".header-space").css("height","80px"),$(".header-container").css("height","80px")),$.Topic("CATEGORY_IS_AR_CONDICIONADO").subscribe(function(e){e==1?t.itsAirConditioning(!0):t.itsAirConditioning(!1)}),$.Topic(r.topicNames.PAGE_CHANGED).subscribe(function(){location.pathname.includes("/black-friday")?($("#page").css("background-color","#1E1E1E"),$("#WIDGET_ID-WIDGET_INSTANCE_ID").css("background","#ffffff")):$("#page").css("background-color","#ffffff")})},goToOrderHistoryPage:function(){var e=this;e.user().loggedIn()?f.goTo("orderHistory"):(c.getInstance().setItem("goToOrderHistoryPage","true"),$.Topic("OPEN_LOGIN_MODAL").publish())},goToOrderProfile:function(){var e=this;e.user().loggedIn()?f.goTo("profile"):(c.getInstance().setItem("goToOrderProfile","true"),$.Topic("OPEN_LOGIN_MODAL").publish())},openMenu:function(e){$.Topic("OPEN_CATEGORY_MENU").publish()},beforeAppear:function(){var e=this;$(".user-welcome").on("mouseover",function(){$(".offlogin").css("visibility","revert")}),$(".user-welcome").on("mouseout",function(){$(".offlogin").css("visibility","hidden")}),e.pageContext().page.name==="category"&&$("#page").css("background-color","#fff"),$("#page").addClass("page-ready"),window.headermenu=this,$(window).scrollTop()>1&&$(".btu-calc").addClass("hidden"),window.addEventListener("scroll",function(e){$(window).scrollTop()>1?$(".btu-calc").addClass("hidden"):$(".btu-calc").removeClass("hidden")});var e=this;e.searchText(""),e.wentToTop(!1),e.getWishListSpaces(),e.showUserMenu(!1);var t=this.hasOwnProperty("preHeaderTexts")&&this.hasOwnProperty("preHeaderLinks");t=t&&this.preHeaderTexts()&&this.preHeaderLinks(),t=t&&this.preHeaderTexts().length>0&&this.preHeaderLinks().length>0,t&&(this.vectorizedPreHeaderTexts(this.preHeaderTexts().split(",")),this.vectorizedPreHeaderLinks(this.preHeaderLinks().split(",")));var n=this.hasOwnProperty("mostSearchedTexts")&&this.hasOwnProperty("mostSearchedLinks");n=n&&this.mostSearchedTexts()&&this.mostSearchedLinks(),n=n&&this.mostSearchedTexts().length>0&&this.mostSearchedLinks().length>0,n&&(this.vectorizedMostSearchedTexts(this.mostSearchedTexts().split(",")),this.vectorizedMostSearchedLinks(this.mostSearchedLinks().split(","))),this.checkResponsiveFeatures(),window.header=this;var e=this;header.checkProductPage(),header.getSuggestedProducts(),$(window).scroll(function(){e.pageContext().pageType.id==="productPageType"&&(header.checkProductPage(),$(window).scrollTop()>800&&!e.showGoTopButton()?e.showGoTopButton(!0):$(window).scrollTop()<=800&&e.showGoTopButton()&&e.showGoTopButton(!1))}),e.goToTop.bind(e)(),$.Topic("CATEGORY_IS_AR_CONDICIONADO").subscribe(function(t){t==1?e.itsAirConditioning(!0):e.itsAirConditioning(!1)});var r=window.location.pathname;e.isPageProfile(r.indexOf("/orderHistory")>-1||r.indexOf("/profile")>-1||r.indexOf("/addressbook")>-1||r.indexOf("/updatepassword")>-1||r.indexOf("/wishlist")>-1||r.indexOf("/ordersOld")>-1);if(e.blackFridayActive()&&!e.isPageProfile()){if(!e.blackFridayDate()){e.blackFridayActive(!1);return}var i=e.blackFridayDate().split("/").reverse().join("/"),s=new Date(i);s0&&(s=e.split(",")),i[t.ENDPOINT_KEY]=t.ENDPOINT_COLLECTIONS_GET_COLLECTION,n.load("categoryList",[n.rootCategoryId(),n.catalogId(),1e3],r,function(e){var t="";for(var r=0;r0&&(r[i].subcat=!0))}e.preHeaderObjects(r)},filterChildCategories:function(e){var t=[];return e.hasOwnProperty("childCategoriesIdsToShow")&&e.childCategoriesIdsToShow&&e.childCategoriesIdsToShow.length>0&&(t=e.childCategoriesIdsToShow.split(",")),e.childCategories&&e.childCategories.length>0&&t.length>0&&(e.childCategories=e.childCategories.filter(function(e){return e&&t.includes(e.id)})),e},mergeCategoryImage:function(e,t){e.hasBanner=!1;for(var n=0;n0){var s=i.tags.find(function(e){return e.repositoryId==="mediumTag"});if(s)return e.hasBanner=!0,e.banner=i,e}}return e},doSortingWithPriority:function(e,t){if(!e)return null;var n={};if(t&&t.length>0){var r=t.split(",");for(var i=0;it.displayName?1:e.displayName0&&(e=t.target);var n=e.children[1];return e.classList.contains("collapsed")?n.style.transform="translateY(-50%) rotate(90deg)":n.style.transform="translateY(-50%) rotate(-90deg)"},100)},formatUserName:function(){var e=this,t=e.user().loggedInUserName(),n=t.split(" ")[0];return n.length<13?n:h(n,0,13)+".."},checkDisplayBTUCalcButton:function(){var e=this,t=e.site().extensionSiteSettings.frigelarSiteCustomConfigurations.pagesToHideBTUCalcButton;if(t){t=t.split(",");if(!t.includes(f.getRelativePath()))return!1}return!0},closeModalAtendimento:function(){$("#atendimento-modal").modal("hide")},openAtendimento:function(){$("#atendimento-modal").modal(),setTimeout(function(){var e=$("#atendimento-modal.modal.fade.right.in")},500),$("html, body").css("overflow","auto")},openChat:function(){var e=this;$.Topic("CHATBOT_STATUS").publish(e.chatStatus()),$("#atendimento-modal").modal("hide"),$("#blip-chat-icon").click()},handleKeyPress:function(e,t){var n=this;if(t.keyCode!=13)return!0;n.handleSearch(!0),n.closeSearch()},goToTop:function(){var e=this;setTimeout(function(){$("html").animate({scrollTop:0},"swing"),setTimeout(function(){e.wentToTop(!0)},250)},700)},getSuggestedProducts:function(){var e=this;if(!(e.hasOwnProperty("no_result_products")&&e.no_result_products()&&e.no_result_products().length>0))return;var n=e.no_result_products();n=n.split(",").map(function(e){return e.replace(" ","")}).join(",");var r={productIds:n,continueOnMissingProduct:!0,showInactiveProducts:!1};a.request(t.ENDPOINT_PRODUCTS_LIST_PRODUCTS,r,function(e){header.mountSujestProduts(e)},function(e){console.error(e)})},mountSujestProduts:function(e){var t=this,n=e;for(var r=0;r600?n:680,$(".search-box").css("height",n+"px")}else setTimeout(function(){$(".search-box-wrapper").css("opacity","1")},400)},closeSearch:function(e){$(".search-box").removeClass("active"),e=1e3;var t=this;t.inProgressStateChange(!0),t.productSearchList([]),l.isMobile()?($(".search-box").removeClass("custom-padding-top"),$(".search-box").slideUp(500,function(){$("html, body").css("overflow","auto"),$(".header-container").css("position",""),t.checkProductPage(),$(".search-box").removeAttr("style"),t.inProgressStateChange(!1)}),$(".header-container").removeClass("active")):e===!0?($(".search-box-wrapper").css("opacity","0"),$(".search-box").removeClass("active"),$("#search-input").removeClass("active"),$(".header-container").removeClass("active"),$("html, body").css("overflow","auto"),$("#desktop-category-menu").removeClass("hide-menu"),$(".search-box-wrapper").css("display","none"),t.inProgressStateChange(!1)):($(".search-box-wrapper").css("opacity","0"),$(".header-container").removeClass("active"),$(".search-box").removeClass("active"),$("html, body").css("overflow","auto"),$("#desktop-category-menu").removeClass("hide-menu"),$(".search-box-wrapper").css("display","none"),t.inProgressStateChange(!1)),$(".search-shadow").css("opacity","0"),clearTimeout(e),e=setTimeout(function(){$(".search-shadow").css("display","none")},1e3),t.checkProductPage()},search:function(e){var n=this,r;e.length==1&&(e+=" ");var i={Ntt:e+"*",No:0,Nrpp:10};a.request(t.ENDPOINT_SEARCH_SEARCH,i,function(e){n.searchResults(e),n.openSearch(r)},function(e){e.status==200?this.success(res):(n.inProgressSearch=!1,console.error("Erro ao pesquisar: ",res))})},searchResults:function(e){var t=window.header,n=[];e=e.resultsList;if(!e||e.records.length==0){t.productSearchList([]),t.createSugest();return}t.mountCategorySuggestions(e);for(var r=0;r"+e.replace(new RegExp(t.replace(/[\\^$*+?.()|[\]{}]/g,"\\$&"),"gi"),function(e){return(document.location.href.indexOf("dev-")!=-1||document.location.href.indexOf("tst-")!=-1)&&e.includes("ar ")&&(e=e.replace("ar ","ar-")),""+e+""})+""}function y(t){var n=document.querySelector(".cont-padd-left");n&&!n.contains(t.target)&&(e.closeSearch(1e3),e.searchText(""))}var e=this,t=[],n=e.productSearchList(),r=$("#search-input").val().toLowerCase(),i=[],s=[],o=[];const u=5;(document.location.href.indexOf("dev-")!=-1||document.location.href.indexOf("tst-")!=-1)&&r.includes("-")&&(r=r.replace("-"," "));const a=document.getElementById("autocomplete-results");for(var f=0;f0){function c(e,t){return e.includes(t)}var i=s.filter(function(e){return c(e,r)});i.length===0?($(".title").css("display","none"),$("#autocomplete-results").css("display","none")):($(".title").css("display","block"),a.style.display="block")}const p=i.map(function(e){return h(e,r)});if(r==""||r.length==0||!r){a.style.display="none";return}for(var f=0;f2&&$(".typeahead-products-carousel").slick(t)},300)},getWishListSpaces:function(){var t=this,n=function(){var e="header_getSpaces";$.Topic("FRIGELAR_GET_WISH_LIST_SPACES_CALLBACK").subscribe(function(n){if(n.requestId===e){var r=n.result.find(function(e){return e.products.items&&e.products.items.length>0});t.showHasSpacesFlag(r?!0:!1)}}),$.Topic("FRIGELAR_GET_WISH_LIST_SPACES").publish({requestId:e})};if(e.hasOwnProperty("frigelar_wishListWidgetLoaded"))n();else var r=setInterval(function(){e.hasOwnProperty("frigelar_wishListWidgetLoaded")&&e.frigelar_wishListWidgetLoaded()&&(n(),clearInterval(r))},50)},toggleUserMenu:function(){var e=this,t=e.showUserMenu();$(".header-container .dropdown-user").slideToggle("fast",function(){e.showUserMenu(!t)})},handleSearch:function(e,n){var r=this,i=r.searchText().trim();if(i.length!=0){r.searchText("");var s="/searchresults?"+t.SEARCH_TERM_KEY+"="+encodeURIComponent(i)+"*&"+t.SEARCH_RANDOM_KEY+"="+Math.floor(Math.random()*1e3)+"&"+t.SEARCH_TYPE+"="+t.SEARCH_TYPE_SIMPLE+"&"+t.PARAMETERS_TYPE+"="+t.PARAMETERS_SEARCH_QUERY;n&&(s=s.concat("&"+t.SEARCH_NAV_DESCRIPTORS_KEY+"="+n)),f.goTo(s)}},checkDisplayBTUCalcButton:function(){var e=this,t=e.site().extensionSiteSettings.frigelarSiteCustomConfigurations.pagesToHideBTUCalcButton;if(t){t=t.split(",");if(!t.includes(f.getRelativePath()))return!1}return!0},mountCategorySuggestions:function(n){var r=this;r.categoriesHeader.removeAll();if(n&&n.records&&n.records.length>0){var i=new Set;n.records.forEach(function(e){var t=e.records.map(function(e){return e.attributes["product.parentCategory.id"]});t&&t.length>0&&t.forEach(function(e){e.forEach(function(e){i.add(e)})})});var s=new Set;i.forEach(function(e){var t=e.split(".");t&&t.length>0&&(t[0]===r.rootCategoryId()?t.length>1&&s.add(t[1]):s.add(t[0]))});var o=[];s.forEach(function(e){var t=e;t=t.replace(/__/g,"_"),t=t.replace(/____/g,"__"),o.push({id:t})}),r.categories()&&r.categories().length>0&&o.forEach(function(e){var n=r.categories().find(function(t){return t.id===e.id});if(n){e.dimensionId=n.dimensionId,e.displayName=n.displayName;var i=r.searchText().trim();i+=t.SEARCH_WILDCARD,e.url="/searchresults?"+t.SEARCH_TERM_KEY+"="+encodeURIComponent(i)+"&"+t.SEARCH_RANDOM_KEY+"="+Math.floor(Math.random()*1e3)+"&"+t.SEARCH_TYPE+"="+t.SEARCH_TYPE_SIMPLE+"&"+t.PARAMETERS_TYPE+"="+t.PARAMETERS_SEARCH_QUERY,e.url=e.url.concat("&"+t.SEARCH_NAV_DESCRIPTORS_KEY+"="+n.dimensionId)}}),o&&o.length>0&&e.utils.arrayPushAll(r.categoriesHeader,o)}},navigationToCategory:function(e){f.goTo(e.route)},closeDownloadApp:function(){var e=this;$(".header-download-app").css("display","none"),$("#btu-calc-button-with-app").css("top","95px"),$(".header-container").removeClass("header-with-download-app"),$(".btu-calc-button").removeClass("btu-calc-button-with-app"),c.getInstance().setItem("removeDownloadApp","true"),e.hideDownloadApp(!0)},alteraAlturaHeader:function(){$(".header-container").addClass("header-with-download-app"),$(".btu-calc-button").addClass("btu-calc-button-with-app")},getAppStoreLink:function(){var e=navigator.userAgent||navigator.vendor||window.opera;return e.match(/iPad/i)||e.match(/iPhone/i)||e.match(/iPod/i)?"https://apps.apple.com/bz/app/frigelar/id1546654308":"https://play.google.com/store/apps/details?id=br.com.frigelar.pecas&hl=pt_BR&gl=US"},onlineAssistance:function(e){$("#atendimento-modal").modal("hide"),setTimeout(function(){f.goTo(e)},150)},bannerClick:function(){var e=this;e.x_mobileBannerLinks&&(e.x_mobileBannerLinks.toLowerCase().startsWith("/")?f.goTo(e.x_mobileBannerLinks):window.open(e.x_mobileBannerLinks))},estimateTimerBlackFriday:function(e){try{var t=new Date,n=(e-t)/1e3;document.querySelector("#black-days").innerHTML=Math.floor(n/3600/24),document.querySelector("#black-hours").innerHTML=this.formatTime(Math.floor(n/3600)%24),document.querySelector("#black-minutes").innerHTML=this.formatTime(Math.floor(n/60)%60),document.querySelector("#black-seconds").innerHTML=this.formatTime(Math.floor(n)%60)}catch(r){}},formatTime:function(e){return e<10?"0"+e:e}}})