<!--

    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.

-->
<ng-container [formGroup]="alarmsTableWidgetSettingsForm">
  <div class="tb-form-panel">
    <div class="tb-form-panel-title" translate>widgets.table.table-header</div>
    <div class="tb-form-row">
      <div class="fixed-title-width">{{ 'widgets.table.alarms-table-title' | translate }}</div>
      <mat-form-field class="flex-1" appearance="outline" subscriptSizing="dynamic">
        <input matInput formControlName="alarmsTitle" placeholder="{{ 'widget-config.set' | translate }}">
      </mat-form-field>
    </div>
    <div class="tb-form-row">
      <mat-slide-toggle class="mat-slide"  formControlName="enableStickyHeader">
        {{ 'widgets.table.enable-sticky-header' | translate }}
      </mat-slide-toggle>
    </div>
    <div class="tb-form-panel stroked">
      <div class="tb-form-panel-title" translate>widgets.table.header-buttons</div>
      <mat-slide-toggle class="mat-slide"  formControlName="enableSearch">
        {{ 'widgets.table.enable-alarms-search' | translate }}
      </mat-slide-toggle>
      <mat-slide-toggle class="mat-slide"  formControlName="enableSelectColumnDisplay">
        {{ 'widgets.table.enable-select-column-display' | translate }}
      </mat-slide-toggle>
      <mat-slide-toggle class="mat-slide"  formControlName="enableFilter">
        {{ 'widgets.table.enable-alarm-filter' | translate }}
      </mat-slide-toggle>
    </div>
  </div>
  <div class="tb-form-panel">
    <div class="tb-form-panel-title" translate>widgets.table.columns</div>
    <mat-slide-toggle class="mat-slide"  formControlName="enableSelection">
      {{ 'widgets.table.enable-alarms-selection' | translate }}
    </mat-slide-toggle>
    <div class="tb-form-panel stroked">
      <mat-slide-toggle class="mat-slide"  formControlName="enableStickyAction">
        {{ 'widgets.table.enable-sticky-action' | translate }}
      </mat-slide-toggle>
      <mat-slide-toggle class="mat-slide"  formControlName="showCellActionsMenu">
        {{ 'widgets.table.show-cell-actions-menu-mobile' | translate }}
      </mat-slide-toggle>
    </div>
    <div class="tb-form-panel stroked">
      <div class="tb-form-panel-title" translate>widgets.table.table-buttons</div>
      <mat-slide-toggle class="mat-slide" formControlName="displayActivity">
        {{ 'widgets.table.display-alarm-activity' | translate }}
      </mat-slide-toggle>
      <mat-slide-toggle class="mat-slide" formControlName="displayDetails">
        {{ 'widgets.table.display-alarm-details' | translate }}
      </mat-slide-toggle>
      <mat-slide-toggle class="mat-slide" formControlName="allowAssign">
        {{ 'widgets.table.allow-alarms-assign' | translate }}
      </mat-slide-toggle>
      <mat-slide-toggle class="mat-slide" formControlName="allowAcknowledgment">
        {{ 'widgets.table.allow-alarms-ack' | translate }}
      </mat-slide-toggle>
      <mat-slide-toggle class="mat-slide" formControlName="allowClear">
        {{ 'widgets.table.allow-alarms-clear' | translate }}
      </mat-slide-toggle>
    </div>
    <mat-form-field class="flex-1" subscriptSizing="dynamic">
      <mat-label translate>widgets.table.hidden-cell-button-display-mode</mat-label>
      <mat-select formControlName="reserveSpaceForHiddenAction">
        <mat-option [value]="'true'">
          {{ 'widgets.table.show-empty-space-hidden-action' | translate }}
        </mat-option>
        <mat-option [value]="'false'">
          {{ 'widgets.table.dont-reserve-space-hidden-action' | translate }}
        </mat-option>
      </mat-select>
    </mat-form-field>
    <mat-form-field class="flex-1" subscriptSizing="dynamic">
      <mat-label translate>widgets.table.default-sort-order</mat-label>
      <input matInput formControlName="defaultSortOrder">
    </mat-form-field>
  </div>
  <div class="tb-form-panel">
    <div class="tb-form-panel-title" translate>widgets.table.pagination</div>
    <mat-slide-toggle class="mat-slide" formControlName="displayPagination">
      {{ 'widgets.table.display-pagination' | translate }}
    </mat-slide-toggle>
    <div class="tb-form-row space-between column-xs">
      <div class="fixed-title-width !min-w-30">{{ 'widgets.table.page-step-settings' | translate }}</div>
      <div class="flex flex-row items-center justify-start gap-2">
        <div class="tb-small-label" translate>widgets.table.page-step-increment</div>
        <mat-form-field appearance="outline" class="number" subscriptSizing="dynamic">
          <input matInput formControlName="pageStepIncrement" type="number" min="1" step="1" required
                 placeholder="{{ 'widget-config.set' | translate }}">
          @if (alarmsTableWidgetSettingsForm.get('pageStepIncrement').invalid
            && alarmsTableWidgetSettingsForm.get('pageStepIncrement').touched) {
            <mat-icon matSuffix
                      matTooltipPosition="above"
                      matTooltipClass="tb-error-tooltip"
                    [matTooltip]="(alarmsTableWidgetSettingsForm.get('pageStepIncrement').hasError('required')
                                     ? 'widgets.value-source.value-required'
                                     : 'widgets.table.page-step-increment-format-message') | translate"
              class="tb-error">
              warning
            </mat-icon>
          }
        </mat-form-field>
        <mat-divider vertical class="xs:hidden"></mat-divider>
        <div class="tb-small-label" translate>widgets.table.page-step-count</div>
        <mat-form-field appearance="outline" class="number" subscriptSizing="dynamic">
          <input matInput formControlName="pageStepCount" type="number" min="1" max="100" step="1" required
                 placeholder="{{ 'widget-config.set' | translate }}">
          @if (alarmsTableWidgetSettingsForm.get('pageStepCount').invalid
            && alarmsTableWidgetSettingsForm.get('pageStepCount').touched) {
            <mat-icon matSuffix
                      matTooltipPosition="above"
                      matTooltipClass="tb-error-tooltip"
                    [matTooltip]="(alarmsTableWidgetSettingsForm.get('pageStepCount').hasError('required')
                                     ? 'widgets.value-source.value-required'
                                     : 'widgets.table.page-step-count-format-message') | translate"
              class="tb-error">
              warning
            </mat-icon>
          }
        </mat-form-field>
      </div>
    </div>
    <div class="tb-form-row space-between column-xs">
      <div translate>widgets.table.default-page-size</div>
      <mat-form-field appearance="outline" subscriptSizing="dynamic">
        <mat-select formControlName="defaultPageSize" placeholder="{{ 'widget-config.set' | translate }}">
          @for (size of pageStepSizeValues; track size) {
            <mat-option [value]="size">
              {{ size }}
            </mat-option>
          }
        </mat-select>
      </mat-form-field>
    </div>
  </div>
  <div class="tb-form-panel tb-slide-toggle">
    <div class="tb-form-panel-title" translate>widgets.table.rows</div>
    <mat-expansion-panel class="tb-settings" [expanded]="alarmsTableWidgetSettingsForm.get('useRowStyleFunction').value">
      <mat-expansion-panel-header class="flex flex-row flex-wrap">
        <mat-panel-title>
          <mat-slide-toggle class="mat-slide flex items-stretch justify-center" formControlName="useRowStyleFunction" (click)="$event.stopPropagation()">
            {{ 'widgets.table.use-row-style-function' | translate }}
          </mat-slide-toggle>
        </mat-panel-title>
        <mat-panel-description class="flex max-w-40% flex-full items-center justify-end xs:!hidden" translate>
          widget-config.advanced-settings
        </mat-panel-description>
      </mat-expansion-panel-header>
      <ng-template matExpansionPanelContent>
        <tb-js-func required
                    formControlName="rowStyleFunction"
                    withModules
                    [globalVariables]="functionScopeVariables"
                    [functionArgs]="['alarm', 'ctx']"
                    functionTitle="{{ 'widgets.table.row-style-function' | translate }}"
                    helpId="widget/lib/alarm/row_style_fn">
        </tb-js-func>
      </ng-template>
    </mat-expansion-panel>
  </div>
</ng-container>
