import { Component, OnInit } from '@angular/core';
import { FormBuilder, Validators } from '@angular/forms';
import { BsModalRef } from 'ngx-bootstrap/modal';
import { FrameDetailComponent } from '../../../../frame/core/detail/frame.detail';

@Component({
  selector: 'app-judge-room-page-detail',
  templateUrl: './judge-room-page-detail.component.html',
  styleUrls: ['./judge-room-page-detail.component.scss']
})
export class JudgeRoomPageDetailComponent extends FrameDetailComponent implements OnInit {

  schoolArray = [];
  batchArray = [];
  groupArray = [];
  roomArray = [];

  constructor(bsModalRef: BsModalRef, fb: FormBuilder) {
    super(bsModalRef);
    this.detailForm = fb.group({
      'school_id': [null, Validators.compose([Validators.required])],
      'batch_id': [null, Validators.compose([Validators.required])],
      'judge_name': [null, Validators.compose([Validators.required])],
      'login_name': [null, Validators.compose([Validators.required])],
      'ly_group_id': [null, Validators.compose([Validators.required])],
      'ly_room_id': [null, Validators.compose([Validators.required])],
      'judge_seq': [null, Validators.compose([Validators.required])],
      'judge_mobile': [null, null],
      'judge_enable': [null, null],
    });
   }

  ngOnInit(): void {
    this.schoolArray = this.ResponseArray;
  }

  requestBatch() {
    if(!this.currentEntity.school_id) return;
    this.AjaxService.requestArray('cf/school/batch/list.htm', {school_id: this.currentEntity.school_id}, (array) => {
      this.batchArray = array;
    });
  }

  requestGroup() {
    if(!this.currentEntity.batch_id) return;
    this.AjaxService.requestArray('ly/group/list/batch.htm', {batch_id: this.currentEntity.batch_id}, (array) => {
      this.groupArray = array;
    });
  }

  requestRoom() {
    if(!this.currentEntity.ly_group_id) return;
    this.AjaxService.requestArray('ly/room/interview/list/bygroup.htm', {ly_group_id: this.currentEntity.ly_group_id}, (array) => {
      this.roomArray = array;
      for(const room of this.roomArray) {
        room.room_name = room.exam_date +  ' 第【' + room.room_seq + '】考场（'+ room.room_addr+"）" ;
      }
    });
  }


}
