<!--

    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 [formGroup]="filterUserInfoFormGroup" (ngSubmit)="save()" style="width: 500px;">
  <mat-toolbar color="primary">
    <h2>{{(data.readonly ? 'filter.filter-user-params' : 'filter.edit-filter-user-params') | translate}}</h2>
    <span class="flex-1"></span>
    <button mat-icon-button
            (click)="cancel()"
            type="button">
      <mat-icon class="material-icons">close</mat-icon>
    </button>
  </mat-toolbar>
  <div mat-dialog-content>
    <div class="tb-form-panel no-padding no-border">
      <div class="tb-form-row">
        <mat-slide-toggle class="mat-slide" formControlName="editable">
          <div tb-hint-tooltip-icon="{{ 'filter.editable-hint' | translate }}">
            {{ 'filter.editable' | translate }}
          </div>
        </mat-slide-toggle>
      </div>
      <div class="tb-form-row space-between">
        <mat-slide-toggle class="mat-slide" formControlName="autogeneratedLabel">
          <div tb-hint-tooltip-icon="{{ 'filter.custom-label-hint' | translate }}">
            {{ 'filter.custom-label' | translate }}
          </div>
        </mat-slide-toggle>
        <mat-form-field subscriptSizing="dynamic" appearance="outline" class="medium-width flex-xs">
          <input matInput placeholder="{{ 'filter.display-label' | translate}}" formControlName="label">
        </mat-form-field>
      </div>
      <div class="tb-form-row space-between">
        <div class="min-w-44" translate>filter.order-priority</div>
        <mat-form-field subscriptSizing="dynamic" appearance="outline" class="medium-width flex-xs">
          <input matInput type="number" formControlName="order">
        </mat-form-field>
      </div>
      @if (showUniInput) {
        <div class="tb-form-row space-between">
          <div class="min-w-44" translate>filter.unit</div>
          <tb-unit-input supportsUnitConversion formControlName="unit" class="medium-width flex-xs">
          </tb-unit-input>
        </div>
      }
    </div>
  </div>
  <div mat-dialog-actions class="flex items-center justify-end">
    <button mat-button color="primary"
            type="button"
            [disabled]="(isLoading$ | async)"
            (click)="cancel()"
            cdkFocusInitial>
      {{ (data.readonly ? 'action.close' : 'action.cancel') | translate }}
    </button>
    @if (!data.readonly) {
      <button mat-raised-button color="primary"
              type="submit"
              [disabled]="(isLoading$ | async) || filterUserInfoFormGroup.invalid || !filterUserInfoFormGroup.dirty">
        {{ 'action.update' | translate }}
      </button>
    }
  </div>
</form>
