<!--

    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]="aggregatedValueCardWidgetConfigForm">
  <tb-timewindow-config-panel formControlName="timewindowConfig">
  </tb-timewindow-config-panel>
  <tb-datasources
    [configMode]="basicMode"
    hideDataKeyLabel
    hideDataKeyColor
    hideDataKeyUnits
    hideDataKeyDecimals
    hideLatestDataKeys
    formControlName="datasources">
  </tb-datasources>
  <div class="tb-form-panel">
    <div class="tb-form-panel-title" translate>widget-config.appearance</div>
    <div class="tb-form-row">
      <mat-slide-toggle class="mat-slide" formControlName="autoScale">
        {{ 'widgets.aggregated-value-card.auto-scale' | translate }}
      </mat-slide-toggle>
    </div>
    <div class="tb-form-row column-xs">
      <mat-slide-toggle class="mat-slide fixed-title-width" formControlName="showTitle">
        {{ 'widget-config.title' | translate }}
      </mat-slide-toggle>
      <div class="flex flex-1 flex-row items-center justify-start gap-2">
        <tb-string-pattern-autocomplete class="flex-1"
                                        appearance="outline"
                                        brackets="curly"
                                        subscriptSizing="dynamic"
                                        predefinedValuesButton="true"
                                        [predefinedValues]="predefinedValues"
                                        [disabled]="!aggregatedValueCardWidgetConfigForm.get('showTitle').value"
                                        placeholderText="{{ 'widget-config.set' | translate }}"
                                        formControlName="title"
        ></tb-string-pattern-autocomplete>
        <tb-font-settings formControlName="titleFont"
                          clearButton
                          [previewText]="aggregatedValueCardWidgetConfigForm.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 column-xs">
      <mat-slide-toggle class="mat-slide fixed-title-width" formControlName="showIcon">
        {{ 'widgets.value-card.icon' | translate }}
      </mat-slide-toggle>
      <div class="flex flex-1 flex-row items-center justify-start gap-2">
        <mat-form-field appearance="outline" class="number flex" subscriptSizing="dynamic">
          <input matInput type="number" min="0" formControlName="iconSize" placeholder="{{ 'widget-config.set' | translate }}">
        </mat-form-field>
        <tb-css-unit-select class="flex-1" formControlName="iconSizeUnit"></tb-css-unit-select>
        <tb-material-icon-select asBoxInput
                                 iconClearButton
                                 [color]="aggregatedValueCardWidgetConfigForm.get('iconColor').value"
                                 formControlName="icon">
        </tb-material-icon-select>
        <tb-color-input asBoxInput
                        colorClearButton
                        formControlName="iconColor">
        </tb-color-input>
      </div>
    </div>
    <div class="tb-form-row column-xs">
      <mat-slide-toggle class="mat-slide fixed-title-width" formControlName="showSubtitle">
        {{ 'widgets.aggregated-value-card.subtitle' | translate }}
      </mat-slide-toggle>
      <div class="flex flex-1 flex-row items-center justify-start gap-2">
        <tb-string-pattern-autocomplete class="flex-1"
                                        appearance="outline"
                                        brackets="curly"
                                        subscriptSizing="dynamic"
                                        [predefinedValuesButton]="true"
                                        [predefinedValues]="predefinedValues"
                                        [disabled]="!aggregatedValueCardWidgetConfigForm.get('showSubtitle').value"
                                        placeholderText="{{ 'widget-config.set' | translate }}"
                                        formControlName="subtitle"
        ></tb-string-pattern-autocomplete>
        <tb-font-settings formControlName="subtitleFont"
                          clearButton
                          [previewText]="aggregatedValueCardWidgetConfigForm.get('subtitle').value">
        </tb-font-settings>
        <tb-color-input asBoxInput
                        colorClearButton
                        formControlName="subtitleColor">
        </tb-color-input>
      </div>
    </div>
    <div class="tb-form-row column-xs">
      <mat-slide-toggle class="mat-slide fixed-title-width" formControlName="showDate">
        {{ 'widgets.value-card.date' | translate }}
      </mat-slide-toggle>
      <div class="flex flex-row items-center justify-start gap-2 gt-xs:flex-1">
        <tb-date-format-select class="flex-1" formControlName="dateFormat"></tb-date-format-select>
        <tb-font-settings formControlName="dateFont"
                          [previewText]="datePreviewFn">
        </tb-font-settings>
        <tb-color-input asBoxInput
                        colorClearButton
                        formControlName="dateColor">
        </tb-color-input>
      </div>
    </div>
    <div class="tb-form-row column-xs">
      <mat-slide-toggle class="mat-slide fixed-title-width" formControlName="showChart">
        {{ 'widgets.aggregated-value-card.chart' | translate }}
      </mat-slide-toggle>
      <div class="flex flex-1 flex-row items-center justify-start gap-2">
        <tb-unit-input class="flex" supportsUnitConversion formControlName="chartUnits"></tb-unit-input>
        <mat-form-field appearance="outline" class="number flex" subscriptSizing="dynamic">
          <input matInput formControlName="chartDecimals" type="number" min="0" max="15" step="1" placeholder="{{ 'widget-config.set' | translate }}">
          <div matSuffix class="lt-md:!hidden" translate>widget-config.decimals-suffix</div>
        </mat-form-field>
        <tb-color-input asBoxInput
                        colorClearButton
                        formControlName="chartColor">
        </tb-color-input>
      </div>
    </div>
  </div>
  <tb-aggregated-data-keys-panel
    [datasourceType]="datasource?.type"
    [keyName]="keyName"
    formControlName="values">
  </tb-aggregated-data-keys-panel>
  <div class="tb-form-panel">
    <div class="tb-form-panel-title" translate>widget-config.card-appearance</div>
    <div class="tb-form-row space-between">
      <div>{{ 'widgets.background.background' | translate }}</div>
      <tb-background-settings formControlName="background">
      </tb-background-settings>
    </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="fullscreen">{{ 'fullscreen.fullscreen' | translate }}</mat-chip-option>
      </mat-chip-listbox>
    </div>
    <div class="tb-form-row space-between">
      <div>{{ 'widget-config.card-border-radius' | translate }}</div>
      <mat-form-field appearance="outline" subscriptSizing="dynamic">
        <input matInput formControlName="borderRadius" placeholder="{{ 'widget-config.set' | translate }}">
      </mat-form-field>
    </div>
    <div class="tb-form-row space-between">
      <div>{{ 'widget-config.card-padding' | translate }}</div>
      <mat-form-field appearance="outline" subscriptSizing="dynamic">
        <input matInput formControlName="padding" placeholder="{{ 'widget-config.set' | translate }}">
      </mat-form-field>
    </div>
  </div>
  <tb-widget-actions-panel
    formControlName="actions">
  </tb-widget-actions-panel>
</ng-container>
