@ic-pay/icpay-widget 1.2.61 → 1.2.83

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.
@@ -0,0 +1,2068 @@
1
+ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
2
+ :host {
3
+ /* Light mode defaults (from COLOR_PALETTE.md) */
4
+ --icpay-background: #ffffff;
5
+ --icpay-foreground: #171717;
6
+ --icpay-muted-foreground: #6b7280;
7
+ --icpay-accent-foreground: #ffffff;
8
+ --icpay-primary: #3b82f6;
9
+ --icpay-destructive: #ef4444;
10
+ --icpay-primary-foreground: #ffffff;
11
+ --icpay-secondary: #f3f4f6;
12
+ --icpay-secondary-foreground: #171717;
13
+ --icpay-accent: #f9fafb;
14
+ --icpay-muted: #f9fafb;
15
+ --icpay-border: #e5e7eb;
16
+ --icpay-input: #e5e7eb;
17
+ --icpay-ring: #3b82f6;
18
+ --icpay-destructive-foreground: #ffffff;
19
+
20
+ /* Status colors */
21
+ --icpay-success-bg: rgba(16, 185, 129, 0.1);
22
+ --icpay-success-text: #059669;
23
+ --icpay-success-border: rgba(16, 185, 129, 0.3);
24
+ --icpay-warning-bg: rgba(245, 158, 11, 0.1);
25
+ --icpay-warning-text: #d97706;
26
+ --icpay-warning-border: rgba(245, 158, 11, 0.3);
27
+ --icpay-error-bg: rgba(239, 68, 68, 0.1);
28
+ --icpay-error-text: #dc2626;
29
+ --icpay-error-border: rgba(239, 68, 68, 0.3);
30
+ --icpay-processing-bg: rgba(59, 130, 246, 0.1);
31
+ --icpay-processing-text: #2563eb;
32
+ --icpay-processing-border: rgba(59, 130, 246, 0.3);
33
+
34
+ /* Legacy compatibility variables */
35
+ --icpay-text: var(--icpay-foreground);
36
+ --icpay-surface: transparent;
37
+ --icpay-surface-alt: var(--icpay-secondary);
38
+ --icpay-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
39
+
40
+ display: block;
41
+ font-family: var(--icpay-font);
42
+ color: var(--icpay-foreground);
43
+ background: transparent;
44
+ }
45
+
46
+ :host([data-theme="dark"]) {
47
+ /* Dark mode (from COLOR_PALETTE.md) */
48
+ --icpay-background: hsl(222.2 84% 4.9%);
49
+ --icpay-foreground: hsl(210 40% 98%);
50
+ --icpay-muted-foreground: hsl(215 20.2% 65.1%);
51
+ --icpay-accent-foreground: hsl(210 40% 98%);
52
+ --icpay-primary: hsl(210 40% 98%);
53
+ --icpay-destructive: hsl(0 62.8% 30.6%);
54
+ --icpay-primary-foreground: hsl(222.2 47.4% 11.2%);
55
+ --icpay-secondary: hsl(217.2 32.6% 17.5%);
56
+ --icpay-secondary-foreground: hsl(210 40% 98%);
57
+ --icpay-accent: hsl(217.2 32.6% 17.5%);
58
+ --icpay-muted: hsl(217.2 32.6% 17.5%);
59
+ --icpay-border: hsl(217.2 32.6% 30%);
60
+ --icpay-input: hsl(217.2 32.6% 17.5%);
61
+ --icpay-ring: hsl(210 40% 98%);
62
+ --icpay-destructive-foreground: hsl(210 40% 98%);
63
+
64
+ /* Status colors for dark mode */
65
+ --icpay-success-bg: rgba(16, 185, 129, 0.1);
66
+ --icpay-success-text: #34d399;
67
+ --icpay-success-border: rgba(16, 185, 129, 0.3);
68
+ --icpay-warning-bg: rgba(245, 158, 11, 0.1);
69
+ --icpay-warning-text: #fbbf24;
70
+ --icpay-warning-border: rgba(245, 158, 11, 0.3);
71
+ --icpay-error-bg: rgba(239, 68, 68, 0.1);
72
+ --icpay-error-text: #f87171;
73
+ --icpay-error-border: rgba(239, 68, 68, 0.3);
74
+ --icpay-processing-bg: rgba(59, 130, 246, 0.1);
75
+ --icpay-processing-text: #60a5fa;
76
+ --icpay-processing-border: rgba(59, 130, 246, 0.3);
77
+
78
+ --icpay-text: var(--icpay-foreground);
79
+ --icpay-surface-alt: var(--icpay-secondary);
80
+ }
81
+
82
+ .icpay-card {
83
+ background: none;
84
+ border: none;
85
+ border-radius: 16px;
86
+ box-shadow: none;
87
+ }
88
+
89
+ .icpay-section {
90
+ padding: 20px;
91
+ }
92
+
93
+ .icpay-powered-by {
94
+ margin-top: 12px;
95
+ text-align: center;
96
+ font-size: 10px;
97
+ color: var(--icpay-muted-foreground);
98
+ opacity: 0.6;
99
+ }
100
+
101
+ .icpay-powered-by a {
102
+ color: var(--icpay-muted-foreground);
103
+ text-decoration: none;
104
+ transition: opacity 0.2s ease;
105
+ }
106
+
107
+ .icpay-powered-by a:hover {
108
+ opacity: 1;
109
+ text-decoration: underline;
110
+ }
111
+
112
+ .pay-button {
113
+ width: 100%;
114
+ background: var(--icpay-foreground);
115
+ color: var(--icpay-background);
116
+ border: 1px solid var(--icpay-border);
117
+ border-radius: 16px;
118
+ padding: 16px;
119
+ font-size: 16px;
120
+ font-weight: 600;
121
+ cursor: pointer;
122
+ transition: all 0.3s ease;
123
+ box-shadow: none;
124
+ }
125
+
126
+ .pay-button:hover {
127
+ background: color-mix(in srgb, var(--icpay-foreground) 90%, transparent);
128
+ }
129
+
130
+ .pay-button.processing {
131
+ background: var(--icpay-muted-foreground);
132
+ color: var(--icpay-background);
133
+ border-color: var(--icpay-muted-foreground);
134
+ cursor: not-allowed;
135
+ animation: pulse 2s infinite;
136
+ }
137
+
138
+ @keyframes pulse {
139
+ 0%, 100% { opacity: 1; }
140
+ 50% { opacity: 0.7; }
141
+ }
142
+ `;function Te(i,s){if(!i)return;let e="light";if(s?.mode)e=s.mode;else if(typeof document<"u"){let a=document.documentElement.getAttribute("data-icpay-theme")||document.documentElement.getAttribute("data-theme");(a==="light"||a==="dark")&&(e=a)}if(!s){i instanceof HTMLElement&&i.setAttribute("data-theme",e),typeof document<"u"&&document.documentElement&&(document.documentElement.setAttribute("data-icpay-theme",e),document.documentElement.style.setProperty("--icpay-theme-mode",e));return}i instanceof HTMLElement&&i.setAttribute("data-theme",e),typeof document<"u"&&document.documentElement&&(document.documentElement.setAttribute("data-icpay-theme",e),document.documentElement.style.setProperty("--icpay-theme-mode",e));let t=(a,n)=>{n&&i.style.setProperty(a,n)};s.primaryColor&&t("--icpay-primary",s.primaryColor),s.secondaryColor&&t("--icpay-secondary",s.secondaryColor),s.accentColor&&t("--icpay-accent",s.accentColor),s.textColor&&t("--icpay-foreground",s.textColor),s.mutedTextColor&&t("--icpay-muted-foreground",s.mutedTextColor),s.surfaceColor&&t("--icpay-background",s.surfaceColor),s.surfaceAltColor&&t("--icpay-secondary",s.surfaceAltColor),s.borderColor&&t("--icpay-border",s.borderColor),s.fontFamily&&t("--icpay-font",s.fontFamily),s.textColor&&t("--icpay-text",s.textColor),s.mutedTextColor&&t("--icpay-muted",s.mutedTextColor),s.surfaceAltColor&&t("--icpay-surface-alt",s.surfaceAltColor)}import{Icpay as $e}from"@ic-pay/icpay-sdk";var Ie=typeof window<"u";function ne(i,s,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${s}`,e):console.log(`[ICPay Widget] ${s}`))}function u(i){if(!Ie)return{client:{},quoteUsd:async()=>({tokenAmountDecimals:"0"}),sendUsd:async()=>({transactionId:"0",status:"pending"}),startOnrampUsd:async()=>({transactionId:"0",status:"pending",metadata:{icpay_onramp:{sessionId:null}}}),notifyIntentUntilComplete:()=>({stop:()=>{}})};ne(i.debug||!1,"Creating SDK with config:",i);let s={publishableKey:i.publishableKey};i.enableEvents!==void 0?s.enableEvents=i.enableEvents:s.enableEvents=!0,i.apiUrl&&(s.apiUrl=i.apiUrl),i.icHost&&(s.icHost=i.icHost),i.actorProvider&&(s.actorProvider=i.actorProvider),i.connectedWallet&&(s.connectedWallet=i.connectedWallet),i.evmProvider&&(s.evmProvider=i.evmProvider),i.solanaProvider&&(s.solanaProvider=i.solanaProvider),i.onrampDisabled!==void 0&&(s.onrampDisabled=i.onrampDisabled),i.debug!==void 0&&(s.debug=i.debug),ne(i.debug||!1,"Filtered SDK config:",s);try{let l=function(d,p,h){return t.notifyPaymentIntentOnRamp({paymentIntentId:d,intervalMs:p,orderId:h})};var e=l;ne(i.debug||!1,"typeof Icpay:",typeof $e);let t=new $e(s);if(Ie){let d=t,p=h=>{d.addEventListener(h,c=>{window.dispatchEvent(new CustomEvent(h,{detail:c?.detail??c}))})};["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(p)}async function a(d,p,h){if(typeof p=="string"&&p.trim().length>0)return t.calculateTokenAmountFromUSD({usdAmount:d,tokenShortcode:p.toLowerCase()});if(typeof h=="string"&&h.trim().length>0)return t.calculateTokenAmountFromUSD({usdAmount:d,ledgerCanisterId:h});throw new Error("quoteUsd requires tokenShortcode or ledgerCanisterId")}async function n(d,p,h,c){let y={...i.metadata,...h||{}};i.externalCostAmount!=null&&y.externalCostAmount==null&&(y.externalCostAmount=i.externalCostAmount);let g=`Pay ${d} with crypto`,I=i.description||y.__description||y.description||g,Z={usdAmount:d,metadata:y,description:I,recipientAddresses:i.recipientAddresses,recipientAddress:i.recipientAddress};if(typeof p=="string"&&p.trim().length>0&&(Z.tokenShortcode=p.toLowerCase()),typeof c=="string"&&c.trim().length>0&&(Z.ledgerCanisterId=c),!Z.tokenShortcode&&!Z.ledgerCanisterId)throw new Error("sendUsd requires tokenShortcode or ledgerCanisterId");return ne(!!i.debug,"Calling createPaymentUsd (flow decision handled by components)",Z),t.createPaymentUsd(Z)}async function o(d,p,h){let c={...i.metadata,...h||{}},y=`Pay ${d} with crypto`,g=i.description||c.__description||c.description||y;return ne(!!i.debug,"Calling onramp createPaymentUsd",{usdAmount:d,ledgerCanisterId:p,description:g}),t.createPaymentUsd({usdAmount:d,ledgerCanisterId:p,metadata:c,onrampPayment:!0,description:g,recipientAddresses:i.recipientAddresses,recipientAddress:""})}return{client:t,quoteUsd:a,sendUsd:n,startOnrampUsd:o,notifyIntentUntilComplete:l}}catch(t){throw ne(i.debug||!1,"Error creating SDK:",t),t}}import{LitElement as Ye,html as P,css as Ge}from"lit";import{customElement as Qe,property as ae,state as R}from"lit/decorators.js";function v(i,s,e){i&&(e!==void 0?console.log(s,e):console.log(s))}var Ze=[{key:"wallet",label:"Connect wallet",tooltip:"Awaiting wallet connection",status:"pending"},{key:"await",label:"Awaiting confirmation",tooltip:"Awaiting wallet signature",status:"pending"},{key:"transfer",label:"Transferring funds",tooltip:"Awaiting transfer to merchant",status:"pending"},{key:"verify",label:"Verifying payment",tooltip:"Please wait while we verify",status:"pending"}],b=class extends Ye{constructor(){super(...arguments);this.open=!1;this.suspended=!1;this.steps=Ze;this.amount=0;this.currency="";this.ledgerSymbol="";this.debug=!1;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.confirmLoadingStartedAt=null;this.progressionTimer=null;this.currentWalletType=null;this.showWalletSelector=!1;this.isTransitioning=!1;this.isOnrampFlow=!1;this.onMethodStart=e=>{let t=e?.detail?.name||"",a=e?.detail?.type||"";if(v(this.debug,"ICPay Progress: Method start event received:",e.detail),t==="createPayment"||t==="createPaymentUsd"||t==="sendUsd"||t==="pay"||t==="unlock"||t==="tip"||t==="donate"||t==="order"){if(this.open=!0,this.activeIndex=0,this.completed=!1,this.failed=!1,this.errorMessage=null,this.showSuccess=!1,this.showConfetti=!1,this.showWalletSelector=!1,this.isTransitioning=!1,this.currentSteps=this.currentSteps.map(n=>({...n,status:"pending"})),a==="onramp"){this.isOnrampFlow=!0;let n={wallet:{label:"Payment initiated",tooltip:"Please pay in the new tab"},await:{label:"Onramp process started",tooltip:"Verifying funds with provider"},transfer:{label:"Funds received",tooltip:"Payment in progress"},verify:{label:"Payment completed",tooltip:"Finalizing your payment"}};this.currentSteps=this.currentSteps.map(o=>n[o.key]?{...o,label:n[o.key].label,tooltip:n[o.key].tooltip}:o)}this.setLoadingByKey("wallet"),e?.detail?.amount!==void 0&&(this.currentAmount=e.detail.amount,this.amount=e.detail.amount,v(this.debug,"ICPay Progress: Amount updated to:",e.detail.amount)),e?.detail?.currency&&(this.currentCurrency=e.detail.currency,this.currency=e.detail.currency,v(this.debug,"ICPay Progress: Currency updated to:",e.detail.currency)),e?.detail?.ledgerSymbol&&(this.currentLedgerSymbol=e.detail.ledgerSymbol,this.ledgerSymbol=e.detail.ledgerSymbol,v(this.debug,"ICPay Progress: Current state after method start:",{activeIndex:this.activeIndex,currentAmount:this.currentAmount,currentCurrency:this.currentCurrency,currentLedgerSymbol:this.currentLedgerSymbol})),v(this.debug,"ICPay Progress: Waiting for wallet confirmation before starting progression"),this.requestUpdate()}!this.failed&&!this.completed&&(t==="createPaymentX402Usd"?(this.completeByKey("wallet"),this.setLoadingByKey("await")):t==="sendFundsToLedger"?(this.completeByKey("wallet"),this.completeByKey("await"),this.setLoadingByKey("transfer")):t==="notifyLedgerTransaction"&&(this.completeByKey("wallet"),this.completeByKey("await"),this.setLoadingByKey("transfer")))};this.onMethodSuccess=e=>{let t=e?.detail?.name||"";if((t==="createPayment"||t==="createPaymentUsd"||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){if(this.isOnrampFlow)return;t==="getLedgerBalance"?(this.completeByKey("wallet"),this.setLoadingByKey("await")):t==="sendFundsToLedger"?(this.completeByKey("wallet"),this.completeByKey("await"),this.completeByKey("transfer"),this.setLoadingByKey("verify")):t==="notifyLedgerTransaction"&&(this.completeByKey("wallet"),this.completeByKey("await"),this.completeByKey("transfer"),this.setLoadingByKey("verify"))}};this.onTransactionCreated=e=>{let t=e?.detail?.transactionId||e?.detail?.id;if(v(this.debug,"ICPay Progress: Transaction created event received:",e.detail),!this.failed&&!this.completed){if(this.isOnrampFlow)return;this.completeByKey("wallet"),this.completeByKey("await"),this.setLoadingByKey("transfer")}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",a=e?.detail?.transactionId||e?.detail?.id,n=e?.detail?.metadata||e?.detail?.intent?.metadata||{};if(v(this.debug,"ICPay Progress: Transaction updated event received:",e.detail),!this.failed&&!this.completed&&this.isOnrampFlow){let o=n?.onramp_order_completed===!0||n?.icpay_onramp?.status==="completed"||n?.onrampCompleted===!0;t==="requires_payment"&&!o?(this.completeByKey("wallet"),this.setLoadingByKey("await")):(t==="pending"||t==="processing"||o)&&(this.completeByKey("wallet"),this.completeByKey("await"),this.setLoadingByKey("transfer"))}this.dispatchEvent(new CustomEvent("icpay-progress-transaction-updated",{detail:{status:t,transactionId:a,step:this.activeIndex},bubbles:!0}))};this.onTransactionCompleted=e=>{let t=e?.detail?.transactionId||e?.detail?.id,a=e?.detail?.status||"completed";v(this.debug,"ICPay Progress: Transaction completed event received:",e.detail),v(this.debug,"ICPay Progress: Current state when transaction completed:",{activeIndex:this.activeIndex,completed:this.completed,failed:this.failed,showSuccess:this.showSuccess}),this.completeByKey("transfer"),this.completeByKey("await"),this.completeByKey("verify"),this.completed=!0,this.showSuccess=!0,this.showConfetti=!0,this.isOnrampFlow=!1,this.dispatchEvent(new CustomEvent("icpay-progress-completed",{detail:{transactionId:t,status:a,amount:this.currentAmount||this.amount,currency:this.currentCurrency||this.currency,ledgerSymbol:this.currentLedgerSymbol||this.ledgerSymbol},bubbles:!0})),setTimeout(()=>{this.showConfetti=!1},3e3)};this.onTransactionFailed=e=>{let t=e?.detail?.message||e?.detail?.error?.message||"Transaction failed",a=e?.detail?.error?.code||e?.detail?.code||"UNKNOWN_ERROR",n=e?.detail?.transactionId||e?.detail?.id;v(this.debug,"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.isOnrampFlow=!1,this.dispatchEvent(new CustomEvent("icpay-progress-failed",{detail:{errorMessage:t,errorCode:a,transactionId:n,step:this.activeIndex},bubbles:!0}))};this.onTransactionMismatched=e=>{let t=e?.detail?.requestedAmount,a=e?.detail?.paidAmount,n=e?.detail?.transactionId||e?.detail?.id;this.failed=!0;let o=t!=null?String(t):"unknown",l=a!=null?String(a):"unknown";this.errorMessage=`Amount mismatch. Requested ${o}, paid ${l}.`,this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",this.errorMessage),this.stopAutomaticProgression(),this.open=!0,this.isOnrampFlow=!1,this.dispatchEvent(new CustomEvent("icpay-progress-failed",{detail:{errorMessage:this.errorMessage,errorCode:"MISMATCHED_AMOUNT",transactionId:n,step:this.activeIndex,requestedAmount:t,paidAmount:a},bubbles:!0}))};this.onMethodError=e=>{let t=e?.detail?.name||"",a=e?.detail?.error?.message||e?.detail?.message||"An error occurred",n=e?.detail?.error?.code||e?.detail?.code||"METHOD_ERROR";v(this.debug,"ICPay Progress: Method error event received:",e.detail),(t?.startsWith("createPayment")||t==="sendUsd"||t==="pay"||t==="unlock"||t==="tip"||t==="donate"||t==="order")&&(this.failed=!0,this.errorMessage=this.transformErrorMessage(a),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",a),this.stopAutomaticProgression(),this.open=!0,this.isOnrampFlow=!1,this.dispatchEvent(new CustomEvent("icpay-progress-error",{detail:{methodName:t,errorMessage:a,errorCode:n,step:this.activeIndex},bubbles:!0})))};this.onSDKError=e=>{let t=e?.detail?.message||"SDK error occurred",a=e?.detail?.code||"SDK_ERROR";v(this.debug,"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.isOnrampFlow=!1,this.dispatchEvent(new CustomEvent("icpay-progress-sdk-error",{detail:{errorMessage:t,errorCode:a,step:this.activeIndex},bubbles:!0}))};this.onWalletConnected=e=>{let t=e?.detail?.walletType||"unknown";v(this.debug,"ICPay Progress: Wallet connected event received:",e.detail),this.completeByKey("wallet"),this.setLoadingByKey("await"),this.startTransitionToProgress(),this.dispatchEvent(new CustomEvent("icpay-progress-wallet-connected",{detail:{walletType:t,step:this.activeIndex},bubbles:!0})),this.currentWalletType=t};this.onOnrampOpened=e=>{!this.isOnrampFlow||this.failed||this.completed||(this.completeByKey("wallet"),this.setLoadingByKey("await"))};this.onWalletDisconnected=e=>{let t=e?.detail?.walletType||"unknown";v(this.debug,"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.currentWalletType=null};this.onBalanceCheck=e=>{let t=e?.detail?.hasBalance||!1,a=e?.detail?.balance||0;v(this.debug,"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.showWalletSelector=!1,this.dispatchEvent(new CustomEvent("icpay-progress-insufficient-balance",{detail:{balance:a,required:this.currentAmount||this.amount,step:this.activeIndex},bubbles:!0})))};this.onLedgerVerified=e=>{let t=e?.detail?.ledgerId||e?.detail?.canisterId,a=e?.detail?.symbol||"unknown";v(this.debug,"ICPay Progress: Ledger verified event received:",e.detail),a&&a!=="unknown"&&(this.currentLedgerSymbol=a,this.ledgerSymbol=a),this.dispatchEvent(new CustomEvent("icpay-progress-ledger-verified",{detail:{ledgerId:t,symbol:a,step:this.activeIndex},bubbles:!0}))};this.onWidgetPayment=e=>{let t=e?.detail?.amount,a=e?.detail?.currency,n=e?.detail?.ledgerSymbol;if(v(this.debug,"ICPay Progress: Widget payment event received:",e.detail),t!==void 0&&(this.currentAmount=t,this.amount=t),a&&(this.currentCurrency=a,this.currency=a),n&&(this.currentLedgerSymbol=n,this.ledgerSymbol=n),!this.failed){for(let o=this.activeIndex;o<this.currentSteps.length;o++)this.updateStepStatus(o,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-payment",{detail:{amount:t,currency:a,ledgerSymbol:n,step:this.activeIndex},bubbles:!0}))};this.onWidgetError=e=>{let t=e?.detail?.message||"Widget error occurred",a=e?.detail?.code||"WIDGET_ERROR";v(this.debug,"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:a,step:this.activeIndex},bubbles:!0}))};this.onWidgetUnlock=e=>{let t=e?.detail?.amount,a=e?.detail?.currency;if(v(this.debug,"ICPay Progress: Widget unlock event received:",e.detail),!this.failed){for(let n=this.activeIndex;n<this.currentSteps.length;n++)this.updateStepStatus(n,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-unlock",{detail:{amount:t,currency:a,step:this.activeIndex},bubbles:!0}))};this.onWidgetTip=e=>{let t=e?.detail?.amount,a=e?.detail?.currency;if(v(this.debug,"ICPay Progress: Widget tip event received:",e.detail),!this.failed){for(let n=this.activeIndex;n<this.currentSteps.length;n++)this.updateStepStatus(n,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-tip",{detail:{amount:t,currency:a,step:this.activeIndex},bubbles:!0}))};this.onWidgetDonation=e=>{let t=e?.detail?.amount,a=e?.detail?.currency;if(v(this.debug,"ICPay Progress: Widget donation event received:",e.detail),!this.failed){for(let n=this.activeIndex;n<this.currentSteps.length;n++)this.updateStepStatus(n,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-donation",{detail:{amount:t,currency:a,step:this.activeIndex},bubbles:!0}))};this.onWidgetCoffee=e=>{let t=e?.detail?.amount,a=e?.detail?.currency;if(v(this.debug,"ICPay Progress: Widget coffee event received:",e.detail),!this.failed){for(let n=this.activeIndex;n<this.currentSteps.length;n++)this.updateStepStatus(n,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-coffee",{detail:{amount:t,currency:a,step:this.activeIndex},bubbles:!0}))};this.onWalletCancelled=e=>{try{let t=this.getStepIndexByKey("wallet"),a=this.getStepIndexByKey("await"),n=this.getStepIndexByKey("transfer"),o=this.getStepIndexByKey("verify"),l=this.currentSteps&&this.currentSteps.length>0&&this.currentSteps.some((h,c)=>t>=0&&c>t?h.status==="loading"||h.status==="completed":!1),p=(t>=0?this.currentSteps[t]:null)?.status==="completed";if(!l&&!p){this.open=!1,this.activeIndex=0,this.currentSteps=this.currentSteps.map(h=>({...h,status:"pending"})),this.requestUpdate();return}this.open=!0,t>=0&&(this.activeIndex=t,this.currentSteps[t]={...this.currentSteps[t],tooltip:"Wallet connection cancelled",status:"error"},this.requestUpdate())}catch{}};this.onWalletError=e=>{try{let t=e?.detail?.message||"Wallet error",a=this.transformErrorMessage(t);this.open=!0;let n=this.getStepIndexByKey("wallet");n>=0&&(this.activeIndex=n,this.currentSteps[n]={...this.currentSteps[n],tooltip:"Wallet connection failed",status:"error",errorMessage:a},this.requestUpdate())}catch{}}}connectedCallback(){super.connectedCallback();try{if(Te(this,this.theme),!this.theme&&typeof document<"u"){let e=document.documentElement.getAttribute("data-icpay-theme")||document.documentElement.getAttribute("data-theme");e==="light"||e==="dark"?this.setAttribute("data-theme",e):this.setAttribute("data-theme","light")}}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{if(Te(this,this.theme),!this.theme&&typeof document<"u"){let t=document.documentElement.getAttribute("data-icpay-theme")||document.documentElement.getAttribute("data-theme");t==="light"||t==="dark"?this.setAttribute("data-theme",t):this.setAttribute("data-theme","light")}}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-wallet-cancelled",this.onWalletCancelled),window.addEventListener("icpay-sdk-wallet-error",this.onWalletError),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-transaction-mismatched",this.onTransactionMismatched),window.addEventListener("icpay-onramp-opened",this.onOnrampOpened),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-wallet-cancelled",this.onWalletCancelled),window.removeEventListener("icpay-sdk-wallet-error",this.onWalletError),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-transaction-mismatched",this.onTransactionMismatched),window.removeEventListener("icpay-onramp-opened",this.onOnrampOpened),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"),v(this.debug,"ICPay Progress: Starting automatic progression from step:",this.activeIndex),this.progressionTimer=setInterval(()=>{if(this.failed||this.completed){this.stopAutomaticProgression();return}v(this.debug,"ICPay Progress: Processing step:",this.activeIndex),this.updateStepStatus(this.activeIndex,"completed"),this.activeIndex<this.currentSteps.length-1?(this.activeIndex++,this.updateStepStatus(this.activeIndex,"loading"),v(this.debug,"ICPay Progress: Auto-progressed to step:",this.activeIndex)):(this.stopAutomaticProgression(),v(this.debug,"ICPay Progress: All steps completed, waiting for transaction completion")),this.requestUpdate()},3e3)}stopAutomaticProgression(){this.progressionTimer&&(clearInterval(this.progressionTimer),this.progressionTimer=null)}updateStepStatus(e,t,a){if(e>=0&&e<this.currentSteps.length){let n=this.currentSteps[e],o=n.status;n.status=t,t==="completed"&&(n.timestamp=this.getCurrentTime()),t==="error"&&a&&(n.errorMessage=this.transformErrorMessage(a)),o!==t&&v(this.debug,`ICPay Progress: Step ${e} (${n.label}) status changed from ${o} to ${t}`),this.requestUpdate()}}getCurrentTime(){return new Date().toLocaleTimeString("en-US",{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit"})}getStepIcon(e){return e.status==="error"?P`<div class="error-x">✕</div>`:P`<div class="spinner"></div>`}getStepIndexByKey(e){return this.currentSteps.findIndex(t=>t.key===e)}setLoadingByKey(e){let t=this.getStepIndexByKey(e);t>=0&&(this.activeIndex=t,this.updateStepStatus(t,"loading"),e==="verify"&&(this.confirmLoadingStartedAt=Date.now()))}completeByKey(e){let t=this.getStepIndexByKey(e);t>=0&&(this.updateStepStatus(t,"completed"),this.activeIndex=t)}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},(a,n)=>n),t=["#0066FF","#ef4444","#10b981","#f59e0b","#8b5cf6"];return P`
143
+ <div class="confetti">
144
+ ${e.map(a=>P`
145
+ <div
146
+ class="confetti-piece"
147
+ style="
148
+ left: ${Math.random()*100}%;
149
+ top: ${Math.random()*100}%;
150
+ background-color: ${t[Math.floor(Math.random()*t.length)]};
151
+ animation-delay: ${Math.random()*2}s;
152
+ animation-duration: ${2+Math.random()*2}s;
153
+ "
154
+ ></div>
155
+ `)}
156
+ </div>
157
+ `}renderSuccessState(){let e=this.currentAmount||this.amount;return v(this.debug,"ICPay Progress: Rendering success state with:",{displayAmount:e,currentAmount:this.currentAmount,amount:this.amount,currentCurrency:this.currentCurrency,currency:this.currency,currentLedgerSymbol:this.currentLedgerSymbol,ledgerSymbol:this.ledgerSymbol}),P`
158
+ <div class="success-center">
159
+ <div class="success-container">
160
+ <div class="success-icon">
161
+ <svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
162
+ <path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" />
163
+ </svg>
164
+ </div>
165
+ <h2 class="success-title">Payment Complete!</h2>
166
+ <p class="success-message">Your payment of ${e} USD has been successfully processed.</p>
167
+ <div class="success-actions">
168
+ <button class="btn btn-primary" @click=${()=>{this.open=!1}}>Close</button>
169
+ </div>
170
+ </div>
171
+ </div>
172
+ `}renderErrorState(){return this.errorMessage?.includes("Insufficient balance")||!1?this.renderInsufficientFundsError():this.renderGenericError()}renderInsufficientFundsError(){let e=this.currentAmount||this.amount;return P`
173
+ <div class="insufficient-funds-container">
174
+ <div class="payment-summary">
175
+ <div class="payment-amount">Pay $${e} with crypto</div>
176
+ </div>
177
+
178
+ <div class="error-notification">
179
+ <div class="error-content">
180
+ <div class="error-icon-small">
181
+ <svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
182
+ <path stroke-linecap="round" stroke-linejoin="round" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.732-.833-2.5 0L4.268 16.5c-.77.833.192 2.5 1.732 2.5z" />
183
+ </svg>
184
+ </div>
185
+ <div class="error-text">Insufficient balance for this transaction</div>
186
+ </div>
187
+ </div>
188
+
189
+ <div class="error-actions">
190
+ <button class="btn btn-secondary" @click=${()=>this.requestSwitchAccount()} title="Switch to a different account">
191
+ <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" style="width: 16px; height: 16px;">
192
+ <path stroke-linecap="round" stroke-linejoin="round" d="M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4" />
193
+ </svg>
194
+ Switch Account
195
+ </button>
196
+ <button class="btn btn-primary" @click=${()=>{this.open=!1}}>
197
+ <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" style="width: 16px; height: 16px;">
198
+ <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
199
+ </svg>
200
+ Close
201
+ </button>
202
+ </div>
203
+ </div>
204
+ `}renderGenericError(){return P`
205
+ <div class="error-container">
206
+ <div class="error-icon-large">
207
+ <svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
208
+ <path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
209
+ </svg>
210
+ </div>
211
+ <h2 class="error-title">Transaction Failed</h2>
212
+ <p class="error-message-text">${this.errorMessage}</p>
213
+ <div class="error-actions">
214
+ <button class="btn btn-secondary" @click=${()=>this.requestSwitchAccount()} title="Switch to a different account">
215
+ <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" style="width: 16px; height: 16px;">
216
+ <path stroke-linecap="round" stroke-linejoin="round" d="M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4" />
217
+ </svg>
218
+ Switch Account
219
+ </button>
220
+ <button class="btn btn-primary" @click=${()=>{this.open=!1}}>
221
+ <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" style="width: 16px; height: 16px;">
222
+ <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
223
+ </svg>
224
+ Close
225
+ </button>
226
+ </div>
227
+ </div>
228
+ `}requestSwitchAccount(){try{this.open=!1;let e=this.currentWalletType||"unknown";window.dispatchEvent(new CustomEvent("icpay-switch-account",{detail:{walletType:e}}))}catch{}}handleAddFunds(){try{window.dispatchEvent(new CustomEvent("icpay-add-funds",{detail:{amount:this.currentAmount||this.amount,currency:this.currentLedgerSymbol||this.currentCurrency||this.currency}})),this.open=!1}catch(e){console.error("Error handling add funds:",e)}}startTransitionToProgress(){this.isTransitioning=!0,this.requestUpdate(),setTimeout(()=>{this.showWalletSelector=!1,this.isTransitioning=!1,this.requestUpdate()},400)}renderProgressContent(){return this.showSuccess?this.renderSuccessState():this.failed?this.renderErrorState():P`
229
+ <div class="progress-container">
230
+ <div class="progress-header">
231
+ <span class="progress-spacer"></span>
232
+ <h3 class="progress-title">Processing</h3>
233
+ </div>
234
+ ${this.renderConfirmTip()}
235
+ <div class="progress-steps">
236
+ ${this.currentSteps.map((e,t)=>P`
237
+ <div class="step ${t===this.activeIndex?"active":""} ${e.status==="completed"?"completed":""} ${e.status==="error"?"error":""}">
238
+ <div class="step-icon">
239
+ ${this.getStepIcon(e)}
240
+ </div>
241
+ <div class="step-content">
242
+ <div class="step-title">${e.label}</div>
243
+ <div class="step-description">${e.tooltip}</div>
244
+ ${e.status==="error"&&e.errorMessage?P`
245
+ <div class="step-error-message">${e.errorMessage}</div>
246
+ `:""}
247
+ </div>
248
+ </div>
249
+ `)}
250
+ </div>
251
+ </div>
252
+ `}renderConfirmTip(){try{let e=this.getStepIndexByKey("verify");if(e<0||!(this.activeIndex===e&&this.currentSteps[e]?.status==="loading"))return null;let a=this.confirmLoadingStartedAt||0;return(a?Date.now()-a:0)<3e4?null:P`<p class="progress-subtitle" style="margin-top:8px;color:#60a5fa">Verification can take from 30 seconds up to 10 minutes depending on the amount. Please wait…</p>`}catch{return null}}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,this.showWalletSelector=!1,this.isTransitioning=!1}renderStep(e,t){return P`
253
+ <div class="step-item ${e.status}">
254
+ <div class="step-icon">
255
+ ${this.getStepIcon(e)}
256
+ </div>
257
+ <div class="step-content">
258
+ <div class="step-title">
259
+ ${e.status==="completed"?"COMPLETED":e.label}
260
+ </div>
261
+ ${e.status==="completed"?P`
262
+ <div class="step-subtitle">
263
+ ${e.timestamp} - ${e.tooltip}
264
+ </div>
265
+ `:e.status==="error"&&e.errorMessage?P`
266
+ <div class="step-error">${e.errorMessage}</div>
267
+ `:P`
268
+ <div class="step-subtitle">${e.tooltip}</div>
269
+ `}
270
+ </div>
271
+ </div>
272
+ `}get isWalletConnectLoading(){try{let e=this.currentSteps.findIndex(t=>t.key==="wallet");return e<0?!1:this.currentSteps[e].status==="loading"&&!this.failed&&!this.showSuccess}catch{return!1}}render(){return this.suspended?null:P`
273
+ ${this.open?P`
274
+ ${this.renderConfetti()}
275
+ <div class="modal-overlay active">
276
+ <div class="modal-container">
277
+ ${this.showSuccess?null:P`<button class="close-button" @click=${()=>this.closeProgress()} aria-label="Close" title="Close">✕</button>`}
278
+ <div class="modal-content ${this.isTransitioning?"transitioning":""}">
279
+ ${this.renderProgressContent()}
280
+ </div>
281
+ </div>
282
+ </div>
283
+ `:null}
284
+ `}};b.styles=Ge`
285
+ :host {
286
+ display: block;
287
+ font-family: var(--icpay-font, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
288
+ color: var(--icpay-foreground);
289
+ background: var(--icpay-background);
290
+
291
+ /* Theme-aware color variables - Light mode defaults */
292
+ --icpay-background: #ffffff;
293
+ --icpay-foreground: #171717;
294
+ --icpay-muted-foreground: #6b7280;
295
+ --icpay-accent-foreground: #ffffff;
296
+ --icpay-primary: #3b82f6;
297
+ --icpay-destructive: #ef4444;
298
+ --icpay-primary-foreground: #ffffff;
299
+ --icpay-secondary: #f3f4f6;
300
+ --icpay-secondary-foreground: #171717;
301
+ --icpay-accent: #f9fafb;
302
+ --icpay-muted: #f9fafb;
303
+ --icpay-border: #e5e7eb;
304
+ --icpay-input: #e5e7eb;
305
+ --icpay-ring: #3b82f6;
306
+ --icpay-destructive-foreground: #ffffff;
307
+
308
+ /* Status colors */
309
+ --icpay-success-bg: rgba(16, 185, 129, 0.1);
310
+ --icpay-success-text: #059669;
311
+ --icpay-success-border: rgba(16, 185, 129, 0.3);
312
+ --icpay-warning-bg: rgba(245, 158, 11, 0.1);
313
+ --icpay-warning-text: #d97706;
314
+ --icpay-warning-border: rgba(245, 158, 11, 0.3);
315
+ --icpay-error-bg: rgba(239, 68, 68, 0.1);
316
+ --icpay-error-text: #dc2626;
317
+ --icpay-error-border: rgba(239, 68, 68, 0.3);
318
+ --icpay-processing-bg: rgba(59, 130, 246, 0.1);
319
+ --icpay-processing-text: #2563eb;
320
+ --icpay-processing-border: rgba(59, 130, 246, 0.3);
321
+
322
+ /* Use new color palette variables */
323
+ --icpay-text-primary: var(--icpay-foreground);
324
+ --icpay-text-secondary: var(--icpay-muted-foreground);
325
+ --icpay-text-muted: var(--icpay-muted-foreground);
326
+ --icpay-bg-primary: var(--icpay-background);
327
+ --icpay-bg-secondary: var(--icpay-secondary);
328
+ --icpay-bg-secondary-hover: var(--icpay-accent);
329
+ --icpay-bg-success: var(--icpay-success-bg);
330
+ --icpay-bg-error: var(--icpay-error-bg);
331
+ --icpay-border-primary: var(--icpay-border);
332
+ --icpay-border-secondary: var(--icpay-border);
333
+ --icpay-border-success: var(--icpay-success-border);
334
+ --icpay-border-error: var(--icpay-error-border);
335
+ --icpay-accent-primary: var(--icpay-primary);
336
+ --icpay-accent-success: var(--icpay-success-text);
337
+ --icpay-accent-error: var(--icpay-error-text);
338
+
339
+ --icpay-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
340
+ --icpay-shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
341
+ --icpay-shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
342
+ --icpay-shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.1);
343
+
344
+ --icpay-radius-sm: 6px;
345
+ --icpay-radius-md: 8px;
346
+ --icpay-radius-lg: 12px;
347
+ --icpay-radius-xl: 16px;
348
+
349
+ --icpay-spacing-xs: 4px;
350
+ --icpay-spacing-sm: 8px;
351
+ --icpay-spacing-md: 12px;
352
+ --icpay-spacing-lg: 16px;
353
+ --icpay-spacing-xl: 24px;
354
+ }
355
+
356
+ :host([data-theme="dark"]) {
357
+ /* Dark mode (from COLOR_PALETTE.md) */
358
+ --icpay-background: hsl(222.2 84% 4.9%);
359
+ --icpay-foreground: hsl(210 40% 98%);
360
+ --icpay-muted-foreground: hsl(215 20.2% 65.1%);
361
+ --icpay-accent-foreground: hsl(210 40% 98%);
362
+ --icpay-primary: hsl(210 40% 98%);
363
+ --icpay-destructive: hsl(0 62.8% 30.6%);
364
+ --icpay-primary-foreground: hsl(222.2 47.4% 11.2%);
365
+ --icpay-secondary: hsl(217.2 32.6% 17.5%);
366
+ --icpay-secondary-foreground: hsl(210 40% 98%);
367
+ --icpay-accent: hsl(217.2 32.6% 17.5%);
368
+ --icpay-muted: hsl(217.2 32.6% 17.5%);
369
+ --icpay-border: hsl(217.2 32.6% 30%);
370
+ --icpay-input: hsl(217.2 32.6% 17.5%);
371
+ --icpay-ring: hsl(210 40% 98%);
372
+ --icpay-destructive-foreground: hsl(210 40% 98%);
373
+
374
+ /* Status colors for dark mode */
375
+ --icpay-success-bg: rgba(16, 185, 129, 0.1);
376
+ --icpay-success-text: #34d399;
377
+ --icpay-success-border: rgba(16, 185, 129, 0.3);
378
+ --icpay-warning-bg: rgba(245, 158, 11, 0.1);
379
+ --icpay-warning-text: #fbbf24;
380
+ --icpay-warning-border: rgba(245, 158, 11, 0.3);
381
+ --icpay-error-bg: rgba(239, 68, 68, 0.1);
382
+ --icpay-error-text: #f87171;
383
+ --icpay-error-border: rgba(239, 68, 68, 0.3);
384
+ --icpay-processing-bg: rgba(59, 130, 246, 0.1);
385
+ --icpay-processing-text: #60a5fa;
386
+ --icpay-processing-border: rgba(59, 130, 246, 0.3);
387
+ }
388
+
389
+ .modal-overlay {
390
+ position: fixed !important;
391
+ top: 0 !important;
392
+ left: 0 !important;
393
+ right: 0 !important;
394
+ bottom: 0 !important;
395
+ background: rgba(0, 0, 0, 0.5);
396
+ backdrop-filter: blur(8px);
397
+ display: flex;
398
+ align-items: center;
399
+ justify-content: center;
400
+ z-index: 99999 !important;
401
+ opacity: 0;
402
+ visibility: hidden;
403
+ transition: opacity 0.3s ease, visibility 0.3s ease;
404
+ /* Ensure modal breaks out of any parent constraints */
405
+ transform: none !important;
406
+ will-change: opacity, visibility;
407
+ isolation: isolate;
408
+ }
409
+
410
+ @media (max-width: 768px) {
411
+ .modal-overlay {
412
+ align-items: flex-end;
413
+ justify-content: stretch;
414
+ }
415
+ }
416
+
417
+ .modal-content {
418
+ transition: opacity 0.4s ease, transform 0.4s ease;
419
+ opacity: 1;
420
+ transform: translateY(0);
421
+ flex: 1;
422
+ }
423
+
424
+ .modal-content.transitioning {
425
+ opacity: 0;
426
+ transform: translateY(20px);
427
+ }
428
+
429
+ .wallet-selector-container {
430
+ width: 100%;
431
+ }
432
+
433
+ .wallet-selector-title {
434
+ color: var(--icpay-text-primary);
435
+ margin: 0 48px var(--icpay-spacing-lg) 0;
436
+ font-size: 18px;
437
+ font-weight: 600;
438
+ }
439
+
440
+ .wallet-options {
441
+ display: flex;
442
+ flex-direction: column;
443
+ gap: var(--icpay-spacing-sm);
444
+ }
445
+
446
+ .wallet-option {
447
+ width: 100%;
448
+ padding: 12px 16px;
449
+ background: var(--icpay-secondary);
450
+ border: 1px solid var(--icpay-border);
451
+ border-radius: 8px;
452
+ display: flex;
453
+ align-items: center;
454
+ gap: 12px;
455
+ cursor: pointer;
456
+ transition: all 0.3s ease;
457
+ box-sizing: border-box;
458
+ }
459
+
460
+ .wallet-option:hover {
461
+ background: var(--icpay-accent);
462
+ border-color: var(--icpay-border);
463
+ }
464
+
465
+ .wallet-icon {
466
+ width: 48px;
467
+ height: 48px;
468
+ border-radius: 12px;
469
+ background: var(--icpay-primary);
470
+ display: flex;
471
+ align-items: center;
472
+ justify-content: center;
473
+ flex-shrink: 0;
474
+ }
475
+
476
+ .wallet-icon img {
477
+ width: 40px;
478
+ height: 40px;
479
+ object-fit: cover;
480
+ border-radius: 12px;
481
+ }
482
+
483
+ .wallet-icon-placeholder {
484
+ color: var(--icpay-primary-foreground);
485
+ font-size: 12px;
486
+ font-weight: bold;
487
+ }
488
+
489
+ .wallet-label {
490
+ font-weight: 500;
491
+ font-size: 14px;
492
+ color: var(--icpay-foreground);
493
+ }
494
+
495
+ .modal-overlay.active {
496
+ opacity: 1;
497
+ visibility: visible;
498
+ }
499
+
500
+ .modal-container {
501
+ background: var(--icpay-background);
502
+ border: 1px solid var(--icpay-border);
503
+ border-radius: 24px;
504
+ padding: 24px;
505
+ max-width: 420px;
506
+ width: 100%;
507
+ height: 460px;
508
+ box-shadow: var(--icpay-shadow-xl);
509
+ transform: translateY(20px);
510
+ transition: transform 0.3s ease;
511
+ position: relative;
512
+ display: flex;
513
+ flex-direction: column;
514
+ margin: auto;
515
+ }
516
+
517
+ @media (max-width: 768px) {
518
+ .modal-container {
519
+ max-width: 100%;
520
+ width: 100%;
521
+ height: 70vh;
522
+ max-height: 70vh;
523
+ border-radius: 24px 24px 0 0;
524
+ margin: 0;
525
+ transform: translateY(100%);
526
+ overflow: hidden;
527
+ display: flex;
528
+ flex-direction: column;
529
+ }
530
+ .modal-overlay.active .modal-container {
531
+ transform: translateY(0);
532
+ }
533
+ .progress-steps {
534
+ overflow-y: auto;
535
+ flex: 1;
536
+ min-height: 0;
537
+ }
538
+ }
539
+
540
+ .modal-overlay.active .modal-container {
541
+ transform: translateY(0);
542
+ }
543
+
544
+ .close-button {
545
+ position: absolute;
546
+ top: var(--icpay-spacing-lg);
547
+ right: var(--icpay-spacing-lg);
548
+ width: 32px;
549
+ height: 32px;
550
+ display: flex;
551
+ align-items: center;
552
+ justify-content: center;
553
+ color: var(--icpay-text-secondary);
554
+ cursor: pointer;
555
+ border: none;
556
+ background: transparent;
557
+ font-size: 20px;
558
+ transition: all 0.2s;
559
+ z-index: 10;
560
+ }
561
+
562
+ .close-button:hover {
563
+ color: var(--icpay-text-primary);
564
+ }
565
+
566
+ .progress-header {
567
+ display:flex;
568
+ align-items:center;
569
+ margin-bottom: 20px;
570
+ padding-bottom: 20px;
571
+ border-bottom: 1px solid var(--icpay-border);
572
+ flex-shrink: 0;
573
+ }
574
+ .progress-title {
575
+ font-size: 20px;
576
+ font-weight: 600;
577
+ margin: 0;
578
+ color: var(--icpay-foreground);
579
+ flex: 1;
580
+ text-align: center;
581
+ margin-right: 40px;
582
+ }
583
+ .progress-spacer { width:24px; display:inline-block; margin-right:16px; }
584
+ .progress-subtitle { color: var(--icpay-text-secondary); font-size: 14px; }
585
+ .progress-steps {
586
+ margin-bottom: var(--icpay-spacing-xl);
587
+ display: flex;
588
+ flex-direction: column;
589
+ gap: 24px;
590
+ overflow-y: auto;
591
+ flex: 1;
592
+ }
593
+ .step {
594
+ width: 100%;
595
+ padding: 16px;
596
+ background: var(--icpay-secondary);
597
+ border: none;
598
+ border-radius: 12px;
599
+ display: flex;
600
+ align-items: flex-start;
601
+ gap: 16px;
602
+ transition: all 0.3s ease;
603
+ cursor: default;
604
+ box-sizing: border-box;
605
+ }
606
+ .step.active {
607
+ background: var(--icpay-accent);
608
+ }
609
+ .step.completed {
610
+ opacity: 1;
611
+ background: var(--icpay-secondary);
612
+ }
613
+
614
+ .step.error {
615
+ opacity: 1;
616
+ background: var(--icpay-error-bg);
617
+ border: 1px solid var(--icpay-error-border);
618
+ }
619
+ .step-icon {
620
+ width: 40px;
621
+ height: 40px;
622
+ border-radius: 0;
623
+ background: transparent;
624
+ display: flex;
625
+ align-items: center;
626
+ justify-content: center;
627
+ transition: all 0.3s ease;
628
+ position: relative;
629
+ flex-shrink: 0;
630
+ }
631
+ .step.active .step-icon { }
632
+ .step.completed .step-icon { }
633
+
634
+ .step.error .step-icon { background: transparent; }
635
+ .step-icon svg {
636
+ width: 20px;
637
+ height: 20px;
638
+ stroke: var(--icpay-text-primary);
639
+ transition: stroke 0.3s ease;
640
+ }
641
+ .step-content {
642
+ flex: 1;
643
+ display: flex;
644
+ flex-direction: column;
645
+ gap: 0;
646
+ }
647
+ .step-title {
648
+ font-weight: 500;
649
+ font-size: 16px;
650
+ color: var(--icpay-foreground);
651
+ transition: color 0.3s ease;
652
+ margin: 0;
653
+ }
654
+ .step-description {
655
+ font-size: 14px;
656
+ color: var(--icpay-muted-foreground);
657
+ margin: 0;
658
+ }
659
+
660
+ .step-error-message {
661
+ font-size: 11px;
662
+ color: var(--icpay-error-text);
663
+ margin-top: 4px;
664
+ padding: 4px 8px;
665
+ background: var(--icpay-error-bg);
666
+ border-radius: 4px;
667
+ border-left: 3px solid var(--icpay-error-text);
668
+ }
669
+ /* Spinner exactly like in design: wrapper + ::before ring */
670
+ .spinner {
671
+ width: 40px;
672
+ height: 40px;
673
+ margin-right: 0;
674
+ position: relative;
675
+ flex-shrink: 0;
676
+ }
677
+ .spinner::before {
678
+ content: '';
679
+ position: absolute;
680
+ width: 100%;
681
+ height: 100%;
682
+ border: 3px solid var(--icpay-border);
683
+ border-top: 3px solid var(--icpay-primary);
684
+ border-radius: 50%;
685
+ animation: spin 1s linear infinite;
686
+ box-sizing: border-box;
687
+ }
688
+ /* Completed: replace ring with filled green circle + tick */
689
+ .step.completed .spinner::before { display: none; }
690
+ .step.completed .spinner::after {
691
+ content: '✓';
692
+ position: absolute;
693
+ top: 0;
694
+ left: 0;
695
+ width: 100%;
696
+ height: 100%;
697
+ background-color: var(--icpay-success-text);
698
+ border-radius: 50%;
699
+ display: flex;
700
+ align-items: center;
701
+ justify-content: center;
702
+ color: var(--icpay-background);
703
+ font-size: 24px;
704
+ font-weight: bold;
705
+ box-sizing: border-box;
706
+ }
707
+
708
+ /* Error icon (pastel red) like success's green circle */
709
+ .error-x {
710
+ width: 40px;
711
+ height: 40px;
712
+ border-radius: 50%;
713
+ background-color: var(--icpay-error-text);
714
+ display: flex;
715
+ align-items: center;
716
+ justify-content: center;
717
+ color: var(--icpay-background);
718
+ font-size: 20px;
719
+ font-weight: bold;
720
+ box-sizing: border-box;
721
+ }
722
+
723
+ /* Completed icon to match design proportions */
724
+ .complete-icon {
725
+ width: 40px;
726
+ height: 40px;
727
+ position: relative;
728
+ flex-shrink: 0;
729
+ display: flex;
730
+ align-items: center;
731
+ justify-content: center;
732
+ }
733
+ .complete-icon::before {
734
+ content: '';
735
+ position: absolute;
736
+ inset: 0;
737
+ border: 3px solid var(--icpay-border);
738
+ border-radius: 50%;
739
+ background: var(--icpay-secondary);
740
+ box-sizing: border-box;
741
+ }
742
+ .complete-icon svg {
743
+ position: relative;
744
+ width: 20px;
745
+ height: 20px;
746
+ stroke: var(--icpay-foreground);
747
+ display: block;
748
+ }
749
+
750
+ .error-container {
751
+ height: 100%;
752
+ display: flex;
753
+ align-items: center;
754
+ justify-content: center;
755
+ flex-direction: column;
756
+ text-align: center;
757
+ }
758
+
759
+ .error-icon-large {
760
+ width: 64px;
761
+ height: 64px;
762
+ margin: 0 auto var(--icpay-spacing-lg);
763
+ background: var(--icpay-error-text);
764
+ border-radius: var(--icpay-radius-xl);
765
+ display: flex;
766
+ align-items: center;
767
+ justify-content: center;
768
+ }
769
+
770
+ .error-icon-large svg {
771
+ width: 32px;
772
+ height: 32px;
773
+ stroke: var(--icpay-background);
774
+ stroke-width: 2;
775
+ }
776
+
777
+ .error-title {
778
+ font-size: 20px;
779
+ font-weight: 600;
780
+ margin-bottom: var(--icpay-spacing-sm);
781
+ color: var(--icpay-text-primary);
782
+ }
783
+
784
+ .error-message-text {
785
+ color: var(--icpay-text-secondary);
786
+ margin-bottom: var(--icpay-spacing-xl);
787
+ font-size: 14px;
788
+ }
789
+
790
+ .error-details {
791
+ background: var(--icpay-error-bg);
792
+ border: 1px solid var(--icpay-error-border);
793
+ border-radius: var(--icpay-radius-md);
794
+ padding: var(--icpay-spacing-lg);
795
+ margin-bottom: var(--icpay-spacing-xl);
796
+ text-align: left;
797
+ }
798
+
799
+ .error-detail-item {
800
+ display: flex;
801
+ justify-content: space-between;
802
+ align-items: center;
803
+ margin-bottom: var(--icpay-spacing-sm);
804
+ }
805
+
806
+ .error-detail-item:last-child {
807
+ margin-bottom: 0;
808
+ }
809
+
810
+ .error-detail-label {
811
+ font-size: 14px;
812
+ color: var(--icpay-text-secondary);
813
+ font-weight: 500;
814
+ }
815
+
816
+ .error-detail-value {
817
+ font-size: 14px;
818
+ color: var(--icpay-text-primary);
819
+ font-weight: 600;
820
+ }
821
+
822
+ .error-actions {
823
+ display: flex;
824
+ gap: var(--icpay-spacing-sm);
825
+ justify-content: center;
826
+ }
827
+
828
+ .insufficient-funds-container {
829
+ width: 100%;
830
+ }
831
+
832
+ .payment-summary {
833
+ background: var(--icpay-secondary);
834
+ border-radius: var(--icpay-radius-md);
835
+ padding: var(--icpay-spacing-lg);
836
+ margin-bottom: var(--icpay-spacing-lg);
837
+ text-align: center;
838
+ }
839
+
840
+ .payment-amount {
841
+ font-size: 16px;
842
+ font-weight: 600;
843
+ color: var(--icpay-text-primary);
844
+ }
845
+
846
+ .error-notification {
847
+ background: var(--icpay-warning-bg);
848
+ border: 1px solid var(--icpay-warning-border);
849
+ border-radius: var(--icpay-radius-md);
850
+ padding: var(--icpay-spacing-lg);
851
+ margin-bottom: var(--icpay-spacing-xl);
852
+ display: flex;
853
+ align-items: center;
854
+ justify-content: space-between;
855
+ gap: var(--icpay-spacing-lg);
856
+ }
857
+
858
+ .error-content {
859
+ display: flex;
860
+ align-items: center;
861
+ gap: var(--icpay-spacing-md);
862
+ flex: 1;
863
+ }
864
+
865
+ .error-icon-small {
866
+ width: 20px;
867
+ height: 20px;
868
+ color: var(--icpay-warning-text);
869
+ flex-shrink: 0;
870
+ }
871
+
872
+ .error-icon-small svg {
873
+ width: 100%;
874
+ height: 100%;
875
+ }
876
+
877
+ .error-text {
878
+ font-size: 14px;
879
+ font-weight: 500;
880
+ color: var(--icpay-warning-text);
881
+ }
882
+
883
+ .add-funds-btn {
884
+ background: var(--icpay-secondary);
885
+ border: 1px solid var(--icpay-border);
886
+ border-radius: var(--icpay-radius-sm);
887
+ padding: 8px 16px;
888
+ color: var(--icpay-foreground);
889
+ font-size: 14px;
890
+ font-weight: 500;
891
+ cursor: pointer;
892
+ transition: all 0.3s ease;
893
+ flex-shrink: 0;
894
+ }
895
+
896
+ .add-funds-btn:hover {
897
+ background: var(--icpay-accent);
898
+ border-color: var(--icpay-border);
899
+ }
900
+
901
+ .error-message {
902
+ display: flex;
903
+ align-items: flex-start;
904
+ gap: var(--icpay-spacing-md);
905
+ padding: var(--icpay-spacing-lg);
906
+ background: var(--icpay-bg-error);
907
+ border: 1px solid var(--icpay-border-error);
908
+ border-radius: var(--icpay-radius-md);
909
+ margin-top: var(--icpay-spacing-sm);
910
+ }
911
+
912
+ .error-icon {
913
+ flex-shrink: 0;
914
+ width: 20px;
915
+ height: 20px;
916
+ background: var(--icpay-accent-error);
917
+ border-radius: 50%;
918
+ display: flex;
919
+ align-items: center;
920
+ justify-content: center;
921
+ color: var(--icpay-text-primary);
922
+ font-size: 12px;
923
+ font-weight: bold;
924
+ }
925
+
926
+ .error-content h4 {
927
+ margin: 0 0 4px 0;
928
+ font-size: 14px;
929
+ font-weight: 600;
930
+ color: var(--icpay-text-primary);
931
+ }
932
+
933
+ .error-content p {
934
+ margin: 0;
935
+ font-size: 12px;
936
+ color: var(--icpay-error-text);
937
+ line-height: 1.4;
938
+ }
939
+
940
+ .success-container { text-align: center; }
941
+ .success-center {
942
+ height: 100%;
943
+ display: flex;
944
+ align-items: center;
945
+ justify-content: center;
946
+ }
947
+ .success-icon {
948
+ width: 64px;
949
+ height: 64px;
950
+ margin: 0 auto var(--icpay-spacing-lg);
951
+ background: var(--icpay-success-text);
952
+ border-radius: var(--icpay-radius-xl);
953
+ display: flex;
954
+ align-items: center;
955
+ justify-content: center;
956
+ }
957
+ .success-icon svg {
958
+ width: 32px;
959
+ height: 32px;
960
+ stroke: var(--icpay-background);
961
+ stroke-width: 2;
962
+ }
963
+ .success-title {
964
+ font-size: 20px;
965
+ font-weight: 600;
966
+ margin-bottom: var(--icpay-spacing-sm);
967
+ color: var(--icpay-foreground);
968
+ }
969
+ .success-message {
970
+ color: var(--icpay-muted-foreground);
971
+ margin-bottom: 20px;
972
+ font-size: 14px;
973
+ }
974
+ .success-actions {
975
+ display: flex;
976
+ gap: var(--icpay-spacing-sm);
977
+ justify-content: center;
978
+ }
979
+ .btn {
980
+ padding: 10px 20px;
981
+ border-radius: var(--icpay-radius-md);
982
+ font-size: 14px;
983
+ font-weight: 500;
984
+ cursor: pointer;
985
+ transition: all 0.3s ease;
986
+ text-decoration: none;
987
+ display: inline-flex;
988
+ align-items: center;
989
+ gap: var(--icpay-spacing-sm);
990
+ }
991
+ .btn-primary {
992
+ background: var(--icpay-primary);
993
+ color: var(--icpay-primary-foreground);
994
+ border: none;
995
+ }
996
+ .btn-primary:hover {
997
+ transform: translateY(-1px);
998
+ opacity: 0.9;
999
+ }
1000
+ .btn-secondary {
1001
+ background: transparent;
1002
+ color: var(--icpay-muted-foreground);
1003
+ border: 1px solid var(--icpay-border);
1004
+ }
1005
+ .btn-secondary:hover {
1006
+ background: var(--icpay-secondary);
1007
+ border-color: var(--icpay-border);
1008
+ color: var(--icpay-foreground);
1009
+ }
1010
+
1011
+ .confetti {
1012
+ position: fixed;
1013
+ top: 0;
1014
+ left: 0;
1015
+ width: 100%;
1016
+ height: 100%;
1017
+ pointer-events: none;
1018
+ z-index: 1001;
1019
+ }
1020
+
1021
+ .confetti-piece {
1022
+ position: absolute;
1023
+ width: 8px;
1024
+ height: 8px;
1025
+ background: var(--icpay-primary);
1026
+ animation: confetti-fall 3s linear forwards;
1027
+ }
1028
+
1029
+ @keyframes spin {
1030
+ from { transform: rotate(0deg); }
1031
+ to { transform: rotate(360deg); }
1032
+ }
1033
+
1034
+ /* legacy spinner removed; unified spinner defined above to match design */
1035
+
1036
+ @keyframes confetti-fall {
1037
+ 0% {
1038
+ transform: translateY(-100vh) rotate(0deg);
1039
+ opacity: 1;
1040
+ }
1041
+ 100% {
1042
+ transform: translateY(100vh) rotate(720deg);
1043
+ opacity: 0;
1044
+ }
1045
+ }
1046
+ `,r([ae({type:Boolean})],b.prototype,"open",2),r([ae({type:Boolean})],b.prototype,"suspended",2),r([ae({type:Array})],b.prototype,"steps",2),r([ae({type:Number})],b.prototype,"amount",2),r([ae({type:String})],b.prototype,"currency",2),r([ae({type:String})],b.prototype,"ledgerSymbol",2),r([ae({type:Boolean})],b.prototype,"debug",2),r([R()],b.prototype,"activeIndex",2),r([R()],b.prototype,"completed",2),r([R()],b.prototype,"failed",2),r([R()],b.prototype,"errorMessage",2),r([R()],b.prototype,"showSuccess",2),r([R()],b.prototype,"showConfetti",2),r([R()],b.prototype,"currentSteps",2),r([R()],b.prototype,"currentAmount",2),r([R()],b.prototype,"currentCurrency",2),r([R()],b.prototype,"currentLedgerSymbol",2),r([R()],b.prototype,"confirmLoadingStartedAt",2),r([R()],b.prototype,"currentWalletType",2),r([R()],b.prototype,"showWalletSelector",2),r([R()],b.prototype,"isTransitioning",2),r([R()],b.prototype,"isOnrampFlow",2),r([ae({type:Object})],b.prototype,"theme",2),b=r([Qe("icpay-progress-bar")],b);import{html as Se}from"lit";function Je(){if(typeof document>"u")return"dark";let i=document.documentElement.getAttribute("data-icpay-theme");if(i==="light"||i==="dark")return i;let s=document.documentElement.getAttribute("data-theme");return s==="light"||s==="dark"?s:"dark"}function q(i){if(!i.visible)return null;let s=i.width??420,e=i.height??680,t=typeof i.url=="string"&&(i.url||"").startsWith("http"),a=Je();return Se`
1047
+ <style>
1048
+ /* Theme-aware color variables - Light mode defaults */
1049
+ .icpay-onramp-modal-overlay {
1050
+ --icpay-background: #ffffff;
1051
+ --icpay-foreground: #171717;
1052
+ --icpay-muted-foreground: #6b7280;
1053
+ --icpay-primary: #3b82f6;
1054
+ --icpay-primary-foreground: #ffffff;
1055
+ --icpay-secondary: #f3f4f6;
1056
+ --icpay-secondary-foreground: #171717;
1057
+ --icpay-accent: #f9fafb;
1058
+ --icpay-border: #e5e7eb;
1059
+ }
1060
+ /* Dark mode */
1061
+ [data-theme="dark"] .icpay-onramp-modal-overlay,
1062
+ [data-icpay-theme="dark"] .icpay-onramp-modal-overlay,
1063
+ :root[data-theme="dark"] .icpay-onramp-modal-overlay,
1064
+ :root[data-icpay-theme="dark"] .icpay-onramp-modal-overlay,
1065
+ html[data-theme="dark"] .icpay-onramp-modal-overlay,
1066
+ html[data-icpay-theme="dark"] .icpay-onramp-modal-overlay,
1067
+ .icpay-onramp-modal-overlay[data-theme="dark"] {
1068
+ --icpay-background: hsl(222.2 84% 4.9%);
1069
+ --icpay-foreground: hsl(210 40% 98%);
1070
+ --icpay-muted-foreground: hsl(215 20.2% 65.1%);
1071
+ --icpay-primary: hsl(210 40% 98%);
1072
+ --icpay-primary-foreground: hsl(222.2 47.4% 11.2%);
1073
+ --icpay-secondary: hsl(217.2 32.6% 17.5%);
1074
+ --icpay-secondary-foreground: hsl(210 40% 98%);
1075
+ --icpay-accent: hsl(217.2 32.6% 17.5%);
1076
+ --icpay-border: hsl(217.2 32.6% 30%);
1077
+ }
1078
+ .icpay-onramp-modal-overlay {
1079
+ position: fixed !important;
1080
+ inset: 0 !important;
1081
+ display: flex;
1082
+ align-items: center;
1083
+ justify-content: center;
1084
+ background: rgba(0,0,0,0.85);
1085
+ backdrop-filter: blur(10px);
1086
+ z-index: 99999 !important;
1087
+ /* Ensure modal breaks out of any parent constraints */
1088
+ transform: none !important;
1089
+ will-change: auto;
1090
+ isolation: isolate;
1091
+ }
1092
+ .icpay-onramp-modal-container {
1093
+ position: relative;
1094
+ background: var(--icpay-background);
1095
+ border: 1px solid var(--icpay-border);
1096
+ border-radius: 16px;
1097
+ padding: 16px;
1098
+ box-shadow: 0 20px 60px rgba(0,0,0,0.5);
1099
+ margin: auto;
1100
+ max-width: 90vw;
1101
+ }
1102
+ @media (max-width: 768px) {
1103
+ .icpay-onramp-modal-overlay {
1104
+ align-items: flex-end;
1105
+ justify-content: stretch;
1106
+ }
1107
+ .icpay-onramp-modal-container {
1108
+ max-width: 100%;
1109
+ width: 100%;
1110
+ height: 70vh;
1111
+ max-height: 70vh;
1112
+ border-radius: 16px 16px 0 0;
1113
+ margin: 0;
1114
+ overflow-y: auto;
1115
+ display: flex;
1116
+ flex-direction: column;
1117
+ }
1118
+ }
1119
+ </style>
1120
+ <div class="icpay-onramp-modal-overlay" data-theme="${a}">
1121
+ <div class="icpay-onramp-modal-container">
1122
+ <button @click=${i.onClose} style="position:absolute;right:12px;top:12px;background:transparent;border:none;color:var(--icpay-foreground);cursor:pointer;font-size:20px;opacity:0.8;z-index:10">×</button>
1123
+ ${i.onBack?Se`<button @click=${i.onBack} style="position:absolute;left:12px;top:12px;background:transparent;border:1px solid var(--icpay-border);color:var(--icpay-foreground);cursor:pointer;font-size:12px;border-radius:8px;padding:6px 10px;opacity:0.9;z-index:10">Back</button>`:null}
1124
+ <div style="color:var(--icpay-foreground);font-weight:600;font-size:15px;margin-bottom:12px">${i.title||"Complete purchase"}</div>
1125
+ ${t?Se`
1126
+ <iframe
1127
+ title="Onramp"
1128
+ src="${i.url}"
1129
+ style="border:0;width:${typeof s=="number"?`${s}px`:s};height:${typeof e=="number"?`${e}px`:e};border-radius:12px;background:#000"
1130
+ sandbox="allow-forms allow-same-origin allow-scripts allow-popups allow-top-navigation-by-user-activation"
1131
+ allow="payment *"
1132
+ ></iframe>
1133
+ <div style="margin-top:10px;text-align:right">
1134
+ <a href="${i.url}" target="_blank" rel="noopener noreferrer" style="color:var(--icpay-primary);font-size:12px;text-decoration:underline">Open in a new tab</a>
1135
+ </div>
1136
+ `:Se`
1137
+ <div style="width:${typeof s=="number"?`${s}px`:s};height:${typeof e=="number"?`${e}px`:e};display:flex;align-items:center;justify-content:center;background:var(--icpay-secondary);border:1px dashed var(--icpay-border);border-radius:12px;color:var(--icpay-foreground)">
1138
+ ${i.errorMessage||"Onramp URL not available"}
1139
+ </div>
1140
+ `}
1141
+ </div>
1142
+ </div>
1143
+ `}import{LitElement as pt,html as ie,css as ht}from"lit";import{customElement as yt,property as ut,state as L}from"lit/decorators.js";import{IcpayError as Be}from"@ic-pay/icpay-sdk";var J={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"},et={onError:i=>{console.error("[ICPay Widget] Error:",i)},onUserCancelled:()=>{console.log("[ICPay Widget] User cancelled the action")},onInsufficientBalance:i=>{console.warn("[ICPay Widget] Insufficient balance:",i.message)},onWalletError:i=>{console.warn("[ICPay Widget] Wallet error:",i.message)},onNetworkError:i=>{console.error("[ICPay Widget] Network error:",i.message)}};function _(i,s=et){i instanceof Be?(s.onError(i),i.isUserCancelled()?s.onUserCancelled?.():i.isBalanceError()?s.onInsufficientBalance?.(i):i.isWalletError()?s.onWalletError?.(i):i.isNetworkError()&&s.onNetworkError?.(i)):(console.error("[ICPay Widget] Unknown error:",i),s.onError(new Be({code:J.UNKNOWN_ERROR,message:i instanceof Error?i.message:"An unknown error occurred",details:i})))}var tt={[J.WALLET_NOT_CONNECTED]:"Please connect your wallet to continue",[J.WALLET_USER_CANCELLED]:"User have rejected the transfer",[J.WALLET_SIGNATURE_REJECTED]:"User have rejected the transfer",[J.INSUFFICIENT_BALANCE]:"Insufficient balance for this transaction",[J.NETWORK_ERROR]:"Network error. Please try again",[J.API_ERROR]:"Service temporarily unavailable",[J.LEDGER_NOT_FOUND]:"Selected token is not supported",[J.TRANSACTION_FAILED]:"Transaction failed. Please try again",[J.TRANSACTION_TIMEOUT]:"Transaction timed out. Please try again",[J.UNKNOWN_ERROR]:"Something went wrong. Please try again"};function D(i){return tt[i.code]||i.message||"An error occurred"}function z(i){return!i.isUserCancelled()}function F(i){return null}function K(i){return i.isUserCancelled()?"info":i.isBalanceError()||i.isWalletError()?"warning":"error"}import{html as ee}from"lit";var Re=new Set(["metamask","walletconnect","coinbase","brave","rainbow","rabby","okx"]),at=new Set(["phantom","backpack"]);function B(i){return i?Re.has(String(i).toLowerCase()):!1}function nt(i){return i&&(i.id||i.provider||i.key)||""}function it(i){return i&&(i.label||i.name||i.title||i.id)||"Wallet"}function rt(i){return i&&(i.icon||i.logo||i.image)||null}function H(i){return(i||[]).map(s=>({id:nt(s),label:it(s),icon:rt(s)}))}async function V(i,s){try{let e=s?.provider||(typeof window<"u"?window.ethereum:null);if(!e||i===void 0||i===null)return!0;let t=typeof i=="number"?i:String(i).startsWith("0x")?parseInt(String(i),16):parseInt(String(i),10);if(!Number.isFinite(t))return!0;let a=await e.request({method:"eth_chainId"});if(parseInt(a,16)===t)return!0;let o="0x"+t.toString(16);return await e.request({method:"wallet_switchEthereumChain",params:[{chainId:o}]}),!0}catch{try{let t=s?.provider||(typeof window<"u"?window.ethereum:null);if(!t||i===void 0||i===null)return!1;let a=typeof i=="number"?i:String(i).startsWith("0x")?parseInt(String(i),16):parseInt(String(i),10),n="0x"+a.toString(16),o=s?.chainName||`Network ${a}`,l=(s?.rpcUrlPublic?[s.rpcUrlPublic]:[]).filter(Boolean),d={name:s?.nativeSymbol||"ETH",symbol:s?.nativeSymbol||"ETH",decimals:typeof s?.decimals=="number"&&isFinite(s.decimals)?s.decimals:18};return await t.request({method:"wallet_addEthereumChain",params:[{chainId:n,chainName:o,rpcUrls:l,nativeCurrency:d}]}),!0}catch{return!1}}}async function X(i){let{sdk:s,lastWalletId:e,connectedWallet:t,amountUsd:a,chainShortcodes:n,tokenShortcodes:o}=i,l,d=(e||"").toLowerCase(),p=(t?.owner||t?.principal||"").toString();try{d&&Re.has(d)?l=await s?.client?.getExternalWalletBalances?.({network:"evm",address:p,amountUsd:a,chainShortcodes:n,tokenShortcodes:o}):d&&at.has(d)?l=await s?.client?.getExternalWalletBalances?.({network:"sol",address:p,amountUsd:a,chainShortcodes:n,tokenShortcodes:o}):l=await s?.client?.getExternalWalletBalances?.({network:"ic",principal:p,amountUsd:a,chainShortcodes:n,tokenShortcodes:o})}catch{l={balances:[],totalBalancesUSD:0,lastUpdated:new Date}}return{balances:(l?.balances||[]).map(c=>({ledgerId:c.ledgerId,ledgerName:c.ledgerName,ledgerSymbol:c.ledgerSymbol,tokenShortcode:c.tokenShortcode??c.shortcode??null,canisterId:c.canisterId,eip3009Version:c?.eip3009Version??null,x402Accepts:c?.x402Accepts!=null?!!c.x402Accepts:void 0,balance:c.balance,formattedBalance:c.formattedBalance,decimals:c.decimals,currentPrice:c.currentPrice,lastPriceUpdate:c.lastPriceUpdate?new Date(c.lastPriceUpdate):void 0,lastUpdated:c.lastUpdated?new Date(c.lastUpdated):new Date,chainId:typeof c.chainId=="string"?c.chainId:typeof c.chainId=="number"?String(c.chainId):void 0,chainName:c.chainName||c.chain&&(c.chain.name||c.chain.chainName)||c.networkName||void 0,rpcUrlPublic:c.rpcUrlPublic,chainUuid:c.chainUuid,requiredAmount:c.requiredAmount,requiredAmountFormatted:c.requiredAmountFormatted,hasSufficientBalance:c.hasSufficientBalance,logoUrl:c.logoUrl??null})),totalBalancesUSD:l?.totalBalancesUSD,lastUpdated:l?.lastUpdated?new Date(l.lastUpdated):new Date}}function Me(i){let s=Number(i);if(!isFinite(s)||s===0)return"0";if(Math.abs(s)<1e-5)return"< 0.00001";let t=1e5;return(Math.trunc(s*t)/t).toFixed(5).replace(/\.0+$/,"").replace(/(\.[0-9]*?)0+$/,"$1")}import{html as Y}from"lit";function Ue(i){let s=parseFloat(String(i.formattedBalance||"0")),e=Number(i.currentPrice??0),t=(isFinite(s)?s:0)*(isFinite(e)?e:0);return isFinite(t)?t:0}var _e=(i,s)=>Ue(s)-Ue(i);function We(){return Y`<style>
1144
+ /* Theme-aware color variables - Light mode defaults */
1145
+ .modal {
1146
+ --icpay-background: #ffffff;
1147
+ --icpay-foreground: #171717;
1148
+ --icpay-muted-foreground: #6b7280;
1149
+ --icpay-primary: #3b82f6;
1150
+ --icpay-primary-foreground: #ffffff;
1151
+ --icpay-secondary: #f3f4f6;
1152
+ --icpay-secondary-foreground: #171717;
1153
+ --icpay-accent: #f9fafb;
1154
+ --icpay-border: #e5e7eb;
1155
+ --icpay-error-text: #dc2626;
1156
+ }
1157
+ /* Dark mode */
1158
+ [data-theme="dark"] .modal,
1159
+ [data-icpay-theme="dark"] .modal,
1160
+ :root[data-theme="dark"] .modal,
1161
+ :root[data-icpay-theme="dark"] .modal,
1162
+ html[data-theme="dark"] .modal,
1163
+ html[data-icpay-theme="dark"] .modal,
1164
+ .modal[data-theme="dark"] {
1165
+ --icpay-background: hsl(222.2 84% 4.9%);
1166
+ --icpay-foreground: hsl(210 40% 98%);
1167
+ --icpay-muted-foreground: hsl(215 20.2% 65.1%);
1168
+ --icpay-primary: hsl(210 40% 98%);
1169
+ --icpay-primary-foreground: hsl(222.2 47.4% 11.2%);
1170
+ --icpay-secondary: hsl(217.2 32.6% 17.5%);
1171
+ --icpay-secondary-foreground: hsl(210 40% 98%);
1172
+ --icpay-accent: hsl(217.2 32.6% 17.5%);
1173
+ --icpay-border: hsl(217.2 32.6% 30%);
1174
+ --icpay-error-text: #f87171;
1175
+ }
1176
+ .modal { background-color:var(--icpay-background); border-radius:24px; width:100%; max-width:420px; padding:24px; color:var(--icpay-foreground); display:flex; flex-direction:column; border:1px solid var(--icpay-border); height:460px; margin:auto; transition:transform 0.3s ease; position:relative; z-index:1; }
1177
+ @media (max-width: 768px) {
1178
+ .modal { max-width:100%; width:100%; height:70vh; max-height:70vh; border-radius:24px 24px 0 0; margin:0; transform:translateY(100%); overflow:hidden; display:flex; flex-direction:column; }
1179
+ .currency-list { overflow-y:auto; flex:1; min-height:0; }
1180
+ .wallet-list { overflow-y:auto; flex:1; min-height:0; }
1181
+ }
1182
+ .header { display:flex; align-items:center; margin-bottom:20px; padding-bottom:20px; border-bottom:1px solid var(--icpay-border); flex-shrink:0; }
1183
+ .back-button { background:none; border:none; color:var(--icpay-foreground); font-size:24px; cursor:pointer; padding:0; margin-right:16px; }
1184
+ .title { font-size:20px; font-weight:600; flex:1; text-align:center; margin-right:40px; }
1185
+ .currency-list { display:flex; flex-direction:column; gap:0; overflow-y:auto; flex:1; margin-bottom:0; }
1186
+ .currency-item { display:flex; align-items:center; padding:16px 12px; cursor:pointer; transition:background-color 0.2s; border-radius:12px; }
1187
+ .currency-item:hover { background-color:var(--icpay-accent); }
1188
+ .currency-item[disabled] { opacity:0.6; cursor:not-allowed; }
1189
+ .currency-icon { width:48px; height:48px; border-radius:50%; margin-right:16px; display:flex; align-items:center; justify-content:center; font-size:28px; flex-shrink:0; overflow:hidden; }
1190
+ .eth-icon { background:linear-gradient(135deg,#627eea 0%, #8a9bff 100%); }
1191
+ .usdc-icon { background:linear-gradient(135deg,#2775ca 0%, #4da4ff 100%); }
1192
+ .usdt-icon { background:linear-gradient(135deg,#26a17b 0%, #50af95 100%); }
1193
+ .currency-info { flex:1; }
1194
+ .currency-name { font-size:16px; font-weight:500; margin-bottom:4px; }
1195
+ .currency-network { font-size:14px; color:var(--icpay-muted-foreground); }
1196
+ .currency-balance { text-align:right; }
1197
+ .balance-amount { font-size:16px; font-weight:500; margin-bottom:4px; }
1198
+ .balance-available { font-size:14px; color:var(--icpay-muted-foreground); }
1199
+ .footer { display:flex; justify-content:space-between; align-items:center; margin-top:16px; padding-top:16px; border-top:1px solid var(--icpay-border); flex-shrink:0; }
1200
+ .need-wallet { font-size:14px; color:var(--icpay-muted-foreground); }
1201
+ .get-started { font-size:14px; color:var(--icpay-primary); background:none; border:none; cursor:pointer; font-weight:500; }
1202
+ .get-started:hover { text-decoration:underline; }
1203
+ .muted { color:var(--icpay-muted-foreground); }
1204
+ </style>`}function Ae(i){let s=e=>Me(e);return Y`
1205
+ <div class="header">
1206
+ <button class="back-button" @click=${i.onBack}>‹</button>
1207
+ <h1 class="title">Pay with</h1>
1208
+ </div>
1209
+ ${i.isLoading?Y`
1210
+ <div class="muted">Loading your balances…</div>
1211
+ `:i.error?Y`
1212
+ <div style="color:var(--icpay-error-text)">${i.error}</div>
1213
+ `:Y`
1214
+ <div class="currency-list">
1215
+ ${(()=>{let e=(i.balances||[]).filter(t=>t.hasSufficientBalance===!0||t.hasSufficientBalance===void 0).sort(_e);return e.length>0?Y`
1216
+ ${e.map(t=>{let a=(t.ledgerSymbol||"").toUpperCase(),n=t.logoUrl?"":a==="ETH"?"eth-icon":a==="USDC"?"usdc-icon":a==="USDT"?"usdt-icon":"";return Y`
1217
+ <div class="currency-item" @click=${()=>i.onSelect(t.tokenShortcode||t.ledgerSymbol)}>
1218
+ <div class="currency-icon ${n}">
1219
+ ${t.logoUrl?Y`<img src="${t.logoUrl}" alt="${a} logo" style="width:100%;height:100%;object-fit:fill" />`:Y`<span>${a.slice(0,1)}</span>`}
1220
+ </div>
1221
+ <div class="currency-info">
1222
+ <div class="currency-name">${t.ledgerName}</div>
1223
+ <div class="currency-network">${t.chainName||""}</div>
1224
+ </div>
1225
+ <div class="currency-balance">
1226
+ <div class="balance-amount">${s(t.formattedBalance)} ${a}</div>
1227
+ <div class="balance-available">$${Ue(t).toFixed(2)}</div>
1228
+ </div>
1229
+ </div>
1230
+ `})}
1231
+ `:Y`<div class="muted" style="margin-bottom:8px">You have no balances on verified tokens.</div>`})()}
1232
+
1233
+ ${(()=>{let e=(i.balances||[]).filter(t=>t.hasSufficientBalance===!1).sort(_e);return e.length>0?Y`
1234
+ ${e.map(t=>{let a=(t.ledgerSymbol||"").toUpperCase(),n=t.logoUrl?"":a==="ETH"?"eth-icon":a==="USDC"?"usdc-icon":a==="USDT"?"usdt-icon":"";return Y`
1235
+ <div class="currency-item" disabled title="Insufficient balance">
1236
+ <div class="currency-icon ${n}">
1237
+ ${t.logoUrl?Y`<img src="${t.logoUrl}" alt="${a} logo" style="width:100%;height:100%;object-fit:fill" />`:Y`<span>${a.slice(0,1)}</span>`}
1238
+ </div>
1239
+ <div class="currency-info">
1240
+ <div class="currency-name">${t.ledgerName}</div>
1241
+ <div class="currency-network">${t.chainName||""}</div>
1242
+ </div>
1243
+ <div class="currency-balance">
1244
+ <div class="balance-amount">need ${t.requiredAmountFormatted||"--"}</div>
1245
+ <div class="balance-available">${s(t.formattedBalance)} ${a} available</div>
1246
+ </div>
1247
+ </div>
1248
+ `})}
1249
+ `:null})()}
1250
+ </div>
1251
+ `}
1252
+ <div class="footer">
1253
+ <span class="need-wallet">Need a wallet?</span>
1254
+ <button class="get-started" @click=${()=>{try{window.open("https://internetcomputer.org/wallets","_blank","noopener,noreferrer")}catch{}}}>Get started</button>
1255
+ </div>
1256
+ `}function st(){if(typeof document>"u")return"light";let i=document.documentElement.getAttribute("data-icpay-theme");if(i==="light"||i==="dark")return i;let s=document.documentElement.getAttribute("data-theme");return s==="light"||s==="dark"?s:"light"}function ot(i){return!i||!i.startsWith("data:")?i:i.replace(/\s+/g,"")}function lt(i,s){let e=(i||"").toLowerCase();return e==="ii"?"Internet Identity":e==="nfid"?"NFID":e==="plug"?"Plug":e==="oisy"?"Oisy":s&&s.trim()?s:i?i.charAt(0).toUpperCase()+i.slice(1):"Wallet"}function G(i){if(!i.visible)return null;let{wallets:s,onSelect:e,onClose:t,isConnecting:a}=i,n=c=>Me(c),o=c=>{let y=parseFloat(String(c.formattedBalance||"0")),g=Number(c.currentPrice??0),I=(isFinite(y)?y:0)*(isFinite(g)?g:0);return isFinite(I)?I:0},l=(c,y)=>o(y)-o(c),d=s.map(c=>{let y=(c.id||"").toLowerCase();return{...c,icon:c.icon??null}}),p=st();return ee`
1257
+ <div class="icpay-modal-overlay" data-theme="${p}" @click=${c=>{c.target===c.currentTarget&&(c.preventDefault(),c.stopPropagation(),i.onDismiss?i.onDismiss():i.onClose())}} style="position:fixed !important;inset:0 !important;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.5);z-index:99999 !important;transform:none !important;">
1258
+ <style>
1259
+ .icpay-w-8 { width: 2rem; }
1260
+ .icpay-h-8 { height: 2rem; }
1261
+ /* Theme-aware color variables - Light mode defaults */
1262
+ .icpay-modal-overlay {
1263
+ --icpay-background: #ffffff;
1264
+ --icpay-foreground: #171717;
1265
+ --icpay-muted-foreground: #6b7280;
1266
+ --icpay-primary: #3b82f6;
1267
+ --icpay-primary-foreground: #ffffff;
1268
+ --icpay-secondary: #f3f4f6;
1269
+ --icpay-secondary-foreground: #171717;
1270
+ --icpay-accent: #f9fafb;
1271
+ --icpay-border: #e5e7eb;
1272
+ --icpay-success-bg: rgba(16, 185, 129, 0.1);
1273
+ --icpay-success-text: #059669;
1274
+ --icpay-success-border: rgba(16, 185, 129, 0.3);
1275
+ --icpay-warning-bg: rgba(245, 158, 11, 0.1);
1276
+ --icpay-warning-text: #d97706;
1277
+ --icpay-warning-border: rgba(245, 158, 11, 0.3);
1278
+ --icpay-error-bg: rgba(239, 68, 68, 0.1);
1279
+ --icpay-error-text: #dc2626;
1280
+ --icpay-error-border: rgba(239, 68, 68, 0.3);
1281
+ --icpay-processing-bg: rgba(59, 130, 246, 0.1);
1282
+ --icpay-processing-text: #2563eb;
1283
+ --icpay-processing-border: rgba(59, 130, 246, 0.3);
1284
+ }
1285
+ /* Dark mode - check for data-theme on any ancestor or document */
1286
+ [data-theme="dark"] .icpay-modal-overlay,
1287
+ [data-icpay-theme="dark"] .icpay-modal-overlay,
1288
+ :root[data-theme="dark"] .icpay-modal-overlay,
1289
+ :root[data-icpay-theme="dark"] .icpay-modal-overlay,
1290
+ html[data-theme="dark"] .icpay-modal-overlay,
1291
+ html[data-icpay-theme="dark"] .icpay-modal-overlay,
1292
+ .icpay-modal-overlay[data-theme="dark"] {
1293
+ --icpay-background: hsl(222.2 84% 4.9%);
1294
+ --icpay-foreground: hsl(210 40% 98%);
1295
+ --icpay-muted-foreground: hsl(215 20.2% 65.1%);
1296
+ --icpay-primary: hsl(210 40% 98%);
1297
+ --icpay-primary-foreground: hsl(222.2 47.4% 11.2%);
1298
+ --icpay-secondary: hsl(217.2 32.6% 17.5%);
1299
+ --icpay-secondary-foreground: hsl(210 40% 98%);
1300
+ --icpay-accent: hsl(217.2 32.6% 17.5%);
1301
+ --icpay-border: hsl(217.2 32.6% 30%);
1302
+ --icpay-success-bg: rgba(16, 185, 129, 0.1);
1303
+ --icpay-success-text: #34d399;
1304
+ --icpay-success-border: rgba(16, 185, 129, 0.3);
1305
+ --icpay-warning-bg: rgba(245, 158, 11, 0.1);
1306
+ --icpay-warning-text: #fbbf24;
1307
+ --icpay-warning-border: rgba(245, 158, 11, 0.3);
1308
+ --icpay-error-bg: rgba(239, 68, 68, 0.1);
1309
+ --icpay-error-text: #f87171;
1310
+ --icpay-error-border: rgba(239, 68, 68, 0.3);
1311
+ --icpay-processing-bg: rgba(59, 130, 246, 0.1);
1312
+ --icpay-processing-text: #60a5fa;
1313
+ --icpay-processing-border: rgba(59, 130, 246, 0.3);
1314
+ }
1315
+ /* New design styles (scoped) */
1316
+ .icpay-modal-overlay {
1317
+ position: fixed !important;
1318
+ inset: 0 !important;
1319
+ display: flex;
1320
+ align-items: center;
1321
+ justify-content: center;
1322
+ background: rgba(0,0,0,0.5);
1323
+ z-index: 99999 !important;
1324
+ /* Ensure modal breaks out of any parent constraints */
1325
+ transform: none !important;
1326
+ will-change: auto;
1327
+ isolation: isolate;
1328
+ }
1329
+ @media (max-width: 768px) {
1330
+ .icpay-modal-overlay {
1331
+ align-items: flex-end;
1332
+ justify-content: stretch;
1333
+ }
1334
+ }
1335
+ .modal { background-color:var(--icpay-background); border-radius:24px; width:100%; max-width:420px; padding:24px; color:var(--icpay-foreground); display:flex; flex-direction:column; border:1px solid var(--icpay-border); height:460px; margin:auto; transition:transform 0.3s ease; }
1336
+ @media (max-width: 768px) {
1337
+ .modal { max-width:100%; width:100%; height:70vh; max-height:70vh; border-radius:24px 24px 0 0; margin:0; transform:translateY(100%); overflow:hidden; display:flex; flex-direction:column; }
1338
+ .icpay-modal-overlay.active .modal,
1339
+ .icpay-modal-overlay:not([style*="display: none"]) .modal { transform:translateY(0); }
1340
+ .wallet-list { overflow-y:auto; flex:1; min-height:0; }
1341
+ }
1342
+ .header { display:flex; align-items:center; margin-bottom:20px; padding-bottom:20px; border-bottom:1px solid var(--icpay-border); flex-shrink:0; }
1343
+ .back-button { background:none; border:none; color:var(--icpay-foreground); font-size:24px; cursor:pointer; padding:0; margin-right:16px; }
1344
+ .title { font-size:20px; font-weight:600; flex:1; text-align:center; margin-right:40px; }
1345
+ .wallet-list { display:flex; flex-direction:column; gap:0; overflow-y:auto; flex:1; padding-right:8px; scrollbar-gutter: stable; }
1346
+ .wallet-item { display:flex; align-items:center; padding:16px 12px; cursor:pointer; transition:background-color 0.2s; border-radius:12px; }
1347
+ .wallet-item:hover { background-color:var(--icpay-accent); }
1348
+ .wallet-icon { width:48px; height:48px; border-radius:12px; margin-right:16px; display:flex; align-items:center; justify-content:center; font-size:24px; overflow:hidden; }
1349
+ .oisy-icon { background-color:var(--icpay-primary); }
1350
+ .plug-icon { background:linear-gradient(135deg,#667eea 0%, #764ba2 100%); }
1351
+ .wallet-info { flex:1; }
1352
+ .wallet-name { font-size:16px; font-weight:500; margin-bottom:4px; }
1353
+ .wallet-status { font-size:14px; color:var(--icpay-muted-foreground); }
1354
+ .divider { height:0; border-top:1px solid var(--icpay-border); margin:8px 0; border-radius:1px; width:100%; }
1355
+ .footer { display:flex; justify-content:space-between; align-items:center; margin-top:16px; padding-top:16px; flex-shrink:0; }
1356
+ .need-wallet { font-size:14px; color:var(--icpay-muted-foreground); }
1357
+ .get-started { font-size:14px; color:var(--icpay-primary); background:none; border:none; cursor:pointer; font-weight:500; }
1358
+ .get-started:hover { text-decoration:underline; }
1359
+ </style>
1360
+ ${We()}
1361
+ <div class="modal" @click=${c=>c.stopPropagation()}>
1362
+ ${i.step==="balances"?ee`
1363
+ ${Ae({isLoading:!!i.balancesLoading,error:i.balancesError,balances:i.balances,onBack:()=>i.onBack&&i.onBack(),onSelect:c=>i.onSelectBalance&&i.onSelectBalance(c)})}
1364
+ `:ee`
1365
+ <div class="header">
1366
+ <button class="back-button" @click=${()=>{try{t()}catch{}}}>‹</button>
1367
+ <h1 class="title">Connect</h1>
1368
+ </div>
1369
+ <div class="wallet-list">
1370
+ ${i.showCreditCard&&i.onCreditCard?ee`
1371
+ <div class="wallet-item" style="border:1px solid var(--icpay-primary);background:var(--icpay-processing-bg)" @click=${()=>i.onCreditCard&&i.onCreditCard()}>
1372
+ <div class="wallet-icon">
1373
+ 💳
1374
+ </div>
1375
+ <div class="wallet-info">
1376
+ <div class="wallet-name">${i.creditCardLabel||"Pay with credit card"}</div>
1377
+ ${i.creditCardTooltip?ee`<div class="wallet-status">${i.creditCardTooltip}</div>`:null}
1378
+ </div>
1379
+ </div>
1380
+ <div class="divider"></div>
1381
+ `:null}
1382
+ ${(()=>{let c=[],y=null;return d.forEach(g=>{let I=(g.id||"").toLowerCase(),Z=lt(g.id,g.label),Ee=B(I),ke=I==="phantom"||I==="backpack"?"sol":Ee?"evm":"ic";y!==null&&ke!==y&&c.push(ee`<div class="divider"></div>`);let Pe=I==="oisy"||I==="plug"||I==="nfid"||I==="ii"?"Internet Computer":I==="phantom"||I==="backpack"?"Solana":Ee?"Ethereum-compatible":"";c.push(ee`
1383
+ <div class="wallet-item" style="opacity:${a?.6:1}" @click=${()=>e(g.id)}>
1384
+ <div class="wallet-icon">
1385
+ ${g.icon?ee`<img src="${ot(g.icon)}" alt="${Z} logo" class="icpay-w-8 icpay-h-8" style="object-fit:contain" />`:ee`<span>${Z.charAt(0)}</span>`}
1386
+ </div>
1387
+ <div class="wallet-info">
1388
+ <div class="wallet-name">${Z}</div>
1389
+ ${Pe?ee`<div class="wallet-status">${Pe}</div>`:null}
1390
+ </div>
1391
+ </div>
1392
+ `),y=ke}),c})()}
1393
+ </div>
1394
+ <div class="footer">
1395
+ <span class="need-wallet">Need a wallet?</span>
1396
+ <button class="get-started" @click=${()=>{try{window.open("https://metamask.io/en-GB/download","_blank","noopener,noreferrer")}catch{}}}>Get started</button>
1397
+ </div>
1398
+ `}
1399
+ </div>
1400
+ </div>
1401
+ `}import{html as ct}from"lit";function dt(){if(typeof document>"u")return"dark";let i=document.documentElement.getAttribute("data-icpay-theme");if(i==="light"||i==="dark")return i;let s=document.documentElement.getAttribute("data-theme");return s==="light"||s==="dark"?s:"dark"}function Q(i){if(!i.visible)return null;let s=dt();return ct`
1402
+ <div class="icpay-modal-overlay" data-theme="${s}" style="position:fixed !important;inset:0 !important;display:flex;align-items:center;justify-content:center;background:rgba(0, 0, 0, 0.5);z-index:99999 !important;transform:none !important;">
1403
+ <style>
1404
+ /* Theme-aware color variables - Light mode defaults */
1405
+ .icpay-modal-overlay {
1406
+ --icpay-background: #ffffff;
1407
+ --icpay-foreground: #171717;
1408
+ --icpay-muted-foreground: #6b7280;
1409
+ --icpay-primary: #3b82f6;
1410
+ --icpay-primary-foreground: #ffffff;
1411
+ --icpay-secondary: #f3f4f6;
1412
+ --icpay-secondary-foreground: #171717;
1413
+ --icpay-accent: #f9fafb;
1414
+ --icpay-border: #e5e7eb;
1415
+ --icpay-error-text: #dc2626;
1416
+ }
1417
+ /* Dark mode */
1418
+ [data-theme="dark"] .icpay-modal-overlay,
1419
+ [data-icpay-theme="dark"] .icpay-modal-overlay,
1420
+ :root[data-theme="dark"] .icpay-modal-overlay,
1421
+ :root[data-icpay-theme="dark"] .icpay-modal-overlay,
1422
+ html[data-theme="dark"] .icpay-modal-overlay,
1423
+ html[data-icpay-theme="dark"] .icpay-modal-overlay,
1424
+ .icpay-modal-overlay[data-theme="dark"] {
1425
+ --icpay-background: hsl(222.2 84% 4.9%);
1426
+ --icpay-foreground: hsl(210 40% 98%);
1427
+ --icpay-muted-foreground: hsl(215 20.2% 65.1%);
1428
+ --icpay-primary: hsl(210 40% 98%);
1429
+ --icpay-primary-foreground: hsl(222.2 47.4% 11.2%);
1430
+ --icpay-secondary: hsl(217.2 32.6% 17.5%);
1431
+ --icpay-secondary-foreground: hsl(210 40% 98%);
1432
+ --icpay-accent: hsl(217.2 32.6% 17.5%);
1433
+ --icpay-border: hsl(217.2 32.6% 30%);
1434
+ --icpay-error-text: #f87171;
1435
+ }
1436
+ .icpay-modal-overlay {
1437
+ position: fixed !important;
1438
+ inset: 0 !important;
1439
+ display: flex;
1440
+ align-items: center;
1441
+ justify-content: center;
1442
+ background: rgba(0, 0, 0, 0.5);
1443
+ z-index: 99999 !important;
1444
+ /* Ensure modal breaks out of any parent constraints */
1445
+ transform: none !important;
1446
+ will-change: auto;
1447
+ isolation: isolate;
1448
+ }
1449
+ @media (max-width: 768px) {
1450
+ .icpay-modal-overlay {
1451
+ align-items: flex-end;
1452
+ justify-content: stretch;
1453
+ }
1454
+ }
1455
+ </style>
1456
+ ${We()}
1457
+ <div class="modal">
1458
+ ${Ae({isLoading:i.isLoading,error:i.error,balances:i.balances,onBack:i.onClose,onSelect:i.onSelect})}
1459
+ </div>
1460
+ </div>
1461
+ `}function $(i){try{let s=i||{};s.adapters=s.adapters||{};let e=s.adapters.oisy||{},t=e.config||{},a={...t.transport||{},windowOpenerFeatures:"",detectNonClickEstablishment:!1};return s.adapters.oisy={...e,config:{...t,transport:a}},s}catch{return i}}function U(i,s){try{let e=s&&(s.owner||s.principal)||null,t=i&&i.account&&(i.account.owner||i.account.principal)||null,a=o=>typeof o=="string"?o:o&&typeof o.toString=="function"?o.toString():null,n=a(e)||a(t)||null;return n?{owner:n,principal:n}:s||{owner:null}}catch{return s||{owner:null}}}async function te(i){try{let s=typeof i?.getEnabledWallets=="function"?i.getEnabledWallets.bind(i):null;if(!s)return null;let t=(s()||[]).find(d=>(d?.id||"").toLowerCase()==="oisy");if(!t||!t.adapter)return null;let a=t.adapter,n=new a({config:i?.config||{}});if(!await n.isConnected())return null;let l=await n.getPrincipal();return l&&l!=="2vxsx-fae"?l:null}catch{return null}}var De=typeof window<"u",re=null;function ue(i,s,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${s}`,e):console.log(`[ICPay Widget] ${s}`))}var k=class extends pt{constructor(){super(...arguments);this.selectedSymbol=null;this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.walletModalStep="connect";this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampUrl=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.sdk=null;this.onTransactionCompleted=null;this.onUnlock=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="pay",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.config?.priceUsd||0),a=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:a}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(n=>n?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),B(this.lastWalletId)){let n=(this.walletBalances||[]).find(l=>l?.tokenShortcode===e),o=n?.chainId;this.showBalanceModal=!1,this.showWalletModal=!1,V(o,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:n?.chainName,rpcUrlPublic:n?.rpcUrlPublic,nativeSymbol:n?.ledgerSymbol,decimals:n?.decimals}).then(async()=>{try{let l=u(this.config),d=Number(this.config?.priceUsd??0);if(n?.x402Accepts)try{await l.client.createPaymentX402Usd({usdAmount:d,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:n?.ledgerId,icpay_context:"premium:x402"}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"});return}catch{}await l.client.createPaymentUsd({usdAmount:d,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:n?.ledgerId}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"})}catch{}});return}this.showBalanceModal=!1,this.showWalletModal=!1;let a=this.pendingAction;if(this.pendingAction=null,a==="pay")try{let n=(this.walletBalances||[]).find(g=>g?.tokenShortcode===e),o=u(this.config),l=Number(this.config?.priceUsd??0),d=String(n?.chainName||n?.ledgerName||"").toLowerCase(),p=d.includes("sol"),h=this.config?.recipientAddresses||{},c=p&&h.sol||h.ic,y=d.includes("ic");if(n?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:l,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:p?"sol":y?"ic":this.config?.icpay_network,icpay_ledger_id:n?.ledgerId,icpay_context:"premium:x402"}},recipientAddress:c||""});return}catch{return}await o.client.createPaymentUsd({usdAmount:l,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"ic",icpay_ledger_id:n?.ledgerId}},recipientAddress:c||"0x0000000000000000000000000000000000000000"})}catch{}}}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("./wallet-select-BEKXSS66.js")).WalletSelect);let a={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");a.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}let n=new re(a);this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}connectedCallback(){if(super.connectedCallback(),!!De){ue(this.config?.debug||!1,"Premium content connected",{config:this.config}),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.showBalanceModal=!1,this.requestUpdate()}))}catch{}this.onTransactionCompleted=(()=>{this.unlocked=!0,this.succeeded=!0,this.processing=!1;try{window.dispatchEvent(new CustomEvent("icpay-unlock",{detail:{amount:this.config?.priceUsd,currency:this.selectedSymbol||"ICP"}}))}catch{}this.requestUpdate()});try{window.addEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted)}catch{}this.onUnlock=(()=>{this.unlocked=!0,this.succeeded=!0,this.processing=!1,this.requestUpdate()});try{window.addEventListener("icpay-unlock",this.onUnlock)}catch{}}}disconnectedCallback(){super.disconnectedCallback();try{window.removeEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}if(this.onTransactionCompleted)try{window.removeEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted)}catch{}if(this.onUnlock)try{window.removeEventListener("icpay-unlock",this.onUnlock)}catch{}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}this.walletModalStep!=="balances"&&!this.oisyReadyToPay&&(this.pendingAction=null,setTimeout(()=>{t==="pay"&&this.onPay()},0))}}async onPay(){if(De&&!(this.processing||this.unlocked)){ue(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||"ICP"}}))}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){ue(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{re||(re=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?$({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);try{if(typeof window<"u"){let{resolveDerivationOrigin:n}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||n()}}catch{}this.pnp=new re(t);try{let n=await te(this.pnp);if(n){this.walletConnected=!0;let o=U(this.pnp,{owner:n,principal:n,connected:!0}),l=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:o,actorProvider:(d,p)=>this.pnp.getActor({canisterId:d,idl:p,requiresSigning:!0,anon:!1}),...l?{evmProvider:l}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.onPay();return}}catch{}let a=this.pnp.getEnabledWallets();if(ue(this.config?.debug||!1,"Available wallets",a),!a?.length)throw new Error("No wallets available");this.pendingAction="pay",this.showWalletModal=!0;return}catch(e){ue(this.config?.debug||!1,"Wallet connection error:",e),this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error";return}}this.walletModalStep="balances",this.showBalanceModal=!1,this.showWalletModal=!0,await this.fetchAndShowBalances("pay");return}catch(e){_(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),z(t)&&(this.errorMessage=D(t),this.errorSeverity=K(t),this.errorAction=F(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,a=t?.event_id||t?.eventId||t?.id;if(!(!a||typeof a!="string")&&a==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let n=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(n||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let t=await u(this.config).startOnrampUsd(this.config.priceUsd,void 0,{context:"premium:onramp",onrampPayment:!0,onrampProvider:"coinbase"}),a=t?.metadata?.onramp?.url||t?.onramp?.url||t?.metadata?.icpay_onramp?.url||t?.paymentIntent?.metadata?.icpay?.onrampUrl||t?.metadata?.icpay?.onrampUrl||null,n=t?.metadata?.icpay_payment_intent_id||t?.metadata?.paymentIntentId||t?.paymentIntentId||null,o=t?.metadata?.icpay_onramp?.errorMessage||t?.metadata?.onramp?.errorMessage||t?.paymentIntent?.metadata?.icpay?.onrampError||t?.paymentIntent?.metadata?.icpay?.errorMessage||t?.metadata?.icpay?.onrampError||t?.metadata?.icpay?.errorMessage||null;if(this.onrampPaymentIntentId=n,a){this.onrampUrl=a,this.onrampErrorMessage=null;try{window.open(a,"icpay_onramp","noopener,noreferrer");try{window.dispatchEvent(new CustomEvent("icpay-onramp-opened",{detail:{url:a}}))}catch{}}catch{}this.startOnrampPolling()}else this.onrampUrl=null,this.onrampErrorMessage=o||"Failed to obtain onramp URL",this.showOnrampModal=!0}catch(e){this.onrampUrl=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp URL",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let a=u(this.config),n=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>n()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=a.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=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}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(a=>{if(!!!(a&&(a.connected===!0||a.principal||a.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{}let o=U(this.pnp,a),l=this.pnp?.getEvmProvider?.(),d=this.pnp?.getSolanaProvider?.();this.config={...this.config,connectedWallet:o,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...l?{evmProvider:l}:{},...d?{solanaProvider:d}:{}},this.sdk=null,this.walletModalStep="balances",this.showBalanceModal=!1,this.showWalletModal=!0,this.fetchAndShowBalances("pay")}).catch(a=>{this.errorMessage=a instanceof Error?a.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(e){try{this.balancesLoading=!0,this.balancesError=null,this.walletModalStep="balances",this.showBalanceModal=!1;let t=u(this.config),{balances:a}=await X({sdk:t,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.config?.priceUsd??0)});this.walletBalances=a,this.pendingAction=e}catch(t){this.walletBalances=[],this.balancesError=t&&(t.message||String(t))||"Failed to load balances"}finally{this.balancesLoading=!1}}render(){return this.config?ie`
1462
+ <div class="icpay-card icpay-section icpay-widget-base">
1463
+ ${this.config?.progressBar?.enabled!==!1?ie`
1464
+ <icpay-progress-bar
1465
+ .debug=${!!this.config?.debug}
1466
+ .theme=${this.config?.theme}
1467
+ .amount=${Number(this.config?.priceUsd||0)}
1468
+ .ledgerSymbol=${this.selectedSymbol||"ICP"}
1469
+ ></icpay-progress-bar>
1470
+ `:null}
1471
+ <div class="image-container">
1472
+ <div class="locked-image ${this.unlocked?"unlocked":""}" style="background-image:url('${this.config.imageUrl||""}')"></div>
1473
+ ${this.unlocked?null:ie`<div class="lock-overlay">🔒</div>`}
1474
+ </div>
1475
+
1476
+ <div class="pricing">
1477
+ <div class="price">$${Number(this.config?.priceUsd??0).toFixed(2)}</div>
1478
+ <div class="label">One-time unlock</div>
1479
+ </div>
1480
+
1481
+
1482
+
1483
+ <button class="pay-button ${this.processing?"processing":""}" ?disabled=${this.processing||this.unlocked||this.config?.disablePaymentButton===!0||this.succeeded&&this.config?.disableAfterSuccess===!0} @click=${()=>this.onPay()}>
1484
+ ${this.unlocked?"Unlocked":this.processing?"Processing\u2026":(this.config?.buttonLabel||"Pay ${amount} with crypto").replace("{amount}",`${Number(this.config?.priceUsd??0).toFixed(2)}`).replace("{symbol}",this.selectedSymbol||"ICP")}
1485
+ </button>
1486
+
1487
+ ${this.errorMessage?ie`
1488
+ <div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
1489
+ ${this.errorMessage}
1490
+ ${this.errorAction?ie`
1491
+ <button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">
1492
+ ${this.errorAction}
1493
+ </button>
1494
+ `:""}
1495
+ </div>
1496
+ `:""}
1497
+ ${(()=>{let e=this.pnp?.getEnabledWallets?.()||[],t=H(e);return G({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,step:this.walletModalStep,balances:this.walletModalStep==="balances"?this.walletBalances:[],balancesLoading:this.walletModalStep==="balances"?this.balancesLoading:!1,balancesError:this.walletModalStep==="balances"?this.balancesError:null,onSelectBalance:a=>this.onSelectBalanceSymbol(a),onBack:()=>{this.walletModalStep="connect"},onSwitchAccount:()=>this.onSwitchAccount(null),onSelect:a=>this.connectWithWallet(a),onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-cancelled",{detail:{reason:"user_cancelled"}}))}catch{}},onDismiss:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0,creditCardTooltip:(()=>{let n=Number(this.config?.priceUsd||0);return n>0&&n<5&&this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?`Note: Minimum card amount is $5. You will pay about $${(5-n).toFixed(2)} more.`:null})(),oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1,this.onPay()}})})()}
1498
+
1499
+ ${Q({visible:this.showBalanceModal,isLoading:this.balancesLoading,error:this.balancesError,balances:this.walletBalances,onSelect:e=>this.onSelectBalanceSymbol(e),onClose:()=>{this.showBalanceModal=!1}})}
1500
+
1501
+ ${q({visible:this.showOnrampModal,url:this.onrampUrl||void 0,errorMessage:this.onrampErrorMessage||void 0,width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0},title:"Pay with credit card"})}
1502
+ <div class="icpay-powered-by">
1503
+ <a href="https://icpay.org" target="_blank" rel="noopener noreferrer">Powered by icpay</a>
1504
+ </div>
1505
+ </div>
1506
+ `:ie`<div class="icpay-card icpay-section">Loading...</div>`}};k.styles=[j,ht`
1507
+ .image-container {
1508
+ position: relative;
1509
+ border-radius: 16px;
1510
+ overflow: hidden;
1511
+ margin-bottom: 16px;
1512
+ background: #111827;
1513
+ border: 1px solid var(--icpay-border);
1514
+ aspect-ratio: 16/10;
1515
+ }
1516
+ .locked-image {
1517
+ width: 100%;
1518
+ height: 100%;
1519
+ background-size: cover;
1520
+ background-position: center;
1521
+ background-repeat: no-repeat;
1522
+ filter: blur(8px) grayscale(1);
1523
+ transition: all 0.6s ease;
1524
+ min-height: 200px;
1525
+ }
1526
+ .locked-image.unlocked { filter: blur(0px) grayscale(1); }
1527
+ .lock-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
1528
+ .pricing { text-align: center; margin: 16px 0; }
1529
+ .price { font-size: 28px; font-weight: 800; color: var(--icpay-text); }
1530
+ .label { color: var(--icpay-muted); font-size: 14px; }
1531
+ .crypto-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 16px; }
1532
+ .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; }
1533
+ .crypto-option.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }
1534
+
1535
+ .error-message {
1536
+ border: 1px solid;
1537
+ font-weight: 500;
1538
+ }
1539
+
1540
+ .error-message.info {
1541
+ background: var(--icpay-processing-bg);
1542
+ border-color: var(--icpay-processing-border);
1543
+ color: var(--icpay-processing-text);
1544
+ }
1545
+
1546
+ .error-message.warning {
1547
+ background: var(--icpay-warning-bg);
1548
+ border-color: var(--icpay-warning-border);
1549
+ color: var(--icpay-warning-text);
1550
+ }
1551
+
1552
+ .error-message.error {
1553
+ background: var(--icpay-error-bg);
1554
+ border-color: var(--icpay-error-border);
1555
+ color: var(--icpay-error-text);
1556
+ }
1557
+ `],r([ut({type:Object})],k.prototype,"config",2),r([L()],k.prototype,"selectedSymbol",2),r([L()],k.prototype,"unlocked",2),r([L()],k.prototype,"succeeded",2),r([L()],k.prototype,"processing",2),r([L()],k.prototype,"errorMessage",2),r([L()],k.prototype,"errorSeverity",2),r([L()],k.prototype,"errorAction",2),r([L()],k.prototype,"walletConnected",2),r([L()],k.prototype,"pendingAction",2),r([L()],k.prototype,"showWalletModal",2),r([L()],k.prototype,"walletModalStep",2),r([L()],k.prototype,"oisyReadyToPay",2),r([L()],k.prototype,"lastWalletId",2),r([L()],k.prototype,"showOnrampModal",2),r([L()],k.prototype,"onrampUrl",2),r([L()],k.prototype,"onrampPaymentIntentId",2),r([L()],k.prototype,"onrampErrorMessage",2),r([L()],k.prototype,"showBalanceModal",2),r([L()],k.prototype,"balancesLoading",2),r([L()],k.prototype,"balancesError",2),r([L()],k.prototype,"walletBalances",2),k=r([yt("icpay-premium-content")],k);import{LitElement as gt,html as oe,css as mt}from"lit";import{customElement as ft,property as vt,state as W}from"lit/decorators.js";var ze=typeof window<"u",le=null;function ge(i,s,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${s}`,e):console.log(`[ICPay Widget] ${s}`))}var w=class extends gt{constructor(){super(...arguments);this.selectedAmount=1;this.selectedSymbol=null;this.total=0;this.processing=!1;this.succeeded=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.walletModalStep="connect";this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampUrl=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.sdk=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="tip",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.selectedAmount||0),a=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"tip",type:"sendUsd",amount:t,currency:a}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(n=>n?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),this.showBalanceModal=!1,this.showWalletModal=!1,B(this.lastWalletId)){let n=(this.walletBalances||[]).find(l=>l?.tokenShortcode===e),o=n?.chainId;V(o,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:n?.chainName,rpcUrlPublic:n?.rpcUrlPublic,nativeSymbol:n?.ledgerSymbol,decimals:n?.decimals}).then(async()=>{try{let l=u(this.config),d=Number(this.selectedAmount||0);if(n?.x402Accepts)try{await l.client.createPaymentX402Usd({usdAmount:d,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:n?.ledgerId,icpay_context:"tip:x402"}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"}),this.showBalanceModal=!1;return}catch{}await l.client.createPaymentUsd({usdAmount:d,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:n?.ledgerId}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"})}catch{}this.showBalanceModal=!1});return}let a=this.pendingAction;if(this.pendingAction=null,a==="tip")try{let n=(this.walletBalances||[]).find(g=>g?.tokenShortcode===e),o=u(this.config),l=Number(this.selectedAmount||0),d=String(n?.ledgerName||n?.chainName||"").toLowerCase(),p=d.includes("sol"),h=d.includes("ic"),c=this.config?.recipientAddresses||{},y=p&&c.sol||c.ic;if(n?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:l,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:p?"sol":h?"ic":this.config?.icpay_network,icpay_ledger_id:n?.ledgerId,icpay_context:"tip:x402"}},recipientAddress:y||""});return}catch{return}await o.client.createPaymentUsd({usdAmount:l,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"ic",icpay_ledger_id:n?.ledgerId}},recipientAddress:y||"0x0000000000000000000000000000000000000000"})}catch{}}}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;le||(le=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let a=$({...this.config?.plugNPlay||{}});try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");a.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}let n=new le(a);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]}connectedCallback(){if(super.connectedCallback(),!!ze){ge(this.config?.debug||!1,"Tip jar connected",{config:this.config}),this.config&&this.config.defaultAmountUsd&&(this.selectedAmount=this.config.defaultAmountUsd),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.requestUpdate()}))}catch{}}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}this.walletModalStep!=="balances"&&!this.oisyReadyToPay&&(this.pendingAction=null,setTimeout(()=>{t==="tip"&&this.tip()},0))}}selectAmount(e){this.selectedAmount=e}selectSymbol(e){this.selectedSymbol=e}get fillPercentage(){return Math.min(this.total/50*100,100)}async tip(){if(ze&&(ge(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||"ICP"}}))}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){ge(this.config?.debug||!1,"Connecting to wallet via wallet");try{le||(le=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?$({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);try{if(typeof window<"u"){let{resolveDerivationOrigin:n}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||n()}}catch{}this.pnp=new le(t);try{let n=await te(this.pnp);if(n){this.walletConnected=!0;let o=U(this.pnp,{owner:n,principal:n,connected:!0}),l=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:o,actorProvider:(d,p)=>this.pnp.getActor({canisterId:d,idl:p,requiresSigning:!0,anon:!1}),...l?{evmProvider:l}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.tip();return}}catch{}let a=this.pnp.getEnabledWallets();if(ge(this.config?.debug||!1,"Available wallets",a),!a?.length)throw new Error("No wallets available");this.pendingAction="tip",this.showWalletModal=!0;return}catch(e){ge(this.config?.debug||!1,"Wallet connection error:",e),this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error";return}}this.showWalletModal=!0,await this.fetchAndShowBalances();return}catch(e){_(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),z(t)&&(this.errorMessage=D(t),this.errorSeverity=K(t),this.errorAction=F(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,a=t?.event_id||t?.eventId||t?.id;if(!(!a||typeof a!="string")&&a==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let n=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(n||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let t=await u(this.config).startOnrampUsd(this.selectedAmount,void 0,{context:"tip:onramp",onrampPayment:!0,onrampProvider:this?.selectedOnrampProvider||"coinbase"}),a=t?.metadata?.onramp?.url||t?.onramp?.url||t?.metadata?.icpay_onramp?.url||t?.paymentIntent?.metadata?.icpay?.onrampUrl||t?.metadata?.icpay?.onrampUrl||null,n=t?.metadata?.icpay_payment_intent_id||t?.metadata?.paymentIntentId||t?.paymentIntentId||null,o=t?.metadata?.icpay_onramp?.errorMessage||t?.metadata?.onramp?.errorMessage||t?.paymentIntent?.metadata?.icpay?.onrampError||t?.paymentIntent?.metadata?.icpay?.errorMessage||t?.metadata?.icpay?.onrampError||t?.metadata?.icpay?.errorMessage||null;if(this.onrampPaymentIntentId=n,a){this.onrampUrl=a,this.onrampErrorMessage=null;try{window.open(a,"icpay_onramp","noopener,noreferrer");try{window.dispatchEvent(new CustomEvent("icpay-onramp-opened",{detail:{url:a}}))}catch{}}catch{}this.startOnrampPolling()}else this.onrampUrl=null,this.onrampErrorMessage=o||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}catch(e){this.onrampUrl=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let a=u(this.config),n=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>n()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=a.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=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}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(a=>{if(!!!(a&&(a.connected===!0||a.principal||a.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{}let o=U(this.pnp,a),l=this.pnp?.getEvmProvider?.(),d=this.pnp?.getSolanaProvider?.();this.config={...this.config,connectedWallet:o,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...l?{evmProvider:l}:{},...d?{solanaProvider:d}:{}},this.sdk=null,this.walletModalStep="balances",this.showBalanceModal=!1,this.showWalletModal=!0,this.fetchAndShowBalances()}).catch(a=>{this.errorMessage=a instanceof Error?a.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(){try{this.balancesLoading=!0,this.balancesError=null,this.walletModalStep="balances",this.showBalanceModal=!1;let e=u(this.config),{balances:t}=await X({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.selectedAmount||0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!1}}render(){return this.config?oe`
1558
+ <div class="icpay-card icpay-section icpay-widget-base" style="text-align:center;">
1559
+ ${this.config?.progressBar?.enabled!==!1?oe`
1560
+ <icpay-progress-bar
1561
+ .debug=${!!this.config?.debug}
1562
+ .theme=${this.config?.theme}
1563
+ .amount=${Number(this.selectedAmount||0)}
1564
+ .ledgerSymbol=${this.selectedSymbol||"ICP"}
1565
+ ></icpay-progress-bar>
1566
+ `:null}
1567
+ <div class="jar"><div class="fill" style="height:${this.fillPercentage}%"></div></div>
1568
+ <div class="label">Total Tips: $${this.total}</div>
1569
+
1570
+ <div class="amounts">
1571
+ ${this.amounts.map(e=>oe`<div class="chip ${this.selectedAmount===e?"selected":""}" @click=${()=>this.selectAmount(e)}>$${e}</div>`)}
1572
+ </div>
1573
+
1574
+
1575
+
1576
+ <button class="pay-button ${this.processing?"processing":""}"
1577
+ ?disabled=${this.processing||this.config?.disablePaymentButton===!0||this.succeeded&&this.config?.disableAfterSuccess===!0}
1578
+ @click=${()=>this.tip()}>
1579
+ ${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||"ICP"):`Tip $${this.selectedAmount} with crypto`}
1580
+ </button>
1581
+
1582
+ ${this.errorMessage?oe`
1583
+ <div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
1584
+ ${this.errorMessage}
1585
+ ${this.errorAction?oe`
1586
+ <button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">
1587
+ ${this.errorAction}
1588
+ </button>
1589
+ `:""}
1590
+ </div>
1591
+ `:""}
1592
+ ${(()=>{let e=this.pnp?.getEnabledWallets?.()||[],t=H(e);return G({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,step:this.walletModalStep,balances:this.walletModalStep==="balances"?this.walletBalances:[],balancesLoading:this.walletModalStep==="balances"?this.balancesLoading:!1,balancesError:this.walletModalStep==="balances"?this.balancesError:null,onSelectBalance:a=>this.onSelectBalanceSymbol(a),onBack:()=>{this.walletModalStep="connect"},onSwitchAccount:()=>this.onSwitchAccount(null),onSelect:a=>this.connectWithWallet(a),onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-cancelled",{detail:{reason:"user_cancelled"}}))}catch{}},onDismiss:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0,creditCardTooltip:(()=>{let n=Number(this.selectedAmount||this.config?.defaultAmountUsd||0);return n>0&&n<5&&this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?`Note: Minimum card amount is $5. You will pay about $${(5-n).toFixed(2)} more.`:null})(),oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1,this.tip()}})})()}
1593
+
1594
+ ${Q({visible:this.showBalanceModal,isLoading:this.balancesLoading,error:this.balancesError,balances:this.walletBalances,onSelect:e=>this.onSelectBalanceSymbol(e),onClose:()=>{this.showBalanceModal=!1}})}
1595
+
1596
+ ${q({visible:this.showOnrampModal,url:this.onrampUrl||void 0,errorMessage:this.onrampErrorMessage||void 0,width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0},title:"Pay with credit card"})}
1597
+ <div class="icpay-powered-by">
1598
+ <a href="https://icpay.org" target="_blank" rel="noopener noreferrer">Powered by icpay</a>
1599
+ </div>
1600
+ </div>
1601
+ `:oe`<div class="icpay-card icpay-section">Loading...</div>`}};w.styles=[j,mt`
1602
+ .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; }
1603
+ .fill { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(135deg, #d1d5db 0%, #9ca3af 100%); transition: height 0.8s ease; height: 0%; }
1604
+ .amounts { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin: 12px 0; }
1605
+ .chip { background: var(--icpay-surface-alt); border: 2px solid var(--icpay-border); border-radius: 12px; padding: 12px; text-align: center; cursor: pointer; color: var(--icpay-text); font-weight: 600; }
1606
+ .chip.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }
1607
+ .crypto-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 16px; }
1608
+ .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; }
1609
+ .crypto-option.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }
1610
+
1611
+ .error-message {
1612
+ border: 1px solid;
1613
+ font-weight: 500;
1614
+ }
1615
+
1616
+ .error-message.info {
1617
+ background: var(--icpay-processing-bg);
1618
+ border-color: var(--icpay-processing-border);
1619
+ color: var(--icpay-processing-text);
1620
+ }
1621
+
1622
+ .error-message.warning {
1623
+ background: var(--icpay-warning-bg);
1624
+ border-color: var(--icpay-warning-border);
1625
+ color: var(--icpay-warning-text);
1626
+ }
1627
+
1628
+ .error-message.error {
1629
+ background: var(--icpay-error-bg);
1630
+ border-color: var(--icpay-error-border);
1631
+ color: var(--icpay-error-text);
1632
+ }
1633
+ `],r([vt({type:Object})],w.prototype,"config",2),r([W()],w.prototype,"selectedAmount",2),r([W()],w.prototype,"selectedSymbol",2),r([W()],w.prototype,"total",2),r([W()],w.prototype,"processing",2),r([W()],w.prototype,"succeeded",2),r([W()],w.prototype,"errorMessage",2),r([W()],w.prototype,"errorSeverity",2),r([W()],w.prototype,"errorAction",2),r([W()],w.prototype,"walletConnected",2),r([W()],w.prototype,"pendingAction",2),r([W()],w.prototype,"showWalletModal",2),r([W()],w.prototype,"walletModalStep",2),r([W()],w.prototype,"oisyReadyToPay",2),r([W()],w.prototype,"lastWalletId",2),r([W()],w.prototype,"showOnrampModal",2),r([W()],w.prototype,"onrampUrl",2),r([W()],w.prototype,"onrampPaymentIntentId",2),r([W()],w.prototype,"onrampErrorMessage",2),r([W()],w.prototype,"showBalanceModal",2),r([W()],w.prototype,"balancesLoading",2),r([W()],w.prototype,"balancesError",2),r([W()],w.prototype,"walletBalances",2),w=r([ft("icpay-tip-jar")],w);import{LitElement as bt,html as me,css as wt}from"lit";import{customElement as xt,property as Ce,state as T}from"lit/decorators.js";var Fe=typeof window<"u",ce=null;function fe(i,s,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${s}`,e):console.log(`[ICPay Widget] ${s}`))}var m=class extends bt{constructor(){super(...arguments);this.title="Article Title";this.preview="";this.lockedContent="";this.selectedSymbol=null;this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.walletModalStep="connect";this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampUrl=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.sdk=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="unlock",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.config?.priceUsd||0),a=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"unlock",type:"sendUsd",amount:t,currency:a}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(n=>n?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),B(this.lastWalletId)){let n=(this.walletBalances||[]).find(l=>l?.tokenShortcode===e),o=n?.chainId;this.showBalanceModal=!1,this.showWalletModal=!1,V(o,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:n?.chainName,rpcUrlPublic:n?.rpcUrlPublic,nativeSymbol:n?.ledgerSymbol,decimals:n?.decimals}).then(async()=>{try{let l=u(this.config),d=Number(this.config?.priceUsd??0);if(n?.x402Accepts)try{await l.client.createPaymentX402Usd({usdAmount:d,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:n?.ledgerId,icpay_context:"article:x402"}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"});return}catch{}await l.client.createPaymentUsd({usdAmount:d,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:n?.ledgerId}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"})}catch{}});return}this.showBalanceModal=!1,this.showWalletModal=!1;let a=this.pendingAction;if(this.pendingAction=null,a==="unlock")try{let n=(this.walletBalances||[]).find(y=>y?.tokenShortcode===e),o=u(this.config),l=Number(this.config?.priceUsd??0),p=String(n?.ledgerName||n?.chainName||"").toLowerCase().includes("sol"),h=this.config?.recipientAddresses||{},c=p&&h.sol||h.ic;if(p&&n?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:l,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"sol",icpay_ledger_id:n?.ledgerId,icpay_context:"article:x402"}},recipientAddress:c||""});return}catch{return}await o.client.createPaymentUsd({usdAmount:l,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"ic",icpay_ledger_id:n?.ledgerId}},recipientAddress:c||"0x0000000000000000000000000000000000000000"})}catch{}}}get obfuscatedLockedContent(){try{return(this.lockedContent||"").replace(/[^\s]/g,"x")}catch{return"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}}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;ce||(ce=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let a={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");a.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}let n=new ce(a);this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,a=t?.event_id||t?.eventId||t?.id;if(!(!a||typeof a!="string")&&a==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let n=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(n||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let t=await u(this.config).startOnrampUsd(this.config.priceUsd,void 0,{context:"article:onramp",onrampPayment:!0,onrampProvider:"coinbase"}),a=t?.metadata?.onramp?.url||t?.onramp?.url||t?.metadata?.icpay_onramp?.url||t?.paymentIntent?.metadata?.icpay?.onrampUrl||t?.metadata?.icpay?.onrampUrl||null,n=t?.metadata?.icpay_payment_intent_id||t?.metadata?.paymentIntentId||t?.paymentIntentId||null,o=t?.metadata?.icpay_onramp?.errorMessage||t?.metadata?.onramp?.errorMessage||t?.paymentIntent?.metadata?.icpay?.onrampError||t?.paymentIntent?.metadata?.icpay?.errorMessage||t?.metadata?.icpay?.onrampError||t?.metadata?.icpay?.errorMessage||null;if(this.onrampPaymentIntentId=n,a){this.onrampUrl=a,this.onrampErrorMessage=null;try{window.open(a,"icpay_onramp","noopener,noreferrer");try{window.dispatchEvent(new CustomEvent("icpay-onramp-opened",{detail:{url:a}}))}catch{}}catch{}this.startOnrampPolling()}else this.onrampUrl=null,this.onrampErrorMessage=o||"Failed to obtain onramp URL",this.showOnrampModal=!0}catch(e){this.onrampUrl=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp URL",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let a=u(this.config),n=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>n()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=a.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}connectedCallback(){if(super.connectedCallback(),!!Fe){fe(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();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}}}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;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}this.walletModalStep!=="balances"&&!this.oisyReadyToPay&&(this.pendingAction=null,setTimeout(()=>{t==="unlock"&&this.unlock()},0))}}selectSymbol(e){this.selectedSymbol=e}async unlock(){if(Fe&&!(this.processing||this.unlocked)){fe(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||"ICP"}}))}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){fe(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{ce||(ce=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?$({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:n}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||n()}}catch{}this.pnp=new ce(t);try{let n=await te(this.pnp);if(n){this.walletConnected=!0;let o=U(this.pnp,{owner:n,principal:n,connected:!0}),l=this.pnp?.getEvmProvider?.(),d=this.pnp?.getSolanaProvider?.();this.config={...this.config,connectedWallet:o,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...l?{evmProvider:l}:{},...d?{solanaProvider:d}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.unlock();return}}catch{}let a=this.pnp.getEnabledWallets();if(fe(this.config?.debug||!1,"Available wallets",a),!a?.length)throw new Error("No wallets available");this.pendingAction="unlock",this.showWalletModal=!0;return}catch(e){fe(this.config?.debug||!1,"Wallet connection error:",e),this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error";return}}this.showWalletModal=!1,await this.fetchAndShowBalances();return}catch(e){_(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),z(t)&&(this.errorMessage=D(t),this.errorSeverity=K(t),this.errorAction=F(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}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}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(a=>{if(!!!(a&&(a.connected===!0||a.principal||a.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{}let o=U(this.pnp,a),l=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:o,actorProvider:(d,p)=>this.pnp.getActor({canisterId:d,idl:p,requiresSigning:!0,anon:!1}),...l?{evmProvider:l}:{}},this.sdk=null,this.walletModalStep="balances",this.showBalanceModal=!1,this.showWalletModal=!0,this.fetchAndShowBalances()}).catch(a=>{this.errorMessage=a instanceof Error?a.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(){try{this.balancesLoading=!0,this.balancesError=null,this.walletModalStep="balances",this.showBalanceModal=!1;let e=u(this.config),{balances:t}=await X({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.config?.priceUsd??0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!1}}render(){return this.config?me`
1634
+ <div class="icpay-card icpay-section icpay-widget-base">
1635
+ ${this.config?.progressBar?.enabled!==!1?me`
1636
+ <icpay-progress-bar
1637
+ .debug=${!!this.config?.debug}
1638
+ .theme=${this.config?.theme}
1639
+ .amount=${Number(this.config?.priceUsd||0)}
1640
+ .ledgerSymbol=${this.selectedSymbol||"ICP"}
1641
+ ></icpay-progress-bar>
1642
+ `:null}
1643
+ <div class="container">
1644
+ <div class="title">${this.title}</div>
1645
+ <div class="preview">${this.preview}</div>
1646
+ <div class="${this.unlocked?"unlocked":"locked"}">${this.unlocked?this.lockedContent:this.obfuscatedLockedContent}</div>
1647
+ </div>
1648
+
1649
+ <button class="pay-button ${this.processing?"processing":""}" ?disabled=${this.processing||this.unlocked||this.config?.disablePaymentButton===!0||this.succeeded&&this.config?.disableAfterSuccess===!0} @click=${()=>this.unlock()}>
1650
+ ${this.unlocked?"Unlocked":this.processing?"Processing\u2026":(this.config?.buttonLabel||"Pay ${amount} with crypto").replace("{amount}",`${Number(this.config?.priceUsd??0).toFixed(2)}`).replace("{symbol}",this.selectedSymbol||"ICP")}
1651
+ </button>
1652
+
1653
+ ${this.errorMessage?me`
1654
+ <div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
1655
+ ${this.errorMessage}
1656
+ ${this.errorAction?me`
1657
+ <button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">
1658
+ ${this.errorAction}
1659
+ </button>
1660
+ `:""}
1661
+ </div>
1662
+ `:""}
1663
+ ${(()=>{let e=this.pnp?.getEnabledWallets?.()||[],t=H(e);return G({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,step:this.walletModalStep,balances:this.walletModalStep==="balances"?this.walletBalances:[],balancesLoading:this.walletModalStep==="balances"?this.balancesLoading:!1,balancesError:this.walletModalStep==="balances"?this.balancesError:null,onSelectBalance:a=>this.onSelectBalanceSymbol(a),onBack:()=>{this.walletModalStep="connect"},onSelect:a=>this.connectWithWallet(a),onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-cancelled",{detail:{reason:"user_cancelled"}}))}catch{}},onDismiss:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0,creditCardTooltip:(()=>{let n=Number(this.config?.priceUsd||0);return n>0&&n<5&&this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?`Note: Minimum card amount is $5. You will pay about $${(5-n).toFixed(2)} more.`:null})(),oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1,this.unlock()}})})()}
1664
+
1665
+ ${Q({visible:this.showBalanceModal,isLoading:this.balancesLoading,error:this.balancesError,balances:this.walletBalances,onSelect:e=>this.onSelectBalanceSymbol(e),onClose:()=>{this.showBalanceModal=!1}})}
1666
+
1667
+ ${q({visible:this.showOnrampModal,url:this.onrampUrl||void 0,errorMessage:this.onrampErrorMessage||void 0,width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0},title:"Pay with credit card"})}
1668
+ <div class="icpay-powered-by">
1669
+ <a href="https://icpay.org" target="_blank" rel="noopener noreferrer">Powered by icpay</a>
1670
+ </div>
1671
+ </div>
1672
+ `:me`<div class="icpay-card icpay-section">Loading...</div>`}};m.styles=[j,wt`
1673
+ .container { background: var(--icpay-surface-alt); border: 1px solid var(--icpay-border); border-radius: 16px; padding: 16px; margin-bottom: 16px; }
1674
+ .title { color: var(--icpay-text); font-weight: 700; margin-bottom: 8px; }
1675
+ .preview { color: var(--icpay-muted-foreground); margin-bottom: 12px; line-height: 1.6; }
1676
+ .locked { filter: blur(3px); color: #6b7280; margin-bottom: 12px; }
1677
+ .unlocked { filter: blur(0); color: var(--icpay-text); }
1678
+ .crypto-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 16px; }
1679
+ .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; }
1680
+ .crypto-option.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }
1681
+
1682
+ .error-message {
1683
+ border: 1px solid;
1684
+ font-weight: 500;
1685
+ }
1686
+
1687
+ .error-message.info {
1688
+ background: var(--icpay-processing-bg);
1689
+ border-color: var(--icpay-processing-border);
1690
+ color: var(--icpay-processing-text);
1691
+ }
1692
+
1693
+ .error-message.warning {
1694
+ background: var(--icpay-warning-bg);
1695
+ border-color: var(--icpay-warning-border);
1696
+ color: var(--icpay-warning-text);
1697
+ }
1698
+
1699
+ .error-message.error {
1700
+ background: var(--icpay-error-bg);
1701
+ border-color: var(--icpay-error-border);
1702
+ color: var(--icpay-error-text);
1703
+ }
1704
+ `],r([Ce({type:Object})],m.prototype,"config",2),r([Ce({type:String})],m.prototype,"title",2),r([Ce({type:String})],m.prototype,"preview",2),r([Ce({type:String})],m.prototype,"lockedContent",2),r([T()],m.prototype,"selectedSymbol",2),r([T()],m.prototype,"unlocked",2),r([T()],m.prototype,"succeeded",2),r([T()],m.prototype,"processing",2),r([T()],m.prototype,"errorMessage",2),r([T()],m.prototype,"errorSeverity",2),r([T()],m.prototype,"errorAction",2),r([T()],m.prototype,"walletConnected",2),r([T()],m.prototype,"pendingAction",2),r([T()],m.prototype,"showWalletModal",2),r([T()],m.prototype,"walletModalStep",2),r([T()],m.prototype,"oisyReadyToPay",2),r([T()],m.prototype,"lastWalletId",2),r([T()],m.prototype,"showOnrampModal",2),r([T()],m.prototype,"onrampUrl",2),r([T()],m.prototype,"onrampPaymentIntentId",2),r([T()],m.prototype,"onrampErrorMessage",2),r([T()],m.prototype,"showBalanceModal",2),r([T()],m.prototype,"balancesLoading",2),r([T()],m.prototype,"balancesError",2),r([T()],m.prototype,"walletBalances",2),m=r([xt("icpay-article-paywall")],m);import{LitElement as Et,html as de,css as kt}from"lit";import{customElement as St,property as Mt,state as O}from"lit/decorators.js";var Ke=typeof window<"u",Oe=null;function ve(i,s,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${s}`,e):console.log(`[ICPay Widget] ${s}`))}var S=class extends Et{constructor(){super(...arguments);this.selectedIndex=0;this.selectedSymbol=null;this.processing=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.walletModalStep="connect";this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampUrl=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.sdk=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="order",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.selectedItem?.priceUsd||0),a=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"order",type:"sendUsd",amount:t,currency:a}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(n=>n?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),this.showBalanceModal=!1,this.showWalletModal=!1,B(this.lastWalletId)){let n=(this.walletBalances||[]).find(l=>l?.tokenShortcode===e),o=n?.chainId;V(o,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:n?.chainName,rpcUrlPublic:n?.rpcUrlPublic,nativeSymbol:n?.ledgerSymbol,decimals:n?.decimals}).then(async()=>{try{let l=u(this.config),d=Number(this.selectedItem?.priceUsd||0);if(n?.x402Accepts)try{await l.client.createPaymentX402Usd({usdAmount:d,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:n?.ledgerId,icpay_context:"coffee:x402",item:this.selectedItem?.name}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"}),this.showBalanceModal=!1;return}catch{}await l.client.createPaymentUsd({usdAmount:d,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:n?.ledgerId,item:this.selectedItem?.name}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"})}catch{}this.showBalanceModal=!1});return}let a=this.pendingAction;if(this.pendingAction=null,a==="order")try{let n=(this.walletBalances||[]).find(g=>g?.tokenShortcode===e),o=u(this.config),l=Number(this.selectedItem?.priceUsd||0),d=String(n?.ledgerName||n?.chainName||"").toLowerCase(),p=d.includes("sol"),h=d.includes("ic"),c=this.config?.recipientAddresses||{},y=p&&c.sol||c.ic;if(n?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:l,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:p?"sol":h?"ic":this.config?.icpay_network,icpay_ledger_id:n?.ledgerId,icpay_context:"coffee:x402",item:this.selectedItem?.name}},recipientAddress:y||""});return}catch{return}await o.client.createPaymentUsd({usdAmount:l,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"ic",icpay_ledger_id:n?.ledgerId,item:this.selectedItem?.name}},recipientAddress:y||"0x0000000000000000000000000000000000000000"})}catch{}}}connectedCallback(){if(super.connectedCallback(),!!Ke){ve(this.config?.debug||!1,"Coffee shop connected",{config:this.config}),this.config&&typeof this.config.defaultItemIndex=="number"&&(this.selectedIndex=this.config.defaultItemIndex);try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.requestUpdate()}))}catch{}}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}this.walletModalStep!=="balances"&&!this.oisyReadyToPay&&(this.pendingAction=null,setTimeout(()=>{t==="order"&&this.order()},0))}}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(Ke&&!this.processing){ve(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||"ICP"}}))}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){ve(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{Oe||(Oe=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?$({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}},a=this.config?.recipientAddresses;if(a&&(a.ic||a.evm||a.sol)){let o=[];a.ic&&o.push("ic"),a.evm&&o.push("evm"),a.sol&&o.push("sol"),o.length&&(t.chainTypes=o)}else this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}this.pnp=new Oe(t);try{let o=await te(this.pnp);if(o){this.walletConnected=!0;let l=U(this.pnp,{owner:o,principal:o,connected:!0}),d=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:l,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...d?{evmProvider:d}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.order();return}}catch{}let n=this.pnp.getEnabledWallets();if(ve(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="order",this.showWalletModal=!0;return}catch(e){ve(this.config?.debug||!1,"Wallet connection error:",e),this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error";return}}this.pendingAction="order",this.showWalletModal=!0,await this.fetchAndShowBalances();return}catch(e){_(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),z(t)&&(this.errorMessage=D(t),this.errorSeverity=K(t),this.errorAction=F(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,a=t?.event_id||t?.eventId||t?.id;if(!(!a||typeof a!="string")&&a==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let n=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(n||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let t=await u(this.config).startOnrampUsd(this.selectedItem.priceUsd,void 0,{context:"coffee:onramp",onrampPayment:!0,item:this.selectedItem.name,onrampProvider:"coinbase"}),a=t?.metadata?.onramp?.url||t?.onramp?.url||t?.metadata?.icpay_onramp?.url||t?.paymentIntent?.metadata?.icpay?.onrampUrl||t?.metadata?.icpay?.onrampUrl||null,n=t?.metadata?.icpay_payment_intent_id||t?.metadata?.paymentIntentId||t?.paymentIntentId||null,o=t?.metadata?.icpay_onramp?.errorMessage||t?.metadata?.onramp?.errorMessage||t?.paymentIntent?.metadata?.icpay?.onrampError||t?.paymentIntent?.metadata?.icpay?.errorMessage||t?.metadata?.icpay?.onrampError||t?.metadata?.icpay?.errorMessage||null;if(this.onrampPaymentIntentId=n,a){this.onrampUrl=a,this.onrampErrorMessage=null;try{window.open(a,"icpay_onramp","noopener,noreferrer");try{window.dispatchEvent(new CustomEvent("icpay-onramp-opened",{detail:{url:a}}))}catch{}}catch{}this.startOnrampPolling()}else this.onrampUrl=null,this.onrampErrorMessage=o||"Failed to obtain onramp URL",this.showOnrampModal=!0}catch(e){this.onrampUrl=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp URL",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let a=u(this.config),n=()=>{if(this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>n()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=a.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=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}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(a=>{if(!!!(a&&(a.connected===!0||a.principal||a.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{}let o=U(this.pnp,a),l=this.pnp?.getEvmProvider?.(),d=this.pnp?.getSolanaProvider?.();this.config={...this.config,connectedWallet:o,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...l?{evmProvider:l}:{},...d?{solanaProvider:d}:{}},this.sdk=null,this.walletModalStep="balances",this.showBalanceModal=!1,this.showWalletModal=!0,this.fetchAndShowBalances()}).catch(a=>{this.errorMessage=a instanceof Error?a.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(){try{this.balancesLoading=!0,this.balancesError=null,this.walletModalStep="balances",this.showBalanceModal=!1;let e=u(this.config),{balances:t}=await X({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.selectedItem?.priceUsd??0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!1}}render(){return this.config?de`
1705
+ <div class="icpay-card icpay-section icpay-widget-base">
1706
+ ${this.config?.progressBar?.enabled!==!1?de`
1707
+ <icpay-progress-bar
1708
+ .debug=${!!this.config?.debug}
1709
+ .theme=${this.config?.theme}
1710
+ .amount=${Number(this.selectedItem?.priceUsd||0)}
1711
+ .ledgerSymbol=${this.selectedSymbol||"ICP"}
1712
+ ></icpay-progress-bar>
1713
+ `:null}
1714
+ <div class="menu">
1715
+ ${this.config.items.map((e,t)=>de`
1716
+ <div class="item ${this.selectedIndex===t?"selected":""}" @click=${()=>this.selectItem(t)}>
1717
+ <span>${e.name}</span>
1718
+ <span>$${Number(e?.priceUsd??0).toFixed(2)}</span>
1719
+ </div>
1720
+ `)}
1721
+ </div>
1722
+
1723
+ <div class="total">Order Total: $${Number(this.selectedItem?.priceUsd??0).toFixed(2)}</div>
1724
+
1725
+
1726
+
1727
+ <button class="pay-button ${this.processing?"processing":""}" ?disabled=${this.processing} @click=${()=>this.order()}>
1728
+ ${this.processing?"Processing\u2026":`Order ${this.selectedItem.name}`}
1729
+ </button>
1730
+
1731
+ ${this.errorMessage?de`
1732
+ <div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
1733
+ ${this.errorMessage}
1734
+ ${this.errorAction?de`
1735
+ <button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">
1736
+ ${this.errorAction}
1737
+ </button>
1738
+ `:""}
1739
+ </div>
1740
+ `:""}
1741
+ ${(()=>{let e=this.pnp?.getEnabledWallets?.()||[],t=H(e);return G({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,step:this.walletModalStep,balances:this.walletModalStep==="balances"?this.walletBalances:[],balancesLoading:this.walletModalStep==="balances"?this.balancesLoading:!1,balancesError:this.walletModalStep==="balances"?this.balancesError:null,onSelectBalance:a=>this.onSelectBalanceSymbol(a),onBack:()=>{this.walletModalStep="connect"},onSwitchAccount:()=>this.onSwitchAccount(null),onSelect:a=>this.connectWithWallet(a),onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-cancelled",{detail:{reason:"user_cancelled"}}))}catch{}},onDismiss:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0,creditCardTooltip:(()=>{let n=this.config?.defaultItemIndex??0,o=Number(this.config?.items?.[n]?.priceUsd||0);return o>0&&o<5&&this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?`Note: Minimum card amount is $5. You will pay about $${(5-o).toFixed(2)} more.`:null})(),oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1,this.order()}})})()}
1742
+
1743
+ ${Q({visible:this.showBalanceModal,isLoading:this.balancesLoading,error:this.balancesError,balances:this.walletBalances,onSelect:e=>this.onSelectBalanceSymbol(e),onClose:()=>{this.showBalanceModal=!1}})}
1744
+
1745
+ ${q({visible:this.showOnrampModal,url:this.onrampUrl||void 0,errorMessage:this.onrampErrorMessage||void 0,width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0},title:"Pay with credit card"})}
1746
+ <div class="icpay-powered-by">
1747
+ <a href="https://icpay.org" target="_blank" rel="noopener noreferrer">Powered by icpay</a>
1748
+ </div>
1749
+ </div>
1750
+ `:de`<div class="icpay-card icpay-section">Loading...</div>`}};S.styles=[j,kt`
1751
+ .menu { display: grid; gap: 8px; margin-bottom: 12px; }
1752
+ .item { background: var(--icpay-surface-alt); border: 2px solid var(--icpay-border); border-radius: 12px; padding: 16px; display:flex; justify-content: space-between; align-items:center; cursor: pointer; color: var(--icpay-text); font-weight: 600; }
1753
+ .item.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }
1754
+ .total { background: var(--icpay-surface-alt); border: 1px solid var(--icpay-border); border-radius: 12px; padding: 12px; text-align: center; margin-bottom: 12px; color: var(--icpay-text); }
1755
+ .crypto-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 16px; }
1756
+ .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; }
1757
+ .crypto-option.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }
1758
+
1759
+ .error-message {
1760
+ border: 1px solid;
1761
+ font-weight: 500;
1762
+ }
1763
+
1764
+ .error-message.info {
1765
+ background: var(--icpay-processing-bg);
1766
+ border-color: var(--icpay-processing-border);
1767
+ color: var(--icpay-processing-text);
1768
+ }
1769
+
1770
+ .error-message.warning {
1771
+ background: var(--icpay-warning-bg);
1772
+ border-color: var(--icpay-warning-border);
1773
+ color: var(--icpay-warning-text);
1774
+ }
1775
+
1776
+ .error-message.error {
1777
+ background: var(--icpay-error-bg);
1778
+ border-color: var(--icpay-error-border);
1779
+ color: var(--icpay-error-text);
1780
+ }
1781
+ `],r([Mt({type:Object})],S.prototype,"config",2),r([O()],S.prototype,"selectedIndex",2),r([O()],S.prototype,"selectedSymbol",2),r([O()],S.prototype,"processing",2),r([O()],S.prototype,"errorMessage",2),r([O()],S.prototype,"errorSeverity",2),r([O()],S.prototype,"errorAction",2),r([O()],S.prototype,"walletConnected",2),r([O()],S.prototype,"pendingAction",2),r([O()],S.prototype,"showWalletModal",2),r([O()],S.prototype,"walletModalStep",2),r([O()],S.prototype,"oisyReadyToPay",2),r([O()],S.prototype,"lastWalletId",2),r([O()],S.prototype,"showOnrampModal",2),r([O()],S.prototype,"onrampUrl",2),r([O()],S.prototype,"onrampPaymentIntentId",2),r([O()],S.prototype,"onrampErrorMessage",2),r([O()],S.prototype,"showBalanceModal",2),r([O()],S.prototype,"balancesLoading",2),r([O()],S.prototype,"balancesError",2),r([O()],S.prototype,"walletBalances",2),S=r([St("icpay-coffee-shop")],S);import{LitElement as Wt,html as pe,css as At}from"lit";import{customElement as Ct,property as Lt,state as A}from"lit/decorators.js";var je=typeof window<"u",he=null;function be(i,s,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${s}`,e):console.log(`[ICPay Widget] ${s}`))}var x=class extends Wt{constructor(){super(...arguments);this.selectedAmount=10;this.selectedSymbol=null;this.raised=0;this.processing=!1;this.succeeded=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.walletModalStep="connect";this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampUrl=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.sdk=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="donate",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.selectedAmount||0),a=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"donate",type:"sendUsd",amount:t,currency:a}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(n=>n?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),this.showBalanceModal=!1,this.showWalletModal=!1,B(this.lastWalletId)){let n=(this.walletBalances||[]).find(l=>l?.tokenShortcode===e),o=n?.chainId;V(o,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:n?.chainName,rpcUrlPublic:n?.rpcUrlPublic,nativeSymbol:n?.ledgerSymbol,decimals:n?.decimals}).then(async()=>{try{let l=u(this.config),d=Number(this.selectedAmount||0);if(n?.x402Accepts)try{await l.client.createPaymentX402Usd({usdAmount:d,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:n?.ledgerId,icpay_context:"donation:x402"},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"}),this.showBalanceModal=!1;return}catch{}await l.client.createPaymentUsd({usdAmount:d,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:n?.ledgerId},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"})}catch{}this.showBalanceModal=!1});return}let a=this.pendingAction;if(this.pendingAction=null,a==="donate")try{let n=(this.walletBalances||[]).find(y=>y?.tokenShortcode===e),o=u(this.config),l=Number(this.selectedAmount||0),p=String(n?.ledgerName||n?.chainName||"").toLowerCase().includes("sol"),h=this.config?.recipientAddresses||{},c=p&&h.sol||h.ic;if(p&&n?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:l,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"sol",icpay_ledger_id:n?.ledgerId,icpay_context:"donation:x402"}},recipientAddress:c||""});return}catch{return}await o.client.createPaymentUsd({usdAmount:l,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"ic",icpay_ledger_id:n?.ledgerId}},recipientAddress:c||"0x0000000000000000000000000000000000000000"})}catch{}}}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;he||(he=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let a=$({...this.config?.plugNPlay||{}});try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");a.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}let n=new he(a);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]}connectedCallback(){if(super.connectedCallback(),!!je){be(this.config?.debug||!1,"Donation thermometer connected",{config:this.config}),this.config&&typeof this.config.defaultAmountUsd=="number"&&(this.selectedAmount=this.config.defaultAmountUsd),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.requestUpdate()}))}catch{}}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}this.walletModalStep!=="balances"&&!this.oisyReadyToPay&&(this.pendingAction=null,setTimeout(()=>{t==="donate"&&this.donate()},0))}}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(je&&!this.processing){be(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||"ICP"}}))}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){be(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{he||(he=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?$({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);try{if(typeof window<"u"){let{resolveDerivationOrigin:n}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||n()}}catch{}this.pnp=new he(t);try{let n=await te(this.pnp);if(n){this.walletConnected=!0;let o=U(this.pnp,{owner:n,principal:n,connected:!0}),l=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:o,actorProvider:(d,p)=>this.pnp.getActor({canisterId:d,idl:p,requiresSigning:!0,anon:!1}),...l?{evmProvider:l}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.donate();return}}catch{}let a=this.pnp.getEnabledWallets();if(be(this.config?.debug||!1,"Available wallets",a),!a?.length)throw new Error("No wallets available");this.pendingAction="donate",this.showWalletModal=!0;return}catch(e){be(this.config?.debug||!1,"Wallet connection error:",e),this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error";return}}this.showWalletModal=!0,await this.fetchAndShowBalances();return}catch(e){_(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),z(t)&&(this.errorMessage=D(t),this.errorSeverity=K(t),this.errorAction=F(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,a=t?.event_id||t?.eventId||t?.id;if(!(!a||typeof a!="string")&&a==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let n=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(n||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let t=await u(this.config).startOnrampUsd(this.selectedAmount,void 0,{context:"donation:onramp",onrampPayment:!0,onrampProvider:"coinbase"}),a=t?.metadata?.onramp?.url||t?.onramp?.url||t?.metadata?.icpay_onramp?.url||t?.paymentIntent?.metadata?.icpay?.onrampUrl||t?.metadata?.icpay?.onrampUrl||null,n=t?.metadata?.icpay_payment_intent_id||t?.metadata?.paymentIntentId||t?.paymentIntentId||null,o=t?.metadata?.icpay_onramp?.errorMessage||t?.metadata?.onramp?.errorMessage||t?.paymentIntent?.metadata?.icpay?.onrampError||t?.paymentIntent?.metadata?.icpay?.errorMessage||t?.metadata?.icpay?.onrampError||t?.metadata?.icpay?.errorMessage||null;if(this.onrampPaymentIntentId=n,a){this.onrampUrl=a,this.onrampErrorMessage=null;try{window.open(a,"icpay_onramp","noopener,noreferrer");try{window.dispatchEvent(new CustomEvent("icpay-onramp-opened",{detail:{url:a}}))}catch{}}catch{}this.startOnrampPolling()}else this.onrampUrl=null,this.onrampErrorMessage=o||"Failed to obtain onramp URL",this.showOnrampModal=!0}catch(e){this.onrampUrl=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp URL",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let a=u(this.config),n=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>n()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=a.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=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}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(a=>{if(!!!(a&&(a.connected===!0||a.principal||a.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{}let o=U(this.pnp,a),l=this.pnp?.getEvmProvider?.(),d=this.pnp?.getSolanaProvider?.();this.config={...this.config,connectedWallet:o,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...l?{evmProvider:l}:{},...d?{solanaProvider:d}:{}},this.sdk=null,this.walletModalStep="balances",this.showBalanceModal=!1,this.showWalletModal=!0,this.fetchAndShowBalances()}).catch(a=>{this.errorMessage=a instanceof Error?a.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(){try{this.balancesLoading=!0,this.balancesError=null,this.walletModalStep="balances",this.showBalanceModal=!1;let e=u(this.config),{balances:t}=await X({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.selectedAmount||0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!1}}render(){return this.config?pe`
1782
+ <div class="icpay-card icpay-section icpay-widget-base" style="text-align:center;">
1783
+ ${this.config?.progressBar?.enabled!==!1?pe`
1784
+ <icpay-progress-bar
1785
+ .debug=${!!this.config?.debug}
1786
+ .theme=${this.config?.theme}
1787
+ .amount=${Number(this.selectedAmount||0)}
1788
+ .ledgerSymbol=${this.selectedSymbol||"ICP"}
1789
+ ></icpay-progress-bar>
1790
+ `:null}
1791
+ <div class="thermo"><div class="fill" style="height:${this.fillPercentage}%"></div></div>
1792
+ <div class="total">$${Number(this.raised).toFixed(0)} / $${Number(this.config?.goalUsd??0).toFixed(2)}</div>
1793
+
1794
+ <div class="amounts">
1795
+ ${this.amounts.map(e=>pe`<div class="chip ${this.selectedAmount===e?"selected":""}" @click=${()=>this.selectAmount(e)}>$${e}</div>`)}
1796
+ </div>
1797
+
1798
+
1799
+
1800
+ <button class="pay-button ${this.processing?"processing":""}"
1801
+ ?disabled=${this.processing||this.config?.disablePaymentButton===!0||this.succeeded&&this.config?.disableAfterSuccess===!0}
1802
+ @click=${()=>this.donate()}>
1803
+ ${this.succeeded&&this.config?.disableAfterSuccess?"Donated":this.processing?"Processing\u2026":(this.config?.buttonLabel||"Donate {amount} with crypto").replace("{amount}",`${this.selectedAmount}`).replace("{symbol}",this.selectedSymbol||"ICP")}
1804
+ </button>
1805
+
1806
+ ${this.errorMessage?pe`
1807
+ <div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
1808
+ ${this.errorMessage}
1809
+ ${this.errorAction?pe`
1810
+ <button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">
1811
+ ${this.errorAction}
1812
+ </button>
1813
+ `:""}
1814
+ </div>
1815
+ `:""}
1816
+ ${(()=>{let e=this.pnp?.getEnabledWallets?.()||[],t=H(e);return G({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,step:this.walletModalStep,balances:this.walletModalStep==="balances"?this.walletBalances:[],balancesLoading:this.walletModalStep==="balances"?this.balancesLoading:!1,balancesError:this.walletModalStep==="balances"?this.balancesError:null,onSelectBalance:a=>this.onSelectBalanceSymbol(a),onBack:()=>{this.walletModalStep="connect"},onSwitchAccount:()=>this.onSwitchAccount(null),onSelect:a=>this.connectWithWallet(a),onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-cancelled",{detail:{reason:"user_cancelled"}}))}catch{}},onDismiss:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0,creditCardTooltip:(()=>{let n=Number(this.selectedAmount||this.config?.defaultAmountUsd||0);return n>0&&n<5&&this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?`Note: Minimum card amount is $5. You will pay about $${(5-n).toFixed(2)} more.`:null})(),oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1,this.donate()}})})()}
1817
+
1818
+ ${Q({visible:this.showBalanceModal,isLoading:this.balancesLoading,error:this.balancesError,balances:this.walletBalances,onSelect:e=>this.onSelectBalanceSymbol(e),onClose:()=>{this.showBalanceModal=!1}})}
1819
+
1820
+ ${q({visible:this.showOnrampModal,url:this.onrampUrl||void 0,errorMessage:this.onrampErrorMessage||void 0,width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0},title:"Pay with credit card"})}
1821
+ <div class="icpay-powered-by">
1822
+ <a href="https://icpay.org" target="_blank" rel="noopener noreferrer">Powered by icpay</a>
1823
+ </div>
1824
+ </div>
1825
+ `:pe`<div class="icpay-card icpay-section">Loading...</div>`}};x.styles=[j,At`
1826
+ .thermo { width: 60px; height: 200px; background: var(--icpay-surface-alt); border: 3px solid #6b7280; border-radius: 30px; margin: 0 auto 12px; position: relative; overflow: hidden; }
1827
+ .fill { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(135deg, #d1d5db 0%, #9ca3af 100%); transition: height 0.8s ease; height: 0%; border-radius: 0 0 27px 27px; }
1828
+ .amounts { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin: 12px 0; }
1829
+ .chip { background: var(--icpay-surface-alt); border: 2px solid var(--icpay-border); border-radius: 12px; padding: 12px; text-align: center; cursor: pointer; color: var(--icpay-text); font-weight: 600; }
1830
+ .chip.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }
1831
+ .crypto-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 16px; }
1832
+ .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; }
1833
+ .crypto-option.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }
1834
+
1835
+ .error-message {
1836
+ border: 1px solid;
1837
+ font-weight: 500;
1838
+ }
1839
+
1840
+ .error-message.info {
1841
+ background: var(--icpay-processing-bg);
1842
+ border-color: var(--icpay-processing-border);
1843
+ color: var(--icpay-processing-text);
1844
+ }
1845
+
1846
+ .error-message.warning {
1847
+ background: var(--icpay-warning-bg);
1848
+ border-color: var(--icpay-warning-border);
1849
+ color: var(--icpay-warning-text);
1850
+ }
1851
+
1852
+ .error-message.error {
1853
+ background: var(--icpay-error-bg);
1854
+ border-color: var(--icpay-error-border);
1855
+ color: var(--icpay-error-text);
1856
+ }
1857
+ `],r([Lt({type:Object})],x.prototype,"config",2),r([A()],x.prototype,"selectedAmount",2),r([A()],x.prototype,"selectedSymbol",2),r([A()],x.prototype,"raised",2),r([A()],x.prototype,"processing",2),r([A()],x.prototype,"succeeded",2),r([A()],x.prototype,"errorMessage",2),r([A()],x.prototype,"errorSeverity",2),r([A()],x.prototype,"errorAction",2),r([A()],x.prototype,"walletConnected",2),r([A()],x.prototype,"pendingAction",2),r([A()],x.prototype,"showWalletModal",2),r([A()],x.prototype,"walletModalStep",2),r([A()],x.prototype,"oisyReadyToPay",2),r([A()],x.prototype,"lastWalletId",2),r([A()],x.prototype,"showOnrampModal",2),r([A()],x.prototype,"onrampUrl",2),r([A()],x.prototype,"onrampPaymentIntentId",2),r([A()],x.prototype,"onrampErrorMessage",2),r([A()],x.prototype,"showBalanceModal",2),r([A()],x.prototype,"balancesLoading",2),r([A()],x.prototype,"balancesError",2),r([A()],x.prototype,"walletBalances",2),x=r([Ct("icpay-donation-thermometer")],x);import{LitElement as Ut,html as we,css as Ot}from"lit";import{customElement as Nt,property as Pt,state as M}from"lit/decorators.js";import{html as Le}from"lit";function Tt(){if(typeof document>"u")return"dark";let i=document.documentElement.getAttribute("data-icpay-theme");if(i==="light"||i==="dark")return i;let s=document.documentElement.getAttribute("data-theme");return s==="light"||s==="dark"?s:"dark"}function qe(i){if(!i.visible)return null;let s=i.providers||[],e=Tt();return Le`
1858
+ <style>
1859
+ /* Theme-aware color variables - Light mode defaults */
1860
+ .icpay-onramp-overlay {
1861
+ --icpay-background: #ffffff;
1862
+ --icpay-foreground: #171717;
1863
+ --icpay-muted-foreground: #6b7280;
1864
+ --icpay-primary: #3b82f6;
1865
+ --icpay-primary-foreground: #ffffff;
1866
+ --icpay-secondary: #f3f4f6;
1867
+ --icpay-secondary-foreground: #171717;
1868
+ --icpay-accent: #f9fafb;
1869
+ --icpay-border: #e5e7eb;
1870
+ }
1871
+ /* Dark mode */
1872
+ [data-theme="dark"] .icpay-onramp-overlay,
1873
+ [data-icpay-theme="dark"] .icpay-onramp-overlay,
1874
+ :root[data-theme="dark"] .icpay-onramp-overlay,
1875
+ :root[data-icpay-theme="dark"] .icpay-onramp-overlay,
1876
+ html[data-theme="dark"] .icpay-onramp-overlay,
1877
+ html[data-icpay-theme="dark"] .icpay-onramp-overlay,
1878
+ .icpay-onramp-overlay[data-theme="dark"] {
1879
+ --icpay-background: hsl(222.2 84% 4.9%);
1880
+ --icpay-foreground: hsl(210 40% 98%);
1881
+ --icpay-muted-foreground: hsl(215 20.2% 65.1%);
1882
+ --icpay-primary: hsl(210 40% 98%);
1883
+ --icpay-primary-foreground: hsl(222.2 47.4% 11.2%);
1884
+ --icpay-secondary: hsl(217.2 32.6% 17.5%);
1885
+ --icpay-secondary-foreground: hsl(210 40% 98%);
1886
+ --icpay-accent: hsl(217.2 32.6% 17.5%);
1887
+ --icpay-border: hsl(217.2 32.6% 30%);
1888
+ }
1889
+ .icpay-onramp-provider-btn {
1890
+ display: flex;
1891
+ align-items: center;
1892
+ gap: 10px;
1893
+ background: var(--icpay-secondary);
1894
+ border: 1px solid var(--icpay-border);
1895
+ border-radius: 10px;
1896
+ padding: 10px 12px;
1897
+ color: var(--icpay-foreground);
1898
+ cursor: pointer;
1899
+ text-align: left;
1900
+ transition: background-color 0.2s;
1901
+ }
1902
+ .icpay-onramp-provider-btn:hover {
1903
+ background: var(--icpay-accent);
1904
+ }
1905
+ .icpay-onramp-overlay {
1906
+ position: fixed !important;
1907
+ inset: 0 !important;
1908
+ display: flex;
1909
+ align-items: center;
1910
+ justify-content: center;
1911
+ background: rgba(0,0,0,0.85);
1912
+ backdrop-filter: blur(10px);
1913
+ z-index: 99999 !important;
1914
+ /* Ensure modal breaks out of any parent constraints */
1915
+ transform: none !important;
1916
+ will-change: auto;
1917
+ isolation: isolate;
1918
+ }
1919
+ .icpay-onramp-container {
1920
+ position: relative;
1921
+ background: var(--icpay-background);
1922
+ border: 1px solid var(--icpay-border);
1923
+ border-radius: 16px;
1924
+ padding: 16px;
1925
+ box-shadow: 0 20px 60px rgba(0,0,0,0.5);
1926
+ min-width: 320px;
1927
+ max-width: 420px;
1928
+ margin: auto;
1929
+ }
1930
+ @media (max-width: 768px) {
1931
+ .icpay-onramp-overlay {
1932
+ align-items: flex-end;
1933
+ justify-content: stretch;
1934
+ }
1935
+ .icpay-onramp-container {
1936
+ max-width: 100%;
1937
+ width: 100%;
1938
+ height: 70vh;
1939
+ max-height: 70vh;
1940
+ border-radius: 16px 16px 0 0;
1941
+ margin: 0;
1942
+ overflow-y: auto;
1943
+ }
1944
+ }
1945
+ </style>
1946
+ <div class="icpay-onramp-overlay" data-theme="${e}">
1947
+ <div class="icpay-onramp-container">
1948
+ <button @click=${i.onClose} style="position:absolute;right:12px;top:12px;background:transparent;border:none;color:var(--icpay-foreground);cursor:pointer;font-size:20px;opacity:0.8">×</button>
1949
+ <div style="color:var(--icpay-foreground);font-weight:600;font-size:16px;margin-bottom:12px">${i.title||"Choose a provider"}</div>
1950
+ <div style="display:flex;flex-direction:column;gap:10px">
1951
+ ${s.map(t=>Le`
1952
+ <button
1953
+ class="icpay-onramp-provider-btn"
1954
+ @click=${()=>i.onSelect(t.slug)}
1955
+ >
1956
+ ${t.logoUrl?Le`<img src="${t.logoUrl}" style="width:24px;height:24px;border-radius:4px" />`:Le`<div style="width:24px;height:24px;border-radius:4px;background:var(--icpay-secondary)"></div>`}
1957
+ <span style="font-size:14px">${t.name}</span>
1958
+ </button>
1959
+ `)}
1960
+ </div>
1961
+ </div>
1962
+ </div>
1963
+ `}var He=typeof window<"u",ye=null;function N(i,s,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${s}`,e):console.log(`[ICPay Widget] ${s}`))}var f=class extends Ut{constructor(){super(...arguments);this.selectedSymbol=null;this.processing=!1;this.succeeded=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.walletModalStep="connect";this.showOnrampModal=!1;this.onrampUrl=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.showProviderPicker=!1;this.selectedOnrampProvider=null;this.oisyReadyToPay=!1;this.oisySignerPreopened=!1;this.skipDisconnectOnce=!1;this.lastWalletId=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.onrampPollTimer=null;this.pnp=null;this.oisyConnectRetriedNewTab=!1;this.sdk=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="pay",this.walletModalStep="connect",this.showWalletModal=!0,this.oisyReadyToPay=!1,this.lastWalletId=null,this.requestUpdate();try{let t=Number(this.config?.amountUsd||0),a=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:a}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(n=>n?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),this.showBalanceModal=!1,this.showWalletModal=!1,B(this.lastWalletId)){N(this.config?.debug||!1,"EVM selection made",{selectedSymbol:this.selectedSymbol,selPresent:!!t,selSnapshot:t?{ledgerId:t?.ledgerId,ledgerSymbol:t?.ledgerSymbol,ledgerName:t?.ledgerName,chainUuid:t?.chainUuid,chainId:t?.chainId,chainName:t?.chainName,x402Accepts:t?.x402Accepts,requiredAmount:t?.requiredAmount,hasSufficientBalance:t?.hasSufficientBalance}:null});let n=t?.chainId;V(n,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:t?.chainName,rpcUrlPublic:t?.rpcUrlPublic,nativeSymbol:t?.ledgerSymbol,decimals:t?.decimals}).then(async()=>{try{let o=this.getSdk(),l=Number(this.config?.amountUsd??0),d=t?.ledgerSymbol,p=!!(t&&t.x402Accepts);if(N(this.config?.debug||!1,"EVM post-ensure chain snapshot",{targetChain:n,amountUsd:l,symbolNow:d,tryX402:p,x402Accepts:t?.x402Accepts}),p)try{let c=this.config?.recipientAddresses?.evm||"0x0000000000000000000000000000000000000000";N(this.config?.debug||!1,"Using recipientAddress (x402)",{recipientAddress:c});let y={...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:t?.ledgerId,icpay_context:"pay-button:x402"}};N(this.config?.debug||!1,"Attempting X402 flow (EVM selection)",{amountUsd:l,tokenShortcode:t?.tokenShortcode,x402Accepts:t?.x402Accepts}),await o.client.createPaymentX402Usd({usdAmount:l,tokenShortcode:t?.tokenShortcode,metadata:y,recipientAddress:c});return}catch(c){N(this.config?.debug||!1,"X402 payment failed (EVM selection), falling back",{message:c?.message,code:c?.code,data:c?.details||c?.data})}else N(this.config?.debug||!1,"Skipping X402 path",{reason:t?t.x402Accepts?"unknown":"x402Accepts false":"no selection",selPresent:!!t,x402Accepts:t?.x402Accepts});N(this.config?.debug||!1,"Falling back to normal EVM wallet flow",{amountUsd:l,tokenShortcode:t?.tokenShortcode});let h=this.config?.recipientAddresses?.evm||"0x0000000000000000000000000000000000000000";N(this.config?.debug||!1,"Using recipientAddress (normal)",{recipientAddress:h}),await o.client.createPaymentUsd({usdAmount:l,tokenShortcode:t?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:t?.ledgerId}},recipientAddress:h})}catch{}});return}let a=this.pendingAction;if(this.pendingAction=null,a==="pay")try{let n=(this.walletBalances||[]).find(g=>g?.tokenShortcode===e),o=this.getSdk(),l=Number(this.config?.amountUsd??0);N(this.config?.debug||!1,"IC selection made",{selectedSymbol:this.selectedSymbol,selPresent:!!n,selSnapshot:n?{ledgerId:n?.ledgerId,ledgerSymbol:n?.ledgerSymbol,ledgerName:n?.ledgerName,requiredAmount:n?.requiredAmount,hasSufficientBalance:n?.hasSufficientBalance,tokenShortcode:n?.tokenShortcode}:null});let d=String(n?.chainName||"").toLowerCase(),p=d.includes("sol"),h=this.config?.recipientAddresses||{},c=p?h.sol||h.ic||this.config?.recipientAddress:h.ic||this.config?.recipientAddress,y=d.includes("ic");if(n?.x402Accepts)try{let g={...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:p?"sol":y?"ic":this.config?.icpay_network,icpay_ledger_id:n?.ledgerId,icpay_context:"pay-button:x402"}};await o.client.createPaymentX402Usd({usdAmount:l,tokenShortcode:n?.tokenShortcode,metadata:g,recipientAddress:c||""});return}catch(g){N(this.config?.debug||!1,"X402 payment failed (SOL selection), falling back",{message:g?.message,code:g?.code,data:g?.details||g?.data});return}await o.client.createPaymentUsd({usdAmount:l,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"ic",icpay_ledger_id:n?.ledgerId}},recipientAddress:c||"0x0000000000000000000000000000000000000000"})}catch{}}}getSdk(){return this.sdk||(this.sdk=u(this.config)),this.sdk}connectedCallback(){if(super.connectedCallback(),!!He){N(this.config?.debug||!1,"Pay button connected",{config:this.config});try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(e=>{N(this.config?.debug||!1,"SDK transaction created",{detail:e?.detail}),this.showWalletModal=!1,this.showBalanceModal=!1,this.requestUpdate()}))}catch{}}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}this.walletModalStep!=="balances"&&!this.oisyReadyToPay&&(this.pendingAction=null,setTimeout(()=>{t==="pay"&&this.pay()},0))}e.has("config")&&(this.sdk=null)}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{ye||(ye=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let e=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab),t={...this.config?.plugNPlay||{}},a=this.config?.recipientAddresses;if(a&&(a.ic||a.evm||a.sol)){let l=[];a.ic&&l.push("ic"),a.evm&&l.push("evm"),a.sol&&l.push("sol"),l.length&&(t.chainTypes=l)}else this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);let n=e?$(t):t;try{if(typeof window<"u"){let{resolveDerivationOrigin:l}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||l()}}catch{}this.pnp=new ye(n);let o=this.pnp.getEnabledWallets();if(N(this.config?.debug||!1,"Available wallets",o),!o?.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}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.lastWalletId==="oisy"&&(this.oisyConnectRetriedNewTab=!1),this.pnp.connect(e).then(a=>{if(N(this.config?.debug||!1,"Wallet connect result",a),!!!(a&&(a.connected===!0||a.principal||a.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{}let o=U(this.pnp,a),l=this.pnp?.getEvmProvider?.(),d=this.pnp?.getSolanaProvider?.();this.config={...this.config,connectedWallet:o,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...l?{evmProvider:l}:{},...d?{solanaProvider:d}:{}},this.sdk=null,this.walletModalStep="balances",this.fetchAndShowBalances("pay")}).catch(a=>{N(this.config?.debug||!1,"Wallet connection error",a);let n=(e||"").toLowerCase()==="oisy",o=a&&(a.message||String(a))||"";if(n&&!this.oisyConnectRetriedNewTab&&(o.includes("Signer window could not be opened")||o.includes("Communication channel could not be established"))){this.oisyConnectRetriedNewTab=!0,(async()=>{try{ye||(ye=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let d={...this.config?.plugNPlay||{}},p=this.config?.recipientAddresses;if(p&&(p.ic||p.evm||p.sol)){let y=[];p.ic&&y.push("ic"),p.evm&&y.push("evm"),p.sol&&y.push("sol"),y.length&&(d.chainTypes=y)}else this.config?.chainTypes&&(d.chainTypes=this.config.chainTypes);let h=$(d);try{if(typeof window<"u"){let{resolveDerivationOrigin:y}=await import("./origin-44ZEXSX4.js");h.derivationOrigin=this.config?.derivationOrigin||y()}}catch{}this.pnp=new ye(h),this.pnp.connect("oisy").then(y=>{if(!!!(y&&(y.connected===!0||y.principal||y.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:"oisy"}}))}catch{}let I=U(this.pnp,y),Z=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:I,actorProvider:(Ee,ke)=>this.pnp.getActor({canisterId:Ee,idl:ke,requiresSigning:!0,anon:!1}),...Z?{evmProvider:Z}:{}},this.sdk=null,this.walletModalStep="balances",this.fetchAndShowBalances("pay")}).catch(y=>{N(this.config?.debug||!1,"Oisy retry connect (new tab) failed",y),this.errorMessage=y instanceof Error?y.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(d){N(this.config?.debug||!1,"Oisy new-tab init failed",d),this.errorMessage=d instanceof Error?d.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}})();return}this.errorMessage=a instanceof Error?a.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){N(this.config?.debug||!1,"Wallet connection error (sync)",t),this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(e){try{this.balancesLoading=!0,this.balancesError=null,this.walletModalStep="balances",this.showBalanceModal=!1;let t=this.getSdk(),{balances:a}=await X({sdk:t,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.config?.amountUsd??0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=a,this.pendingAction=e}catch(t){this.walletBalances=[],this.balancesError=t&&(t.message||String(t))||"Failed to load balances"}finally{this.balancesLoading=!1}}renderWalletModal(){if(!this.showWalletModal||!this.pnp)return null;let e=this.pnp.getEnabledWallets()||[],t=H(e),a=this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0,n=2,o=Number(this.config?.amountUsd??0),l=a&&o>0&&o<n,d=Math.max(0,n-o),p=l?`Note: Minimum card amount is $${n}. You will pay about $${d.toFixed(2)} more.`:null;return G({visible:this.showWalletModal,wallets:t,isConnecting:!1,onSwitchAccount:()=>this.onSwitchAccount(null),step:this.walletModalStep,balances:this.walletModalStep==="balances"?this.walletBalances||[]:[],balancesLoading:this.walletModalStep==="balances"?this.balancesLoading:!1,balancesError:this.walletModalStep==="balances"?this.balancesError:null,onSelectBalance:h=>this.onSelectBalanceSymbol(h),onBack:()=>{this.walletModalStep="connect"},onSelect:h=>{this.connectWithWallet(h)},onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-cancelled",{detail:{reason:"user_cancelled"}}))}catch{}},onDismiss:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:a?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:a,creditCardTooltip:p,oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.skipDisconnectOnce=!0,this.oisyReadyToPay=!1,this.pay()}})}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1;let e=Array.isArray(this.config?.onramp?.providers)?this.config.onramp.providers.filter(a=>a&&a.enabled!==!1):[],t=e.length?e:[{slug:"coinbase",name:"Coinbase",enabled:!0}];t.length>1?this.showProviderPicker=!0:(this.selectedOnrampProvider=t[0]?.slug||"coinbase",setTimeout(()=>this.createOnrampIntent(),0))}async createOnrampIntent(){try{let e=Number(this.config?.amountUsd??0),t=this.getSdk();this.selectedSymbol||(this.selectedSymbol="ICP");let a=await t.startOnrampUsd(e,void 0,{context:"pay-button:onramp",onrampPayment:!0,onrampProvider:this.selectedOnrampProvider||"coinbase"}),n=a?.metadata?.onramp?.url||a?.onramp?.url||a?.metadata?.icpay_onramp?.url||a?.paymentIntent?.metadata?.icpay?.onrampUrl||a?.metadata?.icpay?.onrampUrl||null,o=a?.metadata?.icpay_onramp?.errorMessage||a?.metadata?.onramp?.errorMessage||a?.paymentIntent?.metadata?.icpay?.onrampError||a?.paymentIntent?.metadata?.icpay?.errorMessage||a?.metadata?.icpay?.onrampError||a?.metadata?.icpay?.errorMessage||null;this.onrampErrorMessage=o||null;let l=a?.metadata?.icpay_payment_intent_id||a?.metadata?.paymentIntentId||a?.paymentIntentId||null;if(this.onrampPaymentIntentId=l,n){this.onrampUrl=n;try{window.open(n,"icpay_onramp","noopener,noreferrer");try{window.dispatchEvent(new CustomEvent("icpay-onramp-opened",{detail:{url:n}}))}catch{}}catch{}this.startOnrampPolling(void 0)}else this.onrampUrl=null,this.showOnrampModal=!0}catch(e){this.onrampUrl=null,this.onrampErrorMessage=e?.message||null,this.showOnrampModal=!0,_(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),z(t)&&(this.errorMessage=D(t),this.errorSeverity=K(t),this.errorAction=F(t))}})}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let a=this.getSdk(),n=()=>{if(this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1},o=l=>{n()};try{window.addEventListener("icpay-sdk-transaction-completed",o,{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=a.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}async pay(){if(!(!He||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||"ICP"}}))}catch{}this.processing=!0;try{if(this.skipDisconnectOnce)this.skipDisconnectOnce=!1;else try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}if(!await this.ensureWallet())return;let t=this.getSdk();try{let a=this.config?.connectedWallet,n=this?.pnp?.account;N(this.config?.debug||!1,"Wallet state before payment",{connectedWallet:a,pnpAccount:n,principal:a?.owner||a?.principal||n?.owner||n?.principal||null})}catch{}this.walletModalStep="balances",this.showWalletModal=!0,await this.fetchAndShowBalances("pay");return}catch(e){N(this.config?.debug||!1,"Payment error",{message:e?.message,code:e?.code,details:e?.details,stack:e?.stack}),_(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),z(t)&&(this.errorMessage=D(t),this.errorSeverity=K(t),this.errorAction=F(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}render(){if(!this.config)return we`<div class="icpay-card icpay-section">Loading...</div>`;let e=this.selectedSymbol||"ICP",t=typeof this.config?.amountUsd=="number"?`${Number(this.config.amountUsd).toFixed(2)}`:"",n=(this.config?.buttonLabel||(typeof this.config?.amountUsd=="number"?"Pay ${amount} with crypto":"Pay with {symbol}")).replace("{amount}",t||"$0.00").replace("{symbol}",e),l=this.config?.progressBar?.enabled!==!1,d=this.showWalletModal||this.showBalanceModal;return we`
1964
+ <div class="icpay-card icpay-section icpay-widget-base">
1965
+ ${l?we`
1966
+ <icpay-progress-bar
1967
+ .debug=${!!this.config?.debug}
1968
+ .theme=${this.config?.theme}
1969
+ .amount=${Number(this.config?.amountUsd||0)}
1970
+ .ledgerSymbol=${e}
1971
+ .suspended=${d}
1972
+ ></icpay-progress-bar>
1973
+ `:null}
1974
+
1975
+ <div class="row single">
1976
+ <button class="pay-button ${this.processing?"processing":""}"
1977
+ ?disabled=${this.processing||this.config?.disablePaymentButton===!0||this.succeeded&&this.config?.disableAfterSuccess===!0}
1978
+ @click=${()=>this.pay()}>
1979
+ ${this.succeeded&&this.config?.disableAfterSuccess?"Paid":this.processing?"Processing\u2026":n}
1980
+ </button>
1981
+ </div>
1982
+
1983
+ ${this.errorMessage?we`
1984
+ <div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
1985
+ ${this.errorMessage}
1986
+ ${this.errorAction?we`<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>`:""}
1987
+ </div>
1988
+ `:""}
1989
+ ${this.renderWalletModal()}
1990
+ ${Q({visible:this.showBalanceModal,isLoading:this.balancesLoading,error:this.balancesError,balances:this.walletBalances,onSelect:p=>this.onSelectBalanceSymbol(p),onClose:()=>{this.showBalanceModal=!1}})}
1991
+ ${q({visible:this.showOnrampModal,url:this.onrampUrl||void 0,errorMessage:this.onrampErrorMessage||void 0,width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0},title:"Pay with credit card"})}
1992
+ ${qe({visible:this.showProviderPicker,providers:(()=>{let p=Array.isArray(this.config?.onramp?.providers)?this.config.onramp.providers.filter(c=>c&&c.enabled!==!1):[];return(p.length?p:[{slug:"coinbase",name:"Coinbase",enabled:!0}]).map(c=>({slug:c.slug,name:c.name||(c.slug==="coinbase"?"Coinbase":c.slug),logoUrl:c.logoUrl||null}))})(),onSelect:p=>{this.selectedOnrampProvider=p,this.showProviderPicker=!1,setTimeout(()=>this.createOnrampIntent(),0)},onClose:()=>{this.showProviderPicker=!1},title:"Choose onramp provider"})}
1993
+ <div class="icpay-powered-by">
1994
+ <a href="https://icpay.org" target="_blank" rel="noopener noreferrer">Powered by icpay</a>
1995
+ </div>
1996
+ </div>
1997
+ `}};f.styles=[j,Ot`
1998
+ .row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
1999
+ .row.single { grid-template-columns: 1fr; }
2000
+ select { background: var(--icpay-surface-alt); border: 1px solid var(--icpay-border); color: var(--icpay-text); border-radius: 8px; padding: 10px; font-weight: 600; }
2001
+ .error-message { border: 1px solid; font-weight: 500; }
2002
+ .error-message.info { background: var(--icpay-processing-bg); border-color: var(--icpay-processing-border); color: var(--icpay-processing-text); }
2003
+ .error-message.warning { background: var(--icpay-warning-bg); border-color: var(--icpay-warning-border); color: var(--icpay-warning-text); }
2004
+ .error-message.error { background: var(--icpay-error-bg); border-color: var(--icpay-error-border); color: var(--icpay-error-text); }
2005
+ `],r([Pt({type:Object})],f.prototype,"config",2),r([M()],f.prototype,"selectedSymbol",2),r([M()],f.prototype,"processing",2),r([M()],f.prototype,"succeeded",2),r([M()],f.prototype,"errorMessage",2),r([M()],f.prototype,"errorSeverity",2),r([M()],f.prototype,"errorAction",2),r([M()],f.prototype,"walletConnected",2),r([M()],f.prototype,"pendingAction",2),r([M()],f.prototype,"showWalletModal",2),r([M()],f.prototype,"walletModalStep",2),r([M()],f.prototype,"showOnrampModal",2),r([M()],f.prototype,"onrampUrl",2),r([M()],f.prototype,"onrampPaymentIntentId",2),r([M()],f.prototype,"onrampErrorMessage",2),r([M()],f.prototype,"showProviderPicker",2),r([M()],f.prototype,"selectedOnrampProvider",2),r([M()],f.prototype,"oisyReadyToPay",2),r([M()],f.prototype,"oisySignerPreopened",2),r([M()],f.prototype,"skipDisconnectOnce",2),r([M()],f.prototype,"lastWalletId",2),r([M()],f.prototype,"showBalanceModal",2),r([M()],f.prototype,"balancesLoading",2),r([M()],f.prototype,"balancesError",2),r([M()],f.prototype,"walletBalances",2),f=r([Nt("icpay-pay-button")],f);import{LitElement as $t,html as xe,css as It}from"lit";import{customElement as Bt,property as Rt,state as C}from"lit/decorators.js";var Ve=typeof window<"u",Ne=null;function _t(i,s,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${s}`,e):console.log(`[ICPay Widget] ${s}`))}var E=class extends $t{constructor(){super(...arguments);this.amountUsd=0;this.hasUserAmount=!1;this.selectedSymbol=null;this.processing=!1;this.succeeded=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.walletModalStep="connect";this.showOnrampModal=!1;this.onrampUrl=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.sdk=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="pay",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.amountUsd||0),a=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:a}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(n=>n?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),this.showBalanceModal=!1,this.showWalletModal=!1,B(this.lastWalletId)){let n=(this.walletBalances||[]).find(l=>l?.tokenShortcode===e),o=n?.chainId;V(o,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:n?.chainName,rpcUrlPublic:n?.rpcUrlPublic,nativeSymbol:n?.ledgerSymbol,decimals:n?.decimals}).then(async()=>{try{let l=u(this.config),d=Number(this.amountUsd||0);if(n?.x402Accepts)try{await l.client.createPaymentX402Usd({usdAmount:d,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:n?.ledgerId,icpay_context:"amount-input:x402"},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"}),this.showBalanceModal=!1;return}catch{}await l.client.createPaymentUsd({usdAmount:d,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:n?.ledgerId},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"})}catch{}this.showBalanceModal=!1});return}let a=this.pendingAction;if(this.pendingAction=null,a==="pay")try{let n=(this.walletBalances||[]).find(g=>g?.tokenShortcode===e),o=u(this.config),l=Number(this.amountUsd||0),d=String(n?.ledgerName||n?.chainName||"").toLowerCase(),p=d.includes("sol"),h=d.includes("ic"),c=this.config?.recipientAddresses||{},y=p&&c.sol||c.ic;if(n?.x402Accepts)try{let g={...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:p?"sol":h?"ic":this.config?.icpay_network,icpay_ledger_id:n?.ledgerId,icpay_context:"amount-input:x402"}};await o.client.createPaymentX402Usd({usdAmount:l,tokenShortcode:n?.tokenShortcode,metadata:g,recipientAddress:y||""});return}catch{return}await o.client.createPaymentUsd({usdAmount:l,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"ic",icpay_ledger_id:n?.ledgerId}},recipientAddress:y||"0x0000000000000000000000000000000000000000"})}catch{}}}connectedCallback(){if(super.connectedCallback(),!!Ve){_t(this.config?.debug||!1,"Amount input connected",{config:this.config}),this.amountUsd=Number(this.config?.defaultAmountUsd??0),this.hasUserAmount=!1;try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.requestUpdate()}))}catch{}}}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.pendingAction&&this.config?.actorProvider)){let t=this.pendingAction;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}this.walletModalStep!=="balances"&&(this.pendingAction=null,setTimeout(()=>{t==="pay"&&this.pay()},0))}}onInputChange(e){let t=Number(this.config?.stepUsd??.5),a=Math.max(0,Number(e.target.value||0)),n=Math.round(a/t)*t;this.amountUsd=Number(n.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{Ne||(Ne=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let e=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab),t={...this.config?.plugNPlay||{}},a=this.config?.recipientAddresses;if(a&&(a.ic||a.evm||a.sol)){let l=[];a.ic&&l.push("ic"),a.evm&&l.push("evm"),a.sol&&l.push("sol"),l.length&&(t.chainTypes=l)}else this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);let n=e?$(t):t;try{if(typeof window<"u"){let{resolveDerivationOrigin:l}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||l()}}catch{}if(this.pnp=new Ne(n),!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}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(a=>{if(!!!(a&&(a.connected===!0||a.principal||a.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{}let o=U(this.pnp,a),l=this.pnp?.getEvmProvider?.(),d=this.pnp?.getSolanaProvider?.();this.config={...this.config,connectedWallet:o,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...l?{evmProvider:l}:{},...d?{solanaProvider:d}:{}},this.sdk=null,this.walletModalStep="balances",this.showBalanceModal=!1,this.showWalletModal=!0,this.fetchAndShowBalances()}).catch(a=>{this.errorMessage=a instanceof Error?a.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(){try{this.balancesLoading=!0,this.balancesError=null,this.walletModalStep="balances",this.showBalanceModal=!1;let e=u(this.config),{balances:t}=await X({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.amountUsd??0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!1}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,a=t?.event_id||t?.eventId||t?.id;if(!(!a||typeof a!="string")&&a==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let n=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(n||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=u(this.config),t=Number(this.amountUsd),a=await e.startOnrampUsd(t,void 0,{context:"amount-input:onramp",onrampPayment:!0,onrampProvider:this?.selectedOnrampProvider||"coinbase"}),n=a?.metadata?.onramp?.url||a?.onramp?.url||a?.metadata?.icpay_onramp?.url||a?.paymentIntent?.metadata?.icpay?.onrampUrl||a?.metadata?.icpay?.onrampUrl||null,o=a?.metadata?.icpay_payment_intent_id||a?.metadata?.paymentIntentId||a?.paymentIntentId||null,l=a?.metadata?.icpay_onramp?.errorMessage||a?.metadata?.onramp?.errorMessage||null;if(this.onrampPaymentIntentId=o,n){this.onrampUrl=n,this.onrampErrorMessage=null;try{window.open(n,"icpay_onramp","noopener,noreferrer");try{window.dispatchEvent(new CustomEvent("icpay-onramp-opened",{detail:{url:n}}))}catch{}}catch{}this.startOnrampPolling()}else this.onrampUrl=null,this.onrampErrorMessage=l||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}catch(e){this.onrampUrl=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let a=u(this.config),n=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>n()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=a.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}async pay(){if(!(!Ve||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||"ICP"}}))}catch{}this.processing=!0;try{if(!await this.ensureWallet())return;this.showWalletModal=!0,await this.fetchAndShowBalances();return}catch(e){_(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),z(t)&&(this.errorMessage=D(t),this.errorSeverity=K(t),this.errorAction=F(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}render(){if(!this.config)return xe`<div class="icpay-card icpay-section">Loading...</div>`;let e=this.config?.placeholder||"Enter amount in USD",a=(this.config?.buttonLabel||"Pay ${amount} with crypto").replace("{amount}",this.amountUsd?`${Number(this.amountUsd).toFixed(2)}`:"$0.00").replace("{symbol}",this.selectedSymbol||"ICP"),n=this.selectedSymbol||"ICP",l=this.config?.progressBar?.enabled!==!1;return xe`
2006
+ <div class="icpay-card icpay-section icpay-widget-base">
2007
+ ${l?xe`
2008
+ <icpay-progress-bar
2009
+ .debug=${!!this.config?.debug}
2010
+ .theme=${this.config?.theme}
2011
+ .amount=${Number(this.amountUsd||0)}
2012
+ .ledgerSymbol=${this.selectedSymbol||"ICP"}
2013
+ ></icpay-progress-bar>
2014
+ `:null}
2015
+
2016
+ <div class="row">
2017
+ <div class="top-row">
2018
+ <div class="amount-field">
2019
+ <span class="currency-prefix">$</span>
2020
+ <input type="number" min="0" step="${Number(this.config?.stepUsd??.5)}" .value=${String(this.amountUsd||"")} placeholder="${e}" @input=${d=>this.onInputChange(d)} />
2021
+ </div>
2022
+ ${null}
2023
+ </div>
2024
+ <button class="pay-button ${this.processing?"processing":""}"
2025
+ ?disabled=${this.processing||this.config?.disablePaymentButton===!0||this.succeeded&&this.config?.disableAfterSuccess===!0}
2026
+ @click=${()=>this.pay()}>
2027
+ ${this.succeeded&&this.config?.disableAfterSuccess?"Paid":this.processing?"Processing\u2026":a}
2028
+ </button>
2029
+ </div>
2030
+ <div class="hint">Min: $${Number(this.config?.minUsd??.5).toFixed(2)}${this.config?.maxUsd?`, Max: $${Number(this.config.maxUsd).toFixed(2)}`:""}</div>
2031
+
2032
+ ${this.errorMessage?xe`
2033
+ <div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
2034
+ ${this.errorMessage}
2035
+ ${this.errorAction?xe`<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>`:""}
2036
+ </div>
2037
+ `:""}
2038
+ ${(()=>{let d=this.pnp?.getEnabledWallets?.()||[],p=H(d);return G({visible:!!(this.showWalletModal&&this.pnp),wallets:p,isConnecting:!1,step:this.walletModalStep,balances:this.walletModalStep==="balances"?this.walletBalances:[],balancesLoading:this.walletModalStep==="balances"?this.balancesLoading:!1,balancesError:this.walletModalStep==="balances"?this.balancesError:null,onSelectBalance:h=>this.onSelectBalanceSymbol(h),onBack:()=>{this.walletModalStep="connect"},onSwitchAccount:()=>this.onSwitchAccount(null),onSelect:h=>this.connectWithWallet(h),onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-cancelled",{detail:{reason:"user_cancelled"}}))}catch{}},onDismiss:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0,creditCardTooltip:(()=>{let c=Number(this.amountUsd||0);return c>0&&c<5&&this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?`Note: Minimum card amount is $5. You will pay about $${(5-c).toFixed(2)} more.`:null})(),oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1,this.pay()}})})()}
2039
+
2040
+ ${Q({visible:this.showBalanceModal,isLoading:this.balancesLoading,error:this.balancesError,balances:this.walletBalances,onSelect:d=>this.onSelectBalanceSymbol(d),onClose:()=>{this.showBalanceModal=!1}})}
2041
+
2042
+ ${q({visible:this.showOnrampModal,url:this.onrampUrl||void 0,errorMessage:this.onrampErrorMessage||void 0,width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0},title:"Pay with credit card"})}
2043
+ <div class="icpay-powered-by">
2044
+ <a href="https://icpay.org" target="_blank" rel="noopener noreferrer">Powered by icpay</a>
2045
+ </div>
2046
+ </div>
2047
+ `}};E.styles=[j,It`
2048
+ .row { display: grid; grid-template-columns: 1fr; gap: 12px; align-items: stretch; }
2049
+ .top-row { display: grid; grid-template-columns: 1fr; gap: 10px; align-items: center; }
2050
+ .top-row.with-selector { grid-template-columns: 1fr 2fr; }
2051
+ icpay-token-selector { width: 100%; }
2052
+ .amount-field { position: relative; width: 100%; }
2053
+ .amount-field .currency-prefix { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--icpay-muted, #a3a3a3); font-weight: 600; pointer-events: none; z-index: 2; }
2054
+ .amount-field input[type="number"] { padding-left: 32px; position: relative; z-index: 1; }
2055
+ input[type="number"] { background: var(--icpay-surface-alt); border: 1px solid var(--icpay-border); color: var(--icpay-text); border-radius: 8px; padding: 10px; font-weight: 600; width: 100%; box-sizing: border-box; height: 54px; }
2056
+ select { background: var(--icpay-surface-alt); border: 1px solid var(--icpay-border); color: var(--icpay-text); border-radius: 8px; padding: 10px; font-weight: 600; }
2057
+ .pay-button { width: 100%; }
2058
+ .error-message { border: 1px solid; font-weight: 500; }
2059
+ .error-message.info { background: var(--icpay-processing-bg); border-color: var(--icpay-processing-border); color: var(--icpay-processing-text); }
2060
+ .error-message.warning { background: var(--icpay-warning-bg); border-color: var(--icpay-warning-border); color: var(--icpay-warning-text); }
2061
+ .error-message.error { background: var(--icpay-error-bg); border-color: var(--icpay-error-border); color: var(--icpay-error-text); }
2062
+ .hint { font-size: 12px; color: var(--icpay-muted); margin-top: 6px; }
2063
+
2064
+ @media (max-width: 520px) {
2065
+ .top-row { grid-template-columns: 1fr; }
2066
+ }
2067
+ `],r([Rt({type:Object})],E.prototype,"config",2),r([C()],E.prototype,"amountUsd",2),r([C()],E.prototype,"hasUserAmount",2),r([C()],E.prototype,"selectedSymbol",2),r([C()],E.prototype,"processing",2),r([C()],E.prototype,"succeeded",2),r([C()],E.prototype,"errorMessage",2),r([C()],E.prototype,"errorSeverity",2),r([C()],E.prototype,"errorAction",2),r([C()],E.prototype,"walletConnected",2),r([C()],E.prototype,"pendingAction",2),r([C()],E.prototype,"showWalletModal",2),r([C()],E.prototype,"walletModalStep",2),r([C()],E.prototype,"showOnrampModal",2),r([C()],E.prototype,"onrampUrl",2),r([C()],E.prototype,"onrampPaymentIntentId",2),r([C()],E.prototype,"onrampErrorMessage",2),r([C()],E.prototype,"oisyReadyToPay",2),r([C()],E.prototype,"lastWalletId",2),r([C()],E.prototype,"showBalanceModal",2),r([C()],E.prototype,"balancesLoading",2),r([C()],E.prototype,"balancesError",2),r([C()],E.prototype,"walletBalances",2),E=r([Bt("icpay-amount-input")],E);export{j as a,Te as b,u as c,q as d,k as e,w as f,m as g,S as h,x as i,f as j,E as k};
2068
+ //# sourceMappingURL=chunk-RA6KGDIL.js.map