import { Component, Input, OnInit } from '@angular/core';
import { ColumnConfigList } from '@app_core/components/grid-config/columnconfiglist';
import { Globals } from '@app_core/services/globals';
import { LocaleService } from '@app_core/services/localization/locale.service';
import { Employee } from '@app_models/employee';
import { AppBaseEntityListWrapper } from '@app_services/app.baseentitylist.wrapper';
import { AppDataService } from '@app_services/app.data.service';
import { EmployeeDataService } from '../employee-data.service';
import { ColumnConfig, EN_Alignment, EN_SortOrder } from '@app_core/components/grid-config/columnconfig';

@Component({
  selector: 'app-employee-list',
  templateUrl: './employee-list.component.html',
  styleUrls: ['./employee-list.component.scss']
})
export class EmployeeListComponent implements OnInit {
  @Input() public dataSource: AppBaseEntityListWrapper<Employee>;
  // @ViewChild('gridCatalog') dxGrid: DxDataGridComponent;

  public columnConfigList: ColumnConfigList = new ColumnConfigList();


  constructor(
    public employeeDataService: EmployeeDataService,
    public appDataService: AppDataService,
    public localeService: LocaleService,
    public globals: Globals,
  ) {
  }

  ngOnInit() {
    this.initColumns();
  }


  initColumns() {
    let col: ColumnConfig;

    // col = this.columnConfigList.addNumber('id', 'EmployeeId', 7);

    if (this.appDataService.showIds) col = this.columnConfigList.addNumber('Id', 'entityId', 7, 0);
    if (this.appDataService.showIds) col = this.columnConfigList.add('Nr', 'employeeNo', 7);

    col = this.columnConfigList.add('Nachname', 'lastName', 25);
    col.sortIndex = 1;
    col.sortOrder = EN_SortOrder.asc;

    col = this.columnConfigList.add('Vorname', 'firstName', 15);
    col.sortIndex = 2;
    col.sortOrder = EN_SortOrder.asc;

    // col = this.columnConfigList.add('Anrede', 'salutation', 10);
    col = this.columnConfigList.add('Kürzel', 'shortName', 7);
    col = this.columnConfigList.add('Position', 'position', 25);

    col = this.columnConfigList.add('Login', 'loginName', 15);
    col = this.columnConfigList.add('Email', 'email', 30);
    col = this.columnConfigList.add('Rang', 'rangId', 10);

    col = this.columnConfigList.add('Handynummer', 'mobilePhoneNo', 20);
    col = this.columnConfigList.add('Festnetznummer', 'phoneNo', 20);


    // if (this.appDataService.showIds) col =
    col = this.columnConfigList.add('Department', 'departmentNamesList', 30);
    col = this.columnConfigList.add('Webapps', 'webappNamesList', 25);
    col = this.columnConfigList.add('Merkmale', 'attributeNamesList', 20);
    // this.columnConfigList.addNumber('Firma-Id', 'clientId', 7);
    col = this.columnConfigList.add('Mandant', 'mandantCode', 15);
    col = this.columnConfigList.addBoolean('Aktiv', 'isActive', -50);
    col.alignment = EN_Alignment.left;

    this.columnConfigList.recalcWidth();
  }


  public loadData() {
    this.employeeDataService.loadData();
  }
}
