<!--

    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.

-->
<form (ngSubmit)="save()" style="width: 400px;" class="user-filter-dialog">
  <mat-toolbar color="primary" class="justify-between">
    <h2>{{ filter.filter | customTranslate }}</h2>
    <button mat-icon-button
            (click)="cancel()"
            type="button">
      <mat-icon class="material-icons">close</mat-icon>
    </button>
  </mat-toolbar>
  <div mat-dialog-content>
    @for (userInputControl of userInputsFormArray.controls; track userInputControl) {
      @switch (userInputControl.controls.valueType.value) {
        @case (valueTypeEnum.STRING) {
          <mat-form-field class="mat-block" appearance="outline">
            <mat-label>{{ userInputControl.controls.label.value | customTranslate }}</mat-label>
            <input matInput [formControl]="userInputControl.controls.value">
          </mat-form-field>
        }
        @case (valueTypeEnum.NUMERIC) {
          <mat-form-field class="mat-block numeric-field" appearance="outline">
            <mat-label>{{ userInputControl.controls.label.value | customTranslate }}</mat-label>
            <input required type="number" matInput [formControl]="userInputControl.controls.value">
            @if (userInputControl.controls.unitSymbol.value) {
              <div matSuffix class="mr-2">
                {{ userInputControl.controls.unitSymbol.value }}
              </div>
            }
          </mat-form-field>
        }
        @case (valueTypeEnum.DATE_TIME) {
          <tb-datetime [formControl]="userInputControl.controls.value"
                       [fieldClass]="'mat-block'"
                       [dateText]="userInputControl.controls.label.value | customTranslate"
                       appearance="outline"
                       required></tb-datetime>
        }
        @case (valueTypeEnum.BOOLEAN) {
          <mat-slide-toggle [formControl]="userInputControl.controls.value">
            <span class="inline-block max-w-72" tbTruncateWithTooltip>
              {{ userInputControl.controls.label.value | customTranslate }}
            </span>
          </mat-slide-toggle>
        }
      }
    }
  </div>
  <div mat-dialog-actions class="flex items-center justify-end">
    <button mat-button color="primary"
            type="button"
            (click)="cancel()" cdkFocusInitial>
      {{ 'action.cancel' | translate }}
    </button>
    <button mat-raised-button color="primary"
            type="submit"
            [disabled]="userInputsFormArray.invalid || !userInputsFormArray.dirty">
      {{ 'action.update' | translate }}
    </button>
  </div>
</form>
