<!--

    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]="rangeChartWidgetConfigForm">
  <tb-timewindow-config-panel formControlName="timewindowConfig">
  </tb-timewindow-config-panel>
  <tb-datasources
    [configMode]="basicMode"
    hideDatasourceLabel
    hideDataKeyColor
    hideDataKeyUnits
    hideDataKeyDecimals
    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 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"
                                        [disabled]="!rangeChartWidgetConfigForm.get('showTitle').value"
                                        [predefinedValues]="predefinedValues"
                                        placeholderText="{{ 'widget-config.set' | translate }}"
                                        formControlName="title"
        ></tb-string-pattern-autocomplete>
        <tb-font-settings formControlName="titleFont"
                          clearButton
                          [previewText]="rangeChartWidgetConfigForm.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">
        {{ 'widget-config.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]="rangeChartWidgetConfigForm.get('iconColor').value"
                                 formControlName="icon">
        </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.range-chart.chart</div>
    <div class="tb-form-row">
      <mat-slide-toggle class="mat-slide" formControlName="dataZoom">
        {{ 'widgets.range-chart.data-zoom' | translate }}
      </mat-slide-toggle>
    </div>
    <tb-time-series-chart-grid-settings
      formControlName="grid">
    </tb-time-series-chart-grid-settings>
  </div>
  <div class="tb-form-panel">
    <div class="tb-form-panel-title" translate>widgets.range-chart.range-chart-appearance</div>
    <div class="tb-form-row space-between">
      <div translate>widget-config.units-short</div>
      <tb-unit-input
        supportsUnitConversion
        formControlName="units">
      </tb-unit-input>
    </div>
    <div class="tb-form-row space-between">
      <div translate>widget-config.decimals-short</div>
      <mat-form-field appearance="outline" class="number" subscriptSizing="dynamic">
        <input matInput formControlName="decimals" type="number" min="0" max="15" step="1" placeholder="{{ 'widget-config.set' | translate }}">
      </mat-form-field>
    </div>
    <div class="tb-form-row space-between">
      <div>{{ 'widgets.range-chart.range-colors' | translate }}</div>
      <tb-color-range-settings formControlName="rangeColors">
      </tb-color-range-settings>
    </div>
    <div class="tb-form-row space-between">
      <div>{{ 'widgets.range-chart.out-of-range-color' | translate }}</div>
      <tb-color-input asBoxInput
                      colorClearButton
                      formControlName="outOfRangeColor">
      </tb-color-input>
    </div>
    <div class="tb-form-row space-between">
      <mat-slide-toggle class="mat-slide" formControlName="showRangeThresholds">
        {{ 'widgets.range-chart.show-range-thresholds' | translate }}
      </mat-slide-toggle>
      <tb-time-series-chart-threshold-settings
        boxButton
        hideYAxis
        [widgetConfig]="widgetConfig?.config"
        title="widgets.range-chart.range-thresholds-settings"
        formControlName="rangeThreshold">
      </tb-time-series-chart-threshold-settings>
    </div>
    <div class="tb-form-row">
      <mat-slide-toggle class="mat-slide" formControlName="fillArea">
        {{ 'widgets.range-chart.fill-area' | translate }}
      </mat-slide-toggle>
    </div>
    <div class="tb-form-row space-between column-xs">
      <div translate>widgets.range-chart.fill-area-opacity</div>
      <mat-form-field class="medium-width number" appearance="outline" subscriptSizing="dynamic">
        <input matInput type="number" formControlName="fillAreaOpacity" min="0" max="1"
               step="0.1" placeholder="{{ 'widget-config.set' | translate }}"/>
      </mat-form-field>
    </div>
    <div class="tb-form-panel stroked">
      <div class="tb-form-panel-title" translate>widgets.time-series-chart.series.line.line</div>
      <div class="tb-form-row">
        <mat-slide-toggle class="mat-slide" formControlName="showLine">
          {{ 'widgets.time-series-chart.series.line.show-line' | translate }}
        </mat-slide-toggle>
      </div>
      <div class="tb-form-row space-between column-xs">
        <mat-slide-toggle class="mat-slide" formControlName="step">
          {{ 'widgets.time-series-chart.series.line.step-line' | translate }}
        </mat-slide-toggle>
        <mat-form-field class="medium-width" appearance="outline" subscriptSizing="dynamic">
          <mat-select formControlName="stepType">
            @for (stepType of lineSeriesStepTypes; track stepType) {
              <mat-option [value]="stepType">
                {{ lineSeriesStepTypeTranslations.get(stepType) | translate }}
              </mat-option>
            }
          </mat-select>
        </mat-form-field>
      </div>
      <div class="tb-form-row">
        <mat-slide-toggle class="mat-slide" formControlName="smooth">
          {{ 'widgets.time-series-chart.series.line.smooth-line' | translate }}
        </mat-slide-toggle>
      </div>
      <div class="tb-form-row space-between column-xs">
        <div translate>widgets.time-series-chart.line-type</div>
        <mat-form-field class="medium-width" appearance="outline" subscriptSizing="dynamic">
          <mat-select formControlName="lineType">
            @for (lineType of chartLineTypes; track lineType) {
              <mat-option [value]="lineType">
                {{ chartLineTypeTranslations.get(lineType) | translate }}
              </mat-option>
            }
          </mat-select>
        </mat-form-field>
      </div>
      <div class="tb-form-row space-between column-xs">
        <div translate>widgets.time-series-chart.line-width</div>
        <mat-form-field class="medium-width number" appearance="outline" subscriptSizing="dynamic">
          <input matInput type="number" formControlName="lineWidth" min="0" step="1" placeholder="{{ 'widget-config.set' | translate }}"/>
        </mat-form-field>
      </div>
    </div>
    <div class="tb-form-panel stroked">
      <div class="tb-form-panel-title" translate>widgets.time-series-chart.series.point.points</div>
      <div class="tb-form-row">
        <mat-slide-toggle class="mat-slide" formControlName="showPoints">
          {{ 'widgets.time-series-chart.series.point.show-points' | translate }}
        </mat-slide-toggle>
      </div>
      <div class="tb-form-row space-between column-lt-md">
        <mat-slide-toggle class="mat-slide" formControlName="showPointLabel">
          <div tb-hint-tooltip-icon="{{'widgets.time-series-chart.series.point.point-label-hint' | translate}}">
            {{ 'widgets.time-series-chart.series.point.point-label' | translate }}
          </div>
        </mat-slide-toggle>
        <div class="flex flex-row items-center justify-start gap-2 lt-md:flex-1">
          <mat-form-field class="medium-width lt-md:flex-1" appearance="outline" subscriptSizing="dynamic">
            <mat-select formControlName="pointLabelPosition">
              @for (position of chartLabelPositions; track position) {
                <mat-option [value]="position">
                  {{ chartLabelPositionTranslations.get(position) | translate }}
                </mat-option>
              }
            </mat-select>
          </mat-form-field>
          <tb-font-settings formControlName="pointLabelFont"
                            clearButton
                            disabledLineHeight
                            forceSizeUnit="px"
                            [previewText]="pointLabelPreviewFn">
          </tb-font-settings>
          <tb-color-input asBoxInput
                          colorClearButton
                          formControlName="pointLabelColor">
          </tb-color-input>
        </div>
      </div>
      <div class="tb-form-row space-between">
        <mat-slide-toggle class="mat-slide" formControlName="enablePointLabelBackground">
          {{ 'widgets.time-series-chart.series.point.point-label-background' | translate }}
        </mat-slide-toggle>
        <tb-color-input asBoxInput
                        colorClearButton
                        formControlName="pointLabelBackground">
        </tb-color-input>
      </div>
      <div class="tb-form-row space-between column-xs">
        <div translate>widgets.time-series-chart.series.point.point-shape</div>
        <mat-form-field class="medium-width" appearance="outline" subscriptSizing="dynamic">
          <mat-select formControlName="pointShape">
            @for (shape of chartShapes; track shape) {
              <mat-option [value]="shape">
                {{ chartShapeTranslations.get(shape) | translate }}
              </mat-option>
            }
          </mat-select>
        </mat-form-field>
      </div>
      <div class="tb-form-row space-between column-xs">
        <div translate>widgets.time-series-chart.series.point.point-size</div>
        <mat-form-field class="medium-width number" appearance="outline" subscriptSizing="dynamic">
          <input matInput type="number" formControlName="pointSize" min="0" step="1" placeholder="{{ 'widget-config.set' | translate }}"/>
        </mat-form-field>
      </div>
    </div>
  </div>
  <div class="tb-form-panel">
    <div class="tb-form-panel-title" translate>widgets.time-series-chart.axis.y-axis</div>
    <tb-time-series-chart-axis-settings
      formControlName="yAxis"
      [aliasController]="aliasController"
      [dataKeyCallbacks]="callbacks"
      [datasource]="datasource"
      axisType="yAxis"
      hideUnits
      hideDecimals>
    </tb-time-series-chart-axis-settings>
  </div>
  <div class="tb-form-panel">
    <div class="tb-form-panel-title" translate>widgets.time-series-chart.axis.x-axis</div>
    <tb-time-series-chart-axis-settings
      formControlName="xAxis"
      axisType="xAxis">
    </tb-time-series-chart-axis-settings>
  </div>
  <tb-time-series-chart-thresholds-panel
    formControlName="thresholds"
    [aliasController]="aliasController"
    [dataKeyCallbacks]="callbacks"
    [datasource]="datasource"
    [widgetConfig]="widgetConfig?.config"
    hideYAxis>
  </tb-time-series-chart-thresholds-panel>
  <div class="tb-form-panel tb-slide-toggle">
    <mat-expansion-panel class="tb-settings" [expanded]="rangeChartWidgetConfigForm.get('showLegend').value" [disabled]="!rangeChartWidgetConfigForm.get('showLegend').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="showLegend" (click)="$event.stopPropagation()">
            {{ 'widget-config.legend' | translate }}
          </mat-slide-toggle>
        </mat-panel-title>
      </mat-expansion-panel-header>
      <ng-template matExpansionPanelContent>
        <div class="tb-form-row space-between">
          <div>{{ 'legend.position' | translate }}</div>
          <mat-form-field class="medium-width" appearance="outline" subscriptSizing="dynamic">
            <mat-select formControlName="legendPosition">
              @for (pos of legendPositions; track pos) {
                <mat-option [value]="pos">
                  {{ legendPositionTranslationMap.get(pos) | translate }}
                </mat-option>
              }
            </mat-select>
          </mat-form-field>
        </div>
        <div class="tb-form-row space-between">
          <div>{{ 'legend.label' | translate }}</div>
          <div class="flex flex-row items-center justify-start gap-2">
            <tb-font-settings formControlName="legendLabelFont"
                              previewText="20 - 30">
            </tb-font-settings>
            <tb-color-input asBoxInput
                            colorClearButton
                            formControlName="legendLabelColor">
            </tb-color-input>
          </div>
        </div>
      </ng-template>
    </mat-expansion-panel>
  </div>
  <div class="tb-form-panel tb-slide-toggle">
    <mat-expansion-panel class="tb-settings" [expanded]="rangeChartWidgetConfigForm.get('showTooltip').value" [disabled]="!rangeChartWidgetConfigForm.get('showTooltip').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="showTooltip" (click)="$event.stopPropagation()">
            {{ 'widget-config.tooltip' | translate }}
          </mat-slide-toggle>
        </mat-panel-title>
      </mat-expansion-panel-header>
      <ng-template matExpansionPanelContent>
        <div class="tb-form-row space-between">
          <div>{{ 'tooltip.label' | translate }}</div>
          <div class="flex flex-row items-center justify-start gap-2">
            <tb-font-settings formControlName="tooltipLabelFont"
                              [initialPreviewStyle]="{ color: rangeChartWidgetConfigForm.get('tooltipLabelColor').value }"
                              previewText="Temperature">
            </tb-font-settings>
            <tb-color-input asBoxInput
                            colorClearButton
                            formControlName="tooltipLabelColor">
            </tb-color-input>
          </div>
        </div>
        <div class="tb-form-row space-between">
          <div>{{ 'tooltip.value' | translate }}</div>
          <div class="flex flex-row items-center justify-start gap-2">
            <tb-font-settings formControlName="tooltipValueFont"
                              [initialPreviewStyle]="{ color: rangeChartWidgetConfigForm.get('tooltipValueColor').value }"
                              [previewText]="tooltipValuePreviewFn">
            </tb-font-settings>
            <tb-color-input asBoxInput
                            colorClearButton
                            formControlName="tooltipValueColor">
            </tb-color-input>
          </div>
        </div>        <div class="tb-form-row column-xs">
        <mat-slide-toggle class="mat-slide fixed-title-width" formControlName="tooltipShowDate">
          {{ 'tooltip.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" excludeLastUpdateAgo includeAuto
          formControlName="tooltipDateFormat"></tb-date-format-select>
          <tb-font-settings formControlName="tooltipDateFont"
                            [initialPreviewStyle]="{ color: rangeChartWidgetConfigForm.get('tooltipDateColor').value }"
                            [previewText]="tooltipDatePreviewFn">
          </tb-font-settings>
          <tb-color-input asBoxInput
                          colorClearButton
                          formControlName="tooltipDateColor">
          </tb-color-input>
        </div>
      </div>
      <div class="tb-form-row">
        <mat-slide-toggle class="mat-slide" formControlName="tooltipDateInterval">
          <div tb-hint-tooltip-icon="{{'tooltip.show-date-time-interval-hint' | translate}}">
            {{ 'tooltip.show-date-time-interval' | translate }}
          </div>
        </mat-slide-toggle>
      </div>
      <div class="tb-form-row space-between">
        <div>{{ 'tooltip.background-color' | translate }}</div>
        <tb-color-input asBoxInput
                        colorClearButton
                        formControlName="tooltipBackgroundColor">
        </tb-color-input>
      </div>
      <div class="tb-form-row space-between">
        <div>{{ 'tooltip.background-blur' | translate }}</div>
        <mat-form-field appearance="outline" class="number" subscriptSizing="dynamic">
          <input matInput formControlName="tooltipBackgroundBlur" type="number" min="0" step="1" placeholder="{{ 'widget-config.set' | translate }}">
          <div matSuffix>px</div>
        </mat-form-field>
      </div>
    </ng-template>
  </mat-expansion-panel>
</div>
<tb-chart-animation-settings
  formControlName="animation">
</tb-chart-animation-settings>
<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>
