import{a as I,b as P}from"./chunk-YKYLT6FT.js";import"./chunk-I5K7GPAI.js";import"./chunk-VQU52MNH.js";import"./chunk-MXSLISEG.js";import"./chunk-7GYHTWED.js";import"./chunk-3GSDFESG.js";import"./chunk-7QEXVS2A.js";import"./chunk-HXEFMD5A.js";import"./chunk-KCLQIV7M.js";import"./chunk-5KCUTXXV.js";import"./chunk-JUDWAYYT.js";import"./chunk-LAJI7RPC.js";import"./chunk-WFZJP5WR.js";import"./chunk-F6KLNSUK.js";import"./chunk-CO3X7TQN.js";import"./chunk-VSFNMVXJ.js";import"./chunk-WQ6DP4JQ.js";import{Ob as v,wb as f}from"./chunk-YSQLW2JA.js";import{ee as O}from"./chunk-NVJ2ZZFT.js";import{Rd as p,Te as z,Yg as m,ab as c,bb as g,bh as u,dd as h,hd as U,jc as d,ya as l}from"./chunk-SKPDQO4E.js";var C=`<div class="row justify-content-center">
  <div class="col-xl-8 col-lg-12 col-md-12">
    <!-- Filtering area -->
    <div class="row">
      <div class="col-lg-4 col-md-6 col-12">
        <label class="report-form-label">{{'REPORT.ORGANIZATION_UNITS' | translate}}</label>
        <armon-select-search query="unit" [allowMulti]="false" [enabledAutoClearSearchValue]="false"
          [(ngModel)]="filterOrganizationUnitId" (ngModelChange)="onFilterChanged($event)">
        </armon-select-search>
      </div>
    </div>

    <!-- Selected parent organization unit -->
    <div class="row mt-4" *ngIf="currentParentOrganizationUnit">
      <div class="col-12">
        <armon-organization-unit-basic [organizationUnit]="currentParentOrganizationUnit"
          (organizationUnitUpdated)="onOrganizationUnitUpserted($event)"
          (organizationUsersUpdated)="onOrganizationUnitUpserted($event)"
          (organizationUnitDeleted)="onOrganizationUnitDeleted($event)"></armon-organization-unit-basic>
      </div>
    </div>

    <div class="row mt-5" *ngIf="!currentParentOrganizationUnit">
      <div class="col-12">
        <nz-empty [nzNotFoundContent]="contentTpl" [nzNotFoundImage]="'./assets/images/empty/search_generic.png'">
          <ng-template #contentTpl>
            <span> {{'ORGANIZATIONUNIT.SELECT_UNIT_FROM_FILTER'|translate}}</span>
          </ng-template>
        </nz-empty>
      </div>
    </div>

    <div class="row b-b-1 my-4 py-2" *ngIf="currentParentOrganizationUnit">
      <div class="col-12 d-flex align-items-center">
        <span>
          <cds-icon shape="circle-arrow" direction="left" style="width: 20px; height: 20px;"
            *ngIf="currentParentHistory.length > 0" (click)="onGoBackRequested()" class="me-2 cursor-pointer" nz-tooltip
            nzTooltipTitle="{{'ORGANIZATIONUNIT.PARENT' | translate}}">
          </cds-icon>
          <span class="text-lg">{{'ORGANIZATIONUNIT.CHILDREN' | translate}}</span>
        </span>
        <div class="ms-auto" *ngIf="currentParentOrganizationUnit && permissionAddOrganizationUnit">
          <button class="btn btn-sm btn-primary" (click)="onAddOrganizationUnitButtonClicked()">{{'ORGANIZATIONUNIT.ADD'
            |
            translate}}</button>
        </div>
      </div>
    </div>

    <!-- Listing area -->
    <div class="row" *ngIf="currentParentOrganizationUnit">
      <!-- List of organization units -->
      <ng-container *ngFor="let organizationUnit of currentChildOrganizationUnits">
        <div class="col-lg-6 col-12">
          <armon-organization-unit-basic [organizationUnit]="organizationUnit"
            (showChildrenRequested)="onShowChildrenRequested($event)"
            (organizationUnitUpdated)="onOrganizationUnitUpserted($event)"
            (organizationUsersUpdated)="onOrganizationUnitUpserted($event)"
            (organizationUnitDeleted)="onOrganizationUnitDeleted($event)"></armon-organization-unit-basic>
        </div>
      </ng-container>
    </div>

    <div class="row pt-3" *ngIf="currentParentOrganizationUnit && currentChildOrganizationUnits.length === 0">
      <div class="col-12">
        <nz-empty [nzNotFoundContent]="contentTpl" [nzNotFoundImage]="'./assets/images/empty/empty_list.png'">
          <ng-template #contentTpl>
            <span>{{'ORGANIZATIONUNIT.INFO_EMPTY_CHILDREN_LIST'|translate}}</span>
          </ng-template>
        </nz-empty>
      </div>
    </div>
  </div>
</div>`;var N="";var _=function(r,n,t,e){var a=arguments.length,i=a<3?n:e===null?e=Object.getOwnPropertyDescriptor(n,t):e,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,n,t,e);else for(var s=r.length-1;s>=0;s--)(o=r[s])&&(i=(a<3?o(i):a>3?o(n,t,i):o(n,t))||i);return a>3&&i&&Object.defineProperty(n,t,i),i},T=class{organizationUnitService;authService;modalService;currentParentOrganizationUnit;currentChildOrganizationUnits=[];currentParentHistory=[];permissionAddOrganizationUnit;filterOrganizationUnitId=null;constructor(n,t,e){this.organizationUnitService=n,this.authService=t,this.modalService=e}ngOnInit(){this.checkPermissions()}onFilterChanged(n){n&&this.organizationUnitService.getOrganizationUnitBasic(this.filterOrganizationUnitId).subscribe(t=>{this.currentParentOrganizationUnit=t,this.currentParentHistory=[],this.getChildren(this.currentParentOrganizationUnit.id)})}onShowChildrenRequested(n){n&&this.showChildrenOfOrganizationUnit(n)}onAddOrganizationUnitButtonClicked(){this.modalService.open(I,{settings:{size:"lg",scrollable:!0},props:{parentOrganizationUnit:this.currentParentOrganizationUnit}}).result.then(n=>{this.onOrganizationUnitUpserted()}).catch(n=>{})}onGoBackRequested(){let n=this.currentParentHistory.pop();n&&(this.currentParentOrganizationUnit=n,this.checkPermissions(),this.getChildren(n.id))}checkPermissions(){let n=[];this.currentParentOrganizationUnit&&(n=this.currentParentOrganizationUnit.ancestorIds||[],n.push(this.currentParentOrganizationUnit.id)),this.permissionAddOrganizationUnit=this.authService.checkPermission(U.ORGANIZATIONUNIT.getWrite(),n)}onOrganizationUnitDeleted(n){this.currentParentOrganizationUnit&&(this.currentParentOrganizationUnit.id===n?this.currentParentHistory.length>0?this.onGoBackRequested():(this.currentParentOrganizationUnit=null,this.currentParentHistory=[],this.currentChildOrganizationUnits=[]):d(this.currentChildOrganizationUnits,"id",n)&&this.getChildren(this.currentParentOrganizationUnit.id))}onOrganizationUnitUpserted(){this.currentParentOrganizationUnit&&this.getChildren(this.currentParentOrganizationUnit.id)}showChildrenOfOrganizationUnit(n){this.currentParentHistory.push(this.currentParentOrganizationUnit),this.currentParentOrganizationUnit=n,this.checkPermissions(),this.getChildren(n.id)}getChildren(n){this.organizationUnitService.getChildrenOfOrganizationUnit(n).subscribe(t=>{this.currentChildOrganizationUnits=t},t=>{this.currentChildOrganizationUnits=[]})}static ctorParameters=()=>[{type:O},{type:v},{type:p}]};T=_([l({selector:"armon-manage-organization-units-unit-level",template:C,standalone:!0,imports:[f,z,g,P,u,m,c,h],styles:[N]})],T);export{T as ManageOrganizationUnitsUnitLevelComponent};
