import"./hoisted.yFz1BYXO.js";const h=window.__PW_API||"https://api.performancewest.net";function m(n){return new URLSearchParams(window.location.search).get(n)??""}const a=m("order_id"),f=m("order_type")||"canada_crtc",l=m("amount"),w=m("expedited"),b=w==="1"?"&expedited=1":"",p=`/order/cancelled?order_id=${a}&order_type=${f}${b}`,u=document.getElementById("btn-back");u&&a&&(u.href=p);const y=document.getElementById("error-retry-link");y&&a&&(y.href=p);const g=document.getElementById("btn-change-method");g&&a&&(g.href=p);function d(n){for(const t of["loading","pick","pay","error"]){const e=document.getElementById(`state-${t}`);e&&e.classList.toggle("hidden",t!==n)}}!a||!l?d("error"):(async()=>{try{const n=document.getElementById("fiat-total");n&&(n.textContent=`$${parseFloat(l).toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})} USD`);const t=await fetch(`${h}/api/v1/checkout/crypto-available`);if(!t.ok)throw new Error("Gateway unavailable");const e=await t.json(),o={BTC:"bitcoin",ETH:"ethereum",LTC:"litecoin",DOGE:"dogecoin",BNB:"bnb",MATIC:"polygon",TRX:"tron"},r=document.getElementById("crypto-list");for(const s of e.cryptos){const i=document.createElement("label");i.className="flex items-center gap-3 p-3 rounded-lg border border-gray-200 cursor-pointer hover:border-pw-400 has-[:checked]:border-pw-500 has-[:checked]:bg-pw-50 transition-colors";const k=s.name.split("-")[0].toLowerCase();i.innerHTML=`
${s.display_name}
${s.name}
`,i.addEventListener("click",()=>{document.getElementById("pick-error")?.classList.add("hidden")}),r.children.length===0&&(i.querySelector("input").checked=!0),r.appendChild(i);const x=document.createElement("button")}const c=document.createElement("button");c.type="button",c.className="mt-4 w-full inline-flex items-center justify-center gap-2 bg-pw-700 hover:bg-pw-800 text-white font-medium px-5 py-3 rounded-lg transition-colors text-sm disabled:opacity-50 disabled:cursor-not-allowed",c.innerHTML='Continue ',c.addEventListener("click",()=>E(c)),r.parentElement.appendChild(c),d("pick")}catch{document.getElementById("error-message").textContent="Could not load available cryptocurrencies. The payment gateway may be temporarily offline.",d("error")}})();async function E(n){const t=document.querySelector('input[name="crypto_choice"]:checked')?.value;if(!t){const e=document.getElementById("pick-error");e&&(e.textContent="Please select a cryptocurrency.",e.classList.remove("hidden"));return}n.disabled=!0,n.textContent="Generating payment address...";try{const e=await fetch(`${h}/api/v1/checkout/crypto-invoice`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({order_id:a,order_type:f,crypto_name:t,amount:l})});if(!e.ok){const r=await e.json().catch(()=>({}));throw new Error(r.error||"Invoice creation failed")}const o=await e.json();document.getElementById("pay-crypto-badge").textContent=o.display_name||t,document.getElementById("pay-amount").textContent=`${o.amount} ${t}`,document.getElementById("pay-fiat").textContent=`$${parseFloat(l).toLocaleString(void 0,{minimumFractionDigits:2})} USD`,document.getElementById("pay-wallet").textContent=o.wallet,document.getElementById("pay-network-warn").textContent=o.display_name||t,document.getElementById("pay-order-id").textContent=a,o.exchange_rate?document.getElementById("pay-rate").textContent=`1 ${t.split("-")[0]} = $${parseFloat(o.exchange_rate).toLocaleString()} USD`:document.getElementById("rate-row")?.classList.add("hidden"),document.getElementById("btn-copy")?.addEventListener("click",()=>{navigator.clipboard.writeText(o.wallet).then(()=>{const r=document.getElementById("btn-copy");r&&(r.title="Copied!",setTimeout(()=>{r.title="Copy address"},2e3))})}),d("pay")}catch(e){const o=document.getElementById("pick-error");o&&(o.textContent=e.message||"Failed to generate payment address.",o.classList.remove("hidden")),n.disabled=!1,n.innerHTML='Continue '}}document.getElementById("btn-change-coin")?.addEventListener("click",()=>{const n=document.querySelectorAll("#crypto-list ~ button");for(const t of n){const e=t;e.disabled=!1,e.innerHTML='Continue '}d("pick")});