import {
  Component,
  OnInit,
  ChangeDetectionStrategy,
  OnChanges,
  Input,
  Output,
  EventEmitter,
  ViewChild,
  ChangeDetectorRef
} from '@angular/core';
import {BaseList} from "../../../../../../core/base/base-list";
import {OBJECT} from "../../../../../../core/enum/role";
import {AppTokenService} from "../../../../../../core/service/security/app-token.service";
import {MatSort, Sort} from '@angular/material/sort';
import {LiveAnnouncer} from '@angular/cdk/a11y';

@Component({
  selector: 'app-create-exam-information-list',
  templateUrl: './create-exam-information-list.component.html',
  styleUrls: ['./create-exam-information-list.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class CreateExamInformationListComponent extends BaseList implements OnInit, OnChanges {
  @ViewChild(MatSort) sort: MatSort;
  @Input() subjectList: any = [];
  role = [];
  roleConfig = OBJECT;
  @Output() edit = new EventEmitter();
  @Output() view = new EventEmitter();
  @Output() expand = new EventEmitter();
  @Output() delete = new EventEmitter();
  column = [
    '1',
    'testing_information_code',
    'testing_information_name',
    'academic_semester_code',
    'academic_year_code',
    '8',
    'count_subject',
    'created_by',
    '10',
    'created_datetime',
    '7'
  ];
  reload: boolean;

  constructor(
    private appTokenSV: AppTokenService,
    private cdr: ChangeDetectorRef,
  ) {
    super();
  }

  ngOnInit(): void {
    this.role = this.appTokenSV.user.rights;
    this.reload = false;
    setTimeout(() => {
      this.reload = true;
      this.cdr.detectChanges();
    }, 5000);
  }

  ngOnChanges(){
    this.subjectList = this.updateMatTable(this.subjectList ? this.subjectList : []);
  }

  onEdit(id){
    this.edit.emit(id);
  }

  onView(id){
    this.view.emit(id);
  }

  onExpand(id){
    this.expand.emit(id);
  }

  onDelete(id){
    this.delete.emit(id);
  }

}
