import * as keycode from '@angular/cdk/keycodes';
import { AfterViewInit, Component, EventEmitter, HostListener, Input, OnInit, Output } from '@angular/core';
import { Department, DepartmentFilter } from '@app_models/basedata/department';
import { DepartmentDataService } from '@app_modules/department/department-data.service';
import { AppBaseEntityWrapper } from '@app_services/app.baseentity.wrapper';
import { AppDataService } from '@app_services/app.data.service';
import * as Cnst from '@app_core/consts';
import { AuthorizeService } from '@app_core/services/authorize.service';
import { LoginPopupComponent } from '@app_core/components/login/login-popup/login-popup.component';

@Component({
  selector: 'app-department-filter',
  templateUrl: './department-filter.component.html',
  styleUrls: ['./department-filter.component.scss'],
})

export class DepartmentFilterComponent implements OnInit, AfterViewInit {

  constructor(
    public departmentDataService: DepartmentDataService,
    public appDataService: AppDataService,
    public authService: AuthorizeService,
  ) { }
  @Input() public filterObject: DepartmentFilter;
  @Input() departmentDetails: AppBaseEntityWrapper<Department>;
  @Output() public filterFetch = new EventEmitter();

  public dropDownAllCaption = Cnst.EN_DropDownConst4Filter.AllCaption;
  public dropDownAllValueString = Cnst.EN_DropDownConst4Filter.AllValueString;
  public dropDownAllValueInt = Cnst.EN_DropDownConst4Filter.AllValueInt;
  public allCaption = Cnst.EN_DropDownConst4Filter.AllCaption;
  public allValue: number = Cnst.EN_DropDownConst4Filter.AllValueInt;
  public noneCaption = Cnst.EN_DropDownConst4Filter.NoneCaption;
  public noneValue = Cnst.EN_DropDownConst4Filter.NoneValueInt;

  ngOnInit() { }
  ngAfterViewInit() { }
  onFilterClick() {
    if (this.departmentDetails.inViewMode) this.filterFetch.emit();
  }
  onClearClick() {
    this.filterObject.filterReset();
  }


  @HostListener('window:keydown', ['$event'])
  keyboardInput(event: any) {
    if (!LoginPopupComponent.LOGIN_IS_SHOWN && !this.departmentDetails.keyDownListenerStopped) {
      if (event.ctrlKey) {
        switch (event.which) {
          case keycode.F: //Ctrl + 'f'
            event.stopPropagation();
            this.onFilterClick();
            return false; //processed
        }
      }
    }
    return true; //default processing
  }

}
