<!--

    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 [formGroup]="stateFormGroup" class="tb-form-table-row tb-time-series-state-row">
  <mat-form-field appearance="outline" class="tb-inline-field tb-state-label-field" subscriptSizing="dynamic">
    <input matInput formControlName="label" placeholder="{{ 'widget-config.set' | translate }}">
  </mat-form-field>
  <mat-form-field appearance="outline" class="tb-inline-field number tb-state-value-field" subscriptSizing="dynamic">
    <input matInput formControlName="value" type="number" placeholder="{{ 'widget-config.set' | translate }}">
  </mat-form-field>
  <mat-form-field class="tb-inline-field tb-state-source-field" appearance="outline" subscriptSizing="dynamic">
    <mat-select formControlName="sourceType">
      @for (type of timeSeriesStateSourceTypes; track type) {
        <mat-option [value]="type">
          {{ timeSeriesStateSourceTypeTranslations.get(type) | translate }}
        </mat-option>
      }
    </mat-select>
  </mat-form-field>
  <div class="tb-state-source-value-field">
    @if (stateFormGroup.get('sourceType').value === TimeSeriesChartStateSourceType.constant) {
      <tb-value-input
        formControlName="sourceValue"
        class="flex-1"
        [layout]="{
                    layout: 'column',
                    breakpoints: {'gt-sm': 'row'}
                 }">
      </tb-value-input>
    }
    @if (stateFormGroup.get('sourceType').value === TimeSeriesChartStateSourceType.range) {
      <mat-form-field
        appearance="outline" class="tb-inline-field number" subscriptSizing="dynamic">
        <input matInput formControlName="sourceRangeFrom" type="number" placeholder="{{ 'widgets.time-series-chart.state.from' | translate }}">
      </mat-form-field>
    }
    @if (stateFormGroup.get('sourceType').value === TimeSeriesChartStateSourceType.range) {
      <mat-form-field
        appearance="outline" class="tb-inline-field number" subscriptSizing="dynamic">
        <input matInput formControlName="sourceRangeTo" type="number" placeholder="{{ 'widgets.time-series-chart.state.to' | translate }}">
      </mat-form-field>
    }
  </div>
  <div class="tb-form-table-row-cell-buttons">
    <button type="button"
            mat-icon-button
            (click)="stateRemoved.emit()"
            matTooltip="{{ 'widgets.time-series-chart.state.remove-state' | translate }}"
            matTooltipPosition="above">
      <mat-icon>delete</mat-icon>
    </button>
  </div>
</div>
