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D,cAAc,CAAC,CAAC;MAC1G;MACA,OAAOmC,0BAA0B,CAACnC,cAAc,EAAErB,aAAa,CAAC;IACpE,CAAC,CAAC;EACN;AACJ;AAEA,SAAS6E,iBAAiBA,CAAA,EAAG;EACzB,IAAIvE,CAAC,CAACL,MAAM,CAAC,CAAC6E,KAAK,CAAC,CAAC,GAAG,GAAG,EAAE;IACzBxE,CAAC,CAAC,wBAAwB,CAAC,CAACgD,QAAQ,CAAC,WAAW,CAAC;EACrD,CAAC,MAAM;IACHhD,CAAC,CAAC,wBAAwB,CAAC,CAAC+C,MAAM,CAAC,WAAW,CAAC;EACnD;AACJ;AAEA/C,CAAC,CAACyE,QAAQ,CAAC,CAACC,KAAK,CAAC,YAAY;EAC1BL,mBAAmB,CAAC,CAAC;EACrBE,iBAAiB,CAAC,CAAC;AACvB,CAAC,CAAC,C","sources":["webpack://app_custom_dietdirect/./cartridges/app_custom_dietdirect/cartridge/client/default/js/einsteinCarousel.js"],"sourcesContent":["'use strict';\n\n/**\n * Validates and Return the cquotient namespace provided by the commerce cloud platform\n * @returns {Object} - einsteinUtils or null\n */\nfunction getEinsteinUtils() {\n var einsteinUtils = window.CQuotient;\n if (einsteinUtils && (typeof einsteinUtils.getCQUserId === 'function') && (typeof einsteinUtils.getCQCookieId === 'function')) {\n return einsteinUtils;\n }\n return null;\n}\n\n/**\n * create slick carousel\n */\nfunction pdSlickCarousel() {\n\t$('.einstein-pd-slick-carousel').each(function () {\n\t\tvar noOfSlides = $(this).closest('.multi-image-container').attr('no-of-slides');\n\t $(this).slick({\n \t infinite: true,\n \t slidesToShow: noOfSlides,\n \t slidesToScroll: 1,\n \t arrows: true,\n \t responsive: [\n \t\t {\n \t\t breakpoint: 768,\n \t\t settings: {\n \t\t \t slidesToShow: 1\n \t\t }\n \t\t },\n \t\t {\n \t\t breakpoint: 1024,\n \t\t settings: {\n \t\t \t slidesToShow: 4\n \t\t }\n \t\t }\n \t\t ]\n \t});\n\t});\n}\n\n/**\n * fills in the carousel with product tile html objects\n * @param {string} einsteinResponse string html for product tiles\n * @param {jQuery} $parentElement parent element where recommendations will show.\n */\nfunction fillDomElement(einsteinResponse, $parentElement) {\n var recommender = $parentElement.data('recommender');\n var recommendedProducts = einsteinResponse[recommender].recs;\n if (recommendedProducts && recommendedProducts.length > 0) {\n var template = $parentElement.data('template');\n var swatches = $parentElement.data('swatches');\n var displayRatings = $parentElement.data('displayratings');\n var components = [];\n components = recommendedProducts.map(function (recommendedProduct) {\n var tiledefinition = {};\n tiledefinition.classxs = $parentElement.data('bsxs');\n tiledefinition.classsm = $parentElement.data('bssm');\n tiledefinition.classmd = $parentElement.data('bsmd');\n tiledefinition.template = template;\n tiledefinition.swatches = swatches;\n tiledefinition.displayratings = displayRatings;\n tiledefinition.model = {\n type: 'product',\n id: recommendedProduct.id\n };\n return tiledefinition;\n });\n\n var url = new URL($parentElement.data('product-load-url'));\n url.searchParams.append('components', JSON.stringify(components));\n url.searchParams.append('limit', $parentElement.data('limit'));\n url.searchParams.append('recommender', recommender);\n $.ajax({\n url: url.href,\n type: 'get',\n dataType: 'html',\n success: function (html) {\n $parentElement.find('.carousel-inner').html(html);\n $('.carousel-inner script').remove();\n pdSlickCarousel();\n $('.einstein-pd-slick-carousel .product-tile-inventory.outofstock').closest('.product-item').addClass('d-none');\n },\n error: function () {\n \t\n }\n });\n }\n}\n\n /**\n * Processes a recommendation tile, with an already initialized category specific anchors array\n * @param {jQuery} $parentElement parent element where recommendations will show.\n * @param {Object} einsteinUtils cquotient object\n * @param {Array} anchorsArray array of objects representing anchors\n */\nfunction processRecommendationsTile($parentElement, einsteinUtils, anchorsArray) {\n var recommender = $parentElement.data('recommender');\n\n var params = {\n userId: einsteinUtils.getCQUserId(),\n cookieId: einsteinUtils.getCQCookieId(),\n ccver: '1.01'\n };\n\n if (anchorsArray) {\n params.anchors = anchorsArray;\n }\n\n /**\n * Processes a recommendation responses\n * @param {Object} einsteinResponse cquotient object\n */\n function recommendationsReceived(einsteinResponse) {\n fillDomElement(einsteinResponse, $parentElement);\n }\n\n if (einsteinUtils.getRecs) {\n einsteinUtils.getRecs(einsteinUtils.clientId, recommender, params, recommendationsReceived);\n } else {\n einsteinUtils.widgets = einsteinUtils.widgets || []; // eslint-disable-line no-param-reassign\n einsteinUtils.widgets.push({\n recommenderName: recommender,\n parameters: params,\n callback: recommendationsReceived\n });\n }\n}\n\n/**\n * Processes a recommendation tile, with an already initialized product specific anchors array\n * @param {jQuery} $parentElement parent element where recommendations will show.\n * @returns {Array} - containing an anchor object\n */\nfunction createProductAnchor($parentElement) {\n return [{\n id: $parentElement.data('primaryProductId'),\n sku: $parentElement.data('secondaryProductId'),\n type: $parentElement.data('alternativeGroupType'),\n alt_id: $parentElement.data('alternativeGroupId')\n }];\n}\n\n/**\n * Rerieves data attributes from parent element and converts to gretel compatible recommenders array\n * @param {jQuery} $parentElement parent element where recommendations will show.\n * @returns {Array} - containing an anchor object\n */\nfunction createCategoryAnchor($parentElement) {\n return [{ id: $parentElement.data('categoryId') }];\n}\n\n/**\n * Gets all placeholder elements, which hold einstein recommendations queries the details from the\n * einstein engine and feeds them back to the dom element\n */\nfunction loadRecommendations() {\n var einsteinUtils = getEinsteinUtils();\n if (einsteinUtils) {\n var $recommendationTiles = $('.einstein-carousel');\n $recommendationTiles.each(function () {\n var $parentElement = $(this);\n if ($(this).closest('.experience-einstein-einsteinCarouselProduct').length) {\n return processRecommendationsTile($parentElement, einsteinUtils, createProductAnchor($parentElement));\n } else if ($(this).closest('.experience-einstein-einsteinCarouselCategory').length) {\n return processRecommendationsTile($parentElement, einsteinUtils, createCategoryAnchor($parentElement));\n }\n return processRecommendationsTile($parentElement, einsteinUtils);\n });\n }\n}\n\nfunction einsteinContainer() {\n if ($(window).width() > 768) {\n $('.multi-image-container').addClass('container');\n } else {\n $('.multi-image-container').remove('container');\n }\n}\n\n$(document).ready(function () {\n loadRecommendations();\n einsteinContainer();\n});\n"],"names":["getEinsteinUtils","einsteinUtils","window","CQuotient","getCQUserId","getCQCookieId","pdSlickCarousel","$","each","noOfSlides","closest","attr","slick","infinite","slidesToShow","slidesToScroll","arrows","responsive","breakpoint","settings","fillDomElement","einsteinResponse","$parentElement","recommender","data","recommendedProducts","recs","length","template","swatches","displayRatings","components","map","recommendedProduct","tiledefinition","classxs","classsm","classmd","displayratings","model","type","id","url","URL","searchParams","append","JSON","stringify","ajax","href","dataType","success","html","find","remove","addClass","error","processRecommendationsTile","anchorsArray","params","userId","cookieId","ccver","anchors","recommendationsReceived","getRecs","clientId","widgets","push","recommenderName","parameters","callback","createProductAnchor","sku","alt_id","createCategoryAnchor","loadRecommendations","$recommendationTiles","einsteinContainer","width","document","ready"],"sourceRoot":""}