<!--

    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.

-->
@if (panelMode) {
  <ng-container *ngTemplateOutlet="deviceFilterPanel"></ng-container>
} @else {
  @if (buttonMode) {
    <button color="primary"
            matTooltip="{{buttonDisplayValue}}"
            matTooltipPosition="above"
            mat-stroked-button
            (click)="toggleDeviceFilterPanel($event)">
      <mat-icon>filter_list</mat-icon>{{buttonDisplayValue}}
    </button>
  } @else {
    <div class="tb-device-filter-config-component tb-form-panel no-padding no-border" [formGroup]="deviceInfoFilterForm">
      <div class="tb-form-row column-xs">
        <div class="fixed-title-width" translate>device-profile.device-profile</div>
        <tb-device-profile-autocomplete
          class="flex-1"
          formControlName="deviceProfileId"
          [inlineField]="true"
          [displayAllOnEmpty]="true"
          (deviceProfileChanged)="deviceProfileChanged($event)"
          [editProfileEnabled]="false"
          [addNewProfile]="false">
        </tb-device-profile-autocomplete>
      </div>
      <div class="tb-form-row column-xs">
        <div class="fixed-title-width" translate>device.device-state</div>
        <mat-form-field class="flex-1" appearance="outline" subscriptSizing="dynamic">
          <mat-select formControlName="active" placeholder="{{ 'device.any' | translate }}">
            <mat-option>{{ 'device.any' | translate }}</mat-option>
            <mat-option [value]="true">{{ 'device.active' | translate }}</mat-option>
            <mat-option [value]="false">{{ 'device.inactive' | translate }}</mat-option>
          </mat-select>
        </mat-form-field>
      </div>
    </div>
  }
}
<ng-template #deviceFilterPanel>
  <form class="mat-content mat-padding flex flex-col" (ngSubmit)="update()">
    <ng-container *ngTemplateOutlet="deviceFilter"></ng-container>
    <div class="tb-panel-actions flex flex-row items-center justify-end">
      <button type="button"
              mat-button
              color="primary"
              (click)="reset()">
        {{ 'action.reset' | translate }}
      </button>
      <span class="flex-1"></span>
      <button type="button"
              mat-button
              (click)="cancel()">
        {{ 'action.cancel' | translate }}
      </button>
      <button type="submit"
              mat-raised-button
              color="primary"
              [disabled]="deviceInfoFilterForm.invalid || !deviceInfoFilterForm.dirty">
        {{ 'action.update' | translate }}
      </button>
    </div>
  </form>
</ng-template>
<ng-template #deviceFilter>
  <div class="tb-device-filter-config-component tb-form-panel no-padding no-border" [formGroup]="deviceInfoFilterForm">
    <div class="tb-form-row column-xs">
      <div class="fixed-title-width" translate>device-profile.device-profile</div>
      <tb-device-profile-autocomplete
        class="flex-1"
        formControlName="deviceProfileId"
        [inlineField]="true"
        [displayAllOnEmpty]="true"
        (deviceProfileChanged)="deviceProfileChanged($event)"
        [editProfileEnabled]="false"
        [addNewProfile]="false">
      </tb-device-profile-autocomplete>
    </div>
    <div class="tb-form-row column-xs">
      <div class="fixed-title-width" translate>device.device-state</div>
      <mat-form-field class="flex-1" appearance="outline" subscriptSizing="dynamic">
        <mat-select formControlName="active" placeholder="{{ 'device.any' | translate }}">
          <mat-option>{{ 'device.any' | translate }}</mat-option>
          <mat-option [value]="true">{{ 'device.active' | translate }}</mat-option>
          <mat-option [value]="false">{{ 'device.inactive' | translate }}</mat-option>
        </mat-select>
      </mat-form-field>
    </div>
  </div>
</ng-template>
