import{a as J}from"./chunk-3BUU6LNF.js";import{a as Q}from"./chunk-I5K7GPAI.js";import{a as W,b as X}from"./chunk-MXSLISEG.js";import"./chunk-7QEXVS2A.js";import{a as V}from"./chunk-D4RZOGGF.js";import"./chunk-HXEFMD5A.js";import"./chunk-KCLQIV7M.js";import"./chunk-5KCUTXXV.js";import{a as Z}from"./chunk-JUDWAYYT.js";import"./chunk-LAJI7RPC.js";import"./chunk-WFZJP5WR.js";import"./chunk-F6KLNSUK.js";import{b as q,c as $,d as H}from"./chunk-YOJ4KGSB.js";import"./chunk-CO3X7TQN.js";import{a as L}from"./chunk-VSFNMVXJ.js";import"./chunk-WQ6DP4JQ.js";import{Ob as x,ob as m,s as F,v as M,y as T}from"./chunk-YSQLW2JA.js";import{Da as P,Ya as f,Za as j}from"./chunk-NVJ2ZZFT.js";import{Aa as h,Ba as y,He as U,Mg as D,Ng as A,Pd as I,Qf as N,Rd as b,Sd as z,Se as E,Te as v,Ue as _,_a as k,ab as g,af as O,bb as p,bh as B,dd as u,fb as w,gb as C,ha as S,hd as c,sc as R,ya as l}from"./chunk-SKPDQO4E.js";var K=`<div class="h-100">
  <side-navigation>
    <ng-template side-navigation-nav>
      <label class="report-form-label">{{'USERGROUP.SEARCH' | translate}}</label>
      <armon-search-text-input [(ngModel)]="filter.filter" [maxLength]="20" [minLength]="3"
        (ngModelChange)="filterChanged($event)" placeholder="COMMON.SEARCH"></armon-search-text-input>
    </ng-template>
    <ng-template side-navigation-content>
      <div class="row">
        <div class="col-12 my-3">
          <button class="btn btn-sm btn-primary" (click)="onAddUserGroupButtonClicked()"
            *ngIf="permissionAddUserGroup">{{'USERGROUP.ADD' | translate}}</button>
        </div>
      </div>
      <ng-container *ngIf="userGroups && userGroups.length>0">
        <div class="row" [@listAnimationFast]="userGroups.length">
          <!-- List of user groups -->
          <div class="col-xxxl-4 col-lg-6 col-md-12" *ngFor="let userGroup of userGroups">
            <armon-user-group-card [userGroup]="userGroup" (userGroupDeleted)="onUserGroupDeleted($event)">
            </armon-user-group-card>
          </div>
        </div>
      </ng-container>
      <div class="row pt-2 pb-2" *ngIf="userGroups && userGroups.length==0">
        <div class="col-12">
          <nz-empty [nzNotFoundContent]="contentTpl" [nzNotFoundImage]="'./assets/images/empty/empty_list.png'">
            <ng-template #contentTpl>
              <span>{{'USERGROUP.FILTER_NO_ITEMS'|translate}}</span>
            </ng-template>
          </nz-empty>
        </div>
      </div>
      <div class="row my-2" *ngIf="userGroups && userGroups.length>0">
        <div class="col-12">
          <armon-pagination [paginationResponse]="paginationResponse" (pageChanged)="pageChanged($event)">
          </armon-pagination>
        </div>
      </div>
    </ng-template>
  </side-navigation>
</div>`;var Y="";var ee=`<ng-container>
  <div class="modal-header">
    <span class="text-lg" *ngIf="currentUserGroup.id">{{currentUserGroup.name}}</span>
    <span class="text-lg" *ngIf="!currentUserGroup.id">{{'USERGROUP.TITLE_NEW_USER_GROUP' | translate}}</span>
  </div>
  <div class="modal-body">
    <form [formGroup]="userGroupForm">
      <div class="form-group form-layout mb-3">
        <label for="name-input">{{'USERGROUP.NAME' | translate}}</label>
        <input type="text" id="name-input" formControlName="name" maxlength="255" class="form-control form-control-sm"
          [ngClass]="{'is-invalid': userGroupForm.get('name').touched && userGroupForm.get('name').invalid}">
        <ng-template
          *ngTemplateOutlet="controlValidationTemplate; context: {$implicit: userGroupForm, control:userGroupForm.get('name')}">
        </ng-template>
      </div>
      <div class="form-group form-layout">
        <label for="hexcode-input" class="w-100">{{'USERGROUP.COLOR' | translate}}</label>
        <nz-color-picker id="hexcode-input" formControlName="hexCode" class="mb-2" nzShowText nzDisabledAlpha="true"
          nzFormat="hex"></nz-color-picker>
      </div>
    </form>
  </div>

  <div class="modal-footer">
    <button class="btn btn-outline-primary" (click)="onCancelClicked($event)">{{'BUTTON.CANCEL' | translate}}</button>
    <button class="btn btn-primary" [disabled]="userGroupForm.invalid" (click)="onSaveClicked($event)">{{'BUTTON.SAVE' |
      translate}}</button>
  </div>
</ng-container>

<!-- FORM FIELD VALIDATION -->
<ng-template #controlValidationTemplate let-form let-control="control">
  <ng-container *ngIf="control.errors">
    <div class="invalid-feedback d-flex flex-column" style="display: initial;">
      <span *ngIf="control.errors.required">{{'VALIDATION.REQUIRED'|translate}}</span>
      <span *ngIf="control.errors.numeric">{{'VALIDATION.POSITIVE_NUMBER'|translate}}</span>
      <span *ngIf="control.errors.max">{{'VALIDATION.MAX_VALUE'|translate:control.errors.max}}</span>
      <span *ngIf="control.errors.maxlength">{{'VALIDATION.MAX_LENGTH'|translate: {
        max:control.errors.maxlength.requiredLength} }}</span>
      <span *ngIf="control.errors.min">{{'VALIDATION.MIN_VALUE'|translate:control.errors.min}}</span>
      <span *ngIf="control.errors.minlength">{{'VALIDATION.MIN_LENGTH'|translate: {
        min:control.errors.minlength.requiredLength} }}</span>
    </div>
  </ng-container>
</ng-template>`;var te=`.justify-content-center{-webkit-box-pack:center;-moz-box-pack:center;-webkit-flex-pack:center;-ms-flex-pack:center;-moz-justify-content:center;-webkit-justify-content:center;justify-content:center}.justify-content-flex-end{-webkit-box-pack:end;-moz-box-pack:end;-webkit-flex-pack:end;-ms-flex-pack:end;-moz-justify-content:flex-end;-webkit-justify-content:flex-end;justify-content:flex-end}.card-footer{padding:.28rem .7rem}.alert{font-size:.756rem}@media screen and (min-width: 992px){.modal-xxl{max-width:1640px}}@media screen and (min-width: 1200px){.modal-xxxl{max-width:1860px}}.modal-fs{max-width:none;position:absolute;margin:auto;inset:16px;height:100vh;display:flex}.btn-link{text-decoration:none}.btn-link:hover{text-decoration:underline}.invalid-feedback{margin-top:0!important;font-size:.672rem!important}
`;var ue=function(s,e,t,o){var n=arguments.length,r=n<3?e:o===null?o=Object.getOwnPropertyDescriptor(e,t):o,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(s,e,t,o);else for(var a=s.length-1;a>=0;a--)(i=s[a])&&(r=(n<3?i(r):n>3?i(e,t,r):i(e,t))||r);return n>3&&r&&Object.defineProperty(e,t,r),r},d=class extends z{userGroupService;formBuilder;sessionService;userGroup=void 0;currentUserGroup;userGroupForm;constructor(e,t,o){super(),this.userGroupService=e,this.formBuilder=t,this.sessionService=o}onModalInitialized(){super.onModalInitialized(),this.initializeForms(),this.setUserGroupData(this.userGroup)}onSaveClicked(e){this.currentUserGroup.id?this.updateUserGroup():this.addUserGroup()}initializeForms(){this.userGroupForm=this.formBuilder.group({name:[null,U.required],hexCode:[null,U.required]})}setUserGroupData(e){this.currentUserGroup=e,this.currentUserGroup||(this.currentUserGroup=new P,this.currentUserGroup.hexCode=R()),this.currentUserGroup&&this.userGroupForm.patchValue(this.currentUserGroup)}updateUserGroup(){let e=new f;e.name=this.userGroupForm.value.name,e.hexCode=this.userGroupForm.value.hexCode,e.id=this.currentUserGroup.id,this.userGroupService.updateUserGroup(f.getRequestModel(e)).subscribe(t=>{this.closeModal(t)})}addUserGroup(){let e=new f;e.name=this.userGroupForm.value.name,e.hexCode=this.userGroupForm.value.hexCode,this.userGroupService.addUserGroup(f.getRequestModel(e)).subscribe(t=>{this.closeModal(t)})}static ctorParameters=()=>[{type:m},{type:E},{type:I}];static propDecorators={userGroup:[{type:h}]}};d=ue([l({selector:"armon-user-group-modal",template:ee,standalone:!0,imports:[p,v,_,k,C,u,J],styles:[te]})],d);var re=`<div class="card mb-3">

  <div class="card-body">

    <div class="group-container">
      <div class="group-icon" [ngStyle]="{'background-color': userGroup.hexCode}">
        <cds-icon shape="users" size="md" [ngStyle]="{'color': invertColor(userGroup.hexCode,true)}"></cds-icon>
      </div>
      <div class="group-title"><span>{{userGroup.name}}</span></div>
    </div>

  </div>

  <div class="card-footer" *ngIf="visibleButtons.length > 0">

    <button class="btn btn-sm btn-link" *ngFor="let button of visibleButtons"
      (click)="onFooterButtonClicked($event, button.event)">{{button.text | translate :
      languageService.userTranslate}}</button>
    <button nz-dropdown [nzDropdownMenu]="menuSub" class="btn btn-link btn-sm me-2" *ngIf="hiddenButtons.length > 0"
      [nzClickHide]="true">
      <cds-icon shape="ellipsis-horizontal"></cds-icon>
    </button>
    <nz-dropdown-menu #menuSub="nzDropdownMenu">
      <ul nz-menu>
        <li nz-menu-item *ngFor="let button of hiddenButtons" (click)="onFooterButtonClicked($event, button.event)">
          {{button.text | translate : languageService.userTranslate}}</li>
      </ul>
    </nz-dropdown-menu>
  </div>
</div>`;var oe=`.justify-content-center{-webkit-box-pack:center;-moz-box-pack:center;-webkit-flex-pack:center;-ms-flex-pack:center;-moz-justify-content:center;-webkit-justify-content:center;justify-content:center}.justify-content-flex-end{-webkit-box-pack:end;-moz-box-pack:end;-webkit-flex-pack:end;-ms-flex-pack:end;-moz-justify-content:flex-end;-webkit-justify-content:flex-end;justify-content:flex-end}.card-footer{padding:.28rem .7rem}.alert{font-size:.756rem}@media screen and (min-width: 992px){.modal-xxl{max-width:1640px}}@media screen and (min-width: 1200px){.modal-xxxl{max-width:1860px}}.modal-fs{max-width:none;position:absolute;margin:auto;inset:16px;height:100vh;display:flex}.btn-link{text-decoration:none}.btn-link:hover{text-decoration:underline}.invalid-feedback{margin-top:0!important;font-size:.672rem!important}:host .group-container{display:-webkit-box;display:-moz-box;display:-webkit-flexbox;display:-ms-flexbox;display:-webkit-flex;display:flex;-webkit-box-orient:horizontal;-moz-box-orient:horizontal;-webkit-flex-direction:row;-moz-flex-direction:row;-ms-flex-direction:row;flex-direction:row}:host .group-container .group-icon{margin:6px 12px 6px 0;width:36px;min-width:36px;height:36px;min-height:36px;display:-webkit-box;display:-moz-box;display:-webkit-flexbox;display:-ms-flexbox;display:-webkit-flex;display:flex;-webkit-box-orient:vertical;-moz-box-orient:vertical;-webkit-flex-direction:column;-moz-flex-direction:column;-ms-flex-direction:column;flex-direction:column;-webkit-box-pack:center;-moz-box-pack:center;-webkit-flex-pack:center;-ms-flex-pack:center;-moz-justify-content:center;-webkit-justify-content:center;justify-content:center;-webkit-box-align:center;-ms-flex-align:center;-webkit-align-items:center;-moz-align-items:center;align-items:center;-webkit-border-radius:.375rem;-moz-border-radius:.375rem;border-radius:.375rem}:host .group-container .group-title{font-size:.75rem;line-height:.85rem;display:-webkit-box;display:-moz-box;display:-webkit-flexbox;display:-ms-flexbox;display:-webkit-flex;display:flex;-webkit-box-orient:vertical;-moz-box-orient:vertical;-webkit-flex-direction:column;-moz-flex-direction:column;-ms-flex-direction:column;flex-direction:column;-webkit-box-pack:center;-moz-box-pack:center;-webkit-flex-pack:center;-ms-flex-pack:center;-moz-justify-content:center;-webkit-justify-content:center;justify-content:center}
`;var de=function(s,e,t,o){var n=arguments.length,r=n<3?e:o===null?o=Object.getOwnPropertyDescriptor(e,t):o,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(s,e,t,o);else for(var a=s.length-1;a>=0;a--)(i=s[a])&&(r=(n<3?i(r):n>3?i(e,t,r):i(e,t))||r);return n>3&&r&&Object.defineProperty(e,t,r),r},G=class extends Q{interactionService;userGroupService;identitySelectionService;languageService;modalService;authService;userGroup;userGroupDeleted=new S;constructor(e,t,o,n,r,i){super(i),this.interactionService=e,this.userGroupService=t,this.identitySelectionService=o,this.languageService=n,this.modalService=r,this.authService=i}ngOnInit(){this.initializeButtons()}initializeButtons(){this.addButton("BUTTON.USERS",this.onShowUsersButtonClicked,c.USERGROUP.getWrite()),this.addButton("BUTTON.EDIT",this.onEditButtonClicked,c.USERGROUP.getWrite()),this.addButton("BUTTON.DELETE",this.onDeleteButtonClicked,c.USERGROUP.getWrite())}listUsersOfUserGroup(e){return this.userGroupService.listUsers(this.userGroup.id,e)}onShowUsersButtonClicked(){this.modalService.open(X,{settings:{size:"xl"},props:{editable:!0,sessionFunction:this.getSessionIdForUserGroup.bind(this)}}).result.then(e=>{}).catch(e=>{})}onEditButtonClicked(){this.modalService.open(d,{settings:{size:"md"},props:{userGroup:this.userGroup}}).result.then(e=>{this.userGroup&&this.userGroup.id===e.id&&(this.userGroup=e)}).catch(e=>{})}invertColor(e,t=!1){if(e.indexOf("#")===0&&(e=e.slice(1)),e.length===3&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),e.length!==6)throw new Error("Invalid HEX color.");var o=parseInt(e.slice(0,2),16),n=parseInt(e.slice(2,4),16),r=parseInt(e.slice(4,6),16);if(t)return o*.299+n*.587+r*.114>186?"#000000":"#FFFFFF";let i=(255-o).toString(16),a=(255-n).toString(16),ie=(255-r).toString(16);return"#"+this.padZero(i)+this.padZero(a)+this.padZero(ie)}padZero(e,t=2){var o=new Array(t).join("0");return(o+e).slice(-t)}onDeleteButtonClicked(){this.interactionService.showDialog(this.userGroup.name,"USERGROUP.APPROVE_FOR_DELETE",null,null,!0,"BUTTON.DELETE","",!0,()=>{this.userGroupService.removeUserGroup(this.userGroup.id).subscribe(()=>{this.userGroupDeleted.emit(this.userGroup.id)})})}getSessionIdForUserGroup(e){return this.identitySelectionService.getSessionForUserGroup(this.userGroup.id,e)}static ctorParameters=()=>[{type:N},{type:m},{type:W},{type:O},{type:b},{type:x}];static propDecorators={userGroup:[{type:h}],userGroupDeleted:[{type:y}]}};G=de([l({selector:"armon-user-group-card",template:re,standalone:!0,imports:[w,p,g,T,M,F,u],styles:[oe]})],G);var fe=function(s,e,t,o){var n=arguments.length,r=n<3?e:o===null?o=Object.getOwnPropertyDescriptor(e,t):o,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(s,e,t,o);else for(var a=s.length-1;a>=0;a--)(i=s[a])&&(r=(n<3?i(r):n>3?i(e,t,r):i(e,t))||r);return n>3&&r&&Object.defineProperty(e,t,r),r},ne=class{userGroupService;authService;modalService;userGroups=[];permissionAddUserGroup;filter;paginationResponse=new A;paginationRequest=new D;constructor(e,t,o){this.userGroupService=e,this.authService=t,this.modalService=o}ngOnInit(){this.filter=j.getEmptyModel(),this.checkPermissions(),this.getUserGroups()}filterChanged(e){this.filter.pagination.skip=0,this.getUserGroups()}onAddUserGroupButtonClicked(){this.modalService.open(d,{settings:{size:"md"}}).result.then(e=>{this.getUserGroups()}).catch(e=>{})}onUserGroupDeleted(e){this.getUserGroups()}getUserGroups(){this.userGroupService.listUserGroups(this.filter).subscribe(e=>{this.userGroups=e.items,this.paginationResponse=e.pagination})}checkPermissions(){this.permissionAddUserGroup=this.authService.checkPermission(c.USERGROUP.getWrite())}pageChanged(e){this.filter.pagination=e,this.getUserGroups()}static ctorParameters=()=>[{type:m},{type:x},{type:b}]};ne=fe([l({selector:"armon-manage-user-groups",template:K,animations:V,standalone:!0,imports:[H,q,Z,v,$,p,g,G,B,L,u],styles:[Y]})],ne);export{ne as ManageUserGroupsComponent};
