import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {PayInListFilterModel} from '../models/pay-in-list.filter.model';

@Component({
  selector: 'app-popup-income-filter',
  templateUrl: './popup-income-filter.component.html',
  styleUrls: ['./popup-income-filter.component.scss']
})
export class PopupIncomeFilterComponent implements OnInit {
  public opened = false;
  public filter: PayInListFilterModel;
  @Output() public DoFilter: EventEmitter<PayInListFilterModel> = new EventEmitter<PayInListFilterModel>();
  constructor() { }

  ngOnInit(): void {
    if ( this.filter === undefined) {
      this.filter = new PayInListFilterModel({});
    }
  }

  public close(status: string): void {
    this.opened = false;

    if (status === 'filter' ){
      this.DoFilter.emit(this.filter);
    }

    if (status === 'clear') {
      this.clearFilter();
      this.DoFilter.emit(this.filter);
    }
  }

  private clearFilter(): void {
    this.filter = new PayInListFilterModel({});
  }

  public show(): void {
    this.opened = true;
  }
}

