(()=>{"use strict";var e={20(e,t,n){var r=n(609),i=Symbol.for("react.element"),a=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,o=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,c={key:!0,ref:!0,__self:!0,__source:!0};function l(e,t,n){var r,a={},l=null,u=null;for(r in void 0!==n&&(l=""+n),void 0!==t.key&&(l=""+t.key),void 0!==t.ref&&(u=t.ref),t)s.call(t,r)&&!c.hasOwnProperty(r)&&(a[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps)void 0===a[r]&&(a[r]=t[r]);return{$$typeof:i,type:e,key:l,ref:u,props:a,_owner:o.current}}t.Fragment=a,t.jsx=l,t.jsxs=l},96(e,t,n){function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}Object.defineProperty(t,"__esModule",{value:!0}),t.UnmountClosed=void 0;var i,a=(i=n(609))&&i.__esModule?i:{default:i},s=n(277),o=["isOpened"],c=["isOpened"];function l(){return l=Object.assign||function(e){for(var t=1;t=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function h(e,t){for(var n=0;n{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.d({},{D:()=>k});const r=window.wc.wcBlocksRegistry,i=window.wp.htmlEntities,a=window.wc.wcSettings;var s=n(609),o=n.n(s),c=n(844);class l{static messages={};static setMessages(e){l.messages=e}static getMessage(e,t=""){return void 0===l.messages[e]?t:l.messages[e]}}var u=n(848);class d extends o().Component{constructor(e){super(e),this.state={...this.state,blikCode:"",blikError:""}}render(){return(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)("input",{type:"text",inputMode:"numeric",value:this.state.blikCode,onChange:this.handleBlikCodeChange,onFocus:this.handleOnFocus,placeholder:l.getMessage("enter_the_blik_code","Payment failed"),maxLength:6,className:"blik-input",pattern:"\\d{6}"}),(0,u.jsx)("span",{className:"atp-block-payment-description",children:l.getMessage("the_code_has_6_digits_note","The code has 6 digits. You'll find it in your banking app.")}),this.state.blikError&&(0,u.jsx)("span",{className:"atp-block-payment-description blik-error",children:this.state.blikError})]})}handleBlikCodeChange=e=>{const t=e.target.value;if(!/^\d*$/.test(t))return;const n=/^\d{6}$/.test(t);this.setState({blikCode:t,blikError:n?"":l.getMessage("code_is_invalid_code_should_be_6_digits","The code you provided is invalid. Code should be 6 digits.")}),n&&this.props.onBlikCodeChange(t)};handleOnFocus=e=>{this.props.onFocus()}}class p{static distillHtmlClassByString(e){return e.toLowerCase().trim().replace(/[\s_-]+/g,"_").replace(/^-+|-+$/g,"").normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^a-z0-9_]/g,"")}}class h extends o().Component{gpayObserver=null;gpayButton=null;static getTermsSelectors(){return["#terms","#terms-and-conditions",'input[name="terms"]','.wc-block-components-checkbox input[name="terms"]']}static findTermsCheckbox(){const e=h.getTermsSelectors();for(let t=0;t50?console.error("Google Pay: API not loaded"):void 0!==window.GooglePay&&window.google&&window.google.payments&&window.google.payments.api?this.initGpay():setTimeout(()=>{this.waitForDeps(e+1)},100)}initGpay(){const{authJwt:e,merchantId:t,merchantOrigin:n,merchantName:r,acceptorId:i,cartTotal:a,currency:s}=this.props,o=["authJwt","merchantId","merchantOrigin","merchantName","acceptorId"];for(const e of o)if(!this.props[e])return void console.error("Google Pay: Missing required field",{field:e,props:this.props});const c="sandbox"===k.getEnvironment()?"TEST":"PRODUCTION",l=k.getShopBaseCountryCode();try{const o=new window.GooglePay(c,e,t,n||window.location.hostname,r,i.toString(),["MASTERCARD","VISA"],["PAN_ONLY","CRYPTOGRAM_3DS"]);o.setTransactionAmount(a||""),o.setTransactionStatus("FINAL"),o.setTransactionCurrencyCode(s||""),o.setTransactionCountryCode(l),o.init(e=>{console.log("data.paymentMethodData.tokenizationData.token: "),console.log(e.paymentMethodData.tokenizationData.token),this.parentPaymentChannel.handleToggleSelected(),k.setPaymentChannelId(this.parentPaymentChannel.getChannelId());const t=JSON.stringify(e.paymentMethodData.tokenizationData.token),n=btoa(t);k.setGpayPaymentResultToken(n),k.submitOrder()})}catch(e){console.error("Google Pay: Init failed",e)}}setupTermsGuard(){const e=document.getElementById("js-pay-button-wrapper");e&&"undefined"!=typeof MutationObserver&&(this.gpayObserver=new MutationObserver(()=>{this.bindGpayClickHandler()}),this.gpayObserver.observe(e,{childList:!0,subtree:!0})),document.addEventListener("change",this.handleTermsChange),this.bindGpayClickHandler()}getTermsSelectors(){return h.getTermsSelectors()}findTermsCheckbox(){return h.findTermsCheckbox()}areTermsAccepted(){const e=this.findTermsCheckbox();return!e||!!e.checked}handleGpayClick=e=>{this.areTermsAccepted()?this.state.termsErrorVisible&&this.setState({termsErrorVisible:!1}):(this.state.termsErrorVisible||this.setState({termsErrorVisible:!0}),e&&("function"==typeof e.stopImmediatePropagation&&e.stopImmediatePropagation(),"function"==typeof e.preventDefault&&e.preventDefault()))};bindGpayClickHandler(){const e=document.getElementById("js-pay-button-wrapper");if(!e)return;const t=e.querySelector('button, div[role="button"]');t&&(this.gpayButton&&this.gpayButton!==t&&this.gpayButton.removeEventListener("click",this.handleGpayClick,!0),this.gpayButton=t,this.gpayButton.addEventListener("click",this.handleGpayClick,!0))}handleTermsChange=e=>{if(!e||!e.target)return;const t=e.target,n=this.getTermsSelectors();for(let e=0;e{if(!e)return 0;const t=Number(e.serviceId);return Number.isFinite(t)?t:0},[e]),v=(0,s.useMemo)(()=>{if(!e)return 0;const t=Number(e.amount);return Number.isFinite(t)?t:0},[e]),_=null!=y?y:v,S=null!==(n=null!=f?f:e?.currency)&&void 0!==n?n:"PLN",w=null!==(r=e?.language)&&void 0!==r?r:"pl",O=null!==(i=e?.cardsDomain)&&void 0!==i?i:"",T=(0,s.useCallback)(()=>{c.current=!1,p.current=!1,k.setCardWidgetSubmitting(!1),k.setCardWidgetFormValid(!1),k.setCardPaymentToken("")},[]),P=(0,s.useCallback)(()=>{p.current=!1,k.setCardWidgetSubmitting(!1)},[]),R=(0,s.useCallback)(()=>{if(o.current&&"function"==typeof o.current.stopConnection)try{o.current.stopConnection()}catch(e){}o.current=null,d.current="",p.current=!1,h.current=null,m.current=null},[]),E=(0,s.useCallback)(()=>{var e;const t=window.wp?.data?.select;if("function"!=typeof t)return;const n=t("wc/store/cart");if(!n||"function"!=typeof n.getCartTotals)return;const r=n.getCartTotals();if(!r||"object"!=typeof r)return;const i=r.total_price,a=Number(null!==(e=r.currency_minor_unit)&&void 0!==e?e:2);if("string"==typeof i||"number"==typeof i){const e=Number(i);if(Number.isFinite(e)&&Number.isFinite(a)){const t=Math.pow(10,a);g(t>0?e/t:e)}}"string"==typeof r.currency_code&&r.currency_code.length>0&&b(r.currency_code)},[]);return(0,s.useEffect)(()=>{E();const e=window.wp?.data?.subscribe;if("function"!=typeof e)return;let t="";const n=e(()=>{var e,n,r;const i=window.wp?.data?.select;if("function"!=typeof i)return;const a=i("wc/store/cart");if(!a||"function"!=typeof a.getCartTotals)return;const s=a.getCartTotals(),o=JSON.stringify({total_price:null!==(e=s?.total_price)&&void 0!==e?e:null,currency_code:null!==(n=s?.currency_code)&&void 0!==n?n:null,currency_minor_unit:null!==(r=s?.currency_minor_unit)&&void 0!==r?r:null});o!==t&&(t=o,E())});return()=>{"function"==typeof n&&n()}},[E]),(0,s.useEffect)(()=>{if(!t||1500!==k.getPaymentChannelId())return R(),T(),k.setCardWidgetSubmitHandler(null),void k.setCardWidgetResetHandler(null);if(!(e&&O&&C&&a.current))return T(),k.setCardWidgetSubmitHandler(null),void k.setCardWidgetResetHandler(null);if(void 0===window.WidgetConnection||void 0===window.widgetEvents)return T(),k.setCardWidgetSubmitHandler(null),void k.setCardWidgetResetHandler(null);R(),T();const n=O+"/widget-new/partner";a.current.src===n&&d.current===n||(a.current.src=n,d.current=n);const r=new window.WidgetConnection({language:w,amount:_,currency:S,serviceId:C});return o.current=r,h.current=_,m.current=S,p.current=!1,k.setCardWidgetSubmitHandler(()=>!(!o.current||!c.current||p.current||k.getIsCardWidgetSubmitting()||k.hasWcFieldValidationErrors()||(p.current=!0,k.setCardWidgetSubmitting(!0),o.current.sendForm(),0))),k.setCardWidgetResetHandler(P),r.startConnection(a.current).then(()=>{window.widgetEvents&&(r.on(window.widgetEvents.validityStatus,(e,t)=>{const n=!(!t||!t.valid);c.current=n,k.setCardWidgetFormValid(n),n||k.setCardPaymentToken("")}),r.on(window.widgetEvents.validationResult,(e,t)=>{const n=!(!t||!t.valid);c.current=n,k.setCardWidgetFormValid(n),n||k.setCardPaymentToken(""),p.current=!1,k.setCardWidgetSubmitting(!1)}),r.on(window.widgetEvents.formSuccess,e=>{p.current=!1,c.current=!0,k.setCardWidgetSubmitting(!1),k.setCardWidgetFormValid(!0),k.setCardPaymentToken(e||""),k.submitOrder()}))}).catch(()=>{T()}),()=>{k.setCardWidgetSubmitHandler(null),k.setCardWidgetResetHandler(null),R(),k.setCardWidgetSubmitting(!1)}},[w,O,t,C,P,T,R]),(0,s.useEffect)(()=>{const e=o.current;if(!e)return;if(p.current||k.getIsCardWidgetSubmitting())return;if(k.getCardPaymentToken())return;const t=h.current!==_,n=m.current!==S;if(t||n)try{t&&("function"==typeof e.updateAmount?e.updateAmount(_):"function"==typeof e.setAmount&&e.setAmount(_),h.current=_),n&&"function"==typeof e.setCurrency&&(e.setCurrency(S),m.current=S)}catch(e){}},[_,S]),t&&1500===k.getPaymentChannelId()?(0,u.jsxs)("div",{className:"bm-card-widget bm-card-widget--blocks",children:[(0,u.jsx)("p",{className:"bm-card-widget__help",children:l.getMessage("card_widget_wait_message","Enter your card details in the form above to place the order.")}),(0,u.jsx)("div",{className:"bm-card-widget__iframe-wrapper",children:(0,u.jsx)("iframe",{id:"bm-card-widget-iframe-blocks",ref:a,className:"bm-card-widget__iframe",title:l.getMessage("card_payment_form_title","Card payment form")})})]}):null}class y extends o().Component{hasParent=!1;static instances=[];isBlik0=!1;blikCode="";isGooglePay=!1;constructor(e){super(e),this.state={isOpen:!1,isSelected:!1},this.hasParent=!!e.hasParent&&e.hasParent,y.instances.push(this)}componentWillUnmount(){y.instances=y.instances.filter(e=>e!==this)}render(){const{numericChannelId:e,id:t,value:n,name:r,label:i,icon:a,description:s,items:o,hasParent:l,data:y}=this.props;this.numericChannelId=e;const f=Array.isArray(o)&&o.length>0,b=509===e&&y&&"object"==typeof y&&"blik0"in y&&!0===y.blik0;this.isBlik0=b;const C=1512===e&&y&&"object"==typeof y&&"merchantId"in y&&"without_redirect"===k.getGpayType();if(this.isGooglePay=C,C&&(!k.getOfferGooglePayOnCheckout()||!h.canRender()))return null;const v=C&&this.state.isSelected,_=e===k.CARD_WIDGET_CHANNEL_ID&&this.state.isSelected;return(0,u.jsxs)("li",{className:`atp-${p.distillHtmlClassByString(i)} atp-block-payment-item ${f&&"atp-has-children"}`,children:[(0,u.jsxs)("label",{className:this.state.isSelected?"atp-active":"",htmlFor:t,children:[(0,u.jsx)("input",{onClick:this.hasParent?this.handleToggleSelected:f?this.handleToggle:this.closeAllInstances,id:t,value:n,type:"radio",name:r}),(0,u.jsx)("img",{src:a,alt:r}),(0,u.jsxs)("div",{className:"atp-block-payment-item-wrapper",children:[b?(0,u.jsx)(d,{placeholder:"******",paymentChannel:this,onBlikCodeChange:this.handleBlikCodeChange,onFocus:this.handleToggleSelected}):(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)("span",{className:"atp-block-payment-label",children:i}),v?(0,u.jsx)(h,{merchantId:y.merchantId,acceptorId:y.acceptorId,merchantOrigin:y.merchantOrigin,merchantName:y.merchantName,authJwt:y.authJwt,cartTotal:y.cartTotal,currency:y.currency,paymentChannelItem:this}):null,_?(0,u.jsx)(m,{config:k.getCardWidgetConfig(),isSelected:this.state.isSelected}):null]}),(0,u.jsx)("span",{className:"atp-block-payment-description",dangerouslySetInnerHTML:{__html:s}})]})]}),(0,u.jsx)(c.Collapse,{isOpened:this.state.isOpen,children:f?(0,u.jsx)(g,{items:o,hasParent:!0}):null})]})}handleBlikCodeChange=e=>{this.blikCode=e,this.handleToggleSelected()};handleToggle=()=>{this.handleToggleSelected(),this.setState({isOpen:!this.state.isOpen,isSelected:this.state.isSelected})};handleToggleSelected=()=>{this.unselectAllInstances(),this.setState({isOpen:this.state.isOpen,isSelected:!0}),k.setPaymentChannelId(this.numericChannelId),k.setIsBlik0(this.isBlik0),k.setIsGpay(this.isGooglePay),k.setBlikCode(this.blikCode),this.numericChannelId!==k.CARD_WIDGET_CHANNEL_ID&&(k.setCardPaymentToken(""),k.setCardWidgetFormValid(!1),k.setCardWidgetSubmitting(!1),k.setCardWidgetSubmitHandler(null)),k.setPlaceOrderButtonHidden(this.isGooglePay&&"without_redirect"===k.getGpayType())};closeAllInstances=()=>{y.instances.forEach(e=>{e.setState({isOpen:!1,isSelected:!1})}),this.handleToggleSelected()};unselectAllInstances(){y.instances.forEach(e=>{e.setState({isOpen:e.state.isOpen,isSelected:!1})})}getChannelId(){return this.numericChannelId}}class g extends o().Component{hasParent=!1;constructor(e){super(e),this.list=e.items,this.hasParent=!!e.hasParent&&e.hasParent}render(){if(this.list&&0!==this.list.length)return(0,u.jsx)("ul",{className:"atp-block-payment",children:this.list.map(e=>(0,u.jsx)(y,{numericChannelId:e.numericChannelId,id:e.key,value:e.value,name:e.name,label:e.label,icon:e.icon,items:e.items,description:e.description,data:e.data,hasParent:this.hasParent}))})}}class f extends o().Component{constructor(e){super(e)}render(){const{label:e,iconSrc:t,iconAlt:n}=this.props;return(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)("span",{className:"wc-block-components-payment-method-label",children:e}),(0,u.jsx)("img",{src:t,alt:n})]})}}class b{static APPLE_PAY_CHANNEL_ID=1513;static GOOGLE_PAY_CHANNEL_ID=1512;static processItem({key:e,value:t,name:n,label:r,icon:i,id:a,block_description:s,items:o,data:c}){(a=parseInt(a))===this.GOOGLE_PAY_CHANNEL_ID&&(c=this.mapGpayData(c));let l={numericChannelId:a,key:e,value:t,name:n,label:r,icon:i,description:s,items:[],data:c};if(o&&o.length>0)for(const e of o)l.items.push(b.processItem(e));return l}static mapGpayData(e){if(!e||!e.gpay_form_data)return null;const t=e.gpay_form_data;return{merchantId:t.merchantId,acceptorId:String(t.acceptorId),merchantOrigin:t.merchantOrigin,merchantName:t.merchantName,authJwt:t.authJwt,cartTotal:t.cart_total,currency:t.currency}}static createChannelsFromServer(e){let t={items:[]};for(const n of e){let e=b.processItem(n);this.validateItem(e)&&t.items.push(e)}return t}static validateItem(e){return!(e.numericChannelId===this.APPLE_PAY_CHANNEL_ID&&!this.isApplePay())}static isApplePay(){return window.ApplePaySession}}class C{static create({title:e,description:t,icon_src:n,whitelabel:r,offer_google_pay_on_checkout:i,gpay_data:a,gpay_type:s,supports:o,place_order_button_label:c,channels:l,recurring_blocked:u,recurring_blocked_message:d,messages:p,adminAjaxUrl:h,nonce:m,environment:y,shopBaseCountryCode:g,card_widget_config:f}){try{return{label:e,description:t,iconSrc:n,whitelabel:r,offerGooglePayOnCheckout:!1!==i,gpayData:a,gpayType:s,placeOrderButtonLabel:c,supports:o,channels:b.createChannelsFromServer(l),recurringBlocked:!0===u,recurringBlockedMessage:null!=d?d:"",messages:p,adminAjaxUrl:h,nonce:m,environment:y,shopBaseCountryCode:g,cardWidgetConfig:null!=f?f:null}}catch(e){const t=e instanceof Error?e.message:"Unknown error";throw new Error(`Create PaymentMethodData failed: ${t}`)}}}let v=function(e){return e.STATUS_SUCCESS="payment_success",e.STATUS_ERROR="error",e.STATUS_CHECK_DEVICE="check_device",e.STATUS_WAIT="wait",e}({});class _ extends o().Component{constructor(e){super(e),this.state={message:"",status:v.STATUS_WAIT,visible:!1}}show(e,t){this.setState({message:e,status:t,visible:!0}),document.body.style.overflow="hidden"}hide(){this.setState({message:"",status:v.STATUS_WAIT,visible:!1}),document.body.style.overflow="auto"}render(){return this.state.visible?(0,u.jsx)("div",{className:"bm-blik-overlay",children:(0,u.jsx)("div",{className:"bm-blik-overlay-content",onClick:e=>e.stopPropagation(),children:(0,u.jsx)("p",{children:(0,u.jsx)("span",{className:`bm-blik-overlay-status ${this.state.status}`,children:this.state.message})})})}):null}}const S=(0,a.getPaymentMethodData)("bluemedia",{});class k extends o().Component{static CARD_WIDGET_CHANNEL_ID=1500;static submittedCardTokenRef="";static getEnvironment(){return k.paymentMethodDataFromServer.environment}static getShopBaseCountryCode(){return k.paymentMethodDataFromServer.shopBaseCountryCode}static getOfferGooglePayOnCheckout(){return!1!==k.paymentMethodDataFromServer.offerGooglePayOnCheckout}static getGpayType(){return k.paymentMethodDataFromServer.gpayType}static getCardWidgetConfig(){return k.paymentMethodDataFromServer.cardWidgetConfig}payment_data=["test"];constructor(){super({}),this.blikOverlayRef=o().createRef(),this.state={channels:k.paymentMethodDataFromServer.channels,recurringBlocked:k.paymentMethodDataFromServer.recurringBlocked,recurringBlockedMessage:k.paymentMethodDataFromServer.recurringBlockedMessage}}static flattenChannelIds(e){const t=new Set,n=e=>{if(e)for(const r of e)t.add(r.numericChannelId),n(r.items)};return n(e.items),t}static init(e){k.paymentMethodDataFromServer=C.create(S),k.cardPaymentToken="",k.isCardWidgetFormValid=!1,k.isCardWidgetSubmitting=!1,k.cardWidgetSubmitHandler=null,k.cardWidgetResetHandler=null,k.submittedCardTokenRef="",l.setMessages(k.paymentMethodDataFromServer.messages),(0,r.registerPaymentMethod)({name:"bluemedia",label:(0,u.jsx)(f,{label:this.paymentMethodDataFromServer.label,iconSrc:this.paymentMethodDataFromServer.iconSrc,iconAlt:this.paymentMethodDataFromServer.label}),content:(0,u.jsx)(k,{}),edit:(0,u.jsx)(k,{}),ariaLabel:this.paymentMethodDataFromServer.label,supports:{features:this.paymentMethodDataFromServer.supports},canMakePayment:()=>!0,placeOrderButtonLabel:this.paymentMethodDataFromServer.placeOrderButtonLabel,savedTokenComponent:(0,u.jsx)(u.Fragment,{children:(0,i.decodeEntities)(this.paymentMethodDataFromServer.description||"")})})}static setPaymentChannelId(e){k.paymentChannelId=e}static setIsBlik0(e){k.isBlik0=e}static setIsGpay(e){k.isGpay=e}static setGpayPaymentResultToken(e){k.GpayPaymentResultToken=e}static setCardPaymentToken(e){k.cardPaymentToken=e}static getCardPaymentToken(){return k.cardPaymentToken||""}static setCardWidgetFormValid(e){k.isCardWidgetFormValid=e}static setCardWidgetSubmitting(e){k.isCardWidgetSubmitting=e}static getIsCardWidgetSubmitting(){return!!k.isCardWidgetSubmitting}static setCardWidgetSubmitHandler(e){k.cardWidgetSubmitHandler=e}static setCardWidgetResetHandler(e){k.cardWidgetResetHandler=e}static resetCardWidgetTransientState(){if("function"==typeof k.cardWidgetResetHandler)try{k.cardWidgetResetHandler()}catch(e){}}static getPaymentChannelId(){return k.paymentChannelId}static triggerCardWidgetSendForm(){return"function"==typeof k.cardWidgetSubmitHandler&&k.cardWidgetSubmitHandler()}static setBlikCode(e){k.blikCode=e}static submitOrder(){try{const e=window?.wp?.data?.select?.("wc/store/checkout");if(e&&"function"==typeof e.isProcessing&&e.isProcessing())return}catch(e){}const e=document.querySelector(".wc-block-components-checkout-place-order-button");e instanceof HTMLElement&&e.click()}static hasWcFieldValidationErrors(){try{const e=window?.wp?.data;if(!e||"function"!=typeof e.select)return!1;const t=e.select("wc/store/validation");if(t&&"function"==typeof t.hasValidationErrors&&!0===t.hasValidationErrors())return!0;const n=e.select("wc/store/checkout");if(n&&"function"==typeof n.hasError&&!0===n.hasError())return!0}catch(e){}return!1}static setPlaceOrderButtonHidden(e){const t=document.querySelector(".wc-block-components-checkout-place-order-button");t instanceof HTMLElement&&(e?t.style.setProperty("display","none","important"):t.style.removeProperty("display"))}showBlikOverlay(e,t){this.blikOverlayRef.current&&this.blikOverlayRef.current.show(e,t)}hideBlikOverlay(){this.blikOverlayRef.current&&this.blikOverlayRef.current.hide()}render(){return this.state.recurringBlocked?(0,u.jsx)(u.Fragment,{children:(0,i.decodeEntities)(this.state.recurringBlockedMessage||"")}):k.paymentMethodDataFromServer.whitelabel?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(_,{ref:this.blikOverlayRef})," ",(0,u.jsx)(g,{items:this.state.channels.items})]}):(0,u.jsx)(u.Fragment,{children:(0,i.decodeEntities)(k.paymentMethodDataFromServer.description||"")})}componentDidMount(){this.subscribeToLiveRecurringData();const e=this.props?.eventRegistration,t=this.props?.emitResponse;if(!e||"function"!=typeof e.onPaymentSetup||"function"!=typeof e.onCheckoutSuccess||!t||!t.responseTypes)return;const{onPaymentSetup:n,onCheckoutSuccess:r}=e;"function"==typeof e.onCheckoutValidation&&(this.unsubscribeCheckoutValidation=e.onCheckoutValidation(async()=>{if(this.state.recurringBlocked){let e=null;try{const t=window?.wp?.data?.select?.("wc/store/payment");t&&"function"==typeof t.getActivePaymentMethod&&(e=t.getActivePaymentMethod())}catch(e){}if("bluemedia"===e)return{type:t.responseTypes.ERROR,message:this.state.recurringBlockedMessage||l.getMessage("payment_failed","Payment failed")}}return!k.paymentMethodDataFromServer.whitelabel||(k.paymentChannelId!==k.CARD_WIDGET_CHANNEL_ID||(k.hasWcFieldValidationErrors()?(k.setCardWidgetSubmitting(!1),k.resetCardWidgetTransientState(),{type:t.responseTypes.ERROR,message:"",hidden:!0}):!!k.getCardPaymentToken()||!!k.isCardWidgetSubmitting||!!k.isCardWidgetFormValid||{type:t.responseTypes.ERROR,errorMessage:l.getMessage("card_widget_fill_message","Complete the card form before placing the order.")}))})),"function"==typeof e.onCheckoutFail&&(this.unsubscribeCheckoutFail=e.onCheckoutFail(async()=>(k.setCardWidgetSubmitting(!1),k.submittedCardTokenRef="",k.resetCardWidgetTransientState(),!0))),this.unsubscribe=n(async()=>{if(k.paymentMethodDataFromServer.whitelabel){const e=k.paymentChannelId;if(e){const n=k.isGpay,r=k.isBlik0,i=k.blikCode;if(e===k.CARD_WIDGET_CHANNEL_ID){const n=k.getCardPaymentToken();if(!n){const e=k.triggerCardWidgetSendForm(),n=l.getMessage("card_widget_wait_message","Enter your card details in the form above to place the order."),r=l.getMessage("card_widget_fill_message","Complete the card form before placing the order."),i=k.isCardWidgetSubmitting||e||k.isCardWidgetFormValid?n:r;return e||k.setCardWidgetSubmitting(!1),{type:t.responseTypes.ERROR,message:i}}return k.submittedCardTokenRef&&k.submittedCardTokenRef===n||(k.submittedCardTokenRef=n),{type:t.responseTypes.SUCCESS,meta:{paymentMethodData:{autopay_numeric_channel_Id:e.toString(),autopay_numeric_channel_id:e.toString(),atp_card_payment_token:n}}}}return r?{type:t.responseTypes.SUCCESS,meta:{paymentMethodData:{autopay_numeric_channel_Id:e.toString(),bluemedia_blik_code:i,blik_0_block_payment:"1"}}}:n&&"without_redirect"===k.getGpayType()?{type:t.responseTypes.SUCCESS,meta:{paymentMethodData:{autopay_numeric_channel_Id:e.toString(),autopay_numeric_channel_id:e.toString(),atp_gpay_payment_token:k.GpayPaymentResultToken}}}:{type:t.responseTypes.SUCCESS,meta:{paymentMethodData:{autopay_numeric_channel_Id:e.toString(),autopay_numeric_channel_id:e.toString()}}}}return k.setCardWidgetSubmitting(!1),{type:t.responseTypes.ERROR,message:l.getMessage("no_payment_channel_selected","No payment channel selected.")}}}),this.unsubscribeCheckoutSuccess=r(async()=>{const e=k.paymentChannelId,n=k.isBlik0;if(e&&n)try{const e=await this.performAjaxRequests();return this.showBlikOverlay(e.message,e.status),await new Promise(e=>setTimeout(e,3e3)),this.hideBlikOverlay(),{type:t.responseTypes.SUCCESS}}catch(e){return this.showBlikOverlay(l.getMessage("payment_failed","Payment failed"),v.STATUS_ERROR),await new Promise(e=>setTimeout(e,3e3)),{type:t.responseTypes.SUCCESS}}})}unsubscribe=null;unsubscribeCheckoutSuccess=null;unsubscribeCheckoutValidation=null;unsubscribeCheckoutFail=null;unsubscribeRecurringCartData=null;subscribeToLiveRecurringData(){const e=window?.wp?.data;if(!e||"function"!=typeof e.select||"function"!=typeof e.subscribe)return;const t=()=>{var t;const n=e.select("wc/store/cart");if(!n||"function"!=typeof n.getCartData)return null;const r=n.getCartData();return null!==(t=r?.extensions?.bluemedia_recurring)&&void 0!==t?t:null},n=e=>{if(!e)return;const t=b.createChannelsFromServer(Array.isArray(e.channels)?e.channels:[]),n=!0===e.recurring_blocked,r="string"==typeof e.recurring_blocked_message?e.recurring_blocked_message:"",i=k.flattenChannelIds(t),a=k.paymentChannelId;(n||a&&!i.has(a))&&(k.setPaymentChannelId(0),k.setIsBlik0(!1),k.setIsGpay(!1),k.setBlikCode(""),k.setCardPaymentToken(""),k.setCardWidgetFormValid(!1),k.setCardWidgetSubmitting(!1),k.setCardWidgetSubmitHandler(null)),this.setState({channels:t,recurringBlocked:n,recurringBlockedMessage:r})};n(t());let r="";this.unsubscribeRecurringCartData=e.subscribe(()=>{const e=t(),i=JSON.stringify(e);i!==r&&(r=i,n(e))})}async performAjaxRequests(){const e=k.paymentMethodDataFromServer.adminAjaxUrl,t=k.paymentMethodDataFromServer.nonce,n=Date.now(),r=async()=>{if(Date.now()-n>12e4)throw new Error("Operation timed out after 2 minutes.");const i=new FormData;i.append("action","bm_payment_get_status_action"),i.append("nonce",t);const a=await fetch(e,{method:"POST",body:i});if(!a.ok)throw new Error("Request failed");const s=await a.json();return s.status===v.STATUS_SUCCESS?s:s.status===v.STATUS_CHECK_DEVICE||s.status===v.STATUS_WAIT?(this.showBlikOverlay(s.message,s.status),await new Promise(e=>setTimeout(e,3e3)),r()):s};return await r()}componentWillUnmount(){this.unsubscribe&&this.unsubscribe(),this.unsubscribeCheckoutSuccess&&this.unsubscribeCheckoutSuccess(),this.unsubscribeCheckoutValidation&&this.unsubscribeCheckoutValidation(),this.unsubscribeCheckoutFail&&this.unsubscribeCheckoutFail(),this.unsubscribeRecurringCartData&&this.unsubscribeRecurringCartData()}}k.init(S)})();