var c=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)};var u=(n,e,t)=>(c(n,e,"read from private field"),t?t.call(n):e.get(n)),a=(n,e,t)=>{if(e.has(n))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(n):e.set(n,t)},g=(n,e,t,o)=>(c(n,e,"write to private field"),o?o.call(n,t):e.set(n,t),t);var d=(n,e,t)=>(c(n,e,"access private method"),t);import{r as x,j as s,t as T,b as k,c as I}from"./assets/axios-047458d6.js";const j=`:host { display: inline-block; } button { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; border: none; border-radius: 24px; color: white; font-weight: bold; cursor: pointer; user-select: none; transition: background 200ms ease-out; overflow: hidden; position: relative; background: #003366; width: 100%; padding: 16px 36px; } button.loading span:first-child { opacity: 0; } button.loading span:last-child { position: absolute; inset: 0; display: flex; justify-content: center; align-items: center; } button:hover { background: #2d7eff; } button:focus { background: #196aee; transition: none; } button:disabled { background: #c5c5c5; color: #878787; cursor: default; } `;function A({payTool:n,data:e,text:t}){const[o,b]=x.useState(!1),[m,f]=x.useState(!1),E=()=>{o||!e||(b(!0),n.init(e).catch(()=>{f(!0),setTimeout(w,2e3)}))},w=()=>{f(!1),b(!1)};return s.jsxs(s.Fragment,{children:[s.jsx("style",{children:j}),s.jsxs("button",{onClick:E,className:T({loading:o}),disabled:!(e!=null&&e.amount),children:[s.jsx("span",{children:t}),o&&s.jsx("span",{children:m?"Error":"Loading..."})]})]})}var h=(n=>(n.WEB="WEB",n.ANDROID="ANDROID",n.IOS="IOS",n.FLUTTER="FLUTTER",n.REACT_NATIVE="REACT_NATIVE",n.API="API",n))(h||{});function R(n,e){return n&&Object.values(h).includes(n)?n:e}class y{async init({apiKey:e,...t}){const o=await k.post("transactions/pre-initialization",{...t,source:R(t==null?void 0:t.source,h.WEB)},{headers:{"api-key":e}});t!=null&&t.openInNewTab?window.open(`https://paytool-dev.fenige.pl/${o.data.transactionId}`,"_blank"):location.href=`https://paytool-dev.fenige.pl/${o.data.transactionId}`}}var l,i,r,p;class v extends HTMLElement{constructor(){super();a(this,r);a(this,l,new y);a(this,i,void 0);this.attachShadow({mode:"open"})}get text(){return this.getAttribute("text")||"Checkout & Pay"}set text(t){this.setAttribute("text",t)}set data(t){d(this,r,p).call(this,t)}connectedCallback(){g(this,i,I.createRoot(this.shadowRoot)),d(this,r,p).call(this,null)}}l=new WeakMap,i=new WeakMap,r=new WeakSet,p=function(t){const o=this.text;u(this,i).render(s.jsx(A,{payTool:u(this,l),data:t,text:o}))};customElements.get("paytool-button")||customElements.define("paytool-button",v);window.Paytool=y;