import{i as p,w as g}from"./wait-8f4ae121.js";import{C as h}from"./index.module-07726c42.js";/**
 * Invoice Ninja (https://invoiceninja.com)
 * Checkout.com Flow SDK — payment form (replaces Frames when processingChannelId is set).
 *
 * @copyright Copyright (c) 2026. Invoice Ninja LLC (https://invoiceninja.com)
 * @license https://www.elastic.co/licensing/elastic-license
 */function l(n){const t=document.querySelector(`meta[name="${n}"]`);return t&&t.getAttribute("content")||""}async function w(){const n=l("payment-session-id"),t=l("payment-session-token"),s=l("public-key"),d=l("environment")||"sandbox";if(!n||!t||!s){const e=document.getElementById("flow-error-message");e&&(e.textContent="Payment session is missing. Please refresh the page.",e.classList.remove("hidden"));return}const i={id:n,payment_session_token:t};try{(await h({paymentSession:i,publicKey:s,environment:d,onPaymentCompleted:(c,r)=>{const a=document.getElementById("server-response");if(!a)return;const m=a.querySelector('input[name="gateway_response"]'),u=a.querySelector('input[name="store_card"]');if(m&&(m.value=JSON.stringify({id:r.id})),u){const f=document.querySelector("input[name=token-billing-checkbox]:checked");u.value=f?f.value:"false"}a.submit()},onError:c=>{var a;const r=document.getElementById("flow-error-message");r&&(r.textContent=((a=c.detail)==null?void 0:a.message)||"Payment failed. Please try again.",r.classList.remove("hidden"))}})).create("flow").mount("#flow-container")}catch(e){const o=document.getElementById("flow-error-message");o&&(o.textContent=(e==null?void 0:e.message)||"Unable to load payment form. Please refresh the page.",o.classList.remove("hidden"))}}function k(){w()}function v(){const n=document.getElementById("flow-container"),t=document.getElementById("pay-now-with-token--container"),s=document.getElementById("save-card--container");Array.from(document.getElementsByClassName("toggle-payment-with-token")||[]).forEach(e=>{e.addEventListener("click",()=>{n&&n.classList.add("hidden"),t&&t.classList.remove("hidden"),s&&(s.style.display="none");const o=document.querySelector("input[name=token]");o&&(o.value=e.dataset.token||"")})});const d=document.getElementById("toggle-payment-with-credit-card");d&&d.addEventListener("click",()=>{n&&n.classList.remove("hidden"),t&&t.classList.add("hidden"),s&&(s.style.display="grid");const e=document.querySelector("input[name=token]");e&&(e.value="")});const i=document.getElementById("pay-now-with-token");i&&i.addEventListener("click",e=>{e.preventDefault(),i.disabled=!0;const o=i.querySelector("svg"),c=i.querySelector("span");o&&o.classList.remove("hidden"),c&&c.classList.add("hidden"),document.getElementById("server-response").submit()})}function y(){if(document.getElementById("flow-container")){v(),k();const t=document.querySelectorAll("input.toggle-payment-with-token");t.length>0&&t[0].click()}}p()?y():g("#checkout-credit-card-payment").then(()=>y());
