import { Component, EventEmitter, Input, Output } from '@angular/core';
import { ToastrService } from 'ngx-toastr';
export interface DataModel {
  code: string,
  name: string,
  type: string
}
@Component({
  selector: 'app-indicators-and-curriculum',
  templateUrl: './indicators-and-curriculum.component.html',
  styleUrls: ['./indicators-and-curriculum.component.scss']
})
export class IndicatorsAndCurriculumComponent {
  @Output() sendPathTitle: EventEmitter<string[]> = new EventEmitter<string[]>();
  editTab = false
  currentPage = 1
  search = ""
  page = Array.from({ length: 1 }, (_, i) => i + 1);

  dataList: DataModel[] = [
    { code: "CC-01", name: "จิตสำนึกด้านความปลอดภัยและคุณภาพ (Safety & Quality)", type: "CC" },
    { code: "CC-02", name: "การทำงานเป็นทีมแบบ TAT (TAT Teamwork)", type: "CC" },
    { code: "CC-03", name: "ความรับผิดชอบในหน้าที่และโปร่งใส (Accountability & Ethics)", type: "CC" },
    { code: "MC-01", name: "การคิดเชิงกลยุทธ์ (Strategic Thinking)", type: "MC" },
    { code: "MC-02", name: "การมีทัศนคติที่เติบโต (Mindset-Growth)", type: "MC" },
    { code: "PC-01", name: "ความรู้ด้านกฎหมายแรงงาน, กฎหมายแพ่งพาณิชย์, กฎหมายอาญา", type: "PC" },
  ]
  constructor(private toastr: ToastrService) {
    this.pathTitleChange()
    this.searchChange()
  }

  pathTitleChange() {
    this.sendPathTitle.emit(this.editTab ? ['การประเมินสมรรถนะ', 'การจัดการสมรรถนะ', 'ตัวชี้วัดเเละหลักสูตร', 'การจัดการตัวชี้วัดเเละหลักสูตร'] : ['การประเมินสมรรถนะ', 'การจัดการสมรรถนะ', 'ตัวชี้วัดเเละหลักสูตร'])
  }

  searchChange() {
    this.currentPage = 1;
    const filteredData = this.dataListFilter();
    this.page = Array.from({ length: Math.ceil(filteredData.length / 10) }, (_, i) => i + 1);
  }

  dataListFilter() {
    return this.dataList.filter(x => {
      const match = x.code.includes(this.search) || x.name.includes(this.search);
      return match;
    });
  }


  showSuccess() {
    this.toastr.success('บันทึกข้อมูลสำเร็จ', 'เเจ้งเตือน', {
      timeOut: 3000,
      positionClass: 'toast-top-right',
    });
  }
  showSuccessEdit() {
    this.toastr.success('เเก้ไขข้อมูลสำเร็จ', 'เเจ้งเตือน', {
      timeOut: 3000,
      positionClass: 'toast-top-right',
    });
  }
  showSuccessDelete() {
    this.toastr.success('ลบข้อมูลสำเร็จ', 'เเจ้งเตือน', {
      timeOut: 3000,
      positionClass: 'toast-top-right',
    });
  }
  addUser() {
    console.log('เพิ่มผู้ใช้งาน');
  }

  deleteUser() {
    console.log('ลบผู้ใช้งาน');
  }

  editUser() {
    console.log('แก้ไขผู้ใช้งาน');
  }

  
}