import{g as l}from"./api-DZ3cXm1m.js";function m(){var o,i;const s=document.getElementById("editInvoiceBillingForm");if(!s)return;const n=new FormData(s);n.set("is_active",document.getElementById("edit_is_active").checked?"1":"0"),n.set("is_automatic",document.getElementById("edit_is_automatic").checked?"1":"0");try{const e=document.getElementById("edit_settings").value.trim();e&&JSON.parse(e);const t=document.getElementById("edit_mapping_fields").value.trim();t&&JSON.parse(t)}catch{window.showError(((i=(o=window.translations)==null?void 0:o.messages)==null?void 0:i.json_error)||"JSON format error. Please check settings and mapping fields.");return}s.submit()}async function u(){var o,i;if(!await window.showConfirm(((i=(o=window.translations)==null?void 0:o.confirmations)==null?void 0:i.test)||"Are you sure you want to test this module?",{confirmClass:"btn-primary",icon:"question"}))return;const n=window.routes.test;fetch(n,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${l()}`}}).then(e=>e.json()).then(e=>{var t,r,c,d;e.success?(a("success",((r=(t=window.translations)==null?void 0:t.messages)==null?void 0:r.test_successful)||"Module test successful"),setTimeout(()=>{window.location.reload()},2e3)):a("error",e.message||((d=(c=window.translations)==null?void 0:c.messages)==null?void 0:d.test_failed)||"Module test failed")}).catch(e=>{var t,r;console.error("Test error:",e),a("error",((r=(t=window.translations)==null?void 0:t.messages)==null?void 0:r.test_failed)||"Module test failed")})}function a(s,n){const i=`
        <div class="alert ${s==="success"?"alert-success":"alert-danger"} alert-dismissible fade show" role="alert">
            ${n}
            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
        </div>
    `;document.querySelector(".container-fluid").insertAdjacentHTML("afterbegin",i),setTimeout(()=>{const t=document.querySelector(".alert");t&&t.remove()},5e3)}function f(){const s=document.getElementById("editInvoiceBillingForm");s&&s.addEventListener("submit",function(o){o.preventDefault(),m()});const n=document.getElementById("testModuleBtn");n&&n.addEventListener("click",u)}document.addEventListener("DOMContentLoaded",function(){f()});
