<!--

    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.

-->
<ng-container [formGroup]="alarmsTableWidgetConfigForm">
  <tb-timewindow-config-panel formControlName="timewindowConfig">
  </tb-timewindow-config-panel>
  <tb-datasources
    [configMode]="basicMode"
    hideDataKeys
    formControlName="datasources">
  </tb-datasources>
  <div class="tb-form-panel">
    <div fxLayout="row" fxLayoutAlign="space-between center">
      <div class="tb-form-panel-title" translate>alarm.filter</div>
      <button mat-button color="primary"
        (click)="alarmFilterConfig.reset()">
        {{ 'action.reset' | translate }}
      </button>
    </div>
    <tb-alarm-filter-config #alarmFilterConfig buttonMode="false" formControlName="alarmFilterConfig"
                            [initialAlarmFilterConfig]="{}"></tb-alarm-filter-config>
  </div>
  <tb-data-keys-panel
    panelTitle="{{ 'widgets.table.columns' | translate }}"
    addKeyTitle="{{ 'widgets.table.add-column' | translate }}"
    keySettingsTitle="{{ 'widgets.table.column-settings' | translate }}"
    removeKeyTitle="{{ 'widgets.table.remove-column' | translate }}"
    noKeysText="{{ 'widgets.table.no-columns' | translate }}"
    requiredKeysText="{{ 'widgets.table.alarm-column-error' | translate }}"
    hideDataKeyColor
    hideUnits
    hideDecimals
    [datasourceType]="alarmSource?.type"
    [deviceId]="alarmSource?.deviceId"
    [entityAliasId]="alarmSource?.entityAliasId"
    formControlName="columns">
  </tb-data-keys-panel>
  <div class="tb-form-panel">
    <div class="tb-form-panel-title" translate>widget-config.appearance</div>
    <div class="tb-form-row column-xs">
      <mat-slide-toggle class="mat-slide fixed-title-width" formControlName="showTitle">
        {{ 'widget-config.card-title' | translate }}
      </mat-slide-toggle>
      <div fxFlex fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px">
        <mat-form-field fxFlex appearance="outline" subscriptSizing="dynamic">
          <input matInput formControlName="title" placeholder="{{ 'widget-config.set' | translate }}">
        </mat-form-field>
        <tb-font-settings formControlName="titleFont"
                          clearButton
                          [previewText]="alarmsTableWidgetConfigForm.get('title').value"
                          [initialPreviewStyle]="widgetConfig.config.titleStyle">
        </tb-font-settings>
        <tb-color-input asBoxInput
                        colorClearButton
                        formControlName="titleColor">
        </tb-color-input>
      </div>
    </div>
    <div class="tb-form-row space-between">
      <mat-slide-toggle class="mat-slide"  formControlName="showTitleIcon">
        {{ 'widget-config.card-icon' | translate }}
      </mat-slide-toggle>
      <div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px">
        <tb-material-icon-select asBoxInput
                                 iconClearButton
                                 [color]="alarmsTableWidgetConfigForm.get('iconColor').value"
                                 formControlName="titleIcon">
        </tb-material-icon-select>
        <tb-color-input asBoxInput
                        colorClearButton
                        formControlName="iconColor">
        </tb-color-input>
      </div>
    </div>
  </div>
  <div class="tb-form-panel">
    <div class="tb-form-panel-title" translate>widgets.table.table-buttons</div>
    <div class="tb-form-row column">
      <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>
  </div>
  <div class="tb-form-panel">
    <div class="tb-form-panel-title" translate>widget-config.card-appearance</div>
    <div class="tb-form-row space-between column-lt-md">
      <div translate>widget-config.show-card-buttons</div>
      <mat-chip-listbox multiple formControlName="cardButtons">
        <mat-chip-option value="search">{{ 'action.search' | translate }}</mat-chip-option>
        <mat-chip-option value="filter">{{ 'alarm.alarm-filter' | translate }}</mat-chip-option>
        <mat-chip-option value="columnsToDisplay">{{ 'widgets.table.columns-to-display' | translate }}</mat-chip-option>
        <mat-chip-option value="fullscreen">{{ 'fullscreen.fullscreen' | translate }}</mat-chip-option>
      </mat-chip-listbox>
    </div>
    <div class="tb-form-row space-between">
      <div>{{ 'widget-config.text-color' | translate }}</div>
      <tb-color-input asBoxInput
                      colorClearButton
                      formControlName="color">
      </tb-color-input>
    </div>
    <div class="tb-form-row space-between">
      <div>{{ 'widget-config.background-color' | translate }}</div>
      <tb-color-input asBoxInput
                      colorClearButton
                      formControlName="backgroundColor">
      </tb-color-input>
    </div>
  </div>
  <tb-widget-actions-panel
    formControlName="actions">
  </tb-widget-actions-panel>
</ng-container>
