import{d as m}from"./datatables-I6jthWPb.js";import{r as f,g as p}from"./api-DZ3cXm1m.js";import{c as w,g as h}from"./datatable-filters-CecjJm_7.js";import"./bootstrap.esm-Bb7dPm-H.js";import"./datatables-Bo82YvhT.js";/* empty css                                  */import"./vendor-zLyX4B24.js";import"./tr-CHCA6xOE.js";const a=window.translations||{},b=window.routes||{},i=window.permissions||{},o=w(null,{search:!0,searchPlaceholder:a.search_placeholder||"Search..."}),c=$("#clientDiscountsTable").DataTable({...m.getDefaultConfig(),serverSide:!0,dom:h(),ajax:{url:$("#clientDiscountsTable").data("records-url"),type:"GET",data:function(e){const n=o.getValues();e.search={value:n.search||""}},beforeSend:function(e){e.setRequestHeader("Authorization",`Bearer ${p()}`)},error:async function(e){e.status===401&&await f()&&c.ajax.reload()}},columns:[{data:"id",name:"id",width:"60px"},{data:"name",name:"name"},{data:"client",name:"client"},{data:"type",name:"type"},{data:"applies_to",name:"applies_to"},{data:"is_active",name:"is_active",render:function(e,n,t){return e?`<span class="badge bg-success">${a.status_active||"Active"}</span>`:`<span class="badge bg-secondary">${a.status_inactive||"Inactive"}</span>`}},{data:"expires_at",name:"expires_at"},{data:"created_at",name:"created_at"},{data:null,orderable:!1,searchable:!1,width:"150px",render:function(e,n,t){var r,l,d,u;let s="";return(r=i.client_discounts)!=null&&r.view&&(s+=`<a href="${t.actions.show}" class="btn btn-outline-info" title="${a.buttons_show||"Show"}"><i class="fas fa-eye"></i></a>`),(l=i.client_discounts)!=null&&l.update&&(s+=`<a href="${t.actions.edit}" class="btn btn-outline-primary" title="${a.buttons_edit||"Edit"}"><i class="fas fa-edit"></i></a>`),(d=i.client_discounts)!=null&&d.delete&&(s+=`<button type="button" class="btn btn-outline-danger delete-item" data-url="${(u=b.delete)==null?void 0:u.replace(":id",t.id)}" title="${a.buttons_delete||"Delete"}"><i class="fas fa-trash"></i></button>`),`<div class="btn-group btn-group-sm" role="group">${s}</div>`}}],order:[[0,"desc"]],initComplete:function(){o.init()}});o.setDataTable(c);$(document).on("click",".delete-item",async function(){const e=$(this).data("url");if(await window.showConfirm(a.delete_confirm||"Are you sure you want to delete this item?",{confirmClass:"btn-danger"}))try{const t=await fetch(e,{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:`Bearer ${p()}`}});if(t.status===401&&await f())return $(this).trigger("click");const s=await t.json();t.ok?(c.ajax.reload(),window.showSuccess(s.message||a.delete_success||"Discount deleted successfully")):window.showError(s.message||a.delete_error||"An error occurred")}catch(t){console.error("Error:",t),window.showError(a.delete_error||"An error occurred while deleting")}});
