<!--

    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]="deleteRelationConfigForm" class="tb-form-panel no-padding no-border">
  <div class="tb-form-panel stroked no-padding-bottom">
    <div class="tb-form-panel-title" translate>rule-node-config.relation-parameters</div>
    <div class="flex flex-col">
      <mat-form-field class="mat-block" hideRequiredMarker appearance="outline">
        <mat-label translate>relation.direction</mat-label>
        <mat-select required matInput formControlName="direction">
          @for (type of directionTypes; track type) {
            <mat-option [value]="type">
              {{ directionTypeTranslations.get(type) | translate }}
            </mat-option>
          }
        </mat-select>
      </mat-form-field>
      <tb-relation-type-autocomplete
        appearance="outline"
        required
        formControlName="relationType">
      </tb-relation-type-autocomplete>
    </div>
  </div>
  <div class="tb-form-panel stroked">
    <div tb-hint-tooltip-icon="{{ 'rule-node-config.delete-relation-with-specific-entity-hint' | translate }}"
         class="tb-form-row no-border no-padding">
      <mat-slide-toggle class="mat-slide" formControlName="deleteForSingleEntity">
        {{ 'rule-node-config.delete-relation-with-specific-entity' | translate }}
      </mat-slide-toggle>
    </div>
    @if (deleteRelationConfigForm.get('deleteForSingleEntity').value) {
      <div>
        <div class="flex flex-row gap-2.5">
          <tb-entity-type-select
            class="flex-1"
            showLabel
            required
            appearance="outline"
            [allowedEntityTypes]="allowedEntityTypes"
            formControlName="entityType">
          </tb-entity-type-select>
          @if (deleteRelationConfigForm.get('entityType').value && deleteRelationConfigForm.get('entityType').value !== entityType.TENANT) {
            <mat-form-field
              appearance="outline"
              class="mat-block flex-1">
              <mat-label>{{ entityTypeNamePatternTranslation.get(deleteRelationConfigForm.get('entityType').value) | translate }}</mat-label>
              <input required matInput formControlName="entityNamePattern">
            </mat-form-field>
          }
        </div>
        @if (deleteRelationConfigForm.get('entityType').value && deleteRelationConfigForm.get('entityType').value !== entityType.TENANT) {
          <tb-example-hint
          [hintText]="'rule-node-config.kv-map-single-pattern-hint'"></tb-example-hint>
        }
      </div>
    }
  </div>
</section>
