<!--

    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.

-->
<div class="tb-form-panel tb-scada-symbol-behaviors">
  <div class="tb-form-table">
    <div class="tb-form-table-header" [class.no-padding-right]="!disabled">
      <div class="tb-form-table-header-cell tb-id-header" translate>scada.behavior.id</div>
      <div class="tb-form-table-header-cell tb-name-header" translate>scada.behavior.name</div>
      <div class="tb-form-table-header-cell tb-type-header" translate>scada.behavior.type</div>
      <div class="tb-form-table-header-cell tb-actions-header" [class.disabled]="disabled"></div>
    </div>
    @if (behaviorsFormArray().controls.length) {
      <div class="tb-form-table-body tb-drop-list"
           cdkDropList cdkDropListOrientation="vertical"
           [cdkDropListDisabled]="!dragEnabled"
           (cdkDropListDropped)="behaviorDrop($event)">
        @for (behaviorControl of behaviorsFormArray().controls; track trackByBehavior($index, behaviorControl)) {
          <div cdkDrag [cdkDragDisabled]="!dragEnabled"
               [class.tb-draggable]="!disabled"
               [class.tb-draggable-form-table-row]="!disabled"
               >
            <tb-scada-symbol-metadata-behavior-row class="flex-1"
                                                   [index]="$index"
                                                   [formControl]="behaviorControl"
                                                   [aliasController]="aliasController"
                                                   [callbacks]="callbacks"
                                                   (behaviorRemoved)="removeBehavior($index)">
            </tb-scada-symbol-metadata-behavior-row>
            <div class="tb-form-table-row-cell-buttons">
              @if (!disabled) {
                <button mat-icon-button
                        type="button"
                        cdkDragHandle
                        [class.tb-hidden]="!dragEnabled"
                        matTooltip="{{ 'action.drag' | translate }}"
                        matTooltipPosition="above">
                  <mat-icon>drag_indicator</mat-icon>
                </button>
              }
            </div>
          </div>
        }
      </div>
    } @else {
      <span class="tb-prompt flex items-center justify-center">{{ 'scada.behavior.no-behaviors' | translate }}</span>
    }
    @if (errorText) {
      <tb-error noMargin [error]="errorText" style="padding-left: 12px;"></tb-error>
    }
  </div>
  @if (!disabled) {
    <div>
      <button type="button" mat-stroked-button color="primary" (click)="addBehavior()">
        {{ 'scada.behavior.add-behavior' | translate }}
      </button>
    </div>
  }
</div>

