<!--

    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 class="tb-filter flex flex-col" [formGroup]="eventFilterFormGroup" (ngSubmit)="update()">
  <div class="tb-filter-container mat-padding flex flex-col">
    @for (column of showColumns; track column) {
      @switch (column.key) {
        @case (isSelector(column.key)) {
          <mat-form-field appearance="outline">
            <mat-label>{{ column.title | translate}}</mat-label>
            <mat-select [formControlName]="column.key">
              <mat-option [value]="">{{ 'event.all-events' | translate}}</mat-option>
              @for (value of selectorValues(column.key); track value) {
                <mat-option [value]="value">
                  {{ value }}
                </mat-option>
              }
            </mat-select>
          </mat-form-field>
        }
        @case (isNumberFields(column.key)) {
          <mat-form-field appearance="outline">
            <mat-label>{{ column.title | translate}}</mat-label>
            <input matInput type="number" min="0" [name]="column.key" [formControlName]="column.key">
            @if (eventFilterFormGroup.get(column.key).hasError('min')) {
              <mat-error>
                {{ 'event.min-value' | translate }}
              </mat-error>
            }
          </mat-form-field>
        }
        @case ('isError') {
          <tb-checkbox formControlName="isError" [falseValue]="''"
                       (ngModelChange)="changeIsError($event)">
            {{ 'event.has-error' | translate }}
          </tb-checkbox>
        }
        @case ('errorStr') {
          <mat-form-field [class.!hidden]="!showErrorMsgFields()" appearance="outline">
            <mat-label>{{ column.title | translate}}</mat-label>
            <input matInput type="text" name="errorSearchText" formControlName="errorStr">
          </mat-form-field>
        }
        @default {
          <mat-form-field appearance="outline">
            <mat-label>{{ column.title | translate}}</mat-label>
            <input matInput type="text" [name]="column.key" [formControlName]="column.key">
          </mat-form-field>
        }
      }
    }
  </div>
  <div class="tb-panel-actions mat-padding flex flex-row items-center justify-end">
    <button type="button"
            mat-button
            (click)="cancel()">
      {{ 'action.cancel' | translate }}
    </button>
    <button type="submit"
            mat-raised-button
            color="primary"
            [disabled]="eventFilterFormGroup.invalid || !eventFilterFormGroup.dirty">
      {{ 'action.update' | translate }}
    </button>
  </div>
</form>
