{"version":3,"file":"rewards.widgets.bundle.js","mappings":";;;;;;;;;;;;;;;;AAAkE;AACV;AACA;AAExD,MAAMI,WAAW,GAAG,YAAY;;AAEhC;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,6BAAe,oCAAUC,MAAM,EAAE;EAC7B;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACI,MAAMC,OAAO,SAASD,MAAM,CAAC;IACzB;AACR;AACA;AACA;IACQE,KAAKA,CAAA,EAAG;MACJ,OAAO;QACHC,mBAAmB,EAAE;UACjBC,aAAa,EAAE,6BAA6B;UAC5CC,cAAc,EAAE,8BAA8B;UAC9CC,aAAa,EAAE,0BAA0B;UACzCC,eAAe,EAAE;QACrB,CAAC;QACDC,cAAc,EAAE,EAAE;QAClBC,cAAc,EAAE,EAAE;QAClBC,WAAW,EAAE,EAAE;QACfC,oBAAoB,EAAE,UAAU;QAChCC,YAAY,EAAE,KAAK;QACnBC,aAAa,EAAE,IAAI;QACnB,GAAG,KAAK,CAACX,KAAK,CAAC;MACnB,CAAC;IACL;;IAEA;AACR;AACA;AACA;AACA;IACQY,IAAIA,CAAA,EAAG;MACH,KAAK,CAACA,IAAI,CAAC,CAAC;MACZ,IAAI,CAACN,cAAc,GAAG,IAAI,CAACN,KAAK,CAAC,CAAC,CAACM,cAAc;MACjD,IAAI,CAACC,cAAc,GAAG,IAAI,CAACP,KAAK,CAAC,CAAC,CAACO,cAAc;MACjD,IAAI,CAACC,WAAW,GAAG,IAAI,CAACR,KAAK,CAAC,CAAC,CAACQ,WAAW;MAC3C,IAAI,CAACP,mBAAmB,GAAG,IAAI,CAACD,KAAK,CAAC,CAAC,CAACC,mBAAmB;;MAE3D;MACA,IAAI,CAACY,YAAY,GAAG,CAAC,CAAC;;MAEtB;MACA,IAAI,CAACC,UAAU,CAAC,CAAC;;MAEjB;MACA,I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MAE9CE,WAAW,CAACC,WAAW,CAAC,IAAI,CAAClG,KAAK,CAAC,CAAC,CAACS,oBAAoB,CAAC;IAC9D;EACJ;EAEA,OAAOV,OAAO;AAClB","sources":["webpack://sfra-boilerplate/./cartridges/plugin_rewards/cartridge/client/default/js/widgets/account/Rewards.js"],"sourcesContent":["import { getJSONByUrl, postJsonData } from 'widgets/toolbox/ajax';\nimport { RefElement } from 'widgets/toolbox/RefElement';\nimport { copyTextToClipboard } from 'core/toolbox/util';\n\nconst ALERT_EVENT = 'alert.show';\n\n/**\n * @typedef {typeof import('widgets/Widget').default} Widget\n */\n\n/**\n * @param {Widget} Widget - Base widget class for extension\n * @returns {Rewards} - The extended Rewards widget class\n */\nexport default function (Widget) {\n /**\n * @class Rewards\n * @extends Widget\n * @classdesc Represents the Rewards component with features:\n * 1. Renders the rewards header, list, and progress bar.\n * 2. Handles \"Scan Barcode in Store\" and \"Apply\" actions.\n * 3. Dynamically updates the rewards model and re-renders the component.\n *\n * @property {string} data-widget - Widget name `rewards`\n * @property {string} data-get-model-url - URL to get the rewards model\n * @property {string} data-apply-reward-url - URL to apply a reward\n * @property {string} data-scan-barcode-url - URL to scan barcode\n * @property {object} data-accessibility-alerts - Accessibility alert messages\n * for different user actions. Possible keys are: `rewardApplied`, `barcodeScanned`,\n * `barcodeCopied`, `progressUpdated`\n *\n * @example <caption>Example of Rewards widget usage</caption>\n * <section\n * class=\"l-rewards\"\n * data-widget=\"rewards\"\n * data-get-model-url=\"${URLUtils.url('Rewards-Get').toString()}\"\n * data-apply-reward-url=\"${URLUtils.url('Rewards-Apply').toString()}\"\n * data-scan-barcode-url=\"${URLUtils.url('Mulesoft-Barcode').toString()}\"\n * >\n * <!-- Rewards content will be rendered here -->\n * </section>\n */\n class Rewards extends Widget {\n /**\n * @description Returns the preferences for the widget, including URLs and accessibility alerts.\n * @returns {object} Preferences object\n */\n prefs() {\n return {\n accessibilityAlerts: {\n rewardApplied: 'Reward applied successfully',\n barcodeScanned: 'Barcode scanned successfully',\n barcodeCopied: 'Code copied to clipboard',\n progressUpdated: 'Progress updated'\n },\n applyRewardUrl: '',\n scanBarcodeUrl: '',\n getModelUrl: '',\n classesBarcodeActive: 'm-active',\n barcodeWidth: '321',\n barcodeHeight: '44',\n ...super.prefs()\n };\n }\n\n /**\n * @description Initializes the widget by setting up properties and\n * (conditionally) fetching the initial rewards model.\n * @returns {void}\n */\n init() {\n super.init();\n this.applyRewardUrl = this.prefs().applyRewardUrl;\n this.scanBarcodeUrl = this.prefs().scanBarcodeUrl;\n this.getModelUrl = this.prefs().getModelUrl;\n this.accessibilityAlerts = this.prefs().accessibilityAlerts;\n\n // Cache object to store previously retrieved barcodes\n this.barcodeCache = {};\n\n // Initialize events\n this.initEvents();\n\n // Load model (or use cached) on init\n this.loadRewardsModel(false);\n }\n\n /**\n * @description Sets up event listeners.\n */\n initEvents() {\n this.eventBus().on('minicart.updated', 'loadRewardsModel', true);\n this.eventBus().on('cart.updated', 'loadRewardsModel', true);\n\n // Called when the panel is opened\n // We do NOT force a refresh here. We just re-render if we have a cached model\n // or reload if we do not.\n this.eventBus().on('rewards.panel.opened', () => {\n this.loadRewardsModel(false);\n });\n }\n\n /**\n * @description Conditionally load rewards model. If the model is already\n * cached (this.rewardsModel) and we're not forcing a refresh,\n * we skip the AJAX call and just render from cache.\n * @param {boolean} [forceRefresh=false] - Whether to force re-fetch the model\n */\n loadRewardsModel(forceRefresh = false) {\n // If we already have a model and we're not forced to refresh it,\n // simply re-render from the existing cache:\n if (!forceRefresh && this.rewardsModel) {\n this.renderRewardsPage();\n return;\n }\n\n const wrapper = this.refs.self.get();\n this.toggleLoadingState(wrapper);\n\n getJSONByUrl(this.getModelUrl)\n .then(response => {\n this.rewardsModel = response.rewardsModel;\n this.renderRewardsPage();\n })\n .catch(error => {\n console.error('Error retrieving rewards model:', error);\n })\n .finally(() => {\n this.toggleLoadingState(wrapper);\n });\n }\n\n /**\n * @description Clears the rewards model cache. The next call to\n * loadRewardsModel() without forceRefresh=false will re-fetch from server.\n */\n clearRewardsModelCache() {\n this.rewardsModel = null;\n }\n\n /**\n * @description - Sets the loading class on/off when fetching data\n * @param {HTMLElement} el - The container element to toggle the load state on\n * @returns {Boolean} - true/false based on if the class toggled\n */\n toggleLoadingState(el) {\n if (!el) {\n return false;\n }\n el.classList.toggle('m-loading');\n return true;\n }\n\n /**\n * @description Renders the entire rewards page by rendering the header, list, and progress bar.\n * @returns {Promise<void>}\n */\n renderRewardsPage() {\n return Promise.all([\n this.renderRewardsHeader(),\n this.renderRewardsList(),\n this.renderProgressBar()\n ]);\n }\n\n /**\n * @description Renders the rewards header section.\n * @returns {Promise<void>}\n */\n renderRewardsHeader() {\n const headerData = {\n firstName: this.rewardsModel?.customerInfo?.firstName,\n rewardsCount: this.rewardsModel?.rewardsCount || 0,\n hasRewards: this.rewardsModel?.hasRewards\n };\n\n return this.render('rewardsHeaderTemplate', headerData, this.ref('rewardsHeaderContainer'));\n }\n\n /**\n * @description Renders the rewards list section.\n * @returns {Promise<void>}\n */\n renderRewardsList() {\n const rewardsData = {\n rewardsAllowed: this.rewardsModel?.rewardsAllowed,\n hasRewards: this.rewardsModel?.hasRewards,\n displayOrdersInfoBox: this.rewardsModel?.displayOrdersInfoBox,\n rewards: this.rewardsModel?.items || [],\n svgIcon: '#rewards'\n };\n\n return this.render('rewardsListTemplate', rewardsData, this.ref('rewardsListContainer'));\n }\n\n /**\n * @description Renders the progress bar section.\n * @returns {Promise<void>}\n */\n renderProgressBar() {\n const progressData = this.rewardsModel?.progress || {\n amountAway: '50',\n progressTitle: '',\n progressMessage: '',\n progressPercent: 0,\n progressPercentText: '0%',\n backOnSpendMessage: '5% back on your spend'\n };\n\n return this.render('progressBarTemplate', progressData, this.ref('progressBarContainer'));\n }\n\n /**\n * @description Handles the \"Apply\" button click event to apply a reward.\n * @listens dom#click\n * @param {Element} el - The element that triggered the event\n * @returns {Promise<void>}\n */\n applyReward(el) {\n el.disable();\n\n const couponCode = el.data('rewardId'); // This is the coupon code\n const url = this.applyRewardUrl;\n\n if (!couponCode || !url) {\n console.error('Reward ID or Apply Reward URL is missing.');\n el.enable();\n return Promise.resolve();\n }\n\n return postJsonData(url, { couponCode })\n .then(response => {\n // Always update the cached model and re-render,\n // even if there's an error, because the server\n // may have returned updated model info (e.g., isError, errorMessage).\n this.rewardsModel = response.rewardsModel;\n this.renderRewardsPage();\n\n if (response.success) {\n const accessibilityAlert = this.accessibilityAlerts.rewardApplied;\n const alertClassName = 'm-notification m-notification_copy';\n this.eventBus().emit(ALERT_EVENT, { accessibilityAlert, alertClassName });\n this.eventBus().emit('coupon.updated', response);\n } else {\n // Log the error or show a notification if needed\n console.error('Failed to apply reward:', response.errorMessage);\n\n // Optionally, you can fire an alert event to show a notification:\n // this.eventBus().emit(ALERT_EVENT, {\n // accessibilityAlert: response.errorMessage,\n // alertClassName: 'm-notification m-notification_error'\n // });\n }\n })\n .catch(error => {\n console.error('Error applying reward:', error);\n })\n .finally(() => {\n el.enable();\n });\n }\n\n\n /**\n * Inserts a barcode image into the DOM inside a specified container.\n *\n * @param {string|number} rewardId - The unique identifier for the reward.\n * @param {string} base64Image - The Base64-encoded image data of the barcode.\n * @param {number} barcodeWidth - The desired width of the barcode image in pixels.\n * @param {number} barcodeHeight - The desired height of the barcode image in pixels.\n * @param {Element} barcodeContainer - The image container\n */\n insertBarcodeImage(rewardId, base64Image, barcodeWidth, barcodeHeight, barcodeContainer) {\n if (!barcodeContainer) {\n console.error(`Barcode container not found for reward ID: ${rewardId}`);\n return;\n }\n\n const imgElement = document.createElement('img');\n imgElement.src = base64Image;\n imgElement.style.width = `${barcodeWidth}px`;\n imgElement.style.height = `${barcodeHeight}px`;\n imgElement.alt = `Barcode for reward ID ${rewardId}`;\n\n barcodeContainer.appendChild(imgElement);\n }\n\n /**\n * @description Handles the \"Scan Barcode in Store\" action.\n * @listens dom#click\n * @param {Element} el - The element that triggered the event\n * @returns {Promise<void>}\n */\n scanBarcodeInStore(el) {\n const rewardId = el.data('rewardId');\n const url = this.scanBarcodeUrl;\n const barcodeWidth = this.prefs().barcodeWidth;\n const barcodeHeight = this.prefs().barcodeHeight;\n const requested = el.attr('requested');\n\n if (!rewardId || !url) {\n console.error('Reward ID or Scan Barcode URL is missing.');\n return Promise.resolve();\n }\n\n // Toggle the barcode display\n this.toggleBarcode(el);\n\n // If the image has already been requested, skip re-fetch\n if (requested) {\n return Promise.resolve();\n }\n\n // Mark that we've requested this barcode already\n el.attr('requested', true);\n\n const barcodeContainerSelector = `[data-ref=\"barcode-image-${rewardId}\"]`;\n const barcodeContainer = this.ref('self').get()?.querySelector(barcodeContainerSelector);\n\n // Check if the barcode data is in cache\n if (this.barcodeCache[rewardId]) {\n this.insertBarcodeImage(\n rewardId,\n this.barcodeCache[rewardId],\n barcodeWidth,\n barcodeHeight,\n barcodeContainer\n );\n return Promise.resolve();\n }\n\n // Otherwise, fetch from server\n this.toggleLoadingState(barcodeContainer);\n\n return getJSONByUrl(url, {\n code: rewardId,\n width: barcodeWidth,\n height: barcodeHeight\n })\n .then(data => {\n if (data.success) {\n // Cache the base64 for future usage\n this.barcodeCache[rewardId] = data.base64Image;\n // Insert the barcode image into the DOM\n this.insertBarcodeImage(\n rewardId,\n data.base64Image,\n barcodeWidth,\n barcodeHeight,\n barcodeContainer\n );\n } else {\n console.error('Error fetching barcode:', data.errorMessage);\n el.attr('requested', false);\n }\n })\n .catch(error => {\n console.error('AJAX request failed:', error);\n el.attr('requested', false);\n })\n .finally(() => {\n this.toggleLoadingState(barcodeContainer);\n });\n }\n\n /**\n * @description Copy coupon code to clipboard\n * @listens dom#click\n * @param {Element} el - The element that triggered the event\n * @returns {void}\n */\n copyBarcode(el) {\n copyTextToClipboard(el.data('rewardId'));\n\n const accessibilityAlert = this.accessibilityAlerts.barcodeCopied;\n const alertClassName = 'm-notification';\n\n this.eventBus().emit(ALERT_EVENT, { accessibilityAlert, alertClassName });\n }\n\n /**\n * @description Handles the \"Scan Barcode in Store\" toggle.\n * @listens dom#click\n * @param {Element} el - The element that triggered the event\n */\n toggleBarcode(el) {\n const parentEl = el?.get()?.closest('[data-toggle]');\n const parentElRef = new RefElement([parentEl]);\n\n parentElRef.toggleClass(this.prefs().classesBarcodeActive);\n }\n }\n\n return Rewards;\n}\n"],"names":["getJSONByUrl","postJsonData","RefElement","copyTextToClipboard","ALERT_EVENT","Widget","Rewards","prefs","accessibilityAlerts","rewardApplied","barcodeScanned","barcodeCopied","progressUpdated","applyRewardUrl","scanBarcodeUrl","getModelUrl","classesBarcodeActive","barcodeWidth","barcodeHeight","init","barcodeCache","initEvents","loadRewardsModel","eventBus","on","forceRefresh","rewardsModel","renderRewardsPage","wrapper","refs","self","get","toggleLoadingState","then","response","catch","error","console","finally","clearRewardsModelCache","el","classList","toggle","Promise","all","renderRewardsHeader","renderRewardsList","renderProgressBar","headerData","firstName","customerInfo","rewardsCount","hasRewards","render","ref","rewardsData","rewardsAllowed","displayOrdersInfoBox","rewards","items","svgIcon","progressData","progress","amountAway","progressTitle","progressMessage","progressPercent","progressPercentText","backOnSpendMessage","applyReward","disable","couponCode","data","url","enable","resolve","success","accessibilityAlert","alertClassName","emit","errorMessage","insertBarcodeImage","rewardId","base64Image","barcodeContainer","imgElement","document","createElement","src","style","width","height","alt","appendChild","scanBarcodeInStore","requested","attr","toggleBarcode","barcodeContainerSelector","querySelector","code","copyBarcode","parentEl","closest","parentElRef","toggleClass"],"sourceRoot":""}