import{a as X}from"./chunk-I5K7GPAI.js";import{a as Y}from"./chunk-D4RZOGGF.js";import{a as Q,b as J,c as K}from"./chunk-UZB7YFT6.js";import{a as $,b as H}from"./chunk-WQ6DP4JQ.js";import{B as P,H as h,I as U,Ob as R,s as k,v as W,y as B}from"./chunk-YSQLW2JA.js";import{Lc as q,Mc as V,Nc as Z}from"./chunk-NVJ2ZZFT.js";import{Aa as d,He as E,Me as A,Nc as g,Ne as F,Pd as f,Qf as N,Rd as _,Sd as v,Te as S,Ue as w,_a as T,ab as m,bb as p,bc as D,bh as G,cd as L,dc as M,dd as c,eh as j,hd as u,id as O,jd as b,ya as a}from"./chunk-SKPDQO4E.js";var ee=`<div class="row justify-content-center">
  <div class="col-xl-8 col-lg-12 col-md-12">
    <div class="row">
      <div class="col-12 my-2">
        <button class="btn btn-sm btn-primary" (click)="onAddRoleButtonClicked()" *ngIf="permissionAddRole">{{'ROLE.ADD' | translate}}</button>
      </div>
    </div>
    <!-- Listing area -->
    <div class="row my-2" [@listAnimation]="roleList.length">
      <!-- List of roles -->
      <div class="col-xl-6 col-lg-6 col-md-6 col-sm-12" *ngFor="let role of roleList">
        <armon-role-card [roleItem]="role"></armon-role-card>
      </div>
    </div>
  </div>
</div>`;var te="";var oe=`<div class="modal-header">
  <span class="text-lg">{{'ROLE.TITLE_DEFINITION' | translate}}</span>
</div>

<div class="modal-body">

  <div class="alert alert-warning" role="alert" *ngIf="isPredefinedRole">
    {{'ROLE.NO_EDIT_FOR_READONLY' | translate}}
  </div>

  <form class="form" [formGroup]="roleForm">
    <div class="form-group row">
      <div class="col-md-4 col-sm-12">
        <label for="roleName" class="required">{{'ROLE.NAME' | translate}}</label>
      </div>
      <div class="col-md-8 col-sm-12">
        <!-- <label for="roleName" aria-haspopup="true" role="tooltip" class="w-100 tooltip tooltip-validation tooltip-sm tooltip-bottom-left"
            [class.invalid]="isFormFieldInvalid('name')"> -->
        <div class="input-group">
          <input id="roleName" type="text" formControlName="name" class="form-control form-control-sm"
            [ngClass]="{'is-invalid': isFormFieldInvalid('name')}">
          <div class="invalid-feedback" *ngIf="roleForm.get('name').errors && roleForm.get('name').errors.required">
            {{'VALIDATION.REQUIRED' | translate}}
          </div>
          <div class="invalid-feedback" *ngIf="roleForm.get('name').errors && roleForm.get('name').errors.minlength">
            <span [translate]="'VALIDATION.MIN_LENGTH'" [translateParams]="{min: 3}"></span>
          </div>
        </div>
        <!-- </label> -->
      </div>
    </div>

    <div class="form-group row">
      <div class="col-md-4 col-sm-12">
        <label for="roleOrganizationWide" class="required">{{'ROLE.IS_ORGANIZATION_WIDE' | translate}}</label>
      </div>
      <div class="col-md-8 col-sm-12">
        <div class="toggle-switch">
          <input type="checkbox" id="roleOrganizationWide" formControlName="isOrganizationWide"
            (change)="onOrganizationWideSelectionChanged($event)">
          <label for="roleOrganizationWide"></label>
        </div>
      </div>
    </div>
  </form>

  <div class="mxh-vh-50 overflow-y-auto px-1">

    <ng-container *ngFor="let permission of permissions">
      <div (click)="onChangePermissionSelection(permission)" class="d-flex permission-item mb-3"
        [ngClass]="{'selected': isSelected(permission.code), 'notSelectable': isNotAvailable(permission.type) || hasNotPermission(permission.code) || isPredefinedPermission(permission.code)}">
        <div class="d-flex flex-column py-2 px-2">
          <cds-icon shape="success-standard" solid class="color-success mt-1" *ngIf="isSelected(permission.code)">
          </cds-icon>
          <cds-icon shape="success-standard" solid class="color-gray mt-1" *ngIf="!isSelected(permission.code)">
          </cds-icon>
          <!-- <cds-icon shape="error-standard" solid class="color-error mt-auto" *ngIf="(isNotAvailable(permission.type) || hasNotPermission(permission.code) || isPredefinedPermission(permission.code))"></cds-icon> -->
        </div>
        <div class="d-flex flex-column flex-grow-1 py-2 px-3 b-l-1">
          <span class="text-md">{{permission.name | translate}}</span>
          <span class="text-sm text-black-50">{{permission.info | translate}}</span>

          <span class="text-xs color-error mt-2"
            *ngIf="isPredefinedPermission(permission.code)">{{'ROLE.NO_EDIT_FOR_PREDEFINED_PERMISSION' |
            translate}}</span>
          <span class="text-xs color-error mt-2"
            *ngIf="isNotAvailable(permission.type)">{{'ROLE.NO_EDIT_FOR_ORGANIZATION_WIDE' | translate}}</span>
          <span class="text-xs color-error mt-2"
            *ngIf="hasNotPermission(permission.code)">{{'ROLE.NO_EDIT_FOR_HAS_NOT_PERMISSION' | translate}}</span>
        </div>
      </div>
    </ng-container>

  </div>

</div>

<div class="modal-footer">
  <button class="btn btn-outline-primary" (click)="onCancelClicked($event)">{{'BUTTON.CANCEL' | translate}}</button>
  <button class="btn btn-success" (click)="onSaveClicked($event)" [disabled]="roleForm.invalid">{{'BUTTON.SAVE' |
    translate}}</button>
</div>`;var ie=`.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}.permission-item{border:1px solid rgb(235,235,235);-webkit-border-radius:.375rem;-moz-border-radius:.375rem;border-radius:.375rem;cursor:pointer}.permission-item:hover{background-color:#e7f1de!important;border-color:#91bf66!important}.selected{border-color:#c0daa8!important;background-color:#f7faf4!important}.selected:hover{background-color:#e7f1de!important;border-color:#91bf66!important}.notSelectable{cursor:not-allowed!important;pointer-events:none}
`;var z=[O.Organization,O.System,O.Role];var ve=function(s,e,t,i){var r=arguments.length,o=r<3?e:i===null?i=Object.getOwnPropertyDescriptor(e,t):i,n;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(s,e,t,i);else for(var l=s.length-1;l>=0;l--)(n=s[l])&&(o=(r<3?n(o):r>3?n(e,t,o):n(e,t))||o);return r>3&&o&&Object.defineProperty(e,t,o),o},I=class extends v{translate;authService;roleService;dynamicFormService;interactionService;sessionService;role=void 0;roleForm=new A({name:new F("",[E.required,E.minLength(3)]),isOrganizationWide:new F("",E.required)});currentRoleId;currentRolePermissions=[];currentTypeRoleId;currentRolePredefinedPermissions=[];FORM_FIELD_ORGANIZATIONWIDE="isOrganizationWide";FORM_FIELD_NAME="name";constructor(e,t,i,r,o,n){super(),this.translate=e,this.authService=t,this.roleService=i,this.dynamicFormService=r,this.interactionService=o,this.sessionService=n}get permissions(){return b.filter(e=>e.code!==u.USER.getUser()&&(e.specific==null||e.specific==!1))}get isOrganizationWide(){return this.roleForm&&this.roleForm.get(this.FORM_FIELD_ORGANIZATIONWIDE).value}get isPredefinedRole(){return this.currentTypeRoleId!==null}onModalInitialized(){super.onModalInitialized(),this.setRoleData(this.role)}isFormFieldInvalid(e){return D(this.roleForm,e)}isSelected(e){return this.currentRolePermissions.indexOf(e)>=0}isNotAvailable(e){return!this.isOrganizationWide&&z.indexOf(e)>=0}isPredefinedPermission(e){return this.currentRolePredefinedPermissions.indexOf(e)>=0}hasNotPermission(e){return!this.authService.isPermittedForOrganization(e)&&!this.authService.isPermittedForAnyUnitInOrganization(e)}onChangePermissionSelection(e){if(this.isNotAvailable(e.type)||this.hasNotPermission(e.code)||this.isPredefinedPermission(e.code))return;let t=this.currentRolePermissions.indexOf(e.code);t>=0?this.currentRolePermissions.splice(t,1):this.currentRolePermissions.push(e.code)}onOrganizationWideSelectionChanged(e){this.isOrganizationWide||b.filter(i=>z.indexOf(i.type)>=0).forEach(i=>{let r=this.currentRolePermissions.indexOf(i.code);r>=0&&this.currentRolePermissions.splice(r,1)})}onSaveClicked(e){this.currentTypeRoleId?this.updateTypedRole():this.currentRoleId?this.updateRole():this.addRole()}addRole(){let e=new q;e.name=this.roleForm.get(this.FORM_FIELD_NAME).value,e.isOrganizationWide=this.roleForm.get(this.FORM_FIELD_ORGANIZATIONWIDE).value,e.permissions=this.currentRolePermissions,this.processSaveResponse(this.roleService.addRole(e),!0)}updateRole(){let e=new V;e.name=this.roleForm.get(this.FORM_FIELD_NAME).value,e.permissions=this.currentRolePermissions,this.processSaveResponse(this.roleService.updateRole(this.currentRoleId,e),!1)}updateTypedRole(){let e=new Z;e.permissions=this.currentRolePermissions,this.processSaveResponse(this.roleService.updateTypedRole(this.currentRoleId,e),!1)}processSaveResponse(e,t){e.subscribe(i=>{this.interactionService.showMessage(t?"ROLE.INSERT_SUCCEED":"ROLE.UPDATE_SUCCEED",null,g.Success),this.closeModal(i)})}setRoleData(e){this.currentRoleId=e?e.id:null,this.currentTypeRoleId=e&&e.typeId||null,this.currentRolePermissions=e?e.permissions||[]:[],this.currentRolePredefinedPermissions=e?e.minPermissions||[]:[],e&&this.translate.get(e.name).subscribe(t=>{this.roleForm.get(this.FORM_FIELD_NAME).setValue(t)}),this.roleForm.get(this.FORM_FIELD_ORGANIZATIONWIDE).setValue(e?e.isOrganizationWide:!1),this.currentTypeRoleId?this.roleForm.disable():this.currentRoleId?(this.roleForm.enable(),this.roleForm.get(this.FORM_FIELD_ORGANIZATIONWIDE).disable()):(this.roleForm.enable(),this.roleForm.get(this.FORM_FIELD_ORGANIZATIONWIDE).enable())}static ctorParameters=()=>[{type:L},{type:R},{type:h},{type:U},{type:N},{type:f}];static propDecorators={role:[{type:d}]}};I=ve([a({selector:"armon-role-modal",template:oe,standalone:!0,imports:[p,S,w,T,c,m],styles:[ie]})],I);var re=`<div class="card mb-3">

  <div class="card-body mhs-10">

    <!-- Name of role -->
    <span class="text-base fw-medium color-gray-dark">{{roleItem.name | translate}}</span>
    <div class="mt-4 d-flex column-gap-1">
      <armon-icon-label *ngIf="roleItem.typeId" [colorCode]="3">
        <ng-template icon-label-icon>
          <cds-icon shape="bundle"></cds-icon>
        </ng-template>
        <ng-template icon-label-content><span>{{'PACS.PPERMISSION_TYPE_PREDEFINED'|translate}}</span></ng-template>
      </armon-icon-label>
      <armon-icon-label *ngIf="roleItem.isOrganizationWide" [colorCode]="2">
        <ng-template icon-label-icon>
          <cds-icon shape="organization"></cds-icon>
        </ng-template>
        <ng-template icon-label-content><span>Organizasyon Geneli</span></ng-template>
      </armon-icon-label>
    </div>
  </div>

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

    <button class="btn btn-sm btn-link" *ngFor="let button of visibleButtons"
      (click)="onFooterButtonClicked($event, button.event)">{{button.text | translate}}</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}}</li>
      </ul>
    </nz-dropdown-menu>

  </div>

</div>`;var ne="";var se=`<div class="modal-header">
  <div class="d-flex flex-column">
    <span class="text-lg">{{roleItem.name | translate}}</span>
    <span class="text-sm" *ngIf="roleItem.isOrganizationWide">{{'ROLE.ORGANIZATION_WIDE_DEFINED' | translate}}</span>
  </div>
</div>

<div class="modal-body mxh-vh-70">
  <div class="d-flex flex-column">
    <ng-container *ngFor="let permission of rolePermissions">
      <span class="text-md"><cds-icon shape="success-standard" solid class="color-success me-2"
          style="width: 12px; height: 12px;"></cds-icon>{{permission.name | translate}}</span>
      <span class="text-sm text-black-50 mb-3 ms-4">{{permission.info | translate}}</span>
    </ng-container>
  </div>

  <nz-empty [nzNotFoundContent]="contentTpl" *ngIf="rolePermissions.length == 0"
    [nzNotFoundImage]="'./assets/images/empty/empty_list.png'">
    <ng-template #contentTpl>
      <span>{{'ROLE.EMPTY_PERMISSION_LIST'|translate}}</span>
    </ng-template>
  </nz-empty>
</div>

<div class="modal-footer">
  <button class="btn btn-outline-primary" (click)="onCancelClicked($event)">{{'BUTTON.CLOSE' | translate}}</button>
</div>`;var le="";var ge=function(s,e,t,i){var r=arguments.length,o=r<3?e:i===null?i=Object.getOwnPropertyDescriptor(e,t):i,n;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(s,e,t,i);else for(var l=s.length-1;l>=0;l--)(n=s[l])&&(o=(r<3?n(o):r>3?n(e,t,o):n(e,t))||o);return r>3&&o&&Object.defineProperty(e,t,o),o},C=class extends v{sessionService;roleItem;constructor(e){super(),this.sessionService=e}get rolePermissions(){return this.roleItem?b.filter(e=>this.roleItem.permissions.indexOf(e.code)>=0):[]}onModalInitialized(){super.onModalInitialized()}static ctorParameters=()=>[{type:f}];static propDecorators={roleItem:[{type:d}]}};C=ge([a({selector:"armon-role-detailed-modal",template:se,standalone:!0,imports:[p,m,G,c],styles:[le]})],C);var ae=`<div class="modal-header">
  <div class="d-flex flex-column">
    <span class="text-lg">{{'ROLE.TITLE_REMOVE' | translate}}</span>
    <span class="text-md">{{roleItem.name | translate}}</span>
  </div>
</div>

<div class="modal-body">

  <div class="row mb-4">
    <div class="col-12">
      <span class="text-md">{{'ROLE.REMOVE_INFO' | translate}}</span>
    </div>
  </div>

  <div class="row">
    <div class="col-12">
      <nz-form-item class="w-100">
        <label>{{'ROLE.NEW' | translate}}</label>
        <nz-select class="w-100" [(ngModel)]="newRoleId" nzSize="small">
          <nz-option *ngFor="let option of roleAvailable" [nzValue]="option.id" [nzLabel]="option.name |
          translate"></nz-option>
        </nz-select>
      </nz-form-item>
    </div>
  </div>
</div>

<div class="modal-footer">
  <button class="btn btn-outline-primary" (click)="onCancelClicked($event)">{{'BUTTON.CANCEL' | translate}}</button>
  <button class="btn btn-danger" (click)="onDeleteClicked($event)"
    [disabled]="!newRoleId">{{'BUTTON.DELETE' | translate}}</button>
</div>`;var me="";var Ee=function(s,e,t,i){var r=arguments.length,o=r<3?e:i===null?i=Object.getOwnPropertyDescriptor(e,t):i,n;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(s,e,t,i);else for(var l=s.length-1;l>=0;l--)(n=s[l])&&(o=(r<3?n(o):r>3?n(e,t,o):n(e,t))||o);return r>3&&o&&Object.defineProperty(e,t,o),o},x=class extends v{roleService;interactionService;sessionService;roleItem;newRoleId;constructor(e,t,i){super(),this.roleService=e,this.interactionService=t,this.sessionService=i}get roleAvailable(){return this.roleItem?this.roleService.allRoles.filter(e=>e.isOrganizationWide===this.roleItem.isOrganizationWide&&e.id!==this.roleItem.id&&e.id!==this.roleService.getRoleIdWithType(P.ORGANIZATION_VISITOR)&&e.id!==this.roleService.getRoleIdWithType(P.ORGANIZATIONUNIT_VISITOR)):[]}onModalInitialized(){super.onModalInitialized()}onDeleteClicked(e){this.roleService.removeRole(this.roleItem.id,this.newRoleId).subscribe(()=>{this.interactionService.showMessage("ROLE.DELETE_SUCCEED",null,g.Success),this.closeModal()})}static ctorParameters=()=>[{type:h},{type:N},{type:f}];static propDecorators={roleItem:[{type:d}]}};x=Ee([a({selector:"armon-role-remove-modal",template:ae,standalone:!0,imports:[$,H,j,S,m,c],styles:[me]})],x);var Se=function(s,e,t,i){var r=arguments.length,o=r<3?e:i===null?i=Object.getOwnPropertyDescriptor(e,t):i,n;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(s,e,t,i);else for(var l=s.length-1;l>=0;l--)(n=s[l])&&(o=(r<3?n(o):r>3?n(e,t,o):n(e,t))||o);return r>3&&o&&Object.defineProperty(e,t,o),o},y=class extends X{modalService;authService;roleItem;constructor(e,t){super(t),this.modalService=e,this.authService=t}ngOnInit(){this.initializeButtons()}initializeButtons(){this.addButton("BUTTON.DETAILS",this.onShowDetailsButtonClicked),this.addButton("BUTTON.EDIT",this.onEditButtonClicked,u.ROLE.getWrite()),this.roleItem.typeId||this.addButton("BUTTON.DELETE",this.onDeleteButtonClicked,u.ROLE.getWrite())}onShowDetailsButtonClicked(){this.modalService.open(C,{settings:{size:"lg",scrollable:!0},props:{roleItem:this.roleItem}}).result.then(e=>{}).catch(e=>{})}onEditButtonClicked(){this.modalService.open(I,{settings:{size:"lg",scrollable:!0},props:{role:M(this.roleItem)}}).result.then(e=>{}).catch(e=>{})}onDeleteButtonClicked(){this.modalService.open(x,{settings:{size:"md",scrollable:!0},props:{roleItem:this.roleItem}}).result.then(e=>{}).catch(e=>{})}static ctorParameters=()=>[{type:_},{type:R}];static propDecorators={roleItem:[{type:d}]}};y=Se([a({selector:"armon-role-card",template:re,standalone:!0,imports:[p,K,Q,J,m,B,W,k,c],styles:[ne]})],y);var Ne=function(s,e,t,i){var r=arguments.length,o=r<3?e:i===null?i=Object.getOwnPropertyDescriptor(e,t):i,n;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(s,e,t,i);else for(var l=s.length-1;l>=0;l--)(n=s[l])&&(o=(r<3?n(o):r>3?n(e,t,o):n(e,t))||o);return r>3&&o&&Object.defineProperty(e,t,o),o},ce=class{roleService;authService;modalService;permissionAddRole;constructor(e,t,i){this.roleService=e,this.authService=t,this.modalService=i}get roleList(){return this.roleService.allRoles}ngOnInit(){this.checkPermissions()}checkPermissions(){this.permissionAddRole=this.authService.checkPermission(u.ROLE.getWrite())}onAddRoleButtonClicked(){this.modalService.open(I,{settings:{size:"lg"}}).result.then(e=>{}).catch(e=>{})}static ctorParameters=()=>[{type:h},{type:R},{type:_}]};ce=Ne([a({selector:"armon-manage-roles",template:ee,animations:Y,standalone:!0,imports:[p,m,y,c],styles:[te]})],ce);export{ce as ManageRolesComponent};
