<!--

    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.

-->
<section [formGroup]="timeInputForm" [class]="containerClass">
  <mat-form-field [class]="{'number': inlineField, 'max-w-66%': !inlineField && !sameWidthInputs, 'flex-full': !inlineField}"
                  [appearance]="inlineField ? 'outline' : appearance"
                  subscriptSizing="dynamic">
    @if (labelText && !inlineField) {
      <mat-label>{{ labelText }}</mat-label>
    }
    <input type="number" [min]="minValueValidator" step="1" matInput formControlName="time" placeholder="{{ 'widget-config.set' | translate }}">
    <div matSuffix>
      <ng-content select="[matSuffix]"></ng-content>
    </div>
    @if (inlineField) {
      @if (hasError) {
        <mat-icon matSuffix
                  matTooltipPosition="above"
                  matTooltipClass="tb-error-tooltip"
                  [matTooltip]="hasError"
                  class="tb-error">
          warning
        </mat-icon>
      }
    }
    @if ((subscriptSizing === 'fixed') && !inlineField) {
      <mat-hint>{{ hintText }}</mat-hint>
    }
    @if (hasError && !inlineField) {
      <mat-error>
        {{ hasError }}
      </mat-error>
    }
  </mat-form-field>
  <mat-form-field [class.h-fit]="!inlineField"
                  [class.max-w-33%]="!inlineField && !sameWidthInputs"
                  [class.flex-full]="!inlineField"
                  [appearance]="inlineField ? 'outline' : appearance"
                  [subscriptSizing]="inlineField ? 'dynamic' : subscriptSizing">
    @if (!inlineField) {
      <mat-label translate>rule-node-config.units</mat-label>
    }
    <mat-select formControlName="timeUnit">
      @for (timeUnit of timeUnits; track timeUnit) {
        <mat-option [value]="timeUnit">{{ timeUnitTranslations.get(timeUnit) | translate }}</mat-option>
      }
    </mat-select>
  </mat-form-field>
</section>
