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

@Component({
  selector: 'app-exam-written-photo-graph',
  templateUrl: './exam-written-photo-graph.component.html',
  styleUrls: ['./exam-written-photo-graph.component.scss']
})
export class ExamWrittenPhotoGraphComponent extends FramePageComponent implements OnInit {

  room;
  agentArray = [];
  subjectArray = [];
  roomArray = [];
  stdArray = [];

  constructor(modalService: BsModalService) {
    super(modalService);
    this.room = {};
    AjaxService.requestArray('exam/photograph/written/agent/list.htm', {}, (array) => {
      this.agentArray = array;
    });
  }

  ngOnInit() {

  }

  requestSubjectArray() {
    AjaxService.requestArray('exam/photograph/written/subject/list.htm', {ly_agent_id:this.room.ly_agent_id}, (array) => {
      for(const sb of array) {
        sb.subject_value = `${sb.subject_name}[${sb.subject_std_total}]`
      }
      this.subjectArray = array;
    });
  }

  requestRoomArray() {
    AjaxService.requestArray('exam/photograph/written/room/list.htm', {ag_subject_id:this.room.ag_subject_id}, (array) => {
      for(const sb of array) {
        sb.room_value = `${sb.room_name}:${sb.room_addr}[${sb.real_std_total}/${sb.room_capacity}]`
      }
      this.roomArray = array;
    });
  }
  requestStdArray() {
    if(this.room.ly_room_id === undefined)
      return;
    AjaxService.requestArray('exam/photograph/written/std/list.htm', {ag_subject_id:this.room.ag_subject_id,ly_room_id: this.room.ly_room_id}, (array) => {
      this.stdArray = array;
    });
  }
}

