define(["knockout","pageLayout/product","ccLogger","ccRestClient","ccConstants","pubsub","CCi18n","js/recsRequest","pageLayout/cart","notifier","navigation","ccResourceLoader!global/frigelarGlobalUtils","ccResourceLoader!global/frigelarGlobalPaymentUtils"],function(e,t,n,r,i,s,o,u,a,f,l,c,h){"use strict";return e.bindingHandlers.recsetCCLink={init:function(t,n,r,i,s){var o=e.utils.unwrapObservable(n()),u=s.$parents,a,f=o;for(var l=0;l978?this.isMobile(!1):e<=978&&this.isMobile(!0)},beforeAppear:function(){var e=this;e.activeProdIndex(0),e.sliderLoaded(!1),window.recomendacoes=this},onLoad:function(n){n.checkResponsiveFeatures(),n.recommendations=e.observableArray(),n.recommendationsGroups=e.observableArray(),n.hasFixedProducts=n.fixedProductsIds&&n.fixedProductsIds()&&n.fixedProductsIds().trim().length>0;var o;$.Topic(s.topicNames.PAGE_CHANGED).subscribe(function(e){o=e.pageId,n.sliderControl([])}),n.recommendationsGroups=e.computed(function(){var t=[];if(n.recommendations){n.numberOfRecommendationsToShow=n.numRecs()0){var a=new Promise(function(t,i){s.getAvailability(s.id(),s.childSKUs()[0].repositoryId(),n.user().catalog?n.user().catalog.repositoryId:n.user().catalogId()),r.brand&&r.brand.toLowerCase()==="eos"&&n.eosOrder&&n.eosOrder()?e.unshift({id:r.id,recSetId:u,ccProduct:s}):e.push({id:r.id,recSetId:u,ccProduct:s});var a={id:r.repositoryId,url:r.route,name:r.displayName,description:r.description,manufacturer:r.brand,category:null,unit_sale_price:r.listPrice};a.manufacturer&&a.manufacturer.toLowerCase()==="eos"&&n.eosOrder&&n.eosOrder()?o.unshift(a):o.push(a),t()});i.push(a)}}}),Promise.all(i).then(function(){$.Topic(s.topicNames.RECS_RECOMMENDATIONS_CHANGED).publish(o),n.sendProductsToGTM(e()),n.recommendationsloaded(!0)})}).catch(function(e){})},f=function(e){var t,r,i,s,o=[];n.recommendations.removeAll(),n.hasFixedProducts?(r=n.fixedProductsIds().split(",").map(function(e){return{repositoryid:e.trim()}}),a(n.recommendations,o,i,r)):(r=e.recs,i=e.recSetId,a(n.recommendations,o,i,r))};n.hasFixedProducts?f():($.Topic(s.topicNames.RECS_WHO_WANT_RECS).subscribe(function(e){var t=n.pages(),r=e.pageId;if(t.indexOf(r)>-1){var i={};i.id=n.id(),i.numRecs=n.numRecs(),i.restriction=n.restriction?n.restriction():"Blended",i.strategy=n.strategy?n.strategy():"Unrestricted",i.pageId=o,i.collections=n.collections&&n.collections()?n.collections().split(",").map(function(e){return e.trim()}):[],$.Topic(s.topicNames.RECS_WANT_RECS).publish(i)}}),$.Topic(s.topicNames.RECS_HAVE_RECS).subscribe(function(e){n.recsVisitorId=e.visitorId,n.recsSessionId=e.sessionId;var t=Object.keys(e.data);t.indexOf(n.id())>-1&&f(e.data[n.id()])}));var l=n.site().extensionSiteSettings.precificacao,c=parseInt(l.boletoDiscountPercentage),h=parseInt(l.creditCardDiscountPercentage),p=parseInt(l.pixDiscountPercentage);if(p>h&&c>=h||p>h&&c=c||c==h&&p==h)n.showPix(!1),n.showCartao(!0),n.showBoleto(!1);c>p&&c>h&&(n.showPix(!1),n.showCartao(!1),n.showBoleto(!0))},formatProductName:function(e){return e&&this.isMobile()&&e.length>30?e:e&&e.length>105?e.substring(0,105)+"...":e},removeTextDiscountStamp:function(e){var t,n=document.querySelectorAll(e+" .stamp.discount b");for(t=0;t0&&e.$slides[0]?e.$slides[0]:null,n=e.$slides&&e.$slides.length>0&&e.$slides[e.$slides.length-1]?e.$slides[e.$slides.length-1]:null;t&&t.classList.contains("slick-active")?e.$prevArrow&&e.$prevArrow.length>0&&e.$prevArrow[0]&&e.$prevArrow[0].classList.add("disabled"):e.$prevArrow&&e.$prevArrow.length>0&&e.$prevArrow[0]&&e.$prevArrow[0].classList.remove("disabled"),n&&n.classList.contains("slick-active")?e.$nextArrow&&e.$nextArrow.length>0&&e.$nextArrow[0]&&e.$nextArrow[0].classList.add("disabled"):e.$nextArrow&&e.$nextArrow.length>0&&e.$nextArrow[0]&&e.$nextArrow[0].classList.remove("disabled")}}function i(e){var t=setInterval(function(){if(e){var r=$(e).children(".product-box-container");r&&r.length>0&&($(e).slick&&$(e).slick("unslick"),$(e).slick(n),clearInterval(t))}},1e3)}var e=this,t=e.isMobile(),n={variableWidth:!0,slidesToScroll:1,slidesToShow:4,infinite:!1,draggable:!1,swipe:!0,prevArrow:"Seta para a esquerda",nextArrow:"Seta para a direita",responsive:[{breakpoint:1980,settings:{variableWidth:!1}},{breakpoint:1180,settings:{variableWidth:!1}},{breakpoint:978,settings:{slidesToShow:2,arrows:!1}}]},s="#carousel"+e.id();$(s).on("init",function(e,t){$(window).trigger("resize"),r(t),i(s)}),$(s).on("afterChange",function(e,t){r(t)});if(!$(s).hasClass("slick-initialized"))var o=function(){$(s).slick(n),e.sliderLoaded(!0),clearInterval(u)},u=setInterval(function(){$(s).find(".product-box-container").length&&(e.isMobile()?(e.removeTextDiscountStamp(s),e.widget_displayAsProductListing()?clearInterval(u):o()):o())},1500)},validateShowWarrantyMenuProp:function(e,t){if(t.hasOwnProperty(e)){var n=c.getValue(t[e]);return n&&n.length>0}},showWarrantyMenu:function(e){return e.type.toLowerCase()==="servicos"?!0:e.addOnProducts.length>0?!0:this.validateShowWarrantyMenuProp("x_tension",e)?!0:this.validateShowWarrantyMenuProp("x_voltagem",e)?!0:this.validateShowWarrantyMenuProp("x_ciclo",e)?!0:!1},getFees:function(e){var t=e.productSalePrice?e.productSalePrice:e.productListPrice,n=c.createInstallments(t);return n},getFeesTextRecommendations:function(e){var t=e.productSalePrice?e.productSalePrice:e.productListPrice,n=c.getInstallmentsMaxNotFees(t);return n},validateAddToCart:function(e){var t=this;if(t.getProductStockStatus(e)){e=e.product;var n=[e];this.showWarrantyMenu(e)||c.productIsOutlet(e.parentCategories)?$.Topic("OPEN_WARRANTY_MODAL").publishWith(e):t.handleAddToCart(n,t)}},getProductStockStatus:function(e){var t=c.getValue(e.stockStatus);if(t&&(t.stockStatus===i.IN_STOCK||t.stockStatus===i.PREORDERABLE||t.stockStatus===i.BACKORDERABLE)&&(t.orderableQuantity!=undefined||t.productSkuInventoryStatus!=undefined))if(t.orderableQuantity){if(t.orderableQuantity>0)return!0}else{var n=e.childSKUs()[0].repositoryId(),r=t[n];if(t[n])if(r===i.IN_STOCK||r===i.PREORDERABLE||r===i.BACKORDERABLE)return!0}return!1},handleAddToCart:function(e,t){f.clearError(this.WIDGET_ID),f.clearSuccess(this.WIDGET_ID),e=e.map(function(e){return t.buildProductToAddToCart(e)}),$.Topic(s.topicNames.CART_ADD).publishWith(e[0],[{message:"success"}]);var n=e[0].displayName.substr(0,30)+"... foi adicionado ao carrinho";f.sendMessage("addToCart",n,"success",!0),window.minicart.showCart()},goToProductPage:function(e){l.goTo(e)},priceUnavailableText:function(){return o.t("ns.frigelarProductRecommendations:resources.priceUnavailable")},getChildSkusRepositoryId:function(e){var t=c.getValue(e.childSKUs);return c.getValue(t[0].repositoryId)},formatDiscountText_byType:function(e){var t=this,n=t.site().extensionSiteSettings.precificacao,r=0,i=0;console.log("salePrice-->",t.selectedSku().salePrice);var s=t.selectedSku().salePrice?t.selectedSku().salePrice:t.selectedSku().listPrice;e=="boleto"?r=n.boletoDiscountPercentage:e=="pix"?(console.log("entra pix"),r=n.pixDiscountPercentage):e=="cartao"&&(r=t.site().extensionSiteSettings.frigelarSiteCustomConfigurations.cashDiscountPercentage);if(s&&s>n.creditCardDiscountMin)return i=s-s*(parseInt(r)/100),"R$ "+ccNumber.formatNumber(i,!0,2)},buildProductToAddToCart:function(e){var t=$.extend(!0,{},e);return t.orderQuantity=1,t.catRefId=this.getChildSkusRepositoryId(e),t},sendProductsToGTM:function(e){var t=this;$.Topic("GTM_PRODUCT_IMPRESSIONS").publish(e)},openModal:function(){this.showModal(!0)},closeModal:function(){this.showModal(!1)},calculatePrices:function(e){var t=this,n=t.getMaxDiscountValue(e)?t.getMaxDiscountValue(e):e,r=t.getMaxInstallmentNotFees(e),i=r?" Ou "+r.formattedValue+" em "+r.installment+"x de "+r.formattedInstallment+" sem juros":"";return{maxDiscountEnabled:n,maxInstallmentNotFees:r,installmentMaxNotFees:i}},getMaxDiscountValue:function(e){if(e){var t=h.getHigherDiscountBySettings(e);return t}return null},getMaxInstallmentNotFees:function(e){if(e){var t=h.getCreditCardDiscountInformations_MaxInstallmentWithoutFees(e);return t}return null}}})