(()=>{"use strict";var e={n:t=>{var n=t&&t.__esModule?()=>t.default:()=>t;return e.d(n,{a:n}),n},d:(t,n)=>{for(var a in n)e.o(n,a)&&!e.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:n[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.React,n=window.wc.wcBlocksRegistry,a=window.wc.wcSettings,l=window.wp.i18n,s=window.jQuery;var r=e.n(s);const o=window.wp.htmlEntities;function c({elementClass:e,children:n}){return(0,t.createElement)("p",{className:e+"__description"},n)}function i({fieldValue:e,onInputCallback:n}){return(0,t.createElement)("label",{id:"blik_code_label"},(0,t.createElement)("input",{onWheel:e=>e.target.blur(),className:"autopay-blik-code",name:"blik_code",type:"number",step:"1",maxLength:"6",minLength:"6",min:"000000",max:"999999",value:e,placeholder:"000000",onInput:n}),(0,t.createElement)("p",{id:"blik_msg_container",className:"blik_msg_container"}))}const p=(0,a.getSetting)("autopay_blik_data",{}),m="wppay-blik-zero";let u=!1,d=(0,l.__)("Wystąpił błąd.","pay-wp"),y="",_="";const w=async e=>new Promise((t=>setTimeout(t,e))),E=e=>{const[n,a]=(0,t.useState)(""),[s,E]=(0,t.useState)(!1),{eventRegistration:b,emitResponse:g}=e,{responseTypes:f}=g,{onPaymentSetup:k,onCheckoutFail:h}=b;return(0,t.useEffect)((()=>{h((async e=>{const{processingResponse:t}=e;"ERROR"!==t.paymentDetails.type?(_=e.orderId,u=!0,function e(){r().ajax({type:"POST",url:("wppay_refresh_blik_order_status",woocommerce_params.wc_ajax_url.replace("%%endpoint%%","wppay_refresh_blik_order_status")),data:{order_id:_},dataType:"json",success:function(t){t&&(E(!1),"error"===t.type?(d=t.msg,u=!1):"pending"===t.type?(E(!0),setTimeout((()=>e()),1500),u=!0):"success"===t.type&&(u=!1,window.location.href=t.redirect))}})}(),await async function(){for(;!0===u;)await w(500)}(),t.message=d):(d=t.paymentDetails.message,t.message=t.paymentDetails.message)}))}),[h]),(0,t.useEffect)((()=>k((()=>""===y?{type:f.ERROR,message:(0,l.__)("Wpisz kod BLIK","pay-wp")}:{type:f.SUCCESS,meta:{paymentMethodData:{blik_code:y,block_checkout:!0}}}))),[k,g.responseTypes.ERROR,g.responseTypes.SUCCESS]),s?(0,t.createElement)(t.Fragment,null,(0,t.createElement)(c,{elementClass:m},(0,o.decodeEntities)(p.description)),(0,t.createElement)("p",{style:{fontWeight:"bold"}},(0,l.__)("Potwierdź transakcję w aplikacji bankowej.","pay-wp"))):(0,t.createElement)(t.Fragment,null,(0,t.createElement)(c,{elementClass:m},(0,o.decodeEntities)(p.description)),(0,t.createElement)(i,{fieldValue:n,onInputCallback:function(e){let t=e.target.value.replace(/[^0-9]/g,"");y=t,a(t)}}))},b={name:m,label:(0,t.createElement)((function({elementClass:e,children:n,paymentIconElement:a}){return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("span",{className:e+"__label"},n),a)}),{elementClass:m+"__label",paymentIconElement:(0,t.createElement)((function({elementClass:e,iconUrl:n}){return(0,t.createElement)("span",{style:{"margin-left":"5px"},className:e+"__logo"},(0,t.createElement)("img",{src:n}))}),{iconUrl:p.icon_url})},(0,o.decodeEntities)(p.label)),content:(0,t.createElement)(E,null),edit:(0,t.createElement)(E,null),canMakePayment:()=>!0,ariaLabel:p.label,paymentMethodId:m,supports:{features:p.supports}};(0,n.registerPaymentMethod)(b)})();