document.addEventListener("DOMContentLoaded",function(e){let t=document.querySelector(".datatables-users"),r={1:{title:"Pending",class:"bg-label-warning"},2:{title:"Active",class:"bg-label-success"},3:{title:"Inactive",class:"bg-label-secondary"}},n,l="app-user-view-account.html";function a(e){let t=document.querySelector(".dtr-expanded");(t=e?e.target.parentElement.closest("tr"):t)&&n.row(t).remove().draw()}function s(){var e=document.querySelector(".datatables-users");let t=document.querySelector(".dtr-bs-modal");e&&e.classList.contains("collapsed")?t&&t.addEventListener("click",function(e){e.target.parentElement.classList.contains("delete-record")&&(a(),e=t.querySelector(".btn-close"))&&e.click()}):(e=e?.querySelector("tbody"))&&e.addEventListener("click",function(e){e.target.parentElement.classList.contains("delete-record")&&a(e)})}t&&(document.createElement("div").classList.add("user_role"),document.createElement("div").classList.add("user_plan"),n=new DataTable(t,{ajax:assetsPath+"json/user-list.json",columns:[{data:"id"},{data:"id",orderable:!1,render:DataTable.render.select()},{data:"full_name"},{data:"role"},{data:"current_plan"},{data:"billing"},{data:"status"},{data:"id"}],columnDefs:[{className:"control",orderable:!1,searchable:!1,responsivePriority:5,targets:0,render:function(e,t,n,a){return""}},{targets:1,orderable:!1,searchable:!1,responsivePriority:3,checkboxes:!0,checkboxes:{selectAllRender:'<input type="checkbox" class="form-check-input">'},render:function(){return'<input type="checkbox" class="dt-checkboxes form-check-input">'}},{targets:2,responsivePriority:1,render:function(e,t,n,a){var r=n.full_name,s=n.email,n=n.avatar;let o;return`
              <div class="d-flex justify-content-left align-items-center role-name">
                <div class="avatar-wrapper">
                  <div class="avatar avatar-sm me-3">
                    ${o=n?`<img src="${assetsPath}img/avatars/${n}" alt="Avatar" class="rounded-circle">`:`<span class="avatar-initial rounded-circle bg-label-${["success","danger","warning","info","dark","primary","secondary"][Math.floor(6*Math.random())+1]}">${(r.match(/\b\w/g)||[]).slice(0,2).join("").toUpperCase()}</span>`}
                  </div>
                </div>
                <div class="d-flex flex-column">
                  <a href="${l}" class="text-heading text-truncate"><span class="fw-medium">${r}</span></a>
                  <small>@${s}</small>
                </div>
              </div>
            `}},{targets:3,render:function(e,t,n,a){n=n.role;return`<span class='text-truncate d-flex align-items-center'>${{Subscriber:'<span class="me-2"><i class="icon-base ti tabler-user icon-22px text-success"></i></span>',Author:'<span class="me-2"><i class="icon-base ti tabler-device-desktop icon-22px text-danger"></i></span>',Maintainer:'<span class="me-2"><i class="icon-base ti tabler-chart-pie icon-22px text-info"></i></span>',Editor:'<span class="me-2"><i class="icon-base ti tabler-edit icon-22px text-warning"></i></span>',Admin:'<span class="me-2"><i class="icon-base ti tabler-crown icon-22px text-primary"></i></span>'}[n]||""}${n}</span>`}},{targets:4,render:function(e,t,n,a){return'<span class="fw-medium">'+n.current_plan+"</span>"}},{targets:6,render:function(e,t,n,a){n=n.status;return'<span class="badge '+r[n].class+'" text-capitalized>'+r[n].title+"</span>"}},{targets:-1,title:"Actions",searchable:!1,orderable:!1,render:function(e,t,n,a){return`
              <div class="d-flex align-items-center">
                <a href="javascript:;" class="btn btn-icon btn-text-secondary rounded-pill waves-effect delete-record"><i class="icon-base ti tabler-trash icon-md"></i></a>
                <a href="${l}" class="btn btn-icon btn-text-secondary rounded-pill waves-effect"><i class="icon-base ti tabler-eye icon-md"></i></a>
                <a href="javascript:;" class="btn btn-icon btn-text-secondary rounded-pill waves-effect dropdown-toggle hide-arrow" data-bs-toggle="dropdown"><i class="icon-base ti tabler-dots-vertical icon-md"></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>
              </div>
            `}}],select:{style:"multi",selector:"td:nth-child(2)"},order:[[2,"desc"]],layout:{topStart:{rowClass:"row my-md-0 me-3 ms-0 justify-content-between",features:[{pageLength:{menu:[10,25,50,100],text:"_MENU_"}}]},topEnd:{features:[{search:{placeholder:"Search User",text:"_INPUT_"}},{buttons:[{extend:"collection",className:"btn btn-label-secondary dropdown-toggle me-4",text:'<span class="d-flex align-items-center gap-1"><i class="icon-base ti tabler-upload icon-xs"></i> <span class="d-inline-block">Export</span></span>',buttons:[{extend:"print",text:'<span class="d-flex align-items-center"><i class="icon-base ti tabler-printer me-1"></i>Print</span>',className:"dropdown-item",exportOptions:{columns:[3,4,5,6,7],format:{body:function(e,t,n){if(e.length<=0||!(-1<e.indexOf("<")))return e;{e=(new DOMParser).parseFromString(e,"text/html");let t="";var a=e.querySelectorAll(".role-name");return 0<a.length?a.forEach(e=>{e=e.querySelector(".fw-medium")?.textContent||e.querySelector(".d-block")?.textContent||e.textContent;t+=e.trim()+" "}):t=e.body.textContent||e.body.innerText,t.trim()}}}},customize:function(e){e.document.body.style.color=config.colors.headingColor,e.document.body.style.borderColor=config.colors.borderColor,e.document.body.style.backgroundColor=config.colors.bodyBg;e=e.document.body.querySelector("table");e.classList.add("compact"),e.style.color="inherit",e.style.borderColor="inherit",e.style.backgroundColor="inherit"}},{extend:"csv",text:'<span class="d-flex align-items-center"><i class="icon-base ti tabler-file me-1"></i>Csv</span>',className:"dropdown-item",exportOptions:{columns:[3,4,5,6,7],format:{body:function(e,t,n){if(e.length<=0)return e;e=(new DOMParser).parseFromString(e,"text/html");let a="";var r=e.querySelectorAll(".role-name");return 0<r.length?r.forEach(e=>{e=e.querySelector(".fw-medium")?.textContent||e.querySelector(".d-block")?.textContent||e.textContent;a+=e.trim()+" "}):a=e.body.textContent||e.body.innerText,a.trim()}}}},{extend:"excel",text:'<span class="d-flex align-items-center"><i class="icon-base ti tabler-file-export me-1"></i>Excel</span>',className:"dropdown-item",exportOptions:{columns:[3,4,5,6,7],format:{body:function(e,t,n){if(e.length<=0)return e;e=(new DOMParser).parseFromString(e,"text/html");let a="";var r=e.querySelectorAll(".role-name");return 0<r.length?r.forEach(e=>{e=e.querySelector(".fw-medium")?.textContent||e.querySelector(".d-block")?.textContent||e.textContent;a+=e.trim()+" "}):a=e.body.textContent||e.body.innerText,a.trim()}}}},{extend:"pdf",text:'<span class="d-flex align-items-center"><i class="icon-base ti tabler-file-text me-1"></i>Pdf</span>',className:"dropdown-item",exportOptions:{columns:[3,4,5,6,7],format:{body:function(e,t,n){if(e.length<=0)return e;e=(new DOMParser).parseFromString(e,"text/html");let a="";var r=e.querySelectorAll(".role-name");return 0<r.length?r.forEach(e=>{e=e.querySelector(".fw-medium")?.textContent||e.querySelector(".d-block")?.textContent||e.textContent;a+=e.trim()+" "}):a=e.body.textContent||e.body.innerText,a.trim()}}}},{extend:"copy",text:'<i class="icon-base ti tabler-copy me-1"></i>Copy',className:"dropdown-item",exportOptions:{columns:[3,4,5,6,7],format:{body:function(e,t,n){if(e.length<=0)return e;e=(new DOMParser).parseFromString(e,"text/html");let a="";var r=e.querySelectorAll(".role-name");return 0<r.length?r.forEach(e=>{e=e.querySelector(".fw-medium")?.textContent||e.querySelector(".d-block")?.textContent||e.textContent;a+=e.trim()+" "}):a=e.body.textContent||e.body.innerText,a.trim()}}}}]},{text:'<i class="icon-base ti tabler-plus me-0 me-sm-1 icon-16px"></i><span class="d-none d-sm-inline-block">Add New User</span>',className:"add-new btn btn-primary rounded-2 waves-effect waves-light",attr:{"data-bs-toggle":"modal","data-bs-target":"#addRoleModal"}}]}]},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().full_name}}),type:"column",renderer:function(e,t,n){var a,r,s,n=n.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!!n&&((a=document.createElement("div")).classList.add("table-responsive"),r=document.createElement("table"),a.appendChild(r),r.classList.add("table"),(s=document.createElement("tbody")).innerHTML=n,r.appendChild(s),a)}}}}),s(),document.addEventListener("show.bs.modal",function(e){e.target.classList.contains("dtr-bs-modal")&&s()}),document.addEventListener("hide.bs.modal",function(e){e.target.classList.contains("dtr-bs-modal")&&s()})),setTimeout(()=>{[{selector:".dt-buttons .btn",classToRemove:"btn-secondary"},{selector:".dt-buttons.btn-group .btn-group",classToRemove:"btn-group"},{selector:".dt-buttons.btn-group",classToRemove:"btn-group",classToAdd:"d-flex"},{selector:".dt-search .form-control",classToRemove:"form-control-sm"},{selector:".dt-length .form-select",classToRemove:"form-select-sm"},{selector:".dt-length",classToAdd:"mb-md-6 mb-0"},{selector:".dt-layout-start",classToAdd:"ps-3 mt-0"},{selector:".dt-layout-end",classToRemove:"justify-content-between",classToAdd:"justify-content-md-between justify-content-center d-flex flex-wrap gap-4 mt-0 mb-md-0 mb-6"},{selector:".dt-layout-table",classToRemove:"row mt-2"},{selector:".dt-layout-full",classToRemove:"col-md col-12",classToAdd:"table-responsive"}].forEach(({selector:e,classToRemove:n,classToAdd:a})=>{document.querySelectorAll(e).forEach(t=>{n&&n.split(" ").forEach(e=>t.classList.remove(e)),a&&a.split(" ").forEach(e=>t.classList.add(e))})})},100);var o=document.querySelectorAll(".role-edit-modal"),c=document.querySelector(".add-new-role"),i=document.querySelector(".role-title");c.onclick=function(){i.innerHTML="Add New Role"},o&&o.forEach(function(e){e.onclick=function(){i.innerHTML="Edit Role"}})});