import{$ as u}from"./datatables-Bo82YvhT.js";import{d as _}from"./datatables-I6jthWPb.js";import{T as v}from"./bootstrap.esm-Bb7dPm-H.js";/* empty css                                  */const b=document.createElement("style");b.textContent=`
.dt-rowReorder-moving {
    background-color: #f8f9fa !important;
    outline: 2px dashed #0d6efd !important;
    outline-offset: -2px !important;
    box-shadow: 0 5px 15px rgba(0,0,0,.15) !important;
    cursor: grabbing !important;
    opacity: 0.85 !important;
    z-index: 1000 !important;
    transform: scale(1.02) !important;
    transition: transform 0.1s ease-in-out !important;
}
.dt-rowReorder-moving td {
    background-color: #f8f9fa !important;
}
.dt-rowReorder-moving .drag-handle {
    color: #0d6efd !important;
}
.drag-handle:hover {
    color: #0d6efd !important;
    background-color: rgba(13, 110, 253, 0.05);
    border-radius: 4px;
}
.dt-rowReorder-dropZone {
    background-color: rgba(13, 110, 253, 0.1) !important;
    border-top: 2px dashed #0d6efd !important;
    border-bottom: 2px dashed #0d6efd !important;
}
tr:hover .drag-handle {
    color: #6c757d !important;
}
`;document.head.appendChild(b);document.addEventListener("DOMContentLoaded",function(){const e=window.translations||{},f=window.permissions||{clientCustomFields:{view:!1,update:!1,delete:!1}},g=window.routes||{clientCustomFields:{edit:"/admin/client-custom-fields/:id/edit",delete:"/admin/client-custom-fields/:id"}},w=document.getElementById("clientCustomFields"),h=w.dataset.recordsUrl||"/admin/client-custom-fields/records",y=w.dataset.reorderUrl||"/admin/client-custom-fields/reorder",m=u("#clientCustomFields").DataTable({..._.getDefaultConfig(),serverSide:!0,dom:'<"d-flex justify-content-between align-items-center mb-3"<"d-flex align-items-center"l><"d-flex align-items-center"f>>t<"d-flex justify-content-between align-items-center mt-3"<"d-flex align-items-center"i><"d-flex align-items-center"p>>',rowReorder:{selector:"td:first-child",update:!1,dataSrc:"field_order",snapX:!0,animation:300,multiHandle:!1,cloneOpacity:.9},ajax:{url:h,type:"GET",headers:{Authorization:"Bearer "+document.querySelector('meta[name="api-token"]').getAttribute("content")}},order:[[3,"asc"]],columns:[{data:"field_order",name:"handle",orderable:!1,searchable:!1,render:function(){return'<div class="drag-handle d-flex align-items-center justify-content-center" style="cursor: grab; width: 30px; height: 30px; margin: 0 auto; color: #aaa; transition: color 0.2s ease-in-out;"><i class="fas fa-grip-vertical"></i></div>'}},{data:"name",name:"name"},{data:"type",name:"type",render:function(s){return e["types_"+s]||s}},{data:"field_order",name:"field_order"},{data:"is_required",name:"is_required",render:function(s){var o,r;return s?`<span class="badge bg-success">${((o=e.common)==null?void 0:o.yes)||"Yes"}</span>`:`<span class="badge bg-danger">${((r=e.common)==null?void 0:r.no)||"No"}</span>`}},{data:"show_in_order",name:"show_in_order",render:function(s){var o,r;return s?`<span class="badge bg-success">${((o=e.common)==null?void 0:o.yes)||"Yes"}</span>`:`<span class="badge bg-danger">${((r=e.common)==null?void 0:r.no)||"No"}</span>`}},{data:"show_in_clientarea",name:"show_in_clientarea",render:function(s){var o,r;return s?`<span class="badge bg-success">${((o=e.common)==null?void 0:o.yes)||"Yes"}</span>`:`<span class="badge bg-danger">${((r=e.common)==null?void 0:r.no)||"No"}</span>`}},{data:"show_in_invoice",name:"show_in_invoice",render:function(s){var o,r;return s?`<span class="badge bg-success">${((o=e.common)==null?void 0:o.yes)||"Yes"}</span>`:`<span class="badge bg-danger">${((r=e.common)==null?void 0:r.no)||"No"}</span>`}},{data:"id",name:"actions",orderable:!1,searchable:!1,render:function(s,o,r){var l,t,n,a,i,c;const d=[];if((l=f.clientCustomFields)!=null&&l.view){const p=g.clientCustomFields.show.replace(":id",s);d.push(`
                            <a href="${p}"
                               class="btn btn-sm btn-outline-info d-inline-flex align-items-center justify-content-center"
                               style="width: 32px; height: 32px;"
                               data-bs-toggle="tooltip"
                               title="${((t=e.buttons)==null?void 0:t.view)||"View"}">
                                <i class="fas fa-eye"></i>
                            </a>`)}if((n=f.clientCustomFields)!=null&&n.update){const p=g.clientCustomFields.edit.replace(":id",s);d.push(`
                            <a href="${p}"
                               class="btn btn-sm btn-outline-primary d-inline-flex align-items-center justify-content-center ms-1"
                               style="width: 32px; height: 32px;"
                               data-bs-toggle="tooltip"
                               title="${((a=e.buttons)==null?void 0:a.edit)||"Edit"}">
                                <i class="fas fa-edit"></i>
                            </a>`)}return(i=f.clientCustomFields)!=null&&i.delete&&d.push(`
                            <button type="button"
                                    class="btn btn-sm btn-outline-danger d-inline-flex align-items-center justify-content-center ms-1 delete-custom-field"
                                    style="width: 32px; height: 32px;"
                                    data-id="${s}"
                                    data-bs-toggle="tooltip"
                                    title="${((c=e.buttons)==null?void 0:c.delete)||"Delete"}">
                                <i class="fas fa-trash"></i>
                            </button>`),d.length===0?'<span class="text-muted">-</span>':`<div class="d-inline-flex">${d.join("")}</div>`}}],drawCallback:function(){x()}});m.on("row-reorder",function(s,o,r){if(o.length===0)return;const d=u('<div class="processing-overlay"></div>').css({position:"absolute",top:0,left:0,width:"100%",height:"100%",backgroundColor:"rgba(255, 255, 255, 0.5)",zIndex:1e3,display:"flex",justifyContent:"center",alignItems:"center"}).append('<div class="spinner-border text-primary" role="status"><span class="visually-hidden">Loading...</span></div>');u(w).closest(".dataTables_wrapper").css("position","relative").append(d);const l=o.map(function(t){return{id:m.row(t.node).data().id,old_order:t.oldData,new_order:t.newData}});u.ajax({url:y,type:"PATCH",headers:{Authorization:"Bearer "+document.querySelector('meta[name="api-token"]').getAttribute("content"),"Content-Type":"application/json"},data:JSON.stringify({updates:l}),dataType:"json",success:function(t){var n,a,i,c;d.remove(),t.success?(window.toastr?window.toastr.success(t.message||((n=e.messages)==null?void 0:n.reorder_success)||"Order updated successfully."):window.bootstrap&&window.bootstrap.Toast?new bootstrap.Toast(document.getElementById("successToast")).show():window.showSuccess(t.message||((a=e.messages)==null?void 0:a.reorder_success)||"Order updated successfully."),m.ajax.reload()):window.toastr?window.toastr.error(t.message||((i=e.messages)==null?void 0:i.reorder_error)||"An error occurred while updating the order."):window.bootstrap&&window.bootstrap.Toast?new bootstrap.Toast(document.getElementById("errorToast")).show():window.showError(t.message||((c=e.messages)==null?void 0:c.reorder_error)||"An error occurred while updating the order.")},error:function(t){var n,a,i;if(d.remove(),console.error("Reorder error:",t),t.responseJSON&&console.error("Server response:",t.responseJSON),typeof toastr<"u"){const c=((n=t.responseJSON)==null?void 0:n.message)||((a=e.messages)==null?void 0:a.reorder_error)||"An error occurred while updating the order.";toastr.error(c)}else window.showError(((i=e.messages)==null?void 0:i.reorder_error)||"An error occurred while updating the order.");m.order([3,"asc"]).ajax.reload(null,!1)}})});function x(){[...document.querySelectorAll('[data-bs-toggle="tooltip"]')].map(o=>new v(o,{boundary:document.body}))}u(document).on("click",".delete-custom-field",async function(s){var l;s.preventDefault();const o=u(this).data("id"),r=g.clientCustomFields.delete.replace(":id",o);await window.showConfirm(((l=e.messages)==null?void 0:l.delete_confirm)||"Are you sure you want to delete this record?",{title:"Onay",confirmText:"Onayla",confirmClass:"btn-danger"})&&u.ajax({url:r,type:"DELETE",headers:{Authorization:"Bearer "+document.querySelector('meta[name="api-token"]').getAttribute("content")},success:function(t){var i;const n=((i=e.messages)==null?void 0:i.delete_success)||"Record deleted successfully.",a=document.getElementById("successToast");window.toastr?window.toastr.success(n):window.bootstrap&&window.bootstrap.Toast&&a?new bootstrap.Toast(a).show():window.showSuccess(n),m.ajax.reload()},error:function(t){var i;const n=((i=e.messages)==null?void 0:i.delete_error)||"An error occurred.",a=document.getElementById("errorToast");window.toastr?window.toastr.error(n):window.bootstrap&&window.bootstrap.Toast&&a?new bootstrap.Toast(a).show():window.showError(n),console.error(t)}})})});
