<!--

    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="flex flex-1 flex-row items-center justify-start gap-4" [formGroup]="filterPredicateFormGroup">
  <div class="tb-form-panel no-border no-padding-right flex-1" style="flex-direction: row">
    @switch (type) {
      @case (filterPredicateType.STRING) {
        <div class="tb-form-row no-padding no-border column-xs flex-1/ w-full max-w-30% xs:max-w-full">
          <mat-form-field hideRequiredMarker class="flex-1" appearance="outline" subscriptSizing="dynamic">
            <mat-select required formControlName="operation" placeholder="{{'filter.operation.operation' | translate}}">
              @for (operation of stringOperations; track operation) {
                <mat-option [value]="operation">
                  {{stringOperationTranslationMap.get(stringOperation[operation]) | translate}}
                </mat-option>
              }
            </mat-select>
          </mat-form-field>
          @if (filterPredicateFormGroup.get('operation').value !== stringOperation.NO_DATA) {
            <mat-chip-listbox formControlName="ignoreCase" [hideSingleSelectionIndicator]="true">
              <mat-chip-option color="primary" [value]="true">{{ 'alarm-rule.ignore-case' | translate }}</mat-chip-option>
            </mat-chip-listbox>
          }
        </div>
      }
      @case (filterPredicateType.NUMERIC) {
        <div class="tb-form-row no-border no-padding no-border w-full max-w-30%">
          <mat-form-field hideRequiredMarker class="flex-1" appearance="outline" subscriptSizing="dynamic">
            <mat-select required formControlName="operation" placeholder="{{'filter.operation.operation' | translate}}">
              @for (operation of numericOperations; track operation) {
                <mat-option [value]="operation">
                  {{numericOperationTranslations.get(numericOperationEnum[operation]) | translate}}
                </mat-option>
              }
            </mat-select>
          </mat-form-field>
        </div>
      }
      @case (filterPredicateType.BOOLEAN) {
        <div class="tb-form-row no-border no-padding no-border w-full max-w-30%">
          <mat-form-field hideRequiredMarker class="flex-1"  appearance="outline" subscriptSizing="dynamic">
            <mat-select required formControlName="operation" placeholder="{{'filter.operation.operation' | translate}}">
              @for (operation of booleanOperations; track operation) {
                <mat-option [value]="operation">
                  {{booleanOperationTranslations.get(booleanOperationEnum[operation]) | translate}}
                </mat-option>
              }
            </mat-select>
          </mat-form-field>
        </div>
      }
      @case (filterPredicateType.COMPLEX) {
        <div class="tb-form-row no-border no-padding flex-1">
          <button type="button" style="--mat-button-outlined-horizontal-padding: 3px 0px 12px;"
                  class="block w-full"
                  mat-stroked-button [color]="predicateValid ? 'primary' : 'warn'"
                  (click)="openComplexFilterDialog()">
            <div class="flex items-center gap-2">
              <span class="w-full text-start" translate>filter.complex-filter</span>
              <mat-icon class="tb-mat-20 tb-alarm-rule-schedule-edit-icon">{{ disabled ? 'visibility' : 'edit' }} </mat-icon>
            </div>
          </button>
        </div>
      }
    }
    <tb-alarm-rule-filter-predicate-no-data-value class="flex-full" [class.!hidden]="!(filterPredicateFormGroup.get('operation').value === stringOperation.NO_DATA)"
                                                  [arguments]="arguments"
                                                  [argumentInUse]="argumentInUse"
                                                  [valueType]="valueType"
                                                  formControlName="duration">
    </tb-alarm-rule-filter-predicate-no-data-value>
    <tb-alarm-rule-filter-predicate-value class="flex-full" [class.!hidden]="!(filterPredicateFormGroup.get('operation').value !== stringOperation.NO_DATA && type !== filterPredicateType.COMPLEX)"
                                          [arguments]="arguments"
                                          [argumentInUse]="argumentInUse"
                                          [valueType]="valueType"
                                          formControlName="value">
    </tb-alarm-rule-filter-predicate-value>
  </div>
</div>
