<!--

    Copyright © 2016-2026 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.

-->
<section [formGroup]="checkRelationConfigForm" class="tb-form-panel stroked no-padding-bottom">
  <div class="tb-form-panel-title" translate>rule-node-config.relation-search-parameters</div>
  <div class="flex flex-col">
    <mat-form-field class="mat-block" hideRequiredMarker appearance="outline">
      <mat-label>{{ 'relation.direction' | translate }}</mat-label>
      <mat-select formControlName="direction" required>
        @for (direction of entitySearchDirection; track direction) {
          <mat-option [value]="direction">
            {{ entitySearchDirectionTranslationsMap.get(direction) | translate }} <span translate>rule-node-config.relations-query-config-direction-suffix</span>
          </mat-option>
        }
      </mat-select>
    </mat-form-field>
    <tb-relation-type-autocomplete
      appearance="outline"
      required
      formControlName="relationType">
    </tb-relation-type-autocomplete>
    <div tb-hint-tooltip-icon="{{ 'rule-node-config.check-relation-to-specific-entity-tooltip' | translate }}"
         class="tb-form-row no-border no-padding slide-toggle">
      <mat-slide-toggle class="mat-slide" formControlName="checkForSingleEntity">
        {{ 'rule-node-config.check-relation-to-specific-entity' | translate }}
      </mat-slide-toggle>
    </div>
    @if (checkRelationConfigForm.get('checkForSingleEntity').value) {
      <div class="same-width-component-row">
        <tb-entity-type-select
          appearance="outline"
          style="min-width: 100px; flex: 1;"
          showLabel
          required
          formControlName="entityType">
        </tb-entity-type-select>
        @if (checkRelationConfigForm.get('entityType').value) {
          <tb-entity-autocomplete
            appearance="outline"
            class="flex-1"
            required
            [entityType]="checkRelationConfigForm.get('entityType').value"
            formControlName="entityId">
          </tb-entity-autocomplete>
        }
      </div>
    }
  </div>
</section>
