import{Fb as _,k as R,nb as k,wb as M}from"./chunk-YSQLW2JA.js";import{ud as f}from"./chunk-NVJ2ZZFT.js";import{Aa as h,Dc as s,Nc as m,Pd as x,Qf as T,Sd as y,Te as D,Ve as E,Wb as o,Ye as C,_a as u,ab as b,af as w,bb as g,dc as I,dd as v,mg as S,wa as c,ya as p}from"./chunk-SKPDQO4E.js";var O=`<div class="modal-header">
  <span class="text-lg" *ngIf="!isEditMode">{{'FORBIDDEN_IDENTITY.ADD_RECORD' | translate}}</span>
  <span class="text-lg" *ngIf="isEditMode">{{'FORBIDDEN_IDENTITY.EDIT_RECORD' | translate}}</span>
</div>
<div class="modal-body">
  <div class="row">
    <div class="col-12" *ngIf="!isEditMode">
      <div class="form-group">
        <label class="required">{{'IDENTITY.TITLE' | translate : languageService.userTranslate}}</label>
        <armon-select-search query="identity" [(ngModel)]="userId" (ngModelChange)="onSelectedUserChanged($event)"
          [ngClass]="{'disabledElement': disableIdentitySelection}">
        </armon-select-search>
        <span class="text-xxs" *ngIf="!isEditMode && !disableIdentitySelection"><cds-icon shape="info-standard"
            class="me-1"></cds-icon>{{'FORBIDDEN_IDENTITY.FILTER_INFO'|translate}}</span>
      </div>
    </div>
    <div class="col-12 mb-2" *ngIf="isEditMode && record.user">
      <span class="py-2 text-md"><strong>{{record.user.fullname}}</strong></span>
    </div>
    <div class="col-12">
      <div class="form-group">
        <label class="required">{{'FORBIDDEN_IDENTITY.RECORD_START_DATE' | translate}}</label>
        <input [(ngModel)]="record.startUtc" type="text" class="form-control form-control-sm bg-white" readonly owlinput
          (ngModelChange)="onStartDateChanged($event)" [owlDateTime]="dt1" [owlDateTimeTrigger]="dt1"
          [min]="startOfDay">
        <owl-date-time [firstDayOfWeek]="1" #dt1 [pickerType]="'calendar'"></owl-date-time>
      </div>
    </div>
    <div class="col-12">
      <div class="form-group">
        <label class="required">{{'FORBIDDEN_IDENTITY.RECORD_END_DATE' | translate}}</label>
        <input [(ngModel)]="record.endUtc" type="text" class="form-control form-control-sm bg-white" readonly owlinput
          (ngModelChange)="onEndDateChanged($event)" [owlDateTime]="dt2" [owlDateTimeTrigger]="dt2"
          [min]="record.startUtc">
        <owl-date-time [firstDayOfWeek]="1" #dt2 [pickerType]="'calendar'"></owl-date-time>
      </div>
    </div>
    <div class="col-12">
      <div class="form-group">
        <label>{{'REPORT.REGION' | translate}}</label>
        <armon-select-search query="region" [(ngModel)]="regionId" (ngModelChange)="onSelectedRegionChanged($event)">
        </armon-select-search>
      </div>
    </div>
    <div class="col-12">
      <div class="form-group">
        <label for="noteInput">{{'FORBIDDEN_IDENTITY.RECORD_NOTE' | translate}}</label>
        <textarea name="note" id="noteTextArea" [(ngModel)]="record.note" rows="2" cols="20" maxlength="256"
          class="form-control form-control-sm" style="resize:none"></textarea>
      </div>
    </div>
    <div class="col-12" *ngIf="credentials && credentials.length > 0">
      <label>{{'FORBIDDEN_IDENTITY.CRENDENTIALS' | translate}}</label>
      <div class="d-flex">
        <nz-switch [(ngModel)]="forAllCredentials" (ngModelChange)="onForAllCredentialsChanged($event)" nzSize="small">
        </nz-switch>
        <label class="report-form-label ms-1">{{'FORBIDDEN_IDENTITY.ALL_CRENDENTIALS_APPLY' | translate}}</label>
      </div>
      <div class="credential-selection">
        <ng-container *ngFor="let credential of credentials">
          <div class="credential-container" [ngClass]="{'passive': forAllCredentials}">
            <div class="sub-container">
              <input type="checkbox" clrCheckbox [(ngModel)]="credential.added"
                (ngModelChange)="onCredentialSelectionChanged($event)" />
            </div>
            <div class="sub-container">
              <cds-icon [attr.shape]="credential.credentialType.icon" style="width: 28px; height: 28px;"></cds-icon>
            </div>
            <div class="info-container">
              <span class="description">{{credential.credentialType.description | translate}}</span>
              <span *ngIf="credential.dataText">{{credential.dataText|translate}}<span
                  *ngIf="credential.decData">&nbsp;({{credential.decData}})</span></span>
            </div>
          </div>
        </ng-container>
      </div>
    </div>
  </div>
</div>
<div class="modal-footer">
  <button class="btn btn-outline-primary" (click)="onCancelClicked($event)">{{'BUTTON.CLOSE' | translate}}</button>
  <button class="btn btn-primary me-0" (click)="onSaveClicked($event)" [disabled]="disableSaveButton">{{'BUTTON.SAVE'
    | translate}}
  </button>
</div>`;var N=`.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 .credential-selection{overflow-x:auto;max-height:180px;height:auto}:host .credential-container{display:-webkit-box;display:-moz-box;display:-webkit-flexbox;display:-ms-flexbox;display:-webkit-flex;display:flex;-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;margin:3px 0;background-color:#f5f6f8;border:1px solid #ced4de}:host .credential-container.passive{opacity:.3;pointer-events:none}:host .credential-container .sub-container{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-align:center;-ms-flex-align:center;-webkit-align-items:center;-moz-align-items:center;align-items: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;padding:6px}:host .credential-container .sub-container cds-icon{color:#aaa}:host .credential-container .info-container{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;font-size:.588rem}:host .credential-container .info-container .description{font-size:.714rem}
`;var U=function(a,e,t,n){var r=arguments.length,i=r<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,d;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(a,e,t,n);else for(var l=a.length-1;l>=0;l--)(d=a[l])&&(i=(r<3?d(i):r>3?d(e,t,i):d(e,t))||i);return r>3&&i&&Object.defineProperty(e,t,i),i},z=class extends y{sessionService;identityService;interactionService;languageService;searchIdentity;searchRegion;record;userId;regionId;isEditMode=!1;startOfDay;disableSaveButton=!0;disableIdentitySelection=!1;forAllCredentials=!0;credentials;constructor(e,t,n,r){super(),this.sessionService=e,this.identityService=t,this.interactionService=n,this.languageService=r}onModalInitialized(){super.onModalInitialized(),this.startOfDay=s.local().startOf("day").toJSDate(),o(this.record)||(o(this.record.userId)||(this.userId=this.record.userId),o(this.record.user?.id)||(this.userId=this.record.user.id),o(this.record.regionId)||(this.regionId=this.record.regionId),this.record=I(this.record)),this.record.id&&this.record.id!=""?(this.isEditMode=!0,this.getIdentityDetails(this.userId)):this.isEditMode=!1,this.onModelChanged()}onModalViewInitialized(){super.onModalViewInitialized(),this.record.userId&&(this.disableIdentitySelection=!0)}upsertRecord(){this.record.regionId=this.regionId,this.forAllCredentials?this.record.credentialIds=null:(this.record.credentialIds=[],this.credentials.forEach(e=>{e.added&&this.record.credentialIds.push(e.id)}),this.record.credentialIds.length==0&&(this.record.credentialIds=null)),this.isEditMode?this.identityService.updateForbiddenRecord(this.record.id,f.getRequestModel(this.record)).subscribe(e=>{this.interactionService.showMessage("FORBIDDEN_IDENTITY.RECORD_EDIT_SUCCEED",null,m.Success),this.afterUpsertRecord(e)}):this.identityService.addForbiddenRecord(this.userId,f.getRequestModel(this.record)).subscribe(e=>{this.interactionService.showMessage("FORBIDDEN_IDENTITY.RECORD_ADD_SUCCEED",null,m.Success),this.afterUpsertRecord(e)})}afterUpsertRecord(e){this.closeModal(e)}validateForm(){let e=!1;(!this.userId||this.userId=="")&&(e=!0),this.disableSaveButton=e}onModelChanged(e){this.validateForm()}getIdentityDetails(e){this.identityService.getIdentityDetailedById(e).subscribe(t=>{this.credentials=t.credentials,(this.isEditMode||this.disableIdentitySelection)&&(!this.record.credentialIds||this.record.credentialIds.length==0?this.forAllCredentials=!0:(this.forAllCredentials=!1,this.record.credentialIds.forEach(n=>{let r=this.credentials.find(i=>i.id==n);r&&(r.added=!0)})))})}onSelectedUserChanged(e){o(this.userId)?this.credentials=null:this.getIdentityDetails(this.userId),this.validateForm()}onSelectedRegionChanged(e){this.validateForm()}onStartDateChanged(e){s.fromJSDate(this.record.startUtc)>=s.fromJSDate(this.record.endUtc)&&(this.record.endUtc=s.fromJSDate(this.record.startUtc).plus({days:30}).endOf("day").toJSDate())}onEndDateChanged(e){}onSaveClicked(e){this.disableSaveButton==!1&&this.upsertRecord()}onForAllCredentialsChanged(e){}onCredentialSelectionChanged(e){this.credentials.findIndex(t=>t.added==!0)==-1&&(this.forAllCredentials=!0)}static ctorParameters=()=>[{type:x},{type:k},{type:T},{type:w}];static propDecorators={searchIdentity:[{type:c,args:["searchIdentity"]}],searchRegion:[{type:c,args:["searchRegion"]}],record:[{type:h}]}};z=U([p({selector:"armon-forbidden-identity-record-upsert",template:O,standalone:!0,providers:[{provide:E,useClass:R}],imports:[g,u,D,C,S,_,b,v,M],styles:[N]})],z);export{z as a};
