import { Component, EventEmitter, Output } from '@angular/core';
export interface DataModel {
  code: string,
  bis: BisModel[],
  startDate: string,
  endDate: string
}
export interface BisModel {
  name: string,
  oj: boolean,
  cm: boolean,
  t: boolean,
  cdr: CdrModel
}
export interface CdrModel {
  check: boolean,
  name: string,
  code: string
}
@Component({
  selector: 'app-idp-evalution',
  templateUrl: './idp-evalution.component.html',
  styleUrls: ['./idp-evalution.component.scss']
})
export class IdpEvalutionComponent {
  @Output() sendPageEvalution: EventEmitter<string> = new EventEmitter<string>();
  pathTitle = ['การประเมินผล', 'ประเมินผล']
  hoveredCode: string | null = null;
  dataList: DataModel[] = [{
    code: "CC-01",
    bis: [{
      name: "สอนงานด้านความปลอดภัย และคุณภาพของบริษัทให้กับพนักงานในหน่วยงาน",
      oj: true,
      cm: false,
      t: true,
      cdr: {
        check: false,
        name: "จิตใต้สำนึกด้านความปลอดภัยและคุณภาพ (Safety & Quality) สำหรับระดับพนักงาน S3-S4",
        code: "CC-01-4"
      }
    }, {
      name: "ติดตามและปรับปรุงการทำงานด้านความปลอดภัยและ คุณภาพของทีมงาน",
      oj: false,
      cm: false,
      t: false,
      cdr: {
        check: false,
        name: "",
        code: ""
      }
    }],
    startDate: "01-01-2023",
    endDate: "31-12-2023"
  }, {
    code: "CC-02",
    bis: [{
      name: "สอนงาน และพัฒนาทีมงานให้เกิดการทำงานเป็นทีมโดยยึดเป้าหมายเดียวกัน (TAT Goal) และคำนึงถึงความต้องการของลูกค้าเป็นหลัก (Next Customer)",
      oj: true,
      cm: false,
      t: false,
      cdr: {
        check: false,
        name: "",
        code: ""
      }
    }],
    startDate: "01-01-2023",
    endDate: "31-12-2023"
  }, {
    code: "CC-03",
    bis: [],
    startDate: "",
    endDate: ""
  }]

  getNestedValue(obj: any, path: string) {
    return path.split('.').reduce((acc, key) => acc && acc[key], obj);
  }
  checkBg(data: any[], field: string) {
    return data.every(x => !this.getNestedValue(x, field));
  }
  dataListFilter() {
    return this.dataList
  }

  returnPage() {
    this.sendPageEvalution.emit("")
  }
}