import{M as f}from"./bootstrap.esm-Bb7dPm-H.js";import{d as g}from"./datatables-I6jthWPb.js";import{s as r}from"./toastr-helper-Wdj0mZjX.js";import{i as y}from"./tooltip-manager-D9RaGGY4.js";import{r as h,g as d}from"./api-DZ3cXm1m.js";import{c as b,g as _}from"./datatable-filters-CecjJm_7.js";import"./datatables-Bo82YvhT.js";/* empty css                                  */import"./vendor-zLyX4B24.js";import"./tr-CHCA6xOE.js";document.addEventListener("DOMContentLoaded",function(){var m;if(!document.getElementById("payouts-table"))return;const u=window.payoutsConfig||{},i=u.routes||{},o=u.translations||{},l=b(null,{filters:[{type:"select",id:"statusFilter",width:"150px",options:[{value:"",label:o.filter_all||"All Statuses"},{value:"pending",label:o.payout_status_pending||"Pending"},{value:"paid",label:o.payout_status_paid||"Paid"},{value:"rejected",label:o.payout_status_rejected||"Rejected"}]}],search:!0,searchPlaceholder:o.search_placeholder||"Search..."}),c=$("#payouts-table").DataTable({...g.getDefaultConfig(),serverSide:!0,searching:!1,dom:_(),ajax:{url:i.records,type:"GET",headers:{Authorization:"Bearer "+d()},data:function(e){const a=l.getValues();e.search=a.search||"",e.status=a.statusFilter||""},error:function(e){e.status===401&&h().then(a=>{a&&c.ajax.reload()})}},columns:[{data:"id",name:"id"},{data:"client_name",name:"client_name",orderable:!1,render:function(e,a,n){var t;return`<a href="${(t=i.showAffiliate)==null?void 0:t.replace(":id",n.affiliate_id)}" class="text-decoration-none">${e}</a>`}},{data:"amount",name:"amount",className:"text-end fw-semibold"},{data:"status",name:"status",className:"text-center",render:function(e){const n={pending:{class:"bg-warning",text:o.payout_status_pending||"Pending"},paid:{class:"bg-success",text:o.payout_status_paid||"Paid"},rejected:{class:"bg-danger",text:o.payout_status_rejected||"Rejected"}}[e]||{class:"bg-secondary",text:e};return`<span class="badge ${n.class}">${n.text}</span>`}},{data:"payment_method",name:"payment_method"},{data:"admin_name",name:"admin_name",orderable:!1},{data:"notes",name:"notes",orderable:!1,render:function(e){return e?e.length>40?e.substring(0,40)+"...":e:"-"}},{data:"paid_at",name:"paid_at",render:function(e){return e?new Date(e).toLocaleDateString(document.documentElement.lang||"tr"):"-"}},{data:"created_at",name:"created_at",render:function(e){return e?new Date(e).toLocaleDateString(document.documentElement.lang||"tr"):"-"}},{data:"id",name:"actions",orderable:!1,searchable:!1,className:"text-end pe-4",render:function(e,a,n){return n.status!=="pending"?'<span class="text-muted">-</span>':`<div class="d-inline-flex">
                        <button type="button"
                                class="btn btn-sm btn-outline-success d-inline-flex align-items-center justify-content-center approve-payout-btn"
                                style="width: 32px; height: 32px;"
                                data-id="${e}"
                                data-bs-toggle="tooltip"
                                title="${o.button_approve||"Approve"}">
                            <i class="fas fa-check"></i>
                        </button>
                        <button type="button"
                                class="btn btn-sm btn-outline-danger d-inline-flex align-items-center justify-content-center ms-1 reject-payout-btn"
                                style="width: 32px; height: 32px;"
                                data-id="${e}"
                                data-bs-toggle="tooltip"
                                title="${o.button_reject||"Reject"}">
                            <i class="fas fa-times"></i>
                        </button>
                    </div>`}}],drawCallback:function(){y()},initComplete:function(){l.init()}});l.setDataTable(c),$(document).on("click",".approve-payout-btn",async function(){var s;const e=$(this).data("id");if(!await window.showConfirm(o.messages_confirm_approve_payout||"Are you sure you want to approve this payout?",{confirmClass:"btn-success",icon:"question"}))return;const n=(s=i.approvePayout)==null?void 0:s.replace(":id",e);n&&fetch(n,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer "+d()}}).then(t=>t.json()).then(t=>{t.success?(r("success",t.message),c.ajax.reload()):r("error",t.message||"Operation failed.")}).catch(t=>{console.error("Error:",t),r("error","An error occurred.")})}),$(document).on("click",".reject-payout-btn",function(){const e=$(this).data("id");document.getElementById("rejectPayoutId").value=e,document.getElementById("payoutRejectReason").value="",new f(document.getElementById("payoutRejectModal")).show()}),(m=document.getElementById("confirmPayoutReject"))==null||m.addEventListener("click",function(){var s;const e=document.getElementById("rejectPayoutId").value,a=document.getElementById("payoutRejectReason").value;if(!a.trim()){r("error","Please provide a rejection reason.");return}const n=(s=i.rejectPayout)==null?void 0:s.replace(":id",e);n&&fetch(n,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer "+d()},body:JSON.stringify({reason:a})}).then(t=>t.json()).then(t=>{var p;t.success?(r("success",t.message),c.ajax.reload(),(p=f.getInstance(document.getElementById("payoutRejectModal")))==null||p.hide()):r("error",t.message||"Operation failed.")}).catch(t=>{console.error("Error:",t),r("error","An error occurred.")})})});
