{"version":3,"sources":["webpack:///webpack/bootstrap","webpack:///../grocery-advanced-salesforce-commerce-cloud/cartridges/plugin_multi_wishlist/cartridge/client/default/js/multiWishlist.js","webpack:///./cartridges/app_custom_masymas/cartridge/client/default/js/multiWishlist.js"],"names":[],"mappings":";QAAA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;QAEA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;;;QAGA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA,0CAA0C,gCAAgC;QAC1E;QACA;;QAEA;QACA;QACA;QACA,wDAAwD,kBAAkB;QAC1E;QACA,iDAAiD,cAAc;QAC/D;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA,yCAAyC,iCAAiC;QAC1E,gHAAgH,mBAAmB,EAAE;QACrI;QACA;;QAEA;QACA;QACA;QACA,2BAA2B,0BAA0B,EAAE;QACvD,iCAAiC,eAAe;QAChD;QACA;QACA;;QAEA;QACA,sDAAsD,+DAA+D;;QAErH;QACA;;;QAGA;QACA;;;;;;;;;;;;;AClFY;;AAEZ;AACA;;AAEA;AACA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB;AACA,4D;AACA;AACA;AACA;AACA;AACA,2EAA2E,iBAAiB,IAAI,QAAQ;;AAExG;AACA;AACA;AACA,KAAK;AACL;;AAEA;AACA;AACA,YAAY,KAAK;AACjB;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;;AAEA;;AAEA,kB;AACA;AACA;AACA;AACA,uBAAuB,aAAa;AACpC;AACA;AACA;AACA;AACA,iBAAiB;AACjB;AACA;AACA;AACA,aAAa;AACb;;AAEA,KAAK;AACL;;AAEA;AACA;AACA,YAAY,KAAK;AACjB;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,qBAAqB;AACrB;AACA;AACA;AACA;AACA,yBAAyB;AACzB;AACA;AACA,aAAa;AACb,SAAS;AACT;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;;AAEA;AACA;AACA,YAAY,KAAK;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,qBAAqB;AACrB;AACA;AACA;AACA;AACA;AACA;AACA,yBAAyB;AACzB;AACA;AACA,aAAa;AACb;AACA,KAAK;AACL;;AAEA;AACA;AACA,YAAY,KAAK;AACjB;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,qBAAqB;AACrB;AACA;AACA;AACA;AACA;AACA;AACA,yBAAyB;AACzB;AACA;AACA,aAAa;AACb;AACA,KAAK;AACL;;AAEA;AACA;AACA,WAAW,OAAO;AAClB,YAAY,KAAK;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA,iBAAiB;AACjB;AACA;AACA,aAAa;AACb;AACA,SAAS;AACT;;AAEA;AACA;;AAEA;AACA;AACA;AACA,aAAa;AACb;AACA;AACA;;AAEA;AACA;AACA,aAAa;AACb;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,YAAY,KAAK;AACjB;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA,KAAK;AACL;;AAEA;AACA,YAAY,KAAK;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,2EAA2E;AAC3E;AACA;AACA,SAAS;AACT;AACA;AACA;AACA,SAAS;AACT,KAAK;AACL;;AAEA;AACA,YAAY,KAAK;AACjB;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,8EAA8E;AAC9E;AACA;AACA;AACA;AACA,iBAAiB;AACjB;AACA,SAAS;AACT;AACA;AACA,SAAS;AACT,KAAK;AACL;;AAEA;AACA,YAAY,KAAK;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;;AAEA;AACA,YAAY,KAAK;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA,uBAAuB,8BAA8B;AACrD;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,SAAS;AACT;AACA;AACA,KAAK;AACL;;AAEA;AACA,YAAY,KAAK;AACjB;AACA;AACA;;AAEA;;AAEA,2BAA2B,8BAA8B;AACzD;;AAEA;AACA;AACA,qBAAqB;AACrB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,YAAY,KAAK;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa;AACb;AACA;AACA,aAAa;AACb,SAAS;AACT,KAAK;AACL;;AAEA;AACA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,KAAK;AACL;;AAEA;AACA,YAAY,KAAK;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa;AACb;AACA;AACA,aAAa;AACb;AACA;AACA;AACA,SAAS;AACT,KAAK;AACL;;AAEA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,YAAY,KAAK;AACjB;AACA;AACA;AACA;;AAEA;AACA;;AAEA,uBAAuB,8BAA8B;AACrD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;;AAEA;AACA,YAAY,KAAK;AACjB;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,KAAK;;AAEL;AACA;AACA;AACA;AACA,KAAK;AACL;;AAEA;AACA,YAAY,KAAK;AACjB;AACA;AACA;;AAEA;AACA,uBAAuB,8BAA8B;AACrD;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,2BAA2B,8BAA8B;AACzD;AACA;AACA,+EAA+E,8BAA8B;AAC7G,2DAA2D,UAAU,GAAG,cAAc,YAAY,8BAA8B,wDAAwD,cAAc;AACtM,qEAAqE,UAAU;AAC/E,8EAA8E,cAAc;AAC5F,yDAAyD,mBAAmB,WAAW,oBAAoB;AAC3G;AACA,0BAA0B;AAC1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA,KAAK;;AAEL;AACA,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;ACvnBA;AAAA;AAAA","file":"default/js/multiWishlist.js","sourcesContent":[" \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 \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\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.l = 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// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = \"./cartridges/app_custom_masymas/cartridge/client/default/js/multiWishlist.js\");\n","'use strict'\n\nconst SUCCESS_TYPE_NOTIFICATION = 'alert-success';\nconst ERROR_TYPE_NOTIFICATION = 'alert-danger';\n\n/**\n * appends params to a url\n * @param {string} data - data returned from the server's ajax call\n * @param {Object} icon - icon that was clicked to add a product to the wishlist\n */\n function changeHeartIcon(icon) {\n $.spinner().stop();\n if (icon.hasClass('fa-heart-o')) {\n icon.removeClass('fa-heart-o').addClass('fa-heart');\n }\n}\n\n/**\n * Create an alert to display the alert message\n * @param {Object} message - Message to display\n * @param {string} notificationType - type of notification to print correct alert color\n */\nfunction displayMessageWishlist(notificationType, message) { \n if ($('.add-to-wishlist-messages').length === 0) {\n $('body').append('
');\n }\n $('.add-to-wishlist-messages')\n .append(`
${message}
`);\n\n setTimeout(() => {\n $('.add-to-wishlist-messages').remove();\n // button.removeAttr('disabled');\n }, 3000);\n}\n\n/**\n * Save preferred list and shows the selected wishlist\n * @return {void} - Do an Ajax call and manage de response\n */\n function saveAndSelectWishList() {\n $('.list-tab').on('click', function (e) {\n $('.list-tab').removeClass('active');\n $(this).addClass('active');\n\n var $wishlistTabs = $('.mym-js-wishlist-tabs');\n var url = $wishlistTabs.attr('data-save-list-url');\n var uuid = $(this).attr('data-list-uuid');\n\n var listUUID = $(this).attr('data-list-uuid');\n\n $('.wishlist-categories').addClass('d-none');\n $('.wishlist-products').addClass('d-none');\n\n $('.wishlist-' + listUUID).removeClass('d-none');\n \n if (url) { \n $.ajax({\n url: url,\n method: 'POST',\n data: { uuid: uuid },\n success: function (data) {\n if (data.error) {\n displayMessageWishlist(ERROR_TYPE_NOTIFICATION , data.error);\n }\n },\n error: function () {\n displayMessageWishlist(ERROR_TYPE_NOTIFICATION , 'Error Saving preferred wishlist');\n }\n });\n }\n\n });\n}\n\n/**\n * Create a new wishlist\n * @return {void} - Do an Ajax call and manage de response\n */\nfunction createNewList() {\n $('#btn-create-new-wishlist').on('click', function (e) {\n e.preventDefault();\n\n var closeButton = $('#btn-close-modal-new-wishlist');\n var selectedForm = $('#create-wishlist-form');\n var url = $(selectedForm).attr('action');\n var formData = $(selectedForm).serialize();\n var listElement = $('#createNewWishlistInputValue');\n var listName = $(listElement).val() ? $(listElement).val() : '';\n\n if (url && listName && listName !== '') {\n $.ajax({\n url: url,\n method: 'post',\n data: formData,\n success: function (response) {\n $(listElement).html('');\n // close Modal\n if ($(closeButton.length > 0)) {\n $(closeButton).click();\n }\n\n if (response.error) {\n displayMessageWishlist(ERROR_TYPE_NOTIFICATION , response.message);\n } else {\n displayMessageWishlist(SUCCESS_TYPE_NOTIFICATION , response.message);\n // recarga de la página\n setTimeout(function () {\n location.reload();\n }, 2000);\n }\n }\n });\n } else if (listName === '') {\n if ($(closeButton.length > 0)) {\n $(closeButton).click();\n }\n displayMessageWishlist(ERROR_TYPE_NOTIFICATION , 'The new whislist needs a name');\n }\n });\n}\n\n/**\n * Remove wishlist\n * @return {void} - Do an Ajax call and manage de response\n */\nfunction removeWishList() {\n $('.btn-removelist').on('click', function (e) {\n e.preventDefault();\n var UUID = $(this).data('remove-list-uuid');\n var closeButton = $('#btn-close-modal-remove-wishlist-' + UUID);\n var selectedForm = $('#remove-wishlist-form-' + UUID);\n var url = $(selectedForm).attr('action');\n var formData = $(selectedForm).serialize();\n\n if (url) {\n $.ajax({\n url: url,\n method: 'post',\n data: formData,\n success: function (response) {\n // close Modal\n if ($(closeButton.length > 0)) {\n $(closeButton).click();\n }\n\n if (response.error) {\n displayMessageWishlist(ERROR_TYPE_NOTIFICATION , response.message);\n } else {\n if ($(closeButton.length > 0)) {\n $(closeButton).click();\n }\n displayMessageWishlist(SUCCESS_TYPE_NOTIFICATION , response.message);\n setTimeout(function () {\n location. reload();\n }, 2000);\n }\n }\n });\n }\n });\n}\n\n/**\n * Edit wishlist\n * @return {void} - Do an Ajax call and manage de response\n */\nfunction editWishList() {\n $('.btn-editlist').on('click', function (e) {\n e.preventDefault();\n\n var UUID = $(this).data('edit-list-uuid');\n var closeButton = $('#btn-close-modal-edit-wishlist-' + UUID);\n var selectedForm = $('#edit-wishlist-form-' + UUID);\n var url = $(selectedForm).attr('action');\n var formData = $(selectedForm).serialize();\n\n if (url) {\n $.ajax({\n url: url,\n method: 'post',\n data: formData,\n success: function (response) {\n // close Modal\n if ($(closeButton.length > 0)) {\n $(closeButton).click();\n }\n\n if (response.error) {\n displayMessageWishlist(ERROR_TYPE_NOTIFICATION , response.message);\n } else {\n if ($(closeButton.length > 0)) {\n $(closeButton).click();\n }\n displayMessageWishlist(SUCCESS_TYPE_NOTIFICATION , response.message);\n setTimeout(function () {\n location. reload();\n }, 2000);\n }\n }\n });\n }\n });\n}\n\n/**\n * Shows only the selected dropdown of wishlist if user have more than one\n * @param {string} parentNode - parentNode\n * @return {void} - Do an Ajax call and manage de response\n */\nfunction showHideWishListDropdown(parentNode) {\n // Comportamiento especificon en PDP al actuar sobre dos iconos\n if ($('.wishlist-icon-position-pdp').length) {\n var dropdownLists = $('[class*=\"dropdown-' + parentNode + '\"]', '.detailsPDP, .sticky-add-to-cart');\n // Case click in sticky or PDP product\n if (dropdownLists.length > 0) {\n\n dropdownLists.each(function() {\n var $element = $(this);\n \n if ($element.hasClass('d-block')) {\n $element.removeClass('d-block');\n } else {\n $element.addClass('d-block');\n }\n });\n // Case clik in other PLP -> recomendations\n } else {\n var dropdownList = $('#dropdown-' + parentNode);\n\n var dropdownLogged = dropdownList.find('.dropdownLogged');\n var dropdownNotLogged = dropdownList.find('.dropdownNotLogged');\n\n if ($('#customerLogged').data('customerlogged')) {\n dropdownNotLogged.removeClass('d-flex').addClass('d-none');\n dropdownLogged.removeClass('d-none').addClass('d-flex');\n } else {\n dropdownLogged.removeClass('d-flex').addClass('d-none');\n dropdownNotLogged.removeClass('d-none').addClass('d-flex');\n }\n\n if (dropdownList.hasClass('d-block')) {\n $(dropdownList).removeClass('d-block');\n } else {\n $('.wishlistCustomerList').removeClass('d-block');\n $(dropdownList).addClass('d-block');\n }\n }\n } else {\n // No estamos en la PDP, se mantiene el comportamiento normal\n var dropdownList = $('#dropdown-' + parentNode);\n\n if (dropdownList.hasClass('d-block')) {\n $(dropdownList).removeClass('d-block');\n } else {\n $('.wishlistCustomerList').removeClass('d-block');\n $(dropdownList).addClass('d-block');\n }\n }\n}\n\n/**\n * Add a click event listener for when user clicks outside the heart icon removes any dropdown displayed\n * @return {void} - Do an Ajax call and manage de response\n */\nfunction hideDropdownWhenclickOut() {\n var html = document.body.parentNode;\n html.addEventListener('click', function(event) {\n if (!$('#dropdownMenuLink > span > i.fa').is(event.target)) {\n $('.wishlistCustomerList').removeClass('d-block');\n } else if ($('.wishlistIcon > span > i.fa').is(event.target)) {\n showHideWishListDropdown(event.target.parentNode.getAttribute('data-pid'));\n }\n });\n}\n\n/**Adds a product from a selected list\n * @return {void} - Do an Ajax call and manage de response\n */\nfunction addProductToSelectedList(pid, wishlistUUID) {\n var selectedForm = $('#selector-wishlist-form-' + pid + '-' + wishlistUUID);\n var url = $(selectedForm).attr('action');\n var formData = $(selectedForm).serialize();\n if (!url || !pid) {\n return;\n }\n\n $.ajax({\n url,\n type: 'post',\n dataType: 'json',\n data: formData,\n success(response) {\n displayMessageWishlist(SUCCESS_TYPE_NOTIFICATION , response.message);\n UpdateCustomerWishlistsPseudoContext(\"Add\", pid, wishlistUUID); //MUST DONE before toggle\n toggleProductInFrontLists(pid, wishlistUUID);\n $('.wishlistCustomerList').removeClass('d-block');\n },\n error() {\n displayMessageWishlist(ERROR_TYPE_NOTIFICATION , response.message);\n $('.wishlistCustomerList').removeClass('d-block');\n },\n });\n}\n\n/**Removes a product from a selected list\n * @return {void} - Do an Ajax call and manage de response\n */\nfunction handleProductRemoval(pid, wishlistUUID) {\n var selectedForm = $('#selector-wishlist-form-' + pid + '-' + wishlistUUID);\n var url = $(selectedForm).attr('action');\n var formData = $(selectedForm).serialize();\n\n if (!url || !pid) {\n return;\n }\n\n $.ajax({\n url,\n type: 'post',\n dataType: 'json',\n data: formData,\n success(response) {\n displayMessageWishlist(SUCCESS_TYPE_NOTIFICATION, response.message);\n UpdateCustomerWishlistsPseudoContext(\"Remove\", pid, wishlistUUID); //MUST DONE before toggle\n toggleProductInFrontLists(pid, wishlistUUID);\n if (window.location.href.includes('wishlist')) {\n setTimeout(function () {\n location.reload();\n }, 1000);\n }\n },\n error() {\n displayMessageWishlist(ERROR_TYPE_NOTIFICATION, response.message);\n },\n });\n}\n\n/**Redirects to the handleProductRemoval when a product is deleted in \"lista de la compra\" section\n * @return {void} - Do an Ajax call and manage de response (in \"handleProductRemoval\")\n */\nfunction removeProductToSelectedList() {\n $('.remove-from-multiwishlist').on('click', function (e) {\n e.preventDefault();\n var pid = $(this).find($('input[name=pid]')).val();\n var wishlistUUID = $(this).find($('input[name=wishlistUUID]')).val();\n handleProductRemoval(pid, wishlistUUID);\n });\n}\n\n/**Redirects to \"addProductToSelectedList\" or \"removeProductToSelectedList\"\n * @return {void} - Do an Ajax call and manage de response\n */\nfunction SelectorAddOrRemoveFromSelectedList () {\n $(document).off('click', '.wishlistCustomerListLink').on('click', '.wishlistCustomerListLink', function (e) {\n e.preventDefault();\n var pid = $(this).find('input[name=pid]').val();\n var wishlistUUID = $(this).find('input[name=wishlistUUID]').val();\n var customerWishlists = $('#customerLists').data('customerlists');\n\n var isProductInWishlist = false;\n\n for (var i = 0; i < customerWishlists.length; i++) {\n if (customerWishlists[i].UUID === wishlistUUID) {\n var wishlist = customerWishlists[i];\n break;\n }\n }\n\n if (wishlist && wishlist.productsIDs && wishlist.productsIDs.includes(pid)) {\n isProductInWishlist = true;\n }\n\n if (isProductInWishlist) {\n handleProductRemoval(pid, wishlistUUID);\n } else {\n addProductToSelectedList(pid, wishlistUUID);\n }\n });\n}\n\n/**Updates the info in PseudoContext \"customerWishlists\"\n * @return {void} - Do an Ajax call and manage de response\n */\nfunction UpdateCustomerWishlistsPseudoContext (type, pid, wishlistUUID) {\n var customerWishlists = $('#customerLists').data('customerlists');\n\n if (customerWishlists) {\n\n for (var i = 0; i < customerWishlists.length; i++) {\n if (customerWishlists[i].UUID === wishlistUUID) {\n \n if (type === \"Add\" && !customerWishlists[i].productsIDs.includes(pid)) {\n customerWishlists[i].productsIDs.push(pid);\n } else {\n var index = customerWishlists[i].productsIDs.indexOf(pid);\n if (index !== -1) {\n customerWishlists[i].productsIDs.splice(index, 1);\n }\n }\n }\n }\n }\n}\n\n/**Add all product in the list to cart and redirect to cart page\n * @return {void} - Do an Ajax call and manage de response\n */\nfunction addToBasketAllProductsInList() {\n $('.add-all-to-basket').on('click', function (e) {\n e.preventDefault();\n var wishlistUUID = $(this).find($('input[name=wishlistUUID]')).val();\n var selectedForm = $('#add-all-to-basket-wishlist-form-' + wishlistUUID);\n var url = $(selectedForm).attr('action');\n var formData = $(selectedForm).serialize();\n var storefrontUrlCart = 'cart';\n if (!url) {\n return;\n }\n\n $.ajax({\n url,\n type: 'post',\n dataType: 'json',\n data: formData,\n success() {\n window.location.replace(storefrontUrlCart);\n },\n error() {\n displayMessageWishlist(ERROR_TYPE_NOTIFICATION , 'We cannot add the products to basket');\n },\n });\n });\n}\n\n/**\n * Display message and change icon\n * @param {string} data - data returned from the server's ajax call\n * @param {Object} icon - icon that was clicked to add a product to the wishlist\n */\n function displayMessageAndChangeIcon(data, icon) {\n $.spinner().stop();\n var status;\n if (data) {\n status = 'alert-success';\n if (icon.hasClass('fa-heart-o')) {\n icon.removeClass('fa-heart-o').addClass('fa-heart');\n }else if (icon.hasClass('fa-heart')) {\n icon.removeClass('fa-heart').addClass('fa-heart-o');\n }\n } else {\n status = 'alert-danger';\n }\n\n if ($('.add-to-wishlist-messages').length === 0) {\n $('body').append('
');\n }\n $('.add-to-wishlist-messages')\n .append('
' + data.msg + '
');\n\n setTimeout(function () {\n $('.add-to-wishlist-messages').remove();\n }, 5000);\n}\n\n/**Add automatic the product when user only has a unic wishlist\n * @return {void} - Do an Ajax call and manage de response\n */\nfunction addToUnicWishlist() {\n $('body').on('click', '.wishlistTileIconUnic', function (e) {\n e.preventDefault();\n var icon = $(this).find('i.fa-heart-o, i.fa-heart').first();\n var url = $(this).attr('href');\n var pid = $(this).attr('data-pid');\n var optionId = $(this).closest('.product-detail').find('.product-option').attr('data-option-id');\n var optionVal = $(this).closest('.product-detail').find('.options-select option:selected').attr('data-value-id');\n optionId = optionId || null;\n optionVal = optionVal || null;\n if (!url || !pid) {\n return;\n }\n\n $.spinner().start();\n $.ajax({\n url: url,\n type: 'post',\n dataType: 'json',\n data: {\n pid: pid,\n optionId: optionId,\n optionVal: optionVal\n },\n success: function (data) {\n displayMessageAndChangeIcon(data, icon);\n },\n error: function (err) {\n displayMessageAndChangeIcon(err, icon);\n }\n });\n });\n}\n\n/**Toggle productId from the wishlist in pseudo CONTEXT generated in frontend\n * @param {string} productID - data returned from the server's ajax call\n * @param {string} wishlistUUID - data returned from the server's ajax call\n * @return {void} - Do an Ajax call and manage de response\n */\nfunction toggleProductInFrontLists(productId, wishlistUUID) {\n var customerWishlists = $('#customerLists').data('customerlists');\n var heartIconElement = $('[data-pid=\"' + productId + '\"] > .fa-stack-1x');\n \n if (customerWishlists && customerWishlists.length > 0) {\n var productExists = false;\n \n for (var i = 0; i < customerWishlists.length; i += 1) {\n var wishlist = customerWishlists[i];\n if (wishlist.productsIDs) {\n if (wishlist.productsIDs && wishlist.productsIDs.includes(productId)) {\n productExists = true;\n break;\n }\n }\n }\n if (productExists) {\n heartIconElement.removeClass('fa-heart-o').addClass('fa-heart');\n } else {\n heartIconElement.removeClass('fa-heart').addClass('fa-heart-o');\n }\n }\n}\n\n/**Initialise refresh by client proccess\n * @return {void} - Only initialise the wishlist refresh proccess\n */\nfunction initializeWishlists() {\n var customerWishlists = $('#customerLists').data('customerlists');\n\n // PLP - Actualiza las wishlists en los tiles del PLP\n $('.wishlistIconGeneral').each(function () {\n var productId = $(this).find('.wishlist-icon-position-plp').data('pid');\n actualizarWishlist($(this), productId, customerWishlists);\n });\n\n // PDP - Actualiza las wishlists en los tiles del PDP\n $('.wishlist-icon-position-pdp').parent().each(function () {\n var productId = $(this).find('.wishlist-icon-position-pdp').data('pid');\n actualizarWishlist($(this), productId, customerWishlists);\n });\n}\n\n/**Actualization every wishlist in tile\n * @return {void} - No returns\n */\nfunction actualizarWishlist(element, productId, customerWishlists) {\n var isProductInWishlist = false;\n\n if (customerWishlists) {\n for (var i = 0; i < customerWishlists.length; i++) {\n var wishlist = customerWishlists[i];\n if (wishlist.productsIDs && wishlist.productsIDs.includes(productId)) {\n isProductInWishlist = true;\n break;\n }\n }\n }\n\n if (isProductInWishlist) {\n element.find('.fa-stack-1x').removeClass('fa-heart-o').addClass('fa-heart');\n } else {\n element.find('.fa-stack-1x').removeClass('fa-heart').addClass('fa-heart-o');\n }\n\n // Mostrar u ocultar secciones según si el cliente está logueado\n if ($('#customerLogged').data('customerlogged')) {\n element.find('.dropdownNotLogged').removeClass('d-flex').addClass('d-none');\n element.find('.dropdownLogged').removeClass('d-none').addClass('d-flex');\n\n // Si está logueado, actualiza las listas desplegables\n if (customerWishlists) {\n var dropdownLogged = element.find('.dropdownLogged');\n var dropdownLoggedContent = $('
');\n for (var i = 0; i < customerWishlists.length; i++) {\n var wishlist = customerWishlists[i];\n var wishlistHTML = \n `\n
\n \n \n \n
\n ${wishlist.name ? wishlist.name : 'Lista Nueva'}\n
`;\n var wishlistElement = $(wishlistHTML);\n dropdownLoggedContent.append(wishlistElement);\n }\n dropdownLogged.empty();\n dropdownLogged.append(dropdownLoggedContent);\n dropdownLogged.find('.dropdown-item').unwrap();\n element.find('.dropdownNotLogged').removeClass('d-flex').addClass('d-none');\n dropdownLogged.removeClass('d-none').addClass('d-flex');\n }\n } else {\n element.find('.dropdownLogged').removeClass('d-flex').addClass('d-none');\n element.find('.dropdownNotLogged').removeClass('d-none').addClass('d-flex');\n }\n}\n\n$(document).ready(function() {\n\n initializeWishlists();\n\n // Vuelve a inicializar wishlists cuando se carguen las recomendaciones\n $(document).on('recommendationsLoaded', function () {\n initializeWishlists();\n });\n\n SelectorAddOrRemoveFromSelectedList();\n});\n\nmodule.exports = {\n createNewList: createNewList(),\n saveAndSelectWishList: saveAndSelectWishList(),\n removeWishList: removeWishList(),\n editWishList: editWishList(),\n showHideWishListDropdown: showHideWishListDropdown(),\n // addProductToSelectedList: addProductToSelectedList(),\n // handleProductRemoval: handleProductRemoval(),\n removeProductToSelectedList: removeProductToSelectedList(),\n SelectorAddOrRemoveFromSelectedList: SelectorAddOrRemoveFromSelectedList(),\n addToBasketAllProductsInList: addToBasketAllProductsInList(),\n hideDropdownWhenclickOut: hideDropdownWhenclickOut(),\n addToUnicWishlist: addToUnicWishlist()\n}\n","import \"plugin_multi_wishlist/multiWishlist\";"],"sourceRoot":""}