import { Component, Input, OnInit, ViewChild, AfterViewInit } from '@angular/core';
import { Department } from '@app_models/basedata/department';
import { AppBaseEntityWrapper } from '@app_services/app.baseentity.wrapper';
import { AppDataService } from '@app_services/app.data.service';
import { CostCentre } from '@app_models/basedata/cost-centre';
import { Employee } from '@app_models/employee';
import { EmployeeDataService } from '@app_modules/employee/employee-data.service';
import { DepartmentDataService } from '@app_modules/department/department-data.service';
import { NgForm } from '@angular/forms';

@Component({
  selector: 'app-department-content',
  templateUrl: './department-content.component.html',
  styleUrls: ['./department-content.component.scss']
})
export class DepartmentContentComponent implements OnInit, AfterViewInit {
  @ViewChild('detailForm') detailForm: NgForm;
  @Input() departmentDetails: AppBaseEntityWrapper<Department>;


  public get department(): Department {
    return this.departmentDetails.entity;
  }


  public get employeeList(): Employee[] {
    return this.departmentService.employeeList.items;
  }



  public get costCentreList(): CostCentre[] {
    return this.appDataService.costCentreList.items;
  }


  constructor(
    private appDataService: AppDataService,
    private departmentService: DepartmentDataService) { }

  ngOnInit() {
  }

  ngAfterViewInit(): void {
    this.departmentDetails.detailForm = this.detailForm;
  }

  depNameWasChanged() {
    if (!this.department.departmentName) return;
    if (!this.department.departmentNameFolder) this.department.departmentNameFolder = this.department.departmentName;
    if (!this.department.adGroupDepartmentName) this.department.adGroupDepartmentName = this.department.departmentName;
  }
}
