import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { CourseService } from 'src/app/service/course.service';
import { DocumentService } from 'src/app/service/document.service';
import { ExcelService } from 'src/app/service/excel.service';

@Component({
  selector: 'app-approved-list',
  templateUrl: './approved-list.component.html',
  styleUrls: ['./approved-list.component.scss']
})
export class ApprovedListComponent implements OnInit {

  constructor(
    private routes: Router,
    private excelService:ExcelService,private documentService:DocumentService,private courseService:CourseService
  ) {}
  page = 1;
  pageSize = 10;
  testdata: {
    id:string;
    img: String;
    name: String;
    details: String;
    document: String;
  }[] = [];

  ngOnInit() {

    this.testdata = [
      {
        id:'1',
        img: "assets/images/icon/excel.png",
        name: "Excel",
        details: "xxxxxxxxxxxxxxxxxxxxxxxxxxx",
        document: "0"
      },
      {
        id:'2',
        img: "assets/images/icon/document.png",
        name: "Document",
        details: "xxxxxxxxxxxxxxxxxxxxxxxxxxx",
        document: "0"
      },
      {
        id:'3',
        img: "assets/images/icon/course.png",
        name: "Course",
        details: "xxxxxxxxxxxxxxxxxxxxxxxxxxx",
        document: "0"
      },
    ];
    this.getListCount();
  }
  async getListCount(){
    try {
      const countExcel = await this.excelService.getCountContent().toPromise();
      const countDoc = await this.documentService.getCountContent().toPromise();
      const countCourse = await this.courseService.getCountContent().toPromise();
      this.testdata.forEach((x ,i) => {
        if(i == 0){
          x.document = countExcel.toString()
        }else if(i == 1){
          x.document = countDoc.toString()
        }else if(i == 2){
          x.document = countCourse.toString()
        }
      })
    } catch (error) {
      console.error('Error loading data:', error);
    }
  }
  openView(id:string){
    if(id =='1'){
      this.routes.navigate(['apps/view-list-excel/1']);
    }else if(id =='2'){
      this.routes.navigate(['apps/view-list-doc/1']);
    }else if(id =='3'){
      this.routes.navigate(['apps/view-list-course/1']);
    }
  }
}
