import{i as h,w as y}from"./wait-8f4ae121.js";/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/class p{constructor(){this.copyToClipboard=this.copyToClipboard.bind(this),this.refreshBTCPrice=this.refreshBTCPrice.bind(this)}copyToClipboard(r,c,a){const e=a?c.nextElementSibling:c,n=e.src,o=document.createElement("input"),s=document.getElementById(r),{value:t,innerText:i}=s||{},d=t||i;o.value=d,document.body.appendChild(o),o.select(),document.execCommand("copy"),document.body.removeChild(o),e.src="data:image/svg+xml;base64,"+btoa(`
`),setTimeout(()=>{e.src=n},5e3)}async refreshBTCPrice(){const r=document.querySelector(".icon-refresh");r.classList.add("rotating"),document.getElementsByClassName("btc-value")[0].innerHTML="Refreshing...";try{const c=await getBTCPrice();if(c){const a=document.querySelector('meta[name="currency"]').content;document.getElementsByClassName("btc-value")[0].innerHTML="1 BTC = "+(c||"N/A")+" "+a+", updates in ";const e=(document.querySelector('meta[name="amount"]').content/c).toFixed(10);document.querySelector('input[name="btc_price"]').value=c,document.querySelector('input[name="btc_amount"]').value=e,document.getElementById("btc-amount").textContent=e;const n=document.querySelector('meta[name="btc_address"]').content,o=document.getElementById("qr-code-link"),s=document.getElementById("open-in-wallet-link");o.href=`bitcoin:${n}?amount=${e}`,s.href=`bitcoin:${n}?amount=${e}`,fetchAndDisplayQRCode(e),startTimer(600)}}finally{r.classList.remove("rotating")}}handle(){window.copyToClipboard=this.copyToClipboard,window.refreshBTCPrice=this.refreshBTCPrice;const r=e=>{const n=new Date().getTime()+e*1e3;document.getElementById("countdown").innerHTML="10:00 min";const o=()=>{const s=new Date().getTime(),t=n-s;if(document.getElementsByClassName("btc-value")[0].innerHTML.includes("Refreshing"))return;if(t<0){refreshBTCPrice();return}const d=Math.floor(t%(1e3*60*60)/(1e3*60)),l=Math.floor(t%(1e3*60)/1e3),u=String(d).padStart(2,"0"),w=String(l).padStart(2,"0");document.getElementById("countdown").innerHTML=u+":"+w+" min"};clearInterval(window.countdownInterval),window.countdownInterval=setInterval(o,1e3)},c=()=>{const n=`wss://www.blockonomics.co/payment/${document.querySelector('meta[name="btc_address"]').content}`,o=new WebSocket(n);o.onmessage=function(s){const t=JSON.parse(s.data);console.log("Payment status:",t.status);const i=t.status===0,d=t.status===1;(i||d)&&(document.querySelector('input[name="txid"]').value=t.txid||"",document.getElementById("server-response").submit())}},a=async(e=null)=>{try{const n=document.querySelector('meta[name="btc_address"]').content,s=encodeURIComponent(`bitcoin:${n}?amount=${e||"{{$btc_amount}}"}`),t=await fetch(`/api/v1/get-blockonomics-qr-code?qr_string=${s}`);if(!t.ok)throw new Error(`HTTP error! status: ${t.status}`);const i=await t.text();document.getElementById("qrcode-container").innerHTML=i}catch(n){console.error("Error fetching QR code:",n),document.getElementById("qrcode-container").textContent="Error loading QR code"}};r(600),c(),a()}}function m(){new p().handle(),window.bootBlockonomics=m}h()?m():y("#blockonomics-payment").then(()=>m());