<!--

    Copyright © 2016-2023 The Thingsboard Authors

    Licensed 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.

-->
<div class="tb-form-panel no-border no-padding">
  <div class="tb-form-table" [formGroup]="relationFiltersFormGroup">
    <div class="tb-form-table-header">
      <div class="tb-form-table-header-cell flex-50">{{ 'relation.relation-type' | translate }}</div>
      <div class="tb-form-table-header-cell flex-50">{{ 'entity.entity-types' | translate }}</div>
      <div class="tb-form-table-header-cell actions-header"></div>
    </div>
    <div class="tb-form-table-body" formArrayName="relationFilters">
      <div class="tb-form-table-row"
           *ngFor="let relationFilterControl of relationFiltersFormArray.controls; let $index = index">
        <tb-relation-type-autocomplete subscriptSizing="dynamic"
                                       class="flex-50" showLabel="false"
                                       [additionalClasses]="['tb-inline-field']"
                                       appearance="outline"
                                       [formControl]="relationFilterControl.get('relationType')">
        </tb-relation-type-autocomplete>
        <tb-entity-type-list class="entity-type-list flex-50" subscriptSizing="dynamic" appearance="outline"
                             [additionalClasses]="['tb-inline-field', 'tb-chips', 'flex']"
                             filledInputPlaceholder="{{ 'entity.add-entity-type' | translate }}"
                             [allowedEntityTypes]="allowedEntityTypes"
                             [formControl]="relationFilterControl.get('entityTypes')">
        </tb-entity-type-list>
        <div class="tb-form-table-row-cell-buttons">
          <button type="button"
                  mat-icon-button
                  (click)="removeFilter($index)"
                  [disabled]="isLoading$ | async"
                  matTooltip="{{ 'relation.remove-filter' | translate }}"
                  matTooltipPosition="above">
            <mat-icon>delete</mat-icon>
          </button>
        </div>
      </div>
      <div [fxShow]="!relationFiltersFormArray.length">
        <span fxLayoutAlign="center center" class="tb-prompt" translate>relation.any-relation</span>
      </div>
    </div>
  </div>
  <div>
    <button type="button" mat-stroked-button color="primary" (click)="addFilter()">
      {{ 'filter.add' | translate }}
    </button>
  </div>
</div>
