import"./bootstrap.esm-Bb7dPm-H.js";import{d as h}from"./datatables-CdFC5o1t.js";import{i as v}from"./tooltip-manager-D9RaGGY4.js";import{g as u}from"./api-DZ3cXm1m.js";import"jquery";import"./datatables-bbQliV7G.js";/* empty css                                  */let m;const y=document.querySelector("#invoiceBillings").getAttribute("data-records-url");function x(){m=$("#invoiceBillings").DataTable({...h.getDefaultConfig(),serverSide:!0,searching:!1,dom:'<"d-flex align-items-center mb-3"<"d-flex align-items-center"l>>t<"d-flex justify-content-between align-items-center mt-3"<"d-flex align-items-center"i><"d-flex align-items-center"p>>',ajax:{url:y,type:"GET",headers:{Authorization:`Bearer ${u()}`}},columns:[{data:"name",name:"name"},{data:"display_name",name:"display_name"},{data:"type",name:"type"},{data:"is_active",name:"is_active",render:function(t){var n,s,a,o,e,i;return t===!0||t===1?`<span class="badge bg-success">${((a=(s=(n=window.translations)==null?void 0:n.languages)==null?void 0:s.status)==null?void 0:a.active)||"Active"}</span>`:`<span class="badge bg-danger">${((i=(e=(o=window.translations)==null?void 0:o.languages)==null?void 0:e.status)==null?void 0:i.inactive)||"Inactive"}`}},{data:"is_automatic",name:"is_automatic",render:function(t){var n,s,a,o,e,i;return t===!0||t===1?`<span class="badge bg-success">${((a=(s=(n=window.translations)==null?void 0:n.languages)==null?void 0:s.status)==null?void 0:a.active)||"Active"}</span>`:`<span class="badge bg-secondary">${((i=(e=(o=window.translations)==null?void 0:o.languages)==null?void 0:e.status)==null?void 0:i.inactive)||"Inactive"}`}},{data:"status",name:"status"},{data:"created_at",name:"created_at"},{data:"id",name:"actions",orderable:!1,searchable:!1,render:function(t){var s,a,o,e,i,l,d,c,f,g,b,w;const n=[];if((a=(s=window.permissions)==null?void 0:s.invoiceBillings)!=null&&a.update){const p=window.routes.invoiceBillings.edit.replace(":id",t);n.push(`
                            <a href="${p}"
                               class="btn btn-sm btn-outline-primary d-inline-flex align-items-center justify-content-center"
                               style="width: 32px; height: 32px;"
                               data-bs-toggle="tooltip"
                               title="${((e=(o=window.translations)==null?void 0:o.buttons)==null?void 0:e.edit)||"Edit"}">
                                <i class="fas fa-edit"></i>
                            </a>`)}return(l=(i=window.permissions)==null?void 0:i.invoiceBillings)!=null&&l.update&&n.push(`
                            <button type="button"
                                    class="btn btn-sm btn-outline-info d-inline-flex align-items-center justify-content-center ms-1 test-module"
                                    style="width: 32px; height: 32px;"
                                    data-id="${t}"
                                    data-bs-toggle="tooltip"
                                    title="${((c=(d=window.translations)==null?void 0:d.buttons)==null?void 0:c.test)||"Test"}">
                                <i class="fas fa-vial"></i>
                            </button>`),(g=(f=window.permissions)==null?void 0:f.invoiceBillings)!=null&&g.delete&&n.push(`
                            <button type="button"
                                    class="btn btn-sm btn-outline-danger d-inline-flex align-items-center justify-content-center ms-1 delete-module"
                                    style="width: 32px; height: 32px;"
                                    data-id="${t}"
                                    data-bs-toggle="tooltip"
                                    title="${((w=(b=window.translations)==null?void 0:b.buttons)==null?void 0:w.delete)||"Delete"}">
                                <i class="fas fa-trash"></i>
                            </button>`),n.length===0?'<span class="text-muted">-</span>':`<div class="d-inline-flex">${n.join("")}</div>`}}],drawCallback:function(){v()}})}async function T(t){var a,o;if(!await window.showConfirm(((o=(a=window.translations)==null?void 0:a.confirmations)==null?void 0:o.test)||"Are you sure you want to test this module?",{confirmClass:"btn-primary",icon:"question"}))return;const s=window.routes.invoiceBillings.test.replace(":id",t);fetch(s,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${u()}`}}).then(e=>e.json()).then(e=>{var i,l,d,c;e.success?(r("success",((l=(i=window.translations)==null?void 0:i.messages)==null?void 0:l.test_successful)||"Module test successful"),m.ajax.reload()):r("error",e.message||((c=(d=window.translations)==null?void 0:d.messages)==null?void 0:c.test_failed)||"Module test failed")}).catch(e=>{var i,l;console.error("Test error:",e),r("error",((l=(i=window.translations)==null?void 0:i.messages)==null?void 0:l.test_failed)||"Module test failed")})}async function A(t){var a,o;if(!await window.showConfirm(((o=(a=window.translations)==null?void 0:a.confirmations)==null?void 0:o.delete)||"Are you sure you want to delete this billing module?",{confirmClass:"btn-danger",icon:"warning"}))return;const s=window.routes.invoiceBillings.delete.replace(":id",t);fetch(s,{method:"DELETE",headers:{Authorization:`Bearer ${u()}`}}).then(e=>e.json()).then(e=>{var i,l;e.success?(r("success",((l=(i=window.translations)==null?void 0:i.messages)==null?void 0:l.deleted)||"Module deleted successfully"),m.row(`[data-id="${t}"]`).remove().draw()):r("error",e.message||"Module could not be deleted")}).catch(e=>{console.error("Delete error:",e),r("error","Module could not be deleted")})}function r(t,n){const a=`
        <div class="alert ${t==="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",a),setTimeout(()=>{const e=document.querySelector(".alert");e&&e.remove()},5e3)}function j(){document.addEventListener("click",function(t){if(t.target.closest(".test-module")){const s=t.target.closest(".test-module").getAttribute("data-id");T(s)}}),document.addEventListener("click",function(t){if(t.target.closest(".delete-module")){const s=t.target.closest(".delete-module").getAttribute("data-id");A(s)}})}document.addEventListener("DOMContentLoaded",function(){x(),j()});
