import"./bootstrap.esm-Bb7dPm-H.js";import{i as k}from"./tooltip-manager-D9RaGGY4.js";import{d as S}from"./datatables-I6jthWPb.js";import{s as d}from"./toastr-helper-Wdj0mZjX.js";import"./datatables-Bo82YvhT.js";/* empty css                                  */document.addEventListener("DOMContentLoaded",function(){const c=document.getElementById("roles-table");if(!c)return;const I=c.dataset.recordsUrl,o=$("#roles-table").DataTable({...S.getDefaultConfig(),serverSide:!0,searching:!0,dom:'<"d-flex justify-content-between align-items-center mb-3"<"d-flex align-items-center"l><"d-flex align-items-center"f>>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:I,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.permission_filter=p("advPermission"),e.guard_name=p("advGuardName"),e.date_range=((n=document.getElementById("advDateRange"))==null?void 0:n.value)||""}},columns:[{data:"id",name:"id",orderable:!1,searchable:!1,width:"40px",render:function(e){return`<input type="checkbox" class="form-check-input row-checkbox" value="${e}">`}},{data:"id",name:"id"},{data:"name",name:"name",render:function(e,t,n){return`<span class="fw-bold">${e}</span>`}},{data:"guard_name",name:"guard_name",render:function(e){return`<span class="badge bg-info">${e}</span>`}},{data:"permissions_count",name:"permissions_count",render:function(e){return e===0?'<span class="text-muted">0</span>':`<span class="badge bg-primary">${e}</span>`}},{data:"users_count",name:"users_count",render:function(e){return e===0?'<span class="text-muted">0</span>':`<span class="badge bg-success">${e}</span>`}},{data:"created_at",name:"created_at",render:function(e){return new Date(e).toLocaleString(document.documentElement.lang||"tr")}},{data:"id",name:"actions",orderable:!1,searchable:!1,render:function(e,t,n){var i,s,g,h,b,y,w,E,v,x,B;const a=[];if((s=(i=window.permissions)==null?void 0:i.roleManagement)!=null&&s.update){const j=(b=(h=(g=window.routes)==null?void 0:g.roleManagement)==null?void 0:h.edit)==null?void 0:b.replace(":id",e);a.push(`
                            <a href="${j}"
                               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="${((w=(y=window.translations)==null?void 0:y.buttons)==null?void 0:w.edit)||"Edit"}">
                                <i class="fas fa-edit"></i>
                            </a>`)}return(v=(E=window.permissions)==null?void 0:E.roleManagement)!=null&&v.delete&&n.users_count===0&&a.push(`
                            <button type="button"
                                    class="btn btn-sm btn-outline-danger d-inline-flex align-items-center justify-content-center ms-1 delete-role"
                                    style="width: 32px; height: 32px;"
                                    data-id="${e}"
                                    data-name="${n.name}"
                                    data-bs-toggle="tooltip"
                                    title="${((B=(x=window.translations)==null?void 0:x.buttons)==null?void 0:B.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(){k()}}),l=document.getElementById("searchInput");if(l){let e;l.addEventListener("input",function(){clearTimeout(e),e=setTimeout(function(){o.ajax.reload()},500)})}const u=document.getElementById("toggleAdvancedSearch"),r=document.getElementById("advancedSearchContainer");u&&r&&u.addEventListener("click",function(){r.style.display==="none"?(r.style.display="block",r.classList.add("show")):(r.classList.remove("show"),setTimeout(function(){r.style.display="none"},300))});const m=document.getElementById("applyAdvancedSearch");m&&m.addEventListener("click",function(){o.ajax.reload()});const f=document.getElementById("resetAdvancedSearch");f&&f.addEventListener("click",function(){const e=document.getElementById("advPermission"),t=document.getElementById("advGuardName"),n=document.getElementById("advDateRange");e&&(e.selectedIndex=-1),t&&(t.selectedIndex=-1),n&&(n.value=""),o.ajax.reload()}),$(document).on("click",".delete-role",async function(){var a,i;const e=$(this).data("id"),t=$(this).data("name");await window.showConfirm(`${((i=(a=window.translations)==null?void 0:a.messages)==null?void 0:i.confirm_delete)||"Bu rolü silmek istediğinizden emin misiniz?"}

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