<!--

    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-threshold-settings-panel" [formGroup]="thresholdSettingsFormGroup">
  <div class="tb-threshold-settings-title">{{ panelTitle | translate }}</div>
  <div class="tb-threshold-settings-panel-content">
    @if (!hideYAxis) {
      <div class="tb-form-row space-between column-xs">
        <div translate>widgets.time-series-chart.axis.y-axis</div>
        <mat-form-field class="medium-width" appearance="outline" subscriptSizing="dynamic">
          <mat-select formControlName="yAxisId">
            @for (yAxis of yAxisIds; track yAxis) {
              <mat-option [value]="yAxis">
                {{ yAxis }}
              </mat-option>
            }
          </mat-select>
        </mat-form-field>
      </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 column-lt-md">
      <mat-slide-toggle class="mat-slide" formControlName="showLabel">
        {{ 'widgets.time-series-chart.threshold.label' | translate }}
      </mat-slide-toggle>
      <div class="flex lt-md:flex-1 flex-row items-center justify-start gap-2">
        <mat-form-field class="medium-width lt-md:flex-1" appearance="outline" subscriptSizing="dynamic">
          <mat-select formControlName="labelPosition">
            @for (position of timeSeriesThresholdLabelPositions; track position) {
              <mat-option [value]="position">
                {{ timeSeriesThresholdLabelPositionTranslations.get(position) | translate }}
              </mat-option>
            }
          </mat-select>
        </mat-form-field>
        <tb-font-settings formControlName="labelFont"
                          clearButton
                          disabledLineHeight
                          forceSizeUnit="px"
                          [previewText]="labelPreviewFn">
        </tb-font-settings>
        <tb-color-input asBoxInput
                        colorClearButton
                        formControlName="labelColor">
        </tb-color-input>
      </div>
    </div>
    <div class="tb-form-row space-between">
      <mat-slide-toggle class="mat-slide" formControlName="enableLabelBackground">
        {{ 'widgets.time-series-chart.threshold.label-background' | translate }}
      </mat-slide-toggle>
      <tb-color-input asBoxInput
                      colorClearButton
                      formControlName="labelBackground">
      </tb-color-input>
    </div>
    <div class="tb-form-panel">
      <div class="tb-form-panel-title" translate>widgets.time-series-chart.threshold.line-appearance</div>
      <div class="tb-form-row space-between">
        <div translate>widgets.time-series-chart.threshold.line-color</div>
        <tb-color-input asBoxInput
                        colorClearButton
                        formControlName="lineColor">
        </tb-color-input>
      </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 class="tb-form-row column-xs">
        <div translate>widgets.time-series-chart.threshold.start-symbol</div>
        <div class="tb-flex row flex-end">
          <mat-form-field class="medium-width lt-md:flex-1" appearance="outline" subscriptSizing="dynamic">
            <mat-select formControlName="startSymbol">
              @for (shape of chartShapes; track shape) {
                <mat-option [value]="shape">
                  {{ chartShapeTranslations.get(shape) | translate }}
                </mat-option>
              }
            </mat-select>
          </mat-form-field>
          <div class="tb-small-label" translate>widgets.time-series-chart.threshold.symbol-size</div>
          <mat-form-field appearance="outline" class="number fixed-width" subscriptSizing="dynamic">
            <input matInput formControlName="startSymbolSize"
                   type="number" min="0" step="1" placeholder="{{ 'widget-config.set' | translate }}">
          </mat-form-field>
        </div>
      </div>
      <div class="tb-form-row column-xs">
        <div translate>widgets.time-series-chart.threshold.end-symbol</div>
        <div class="tb-flex row flex-end">
          <mat-form-field class="medium-width lt-md:flex-1" appearance="outline" subscriptSizing="dynamic">
            <mat-select formControlName="endSymbol">
              @for (shape of chartShapes; track shape) {
                <mat-option [value]="shape">
                  {{ chartShapeTranslations.get(shape) | translate }}
                </mat-option>
              }
            </mat-select>
          </mat-form-field>
          <div class="tb-small-label" translate>widgets.time-series-chart.threshold.symbol-size</div>
          <mat-form-field appearance="outline" class="number fixed-width" subscriptSizing="dynamic">
            <input matInput formControlName="endSymbolSize"
                   type="number" min="0" step="1" placeholder="{{ 'widget-config.set' | translate }}">
          </mat-form-field>
        </div>
      </div>
    </div>
  </div>
  <div class="tb-threshold-settings-panel-buttons">
    <button mat-button
            color="primary"
            type="button"
            (click)="cancel()">
      {{ 'action.cancel' | translate }}
    </button>
    <button mat-raised-button
            color="primary"
            type="button"
            (click)="applyThresholdSettings()"
            [disabled]="thresholdSettingsFormGroup.invalid || !thresholdSettingsFormGroup.dirty">
      {{ 'action.apply' | translate }}
    </button>
  </div>
</div>
