import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { BsModalService } from 'ngx-bootstrap/modal';
import { CookieService } from 'ngx-cookie-service';
import { AjaxService } from '../../../../../core/service/ajax.service';
import { FramePageComponent } from '../../../../frame/core/page/frame.page';

@Component({
  selector: 'app-layout-material-score',
  templateUrl: './layout-material-score.component.html',
  styleUrls: ['./layout-material-score.component.scss']
})
export class LayoutMaterialScoreComponent extends FramePageComponent implements OnInit {

  agent: any;
  exam_date: any;
  dateArray = [];
  roomArray = [];

  constructor(private router: Router, private cookies: CookieService, modalService: BsModalService) {
    super(modalService);
    let agent_id = this.cookies.get('CurrentAgentId');
    if(agent_id != undefined && agent_id.length > 0) {
      AjaxService.requestEntity('layout/agent/find.htm',{ly_agent_id: agent_id},(entity) => {
          this.agent = entity;
          setTimeout(()=> {
            if(this.pager) {
              this.pager.reload();
            }
          },1);
          this.requestDate();
      });
    } else {
        this.router.navigate(['/art/layout/agent/page']);
    }
   }

  ngOnInit() {
  }


  requestDate() {
    AjaxService.requestArray('exam/checkin/init/date.htm', {agent_id: this.agent.ly_agent_id}, (array) => {
        this.dateArray = array;
      if (this.dateArray.length === 1) {
        this.exam_date = this.dateArray[0].exam_date;
        this.requestRoom();
      }
    });
  }


  requestRoom() {
    AjaxService.requestArray('exam/interview/score/room/list.htm', {
      agent_id: this.agent.ly_agent_id,
      exam_date: this.exam_date
    }, (array) => {
      this.roomArray = array;
    });
  }



}
