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,QAAQ;EACR+C,SAAS,EAAE/B;AACf,CAAC;AAEDH,qBAAqB,CAAEiC,OAAQ,CAAC,C","sources":["webpack://wt-sc-blocks/external window [\"wc\",\"blocksCheckout\"]","webpack://wt-sc-blocks/external window [\"wc\",\"wcBlocksData\"]","webpack://wt-sc-blocks/external window [\"wp\",\"data\"]","webpack://wt-sc-blocks/external window [\"wp\",\"element\"]","webpack://wt-sc-blocks/external window [\"wp\",\"htmlEntities\"]","webpack://wt-sc-blocks/external window [\"wp\",\"i18n\"]","webpack://wt-sc-blocks/webpack/bootstrap","webpack://wt-sc-blocks/webpack/runtime/compat get default export","webpack://wt-sc-blocks/webpack/runtime/define property getters","webpack://wt-sc-blocks/webpack/runtime/hasOwnProperty shorthand","webpack://wt-sc-blocks/webpack/runtime/make namespace object","webpack://wt-sc-blocks/./src/main/frontend.js"],"sourcesContent":["module.exports = window[\"wc\"][\"blocksCheckout\"];","module.exports = window[\"wc\"][\"wcBlocksData\"];","module.exports = window[\"wp\"][\"data\"];","module.exports = window[\"wp\"][\"element\"];","module.exports = window[\"wp\"][\"htmlEntities\"];","module.exports = window[\"wp\"][\"i18n\"];","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import metadata from './block.json';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __, sprintf, _n } from '@wordpress/i18n';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { CART_STORE_KEY, VALIDATION_STORE_KEY } from '@woocommerce/block-data';\nimport { useState, useEffect } from '@wordpress/element';\nimport { applyCheckoutFilter, extensionCartUpdate } from '@woocommerce/blocks-checkout';\n\n\n// Global import\nconst { registerCheckoutBlock } = wc.blocksCheckout;\n\n \nexport const WtScBlocksMain = (() => {\n const [couponCode, setCouponCode] = useState('');\n const [isClickBinded, setIsClickBinded] = useState(false);\n const { applyCoupon, removeCoupon } = useDispatch( CART_STORE_KEY );\n const { createErrorNotice, createSuccessNotice } = useDispatch( 'core/notices' );\n\n if ( ! isClickBinded ) {\n \n /* Set `true` for preventing multiple event binding */\n setIsClickBinded(true);\n \n /* Click event triggered by plugin public JS file */\n document.addEventListener('wt_sc_api_coupon_clicked', function(e){ \n\n const couponCode = e.detail.coupon_code;\n const couponId = e.detail.coupon_id;\n const context = 'wc/cart'; /* message context */\n\n applyCoupon(couponCode)\n .then((response) => { \n \n /* Trigger a custom event */\n const coupon_click_done_event = new CustomEvent(\"wt_sc_api_coupon_click_done\", {\n detail:{ 'coupon_code' : couponCode, 'coupon_id': couponId, 'status': true}\n });\n document.dispatchEvent(coupon_click_done_event);\n\n /* Show success message */\n if (\n applyCheckoutFilter( {\n filterName: 'showApplyCouponNotice',\n defaultValue: true,\n arg: { couponCode, context },\n } )\n ) {\n createSuccessNotice(\n sprintf(\n /* translators: %s coupon code. */\n __('Coupon code \"%s\" has been applied to your cart.', 'wt-smart-coupons-for-woocommerce'),\n couponCode\n ),\n { id: 'coupon-form', type: 'snackbar', context }\n );\n }\n\n })\n .catch((error) => { \n \n /* Trigger a custom event */\n const coupon_click_done_event = new CustomEvent(\"wt_sc_api_coupon_click_done\", {\n detail:{ 'coupon_code' : couponCode, 'coupon_id': couponId, 'status': false, 'message': error.message}\n });\n document.dispatchEvent(coupon_click_done_event);\n\n /* Show error message */\n createErrorNotice(\n error.message,\n {\n id: 'coupon-form',\n type: 'snackbar',\n context,\n }\n );\n }); \n });\n\n }\n \n return '';\n});\n\nconst options = {\n metadata,\n component: WtScBlocksMain\n};\n\nregisterCheckoutBlock( options );\n"],"names":["metadata","useDispatch","useSelect","__","sprintf","_n","decodeEntities","CART_STORE_KEY","VALIDATION_STORE_KEY","useState","useEffect","applyCheckoutFilter","extensionCartUpdate","registerCheckoutBlock","wc","blocksCheckout","WtScBlocksMain","couponCode","setCouponCode","isClickBinded","setIsClickBinded","applyCoupon","removeCoupon","createErrorNotice","createSuccessNotice","document","addEventListener","e","detail","coupon_code","couponId","coupon_id","context","then","response","coupon_click_done_event","CustomEvent","dispatchEvent","filterName","defaultValue","arg","id","type","catch","error","message","options","component"],"sourceRoot":""}