<!--

    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-form-panel" [class.stroked]="stroked" [formGroup]="barWidthSettingsFormGroup">
  <div class="flex flex-row items-center justify-between">
    <div class="flex-1" translate>widgets.time-series-chart.no-aggregation-bar-width-strategy</div>
    <tb-toggle-select formControlName="strategy" selectMediaBreakpoint="xs">
      @for (strategy of timeSeriesChartNoAggregationBarWidthStrategies; track strategy) {
        <tb-toggle-option [value]="strategy">
          {{ timeSeriesChartNoAggregationBarWidthStrategyTranslations.get(strategy) | translate }}
        </tb-toggle-option>
      }
    </tb-toggle-select>
  </div>
  @if (barWidthSettingsFormGroup.get('strategy').value === TimeSeriesChartNoAggregationBarWidthStrategy.group) {
    <ng-container
      *ngTemplateOutlet="barWidth;
      context: {
        formGroup: barWidthSettingsFormGroup.get('groupWidth'),
        label: 'widgets.time-series-chart.bar-group-width'
      }">
    </ng-container>
  }
  @if (barWidthSettingsFormGroup.get('strategy').value === TimeSeriesChartNoAggregationBarWidthStrategy.separate) {
    <ng-container
      *ngTemplateOutlet="barWidth;
      context: {
        formGroup: barWidthSettingsFormGroup.get('barWidth'),
        label: 'widgets.time-series-chart.bar-width'
      }">
    </ng-container>
  }
</div>
<ng-template #barWidth let-label="label" let-formGroup="formGroup">
  <div class="tb-form-row space-between column-lt-md" [formGroup]="formGroup">
    <div translate>{{ label }}</div>
    <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="relative">
          <mat-select-trigger>
            {{ (formGroup.get('relative').value ?
            'widgets.time-series-chart.bar-width-relative' :
            'widgets.time-series-chart.bar-width-absolute') | translate }}
          </mat-select-trigger>
          <mat-option [value]="true">
            {{ 'widgets.time-series-chart.bar-width-relative' | translate }}
          </mat-option>
          <mat-option [value]="false">
            {{ 'widgets.time-series-chart.bar-width-absolute' | translate }}
          </mat-option>
        </mat-select>
      </mat-form-field>
      @if (formGroup.get('relative').value) {
        <mat-form-field class="number fixed-width" appearance="outline" subscriptSizing="dynamic">
          <input required matInput type="number" formControlName="relativeWidth" min="0.1" max="100" placeholder="{{ 'widget-config.set' | translate }}"/>
          <span matSuffix>%</span>
        </mat-form-field>
      }
      @if (!formGroup.get('relative').value) {
        <mat-form-field class="number fixed-width" appearance="outline" subscriptSizing="dynamic">
          <input required matInput type="number" formControlName="absoluteWidth" min="100" step="1" placeholder="{{ 'widget-config.set' | translate }}"/>
          <span matSuffix>ms</span>
        </mat-form-field>
      }
    </div>
  </div>
</ng-template>
