!function(){"use strict";window.przelewy24OneClicks={selectors:{oneClickDeleteButtons:document.querySelectorAll(".account-p24-one-clicks-table button[data-delete]")},params:window.przelewy24OneClicksParams||null,_delegationAttached:!1,init(){console.debug("p24 oneclicks init",this.params),this.oneClickHandleDeleteButtons()},oneClickHandleDeleteButtons(){this._delegationAttached||(this._delegationAttached=!0,console.debug("p24 oneclicks delegate init"),document.addEventListener("click",(e=>{const t=e.target.closest&&e.target.closest("button[data-delete]");if(!t)return;e.preventDefault();try{e.stopPropagation(),e.stopImmediatePropagation&&e.stopImmediatePropagation()}catch(e){}const{id:n,nonce:o}=t.dataset;console.debug("p24 oneclick delete click",{id:n,nonce:o});const a=new FormData;a.append("nonce",o),a.append("id",parseInt(n));const s=window.przelewy24OneClicksParams&&window.przelewy24OneClicksParams.url||null;if(!s)return alert("Unable to delete card: missing endpoint URL"),void console.warn("p24 oneclick delete aborted: missing url",window.przelewy24OneClicksParams);(async()=>{try{const e=await fetch(s,{method:"POST",body:a,credentials:"same-origin"});console.debug("p24 oneclick delete response status",e.status);const t=await e.text();if(console.debug("p24 oneclick delete response text",t),!t){if(e.ok)return window.location.reload();throw new Error("Empty response from server")}let n;try{n=JSON.parse(t)}catch(e){throw new Error("Invalid JSON response")}if(n&&(!0===n.success||"true"===n.success))return window.location.reload();const o=n&&n.data&&n.data.message?n.data.message:"Error while deleting saved card";alert(o)}catch(e){console.warn("p24 oneclick delete error",e),alert(e.message||"Error while deleting saved card")}})()}),{capture:!0}))}},"loading"!==document.readyState?window.przelewy24OneClicks.init():document.addEventListener("DOMContentLoaded",(()=>{window.przelewy24OneClicks.init()}))}();
