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BAAsB,CAAC;IAC3C,CAAC,EAAE,EAAE,CAAC;EACV;EAEA,OACIE,oDAAA;IACEW,uBAAuB,EAAE;MAACC,MAAM,EAAEH;IAAY;EAAE,CACjD,CAAC;AAEV,CAAC;AAED1D,qBAAqB,CAAE;EACnBL,QAAQ;EACRmE,SAAS,EAAEP;AACf,CAAE,CAAC,C","sources":["webpack://wt-sc-blocks/external window \"React\"","webpack://wt-sc-blocks/external window [\"wp\",\"components\"]","webpack://wt-sc-blocks/external window [\"wp\",\"data\"]","webpack://wt-sc-blocks/external window [\"wp\",\"element\"]","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/giveaway-product/frontend.js"],"sourcesContent":["module.exports = window[\"React\"];","module.exports = window[\"wp\"][\"components\"];","module.exports = window[\"wp\"][\"data\"];","module.exports = window[\"wp\"][\"element\"];","// 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 {Disabled} from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nconst { registerCheckoutFilters,registerCheckoutBlock,extensionCartUpdate } = window.wc.blocksCheckout;\n\n// Declare some global variables.\nvar wbte_giveaway_eligible_message_timeout = null;\nvar wbte_giveaway_products_timeout = null;\nvar wbte_cart_obj = null;\nvar wbte_isFirefox = typeof InstallTrigger !== 'undefined';\n\n\n/**\n * Register checkout filter to alter cart and show notices\n */\nconst updateDataToCart = ( defaultValue, extensions, args ) => {\n\n wbte_cart_obj = args?.cart;\n\n // Add giveaway item text to cart item.\n const cartitem_giveaway_text = args?.cart?.extensions?.wt_sc_blocks?.cartitem_giveaway_text;\n const cart_item_key = args?.cartItem?.key;\n if (cart_item_key && cartitem_giveaway_text && cartitem_giveaway_text[cart_item_key] ) {\n args.cartItem.short_description = cartitem_giveaway_text[cart_item_key];\n args.cartItem.quantity_limits.maximum = args.cartItem.quantity;\n args.cartItem.quantity_limits.minimum = args.cartItem.quantity;\n }\n\n //Show giveaway available message.\n const { createInfoNotice, removeNotice, removeAllNotices } = useDispatch( 'core/notices' );\n const context = 'wc/cart';\n const msg_id = 'wbte-giveaway-eligible-msg';\n const giveaway_eligible_message = args?.cart?.extensions?.wt_sc_blocks?.giveaway_eligible_message;\n clearTimeout(wbte_giveaway_eligible_message_timeout);\n wbte_giveaway_eligible_message_timeout = setTimeout(function(){\n if(giveaway_eligible_message){\n createInfoNotice( giveaway_eligible_message, { id: msg_id, type: 'default', isDismissible: false , context } );\n }else{\n removeNotice( msg_id, context );\n } \n }, 10);\n\n return defaultValue;\n};\n\nregisterCheckoutFilters( 'wt-sc-blocks-update-cart', {\n itemName: updateDataToCart,\n} );\n\n\nconst modifyCartItemClass = ( defaultValue, extensions, args ) => {\n \n // Add custom CSS class to giveaway cart item.\n const cartitem_giveaway_text = args?.cart?.extensions?.wt_sc_blocks?.cartitem_giveaway_text;\n const cart_item_key = args?.cartItem?.key;\n if (cart_item_key && cartitem_giveaway_text && cartitem_giveaway_text[cart_item_key] ) {\n return 'wbte-giveaway-cart-item';\n }\n\n return defaultValue;\n};\n\nregisterCheckoutFilters( 'wt-sc-blocks-modify-cart-item-class', {\n cartItemClass: modifyCartItemClass,\n} );\n\n\ndocument.addEventListener('wbte_sc_checkout_value_updated', function(e){ \n extensionCartUpdate( {\n namespace: 'wbte-sc-blocks-update-checkout',\n data: {},\n } );\n});\n\n// Webkit browsers (other than Firefox) requires an extra refresh to show the giveaway products\nif ( ! wbte_isFirefox && \"1\" === WTSmartCouponOBJ.is_cart ) {\n \n setTimeout(function(){ \n if ( wbte_cart_obj ) {\n\n let html = wbte_cart_obj?.extensions?.wt_sc_blocks?.giveaway_products_html;\n let temp_elm = document.createElement(\"div\");\n temp_elm.innerHTML = html;\n let text = temp_elm.textContent || temp_elm.innerText || \"\";\n\n // Only do the refresh when giveaway product HTML exists.\n if ( text.trim() ) { \n extensionCartUpdate( {\n namespace: 'wbte-sc-blocks-update-checkout',\n data: {},\n } );\n }\n }\n }, 100);\n}\n\n/** \n * Giveaway products block\n */\nconst Block = ({ children, checkoutExtensionData, cart }) => {\n \n const [productsHtml, setProductsHtml] = useState('');\n \n if ( wbte_cart_obj ) {\n clearTimeout(wbte_giveaway_products_timeout);\n wbte_giveaway_products_timeout = setTimeout(function(){\n const giveaway_products_html = wbte_cart_obj?.extensions?.wt_sc_blocks?.giveaway_products_html;\n setProductsHtml(giveaway_products_html);\n }, 10); \n }\n \n return (\n
\n );\n}\n\nregisterCheckoutBlock( {\n metadata,\n component: Block\n} );\n "],"names":["metadata","Disabled","useState","useDispatch","registerCheckoutFilters","registerCheckoutBlock","extensionCartUpdate","window","wc","blocksCheckout","wbte_giveaway_eligible_message_timeout","wbte_giveaway_products_timeout","wbte_cart_obj","wbte_isFirefox","InstallTrigger","updateDataToCart","defaultValue","extensions","args","cart","cartitem_giveaway_text","wt_sc_blocks","cart_item_key","cartItem","key","short_description","quantity_limits","maximum","quantity","minimum","createInfoNotice","removeNotice","removeAllNotices","context","msg_id","giveaway_eligible_message","clearTimeout","setTimeout","id","type","isDismissible","itemName","modifyCartItemClass","cartItemClass","document","addEventListener","e","namespace","data","WTSmartCouponOBJ","is_cart","html","giveaway_products_html","temp_elm","createElement","innerHTML","text","textContent","innerText","trim","Block","children","checkoutExtensionData","productsHtml","setProductsHtml","dangerouslySetInnerHTML","__html","component"],"sourceRoot":""}