var y=Object.defineProperty;var p=(n,e,t)=>e in n?y(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var o=(n,e,t)=>(p(n,typeof e!="symbol"?e+"":e,t),t);import{i as g,w as h}from"./wait-8f4ae121.js";/**
 * Invoice Ninja (https://invoiceninja.com)
 *
 * @link https://github.com/invoiceninja/invoiceninja source repository
 *
 * @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
 *
 * @license https://opensource.org/licenses/AAL
 */class v{constructor(e){o(this,"handleAuthorization",()=>{document.getElementById("forte_errors").innerHTML="";var e=document.getElementById("account-number").value,t=document.getElementById("routing-number").value,r={api_login_id:this.apiLoginId,account_number:e,routing_number:t,account_type:"checking"};return document.getElementById("pay-now")&&(document.getElementById("pay-now").disabled=!0,document.querySelector("#pay-now > svg").classList.remove("hidden"),document.querySelector("#pay-now > span").classList.add("hidden")),forte.createToken(r).success(this.successResponseHandler).error(this.failedResponseHandler),!1});o(this,"successResponseHandler",e=>(document.getElementById("payment_token").value=e.onetime_token,document.getElementById("last_4").value=e.last_4,document.getElementById("account_holder_name").value=document.getElementById("account-holder-name").value,document.getElementById("server_response").submit(),!1));o(this,"failedResponseHandler",e=>{var t='<div class="alert alert-failure mb-4"><ul><li>'+e.response_description+"</li></ul></div>";return document.getElementById("forte_errors").innerHTML=t,document.getElementById("pay-now").disabled=!1,document.querySelector("#pay-now > svg").classList.add("hidden"),document.querySelector("#pay-now > span").classList.remove("hidden"),!1});o(this,"handle",()=>{Array.from(document.getElementsByClassName("toggle-payment-with-token")).forEach(t=>t.addEventListener("click",r=>{document.getElementById("forte-payment-container").classList.add("hidden"),document.querySelector("input[name=token]").value=r.target.dataset.token})),document.getElementById("toggle-payment-with-new-bank-account").addEventListener("click",t=>{document.getElementById("forte-payment-container").classList.remove("hidden"),document.querySelector("input[name=token]").value=""});let e=document.getElementById("pay-now");return e&&e.addEventListener("click",t=>{if(document.querySelector("input[name=token]").value)return this.completePaymentUsingToken();const a=document.getElementById("account-holder-name"),d=document.getElementById("routing-number"),s=document.getElementById("account-number");let l=!0,u=[];if(a.value.trim()?a.classList.remove("border-red-500"):(l=!1,u.push("Account holder name is required"),a.classList.add("border-red-500")),!d.value.trim()||!/^\d{9}$/.test(d.value)?(l=!1,u.push("Valid 9-digit routing number is required"),d.classList.add("border-red-500")):d.classList.remove("border-red-500"),!s.value.trim()||!/^\d{4,17}$/.test(s.value)?(l=!1,u.push("Valid account number is required (4-17 digits)"),s.classList.add("border-red-500")):s.classList.remove("border-red-500"),!l){const c='<div class="alert alert-failure mb-4"><ul>'+u.map(m=>"<li>"+m+"</li>").join("")+"</ul></div>";return document.getElementById("forte_errors").innerHTML=c,!1}this.handleAuthorization()}),this});this.apiLoginId=e}completePaymentUsingToken(){let e=document.getElementById("pay-now");return this.payNowButton=e,this.payNowButton.disabled=!0,this.payNowButton.querySelector("svg").classList.remove("hidden"),this.payNowButton.querySelector("span").classList.add("hidden"),document.getElementById("server_response").submit(),!1}}function i(){const n=document.querySelector('meta[name="forte-api-login-id"]').content;new v(n).handle()}g()?i():h("#force-ach-payment").then(()=>i());
