document.addEventListener("DOMContentLoaded",function(e){let t=document.querySelector(".datatables-permissions"),r="app-user-list.html",a;t&&(a=new DataTable(t,{ajax:assetsPath+"json/permissions-list.json",columns:[{data:"id"},{data:"id"},{data:"name"},{data:"assigned_to"},{data:"created_date"},{data:"id"}],columnDefs:[{className:"control",orderable:!1,searchable:!1,responsivePriority:2,targets:0,render:function(e,t,a,s){return""}},{targets:1,searchable:!1,visible:!1},{targets:2,render:function(e,t,a,s){return'<span class="text-nowrap text-heading">'+a.name+"</span>"}},{targets:3,orderable:!1,render:function(e,t,a,s){a=a.assigned_to;let n="",o={Admin:`<a href="${r}"><span class="badge bg-label-primary me-4">Administrator</span></a>`,Manager:`<a href="${r}"><span class="badge bg-label-warning me-4">Manager</span></a>`,Users:`<a href="${r}"><span class="badge bg-label-success me-4">Users</span></a>`,Support:`<a href="${r}"><span class="badge bg-label-info me-4">Support</span></a>`,Restricted:`<a href="${r}"><span class="badge bg-label-danger me-4">Restricted User</span></a>`};return a.forEach(e=>{n+=o[e]||""}),`<span class="text-nowrap">${n}</span>`}},{targets:4,orderable:!1,render:function(e,t,a,s){return'<span class="text-nowrap">'+a.created_date+"</span>"}},{targets:-1,searchable:!1,title:"Actions",orderable:!1,render:function(e,t,a,s){return`
              <div class="d-flex align-items-center">
                <span class="text-nowrap">
                  <button class="btn btn-icon me-1" data-bs-target="#editPermissionModal" data-bs-toggle="modal" data-bs-dismiss="modal">
                    <i class="icon-base ti tabler-edit icon-22px"></i>
                  </button>
                  <a href="javascript:;" class="btn btn-icon dropdown-toggle hide-arrow" data-bs-toggle="dropdown">
                    <i class="icon-base ti tabler-dots-vertical icon-22px"></i>
                  </a>
                  <div class="dropdown-menu dropdown-menu-end m-0">
                    <a href="javascript:;" class="dropdown-item">Edit</a>
                    <a href="javascript:;" class="dropdown-item">Suspend</a>
                  </div>
                </span>
              </div>
            `}}],order:[[1,"asc"]],layout:{topStart:{rowClass:"row m-3 my-0 justify-content-between",features:[{pageLength:{menu:[10,25,50,100],text:"Show _MENU_"}}]},topEnd:{features:[{search:{placeholder:"Search Permissions",text:"_INPUT_"}},{buttons:[{text:'<i class="icon-base ti tabler-plus icon-xs me-0 me-sm-2"></i><span class="d-none d-sm-inline-block">Add Permission</span>',className:"add-new btn btn-primary",attr:{"data-bs-toggle":"modal","data-bs-target":"#addPermissionModal"}}]}]},bottomStart:{rowClass:"row mx-3 justify-content-between",features:["info"]},bottomEnd:"paging"},language:{paginate:{next:'<i class="icon-base ti tabler-chevron-right scaleX-n1-rtl icon-18px"></i>',previous:'<i class="icon-base ti tabler-chevron-left scaleX-n1-rtl icon-18px"></i>',first:'<i class="icon-base ti tabler-chevrons-left scaleX-n1-rtl icon-18px"></i>',last:'<i class="icon-base ti tabler-chevrons-right scaleX-n1-rtl icon-18px"></i>'}},responsive:{details:{display:DataTable.Responsive.display.modal({header:function(e){return"Details of "+e.data().name}}),type:"column",renderer:function(e,t,a){var s,n,o,a=a.map(function(e){return""!==e.title?`<tr data-dt-row="${e.rowIndex}" data-dt-column="${e.columnIndex}">
                      <td>${e.title}:</td>
                      <td>${e.data}</td>
                    </tr>`:""}).join("");return!!a&&((s=document.createElement("div")).classList.add("table-responsive"),n=document.createElement("table"),s.appendChild(n),n.classList.add("table"),(o=document.createElement("tbody")).innerHTML=a,n.appendChild(o),s)}}}})),$(".datatables-permissions tbody").on("click",".delete-record",function(){a.row($(this).parents("tr")).remove().draw()}),setTimeout(()=>{[{selector:".dt-buttons .btn",classToRemove:"btn-secondary"},{selector:".dt-search .form-control",classToRemove:"form-control-sm"},{selector:".dt-length .form-select",classToRemove:"form-select-sm"},{selector:".dt-length",classToAdd:"mb-0 mb-md-4"},{selector:".dt-buttons",classToAdd:"mb-0"},{selector:".dt-layout-end",classToRemove:"justify-content-between",classToAdd:"justify-content-md-between justify-content-center d-flex flex-wrap gap-md-4 mb-sm-0 mb-6 mt-0"},{selector:".dt-layout-start",classToAdd:"mt-0"},{selector:".dt-layout-table",classToRemove:"row mt-2"},{selector:".dt-layout-full",classToRemove:"col-md col-12",classToAdd:"table-responsive"}].forEach(({selector:e,classToRemove:a,classToAdd:s})=>{document.querySelectorAll(e).forEach(t=>{a&&a.split(" ").forEach(e=>t.classList.remove(e)),s&&s.split(" ").forEach(e=>t.classList.add(e))})})},100)});