@ic-pay/icpay-widget 0.1.76 → 0.1.78

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -57,9 +57,9 @@ var Ie=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var s=(o,a,e
57
57
  0%, 100% { opacity: 1; }
58
58
  50% { opacity: 0.7; }
59
59
  }
60
- `;function ee(o,a){if(!o||!a)return;let e=a.primaryColor||void 0,t=a.secondaryColor||void 0,i=(I,E)=>{E&&o.style.setProperty(I,E)};i("--icpay-primary",e),i("--icpay-secondary",t);let r=I=>{if(!I)return null;let E=I.replace("#",""),le=E.length===3?E.split("").map(Le=>Le+Le).join(""):E,ce=parseInt(le,16),de=ce>>16&255,Oe=ce>>8&255,Ne=ce&255;return{r:de,g:Oe,b:Ne}},g=(I=>{let E=r(I);if(!E)return 0;let le=ce=>{let de=ce/255;return de<=.03928?de/12.92:Math.pow((de+.055)/1.055,2.4)};return .2126*le(E.r)+.7152*le(E.g)+.0722*le(E.b)})(e||t)>.6,w=a.surfaceColor||(g?"#f3f4f6":"#1f2937"),H=a.surfaceAltColor||(g?"#e5e7eb":"#374151"),he=a.borderColor||(g?"#d1d5db":"#4b5563"),N=a.textColor||(g?"#111827":"#f9fafb"),J=a.accentColor||t||e||(g?"#6b7280":"#9ca3af"),ae=a.mutedTextColor||(g?"#6b7280":"#9ca3af");i("--icpay-accent",J),i("--icpay-text",N),i("--icpay-muted",ae),i("--icpay-surface",w),i("--icpay-surface-alt",H),i("--icpay-border",he)}import{Icpay as Ce}from"@ic-pay/icpay-sdk";var Ae=typeof window<"u";function fe(o,a,e){o&&(e!==void 0?console.log(`[ICPay Widget] ${a}`,e):console.log(`[ICPay Widget] ${a}`))}function c(o){if(!Ae)return{client:{},quoteUsd:async()=>({tokenAmountDecimals:"0"}),sendUsd:async()=>({transactionId:"0",status:"pending"})};fe(o.debug||!1,"Creating SDK with config:",o);let a={publishableKey:o.publishableKey};o.enableEvents!==void 0?a.enableEvents=o.enableEvents:a.enableEvents=!0,o.apiUrl&&(a.apiUrl=o.apiUrl),o.icHost&&(a.icHost=o.icHost),o.actorProvider&&(a.actorProvider=o.actorProvider),o.connectedWallet&&(a.connectedWallet=o.connectedWallet),o.debug!==void 0&&(a.debug=o.debug),fe(o.debug||!1,"Filtered SDK config:",a);try{fe(o.debug||!1,"typeof Icpay:",typeof Ce);let e=new Ce(a);if(Ae){let r=e,n=l=>{r.addEventListener(l,g=>{window.dispatchEvent(new CustomEvent(l,{detail:g?.detail??g}))})};["icpay-sdk-error","icpay-sdk-transaction-created","icpay-sdk-transaction-updated","icpay-sdk-transaction-completed","icpay-sdk-transaction-failed","icpay-sdk-method-start","icpay-sdk-method-success","icpay-sdk-method-error"].forEach(n)}async function t(r,n){return e.calculateTokenAmountFromUSD({usdAmount:r,ledgerCanisterId:n})}async function i(r,n,l){return e.sendFundsUsd({usdAmount:r,ledgerCanisterId:n,metadata:l})}return{client:e,quoteUsd:t,sendUsd:i}}catch(e){throw fe(o.debug||!1,"Error creating SDK:",e),e}}import{LitElement as Be,html as z,css as He}from"lit";import{customElement as qe,property as Ge,state as U}from"lit/decorators.js";import{IcpayError as Me}from"@ic-pay/icpay-sdk";var x={WALLET_NOT_CONNECTED:"WALLET_NOT_CONNECTED",WALLET_USER_CANCELLED:"WALLET_USER_CANCELLED",WALLET_SIGNATURE_REJECTED:"WALLET_SIGNATURE_REJECTED",INSUFFICIENT_BALANCE:"INSUFFICIENT_BALANCE",NETWORK_ERROR:"NETWORK_ERROR",API_ERROR:"API_ERROR",LEDGER_NOT_FOUND:"LEDGER_NOT_FOUND",TRANSACTION_FAILED:"TRANSACTION_FAILED",TRANSACTION_TIMEOUT:"TRANSACTION_TIMEOUT",UNKNOWN_ERROR:"UNKNOWN_ERROR"},Te={onError:o=>{console.error("[ICPay Widget] Error:",o)},onUserCancelled:()=>{console.log("[ICPay Widget] User cancelled the action")},onInsufficientBalance:o=>{console.warn("[ICPay Widget] Insufficient balance:",o.message)},onWalletError:o=>{console.warn("[ICPay Widget] Wallet error:",o.message)},onNetworkError:o=>{console.error("[ICPay Widget] Network error:",o.message)}};function k(o,a=Te){o instanceof Me?(a.onError(o),o.isUserCancelled()?a.onUserCancelled?.():o.isBalanceError()?a.onInsufficientBalance?.(o):o.isWalletError()?a.onWalletError?.(o):o.isNetworkError()&&a.onNetworkError?.(o)):(console.error("[ICPay Widget] Unknown error:",o),a.onError(new Me({code:x.UNKNOWN_ERROR,message:o instanceof Error?o.message:"An unknown error occurred",details:o})))}var Pe={[x.WALLET_NOT_CONNECTED]:"Please connect your wallet to continue",[x.WALLET_USER_CANCELLED]:"User have rejected the transfer",[x.WALLET_SIGNATURE_REJECTED]:"User have rejected the transfer",[x.INSUFFICIENT_BALANCE]:"Insufficient balance for this transaction",[x.NETWORK_ERROR]:"Network error. Please try again",[x.API_ERROR]:"Service temporarily unavailable",[x.LEDGER_NOT_FOUND]:"Selected token is not supported",[x.TRANSACTION_FAILED]:"Transaction failed. Please try again",[x.TRANSACTION_TIMEOUT]:"Transaction timed out. Please try again",[x.UNKNOWN_ERROR]:"Something went wrong. Please try again"};function W(o){return Pe[o.code]||o.message||"An error occurred"}function $(o){return!o.isUserCancelled()}function L(o){if(o.userAction)return o.userAction;switch(o.code){case x.WALLET_NOT_CONNECTED:return"Connect Wallet";case x.INSUFFICIENT_BALANCE:return"Add Funds";case x.NETWORK_ERROR:case x.API_ERROR:return"Try Again";default:return null}}function C(o){return o.isUserCancelled()?"info":o.isBalanceError()||o.isWalletError()?"warning":"error"}import{LitElement as je,html as y,css as De}from"lit";import{customElement as Fe,property as te,state as T}from"lit/decorators.js";var _e=[{key:"init",label:"Initialising icpay SDK",tooltip:"Initializing payment",status:"pending"},{key:"await",label:"Awaiting payment confirmation",tooltip:"Preparing payment",status:"pending"},{key:"transfer",label:"Transferring funds",tooltip:"Submitting payment",status:"pending"},{key:"verify",label:"Verifying payment",tooltip:"Confirming payment",status:"pending"},{key:"confirm",label:"Payment confirmed",tooltip:"Payment completed",status:"pending"}],d=class extends je{constructor(){super(...arguments);this.open=!1;this.steps=_e;this.amount=0;this.currency="";this.ledgerSymbol="";this.activeIndex=0;this.completed=!1;this.failed=!1;this.errorMessage=null;this.showSuccess=!1;this.showConfetti=!1;this.currentSteps=[];this.currentAmount=0;this.currentCurrency="";this.currentLedgerSymbol="";this.progressionTimer=null;this.onMethodStart=e=>{let t=e?.detail?.name||"",i=e?.detail?.type||"";console.log("ICPay Progress: Method start event received:",e.detail),(t==="sendFunds"||t==="sendFundsUsd"||t==="sendUsd"||t==="pay"||t==="unlock"||t==="tip"||t==="donate"||t==="order")&&(this.open=!0,this.activeIndex=0,this.completed=!1,this.failed=!1,this.errorMessage=null,this.showSuccess=!1,this.showConfetti=!1,this.currentSteps=this.currentSteps.map(r=>({...r,status:"pending"})),this.updateStepStatus(0,"loading"),e?.detail?.amount!==void 0&&(this.currentAmount=e.detail.amount,this.amount=e.detail.amount,console.log("ICPay Progress: Amount updated to:",e.detail.amount)),e?.detail?.currency&&(this.currentCurrency=e.detail.currency,this.currency=e.detail.currency,console.log("ICPay Progress: Currency updated to:",e.detail.currency)),e?.detail?.ledgerSymbol&&(this.currentLedgerSymbol=e.detail.ledgerSymbol,this.ledgerSymbol=e.detail.ledgerSymbol,console.log("ICPay Progress: Current state after method start:",{activeIndex:this.activeIndex,currentAmount:this.currentAmount,currentCurrency:this.currentCurrency,currentLedgerSymbol:this.currentLedgerSymbol})),console.log("ICPay Progress: Waiting for wallet confirmation before starting progression"),this.requestUpdate())};this.onMethodSuccess=e=>{let t=e?.detail?.name||"";(t==="sendFunds"||t==="sendFundsUsd"||t==="sendUsd"||t==="pay"||t==="unlock"||t==="tip"||t==="donate"||t==="order")&&this.dispatchEvent(new CustomEvent("icpay-progress-method-success",{detail:{methodName:t,step:this.activeIndex},bubbles:!0}))};this.onTransactionCreated=e=>{let t=e?.detail?.transactionId||e?.detail?.id;console.log("ICPay Progress: Transaction created event received:",e.detail),this.dispatchEvent(new CustomEvent("icpay-progress-transaction-created",{detail:{transactionId:t,step:this.activeIndex},bubbles:!0}))};this.onTransactionUpdated=e=>{let t=e?.detail?.status||"pending",i=e?.detail?.transactionId||e?.detail?.id;console.log("ICPay Progress: Transaction updated event received:",e.detail),this.dispatchEvent(new CustomEvent("icpay-progress-transaction-updated",{detail:{status:t,transactionId:i,step:this.activeIndex},bubbles:!0}))};this.onTransactionCompleted=e=>{let t=e?.detail?.transactionId||e?.detail?.id,i=e?.detail?.status||"completed";console.log("ICPay Progress: Transaction completed event received:",e.detail),console.log("ICPay Progress: Current state when transaction completed:",{activeIndex:this.activeIndex,completed:this.completed,failed:this.failed,showSuccess:this.showSuccess}),this.stopAutomaticProgression();for(let r=this.activeIndex;r<this.currentSteps.length;r++)this.updateStepStatus(r,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0,this.dispatchEvent(new CustomEvent("icpay-progress-completed",{detail:{transactionId:t,status:i,amount:this.currentAmount||this.amount,currency:this.currentCurrency||this.currency,ledgerSymbol:this.currentLedgerSymbol||this.ledgerSymbol},bubbles:!0})),setTimeout(()=>{this.open&&this.showSuccess&&!this.failed&&(this.open=!1)},2e3),setTimeout(()=>{this.showConfetti=!1},3e3)};this.onTransactionFailed=e=>{let t=e?.detail?.message||e?.detail?.error?.message||"Transaction failed",i=e?.detail?.error?.code||e?.detail?.code||"UNKNOWN_ERROR",r=e?.detail?.transactionId||e?.detail?.id;console.log("ICPay Progress: Transaction failed event received:",e.detail),this.failed=!0,this.errorMessage=this.transformErrorMessage(t),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",t),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-failed",{detail:{errorMessage:t,errorCode:i,transactionId:r,step:this.activeIndex},bubbles:!0}))};this.onMethodError=e=>{let t=e?.detail?.name||"",i=e?.detail?.error?.message||e?.detail?.message||"An error occurred",r=e?.detail?.error?.code||e?.detail?.code||"METHOD_ERROR";console.log("ICPay Progress: Method error event received:",e.detail),(t?.startsWith("sendFunds")||t==="sendUsd"||t==="pay"||t==="unlock"||t==="tip"||t==="donate"||t==="order")&&(this.failed=!0,this.errorMessage=this.transformErrorMessage(i),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",i),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-error",{detail:{methodName:t,errorMessage:i,errorCode:r,step:this.activeIndex},bubbles:!0})))};this.onSDKError=e=>{let t=e?.detail?.message||"SDK error occurred",i=e?.detail?.code||"SDK_ERROR";console.log("ICPay Progress: SDK error event received:",e.detail),this.failed=!0,this.errorMessage=this.transformErrorMessage(t),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",t),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-sdk-error",{detail:{errorMessage:t,errorCode:i,step:this.activeIndex},bubbles:!0}))};this.onWalletConnected=e=>{let t=e?.detail?.walletType||"unknown";console.log("ICPay Progress: Wallet connected event received:",e.detail),this.updateStepStatus(0,"completed"),this.startAutomaticProgression(),this.dispatchEvent(new CustomEvent("icpay-progress-wallet-connected",{detail:{walletType:t,step:this.activeIndex},bubbles:!0}))};this.onWalletDisconnected=e=>{let t=e?.detail?.walletType||"unknown";console.log("ICPay Progress: Wallet disconnected event received:",e.detail),this.dispatchEvent(new CustomEvent("icpay-progress-wallet-disconnected",{detail:{walletType:t,step:this.activeIndex},bubbles:!0}))};this.onBalanceCheck=e=>{let t=e?.detail?.hasBalance||!1,i=e?.detail?.balance||0;console.log("ICPay Progress: Balance check event received:",e.detail),t||(this.failed=!0,this.errorMessage="Insufficient balance for transaction",this.updateStepStatus(this.activeIndex,"error","Insufficient balance for transaction"),this.stopAutomaticProgression(),this.dispatchEvent(new CustomEvent("icpay-progress-insufficient-balance",{detail:{balance:i,required:this.currentAmount||this.amount,step:this.activeIndex},bubbles:!0})))};this.onLedgerVerified=e=>{let t=e?.detail?.ledgerId||e?.detail?.canisterId,i=e?.detail?.symbol||"unknown";console.log("ICPay Progress: Ledger verified event received:",e.detail),i&&i!=="unknown"&&(this.currentLedgerSymbol=i,this.ledgerSymbol=i),this.dispatchEvent(new CustomEvent("icpay-progress-ledger-verified",{detail:{ledgerId:t,symbol:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetPayment=e=>{let t=e?.detail?.amount,i=e?.detail?.currency,r=e?.detail?.ledgerSymbol;console.log("ICPay Progress: Widget payment event received:",e.detail),t!==void 0&&(this.currentAmount=t,this.amount=t),i&&(this.currentCurrency=i,this.currency=i),r&&(this.currentLedgerSymbol=r,this.ledgerSymbol=r),this.dispatchEvent(new CustomEvent("icpay-progress-widget-payment",{detail:{amount:t,currency:i,ledgerSymbol:r,step:this.activeIndex},bubbles:!0}))};this.onWidgetError=e=>{let t=e?.detail?.message||"Widget error occurred",i=e?.detail?.code||"WIDGET_ERROR";console.log("ICPay Progress: Widget error event received:",e.detail),this.failed=!0,this.errorMessage=this.transformErrorMessage(t),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",t),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-widget-error",{detail:{errorMessage:t,errorCode:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetUnlock=e=>{let t=e?.detail?.amount,i=e?.detail?.currency;console.log("ICPay Progress: Widget unlock event received:",e.detail),this.dispatchEvent(new CustomEvent("icpay-progress-widget-unlock",{detail:{amount:t,currency:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetTip=e=>{let t=e?.detail?.amount,i=e?.detail?.currency;console.log("ICPay Progress: Widget tip event received:",e.detail),this.dispatchEvent(new CustomEvent("icpay-progress-widget-tip",{detail:{amount:t,currency:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetDonation=e=>{let t=e?.detail?.amount,i=e?.detail?.currency;console.log("ICPay Progress: Widget donation event received:",e.detail),this.dispatchEvent(new CustomEvent("icpay-progress-widget-donation",{detail:{amount:t,currency:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetCoffee=e=>{let t=e?.detail?.amount,i=e?.detail?.currency;console.log("ICPay Progress: Widget coffee event received:",e.detail),this.dispatchEvent(new CustomEvent("icpay-progress-widget-coffee",{detail:{amount:t,currency:i,step:this.activeIndex},bubbles:!0}))}}connectedCallback(){super.connectedCallback();try{ee(this,this.theme)}catch{}this.currentSteps=[...this.steps],this.currentAmount=this.amount,this.currentCurrency=this.currency,this.currentLedgerSymbol=this.ledgerSymbol,this.attachSDKEventListeners()}disconnectedCallback(){super.disconnectedCallback(),this.detachSDKEventListeners(),this.stopAutomaticProgression()}updated(e){if(e.has("theme"))try{ee(this,this.theme)}catch{}}attachSDKEventListeners(){window.addEventListener("icpay-sdk-method-start",this.onMethodStart),window.addEventListener("icpay-sdk-method-success",this.onMethodSuccess),window.addEventListener("icpay-sdk-method-error",this.onMethodError),window.addEventListener("icpay-sdk-transaction-created",this.onTransactionCreated),window.addEventListener("icpay-sdk-transaction-updated",this.onTransactionUpdated),window.addEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted),window.addEventListener("icpay-sdk-transaction-failed",this.onTransactionFailed),window.addEventListener("icpay-sdk-error",this.onSDKError),window.addEventListener("icpay-sdk-wallet-connected",this.onWalletConnected),window.addEventListener("icpay-sdk-wallet-disconnected",this.onWalletDisconnected),window.addEventListener("icpay-sdk-balance-check",this.onBalanceCheck),window.addEventListener("icpay-sdk-ledger-verified",this.onLedgerVerified),window.addEventListener("icpay-pay",this.onWidgetPayment),window.addEventListener("icpay-error",this.onWidgetError),window.addEventListener("icpay-unlock",this.onWidgetUnlock),window.addEventListener("icpay-tip",this.onWidgetTip),window.addEventListener("icpay-donation",this.onWidgetDonation),window.addEventListener("icpay-coffee",this.onWidgetCoffee)}detachSDKEventListeners(){window.removeEventListener("icpay-sdk-method-start",this.onMethodStart),window.removeEventListener("icpay-sdk-method-success",this.onMethodSuccess),window.removeEventListener("icpay-sdk-method-error",this.onMethodError),window.removeEventListener("icpay-sdk-transaction-created",this.onTransactionCreated),window.removeEventListener("icpay-sdk-transaction-updated",this.onTransactionUpdated),window.removeEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted),window.removeEventListener("icpay-sdk-transaction-failed",this.onTransactionFailed),window.removeEventListener("icpay-sdk-error",this.onSDKError),window.removeEventListener("icpay-sdk-wallet-connected",this.onWalletConnected),window.removeEventListener("icpay-sdk-wallet-disconnected",this.onWalletDisconnected),window.removeEventListener("icpay-sdk-balance-check",this.onBalanceCheck),window.removeEventListener("icpay-sdk-ledger-verified",this.onLedgerVerified),window.removeEventListener("icpay-pay",this.onWidgetPayment),window.removeEventListener("icpay-error",this.onWidgetError),window.removeEventListener("icpay-unlock",this.onWidgetUnlock),window.removeEventListener("icpay-tip",this.onWidgetTip),window.removeEventListener("icpay-donation",this.onWidgetDonation),window.removeEventListener("icpay-coffee",this.onWidgetCoffee)}startAutomaticProgression(){this.progressionTimer&&clearInterval(this.progressionTimer),this.activeIndex=1,this.updateStepStatus(this.activeIndex,"loading"),console.log("ICPay Progress: Starting automatic progression from step:",this.activeIndex),this.progressionTimer=setInterval(()=>{if(this.failed||this.completed){this.stopAutomaticProgression();return}console.log("ICPay Progress: Processing step:",this.activeIndex),this.updateStepStatus(this.activeIndex,"completed"),this.activeIndex<this.currentSteps.length-1?(this.activeIndex++,this.updateStepStatus(this.activeIndex,"loading"),console.log("ICPay Progress: Auto-progressed to step:",this.activeIndex)):(this.stopAutomaticProgression(),console.log("ICPay Progress: All steps completed, waiting for transaction completion")),this.requestUpdate()},3e3)}stopAutomaticProgression(){this.progressionTimer&&(clearInterval(this.progressionTimer),this.progressionTimer=null)}updateStepStatus(e,t,i){if(e>=0&&e<this.currentSteps.length){let r=this.currentSteps[e],n=r.status;r.status=t,t==="completed"&&(r.timestamp=this.getCurrentTime()),t==="error"&&i&&(r.errorMessage=this.transformErrorMessage(i)),console.log(`ICPay Progress: Step ${e} (${r.label}) status changed from ${n} to ${t}`),this.requestUpdate()}}getCurrentTime(){return new Date().toLocaleTimeString("en-US",{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit"})}progressPercent(){if(this.failed)return 0;if(this.showSuccess)return 100;let t=this.currentSteps.filter(i=>i.status==="completed").length/this.currentSteps.length*100;return Math.max(0,Math.min(100,t))}verticalPercent(){if(this.failed)return 0;if(this.showSuccess)return 100;let t=this.currentSteps.filter(i=>i.status==="completed").length/this.currentSteps.length*100;return Math.max(0,Math.min(100,t))}getStepIcon(e){switch(e.status){case"loading":return y`<div class="spinner"></div>`;case"completed":return"\u2713";case"error":return"\u2717";default:return"\u25CB"}}transformErrorMessage(e){let t=String(e||"").toLowerCase();return t.includes("user rejected")||t.includes("user cancelled")||t.includes("user canceled")||t.includes("signature rejected")?"User have rejected the transfer":e}renderConfetti(){if(!this.showConfetti)return"";let e=Array.from({length:50},(i,r)=>r),t=["#0066FF","#ef4444","#10b981","#f59e0b","#8b5cf6"];return y`
60
+ `;function ee(o,a){if(!o||!a)return;let e=a.primaryColor||void 0,t=a.secondaryColor||void 0,i=(_,E)=>{E&&o.style.setProperty(_,E)};i("--icpay-primary",e),i("--icpay-secondary",t);let r=_=>{if(!_)return null;let E=_.replace("#",""),ce=E.length===3?E.split("").map(Ce=>Ce+Ce).join(""):E,de=parseInt(ce,16),pe=de>>16&255,Oe=de>>8&255,Ne=de&255;return{r:pe,g:Oe,b:Ne}},g=(_=>{let E=r(_);if(!E)return 0;let ce=de=>{let pe=de/255;return pe<=.03928?pe/12.92:Math.pow((pe+.055)/1.055,2.4)};return .2126*ce(E.r)+.7152*ce(E.g)+.0722*ce(E.b)})(e||t)>.6,x=a.surfaceColor||(g?"#f3f4f6":"#1f2937"),Z=a.surfaceAltColor||(g?"#e5e7eb":"#374151"),ae=a.borderColor||(g?"#d1d5db":"#4b5563"),U=a.textColor||(g?"#111827":"#f9fafb"),J=a.accentColor||t||e||(g?"#6b7280":"#9ca3af"),le=a.mutedTextColor||(g?"#6b7280":"#9ca3af");i("--icpay-accent",J),i("--icpay-text",U),i("--icpay-muted",le),i("--icpay-surface",x),i("--icpay-surface-alt",Z),i("--icpay-border",ae)}import{Icpay as Le}from"@ic-pay/icpay-sdk";var Ae=typeof window<"u";function fe(o,a,e){o&&(e!==void 0?console.log(`[ICPay Widget] ${a}`,e):console.log(`[ICPay Widget] ${a}`))}function c(o){if(!Ae)return{client:{},quoteUsd:async()=>({tokenAmountDecimals:"0"}),sendUsd:async()=>({transactionId:"0",status:"pending"})};fe(o.debug||!1,"Creating SDK with config:",o);let a={publishableKey:o.publishableKey};o.enableEvents!==void 0?a.enableEvents=o.enableEvents:a.enableEvents=!0,o.apiUrl&&(a.apiUrl=o.apiUrl),o.icHost&&(a.icHost=o.icHost),o.actorProvider&&(a.actorProvider=o.actorProvider),o.connectedWallet&&(a.connectedWallet=o.connectedWallet),o.debug!==void 0&&(a.debug=o.debug),fe(o.debug||!1,"Filtered SDK config:",a);try{fe(o.debug||!1,"typeof Icpay:",typeof Le);let e=new Le(a);if(Ae){let r=e,n=l=>{r.addEventListener(l,g=>{window.dispatchEvent(new CustomEvent(l,{detail:g?.detail??g}))})};["icpay-sdk-error","icpay-sdk-transaction-created","icpay-sdk-transaction-updated","icpay-sdk-transaction-completed","icpay-sdk-transaction-failed","icpay-sdk-method-start","icpay-sdk-method-success","icpay-sdk-method-error"].forEach(n)}async function t(r,n){return e.calculateTokenAmountFromUSD({usdAmount:r,ledgerCanisterId:n})}async function i(r,n,l){return e.sendFundsUsd({usdAmount:r,ledgerCanisterId:n,metadata:l})}return{client:e,quoteUsd:t,sendUsd:i}}catch(e){throw fe(o.debug||!1,"Error creating SDK:",e),e}}import{LitElement as Be,html as z,css as He}from"lit";import{customElement as qe,property as Ge,state as N}from"lit/decorators.js";import{IcpayError as Me}from"@ic-pay/icpay-sdk";var w={WALLET_NOT_CONNECTED:"WALLET_NOT_CONNECTED",WALLET_USER_CANCELLED:"WALLET_USER_CANCELLED",WALLET_SIGNATURE_REJECTED:"WALLET_SIGNATURE_REJECTED",INSUFFICIENT_BALANCE:"INSUFFICIENT_BALANCE",NETWORK_ERROR:"NETWORK_ERROR",API_ERROR:"API_ERROR",LEDGER_NOT_FOUND:"LEDGER_NOT_FOUND",TRANSACTION_FAILED:"TRANSACTION_FAILED",TRANSACTION_TIMEOUT:"TRANSACTION_TIMEOUT",UNKNOWN_ERROR:"UNKNOWN_ERROR"},Te={onError:o=>{console.error("[ICPay Widget] Error:",o)},onUserCancelled:()=>{console.log("[ICPay Widget] User cancelled the action")},onInsufficientBalance:o=>{console.warn("[ICPay Widget] Insufficient balance:",o.message)},onWalletError:o=>{console.warn("[ICPay Widget] Wallet error:",o.message)},onNetworkError:o=>{console.error("[ICPay Widget] Network error:",o.message)}};function k(o,a=Te){o instanceof Me?(a.onError(o),o.isUserCancelled()?a.onUserCancelled?.():o.isBalanceError()?a.onInsufficientBalance?.(o):o.isWalletError()?a.onWalletError?.(o):o.isNetworkError()&&a.onNetworkError?.(o)):(console.error("[ICPay Widget] Unknown error:",o),a.onError(new Me({code:w.UNKNOWN_ERROR,message:o instanceof Error?o.message:"An unknown error occurred",details:o})))}var Pe={[w.WALLET_NOT_CONNECTED]:"Please connect your wallet to continue",[w.WALLET_USER_CANCELLED]:"User have rejected the transfer",[w.WALLET_SIGNATURE_REJECTED]:"User have rejected the transfer",[w.INSUFFICIENT_BALANCE]:"Insufficient balance for this transaction",[w.NETWORK_ERROR]:"Network error. Please try again",[w.API_ERROR]:"Service temporarily unavailable",[w.LEDGER_NOT_FOUND]:"Selected token is not supported",[w.TRANSACTION_FAILED]:"Transaction failed. Please try again",[w.TRANSACTION_TIMEOUT]:"Transaction timed out. Please try again",[w.UNKNOWN_ERROR]:"Something went wrong. Please try again"};function W(o){return Pe[o.code]||o.message||"An error occurred"}function $(o){return!o.isUserCancelled()}function C(o){if(o.userAction)return o.userAction;switch(o.code){case w.WALLET_NOT_CONNECTED:return"Connect Wallet";case w.INSUFFICIENT_BALANCE:return"Add Funds";case w.NETWORK_ERROR:case w.API_ERROR:return"Try Again";default:return null}}function L(o){return o.isUserCancelled()?"info":o.isBalanceError()||o.isWalletError()?"warning":"error"}import{LitElement as je,html as b,css as De}from"lit";import{customElement as Fe,property as te,state as R}from"lit/decorators.js";var _e=[{key:"wallet",label:"Connect Wallet",tooltip:"Awaiting wallet connection",status:"pending"},{key:"init",label:"Initialising ICPay",tooltip:"Initializing payment",status:"pending"},{key:"await",label:"Awaiting payment confirmation",tooltip:"Preparing payment",status:"pending"},{key:"transfer",label:"Transferring funds",tooltip:"Submitting payment",status:"pending"},{key:"verify",label:"Verifying payment",tooltip:"Confirming payment",status:"pending"},{key:"confirm",label:"Payment confirmed",tooltip:"Payment completed",status:"pending"}],d=class extends je{constructor(){super(...arguments);this.open=!1;this.steps=_e;this.amount=0;this.currency="";this.ledgerSymbol="";this.activeIndex=0;this.completed=!1;this.failed=!1;this.errorMessage=null;this.showSuccess=!1;this.showConfetti=!1;this.currentSteps=[];this.currentAmount=0;this.currentCurrency="";this.currentLedgerSymbol="";this.progressionTimer=null;this.onMethodStart=e=>{let t=e?.detail?.name||"",i=e?.detail?.type||"";console.log("ICPay Progress: Method start event received:",e.detail),(t==="sendFunds"||t==="sendFundsUsd"||t==="sendUsd"||t==="pay"||t==="unlock"||t==="tip"||t==="donate"||t==="order")&&(this.open=!0,this.activeIndex=0,this.completed=!1,this.failed=!1,this.errorMessage=null,this.showSuccess=!1,this.showConfetti=!1,this.currentSteps=this.currentSteps.map(r=>({...r,status:"pending"})),this.updateStepStatus(0,"loading"),e?.detail?.amount!==void 0&&(this.currentAmount=e.detail.amount,this.amount=e.detail.amount,console.log("ICPay Progress: Amount updated to:",e.detail.amount)),e?.detail?.currency&&(this.currentCurrency=e.detail.currency,this.currency=e.detail.currency,console.log("ICPay Progress: Currency updated to:",e.detail.currency)),e?.detail?.ledgerSymbol&&(this.currentLedgerSymbol=e.detail.ledgerSymbol,this.ledgerSymbol=e.detail.ledgerSymbol,console.log("ICPay Progress: Current state after method start:",{activeIndex:this.activeIndex,currentAmount:this.currentAmount,currentCurrency:this.currentCurrency,currentLedgerSymbol:this.currentLedgerSymbol})),console.log("ICPay Progress: Waiting for wallet confirmation before starting progression"),this.requestUpdate())};this.onMethodSuccess=e=>{let t=e?.detail?.name||"";(t==="sendFunds"||t==="sendFundsUsd"||t==="sendUsd"||t==="pay"||t==="unlock"||t==="tip"||t==="donate"||t==="order")&&(this.dispatchEvent(new CustomEvent("icpay-progress-method-success",{detail:{methodName:t,step:this.activeIndex},bubbles:!0})),!this.failed&&!this.completed&&this.currentSteps[this.activeIndex]?.status==="loading"&&(this.updateStepStatus(this.activeIndex,"completed"),this.activeIndex<this.currentSteps.length-1&&(this.activeIndex++,this.updateStepStatus(this.activeIndex,"loading"))))};this.onTransactionCreated=e=>{let t=e?.detail?.transactionId||e?.detail?.id;console.log("ICPay Progress: Transaction created event received:",e.detail),!this.failed&&!this.completed&&this.activeIndex<this.currentSteps.length-1&&(this.updateStepStatus(this.activeIndex,"completed"),this.activeIndex++,this.updateStepStatus(this.activeIndex,"loading")),this.dispatchEvent(new CustomEvent("icpay-progress-transaction-created",{detail:{transactionId:t,step:this.activeIndex},bubbles:!0}))};this.onTransactionUpdated=e=>{let t=e?.detail?.status||"pending",i=e?.detail?.transactionId||e?.detail?.id;console.log("ICPay Progress: Transaction updated event received:",e.detail),!this.failed&&this.completed,this.dispatchEvent(new CustomEvent("icpay-progress-transaction-updated",{detail:{status:t,transactionId:i,step:this.activeIndex},bubbles:!0}))};this.onTransactionCompleted=e=>{let t=e?.detail?.transactionId||e?.detail?.id,i=e?.detail?.status||"completed";console.log("ICPay Progress: Transaction completed event received:",e.detail),console.log("ICPay Progress: Current state when transaction completed:",{activeIndex:this.activeIndex,completed:this.completed,failed:this.failed,showSuccess:this.showSuccess}),this.stopAutomaticProgression();for(let r=this.activeIndex;r<this.currentSteps.length;r++)this.updateStepStatus(r,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0,this.dispatchEvent(new CustomEvent("icpay-progress-completed",{detail:{transactionId:t,status:i,amount:this.currentAmount||this.amount,currency:this.currentCurrency||this.currency,ledgerSymbol:this.currentLedgerSymbol||this.ledgerSymbol},bubbles:!0})),setTimeout(()=>{this.open&&this.showSuccess&&!this.failed&&(this.open=!1)},2e3),setTimeout(()=>{this.showConfetti=!1},3e3)};this.onTransactionFailed=e=>{let t=e?.detail?.message||e?.detail?.error?.message||"Transaction failed",i=e?.detail?.error?.code||e?.detail?.code||"UNKNOWN_ERROR",r=e?.detail?.transactionId||e?.detail?.id;console.log("ICPay Progress: Transaction failed event received:",e.detail),this.failed=!0,this.errorMessage=this.transformErrorMessage(t),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",t),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-failed",{detail:{errorMessage:t,errorCode:i,transactionId:r,step:this.activeIndex},bubbles:!0}))};this.onMethodError=e=>{let t=e?.detail?.name||"",i=e?.detail?.error?.message||e?.detail?.message||"An error occurred",r=e?.detail?.error?.code||e?.detail?.code||"METHOD_ERROR";console.log("ICPay Progress: Method error event received:",e.detail),(t?.startsWith("sendFunds")||t==="sendUsd"||t==="pay"||t==="unlock"||t==="tip"||t==="donate"||t==="order")&&(this.failed=!0,this.errorMessage=this.transformErrorMessage(i),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",i),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-error",{detail:{methodName:t,errorMessage:i,errorCode:r,step:this.activeIndex},bubbles:!0})))};this.onSDKError=e=>{let t=e?.detail?.message||"SDK error occurred",i=e?.detail?.code||"SDK_ERROR";console.log("ICPay Progress: SDK error event received:",e.detail),this.failed=!0,this.errorMessage=this.transformErrorMessage(t),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",t),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-sdk-error",{detail:{errorMessage:t,errorCode:i,step:this.activeIndex},bubbles:!0}))};this.onWalletConnected=e=>{let t=e?.detail?.walletType||"unknown";console.log("ICPay Progress: Wallet connected event received:",e.detail),this.updateStepStatus(0,"completed"),this.currentSteps[1]&&(this.activeIndex=1,this.updateStepStatus(1,"loading")),this.startAutomaticProgression(),this.dispatchEvent(new CustomEvent("icpay-progress-wallet-connected",{detail:{walletType:t,step:this.activeIndex},bubbles:!0}))};this.onWalletDisconnected=e=>{let t=e?.detail?.walletType||"unknown";console.log("ICPay Progress: Wallet disconnected event received:",e.detail),this.dispatchEvent(new CustomEvent("icpay-progress-wallet-disconnected",{detail:{walletType:t,step:this.activeIndex},bubbles:!0}))};this.onBalanceCheck=e=>{let t=e?.detail?.hasBalance||!1,i=e?.detail?.balance||0;console.log("ICPay Progress: Balance check event received:",e.detail),t||(this.failed=!0,this.errorMessage="Insufficient balance for transaction",this.updateStepStatus(this.activeIndex,"error","Insufficient balance for transaction"),this.stopAutomaticProgression(),this.dispatchEvent(new CustomEvent("icpay-progress-insufficient-balance",{detail:{balance:i,required:this.currentAmount||this.amount,step:this.activeIndex},bubbles:!0})))};this.onLedgerVerified=e=>{let t=e?.detail?.ledgerId||e?.detail?.canisterId,i=e?.detail?.symbol||"unknown";console.log("ICPay Progress: Ledger verified event received:",e.detail),i&&i!=="unknown"&&(this.currentLedgerSymbol=i,this.ledgerSymbol=i),this.dispatchEvent(new CustomEvent("icpay-progress-ledger-verified",{detail:{ledgerId:t,symbol:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetPayment=e=>{let t=e?.detail?.amount,i=e?.detail?.currency,r=e?.detail?.ledgerSymbol;console.log("ICPay Progress: Widget payment event received:",e.detail),t!==void 0&&(this.currentAmount=t,this.amount=t),i&&(this.currentCurrency=i,this.currency=i),r&&(this.currentLedgerSymbol=r,this.ledgerSymbol=r),this.dispatchEvent(new CustomEvent("icpay-progress-widget-payment",{detail:{amount:t,currency:i,ledgerSymbol:r,step:this.activeIndex},bubbles:!0}))};this.onWidgetError=e=>{let t=e?.detail?.message||"Widget error occurred",i=e?.detail?.code||"WIDGET_ERROR";console.log("ICPay Progress: Widget error event received:",e.detail),this.failed=!0,this.errorMessage=this.transformErrorMessage(t),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",t),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-widget-error",{detail:{errorMessage:t,errorCode:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetUnlock=e=>{let t=e?.detail?.amount,i=e?.detail?.currency;console.log("ICPay Progress: Widget unlock event received:",e.detail),this.dispatchEvent(new CustomEvent("icpay-progress-widget-unlock",{detail:{amount:t,currency:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetTip=e=>{let t=e?.detail?.amount,i=e?.detail?.currency;console.log("ICPay Progress: Widget tip event received:",e.detail),this.dispatchEvent(new CustomEvent("icpay-progress-widget-tip",{detail:{amount:t,currency:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetDonation=e=>{let t=e?.detail?.amount,i=e?.detail?.currency;console.log("ICPay Progress: Widget donation event received:",e.detail),this.dispatchEvent(new CustomEvent("icpay-progress-widget-donation",{detail:{amount:t,currency:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetCoffee=e=>{let t=e?.detail?.amount,i=e?.detail?.currency;console.log("ICPay Progress: Widget coffee event received:",e.detail),this.dispatchEvent(new CustomEvent("icpay-progress-widget-coffee",{detail:{amount:t,currency:i,step:this.activeIndex},bubbles:!0}))}}connectedCallback(){super.connectedCallback();try{ee(this,this.theme)}catch{}this.currentSteps=[...this.steps],this.currentAmount=this.amount,this.currentCurrency=this.currency,this.currentLedgerSymbol=this.ledgerSymbol,this.attachSDKEventListeners()}disconnectedCallback(){super.disconnectedCallback(),this.detachSDKEventListeners(),this.stopAutomaticProgression()}updated(e){if(e.has("theme"))try{ee(this,this.theme)}catch{}}attachSDKEventListeners(){window.addEventListener("icpay-sdk-method-start",this.onMethodStart),window.addEventListener("icpay-sdk-method-success",this.onMethodSuccess),window.addEventListener("icpay-sdk-method-error",this.onMethodError),window.addEventListener("icpay-sdk-transaction-created",this.onTransactionCreated),window.addEventListener("icpay-sdk-transaction-updated",this.onTransactionUpdated),window.addEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted),window.addEventListener("icpay-sdk-transaction-failed",this.onTransactionFailed),window.addEventListener("icpay-sdk-error",this.onSDKError),window.addEventListener("icpay-sdk-wallet-connected",this.onWalletConnected),window.addEventListener("icpay-sdk-wallet-disconnected",this.onWalletDisconnected),window.addEventListener("icpay-sdk-balance-check",this.onBalanceCheck),window.addEventListener("icpay-sdk-ledger-verified",this.onLedgerVerified),window.addEventListener("icpay-pay",this.onWidgetPayment),window.addEventListener("icpay-error",this.onWidgetError),window.addEventListener("icpay-unlock",this.onWidgetUnlock),window.addEventListener("icpay-tip",this.onWidgetTip),window.addEventListener("icpay-donation",this.onWidgetDonation),window.addEventListener("icpay-coffee",this.onWidgetCoffee)}detachSDKEventListeners(){window.removeEventListener("icpay-sdk-method-start",this.onMethodStart),window.removeEventListener("icpay-sdk-method-success",this.onMethodSuccess),window.removeEventListener("icpay-sdk-method-error",this.onMethodError),window.removeEventListener("icpay-sdk-transaction-created",this.onTransactionCreated),window.removeEventListener("icpay-sdk-transaction-updated",this.onTransactionUpdated),window.removeEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted),window.removeEventListener("icpay-sdk-transaction-failed",this.onTransactionFailed),window.removeEventListener("icpay-sdk-error",this.onSDKError),window.removeEventListener("icpay-sdk-wallet-connected",this.onWalletConnected),window.removeEventListener("icpay-sdk-wallet-disconnected",this.onWalletDisconnected),window.removeEventListener("icpay-sdk-balance-check",this.onBalanceCheck),window.removeEventListener("icpay-sdk-ledger-verified",this.onLedgerVerified),window.removeEventListener("icpay-pay",this.onWidgetPayment),window.removeEventListener("icpay-error",this.onWidgetError),window.removeEventListener("icpay-unlock",this.onWidgetUnlock),window.removeEventListener("icpay-tip",this.onWidgetTip),window.removeEventListener("icpay-donation",this.onWidgetDonation),window.removeEventListener("icpay-coffee",this.onWidgetCoffee)}startAutomaticProgression(){this.progressionTimer&&clearInterval(this.progressionTimer),this.activeIndex=1,this.updateStepStatus(this.activeIndex,"loading"),console.log("ICPay Progress: Starting automatic progression from step:",this.activeIndex),this.progressionTimer=setInterval(()=>{if(this.failed||this.completed){this.stopAutomaticProgression();return}console.log("ICPay Progress: Processing step:",this.activeIndex),this.updateStepStatus(this.activeIndex,"completed"),this.activeIndex<this.currentSteps.length-1?(this.activeIndex++,this.updateStepStatus(this.activeIndex,"loading"),console.log("ICPay Progress: Auto-progressed to step:",this.activeIndex)):(this.stopAutomaticProgression(),console.log("ICPay Progress: All steps completed, waiting for transaction completion")),this.requestUpdate()},3e3)}stopAutomaticProgression(){this.progressionTimer&&(clearInterval(this.progressionTimer),this.progressionTimer=null)}updateStepStatus(e,t,i){if(e>=0&&e<this.currentSteps.length){let r=this.currentSteps[e],n=r.status;r.status=t,t==="completed"&&(r.timestamp=this.getCurrentTime()),t==="error"&&i&&(r.errorMessage=this.transformErrorMessage(i)),console.log(`ICPay Progress: Step ${e} (${r.label}) status changed from ${n} to ${t}`),this.requestUpdate()}}getCurrentTime(){return new Date().toLocaleTimeString("en-US",{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit"})}progressPercent(){if(this.failed)return 0;if(this.showSuccess)return 100;let t=this.currentSteps.filter(i=>i.status==="completed").length/this.currentSteps.length*100;return Math.max(0,Math.min(100,t))}verticalPercent(){if(this.failed)return 0;if(this.showSuccess)return 100;let t=this.currentSteps.filter(i=>i.status==="completed").length/this.currentSteps.length*100;return Math.max(0,Math.min(100,t))}getStepIcon(e){switch(e.status){case"loading":return b`<div class="spinner"></div>`;case"completed":return"\u2713";case"error":return"\u2717";default:return"\u25CB"}}transformErrorMessage(e){let t=String(e||"").toLowerCase();return t.includes("user rejected")||t.includes("user cancelled")||t.includes("user canceled")||t.includes("signature rejected")?"User have rejected the transfer":e}renderConfetti(){if(!this.showConfetti)return"";let e=Array.from({length:50},(i,r)=>r),t=["#0066FF","#ef4444","#10b981","#f59e0b","#8b5cf6"];return b`
61
61
  <div class="confetti">
62
- ${e.map(i=>y`
62
+ ${e.map(i=>b`
63
63
  <div
64
64
  class="confetti-piece"
65
65
  style="
@@ -72,7 +72,7 @@ var Ie=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var s=(o,a,e
72
72
  ></div>
73
73
  `)}
74
74
  </div>
75
- `}renderSuccessState(){let e=this.currentAmount||this.amount,t=this.currentLedgerSymbol||this.currentCurrency||this.currency;return console.log("ICPay Progress: Rendering success state with:",{displayAmount:e,displayCurrency:t,currentAmount:this.currentAmount,amount:this.amount,currentCurrency:this.currentCurrency,currency:this.currency,currentLedgerSymbol:this.currentLedgerSymbol,ledgerSymbol:this.ledgerSymbol}),y`
75
+ `}renderSuccessState(){let e=this.currentAmount||this.amount,t=this.currentLedgerSymbol||this.currentCurrency||this.currency;return console.log("ICPay Progress: Rendering success state with:",{displayAmount:e,displayCurrency:t,currentAmount:this.currentAmount,amount:this.amount,currentCurrency:this.currentCurrency,currency:this.currency,currentLedgerSymbol:this.currentLedgerSymbol,ledgerSymbol:this.ledgerSymbol}),b`
76
76
  <div class="success-container">
77
77
  <div class="success-icon">
78
78
  <svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
@@ -85,7 +85,7 @@ var Ie=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var s=(o,a,e
85
85
  <button class="btn btn-primary" @click=${()=>{this.open=!1}}>Close</button>
86
86
  </div>
87
87
  </div>
88
- `}renderErrorState(){return y`
88
+ `}renderErrorState(){return b`
89
89
  <div class="error-message">
90
90
  <div class="error-icon">⚠</div>
91
91
  <div class="error-content">
@@ -96,22 +96,22 @@ var Ie=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var s=(o,a,e
96
96
  </div>
97
97
  </div>
98
98
  </div>
99
- `}renderProgressContent(){return this.showSuccess?this.renderSuccessState():this.failed?this.renderErrorState():y`
99
+ `}renderProgressContent(){return this.showSuccess?this.renderSuccessState():this.failed?this.renderErrorState():b`
100
100
  <div class="progress-container">
101
101
  <div class="progress-header">
102
102
  <h2 class="progress-title">Processing Payment</h2>
103
103
  <p class="progress-subtitle">Please wait while we process your transaction</p>
104
104
  </div>
105
105
  <div class="progress-steps">
106
- ${this.currentSteps.map((e,t)=>y`
106
+ ${this.currentSteps.map((e,t)=>b`
107
107
  <div class="step ${t===this.activeIndex?"active":""} ${e.status==="completed"?"completed":""}">
108
108
  <div class="step-icon">
109
- ${e.status==="loading"?y`<div class="loading-spinner"></div>`:""}
110
- ${e.status==="completed"?y`
109
+ ${e.status==="loading"?b`<div class="loading-spinner"></div>`:""}
110
+ ${e.status==="completed"?b`
111
111
  <svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
112
112
  <path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" />
113
113
  </svg>
114
- `:y`
114
+ `:b`
115
115
  <svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
116
116
  <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 3v2m6-2v2M9 19v2m6-2v2M5 9H3m2 6H3m18-6h-2m2 6h-2M7 19h10a2 2 0 002-2V7a2 2 0 00-2-2H7a2 2 0 00-2 2v10a2 2 0 002 2zM9 9h6v6H9V9z" />
117
117
  </svg>
@@ -125,7 +125,7 @@ var Ie=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var s=(o,a,e
125
125
  `)}
126
126
  </div>
127
127
  </div>
128
- `}retryTransaction(){this.activeIndex=0,this.completed=!1,this.failed=!1,this.errorMessage=null,this.showSuccess=!1,this.showConfetti=!1,this.currentSteps=this.currentSteps.map(e=>({...e,status:"pending"})),this.updateStepStatus(0,"loading"),this.startAutomaticProgression(),this.requestUpdate()}closeProgress(){this.open=!1}renderStep(e,t){return y`
128
+ `}retryTransaction(){this.activeIndex=0,this.completed=!1,this.failed=!1,this.errorMessage=null,this.showSuccess=!1,this.showConfetti=!1,this.currentSteps=this.currentSteps.map(e=>({...e,status:"pending"})),this.updateStepStatus(0,"loading"),this.startAutomaticProgression(),this.requestUpdate()}closeProgress(){this.open=!1}renderStep(e,t){return b`
129
129
  <div class="step-item ${e.status}">
130
130
  <div class="step-icon">
131
131
  ${this.getStepIcon(e)}
@@ -134,19 +134,19 @@ var Ie=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var s=(o,a,e
134
134
  <div class="step-title">
135
135
  ${e.status==="completed"?"COMPLETED":e.label}
136
136
  </div>
137
- ${e.status==="completed"?y`
137
+ ${e.status==="completed"?b`
138
138
  <div class="step-subtitle">
139
139
  ${e.timestamp} - ${e.tooltip}
140
140
  </div>
141
- `:e.status==="error"&&e.errorMessage?y`
141
+ `:e.status==="error"&&e.errorMessage?b`
142
142
  <div class="step-error">${e.errorMessage}</div>
143
- `:y`
143
+ `:b`
144
144
  <div class="step-subtitle">${e.tooltip}</div>
145
145
  `}
146
146
  </div>
147
147
  </div>
148
- `}render(){return y`
149
- ${this.open?y`
148
+ `}render(){return b`
149
+ ${this.open?b`
150
150
  ${this.renderConfetti()}
151
151
  <div class="modal-overlay active">
152
152
  <div class="modal-container">
@@ -340,26 +340,26 @@ var Ie=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var s=(o,a,e
340
340
  opacity: 0;
341
341
  }
342
342
  }
343
- `,s([te({type:Boolean})],d.prototype,"open",2),s([te({type:Array})],d.prototype,"steps",2),s([te({type:Number})],d.prototype,"amount",2),s([te({type:String})],d.prototype,"currency",2),s([te({type:String})],d.prototype,"ledgerSymbol",2),s([T()],d.prototype,"activeIndex",2),s([T()],d.prototype,"completed",2),s([T()],d.prototype,"failed",2),s([T()],d.prototype,"errorMessage",2),s([T()],d.prototype,"showSuccess",2),s([T()],d.prototype,"showConfetti",2),s([T()],d.prototype,"currentSteps",2),s([T()],d.prototype,"currentAmount",2),s([T()],d.prototype,"currentCurrency",2),s([T()],d.prototype,"currentLedgerSymbol",2),s([te({type:Object})],d.prototype,"theme",2),d=s([Fe("icpay-progress-bar")],d);import{LitElement as ze,html as pe,css as Ke}from"lit";import{customElement as Ve,property as ge}from"lit/decorators.js";var P=class extends ze{constructor(){super(...arguments);this.options=[];this.value=null;this.defaultSymbol="ICP";this.mode="buttons"}connectedCallback(){super.connectedCallback();try{ee(this,this.theme)}catch{}}updated(e){if(e.has("theme"))try{ee(this,this.theme)}catch{}}get effectiveSymbol(){if(this.value)return this.value;let e=this.options?.[0]?.symbol;return this.defaultSymbol||e||"ICP"}onSelect(e){this.value=e,this.dispatchEvent(new CustomEvent("icpay-token-change",{detail:{symbol:e},bubbles:!0,composed:!0}))}render(){let e=this.options||[];if(this.mode==="none"||e.length<=1){let i=e.length===1?e[0].symbol:this.effectiveSymbol;return this.value!==i&&queueMicrotask(()=>this.onSelect(i)),pe``}if(this.mode==="dropdown"){let i=this.effectiveSymbol;return pe`
343
+ `,s([te({type:Boolean})],d.prototype,"open",2),s([te({type:Array})],d.prototype,"steps",2),s([te({type:Number})],d.prototype,"amount",2),s([te({type:String})],d.prototype,"currency",2),s([te({type:String})],d.prototype,"ledgerSymbol",2),s([R()],d.prototype,"activeIndex",2),s([R()],d.prototype,"completed",2),s([R()],d.prototype,"failed",2),s([R()],d.prototype,"errorMessage",2),s([R()],d.prototype,"showSuccess",2),s([R()],d.prototype,"showConfetti",2),s([R()],d.prototype,"currentSteps",2),s([R()],d.prototype,"currentAmount",2),s([R()],d.prototype,"currentCurrency",2),s([R()],d.prototype,"currentLedgerSymbol",2),s([te({type:Object})],d.prototype,"theme",2),d=s([Fe("icpay-progress-bar")],d);import{LitElement as ze,html as ge,css as Ke}from"lit";import{customElement as Ve,property as ue}from"lit/decorators.js";var T=class extends ze{constructor(){super(...arguments);this.options=[];this.value=null;this.defaultSymbol="ICP";this.mode="buttons"}connectedCallback(){super.connectedCallback();try{ee(this,this.theme)}catch{}}updated(e){if(e.has("theme"))try{ee(this,this.theme)}catch{}}get effectiveSymbol(){if(this.value)return this.value;let e=this.options?.[0]?.symbol;return this.defaultSymbol||e||"ICP"}onSelect(e){this.value=e,this.dispatchEvent(new CustomEvent("icpay-token-change",{detail:{symbol:e},bubbles:!0,composed:!0}))}render(){let e=this.options||[];if(this.mode==="none"||e.length<=1){let i=e.length===1?e[0].symbol:this.effectiveSymbol;return this.value!==i&&queueMicrotask(()=>this.onSelect(i)),ge``}if(this.mode==="dropdown"){let i=this.effectiveSymbol;return ge`
344
344
  <select @change=${r=>this.onSelect(r.target.value)}>
345
- ${e.map(r=>pe`<option value="${r.symbol}" ?selected=${i===r.symbol}>${r.label}<span class="icpay-token-selector-symbol"> (${r.symbol})</span></option>`)}
345
+ ${e.map(r=>ge`<option value="${r.symbol}" ?selected=${i===r.symbol}>${r.label}<span class="icpay-token-selector-symbol"> (${r.symbol})</span></option>`)}
346
346
  </select>
347
- `}let t=this.effectiveSymbol;return pe`
347
+ `}let t=this.effectiveSymbol;return ge`
348
348
  <div class="icpay-token-selector">
349
349
  <label class="label">Select Payment Method</label>
350
350
  <div class="crypto-grid">
351
- ${e.map(i=>pe`
351
+ ${e.map(i=>ge`
352
352
  <div class="crypto-option ${t===i.symbol?"selected":""}" @click=${()=>this.onSelect(i.symbol)}>${i.label}<span class="icpay-token-selector-symbol"> (${i.symbol})</span></div>
353
353
  `)}
354
354
  </div>
355
355
  </div>
356
- `}};P.styles=Ke`
356
+ `}};T.styles=Ke`
357
357
  :host { display: block; }
358
358
  .crypto-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 16px; }
359
359
  .crypto-option { background: var(--icpay-surface-alt); border: 2px solid var(--icpay-border); border-radius: 12px; padding: 12px 8px; text-align: center; cursor: pointer; color: var(--icpay-text); font-weight: 600; font-size: 12px; }
360
360
  .crypto-option.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }
361
361
  select { background: var(--icpay-surface-alt); border: 1px solid var(--icpay-border); color: var(--icpay-text); border-radius: 8px; padding: 10px; font-weight: 600; }
362
- `,s([ge({type:Array})],P.prototype,"options",2),s([ge({type:String})],P.prototype,"value",2),s([ge({type:String})],P.prototype,"defaultSymbol",2),s([ge({type:String})],P.prototype,"mode",2),s([ge({type:Object})],P.prototype,"theme",2),P=s([Ve("icpay-token-selector")],P);var ye=typeof window<"u",ie=null;function q(o,a,e){o&&(e!==void 0?console.log(`[ICPay Widget] ${a}`,e):console.log(`[ICPay Widget] ${a}`))}var b=class extends Be{constructor(){super(...arguments);this.selectedSymbol="ICP";this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;ie||(ie=(await import("@windoge98/plug-n-play")).PNP);let i=new ie(this.config?.plugNPlay||{});this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),ye&&(q(this.config?.debug||!1,"Premium content connected",{config:this.config}),this.tryAutoConnectPNP(),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers())}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null,setTimeout(()=>{t==="pay"&&this.onPay()},0)}}async loadVerifiedLedgers(){if(!(!ye||!this.config?.publishableKey))try{let t=await c(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0]?.symbol||"ICP")}catch(e){console.warn("Failed to load verified ledgers:",e),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol="ICP")}}async onPay(){if(ye&&!(this.processing||this.unlocked)){q(this.config?.debug||!1,"Premium content payment started",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="pay",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){q(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{ie||(ie=(await import("@windoge98/plug-n-play")).PNP),this.pnp=new ie(this.config?.plugNPlay||{});let n=this.pnp.getEnabledWallets();if(q(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="pay",this.showWalletModal=!0;return}catch(n){q(this.config?.debug||!1,"Wallet connection error:",n),this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error";return}}q(this.config?.debug||!1,"Creating SDK for payment");let e=c(this.config),i=this.cryptoOptions.find(n=>n.symbol===this.selectedSymbol).canisterId||await e.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);q(this.config?.debug||!1,"Payment details",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,canisterId:i});let r=await e.sendUsd(this.config.priceUsd,i,{context:"premium-content"});q(this.config?.debug||!1,"Payment completed",{resp:r}),this.unlocked=!0,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:r.transactionId,status:r.status}),this.dispatchEvent(new CustomEvent("icpay-unlock",{detail:{amount:this.config.priceUsd,tx:r},bubbles:!0}))}catch(e){k(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),$(t)&&(this.errorMessage=W(t),this.errorSeverity=C(t),this.errorAction=L(t))}})}finally{this.processing=!1,this.pendingAction=null}}}select(e){this.selectedSymbol=e}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}async connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");let t=await this.pnp.connect(e);if(!!!(t&&(t.connected===!0||t.principal||t.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0,this.config={...this.config,connectedWallet:t,actorProvider:(n,l)=>this.pnp.getActor({canisterId:n,idl:l,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let r=this.pendingAction;this.pendingAction=null,r==="pay"&&setTimeout(()=>this.onPay(),0)}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?z`
362
+ `,s([ue({type:Array})],T.prototype,"options",2),s([ue({type:String})],T.prototype,"value",2),s([ue({type:String})],T.prototype,"defaultSymbol",2),s([ue({type:String})],T.prototype,"mode",2),s([ue({type:Object})],T.prototype,"theme",2),T=s([Ve("icpay-token-selector")],T);var be=typeof window<"u",ie=null;function H(o,a,e){o&&(e!==void 0?console.log(`[ICPay Widget] ${a}`,e):console.log(`[ICPay Widget] ${a}`))}var y=class extends Be{constructor(){super(...arguments);this.selectedSymbol="ICP";this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;ie||(ie=(await import("@windoge98/plug-n-play")).PNP);let i=new ie(this.config?.plugNPlay||{});this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),be&&(H(this.config?.debug||!1,"Premium content connected",{config:this.config}),this.tryAutoConnectPNP(),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers())}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="pay"&&this.onPay()},0)}}async loadVerifiedLedgers(){if(!(!be||!this.config?.publishableKey))try{let t=await c(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0]?.symbol||"ICP")}catch(e){console.warn("Failed to load verified ledgers:",e),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol="ICP")}}async onPay(){if(be&&!(this.processing||this.unlocked)){H(this.config?.debug||!1,"Premium content payment started",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:this.config.priceUsd,currency:this.selectedSymbol}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="pay",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){H(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{ie||(ie=(await import("@windoge98/plug-n-play")).PNP),this.pnp=new ie(this.config?.plugNPlay||{});let n=this.pnp.getEnabledWallets();if(H(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="pay",this.showWalletModal=!0;return}catch(n){H(this.config?.debug||!1,"Wallet connection error:",n),this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error";return}}H(this.config?.debug||!1,"Creating SDK for payment");let e=c(this.config),i=this.cryptoOptions.find(n=>n.symbol===this.selectedSymbol).canisterId||await e.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);H(this.config?.debug||!1,"Payment details",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,canisterId:i});let r=await e.sendUsd(this.config.priceUsd,i,{context:"premium-content"});H(this.config?.debug||!1,"Payment completed",{resp:r}),this.unlocked=!0,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:r.transactionId,status:r.status}),this.dispatchEvent(new CustomEvent("icpay-unlock",{detail:{amount:this.config.priceUsd,tx:r},bubbles:!0}))}catch(e){k(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),$(t)&&(this.errorMessage=W(t),this.errorSeverity=L(t),this.errorAction=C(t))}})}finally{this.processing=!1}}}select(e){this.selectedSymbol=e}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}async connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");let t=await this.pnp.connect(e);if(!!!(t&&(t.connected===!0||t.principal||t.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}this.config={...this.config,connectedWallet:t,actorProvider:(n,l)=>this.pnp.getActor({canisterId:n,idl:l,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let r=this.pendingAction;this.pendingAction=null,r==="pay"&&setTimeout(()=>this.onPay(),0)}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?z`
363
363
  <div class="card section">
364
364
  ${this.config?.progressBar?.enabled!==!1?z`<icpay-progress-bar mode="${this.config?.progressBar?.mode||"modal"}"></icpay-progress-bar>`:null}
365
365
  <div class="image-container">
@@ -414,7 +414,7 @@ var Ie=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var s=(o,a,e
414
414
  </div>
415
415
  `:null})()}
416
416
  </div>
417
- `:z`<div class="card section">Loading...</div>`}};b.styles=[S,He`
417
+ `:z`<div class="card section">Loading...</div>`}};y.styles=[S,He`
418
418
  .image-container {
419
419
  position: relative;
420
420
  border-radius: 16px;
@@ -465,17 +465,17 @@ var Ie=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var s=(o,a,e
465
465
  border-color: rgba(239, 68, 68, 0.3);
466
466
  color: #ef4444;
467
467
  }
468
- `],s([Ge({type:Object})],b.prototype,"config",2),s([U()],b.prototype,"selectedSymbol",2),s([U()],b.prototype,"unlocked",2),s([U()],b.prototype,"succeeded",2),s([U()],b.prototype,"processing",2),s([U()],b.prototype,"availableLedgers",2),s([U()],b.prototype,"errorMessage",2),s([U()],b.prototype,"errorSeverity",2),s([U()],b.prototype,"errorAction",2),s([U()],b.prototype,"walletConnected",2),s([U()],b.prototype,"pendingAction",2),s([U()],b.prototype,"showWalletModal",2),b=s([qe("icpay-premium-content")],b);import{LitElement as Ye,html as j,css as Qe}from"lit";import{customElement as Xe,property as Ze,state as A}from"lit/decorators.js";var me=typeof window<"u",re=null;function G(o,a,e){o&&(e!==void 0?console.log(`[ICPay Widget] ${a}`,e):console.log(`[ICPay Widget] ${a}`))}var u=class extends Ye{constructor(){super(...arguments);this.selectedAmount=1;this.selectedSymbol="ICP";this.total=0;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;re||(re=(await import("@windoge98/plug-n-play")).PNP);let i=new re(this.config?.plugNPlay||{});this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}get amounts(){return this.config?.amountsUsd||[1,5,10]}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),me&&(G(this.config?.debug||!1,"Tip jar connected",{config:this.config}),this.config&&this.config.defaultAmountUsd&&(this.selectedAmount=this.config.defaultAmountUsd),this.tryAutoConnectPNP(),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers(),this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol))}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null,setTimeout(()=>{t==="tip"&&this.tip()},0)}}async loadVerifiedLedgers(){if(!(!me||!this.config?.publishableKey))try{let t=await c(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.config?.cryptoOptions&&this.config.cryptoOptions.length===1&&(this.selectedSymbol=this.config.cryptoOptions[0].symbol),!this.selectedSymbol&&this.availableLedgers.length>0&&(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0].symbol)}catch(e){console.warn("Failed to load verified ledgers:",e),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol="ICP")}}selectAmount(e){this.selectedAmount=e}selectSymbol(e){this.selectedSymbol=e}get fillPercentage(){return Math.min(this.total/50*100,100)}async tip(){if(me&&(G(this.config?.debug||!1,"Tip button clicked!",{config:this.config,processing:this.processing}),!this.processing)){this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="tip",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){G(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{re||(re=(await import("@windoge98/plug-n-play")).PNP),this.pnp=new re(this.config?.plugNPlay||{});let n=this.pnp.getEnabledWallets();if(G(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="tip",this.showWalletModal=!0;return}catch(n){G(this.config?.debug||!1,"Wallet connection error:",n),this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error";return}}G(this.config?.debug||!1,"Creating SDK for payment");let e=c(this.config),i=this.cryptoOptions.find(n=>n.symbol===this.selectedSymbol).canisterId||await e.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);G(this.config?.debug||!1,"Tip payment details",{amount:this.selectedAmount,selectedSymbol:this.selectedSymbol,canisterId:i});let r=await e.sendUsd(this.selectedAmount,i,{context:"tip-jar"});G(this.config?.debug||!1,"Tip payment completed",{resp:r}),this.total+=this.selectedAmount,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:r.transactionId,status:r.status,total:this.total}),this.dispatchEvent(new CustomEvent("icpay-tip",{detail:{amount:this.selectedAmount,tx:r},bubbles:!0}))}catch(e){k(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),$(t)&&(this.errorMessage=W(t),this.errorSeverity=C(t),this.errorAction=L(t))}})}finally{this.processing=!1,this.pendingAction=null}}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}async connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");let t=await this.pnp.connect(e);if(!!!(t&&(t.connected===!0||t.principal||t.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0,this.config={...this.config,connectedWallet:t,actorProvider:(n,l)=>this.pnp.getActor({canisterId:n,idl:l,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let r=this.pendingAction;this.pendingAction=null,r==="tip"&&setTimeout(()=>this.tip(),0)}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?j`
468
+ `],s([Ge({type:Object})],y.prototype,"config",2),s([N()],y.prototype,"selectedSymbol",2),s([N()],y.prototype,"unlocked",2),s([N()],y.prototype,"succeeded",2),s([N()],y.prototype,"processing",2),s([N()],y.prototype,"availableLedgers",2),s([N()],y.prototype,"errorMessage",2),s([N()],y.prototype,"errorSeverity",2),s([N()],y.prototype,"errorAction",2),s([N()],y.prototype,"walletConnected",2),s([N()],y.prototype,"pendingAction",2),s([N()],y.prototype,"showWalletModal",2),y=s([qe("icpay-premium-content")],y);import{LitElement as Ye,html as P,css as Qe}from"lit";import{customElement as Xe,property as Ze,state as A}from"lit/decorators.js";var me=typeof window<"u",re=null;function q(o,a,e){o&&(e!==void 0?console.log(`[ICPay Widget] ${a}`,e):console.log(`[ICPay Widget] ${a}`))}var u=class extends Ye{constructor(){super(...arguments);this.selectedAmount=1;this.selectedSymbol="ICP";this.total=0;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;re||(re=(await import("@windoge98/plug-n-play")).PNP);let i=new re(this.config?.plugNPlay||{});this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}get amounts(){return this.config?.amountsUsd||[1,5,10]}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),me&&(q(this.config?.debug||!1,"Tip jar connected",{config:this.config}),this.config&&this.config.defaultAmountUsd&&(this.selectedAmount=this.config.defaultAmountUsd),this.tryAutoConnectPNP(),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers(),this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol))}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="tip"&&this.tip()},0)}}async loadVerifiedLedgers(){if(!(!me||!this.config?.publishableKey))try{let t=await c(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.config?.cryptoOptions&&this.config.cryptoOptions.length===1&&(this.selectedSymbol=this.config.cryptoOptions[0].symbol),!this.selectedSymbol&&this.availableLedgers.length>0&&(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0].symbol)}catch(e){console.warn("Failed to load verified ledgers:",e),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol="ICP")}}selectAmount(e){this.selectedAmount=e}selectSymbol(e){this.selectedSymbol=e}get fillPercentage(){return Math.min(this.total/50*100,100)}async tip(){if(me&&(q(this.config?.debug||!1,"Tip button clicked!",{config:this.config,processing:this.processing}),!this.processing)){this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"tip",type:"sendUsd",amount:this.selectedAmount,currency:this.selectedSymbol}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="tip",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){q(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{re||(re=(await import("@windoge98/plug-n-play")).PNP),this.pnp=new re(this.config?.plugNPlay||{});let n=this.pnp.getEnabledWallets();if(q(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="tip",this.showWalletModal=!0;return}catch(n){q(this.config?.debug||!1,"Wallet connection error:",n),this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error";return}}q(this.config?.debug||!1,"Creating SDK for payment");let e=c(this.config),i=this.cryptoOptions.find(n=>n.symbol===this.selectedSymbol).canisterId||await e.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);q(this.config?.debug||!1,"Tip payment details",{amount:this.selectedAmount,selectedSymbol:this.selectedSymbol,canisterId:i});let r=await e.sendUsd(this.selectedAmount,i,{context:"tip-jar"});q(this.config?.debug||!1,"Tip payment completed",{resp:r}),this.total+=this.selectedAmount,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:r.transactionId,status:r.status,total:this.total}),this.dispatchEvent(new CustomEvent("icpay-tip",{detail:{amount:this.selectedAmount,tx:r},bubbles:!0}))}catch(e){k(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),$(t)&&(this.errorMessage=W(t),this.errorSeverity=L(t),this.errorAction=C(t))}})}finally{this.processing=!1}}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}async connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");let t=await this.pnp.connect(e);if(!!!(t&&(t.connected===!0||t.principal||t.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}this.config={...this.config,connectedWallet:t,actorProvider:(n,l)=>this.pnp.getActor({canisterId:n,idl:l,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let r=this.pendingAction;this.pendingAction=null,r==="tip"&&setTimeout(()=>this.tip(),0)}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?P`
469
469
  <div class="card section" style="text-align:center;">
470
- ${this.config?.progressBar?.enabled!==!1?j`<icpay-progress-bar mode="${this.config?.progressBar?.mode||"modal"}"></icpay-progress-bar>`:null}
470
+ ${this.config?.progressBar?.enabled!==!1?P`<icpay-progress-bar mode="${this.config?.progressBar?.mode||"modal"}"></icpay-progress-bar>`:null}
471
471
  <div class="jar"><div class="fill" style="height:${this.fillPercentage}%"></div></div>
472
472
  <div class="label">Total Tips: $${this.total}</div>
473
473
 
474
474
  <div class="amounts">
475
- ${this.amounts.map(e=>j`<div class="chip ${this.selectedAmount===e?"selected":""}" @click=${()=>this.selectAmount(e)}>$${e}</div>`)}
475
+ ${this.amounts.map(e=>P`<div class="chip ${this.selectedAmount===e?"selected":""}" @click=${()=>this.selectAmount(e)}>$${e}</div>`)}
476
476
  </div>
477
477
 
478
- ${this.config?.showLedgerDropdown===!0?j`
478
+ ${this.config?.showLedgerDropdown===!0?P`
479
479
  <div>
480
480
  <icpay-token-selector
481
481
  .options=${this.cryptoOptions}
@@ -493,24 +493,24 @@ var Ie=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var s=(o,a,e
493
493
  ${this.succeeded&&this.config?.disableAfterSuccess?"Paid":this.processing?"Processing\u2026":this.config?.buttonLabel?this.config.buttonLabel.replace("{amount}",String(this.selectedAmount)).replace("{symbol}",this.selectedSymbol):`Tip $${this.selectedAmount} with ${this.selectedSymbol}`}
494
494
  </button>
495
495
 
496
- ${this.errorMessage?j`
496
+ ${this.errorMessage?P`
497
497
  <div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
498
498
  ${this.errorMessage}
499
- ${this.errorAction?j`
499
+ ${this.errorAction?P`
500
500
  <button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">
501
501
  ${this.errorAction}
502
502
  </button>
503
503
  `:""}
504
504
  </div>
505
505
  `:""}
506
- ${(()=>{let e=this.pnp?.getEnabledWallets?.()||[];return this.showWalletModal&&this.pnp?j`
506
+ ${(()=>{let e=this.pnp?.getEnabledWallets?.()||[];return this.showWalletModal&&this.pnp?P`
507
507
  <div style="position:fixed;inset:0;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.55);z-index:9999">
508
508
  <div class="card section" style="width:380px;border-radius:12px">
509
509
  <div class="label" style="font-weight:700;margin-bottom:12px;text-align:center">Choose Wallet</div>
510
510
  <div style="display:grid;grid-template-columns:1fr;gap:10px;margin-bottom:12px">
511
- ${e.map(t=>{let i=this.getWalletId(t),r=this.getWalletLabel(t),n=this.getWalletIcon(t);return j`
511
+ ${e.map(t=>{let i=this.getWalletId(t),r=this.getWalletLabel(t),n=this.getWalletIcon(t);return P`
512
512
  <button class="pay-button" style="display:flex;align-items:center;gap:10px;justify-content:center;padding:12px" @click=${()=>this.connectWithWallet(i)}>
513
- ${n?j`<img src="${n}" alt="${r}" style="width:20px;height:20px;border-radius:4px;object-fit:contain;background:transparent" />`:""}
513
+ ${n?P`<img src="${n}" alt="${r}" style="width:20px;height:20px;border-radius:4px;object-fit:contain;background:transparent" />`:""}
514
514
  <span>${r}</span>
515
515
  </button>`})}
516
516
  </div>
@@ -521,7 +521,7 @@ var Ie=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var s=(o,a,e
521
521
  </div>
522
522
  `:null})()}
523
523
  </div>
524
- `:j`<div class="card section">Loading...</div>`}};u.styles=[S,Qe`
524
+ `:P`<div class="card section">Loading...</div>`}};u.styles=[S,Qe`
525
525
  .jar { width: 120px; height: 160px; margin: 0 auto 12px; position: relative; background: linear-gradient(135deg, #374151 0%, #4b5563 100%); border-radius: 0 0 60px 60px; border: 3px solid #6b7280; border-top: 8px solid #6b7280; overflow: hidden; }
526
526
  .fill { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(135deg, #d1d5db 0%, #9ca3af 100%); transition: height 0.8s ease; height: 0%; }
527
527
  .amounts { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin: 12px 0; }
@@ -553,9 +553,9 @@ var Ie=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var s=(o,a,e
553
553
  border-color: rgba(239, 68, 68, 0.3);
554
554
  color: #ef4444;
555
555
  }
556
- `],s([Ze({type:Object})],u.prototype,"config",2),s([A()],u.prototype,"selectedAmount",2),s([A()],u.prototype,"selectedSymbol",2),s([A()],u.prototype,"total",2),s([A()],u.prototype,"processing",2),s([A()],u.prototype,"succeeded",2),s([A()],u.prototype,"availableLedgers",2),s([A()],u.prototype,"errorMessage",2),s([A()],u.prototype,"errorSeverity",2),s([A()],u.prototype,"errorAction",2),s([A()],u.prototype,"walletConnected",2),s([A()],u.prototype,"pendingAction",2),s([A()],u.prototype,"showWalletModal",2),u=s([Xe("icpay-tip-jar")],u);import{LitElement as Je,html as Y,css as et}from"lit";import{customElement as tt,property as be,state as R}from"lit/decorators.js";var ve=typeof window<"u",ne=null;function Q(o,a,e){o&&(e!==void 0?console.log(`[ICPay Widget] ${a}`,e):console.log(`[ICPay Widget] ${a}`))}var p=class extends Je{constructor(){super(...arguments);this.title="Article Title";this.preview="";this.lockedContent="";this.selectedSymbol="ICP";this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;ne||(ne=(await import("@windoge98/plug-n-play")).PNP);let i=new ne(this.config?.plugNPlay||{});this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),ve&&(Q(this.config?.debug||!1,"Article paywall connected",{config:this.config}),this.config&&(typeof this.config.title=="string"&&(this.title=this.config.title),typeof this.config.preview=="string"&&(this.preview=this.config.preview),typeof this.config.lockedContent=="string"&&(this.lockedContent=this.config.lockedContent)),this.tryAutoConnectPNP(),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers())}updated(e){if(e.has("config")&&this.config&&(typeof this.config.title=="string"&&(this.title=this.config.title),typeof this.config.preview=="string"&&(this.preview=this.config.preview),typeof this.config.lockedContent=="string"&&(this.lockedContent=this.config.lockedContent)),e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null,setTimeout(()=>{t==="unlock"&&this.unlock()},0)}}async loadVerifiedLedgers(){if(!(!ve||!this.config?.publishableKey))try{let t=await c(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0]?.symbol||"ICP")}catch(e){console.warn("Failed to load verified ledgers:",e),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol="ICP")}}selectSymbol(e){this.selectedSymbol=e}async unlock(){if(ve&&!(this.processing||this.unlocked)){Q(this.config?.debug||!1,"Article paywall unlock started",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="unlock",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){Q(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{ne||(ne=(await import("@windoge98/plug-n-play")).PNP),this.pnp=new ne(this.config?.plugNPlay||{});let n=this.pnp.getEnabledWallets();if(Q(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="unlock",this.showWalletModal=!0;return}catch(n){Q(this.config?.debug||!1,"Wallet connection error:",n),this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error";return}}Q(this.config?.debug||!1,"Creating SDK for payment");let e=c(this.config),i=this.cryptoOptions.find(n=>n.symbol===this.selectedSymbol).canisterId||await e.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);Q(this.config?.debug||!1,"Article payment details",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,canisterId:i});let r=await e.sendUsd(this.config.priceUsd,i,{context:"article"});Q(this.config?.debug||!1,"Article payment completed",{resp:r}),this.unlocked=!0,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:r.transactionId,status:r.status}),this.dispatchEvent(new CustomEvent("icpay-unlock",{detail:{amount:this.config.priceUsd,tx:r},bubbles:!0}))}catch(e){k(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),$(t)&&(this.errorMessage=W(t),this.errorSeverity=C(t),this.errorAction=L(t))}})}finally{this.processing=!1,this.pendingAction=null}}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}async connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");let t=await this.pnp.connect(e);if(!!!(t&&(t.connected===!0||t.principal||t.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0,this.config={...this.config,connectedWallet:t,actorProvider:(n,l)=>this.pnp.getActor({canisterId:n,idl:l,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let r=this.pendingAction;this.pendingAction=null,r==="unlock"&&setTimeout(()=>this.unlock(),0)}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?Y`
556
+ `],s([Ze({type:Object})],u.prototype,"config",2),s([A()],u.prototype,"selectedAmount",2),s([A()],u.prototype,"selectedSymbol",2),s([A()],u.prototype,"total",2),s([A()],u.prototype,"processing",2),s([A()],u.prototype,"succeeded",2),s([A()],u.prototype,"availableLedgers",2),s([A()],u.prototype,"errorMessage",2),s([A()],u.prototype,"errorSeverity",2),s([A()],u.prototype,"errorAction",2),s([A()],u.prototype,"walletConnected",2),s([A()],u.prototype,"pendingAction",2),s([A()],u.prototype,"showWalletModal",2),u=s([Xe("icpay-tip-jar")],u);import{LitElement as Je,html as G,css as et}from"lit";import{customElement as tt,property as ye,state as I}from"lit/decorators.js";var ve=typeof window<"u",ne=null;function Y(o,a,e){o&&(e!==void 0?console.log(`[ICPay Widget] ${a}`,e):console.log(`[ICPay Widget] ${a}`))}var p=class extends Je{constructor(){super(...arguments);this.title="Article Title";this.preview="";this.lockedContent="";this.selectedSymbol="ICP";this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;ne||(ne=(await import("@windoge98/plug-n-play")).PNP);let i=new ne(this.config?.plugNPlay||{});this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),ve&&(Y(this.config?.debug||!1,"Article paywall connected",{config:this.config}),this.config&&(typeof this.config.title=="string"&&(this.title=this.config.title),typeof this.config.preview=="string"&&(this.preview=this.config.preview),typeof this.config.lockedContent=="string"&&(this.lockedContent=this.config.lockedContent)),this.tryAutoConnectPNP(),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers())}updated(e){if(e.has("config")&&this.config&&(typeof this.config.title=="string"&&(this.title=this.config.title),typeof this.config.preview=="string"&&(this.preview=this.config.preview),typeof this.config.lockedContent=="string"&&(this.lockedContent=this.config.lockedContent)),e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="unlock"&&this.unlock()},0)}}async loadVerifiedLedgers(){if(!(!ve||!this.config?.publishableKey))try{let t=await c(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0]?.symbol||"ICP")}catch(e){console.warn("Failed to load verified ledgers:",e),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol="ICP")}}selectSymbol(e){this.selectedSymbol=e}async unlock(){if(ve&&!(this.processing||this.unlocked)){Y(this.config?.debug||!1,"Article paywall unlock started",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"unlock",type:"sendUsd",amount:this.config.priceUsd,currency:this.selectedSymbol}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="unlock",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){Y(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{ne||(ne=(await import("@windoge98/plug-n-play")).PNP),this.pnp=new ne(this.config?.plugNPlay||{});let n=this.pnp.getEnabledWallets();if(Y(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="unlock",this.showWalletModal=!0;return}catch(n){Y(this.config?.debug||!1,"Wallet connection error:",n),this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error";return}}Y(this.config?.debug||!1,"Creating SDK for payment");let e=c(this.config),i=this.cryptoOptions.find(n=>n.symbol===this.selectedSymbol).canisterId||await e.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);Y(this.config?.debug||!1,"Article payment details",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,canisterId:i});let r=await e.sendUsd(this.config.priceUsd,i,{context:"article"});Y(this.config?.debug||!1,"Article payment completed",{resp:r}),this.unlocked=!0,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:r.transactionId,status:r.status}),this.dispatchEvent(new CustomEvent("icpay-unlock",{detail:{amount:this.config.priceUsd,tx:r},bubbles:!0}))}catch(e){k(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),$(t)&&(this.errorMessage=W(t),this.errorSeverity=L(t),this.errorAction=C(t))}})}finally{this.processing=!1}}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}async connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");let t=await this.pnp.connect(e);if(!!!(t&&(t.connected===!0||t.principal||t.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}this.config={...this.config,connectedWallet:t,actorProvider:(n,l)=>this.pnp.getActor({canisterId:n,idl:l,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let r=this.pendingAction;this.pendingAction=null,r==="unlock"&&setTimeout(()=>this.unlock(),0)}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?G`
557
557
  <div class="card section">
558
- ${this.config?.progressBar?.enabled!==!1?Y`<icpay-progress-bar mode="${this.config?.progressBar?.mode||"modal"}"></icpay-progress-bar>`:null}
558
+ ${this.config?.progressBar?.enabled!==!1?G`<icpay-progress-bar mode="${this.config?.progressBar?.mode||"modal"}"></icpay-progress-bar>`:null}
559
559
  <div class="container">
560
560
  <div class="title">${this.title}</div>
561
561
  <div class="preview">${this.preview}</div>
@@ -578,24 +578,24 @@ var Ie=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var s=(o,a,e
578
578
  ${this.unlocked?"Unlocked":this.processing?"Processing\u2026":(this.config?.buttonLabel||"Pay ${amount} with {symbol}").replace("{amount}",`${Number(this.config?.priceUsd??0).toFixed(2)}`).replace("{symbol}",this.selectedSymbol)}
579
579
  </button>
580
580
 
581
- ${this.errorMessage?Y`
581
+ ${this.errorMessage?G`
582
582
  <div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
583
583
  ${this.errorMessage}
584
- ${this.errorAction?Y`
584
+ ${this.errorAction?G`
585
585
  <button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">
586
586
  ${this.errorAction}
587
587
  </button>
588
588
  `:""}
589
589
  </div>
590
590
  `:""}
591
- ${(()=>{let e=this.pnp?.getEnabledWallets?.()||[];return this.showWalletModal&&this.pnp?Y`
591
+ ${(()=>{let e=this.pnp?.getEnabledWallets?.()||[];return this.showWalletModal&&this.pnp?G`
592
592
  <div style="position:fixed;inset:0;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.55);z-index:9999">
593
593
  <div class="card section" style="width:380px;border-radius:12px">
594
594
  <div class="label" style="font-weight:700;margin-bottom:12px;text-align:center">Choose Wallet</div>
595
595
  <div style="display:grid;grid-template-columns:1fr;gap:10px;margin-bottom:12px">
596
- ${e.map(t=>{let i=this.getWalletId(t),r=this.getWalletLabel(t),n=this.getWalletIcon(t);return Y`
596
+ ${e.map(t=>{let i=this.getWalletId(t),r=this.getWalletLabel(t),n=this.getWalletIcon(t);return G`
597
597
  <button class="pay-button" style="display:flex;align-items:center;gap:10px;justify-content:center;padding:12px" @click=${()=>this.connectWithWallet(i)}>
598
- ${n?Y`<img src="${n}" alt="${r}" style="width:20px;height:20px;border-radius:4px;object-fit:contain;background:transparent" />`:""}
598
+ ${n?G`<img src="${n}" alt="${r}" style="width:20px;height:20px;border-radius:4px;object-fit:contain;background:transparent" />`:""}
599
599
  <span>${r}</span>
600
600
  </button>`})}
601
601
  </div>
@@ -606,7 +606,7 @@ var Ie=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var s=(o,a,e
606
606
  </div>
607
607
  `:null})()}
608
608
  </div>
609
- `:Y`<div class="card section">Loading...</div>`}};p.styles=[S,et`
609
+ `:G`<div class="card section">Loading...</div>`}};p.styles=[S,et`
610
610
  .container { background: var(--icpay-surface-alt); border: 1px solid var(--icpay-border); border-radius: 16px; padding: 16px; margin-bottom: 16px; }
611
611
  .title { color: var(--icpay-text); font-weight: 700; margin-bottom: 8px; }
612
612
  .preview { color: var(--icpay-muted); margin-bottom: 12px; line-height: 1.6; }
@@ -638,7 +638,7 @@ var Ie=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var s=(o,a,e
638
638
  border-color: rgba(239, 68, 68, 0.3);
639
639
  color: #ef4444;
640
640
  }
641
- `],s([be({type:Object})],p.prototype,"config",2),s([be({type:String})],p.prototype,"title",2),s([be({type:String})],p.prototype,"preview",2),s([be({type:String})],p.prototype,"lockedContent",2),s([R()],p.prototype,"selectedSymbol",2),s([R()],p.prototype,"unlocked",2),s([R()],p.prototype,"succeeded",2),s([R()],p.prototype,"processing",2),s([R()],p.prototype,"availableLedgers",2),s([R()],p.prototype,"errorMessage",2),s([R()],p.prototype,"errorSeverity",2),s([R()],p.prototype,"errorAction",2),s([R()],p.prototype,"walletConnected",2),s([R()],p.prototype,"pendingAction",2),s([R()],p.prototype,"showWalletModal",2),p=s([tt("icpay-article-paywall")],p);import{LitElement as it,html as K,css as st}from"lit";import{customElement as rt,property as nt,state as D}from"lit/decorators.js";var xe=typeof window<"u",we=null;function X(o,a,e){o&&(e!==void 0?console.log(`[ICPay Widget] ${a}`,e):console.log(`[ICPay Widget] ${a}`))}var m=class extends it{constructor(){super(...arguments);this.selectedIndex=0;this.selectedSymbol="ICP";this.processing=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),xe&&(X(this.config?.debug||!1,"Coffee shop connected",{config:this.config}),this.config&&typeof this.config.defaultItemIndex=="number"&&(this.selectedIndex=this.config.defaultItemIndex),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers())}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null,setTimeout(()=>{t==="order"&&this.order()},0)}}async loadVerifiedLedgers(){if(!(!xe||!this.config?.publishableKey))try{let t=await c(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.availableLedgers.length>0&&!this.selectedSymbol&&(this.selectedSymbol=this.availableLedgers[0].symbol)}catch(e){console.warn("Failed to load verified ledgers:",e),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol="ICP")}}selectItem(e){this.selectedIndex=e}selectSymbol(e){this.selectedSymbol=e}get selectedItem(){return this.config?.items?.[this.selectedIndex]||{name:"Loading...",priceUsd:0}}async order(){if(xe&&!this.processing){X(this.config?.debug||!1,"Coffee order started",{selectedItem:this.selectedItem,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="order",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){X(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{we||(we=(await import("@windoge98/plug-n-play")).PNP),this.pnp=new we(this.config?.plugNPlay||{});let n=this.pnp.getEnabledWallets();if(X(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="order",this.showWalletModal=!0;return}catch(n){X(this.config?.debug||!1,"Wallet connection error:",n),this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error";return}}X(this.config?.debug||!1,"Creating SDK for payment");let e=c(this.config),i=this.cryptoOptions.find(n=>n.symbol===this.selectedSymbol).canisterId||await e.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);X(this.config?.debug||!1,"Coffee order payment details",{item:this.selectedItem.name,priceUsd:this.selectedItem.priceUsd,selectedSymbol:this.selectedSymbol,canisterId:i});let r=await e.sendUsd(this.selectedItem.priceUsd,i,{context:"coffee",item:this.selectedItem.name});X(this.config?.debug||!1,"Coffee order payment completed",{resp:r}),this.config.onSuccess&&this.config.onSuccess({id:r.transactionId,status:r.status,item:this.selectedItem.name}),this.dispatchEvent(new CustomEvent("icpay-coffee",{detail:{item:this.selectedItem,tx:r},bubbles:!0}))}catch(e){k(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),$(t)&&(this.errorMessage=W(t),this.errorSeverity=C(t),this.errorAction=L(t))}})}finally{this.processing=!1}}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}async connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");let t=await this.pnp.connect(e);if(!!!(t&&(t.connected===!0||t.principal||t.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0,this.config={...this.config,connectedWallet:t,actorProvider:(n,l)=>this.pnp.getActor({canisterId:n,idl:l,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let r=this.pendingAction;this.pendingAction=null,r==="order"&&setTimeout(()=>this.order(),0)}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?K`
641
+ `],s([ye({type:Object})],p.prototype,"config",2),s([ye({type:String})],p.prototype,"title",2),s([ye({type:String})],p.prototype,"preview",2),s([ye({type:String})],p.prototype,"lockedContent",2),s([I()],p.prototype,"selectedSymbol",2),s([I()],p.prototype,"unlocked",2),s([I()],p.prototype,"succeeded",2),s([I()],p.prototype,"processing",2),s([I()],p.prototype,"availableLedgers",2),s([I()],p.prototype,"errorMessage",2),s([I()],p.prototype,"errorSeverity",2),s([I()],p.prototype,"errorAction",2),s([I()],p.prototype,"walletConnected",2),s([I()],p.prototype,"pendingAction",2),s([I()],p.prototype,"showWalletModal",2),p=s([tt("icpay-article-paywall")],p);import{LitElement as it,html as K,css as st}from"lit";import{customElement as rt,property as nt,state as j}from"lit/decorators.js";var we=typeof window<"u",xe=null;function Q(o,a,e){o&&(e!==void 0?console.log(`[ICPay Widget] ${a}`,e):console.log(`[ICPay Widget] ${a}`))}var m=class extends it{constructor(){super(...arguments);this.selectedIndex=0;this.selectedSymbol="ICP";this.processing=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),we&&(Q(this.config?.debug||!1,"Coffee shop connected",{config:this.config}),this.config&&typeof this.config.defaultItemIndex=="number"&&(this.selectedIndex=this.config.defaultItemIndex),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers())}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="order"&&this.order()},0)}}async loadVerifiedLedgers(){if(!(!we||!this.config?.publishableKey))try{let t=await c(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.availableLedgers.length>0&&!this.selectedSymbol&&(this.selectedSymbol=this.availableLedgers[0].symbol)}catch(e){console.warn("Failed to load verified ledgers:",e),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol="ICP")}}selectItem(e){this.selectedIndex=e}selectSymbol(e){this.selectedSymbol=e}get selectedItem(){return this.config?.items?.[this.selectedIndex]||{name:"Loading...",priceUsd:0}}async order(){if(we&&!this.processing){Q(this.config?.debug||!1,"Coffee order started",{selectedItem:this.selectedItem,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"order",type:"sendUsd",amount:this.selectedItem.priceUsd,currency:this.selectedSymbol}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="order",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){Q(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{xe||(xe=(await import("@windoge98/plug-n-play")).PNP),this.pnp=new xe(this.config?.plugNPlay||{});let n=this.pnp.getEnabledWallets();if(Q(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="order",this.showWalletModal=!0;return}catch(n){Q(this.config?.debug||!1,"Wallet connection error:",n),this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error";return}}Q(this.config?.debug||!1,"Creating SDK for payment");let e=c(this.config),i=this.cryptoOptions.find(n=>n.symbol===this.selectedSymbol).canisterId||await e.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);Q(this.config?.debug||!1,"Coffee order payment details",{item:this.selectedItem.name,priceUsd:this.selectedItem.priceUsd,selectedSymbol:this.selectedSymbol,canisterId:i});let r=await e.sendUsd(this.selectedItem.priceUsd,i,{context:"coffee",item:this.selectedItem.name});Q(this.config?.debug||!1,"Coffee order payment completed",{resp:r}),this.config.onSuccess&&this.config.onSuccess({id:r.transactionId,status:r.status,item:this.selectedItem.name}),this.dispatchEvent(new CustomEvent("icpay-coffee",{detail:{item:this.selectedItem,tx:r},bubbles:!0}))}catch(e){k(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),$(t)&&(this.errorMessage=W(t),this.errorSeverity=L(t),this.errorAction=C(t))}})}finally{this.processing=!1}}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}async connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");let t=await this.pnp.connect(e);if(!!!(t&&(t.connected===!0||t.principal||t.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}this.config={...this.config,connectedWallet:t,actorProvider:(n,l)=>this.pnp.getActor({canisterId:n,idl:l,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let r=this.pendingAction;this.pendingAction=null,r==="order"&&setTimeout(()=>this.order(),0)}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?K`
642
642
  <div class="card section">
643
643
  ${this.config?.progressBar?.enabled!==!1?K`<icpay-progress-bar mode="${this.config?.progressBar?.mode||"modal"}"></icpay-progress-bar>`:null}
644
644
  <div class="menu">
@@ -725,7 +725,7 @@ var Ie=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var s=(o,a,e
725
725
  border-color: rgba(239, 68, 68, 0.3);
726
726
  color: #ef4444;
727
727
  }
728
- `],s([nt({type:Object})],m.prototype,"config",2),s([D()],m.prototype,"selectedIndex",2),s([D()],m.prototype,"selectedSymbol",2),s([D()],m.prototype,"processing",2),s([D()],m.prototype,"availableLedgers",2),s([D()],m.prototype,"errorMessage",2),s([D()],m.prototype,"errorSeverity",2),s([D()],m.prototype,"errorAction",2),s([D()],m.prototype,"walletConnected",2),s([D()],m.prototype,"pendingAction",2),s([D()],m.prototype,"showWalletModal",2),m=s([rt("icpay-coffee-shop")],m);import{LitElement as ot,html as V,css as at}from"lit";import{customElement as lt,property as ct,state as M}from"lit/decorators.js";var Ee=typeof window<"u",oe=null;function Z(o,a,e){o&&(e!==void 0?console.log(`[ICPay Widget] ${a}`,e):console.log(`[ICPay Widget] ${a}`))}var h=class extends ot{constructor(){super(...arguments);this.selectedAmount=10;this.selectedSymbol="ICP";this.raised=0;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;oe||(oe=(await import("@windoge98/plug-n-play")).PNP);let i=new oe(this.config?.plugNPlay||{});this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}get amounts(){return this.config?.amountsUsd||[10,25,50,100,250,500]}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),Ee&&(Z(this.config?.debug||!1,"Donation thermometer connected",{config:this.config}),this.config&&typeof this.config.defaultAmountUsd=="number"&&(this.selectedAmount=this.config.defaultAmountUsd),this.tryAutoConnectPNP(),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers())}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null,setTimeout(()=>{t==="donate"&&this.donate()},0)}}async loadVerifiedLedgers(){if(!(!Ee||!this.config?.publishableKey))try{let t=await c(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.availableLedgers.length>0&&!this.selectedSymbol&&(this.selectedSymbol=this.availableLedgers[0].symbol)}catch(e){console.warn("Failed to load verified ledgers:",e),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol="ICP")}}selectAmount(e){this.selectedAmount=e}selectSymbol(e){this.selectedSymbol=e}get fillPercentage(){let e=Number(this.config?.goalUsd??1e3),t=e>0?e:1e3;return Math.min(this.raised/t*100,100)}async donate(){if(Ee&&!this.processing){Z(this.config?.debug||!1,"Donation started",{amount:this.selectedAmount,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="donate",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){Z(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{oe||(oe=(await import("@windoge98/plug-n-play")).PNP),this.pnp=new oe(this.config?.plugNPlay||{});let n=this.pnp.getEnabledWallets();if(Z(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="donate",this.showWalletModal=!0;return}catch(n){Z(this.config?.debug||!1,"Wallet connection error:",n),this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error";return}}Z(this.config?.debug||!1,"Creating SDK for payment");let e=c(this.config),i=this.cryptoOptions.find(n=>n.symbol===this.selectedSymbol).canisterId||await e.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);Z(this.config?.debug||!1,"Donation payment details",{amount:this.selectedAmount,selectedSymbol:this.selectedSymbol,canisterId:i});let r=await e.sendUsd(this.selectedAmount,i,{context:"donation"});Z(this.config?.debug||!1,"Donation payment completed",{resp:r}),this.raised+=this.selectedAmount,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:r.transactionId,status:r.status,raised:this.raised}),this.dispatchEvent(new CustomEvent("icpay-donation",{detail:{amount:this.selectedAmount,tx:r},bubbles:!0}))}catch(e){k(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),$(t)&&(this.errorMessage=W(t),this.errorSeverity=C(t),this.errorAction=L(t))}})}finally{this.processing=!1,this.pendingAction=null}}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}async connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");let t=await this.pnp.connect(e);if(!!!(t&&(t.connected===!0||t.principal||t.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0,this.config={...this.config,connectedWallet:t,actorProvider:(n,l)=>this.pnp.getActor({canisterId:n,idl:l,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let r=this.pendingAction;this.pendingAction=null,r==="donate"&&setTimeout(()=>this.donate(),0)}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?V`
728
+ `],s([nt({type:Object})],m.prototype,"config",2),s([j()],m.prototype,"selectedIndex",2),s([j()],m.prototype,"selectedSymbol",2),s([j()],m.prototype,"processing",2),s([j()],m.prototype,"availableLedgers",2),s([j()],m.prototype,"errorMessage",2),s([j()],m.prototype,"errorSeverity",2),s([j()],m.prototype,"errorAction",2),s([j()],m.prototype,"walletConnected",2),s([j()],m.prototype,"pendingAction",2),s([j()],m.prototype,"showWalletModal",2),m=s([rt("icpay-coffee-shop")],m);import{LitElement as ot,html as V,css as at}from"lit";import{customElement as lt,property as ct,state as M}from"lit/decorators.js";var Ee=typeof window<"u",oe=null;function X(o,a,e){o&&(e!==void 0?console.log(`[ICPay Widget] ${a}`,e):console.log(`[ICPay Widget] ${a}`))}var h=class extends ot{constructor(){super(...arguments);this.selectedAmount=10;this.selectedSymbol="ICP";this.raised=0;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;oe||(oe=(await import("@windoge98/plug-n-play")).PNP);let i=new oe(this.config?.plugNPlay||{});this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}get amounts(){return this.config?.amountsUsd||[10,25,50,100,250,500]}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),Ee&&(X(this.config?.debug||!1,"Donation thermometer connected",{config:this.config}),this.config&&typeof this.config.defaultAmountUsd=="number"&&(this.selectedAmount=this.config.defaultAmountUsd),this.tryAutoConnectPNP(),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers())}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="donate"&&this.donate()},0)}}async loadVerifiedLedgers(){if(!(!Ee||!this.config?.publishableKey))try{let t=await c(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.availableLedgers.length>0&&!this.selectedSymbol&&(this.selectedSymbol=this.availableLedgers[0].symbol)}catch(e){console.warn("Failed to load verified ledgers:",e),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol="ICP")}}selectAmount(e){this.selectedAmount=e}selectSymbol(e){this.selectedSymbol=e}get fillPercentage(){let e=Number(this.config?.goalUsd??1e3),t=e>0?e:1e3;return Math.min(this.raised/t*100,100)}async donate(){if(Ee&&!this.processing){X(this.config?.debug||!1,"Donation started",{amount:this.selectedAmount,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"donate",type:"sendUsd",amount:this.selectedAmount,currency:this.selectedSymbol}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="donate",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){X(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{oe||(oe=(await import("@windoge98/plug-n-play")).PNP),this.pnp=new oe(this.config?.plugNPlay||{});let n=this.pnp.getEnabledWallets();if(X(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="donate",this.showWalletModal=!0;return}catch(n){X(this.config?.debug||!1,"Wallet connection error:",n),this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error";return}}X(this.config?.debug||!1,"Creating SDK for payment");let e=c(this.config),i=this.cryptoOptions.find(n=>n.symbol===this.selectedSymbol).canisterId||await e.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);X(this.config?.debug||!1,"Donation payment details",{amount:this.selectedAmount,selectedSymbol:this.selectedSymbol,canisterId:i});let r=await e.sendUsd(this.selectedAmount,i,{context:"donation"});X(this.config?.debug||!1,"Donation payment completed",{resp:r}),this.raised+=this.selectedAmount,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:r.transactionId,status:r.status,raised:this.raised}),this.dispatchEvent(new CustomEvent("icpay-donation",{detail:{amount:this.selectedAmount,tx:r},bubbles:!0}))}catch(e){k(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),$(t)&&(this.errorMessage=W(t),this.errorSeverity=L(t),this.errorAction=C(t))}})}finally{this.processing=!1}}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}async connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");let t=await this.pnp.connect(e);if(!!!(t&&(t.connected===!0||t.principal||t.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}this.config={...this.config,connectedWallet:t,actorProvider:(n,l)=>this.pnp.getActor({canisterId:n,idl:l,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let r=this.pendingAction;this.pendingAction=null,r==="donate"&&setTimeout(()=>this.donate(),0)}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?V`
729
729
  <div class="card section" style="text-align:center;">
730
730
  ${this.config?.progressBar?.enabled!==!1?V`<icpay-progress-bar mode="${this.config?.progressBar?.mode||"modal"}"></icpay-progress-bar>`:null}
731
731
  <div class="thermo"><div class="fill" style="height:${this.fillPercentage}%"></div></div>
@@ -811,7 +811,7 @@ var Ie=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var s=(o,a,e
811
811
  border-color: rgba(239, 68, 68, 0.3);
812
812
  color: #ef4444;
813
813
  }
814
- `],s([ct({type:Object})],h.prototype,"config",2),s([M()],h.prototype,"selectedAmount",2),s([M()],h.prototype,"selectedSymbol",2),s([M()],h.prototype,"raised",2),s([M()],h.prototype,"processing",2),s([M()],h.prototype,"succeeded",2),s([M()],h.prototype,"availableLedgers",2),s([M()],h.prototype,"errorMessage",2),s([M()],h.prototype,"errorSeverity",2),s([M()],h.prototype,"errorAction",2),s([M()],h.prototype,"walletConnected",2),s([M()],h.prototype,"pendingAction",2),s([M()],h.prototype,"showWalletModal",2),h=s([lt("icpay-donation-thermometer")],h);import{LitElement as dt,html as B,css as pt}from"lit";import{customElement as gt,property as ut,state as F}from"lit/decorators.js";var Se=typeof window<"u",ke=null;function ue(o,a,e){o&&(e!==void 0?console.log(`[ICPay Widget] ${a}`,e):console.log(`[ICPay Widget] ${a}`))}var v=class extends dt{constructor(){super(...arguments);this.selectedSymbol=null;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}get cryptoOptions(){return this.config?.cryptoOptions?.length?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),Se&&(ue(this.config?.debug||!1,"Pay button connected",{config:this.config}),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers(),this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol))}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null,setTimeout(()=>{t==="pay"&&this.pay()},0)}}async loadVerifiedLedgers(){if(!(!Se||!this.config?.publishableKey))try{let t=await c(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||(this.availableLedgers[0]?.symbol??"ICP"))}catch(e){this.dispatchEvent(new CustomEvent("icpay-error",{detail:{message:"Failed to load verified ledgers",cause:e},bubbles:!0})),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}selectSymbol(e){this.selectedSymbol=e}async ensureWallet(){if(this.config.useOwnWallet)return this.config.actorProvider?!0:(this.pendingAction="pay",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0})),!1);if(this.walletConnected)return!0;try{ke||(ke=(await import("@windoge98/plug-n-play")).PNP),this.pnp=new ke(this.config?.plugNPlay||{});let e=this.pnp.getEnabledWallets();if(ue(this.config?.debug||!1,"Available wallets",e),!e?.length)throw new Error("No wallets available");return this.pendingAction="pay",this.showWalletModal=!0,!1}catch(e){return this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error",!1}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}async connectWithWallet(e){if(this.pnp)try{if(ue(this.config?.debug||!1,"Connecting to wallet",{walletId:e}),!e)throw new Error("No wallet ID provided");let t=await this.pnp.connect(e);if(ue(this.config?.debug||!1,"Wallet connect result",t),!!!(t&&(t.connected===!0||t.principal||t.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0,this.config={...this.config,connectedWallet:t,actorProvider:(n,l)=>this.pnp.getActor({canisterId:n,idl:l,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let r=this.pendingAction;this.pendingAction=null,r==="pay"&&setTimeout(()=>this.pay(),0)}catch(t){ue(this.config?.debug||!1,"Wallet connection error",t),this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}renderWalletModal(){if(!this.showWalletModal||!this.pnp)return null;let e=this.pnp.getEnabledWallets()||[];return B`
814
+ `],s([ct({type:Object})],h.prototype,"config",2),s([M()],h.prototype,"selectedAmount",2),s([M()],h.prototype,"selectedSymbol",2),s([M()],h.prototype,"raised",2),s([M()],h.prototype,"processing",2),s([M()],h.prototype,"succeeded",2),s([M()],h.prototype,"availableLedgers",2),s([M()],h.prototype,"errorMessage",2),s([M()],h.prototype,"errorSeverity",2),s([M()],h.prototype,"errorAction",2),s([M()],h.prototype,"walletConnected",2),s([M()],h.prototype,"pendingAction",2),s([M()],h.prototype,"showWalletModal",2),h=s([lt("icpay-donation-thermometer")],h);import{LitElement as dt,html as B,css as pt}from"lit";import{customElement as gt,property as ut,state as D}from"lit/decorators.js";var Se=typeof window<"u",ke=null;function he(o,a,e){o&&(e!==void 0?console.log(`[ICPay Widget] ${a}`,e):console.log(`[ICPay Widget] ${a}`))}var v=class extends dt{constructor(){super(...arguments);this.selectedSymbol=null;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}get cryptoOptions(){return this.config?.cryptoOptions?.length?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),Se&&(he(this.config?.debug||!1,"Pay button connected",{config:this.config}),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers(),this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol))}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="pay"&&this.pay()},0)}}async loadVerifiedLedgers(){if(!(!Se||!this.config?.publishableKey))try{let t=await c(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||(this.availableLedgers[0]?.symbol??"ICP"))}catch(e){this.dispatchEvent(new CustomEvent("icpay-error",{detail:{message:"Failed to load verified ledgers",cause:e},bubbles:!0})),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}selectSymbol(e){this.selectedSymbol=e}async ensureWallet(){if(this.config.useOwnWallet)return this.config.actorProvider?!0:(this.pendingAction="pay",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0})),!1);if(this.walletConnected)return!0;try{ke||(ke=(await import("@windoge98/plug-n-play")).PNP),this.pnp=new ke(this.config?.plugNPlay||{});let e=this.pnp.getEnabledWallets();if(he(this.config?.debug||!1,"Available wallets",e),!e?.length)throw new Error("No wallets available");return this.pendingAction="pay",this.showWalletModal=!0,!1}catch(e){return this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error",!1}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}async connectWithWallet(e){if(this.pnp)try{if(he(this.config?.debug||!1,"Connecting to wallet",{walletId:e}),!e)throw new Error("No wallet ID provided");let t=await this.pnp.connect(e);if(he(this.config?.debug||!1,"Wallet connect result",t),!!!(t&&(t.connected===!0||t.principal||t.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}this.config={...this.config,connectedWallet:t,actorProvider:(n,l)=>this.pnp.getActor({canisterId:n,idl:l,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let r=this.pendingAction;this.pendingAction=null,r==="pay"&&setTimeout(()=>this.pay(),0)}catch(t){he(this.config?.debug||!1,"Wallet connection error",t),this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}renderWalletModal(){if(!this.showWalletModal||!this.pnp)return null;let e=this.pnp.getEnabledWallets()||[];return B`
815
815
  <div style="position:fixed;inset:0;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.55);z-index:9999">
816
816
  <div class="card" style="width:380px;padding:16px;border-radius:12px">
817
817
  <div class="label" style="font-weight:700;margin-bottom:12px;text-align:center">Choose Wallet</div>
@@ -827,26 +827,26 @@ var Ie=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var s=(o,a,e
827
827
  </button>
828
828
  </div>
829
829
  </div>
830
- `}async pay(){if(!(!Se||this.processing)){this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,this.processing=!0;try{if(!await this.ensureWallet())return;let t=c(this.config),i=this.selectedSymbol||"ICP",n=this.cryptoOptions.find(H=>H.symbol===i)?.canisterId||await t.client.getLedgerCanisterIdBySymbol(i),l=Number(this.config?.amountUsd??0),g={context:"pay-button"},w=await t.sendUsd(l,n,g);this.config.onSuccess&&this.config.onSuccess({id:w.transactionId,status:w.status}),this.succeeded=!0,this.dispatchEvent(new CustomEvent("icpay-pay",{detail:{amount:l,tx:w},bubbles:!0}))}catch(e){k(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),$(t)&&(this.errorMessage=W(t),this.errorSeverity=C(t),this.errorAction=L(t))}})}finally{this.processing=!1,this.pendingAction=null}}}render(){if(!this.config)return B`<div class="card section">Loading...</div>`;let e=this.config?.showLedgerDropdown===!0,i=(this.cryptoOptions?.length||0)>1,r=this.config?.showLedgerDropdown,n=r==="dropdown"?"dropdown":r==="none"?"none":"buttons",l=n!=="none"&&(i||n==="dropdown"),g=n==="dropdown"?"dropdown":i?"buttons":"none",w=this.selectedSymbol||this.config?.defaultSymbol||"ICP",H=typeof this.config?.amountUsd=="number"?`${Number(this.config.amountUsd).toFixed(2)}`:"",N=(this.config?.buttonLabel||(typeof this.config?.amountUsd=="number"?"Pay ${amount} with {symbol}":"Pay with {symbol}")).replace("{amount}",H||"$0.00").replace("{symbol}",w),ae=this.config?.progressBar?.enabled!==!1;return B`
830
+ `}async pay(){if(!(!Se||this.processing)){this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:this.config?.amountUsd,currency:this.selectedSymbol||this.config?.defaultSymbol}}))}catch{}this.processing=!0;try{if(!await this.ensureWallet())return;let t=c(this.config),i=this.selectedSymbol||"ICP",n=this.cryptoOptions.find(Z=>Z.symbol===i)?.canisterId||await t.client.getLedgerCanisterIdBySymbol(i),l=Number(this.config?.amountUsd??0),g={context:"pay-button"},x=await t.sendUsd(l,n,g);this.config.onSuccess&&this.config.onSuccess({id:x.transactionId,status:x.status}),this.succeeded=!0,this.dispatchEvent(new CustomEvent("icpay-pay",{detail:{amount:l,tx:x},bubbles:!0}))}catch(e){k(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),$(t)&&(this.errorMessage=W(t),this.errorSeverity=L(t),this.errorAction=C(t))}})}finally{this.processing=!1}}}render(){if(!this.config)return B`<div class="card section">Loading...</div>`;let t=(this.cryptoOptions?.length||0)>1,i=this.config?.showLedgerDropdown,r=i==="dropdown"?"dropdown":i==="none"?"none":"buttons",n=r!=="none"&&(t||r==="dropdown"),l=r==="dropdown"?"dropdown":t?"buttons":"none",g=this.selectedSymbol||this.config?.defaultSymbol||"ICP",x=typeof this.config?.amountUsd=="number"?`${Number(this.config.amountUsd).toFixed(2)}`:"",ae=(this.config?.buttonLabel||(typeof this.config?.amountUsd=="number"?"Pay ${amount} with {symbol}":"Pay with {symbol}")).replace("{amount}",x||"$0.00").replace("{symbol}",g),J=this.config?.progressBar?.enabled!==!1;return B`
831
831
  <div class="card section">
832
- ${ae?B`
832
+ ${J?B`
833
833
  <icpay-progress-bar></icpay-progress-bar>
834
834
  `:null}
835
835
 
836
- <div class="row ${l?"":"single"}">
837
- ${l?B`
836
+ <div class="row ${n?"":"single"}">
837
+ ${n?B`
838
838
  <icpay-token-selector
839
839
  .options=${this.cryptoOptions}
840
840
  .value=${this.selectedSymbol||""}
841
841
  .defaultSymbol=${this.config?.defaultSymbol||"ICP"}
842
- mode=${g}
843
- @icpay-token-change=${I=>this.selectSymbol(I.detail.symbol)}
842
+ mode=${l}
843
+ @icpay-token-change=${le=>this.selectSymbol(le.detail.symbol)}
844
844
  ></icpay-token-selector>
845
845
  `:null}
846
846
  <button class="pay-button ${this.processing?"processing":""}"
847
847
  ?disabled=${this.processing||this.config?.disablePaymentButton===!0||this.succeeded&&this.config?.disableAfterSuccess===!0}
848
848
  @click=${()=>this.pay()}>
849
- ${this.succeeded&&this.config?.disableAfterSuccess?"Paid":this.processing?"Processing\u2026":N}
849
+ ${this.succeeded&&this.config?.disableAfterSuccess?"Paid":this.processing?"Processing\u2026":ae}
850
850
  </button>
851
851
  </div>
852
852
 
@@ -866,21 +866,21 @@ var Ie=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var s=(o,a,e
866
866
  .error-message.info { background: rgba(59,130,246,0.1); border-color: rgba(59,130,246,0.3); color: #3b82f6; }
867
867
  .error-message.warning { background: rgba(245,158,11,0.1); border-color: rgba(245,158,11,0.3); color: #f59e0b; }
868
868
  .error-message.error { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.3); color: #ef4444; }
869
- `],s([ut({type:Object})],v.prototype,"config",2),s([F()],v.prototype,"selectedSymbol",2),s([F()],v.prototype,"processing",2),s([F()],v.prototype,"succeeded",2),s([F()],v.prototype,"availableLedgers",2),s([F()],v.prototype,"errorMessage",2),s([F()],v.prototype,"errorSeverity",2),s([F()],v.prototype,"errorAction",2),s([F()],v.prototype,"walletConnected",2),s([F()],v.prototype,"pendingAction",2),s([F()],v.prototype,"showWalletModal",2),v=s([gt("icpay-pay-button")],v);import{LitElement as ht,html as _,css as ft}from"lit";import{customElement as bt,property as yt,state as O}from"lit/decorators.js";var We=typeof window<"u",$e=null;function mt(o,a,e){o&&(e!==void 0?console.log(`[ICPay Widget] ${a}`,e):console.log(`[ICPay Widget] ${a}`))}var f=class extends ht{constructor(){super(...arguments);this.amountUsd=0;this.hasUserAmount=!1;this.selectedSymbol=null;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}get cryptoOptions(){return this.config?.cryptoOptions?.length?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),We&&(mt(this.config?.debug||!1,"Amount input connected",{config:this.config}),this.amountUsd=Number(this.config?.defaultAmountUsd??0),this.hasUserAmount=!1,this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers(),this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol))}updated(e){if(e.has("config")&&(!this.hasUserAmount&&typeof this.config?.defaultAmountUsd=="number"&&(this.amountUsd===0||this.amountUsd==null||Number.isNaN(this.amountUsd))&&(this.amountUsd=Number(this.config.defaultAmountUsd)),!this.selectedSymbol&&this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol),!(this.config?.cryptoOptions&&this.config.cryptoOptions.length>0)&&this.availableLedgers.length===0&&this.loadVerifiedLedgers(),this.pendingAction&&this.config?.actorProvider)){let t=this.pendingAction;this.pendingAction=null,setTimeout(()=>{t==="pay"&&this.pay()},0)}}async loadVerifiedLedgers(){if(!(!We||!this.config?.publishableKey))try{let t=await c(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||(this.availableLedgers[0]?.symbol??"ICP"))}catch(e){this.dispatchEvent(new CustomEvent("icpay-error",{detail:{message:"Failed to load verified ledgers",cause:e},bubbles:!0})),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}onInputChange(e){let t=Number(this.config?.stepUsd??.5),i=Math.max(0,Number(e.target.value||0)),r=Math.round(i/t)*t;this.amountUsd=Number(r.toFixed(2)),this.hasUserAmount=!0}selectSymbol(e){this.selectedSymbol=e}isValidAmount(){let e=Number(this.config?.minUsd??.5),t=this.config?.maxUsd!==void 0?Number(this.config.maxUsd):1/0;return this.amountUsd>=e&&this.amountUsd<=t}async ensureWallet(){if(this.config.useOwnWallet)return this.config.actorProvider?!0:(this.pendingAction="pay",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0})),!1);if(this.walletConnected)return!0;try{if($e||($e=(await import("@windoge98/plug-n-play")).PNP),this.pnp=new $e(this.config?.plugNPlay||{}),!this.pnp.getEnabledWallets()?.length)throw new Error("No wallets available");return this.pendingAction="pay",this.showWalletModal=!0,!1}catch(e){return this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error",!1}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}async connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");let t=await this.pnp.connect(e);if(!!!(t&&(t.connected===!0||t.principal||t.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0,this.config={...this.config,connectedWallet:t,actorProvider:(n,l)=>this.pnp.getActor({canisterId:n,idl:l,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let r=this.pendingAction;this.pendingAction=null,r==="pay"&&setTimeout(()=>this.pay(),0)}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}async pay(){if(!(!We||this.processing)){if(this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,!this.isValidAmount()){this.errorMessage="Please enter a valid amount",this.errorSeverity="warning";return}this.processing=!0;try{if(!await this.ensureWallet())return;let t=c(this.config),i=this.selectedSymbol||"ICP",n=this.cryptoOptions.find(H=>H.symbol===i)?.canisterId||await t.client.getLedgerCanisterIdBySymbol(i),l=Number(this.amountUsd),g={context:"amount-input"},w=await t.sendUsd(l,n,g);this.config.onSuccess&&this.config.onSuccess({id:w.transactionId,status:w.status,amountUsd:l}),this.succeeded=!0,this.dispatchEvent(new CustomEvent("icpay-amount-pay",{detail:{amount:l,tx:w},bubbles:!0}))}catch(e){k(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),$(t)&&(this.errorMessage=W(t),this.errorSeverity=C(t),this.errorAction=L(t))}})}finally{this.processing=!1,this.pendingAction=null}}}render(){if(!this.config)return _`<div class="card section">Loading...</div>`;let e=this.config?.placeholder||"Enter amount in USD",i=(this.config?.buttonLabel||"Pay ${amount} with {symbol}").replace("{amount}",this.amountUsd?`${Number(this.amountUsd).toFixed(2)}`:"$0.00").replace("{symbol}",this.selectedSymbol||this.config?.defaultSymbol||"ICP"),r=this.config?.showLedgerDropdown===!0,n=this.cryptoOptions.find(N=>N.symbol===(this.selectedSymbol||""))?.label||this.cryptoOptions[0]?.label||this.config?.defaultSymbol||"ICP",l=this.config?.progressBar?.mode||"modal",g=this.config?.showLedgerDropdown,w=g==="buttons"?"buttons":g==="none"?"none":"dropdown",he=this.config?.progressBar?.enabled!==!1&&(l==="modal"?!0:this.processing);return _`
869
+ `],s([ut({type:Object})],v.prototype,"config",2),s([D()],v.prototype,"selectedSymbol",2),s([D()],v.prototype,"processing",2),s([D()],v.prototype,"succeeded",2),s([D()],v.prototype,"availableLedgers",2),s([D()],v.prototype,"errorMessage",2),s([D()],v.prototype,"errorSeverity",2),s([D()],v.prototype,"errorAction",2),s([D()],v.prototype,"walletConnected",2),s([D()],v.prototype,"pendingAction",2),s([D()],v.prototype,"showWalletModal",2),v=s([gt("icpay-pay-button")],v);import{LitElement as ht,html as F,css as ft}from"lit";import{customElement as yt,property as bt,state as O}from"lit/decorators.js";var We=typeof window<"u",$e=null;function mt(o,a,e){o&&(e!==void 0?console.log(`[ICPay Widget] ${a}`,e):console.log(`[ICPay Widget] ${a}`))}var f=class extends ht{constructor(){super(...arguments);this.amountUsd=0;this.hasUserAmount=!1;this.selectedSymbol=null;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}get cryptoOptions(){return this.config?.cryptoOptions?.length?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),We&&(mt(this.config?.debug||!1,"Amount input connected",{config:this.config}),this.amountUsd=Number(this.config?.defaultAmountUsd??0),this.hasUserAmount=!1,this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers(),this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol))}updated(e){if(e.has("config")&&(!this.hasUserAmount&&typeof this.config?.defaultAmountUsd=="number"&&(this.amountUsd===0||this.amountUsd==null||Number.isNaN(this.amountUsd))&&(this.amountUsd=Number(this.config.defaultAmountUsd)),!this.selectedSymbol&&this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol),!(this.config?.cryptoOptions&&this.config.cryptoOptions.length>0)&&this.availableLedgers.length===0&&this.loadVerifiedLedgers(),this.pendingAction&&this.config?.actorProvider)){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="pay"&&this.pay()},0)}}async loadVerifiedLedgers(){if(!(!We||!this.config?.publishableKey))try{let t=await c(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||(this.availableLedgers[0]?.symbol??"ICP"))}catch(e){this.dispatchEvent(new CustomEvent("icpay-error",{detail:{message:"Failed to load verified ledgers",cause:e},bubbles:!0})),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}onInputChange(e){let t=Number(this.config?.stepUsd??.5),i=Math.max(0,Number(e.target.value||0)),r=Math.round(i/t)*t;this.amountUsd=Number(r.toFixed(2)),this.hasUserAmount=!0}selectSymbol(e){this.selectedSymbol=e}isValidAmount(){let e=Number(this.config?.minUsd??.5),t=this.config?.maxUsd!==void 0?Number(this.config.maxUsd):1/0;return this.amountUsd>=e&&this.amountUsd<=t}async ensureWallet(){if(this.config.useOwnWallet)return this.config.actorProvider?!0:(this.pendingAction="pay",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0})),!1);if(this.walletConnected)return!0;try{if($e||($e=(await import("@windoge98/plug-n-play")).PNP),this.pnp=new $e(this.config?.plugNPlay||{}),!this.pnp.getEnabledWallets()?.length)throw new Error("No wallets available");return this.pendingAction="pay",this.showWalletModal=!0,!1}catch(e){return this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error",!1}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}async connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");let t=await this.pnp.connect(e);if(!!!(t&&(t.connected===!0||t.principal||t.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}this.config={...this.config,connectedWallet:t,actorProvider:(n,l)=>this.pnp.getActor({canisterId:n,idl:l,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let r=this.pendingAction;this.pendingAction=null,r==="pay"&&setTimeout(()=>this.pay(),0)}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}async pay(){if(!(!We||this.processing)){if(this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,!this.isValidAmount()){this.errorMessage="Please enter a valid amount",this.errorSeverity="warning";return}try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:this.amountUsd,currency:this.selectedSymbol||this.config?.defaultSymbol}}))}catch{}this.processing=!0;try{if(!await this.ensureWallet())return;let t=c(this.config),i=this.selectedSymbol||"ICP",n=this.cryptoOptions.find(Z=>Z.symbol===i)?.canisterId||await t.client.getLedgerCanisterIdBySymbol(i),l=Number(this.amountUsd),g={context:"amount-input"},x=await t.sendUsd(l,n,g);this.config.onSuccess&&this.config.onSuccess({id:x.transactionId,status:x.status,amountUsd:l}),this.succeeded=!0,this.dispatchEvent(new CustomEvent("icpay-amount-pay",{detail:{amount:l,tx:x},bubbles:!0}))}catch(e){k(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),$(t)&&(this.errorMessage=W(t),this.errorSeverity=L(t),this.errorAction=C(t))}})}finally{this.processing=!1}}}render(){if(!this.config)return F`<div class="card section">Loading...</div>`;let e=this.config?.placeholder||"Enter amount in USD",i=(this.config?.buttonLabel||"Pay ${amount} with {symbol}").replace("{amount}",this.amountUsd?`${Number(this.amountUsd).toFixed(2)}`:"$0.00").replace("{symbol}",this.selectedSymbol||this.config?.defaultSymbol||"ICP"),r=this.config?.showLedgerDropdown===!0,n=this.cryptoOptions.find(U=>U.symbol===(this.selectedSymbol||""))?.label||this.cryptoOptions[0]?.label||this.config?.defaultSymbol||"ICP",l=this.config?.progressBar?.mode||"modal",g=this.config?.showLedgerDropdown,x=g==="buttons"?"buttons":g==="none"?"none":"dropdown",ae=this.config?.progressBar?.enabled!==!1&&(l==="modal"?!0:this.processing);return F`
870
870
  <div class="card section">
871
- ${he?_`<icpay-progress-bar mode="${l}"></icpay-progress-bar>`:null}
871
+ ${ae?F`<icpay-progress-bar mode="${l}"></icpay-progress-bar>`:null}
872
872
 
873
873
  <div class="row">
874
- <input type="number" min="0" step="${Number(this.config?.stepUsd??.5)}" .value=${String(this.amountUsd||"")} placeholder="${e}" @input=${N=>this.onInputChange(N)} />
875
- ${w!=="none"?_`
874
+ <input type="number" min="0" step="${Number(this.config?.stepUsd??.5)}" .value=${String(this.amountUsd||"")} placeholder="${e}" @input=${U=>this.onInputChange(U)} />
875
+ ${x!=="none"?F`
876
876
  <icpay-token-selector
877
877
  .options=${this.cryptoOptions}
878
878
  .value=${this.selectedSymbol||""}
879
879
  .defaultSymbol=${this.config?.defaultSymbol||"ICP"}
880
- mode=${w}
881
- @icpay-token-change=${N=>this.selectSymbol(N.detail.symbol)}
880
+ mode=${x}
881
+ @icpay-token-change=${U=>this.selectSymbol(U.detail.symbol)}
882
882
  ></icpay-token-selector>
883
- `:_`
883
+ `:F`
884
884
  <div class="label" style="padding: 10px;">${n}</div>
885
885
  `}
886
886
  <button class="pay-button ${this.processing?"processing":""}"
@@ -891,21 +891,21 @@ var Ie=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var s=(o,a,e
891
891
  </div>
892
892
  <div class="hint">Default: ${this.config?.defaultSymbol||"ICP"}. Min: $${Number(this.config?.minUsd??.5).toFixed(2)}${this.config?.maxUsd?`, Max: $${Number(this.config.maxUsd).toFixed(2)}`:""}</div>
893
893
 
894
- ${this.errorMessage?_`
894
+ ${this.errorMessage?F`
895
895
  <div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
896
896
  ${this.errorMessage}
897
- ${this.errorAction?_`<button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">${this.errorAction}</button>`:""}
897
+ ${this.errorAction?F`<button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">${this.errorAction}</button>`:""}
898
898
  </div>
899
899
  `:""}
900
- ${(()=>{let N=this.pnp?.getEnabledWallets?.()||[];return this.showWalletModal&&this.pnp?_`
900
+ ${(()=>{let U=this.pnp?.getEnabledWallets?.()||[];return this.showWalletModal&&this.pnp?F`
901
901
  <div style="position:fixed;inset:0;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.55);z-index:9999">
902
902
  <div class="card" style="width:380px;padding:16px;border-radius:12px">
903
903
  <div class="label" style="font-weight:700;margin-bottom:12px;text-align:center">Choose Wallet</div>
904
904
  <div style="display:grid;grid-template-columns:1fr;gap:10px;margin-bottom:12px">
905
- ${N.map(J=>{let ae=this.getWalletId(J),I=this.getWalletLabel(J),E=this.getWalletIcon(J);return _`
906
- <button class="pay-button" style="display:flex;align-items:center;gap:10px;justify-content:center;padding:12px" @click=${()=>this.connectWithWallet(ae)}>
907
- ${E?_`<img src="${E}" alt="${I}" style="width:20px;height:20px;border-radius:4px;object-fit:contain;background:transparent" />`:""}
908
- <span>${I}</span>
905
+ ${U.map(J=>{let le=this.getWalletId(J),_=this.getWalletLabel(J),E=this.getWalletIcon(J);return F`
906
+ <button class="pay-button" style="display:flex;align-items:center;gap:10px;justify-content:center;padding:12px" @click=${()=>this.connectWithWallet(le)}>
907
+ ${E?F`<img src="${E}" alt="${_}" style="width:20px;height:20px;border-radius:4px;object-fit:contain;background:transparent" />`:""}
908
+ <span>${_}</span>
909
909
  </button>`})}
910
910
  </div>
911
911
  <button class="pay-button" style="background:#6b7280;color:#f9fafb" @click=${()=>{this.showWalletModal=!1}}>
@@ -924,5 +924,5 @@ var Ie=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var s=(o,a,e
924
924
  .error-message.warning { background: rgba(245,158,11,0.1); border-color: rgba(245,158,11,0.3); color: #f59e0b; }
925
925
  .error-message.error { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.3); color: #ef4444; }
926
926
  .hint { font-size: 12px; color: var(--icpay-muted); margin-top: 6px; }
927
- `],s([yt({type:Object})],f.prototype,"config",2),s([O()],f.prototype,"amountUsd",2),s([O()],f.prototype,"hasUserAmount",2),s([O()],f.prototype,"selectedSymbol",2),s([O()],f.prototype,"processing",2),s([O()],f.prototype,"succeeded",2),s([O()],f.prototype,"availableLedgers",2),s([O()],f.prototype,"errorMessage",2),s([O()],f.prototype,"errorSeverity",2),s([O()],f.prototype,"errorAction",2),s([O()],f.prototype,"walletConnected",2),s([O()],f.prototype,"pendingAction",2),s([O()],f.prototype,"showWalletModal",2),f=s([bt("icpay-amount-input")],f);export{f as ICPayAmountInput,p as ICPayArticlePaywall,m as ICPayCoffeeShop,h as ICPayDonationThermometer,v as ICPayPayButton,b as ICPayPremiumContent,u as ICPayTipJar,ee as applyThemeVars,S as baseStyles,c as createSdk};
927
+ `],s([bt({type:Object})],f.prototype,"config",2),s([O()],f.prototype,"amountUsd",2),s([O()],f.prototype,"hasUserAmount",2),s([O()],f.prototype,"selectedSymbol",2),s([O()],f.prototype,"processing",2),s([O()],f.prototype,"succeeded",2),s([O()],f.prototype,"availableLedgers",2),s([O()],f.prototype,"errorMessage",2),s([O()],f.prototype,"errorSeverity",2),s([O()],f.prototype,"errorAction",2),s([O()],f.prototype,"walletConnected",2),s([O()],f.prototype,"pendingAction",2),s([O()],f.prototype,"showWalletModal",2),f=s([yt("icpay-amount-input")],f);export{f as ICPayAmountInput,p as ICPayArticlePaywall,m as ICPayCoffeeShop,h as ICPayDonationThermometer,v as ICPayPayButton,y as ICPayPremiumContent,u as ICPayTipJar,ee as applyThemeVars,S as baseStyles,c as createSdk};
928
928
  //# sourceMappingURL=index.js.map