import{a as n,b as l}from"./chunk-2AVGQ2MQ.js";var d=class{constructor(t,e,a,r,o,g,c){this.datePipe=t,this.toastr=e,this.cdr=a,this.router=r,this.sharedService=o,this.TranslateService=g,this.dataManagementService=c,this.list=[],this.sortedList=[],this.sortDirection=!1,this.searchUser="",this.filteredList=[],this.noUsersFound=!1,this.showNavigation=!1,this.next="",this.previous="",this.last="",this.first="",this.currentpageCount=0,this.totalpageCount=0,this.pageSize=100,this.currentPage=1,this.totalPages=1,this.pageSizeOptions=[50,100,250,500],this.displayFrom=0,this.displayTo=0,this.sortColumn="userName",this.selectedRadio="",this.parseResponse=s=>i=>{this.list=i.body.data,this.list=i.body.data.map(h=>l(n({},h),{userNameEncoded:btoa(h.userName)})),this.filteredList=[...this.list],this.sortTable(this.sortColumn),this.totalPages=Math.ceil(this.sortedList.length/this.pageSize),this.currentPage=1,this.updateDisplayRange(),i.body.metadata?(this.showNavigation=!0,this.next=i.body.metadata.links?.next,this.previous=i.body.metadata.links?.previous,this.last=i.body.metadata.links?.last,this.first=i.body.metadata.links?.first,this.currentpageCount=i.body.metadata.pageNumber,this.totalpageCount=Math.ceil(i.body.metadata.totalCount/i.body.metadata.recordsPerPage)):this.showNavigation=!1,s?s():this.cdr.detectChanges()},this.parseError=s=>{switch(s.status){case 400:console.error("Bad Request: ",s.message);break;case 401:console.error("Unauthorized: ",s.message),this.toastr.error(this.TranslateService.instant("Token expired, navigating to logout page."),this.TranslateService.instant("Error")),setTimeout(()=>{this.router.navigate(["/logout"])},3e3);break;case 403:console.error("Forbidden: ",s.message);break;case 404:console.error("Not Found: ",s.message);break;case 447:this.toastr.info(this.TranslateService.instant("Changes were not saved.  The User is under Legal hold. Please contact your Administrator."),this.TranslateService.instant("Info"));break;case 500:console.error("Internal Server Error: ",s.message);break;case 503:console.error("Internal Server Error: ",s.message);break;default:console.error("Unknown Error: ",s.message);break}}}getFormattedDate(t){return this.datePipe.transform(t,"dd-MMM-yyyy HH:mm:ss")||""}sendMeTo(t,e){e!=""&&this.sharedService.setData("currentPolicyName",e),this.router.navigate([t])}get paginatedList(){let t=(this.currentPage-1)*this.pageSize,e=t+this.pageSize;return this.sortedList.slice(t,e)}changePage(t){t<1||t>this.totalPages||(this.currentPage=t,this.updateDisplayRange())}changePageSize(t){let e=t.target.value;this.pageSize=+e,this.currentPage=1,this.totalPages=Math.ceil(this.sortedList.length/this.pageSize),this.updateDisplayRange()}updateDisplayRange(){if(!this.sortedList||this.sortedList.length===0){this.displayFrom=0,this.displayTo=0;return}this.displayFrom=(this.currentPage-1)*this.pageSize+1,this.displayTo=Math.min(this.currentPage*this.pageSize,this.sortedList.length)}getAll(t,e){return this.sortedList=[],this.sortDirection=!1,this.dataManagementService.getAll(t).subscribe(this.parseResponse(e),this.parseError)}getAll_Navigate(t,e){this.sortedList=[],this.sortDirection=!1,this.dataManagementService.getAll_Navigate(t,e).subscribe(this.parseResponse(),this.parseError)}sortTable(t){this.sortColumn===t?this.sortDirection=!this.sortDirection:(this.sortColumn=t,this.sortDirection=!0),this.applySorting()}applySorting(){this.sortedList=this.filteredList.sort((t,e)=>{let a=t[this.sortColumn]||"",r=e[this.sortColumn]||"";typeof a=="string"&&(a=a.toLowerCase()),typeof r=="string"&&(r=r.toLowerCase());let o=0;return a>r?o=1:a<r&&(o=-1),this.sortDirection?o:-o})}getCaretClass(t){return this.sortColumn===t?this.sortDirection?"fa fa-caret-up":"fa fa-caret-down":""}trackByUser(t,e){return e.userName}filterUsers(){this.searchUser=this.searchUser.trim();let t=this.searchUser.toLowerCase();this.filteredList=this.list.filter(e=>e.userName?.toLowerCase().includes(t)||e.displayName?.toLowerCase().includes(t)||e.emailId?.toLowerCase().includes(t)),this.noUsersFound=this.filteredList.length===0,this.currentPage=1,this.totalPages=Math.ceil(this.filteredList.length/this.pageSize),this.applySorting(),this.updateDisplayRange()}};export{d as a};
