import{d as y}from"./datatables-I6jthWPb.js";import{r as f,g}from"./api-DZ3cXm1m.js";import{i as h}from"./tooltip-manager-D9RaGGY4.js";import"./bootstrap.esm-Bb7dPm-H.js";import"./datatables-Bo82YvhT.js";/* empty css                                  */document.addEventListener("DOMContentLoaded",function(){const o=document.getElementById("contractsTable");if(!o)return;const b=o.getAttribute("data-records-url"),a=window.contractsConfig,p={active:"bg-success",draft:"bg-secondary",archived:"bg-warning"},m={tos:"bg-primary",privacy:"bg-info",sla:"bg-warning",aup:"bg-danger",custom:"bg-secondary",kvkk_aydinlatma:"bg-info",affiliate_agreement:"bg-success",reseller_agreement:"bg-success"},c=$("#contractsTable").DataTable({...y.getDefaultConfig(),serverSide:!0,searching:!1,dom:'<"d-flex align-items-center mb-3"<"d-flex align-items-center"l>>t<"d-flex justify-content-between align-items-center mt-3"<"d-flex align-items-center"i><"d-flex align-items-center"p>>',ajax:{url:b,type:"GET",beforeSend:function(e){e.setRequestHeader("Authorization",`Bearer ${g()}`)},error:async function(e){e.status===401&&await f()&&c.ajax.reload()}},columns:[{data:"id",name:"id"},{data:"title",name:"title"},{data:"type",name:"type",render:function(e){const t=m[e]||"bg-secondary",n=a.translations["type_"+e]||e;return`<span class="badge ${t}">${n}</span>`}},{data:"status",name:"status",render:function(e){const t=p[e]||"bg-secondary",n=a.translations["status_"+e]||e;return`<span class="badge ${t}">${n}</span>`}},{data:"version",name:"version"},{data:"requires_acceptance",name:"requires_acceptance",render:function(e){return e?`<span class="badge bg-success">${a.translations.yes}</span>`:`<span class="badge bg-secondary">${a.translations.no}</span>`}},{data:"effective_date",name:"effective_date"},{data:"id",name:"actions",orderable:!1,searchable:!1,render:function(e){var s,r,l,d,u;const t=((s=window.pageConfig)==null?void 0:s.permissions)||{},n=[];if(t.update){const i=a.routes.edit.replace(":id",e);n.push(`
                            <a href="${i}"
                               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="${((l=(r=window.translations)==null?void 0:r.buttons)==null?void 0:l.edit)||"Edit"}">
                                <i class="fas fa-edit"></i>
                            </a>`)}if(t.delete){const i=a.routes.destroy.replace(":id",e);n.push(`
                            <button type="button"
                                    class="btn btn-sm btn-outline-danger d-inline-flex align-items-center justify-content-center ms-1 delete-contract"
                                    style="width: 32px; height: 32px;"
                                    data-id="${e}"
                                    data-url="${i}"
                                    data-bs-toggle="tooltip"
                                    title="${((u=(d=window.translations)==null?void 0:d.buttons)==null?void 0:u.delete)||"Delete"}">
                                <i class="fas fa-trash"></i>
                            </button>`)}return n.length===0?'<span class="text-muted">-</span>':`<div class="d-inline-flex">${n.join("")}</div>`}}],drawCallback:function(){h()}});document.body.addEventListener("click",async function(e){const t=e.target.closest(".delete-contract");if(!t||!confirm(a.translations.confirm_delete))return;const n=t.getAttribute("data-url");try{const s=await fetch(n,{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:`Bearer ${g()}`}});if(s.status===401){await f()&&t.click();return}s.ok&&c.ajax.reload(null,!1)}catch(s){console.error("Delete error:",s)}})});
