import { ChangeDetectionStrategy, Component, EventEmitter, Output } from '@angular/core';
import { UiFilter } from '@ui/filter';
import { TaskCalendarStore } from '../../task-calendar.store';

@Component({
  selector: 'page-task-calendar-filter',
  templateUrl: 'task-calendar-filter.component.html',
  styleUrls: ['task-calendar-filter.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TaskCalendarFilterComponent {
  @Output() exitFilter = new EventEmitter<void>();

  filter$ = this.taskCalendarStore.selectFilter;

  fetching$ = this.taskCalendarStore.selectFetching;

  message$ = this.taskCalendarStore.selectMessage;

  constructor(private taskCalendarStore: TaskCalendarStore) {}

  applyFilter(filters: UiFilter) {
    this.taskCalendarStore.setFilter({ filters });
    this.taskCalendarStore.loadItems();
    this.exitFilter.emit();
  }

  resetFilter() {
    this.taskCalendarStore.loadFilter();
  }
}
