import { Component, Input, OnInit } from '@angular/core';
import { IFilterOption } from '@shared/ui-api/interfaces/route-config/filter-option';
import { FilteringService } from '@shared/ui-api/filtering.service';
import { NotificationService } from '@shared/ui-api/notification.service';

@Component({
  selector: 'app-objects-list-filtering-boolean',
  templateUrl: './objects-list-filtering-boolean.component.html',
  styleUrls: ['./objects-list-filtering-boolean.component.scss']
})
export class ObjectsListFilteringBooleanComponent implements OnInit {
  @Input() filterOption: IFilterOption;
  filteringValue: boolean;

  constructor(private filterService: FilteringService, private notificationService: NotificationService) {
  }

  applyFiltering() {
    if (typeof this.filteringValue !== 'boolean') {
      return this.notificationService.showMessage($localize`Please enter a valid value`);
    }
    this.filterService.addFilter(
      this.filterOption.field,
      this.filteringValue ? 'true' : 'false',
      this.filterOption?.resetQueryParams,
    );
  }

  ngOnInit() {
  }

}
