<!--

    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]="complexFilterFormGroup" (ngSubmit)="save()" style="width: 1200px;">
  <mat-toolbar class="justify-between" color="primary">
    <h2 translate>filter.complex-filter</h2>
    <button mat-icon-button
            (click)="cancel()"
            type="button">
      <mat-icon class="material-icons">close</mat-icon>
    </button>
  </mat-toolbar>
  <div mat-dialog-content>
    <section class="tb-form-panel">
      <div class="flex flex-row items-center justify-between">
        <div class="tb-form-panel-title"
             tb-hint-tooltip-icon="{{ data.valueType === EntityKeyValueType.DATE_TIME ? ('alarm-rule.date-time-hint' | translate) : '' }}">
          {{ 'alarm-rule.filters' | translate }}
        </div>
        <tb-toggle-select formControlName="operation"
                          selectMediaBreakpoint="xs">
          <tb-toggle-option [value]="complexOperationEnum.AND">{{ complexOperationTranslations.get(complexOperationEnum.AND) | translate }}</tb-toggle-option>
          <tb-toggle-option [value]="complexOperationEnum.OR">{{ complexOperationTranslations.get(complexOperationEnum.OR) | translate }}</tb-toggle-option>
        </tb-toggle-select>
      </div>
      <tb-alarm-rule-filter-predicate-list [valueType]="data.valueType"
                                           [arguments]="arguments"
                                           [argumentInUse]="data.argumentInUse"
                                           [operation]="complexFilterFormGroup.get('operation').value"
                                           formControlName="predicates">
      </tb-alarm-rule-filter-predicate-list>
    </section>
  </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>
    @if (!readonly) {
      <button mat-raised-button color="primary"
              type="submit"
              [disabled]="complexFilterFormGroup.invalid || !complexFilterFormGroup.dirty">
        {{ (isAdd ? 'action.add' : 'action.update') | translate }}
      </button>
    }
  </div>
</form>
