(()=> {
"use strict";
var __webpack_modules__=({
"react/jsx-runtime":
((module)=> {
module.exports=window["ReactJSXRuntime"];
})
});
var __webpack_module_cache__={};
function __webpack_require__(moduleId){
var cachedModule=__webpack_module_cache__[moduleId];
if(cachedModule!==undefined){
return cachedModule.exports;
}
var module=__webpack_module_cache__[moduleId]={
exports: {}
};
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
return module.exports;
}
(()=> {
__webpack_require__.n=(module)=> {
var getter=module&&module.__esModule ?
()=> (module['default']) :
()=> (module);
__webpack_require__.d(getter, { a: getter });
return getter;
};
})();
(()=> {
__webpack_require__.d=(exports, definition)=> {
for(var key in definition){
if(__webpack_require__.o(definition, key)&&!__webpack_require__.o(exports, key)){
Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
}
}
};
})();
(()=> {
__webpack_require__.o=(obj, prop)=> (Object.prototype.hasOwnProperty.call(obj, prop))
})();
(()=> {
__webpack_require__.r=(exports)=> {
if(typeof Symbol!=='undefined'&&Symbol.toStringTag){
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
}
Object.defineProperty(exports, '__esModule', { value: true });
};
})();
var __webpack_exports__={};
(()=> {
__webpack_require__.r(__webpack_exports__);
var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__( "react/jsx-runtime");
var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0___default=__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__);
(()=> {
if(!window.wp||!window.wc) return;
const {
__,
sprintf
}=wp.i18n||{
__: s=> s,
sprintf: s=> s
};
const {
registerPlugin
}=wp.plugins;
const {
Notice
}=wp.components;
const {
useState
}=wp.element;
const {
useDispatch,
useSelect
}=wp.data;
const blocksCheckout=wc.blocksCheckout||wc.blocks||{};
const {
ExperimentalOrderMeta,
extensionCartUpdate
}=blocksCheckout||{};
const cartStore=wc.wcBlocksData&&wc.wcBlocksData.cartStore||'wc/store/cart';
if(!ExperimentalOrderMeta||!useDispatch||!useSelect) return;
const NAMESPACE='pw-gift-cards';
const ApplyGiftCard=()=> {
const [code, setCode]=useState('');
const [isSubmitting, setIsSubmitting]=useState(false);
const [notice, setNotice]=useState(null);
const cartData=useSelect(select=> {
const s=select(cartStore);
return s&&s.getCartData ? s.getCartData():null;
}, []);
const giftCards=cartData&&cartData.extensions&&cartData.extensions[NAMESPACE]&&cartData.extensions[NAMESPACE].gift_cards||[];
const submit=async ()=> {
if(!code){
setNotice({
status: 'error',
message: __('Enter a gift card code.', 'pw-woocommerce-gift-cards')
});
return;
}
setIsSubmitting(true);
setNotice(null);
try {
await extensionCartUpdate({
namespace: NAMESPACE,
data: {
code
}});
setCode('');
} catch (err){
setNotice({
status: 'error',
message: err?.message||__('Something went wrong.', 'pw-woocommerce-gift-cards')
});
} finally {
setIsSubmitting(false);
}};
const handleRemove=async cardNumber=> {
setIsSubmitting(true);
setNotice(null);
try {
await extensionCartUpdate({
namespace: NAMESPACE,
data: {
code: cardNumber,
remove: true
}});
} catch (err){
setNotice({
status: 'error',
message: err?.message||__('Unable to remove gift card.', 'pw-woocommerce-gift-cards')
});
} finally {
setIsSubmitting(false);
}};
return (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(ExperimentalOrderMeta, {
children: (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
id: "pwgc-redeem-gift-card-container",
children: [giftCards.length > 0&&(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
className: "pwgc-applied-gift-cards",
children: [(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div", {
className: "pwgc-applied-gift-cards-title",
children: __('Gift cards applied', 'pw-woocommerce-gift-cards')
}), (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("ul", {
className: "pwgc-applied-gift-cards-list",
children: giftCards.map(card=> (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("li", {
className: "pwgc-applied-gift-cards-item",
children: [(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
className: "pwgc-applied-gift-cards-left",
children: [(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div", {
className: "pwgc-gift-card-number",
children: card.number
}), (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div", {
className: "pwgc-gift-card-remaining-balance",
children: card.balance&&(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div", {
className: "pwgc-gift-card-balance",
children: sprintf(__('Remaining balance is %s', 'pw-woocommerce-gift-cards'), card.balance)
})
})]
}), (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div", {
className: "pwgc-applied-gift-cards-right",
children: card.amount&&(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("span", {
className: "pwgc-gift-card-amount",
children: [card.amount, (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("button", {
type: "button",
className: "pwgc-remove-gift-card",
onClick: ()=> handleRemove(card.number),
"aria-label": sprintf(__('Remove gift card %s', 'pw-woocommerce-gift-cards'), card.number),
disabled: isSubmitting,
children: "\xD7"
})]
})
})]
}, card.number))
})]
}), !window.pwgcBlocks.hideRedeemForm&&(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("form", {
id: "pwgc-redeem-gift-card-form",
onSubmit: e=> {
e.preventDefault();
submit();
},
noValidate: true,
children: [(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("label", {
htmlFor: "pwgc-redeem-gift-card-number",
children: __('Have a gift card?', 'pw-woocommerce-gift-cards')
}), (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("input", {
id: "pwgc-redeem-gift-card-number",
type: "text",
value: code,
onChange: e=> setCode(e.target.value),
placeholder: __('Gift card number', 'pw-woocommerce-gift-cards'),
"aria-label": __('Gift card number', 'pw-woocommerce-gift-cards'),
disabled: isSubmitting
}), (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("button", {
type: "submit",
className: `pwgc-apply-gift-card-button wc-block-components-button ${isSubmitting ? 'is-loading':''}`,
disabled: isSubmitting,
"aria-busy": isSubmitting,
children: __('Apply Gift Card', 'pw-woocommerce-gift-cards')
}), notice&&(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(Notice, {
status: notice.status,
isDismissible: false,
children: notice.message
})]
})]
})
});
};
registerPlugin('pw-apply-gift-card-checkout', {
render: ApplyGiftCard,
scope: 'woocommerce-checkout'
});
registerPlugin('pw-apply-gift-card-cart', {
render: ApplyGiftCard,
scope: 'woocommerce-cart'
});
})();
})();
})()
;