var d=Object.defineProperty;var c=(n,e,t)=>e in n?d(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var o=(n,e,t)=>(c(n,typeof e!="symbol"?e+"":e,t),t);import{i as r,w as u}from"./wait-8f4ae121.js";/**
 * Invoice Ninja (https://invoiceninja.com)
 *
 * @link https://github.com/invoiceninja/invoiceninja source repository
 *
 * @copyright Copyright (c) 2026. Invoice Ninja LLC (https://invoiceninja.com)
 *
 * @license https://opensource.org/licenses/AAL
 */class m{constructor(e){o(this,"handleAuthorization",()=>{document.getElementById("lawpay_errors").innerHTML="";const e=document.getElementById("account-holder-name");if(!e||!e.value.trim()){this.showError("Account holder name is required.");return}let t=document.getElementById("pay-now");return t&&(t.disabled=!0,t.querySelector("svg").classList.remove("hidden"),t.querySelector("span").classList.add("hidden")),window.AffiniPay.hostedFields.getPaymentToken({account_holder_name:e.value,account_holder_type:"individual",account_type:"checking"}).then(this.successResponseHandler).catch(this.failedResponseHandler),!1});o(this,"successResponseHandler",e=>{document.getElementById("payment_token").value=e.id,document.getElementById("last_4").value=e.last_four||"";let t=document.getElementById("account-holder-name");return t&&(document.getElementById("account_holder_name").value=t.value),document.getElementById("server_response").submit(),!1});o(this,"failedResponseHandler",e=>{this.showError(e.message||"Tokenization failed.");let t=document.getElementById("pay-now");return t&&(t.disabled=!1,t.querySelector("svg").classList.add("hidden"),t.querySelector("span").classList.remove("hidden")),!1});o(this,"handle",()=>{Array.from(document.getElementsByClassName("toggle-payment-with-token")).forEach(a=>a.addEventListener("click",i=>{var l;(l=document.getElementById("lawpay-ach-container"))==null||l.classList.add("hidden"),document.querySelector("input[name=token]").value=i.target.dataset.token}));let e=document.getElementById("toggle-payment-with-new-bank-account");e&&e.addEventListener("click",()=>{var a;(a=document.getElementById("lawpay-ach-container"))==null||a.classList.remove("hidden"),document.querySelector("input[name=token]").value=""});let t=document.getElementById("pay-now");return t&&t.addEventListener("click",a=>{let i=document.querySelector("input[name=token]");if(i&&i.value)return this.completePaymentUsingToken();this.handleAuthorization()}),this});this.publicKey=e,this.hostedFieldsInstance=null,this.initializeHostedFields()}initializeHostedFields(){this.hostedFieldsInstance=window.AffiniPay.hostedFields.initializeFields({publicKey:this.publicKey,fields:[{selector:"#lawpay_routing_number",input:{type:"routing_number",css:{"font-size":"14px","font-family":"inherit"}}},{selector:"#lawpay_account_number",input:{type:"bank_account_number",css:{"font-size":"14px","font-family":"inherit"}}}]},function(e){})}showError(e){document.getElementById("lawpay_errors").innerHTML='<div class="alert alert-failure mb-4"><ul><li>'+e+"</li></ul></div>"}completePaymentUsingToken(){let e=document.getElementById("pay-now");return e&&(e.disabled=!0,e.querySelector("svg").classList.remove("hidden"),e.querySelector("span").classList.add("hidden")),document.getElementById("server_response").submit(),!1}}function s(){const n=document.querySelector('meta[name="lawpay-public-key"]').content;new m(n).handle()}r()?s():u("#lawpay-ach-payment").then(()=>s());
