import"./bootstrap.esm-Bb7dPm-H.js";import{d as T}from"./datatables-I6jthWPb.js";import{s as g}from"./toastr-helper-Wdj0mZjX.js";import{i as j}from"./tooltip-manager-D9RaGGY4.js";import"./datatables-Bo82YvhT.js";/* empty css                                  */document.addEventListener("DOMContentLoaded",function(){const f=document.getElementById("admins-table");if(!f)return;const B=f.dataset.recordsUrl,u=$("#admins-table").DataTable({...T.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",headers:{Authorization:"Bearer "+document.querySelector('meta[name="api-token"]').getAttribute("content")},data:function(e){var t,n;e.search=((t=document.getElementById("searchInput"))==null?void 0:t.value)||"",e.role=y("advRole"),e.status=y("advStatus"),e.date_range=((n=document.getElementById("advDateRange"))==null?void 0:n.value)||""}},columns:[{data:"id",name:"id"},{data:"name",name:"name"},{data:"email",name:"email"},{data:"roles",name:"roles",orderable:!1,searchable:!1,render:function(e){return!e||e.length===0?'<span class="text-muted">-</span>':e.map(t=>`<span class="badge bg-secondary me-1">${t}</span>`).join("")}},{data:"last_login_at",name:"last_login_at",render:function(e){var t,n;return e?new Date(e).toLocaleString(document.documentElement.lang||"tr"):'<span class="text-muted">'+(((n=(t=window.translations)==null?void 0:t.messages)==null?void 0:n.never_logged_in)||"Never logged in")+"</span>"}},{data:"created_at",name:"created_at",render:function(e){return new Date(e).toLocaleString(document.documentElement.lang||"tr")}},{data:"status",name:"status",render:function(e,t,n){var i,o,r,l,c,m;let a="bg-secondary",s=e;switch(e){case"active":a="bg-success",s=((o=(i=window.translations)==null?void 0:i.status)==null?void 0:o.active)||"Active";break;case"inactive":a="bg-danger",s=((l=(r=window.translations)==null?void 0:r.status)==null?void 0:l.inactive)||"Inactive";break;case"suspended":a="bg-warning",s=((m=(c=window.translations)==null?void 0:c.status)==null?void 0:m.suspended)||"Suspended";break;default:s=n.status_text||e}return`<span class="badge ${a}">${s}</span>`}},{data:"id",name:"actions",orderable:!1,searchable:!1,render:function(e,t,n){var s,i,o,r,l,c,m,v,E,x,I;const a=[];if((i=(s=window.permissions)==null?void 0:s.adminManagement)!=null&&i.update){const S=(l=(r=(o=window.routes)==null?void 0:o.adminManagement)==null?void 0:r.edit)==null?void 0:l.replace(":id",e);a.push(`
                            <a href="${S}"
                               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="${((m=(c=window.translations)==null?void 0:c.buttons)==null?void 0:m.edit)||"Edit"}">
                                <i class="fas fa-edit"></i>
                            </a>`)}return(E=(v=window.permissions)==null?void 0:v.adminManagement)!=null&&E.delete&&n.id!==window.currentUserId&&a.push(`
                            <button type="button"
                                    class="btn btn-sm btn-outline-danger d-inline-flex align-items-center justify-content-center ms-1 delete-admin"
                                    style="width: 32px; height: 32px;"
                                    data-id="${e}"
                                    data-name="${n.name}"
                                    data-bs-toggle="tooltip"
                                    title="${((I=(x=window.translations)==null?void 0:x.buttons)==null?void 0:I.delete)||"Delete"}">
                                <i class="fas fa-trash"></i>
                            </button>`),a.length===0?'<span class="text-muted">-</span>':`<div class="d-inline-flex">${a.join("")}</div>`}}],drawCallback:function(){j()}}),p=document.getElementById("searchInput");if(p){let e;p.addEventListener("input",function(){clearTimeout(e),e=setTimeout(function(){u.ajax.reload()},500)})}const h=document.getElementById("toggleAdvancedSearch"),d=document.getElementById("advancedSearchContainer");h&&d&&h.addEventListener("click",function(){d.style.display==="none"?(d.style.display="block",d.classList.add("show")):(d.classList.remove("show"),setTimeout(function(){d.style.display="none"},300))});const b=document.getElementById("applyAdvancedSearch");b&&b.addEventListener("click",function(){u.ajax.reload()});const w=document.getElementById("resetAdvancedSearch");w&&w.addEventListener("click",function(){const e=document.getElementById("advRole"),t=document.getElementById("advStatus"),n=document.getElementById("advDateRange");e&&(e.selectedIndex=-1),t&&(t.selectedIndex=-1),n&&(n.value=""),u.ajax.reload()}),$(document).on("click",".delete-admin",async function(){var a,s;const e=$(this).data("id"),t=$(this).data("name");await window.showConfirm(`${((s=(a=window.translations)==null?void 0:a.messages)==null?void 0:s.confirm_delete)||"Are you sure you want to delete this admin?"}

Admin: ${t}`,{confirmClass:"btn-danger",icon:"warning"})&&A(e)});function y(e){const t=document.getElementById(e);return t?t.tagName==="SELECT"&&t.multiple?Array.from(t.selectedOptions).map(n=>n.value):t.value:""}function A(e){var n,a,s;const t=(s=(a=(n=window.routes)==null?void 0:n.adminManagement)==null?void 0:a.delete)==null?void 0:s.replace(":id",e);fetch(t,{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:"Bearer "+document.querySelector('meta[name="api-token"]').getAttribute("content")}}).then(i=>i.json()).then(i=>{i.success?(u.ajax.reload(),g("success",i.message||"Admin deleted successfully.")):g("error",i.message||"Delete operation failed.")}).catch(i=>{console.error("Error:",i),g("error","An error occurred while deleting.")})}});
