<!--

    Copyright © 2016-2023 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.

-->
<ng-container *ngIf="panelMode; else componentMode">
  <ng-container *ngTemplateOutlet="deviceFilterPanel"></ng-container>
</ng-container>
<ng-template #componentMode>
  <ng-container *ngIf="buttonMode; else deviceFilter">
    <button color="primary"
            matTooltip="{{buttonDisplayValue}}"
            matTooltipPosition="above"
            mat-stroked-button
            (click)="toggleDeviceFilterPanel($event)">
      <mat-icon>filter_list</mat-icon>{{buttonDisplayValue}}
    </button>
  </ng-container>
</ng-template>
<ng-template #deviceFilterPanel>
  <form fxLayout="column" class="mat-content mat-padding" (ngSubmit)="update()">
    <ng-container *ngTemplateOutlet="deviceFilter"></ng-container>
    <div fxLayout="row" class="tb-panel-actions" fxLayoutAlign="end center">
      <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 fxLayout="column" fxLayoutGap="16px" style="min-width: 280px;" [formGroup]="deviceInfoFilterForm">
    <tb-device-profile-autocomplete
      subscriptSizing="dynamic"
      formControlName="deviceProfileId"
      [displayAllOnEmpty]="true"
      (deviceProfileChanged)="deviceProfileChanged($event)"
      [editProfileEnabled]="false">
    </tb-device-profile-autocomplete>
    <mat-form-field>
      <mat-label translate>device.device-state</mat-label>
      <mat-select formControlName="active">
        <mat-option value="">
          {{ '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>
</ng-template>
