<!--

    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]="limitForm" class="tb-form-table-row overflow-hidden items-start">
  <div class="flex-shrink capitalize" [class]="isPanelView ? 'basis-10' : 'basis-1/5'">
    {{ labelKey | translate}}
  </div>
  <div class="flex-grow flex-shrink flex flex-col gap-2 gt-sm:flex-row gt-sm:gap-3" [class]="isPanelView ? 'basis-1/2' : 'basis-40%'">
    <mat-form-field class="tb-inline-field flex-1" appearance="outline" subscriptSizing="dynamic">
      <mat-select formControlName="type">
        @for (type of ValueSourceTypes; track type) {
          <mat-option [value]="type">
            {{ ValueSourceTypeTranslation.get(type) | translate }}
          </mat-option>
        }
      </mat-select>
    </mat-form-field>
    @if (limitForm.get('type').value === ValueSourceType.entity) {
      <tb-entity-alias-input
        required
        class="flex-1"
        [aliasController]="aliasController"
        formControlName="entityAlias">
      </tb-entity-alias-input>
    }
  </div>
  <div class="flex-grow flex-shrink max-w-5/12" [class]="isPanelView ? 'basis-1/2' : 'basis-40%'">
    @if (limitForm.get('type').value === ValueSourceType.constant) {
      <mat-form-field
        appearance="outline" class="tb-inline-field !w-full number" subscriptSizing="dynamic"
        [class.tb-suffix-absolute]="!limitForm.get('value').value">
        <input matInput formControlName="value" type="number" placeholder="{{ 'widgets.chart.chart-axis.scale-auto' | translate }}">
      </mat-form-field>
    }
    @if (limitForm.get('type').value === ValueSourceType.latestKey) {
      <tb-data-key-input
        required
        requiredText="widgets.chart.chart-axis.key-required"
        [datasourceType]="datasource?.type"
        [entityAliasId]="datasource?.entityAliasId"
        [deviceId]="datasource?.deviceId"
        [aliasController]="aliasController"
        [dataKeyType]="datasource?.type === DatasourceType.function ? DataKeyType.function : null"
        [dataKeyTypes]="[DataKeyType.attribute, DataKeyType.timeseries]"
        [callbacks]="callbacks"
        [editable]="false"
        [formControl]="latestKeyFormControl">
      </tb-data-key-input>
    }
    @if (limitForm.get('type').value === ValueSourceType.entity) {
      <tb-data-key-input
        required
        requiredText="widgets.chart.chart-axis.entity-key-required"
        [datasourceType]="DatasourceType.entity"
        [aliasController]="aliasController"
        [entityAlias]="limitForm.get('entityAlias').value"
        [dataKeyTypes]="[DataKeyType.attribute, DataKeyType.timeseries]"
        [callbacks]="callbacks"
        [editable]="false"
        [formControl]="entityKeyFormControl">
      </tb-data-key-input>
    }
  </div>
</div>
