import"./bootstrap.esm-Bb7dPm-H.js";import{d as E}from"./datatables-I6jthWPb.js";import{r as j,g as h}from"./api-DZ3cXm1m.js";import{i as k}from"./tooltip-manager-D9RaGGY4.js";import{c as B,g as F}from"./datatable-filters-CecjJm_7.js";import"./datatables-Bo82YvhT.js";/* empty css                                  */import"./vendor-zLyX4B24.js";import"./tr-CHCA6xOE.js";let d;const{permissions:C,routes:w,translations:e}=window,L=[{value:"",label:e.filters_all_statuses||"All Statuses"},{value:"pending",label:e.status_pending||"Pending"},{value:"approved",label:e.status_approved||"Approved"},{value:"rejected",label:e.status_rejected||"Rejected"},{value:"cancelled",label:e.status_cancelled||"Cancelled"}],z=[{value:"",label:e.filters_all_types||"All Types"},{value:"product",label:e.type_product||"Product"},{value:"domain",label:e.type_domain||"Domain"}],g=B(null,{filters:[{type:"select",id:"statusFilter",options:L,width:"150px"},{type:"select",id:"typeFilter",options:z,width:"140px"}],search:!0,searchPlaceholder:e.search_placeholder||"Search..."});function S(){var l,i,o,n,r,p,y,_,v,T,q,x;const s=document.getElementById("cancellationRequests");if(!s)return;const u=s.getAttribute("data-records-url");d=$(s).DataTable({...E.getDefaultConfig(),serverSide:!0,searching:!1,dom:F(),ajax:{url:u,type:"GET",beforeSend:function(t){t.setRequestHeader("Authorization",`Bearer ${h()}`)},data:function(t){const a=g.getValues();t.status=a.statusFilter,t.type=a.typeFilter,t.search={value:a.search||""}},error:async function(t){t.status===401&&await j()&&d.ajax.reload()}},columns:[{data:"id",name:"id",title:"ID"},{data:"client_name",name:"client_name",title:((i=(l=e.cancellationRequests)==null?void 0:l.fields)==null?void 0:i.client_name)||"Client"},{data:"product_name",name:"product_name",title:((n=(o=e.cancellationRequests)==null?void 0:o.fields)==null?void 0:n.product_name)||"Product / Domain",orderable:!1},{data:"type",name:"type",title:((p=(r=e.cancellationRequests)==null?void 0:r.fields)==null?void 0:p.type)||"Type"},{data:"reason_text",name:"reason",title:((_=(y=e.cancellationRequests)==null?void 0:y.fields)==null?void 0:_.reason)||"Reason"},{data:"status",name:"status",title:((T=(v=e.cancellationRequests)==null?void 0:v.fields)==null?void 0:T.status)||"Status",render:function(t,a,f){const c=f.status_text||t;return'<span class="badge '+({pending:"bg-warning",approved:"bg-success",rejected:"bg-danger",cancelled:"bg-secondary"}[t]||"bg-secondary")+'">'+c+"</span>"}},{data:"created_at",name:"created_at",title:((x=(q=e.cancellationRequests)==null?void 0:q.fields)==null?void 0:x.created_at)||"Created At"},{data:"actions",name:"actions",orderable:!1,searchable:!1,render:function(t){var c,m,b,D,R;const a=[],f=w.cancellationRequests.show.replace(":id",t);if(a.push(`
                        <a href="${f}"
                           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="${((c=e.buttons)==null?void 0:c.view)||"View"}">
                            <i class="fas fa-eye"></i>
                        </a>`),(m=C.cancellationRequests)!=null&&m.update){const A=w.cancellationRequests.edit.replace(":id",t);a.push(`
                            <a href="${A}"
                               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="${((b=e.buttons)==null?void 0:b.edit)||"Edit"}">
                                <i class="fas fa-edit"></i>
                            </a>`)}return(D=C.cancellationRequests)!=null&&D.delete&&a.push(`
                            <button type="button"
                                    class="btn btn-sm btn-outline-danger d-inline-flex align-items-center justify-content-center ms-1 delete-cancellation-request"
                                    style="width: 32px; height: 32px;"
                                    data-id="${t}"
                                    data-bs-toggle="tooltip"
                                    title="${((R=e.buttons)==null?void 0:R.delete)||"Delete"}">
                                <i class="fas fa-trash"></i>
                            </button>`),`<div class="d-inline-flex">${a.join("")}</div>`}}],initComplete:function(){g.init()},drawCallback:function(){k()}}),g.setDataTable(d)}async function P(s){var i,o;if(!await window.showConfirm(((i=e.messages)==null?void 0:i.confirm_delete)||"Are you sure you want to delete this cancellation request?",{confirmClass:"btn-danger",icon:"warning"}))return;const l=w.cancellationRequests.delete.replace(":id",s);try{let n=await fetch(l,{method:"DELETE",headers:{Authorization:`Bearer ${h()}`}});n.status===401&&await j()&&(n=await fetch(l,{method:"DELETE",headers:{Authorization:`Bearer ${h()}`}}));const r=await n.json();r.success?(window.showToast&&window.showToast("success",((o=e.messages)==null?void 0:o.deleted)||"Cancellation request deleted successfully."),d.ajax.reload()):console.error("Delete error:",r.message)}catch(n){console.error("Delete error:",n)}}function U(){document.addEventListener("click",function(s){if(s.target.closest(".delete-cancellation-request")){const l=s.target.closest(".delete-cancellation-request").getAttribute("data-id");P(l)}})}document.addEventListener("DOMContentLoaded",function(){S(),U()});
