<div class="form-group row">
  <label class="cd-col-form-label"
         i18n>Clients</label>

  <div class="cd-col-form-input"
       [formGroup]="form"
       #formDir="ngForm">
    <span *ngIf="form.get('clients').value.length === 0"
          class="no-border text-muted">
      <span class="form-text text-muted"
            i18n>Any client can access</span>
    </span>

    <ng-container formArrayName="clients">
      <div *ngFor="let item of form.get('clients').value; let index = index; trackBy: trackByFn">
        <div class="card"
             [formGroupName]="index">
          <div class="card-header">
            {{ (index + 1) | ordinal }}
            <span class="float-right clickable"
                  (click)="removeClient(index)"
                  tooltip="Remove">&times;</span>
          </div>

          <div class="card-body">
            <!-- Addresses -->
            <div class="form-group row">
              <label i18n
                     class="cd-col-form-label"
                     for="addresses">Addresses</label>
              <div class="cd-col-form-input">
                <input type="text"
                       class="form-control"
                       name="addresses"
                       id="addresses"
                       formControlName="addresses"
                       placeholder="192.168.0.10, 192.168.1.0/8">
                <span class="invalid-feedback">
                  <span *ngIf="showError(index, 'addresses', formDir, 'required')"
                        i18n>This field is required.</span>

                  <span *ngIf="showError(index, 'addresses', formDir, 'pattern')">
                    <ng-container i18n>Must contain one or more comma-separated values</ng-container>
                    <br>
                    <ng-container i18n>For example:</ng-container> 192.168.0.10, 192.168.1.0/8
                  </span>
                </span>
              </div>
            </div>

            <!-- Access Type-->
            <div class="form-group row">
              <label i18n
                     class="cd-col-form-label"
                     for="access_type">Access Type</label>
              <div class="cd-col-form-input">
                <select class="form-control custom-select"
                        name="access_type"
                        id="access_type"
                        formControlName="access_type">
                  <option value="">{{ getNoAccessTypeDescr() }}</option>
                  <option *ngFor="let item of nfsAccessType"
                          [value]="item.value">{{ item.value }}</option>
                </select>
                <span class="form-text text-muted"
                      *ngIf="getValue(index, 'access_type')">
                  {{ getAccessTypeHelp(index) }}
                </span>
              </div>
            </div>

            <!-- Squash -->
            <div class="form-group row">
              <label i18n
                     class="cd-col-form-label"
                     for="squash">Squash</label>
              <div class="cd-col-form-input">
                <select class="form-control custom-select"
                        name="squash"
                        id="squash"
                        formControlName="squash">
                  <option value="">{{ getNoSquashDescr() }}</option>
                  <option *ngFor="let squash of nfsSquash"
                          [value]="squash">{{ squash }}</option>
                </select>
              </div>
            </div>
          </div>
        </div>
      </div>
    </ng-container>

    <div class="row">
      <div class="col-12">
        <div class="float-right">
          <button class="btn btn-light "
                  (click)="addClient()">
            <i [ngClass]="[icons.add]"></i>
            <ng-container i18n>Add clients</ng-container>
          </button>
        </div>
      </div>
    </div>
  </div>
</div>
