<!--
  ~ Licensed to the Apache Software Foundation (ASF) under one or more
  ~ contributor license agreements.  See the NOTICE file distributed with
  ~ this work for additional information regarding copyright ownership.
  ~ The ASF licenses this file to You under the Apache License, Version 2.0
  ~ (the "License"); you may not use this file except in compliance with
  ~ the License.  You may obtain a copy of the License at
  ~
  ~     http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<h2 mat-dialog-title>Add Users/Groups To Policy</h2>
<form class="add-tenant-to-policy-form" [formGroup]="addTenantsForm">
    <mat-dialog-content>
        <div *ngIf="filteredUsers.length > 0">
            <mat-label>Users</mat-label>
            <mat-selection-list formControlName="users" class="border">
                <mat-list-option *ngFor="let user of filteredUsers" togglePosition="before" [value]="user.id"
                    >{{ user.component.identity }}
                </mat-list-option>
            </mat-selection-list>
        </div>
        <div *ngIf="filteredUserGroups.length > 0" [class.mt-4]="filteredUsers.length > 0">
            <mat-label>User Groups</mat-label>
            <mat-selection-list formControlName="userGroups" class="border">
                <mat-list-option
                    *ngFor="let userGroup of filteredUserGroups"
                    togglePosition="before"
                    [value]="userGroup.id">
                    <i class="fa fa-users mr-3"></i>{{ userGroup.component.identity }}
                </mat-list-option>
            </mat-selection-list>
        </div>
        <div *ngIf="filteredUsers.length === 0 && filteredUserGroups.length === 0" class="value">
            All users and groups are assigned to this policy.
        </div>
    </mat-dialog-content>
    <mat-dialog-actions align="end" *ngIf="{ value: (saving$ | async)! } as saving">
        <button mat-raised-button mat-dialog-close color="accent">Cancel</button>
        <button
            mat-raised-button
            [disabled]="addTenantsForm.invalid || saving.value"
            (click)="addClicked()"
            color="primary">
            <span *nifiSpinner="saving.value">Add</span>
        </button>
    </mat-dialog-actions>
</form>
