{"version":3,"file":"einsteinCarousel.min.js","sources":["einsteinCarousel.min.js"],"sourcesContent":["/******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId])\n/******/ \t\t\treturn installedModules[moduleId].exports;\n\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\texports: {},\n/******/ \t\t\tid: moduleId,\n/******/ \t\t\tloaded: false\n/******/ \t\t};\n\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.loaded = true;\n\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n\n\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(0);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ (function(module, exports) {\n\n\t'use strict';\n\n\t/**\n\t * Validates and Return the cquotient namespace provided by the commerce cloud platform\n\t * @returns {Object} - einsteinUtils or null\n\t */\n\n\tfunction getEinsteinUtils() {\n\t var einsteinUtils = window.CQuotient;\n\t if (einsteinUtils && typeof einsteinUtils.getCQUserId === 'function' && typeof einsteinUtils.getCQCookieId === 'function') {\n\t return einsteinUtils;\n\t }\n\t return null;\n\t}\n\n\t/**\n\t * fills in the carousel with product tile html objects\n\t * @param {string} einsteinResponse string html for product tiles\n\t * @param {jQuery} $parentElement parent element where recommendations will show.\n\t */\n\tfunction fillDomElement(einsteinResponse, $parentElement) {\n\t var recommender = $parentElement.data('recommender');\n\t var recommendedProducts = einsteinResponse[recommender].recs;\n\t if (recommendedProducts && recommendedProducts.length > 0) {\n\t var components = [];\n\t components = recommendedProducts.map(function (recommendedProduct) {\n\t var tiledefinition = {};\n\t tiledefinition.model = {\n\t type: 'product',\n\t id: recommendedProduct.id\n\t };\n\t return tiledefinition;\n\t });\n\n\t var url = new URL($parentElement.data('product-load-url'));\n\t url.searchParams.append('components', JSON.stringify(components));\n\t // SFRA6 migration, not used but implemented for possible new features\n\t url.searchParams.append('recommender', recommender);\n\t $.ajax({\n\t url: url.href,\n\t type: 'get',\n\t dataType: 'html',\n\t success: function success(html) {\n\t $parentElement.find('.multiple-items').html(html);\n\t $('body').trigger('einsteinCarousel:setup', $parentElement);\n\n\t // Adding events \"viewReco\" and \"clickReco\" for SFCC analytics\n\t var einsteinUtils = getEinsteinUtils();\n\t if (einsteinUtils) {\n\t try {\n\t var products = recommendedProducts.map(function (product) {\n\t return {\n\t id: product.id\n\t };\n\t });\n\n\t var params = {\n\t userId: einsteinUtils.getCQUserId(),\n\t cookieId: einsteinUtils.getCQCookieId(),\n\t ccver: '1.01',\n\t products: products\n\t };\n\n\t einsteinUtils.sendActivity(einsteinUtils.clientId, 'viewReco', params);\n\n\t $parentElement.find('.product-tile a').on('click', function () {\n\t try {\n\t einsteinUtils.sendActivity(einsteinUtils.clientId, 'clickReco', params);\n\t } catch (clickError) {\n\t console.error('Error sending clickReco activity:', clickError);\n\t }\n\t });\n\t } catch (viewError) {\n\t console.error('Error sending viewReco activity:', viewError);\n\t }\n\t }\n\t },\n\t error: function error() {\n\t $parentElement.spinner().stop();\n\t }\n\t });\n\t }\n\t}\n\n\t/**\n\t * Processes a recommendation tile, with an already initialized category specific anchors array\n\t * @param {jQuery} $parentElement parent element where recommendations will show.\n\t * @param {Object} einsteinUtils cquotient object\n\t * @param {Array} anchorsArray array of objects representing anchors\n\t */\n\tfunction processRecommendationsTile($parentElement, einsteinUtils, anchorsArray) {\n\t var recommender = $parentElement.data('recommender');\n\n\t var params = {\n\t userId: einsteinUtils.getCQUserId(),\n\t cookieId: einsteinUtils.getCQCookieId(),\n\t ccver: '1.01'\n\t };\n\n\t if (anchorsArray) {\n\t params.anchors = anchorsArray;\n\t }\n\n\t /**\n\t * Processes a recommendation responses\n\t * @param {Object} einsteinResponse cquotient object\n\t */\n\t function recommendationsReceived(einsteinResponse) {\n\t fillDomElement(einsteinResponse, $parentElement);\n\t $parentElement.spinner().stop();\n\t }\n\n\t if (einsteinUtils.getRecs) {\n\t einsteinUtils.getRecs(einsteinUtils.clientId, recommender, params, recommendationsReceived);\n\t } else {\n\t einsteinUtils.widgets = einsteinUtils.widgets || []; // eslint-disable-line no-param-reassign\n\t einsteinUtils.widgets.push({\n\t recommenderName: recommender,\n\t parameters: params,\n\t callback: recommendationsReceived\n\t });\n\t }\n\t}\n\n\t/**\n\t * Processes a recommendation tile, with an already initialized product specific anchors array\n\t * @param {jQuery} $parentElement parent element where recommendations will show.\n\t * @returns {Array} - containing an anchor object\n\t */\n\tfunction createProductAnchor($parentElement) {\n\t return [{\n\t id: $parentElement.data('primaryProductId'),\n\t sku: $parentElement.data('secondaryProductId'),\n\t type: $parentElement.data('alternativeGroupType'),\n\t alt_id: $parentElement.data('alternativeGroupId')\n\t }];\n\t}\n\n\t/**\n\t * Rerieves data attributes from parent element and converts to gretel compatible recommenders array\n\t * @param {jQuery} $parentElement parent element where recommendations will show.\n\t * @returns {Array} - containing an anchor object\n\t */\n\tfunction createCategoryAnchor($parentElement) {\n\t return [{ id: $parentElement.data('categoryId') }];\n\t}\n\n\t/**\n\t * Gets all placeholder elements, which hold einstein recommendations queries the details from the\n\t * einstein engine and feeds them back to the dom element\n\t */\n\tfunction loadRecommendations() {\n\t var einsteinUtils = getEinsteinUtils();\n\t if (einsteinUtils) {\n\t var $recommendationTiles = $('.js-einstein-carousel');\n\t $recommendationTiles.each(function () {\n\t var $parentElement = $(this);\n\t $parentElement.spinner().start();\n\t if ($(this).closest('.experience-einstein-einsteinCarouselProduct').length || $(this).closest('.experience-einstein-einsteinCarouselProductLH').length) {\n\t return processRecommendationsTile($parentElement, einsteinUtils, createProductAnchor($parentElement));\n\t } else if ($(this).closest('.experience-einstein-einsteinCarouselCategory').length || $(this).closest('.experience-einstein-einsteinCarouselCategoryLH').length) {\n\t return processRecommendationsTile($parentElement, einsteinUtils, createCategoryAnchor($parentElement));\n\t }\n\t return processRecommendationsTile($parentElement, einsteinUtils);\n\t });\n\t }\n\t}\n\n\t$(document).ready(function () {\n\t loadRecommendations();\n\t});\n\n/***/ })\n/******/ ]);"],"names":["modules","installedModules","__webpack_require__","moduleId","module","exports","id","loaded","call","m","c","p","getEinsteinUtils","einsteinUtils","window","CQuotient","getCQUserId","getCQCookieId","processRecommendationsTile","$parentElement","anchorsArray","recommender","data","params","userId","cookieId","ccver","recommendationsReceived","einsteinResponse","url","recommendedProducts","recs","length","components","map","recommendedProduct","tiledefinition","model","type","URL","searchParams","append","JSON","stringify","$","ajax","href","dataType","success","html","find","trigger","products","product","sendActivity","clientId","on","clickError","console","error","viewError","spinner","stop","anchors","getRecs","widgets","push","recommenderName","parameters","callback","loadRecommendations","each","this","start","closest","sku","alt_id","document","ready"],"mappings":"AAAS,CAAA,SAAUA,GAET,IAAIC,EAAmB,GAGvB,SAASC,EAAoBC,GAG5B,IAIIC,EAJJ,OAAGH,EAAiBE,KAIhBC,EAASH,EAAiBE,GAAY,CACzCE,QAAS,GACTC,GAAIH,EACJI,OAAQ,CAAA,CACT,EAGAP,EAAQG,GAAUK,KAAKJ,EAAOC,QAASD,EAAQA,EAAOC,QAASH,CAAmB,EAGlFE,EAAOG,OAAS,CAAA,EAGTH,IAhB4BC,OAiBpC,CAIAH,EAAoBO,EAAIT,EAGxBE,EAAoBQ,EAAIT,EAGxBC,EAAoBS,EAAI,GAGjBT,EAAoB,CAAC,CAC5B,EAEA,CAEJ,SAAUE,EAAQC,GASvB,SAASO,IACL,IAAIC,EAAgBC,OAAOC,UAC3B,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