import { Component, EventEmitter, Input, OnInit, } from '@angular/core';
import { Bu1Model, MyBu1Model } from 'src/app/shared/model/bu1.model';
import { Bu1Service } from 'src/app/shared/services/bu1.service';

@Component({
  selector: 'app-department-register',
  templateUrl: './department-register.component.html',
  styleUrls: ['./department-register.component.scss']
})
export class DepartmentRegisterComponent implements OnInit {
  currentPage = 1
  page = Array.from({ length: 1 }, (_, i) => i + 1);
  bu1List: Bu1Model[] = []
  bu1: Bu1Model = new MyBu1Model({})
  search = ""
  constructor(private bu1Service: Bu1Service) { }
  ngOnInit(): void {
    this.getBu1List()
  }
  getBu1List() {
    this.bu1Service.getList().subscribe(response => {
      this.bu1List = response
      this.searchChange()
    })
  }
  searchChange() {
    this.currentPage = 1
    this.page = Array.from({ length: Math.ceil(this.bu1ListFilter().length / 10) }, (_, i) => i + 1);
  }
  bu1ListFilter() {
    return this.bu1List.filter(x => x.bu1id.toLowerCase().includes(this.search) ||
      x.tdesc.toLowerCase().includes(this.search) ||
      x.edesc.toLowerCase().includes(this.search))
  }
  selectBu1(bu1: Bu1Model) {
    this.bu1 = new MyBu1Model(bu1)
  }
  addBu1() {
    // this.bu1Service.post(this.bu1).subscribe((response:any) => {
    //   if (response.success) {
    //     this.getBu1List()
    //   }
    // })
  }
  deleteBu1(bu1: Bu1Model) {
    // this.bu1Service.delete(new MyBu1Model(bu1)).subscribe((response:any) => {
    //   if (response.success) {
    //     this.getBu1List()
    //   }
    // })
  }


}
