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EAAE,UAAU;YAChBkD;UACJ,CACJ,CAAC;QACL,CAAC,CAAC;MACV,CAAC,MAAI;QAEDR,YAAY,CAACzD,kBAAkB,CAACI,kBAAkB,CAAC,CAC9C8D,IAAI,CAAEC,QAAQ,IAAK;UAEhBN,mBAAmB,CAACE,MAAM,CAACK,MAAM,GAAG,SAAS;UAC7CrC,QAAQ,CAACiC,aAAa,CAACH,mBAAmB,CAAC;QAC/C,CAAC,CAAC,CACDQ,KAAK,CAAEC,KAAK,IAAK;UAEdT,mBAAmB,CAACE,MAAM,CAACK,MAAM,GAAG,OAAO;UAC3CrC,QAAQ,CAACiC,aAAa,CAACH,mBAAmB,CAAC;;UAE5C;UACCU,iBAAiB,CACbD,KAAK,CAACE,OAAO,EAAE;YACX1D,EAAE,EAAE,aAAa;YACjBC,IAAI,EAAE,UAAU;YAChBkD;UACJ,CACJ,CAAC;QACL,CAAC,CAAC;MACV;IACJ;EAEJ,CAAC,EAAE,CAACjE,kBAAkB,CAAE,CAAC;EAEzB,OAAQY,oDAAA,CAACb,sEAAwB;IACrBC,kBAAkB,EAAGA,kBAAoB;IACzCC,qBAAqB,EAAGA;EAAuB,CAClD,CAAC;AACd,CAAC;AAGD,MAAMwE,OAAO,GAAG;EACZpD,QAAQ;EACRqD,SAAS,EAAEtB;AACf,CAAC;AAED1B,qBAAqB,CAAE+C,OAAQ,CAAC,C","sources":["webpack://wt-gc-blocks/./src/wallet/walletblock.tsx","webpack://wt-gc-blocks/external window \"React\"","webpack://wt-gc-blocks/external window [\"wc\",\"blocksCheckout\"]","webpack://wt-gc-blocks/external window [\"wc\",\"wcBlocksData\"]","webpack://wt-gc-blocks/external window [\"wp\",\"data\"]","webpack://wt-gc-blocks/external window [\"wp\",\"element\"]","webpack://wt-gc-blocks/external window [\"wp\",\"i18n\"]","webpack://wt-gc-blocks/webpack/bootstrap","webpack://wt-gc-blocks/webpack/runtime/compat get default export","webpack://wt-gc-blocks/webpack/runtime/define property getters","webpack://wt-gc-blocks/webpack/runtime/hasOwnProperty shorthand","webpack://wt-gc-blocks/webpack/runtime/make namespace object","webpack://wt-gc-blocks/./src/wallet/frontend.js"],"sourcesContent":["import { useCallback } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\n\n\nexport const WtGcBlocksCheckoutWallet = ({\n checkoutWalletData,\n setCheckoutWalletData\n}) => {\n\n /* Declare values */\n const { wallet_amount, wallet_amount_html, wallet_coupon_code, wallet_applied } = checkoutWalletData;\n const [ checked, setChecked ] = useState( wallet_applied );\n\n \n /* Handle checkbox click events */\n const onUseWalletChange = useCallback(\n ( event ) => { \n setChecked( event.target.checked ); \n setCheckoutWalletData( {\n ...checkoutWalletData,\n wallet_applied: event.target.checked,\n on_page_load: false\n } );\n },\n [ setChecked, checkoutWalletData, setCheckoutWalletData ]\n ); \n\n\treturn ( wallet_amount > 0 ? \n (
\n \t\t
\n
\n \n
\n
\n
) : '' );\n}","module.exports = window[\"React\"];","module.exports = window[\"wc\"][\"blocksCheckout\"];","module.exports = window[\"wc\"][\"wcBlocksData\"];","module.exports = window[\"wp\"][\"data\"];","module.exports = window[\"wp\"][\"element\"];","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 { __ } from '@wordpress/i18n';\nimport { useEffect, useState } from '@wordpress/element';\nimport { WtGcBlocksCheckoutWallet } from './walletblock.tsx';\nimport { CART_STORE_KEY } from '@woocommerce/block-data';\nimport { useDispatch } from '@wordpress/data';\nimport { registerCheckoutFilters } from '@woocommerce/blocks-checkout';\n\n// Global import\nconst { registerCheckoutBlock } = wc.blocksCheckout;\n\n\n// Arrange the item\nsetTimeout(function(){ \n let targetElm = document.getElementsByClassName('wp-block-woocommerce-checkout-order-summary-subtotal-block').length ? document.getElementsByClassName('wp-block-woocommerce-checkout-order-summary-subtotal-block') : false;\n if( targetElm && document.getElementById('wt_gc_checkout_store_credit_balance') ){\n targetElm[0].before(document.getElementById('wt_gc_checkout_store_credit_balance'));\n } \n}, 200);\n\nconst wbte_gc_hide_wallet_coupon_code = (coupons, params) => {\n var couponsNew = [];\n for ( var k in coupons ) {\n var coupon = coupons[k];\n if ( coupon.code !== params.wt_gc_wallet_coupon_code ) {\n couponsNew.push(coupon);\n } \n } \n\n if ( ! params.wt_gc_wallet_apply_before_tax && ! couponsNew.length ) {\n \n setTimeout(function(){ \n if ( document.getElementsByClassName('wc-block-components-totals-discount').length ) {\n document.getElementsByClassName('wc-block-components-totals-discount')[0].style.display = 'none'; \n }\n }, 200);\n } \n return couponsNew;\n}\n\n// Hide wallet coupon on cart page\nregisterCheckoutFilters( 'wt-gc-blocks', {\n coupons: ( coupons, extensions, args ) => {\n let params = ( typeof wc_cart_params !== 'undefined' ? wc_cart_params : null );\n \n if ( params !== null && params.wt_gc_wallet_applied ) { \n return wbte_gc_hide_wallet_coupon_code(coupons, params);\n }\n return coupons;\n },\n} );\n\n\nconst Block = ({ children, checkoutExtensionData }) => {\n \n const { setExtensionData } = checkoutExtensionData;\n const { applyCoupon, removeCoupon } = useDispatch( CART_STORE_KEY ); \n const [ checkoutWalletData, setCheckoutWalletData ] = useState({ \n 'wallet_amount': wc_checkout_params.wt_gc_wallet_amount, \n 'wallet_amount_html': wc_checkout_params.wt_gc_wallet_amount_html, \n 'wallet_coupon_code': wc_checkout_params.wt_gc_wallet_coupon_code, \n 'wallet_applied': wc_checkout_params.wt_gc_wallet_applied,\n 'on_page_load': true\n });\n\n // Hide wallet coupon on checkout page\n registerCheckoutFilters( 'wt-gc-blocks', {\n coupons: ( coupons, extensions, args ) => {\n let params = ( typeof wc_checkout_params !== 'undefined' ? wc_checkout_params : null );\n \n if ( params !== null ) { \n return wbte_gc_hide_wallet_coupon_code(coupons, params);\n }\n return coupons;\n },\n } );\n\n useEffect( () => {\n\n if ( ! checkoutWalletData.on_page_load ) {\n\n /* Create custom event */\n const wallet_action_event = new CustomEvent(\"wt_gc_api_wallet_action\", {\n detail:{ \n 'coupon_code' : checkoutWalletData.wallet_coupon_code,\n 'status' : 'start'\n }\n });\n\n /* Trigger a custom event */\n setTimeout(function() {\n document.dispatchEvent(wallet_action_event);\n }, 20);\n const context = 'wc/cart'; /* message context */\n\n if ( checkoutWalletData.wallet_applied ) {\n \n applyCoupon(checkoutWalletData.wallet_coupon_code)\n .then((response) => {\n \n wallet_action_event.detail.status = 'success';\n document.dispatchEvent(wallet_action_event);\n })\n .catch((error) => { \n \n wallet_action_event.detail.status = 'error';\n document.dispatchEvent(wallet_action_event);\n\n /* Show error message */\n createErrorNotice(\n error.message, {\n id: 'coupon-form',\n type: 'snackbar',\n context,\n }\n );\n });\n }else{\n \n removeCoupon(checkoutWalletData.wallet_coupon_code)\n .then((response) => {\n \n wallet_action_event.detail.status = 'success';\n document.dispatchEvent(wallet_action_event);\n })\n .catch((error) => {\n \n wallet_action_event.detail.status = 'error';\n document.dispatchEvent(wallet_action_event); \n \n /* Show error message */\n createErrorNotice(\n error.message, {\n id: 'coupon-form',\n type: 'snackbar',\n context,\n }\n ); \n });\n }\n }\n\n }, [checkoutWalletData] );\n\n return ();\n}\n\n\nconst options = {\n metadata,\n component: Block\n};\n\nregisterCheckoutBlock( options );"],"names":["useCallback","__","sprintf","useState","WtGcBlocksCheckoutWallet","checkoutWalletData","setCheckoutWalletData","wallet_amount","wallet_amount_html","wallet_coupon_code","wallet_applied","checked","setChecked","onUseWalletChange","event","target","on_page_load","createElement","className","id","type","name","onChange","htmlFor","dangerouslySetInnerHTML","__html","metadata","useEffect","CART_STORE_KEY","useDispatch","registerCheckoutFilters","registerCheckoutBlock","wc","blocksCheckout","setTimeout","targetElm","document","getElementsByClassName","length","getElementById","before","wbte_gc_hide_wallet_coupon_code","coupons","params","couponsNew","k","coupon","code","wt_gc_wallet_coupon_code","push","wt_gc_wallet_apply_before_tax","style","display","extensions","args","wc_cart_params","wt_gc_wallet_applied","Block","children","checkoutExtensionData","setExtensionData","applyCoupon","removeCoupon","wc_checkout_params","wt_gc_wallet_amount","wt_gc_wallet_amount_html","wallet_action_event","CustomEvent","detail","dispatchEvent","context","then","response","status","catch","error","createErrorNotice","message","options","component"],"sourceRoot":""}