(()=>{"use strict";class e{constructor(){this.enabled=!1,this.isEnabled=!1,this.executing=!1}enable(){return this.enabled?Promise.resolve({enabled:!0}):this.execute("enable").then((e=>(this.enabled=e.enabled,this.isEnabled=e.enabled,e)))}getInfo(){if(!this.enabled)throw new Error("Provider must be enabled before calling getInfo");return this.execute("getInfo")}getTransactions(){if(!this.enabled)throw new Error("Provider must be enabled before calling getTransactions");return this.execute("getTransactions")}lnurl(e){if(!this.enabled)throw new Error("Provider must be enabled before calling lnurl");return this.execute("lnurl",{lnurlEncoded:e})}sendPayment(e){if(!this.enabled)throw new Error("Provider must be enabled before calling sendPayment");return this.execute("sendPayment",{paymentRequest:e})}makeInvoice(e){if(!this.enabled)throw new Error("Provider must be enabled before calling makeInvoice");return"object"!=typeof e&&(e={amount:e}),this.execute("makeInvoice",e)}signMessage(e){if(!this.enabled)throw new Error("Provider must be enabled before calling signMessage");return this.execute("signMessage",{message:e})}verifyMessage(e,t){if(!this.enabled)throw new Error("Provider must be enabled before calling verifyMessage");return this.execute("verifyMessage",{signature:e,message:t})}execute(e,t){return new Promise(((n,r)=>{window.postMessage({application:"LBE",prompt:!0,type:`${e}`,args:t},"*"),window.addEventListener("message",(function e(t){t.data&&t.data.response&&"LBE"===t.data.application&&(t.data.data.error?r(new Error(t.data.data.error)):n(t.data.data.data),window.removeEventListener("message",e))}))}))}}document?(window.webln=new e,window.addEventListener("click",(e=>{const t=e.target;if(!t||!t.closest)return;const n=t.closest('[href^="lightning:" i]'),r=t.closest('[href^="lnurl" i]'),s=t.closest('[href*="lightning=ln" i]');let a,i,l;if(n||s||r){if(e.preventDefault(),n)a=n.getAttribute("href").toLowerCase(),i=a.replace("lightning:","");else if(s){a=s.getAttribute("href");const e=new URL(a),t=new URLSearchParams(e.search);i=t.get("lightning")}else r&&(a=r.getAttribute("href").toLowerCase(),l=a.replace(/^lnurl[pwc]:/i,""));(i||l)&&(i&&i.startsWith("lnurl")&&(l=i.replace(/^lnurl[pwc]:/i,"")),window.webln.enable().then((e=>{if(e.enabled)return l?window.webln.lnurl(l).then((e=>{console.log(e)})).catch((e=>{console.log(e),alert(`Error: ${e.message}`)})):window.webln.sendPayment(i).then((e=>{console.log(e)})).catch((e=>{console.log(e),alert(`Error: ${e.message}`)}))})))}}))):console.warn("Failed to inject WebLN provider")})();