import{T as m}from"./bootstrap.esm-Bb7dPm-H.js";import{d as _}from"./datatables-I6jthWPb.js";import{g as d,r as b}from"./api-DZ3cXm1m.js";import{c as f,g}from"./datatable-filters-CecjJm_7.js";import"./datatables-Bo82YvhT.js";/* empty css                                  */import"./vendor-zLyX4B24.js";import"./tr-CHCA6xOE.js";const a=window.translations||{},u=window.routes||{},h=window.permissions||{};var o;const y=((o=window.pageConfig)==null?void 0:o.currencies)||[],w=[{value:"",label:a.clientBalances_filters_all_currencies||"All Currencies"},...y.map(e=>({value:String(e.id),label:`${e.code} - ${e.name}`}))],v=[{value:"",label:a.clientBalances_filters_all_statuses||"All Statuses"},{value:"positive",label:a.clientBalances_filters_positive||"Positive"},{value:"negative",label:a.clientBalances_filters_negative||"Negative"},{value:"zero",label:a.clientBalances_filters_zero||"Zero"}],r=f(null,{filters:[{type:"select2",id:"clientFilter",width:"200px",placeholder:a.clientBalances_filters_all_clients||"All Clients",ajax:{url:u.clientBalances_clientSearch,headers:{Authorization:`Bearer ${d()}`},processResults:e=>({results:(e.results||e.data||[]).map(t=>({id:t.id,text:t.text||`${t.first_name} ${t.last_name} (${t.email})`}))})}},{type:"select",id:"currencyFilter",width:"160px",options:w},{type:"select",id:"statusFilter",width:"140px",options:v}],search:!0,searchPlaceholder:a.search_placeholder||"Search..."}),p=$("#clientBalancesTable").DataTable({..._.getDefaultConfig(),serverSide:!0,dom:g(),ajax:{url:$("#clientBalancesTable").data("records-url"),type:"POST",data:function(e){const t=r.getValues();e.client_id=t.clientFilter,e.currency_id=t.currencyFilter,e.status=t.statusFilter,e.search={value:t.search||""}},beforeSend:function(e){e.setRequestHeader("Authorization",`Bearer ${d()}`)},error:async function(e){e.status===401&&await b()&&p.ajax.reload()}},columns:[{data:"client_name",name:"client_name"},{data:"client_email",name:"client_email"},{data:"currency_code",name:"currency_code"},{data:"formatted_balance",name:"balance",render:function(e,t,s){return`<span class="badge ${s.balance_badge_class||"bg-secondary"} fs-6">${e}</span>`}},{data:"balance_status",name:"balance_status",render:function(e,t,s){const n=`clientBalances_statuses_${e}`,l=a[n]||e;return`<span class="badge ${s.status_badge_class||"bg-secondary"}">${l}</span>`}},{data:"created_at",name:"created_at"},{data:"id",name:"actions",orderable:!1,searchable:!1,render:function(e,t,s){var i,c;const n=((i=u.clientBalances_show)==null?void 0:i.replace(":id",s.client_id||e))||"#";let l="";return(c=h.clientBalances)!=null&&c.view&&(l+=`<a href="${n}" 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="${a.clientBalances_buttons_show||"Show"}"><i class="fas fa-eye"></i></a>`),`<div class="d-inline-flex">${l}</div>`}}],initComplete:function(){r.init()},drawCallback:function(){[...document.querySelectorAll('[data-bs-toggle="tooltip"]')].map(t=>new m(t,{boundary:document.body}))}});r.setDataTable(p);
