import { Component, OnInit, ViewChild } from '@angular/core';
import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal';
import { FramePager } from 'src/app/core/frame/pager/frame-pager/frame-pager';
import { FrameDetailComponent } from '../../../../frame/core/detail/frame.detail';

declare var aliPlayerUtil :any;

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

  @ViewChild('inroomPager', {static: false}) inroomPager: FramePager;
  @ViewChild('layoutPager', {static: false}) layoutPager: FramePager;
  inroom_num : any;
  videoModal: any;
  bsModalWin: any;
  aliPlayer: any;
  
  constructor(bsModalRef: BsModalRef, private modalService: BsModalService) { 
    super(bsModalRef);
  }

  ngOnInit(): void {
  }

  initDefautEntity(): void {
    this.getMaxStdInRoomNum();
  }

  //考生进场的最大序号
  getMaxStdInRoomNum() {
    this.AjaxService.requestEntity('ly/rooom/interview/std/inroom/get/max.htm', {ly_room_id: this.currentEntity.ly_room_id}, (entity) => {
      this.inroom_num = entity;
      this.inroomPager.reload({ly_room_id: this.currentEntity.ly_room_id});
    });
  }

  //取消进场
  cancelInRoom(std?) {
    this.MsgService.confirmAlert('确定要取消该考生进场吗？', () => {
      this.AjaxService.request('ly/rooom/interview/std/inroom/cancel.htm', {
        ly_room_id : this.currentEntity.ly_room_id,
        std_id : std.std_id,
        real_exam_seq: std.real_exam_seq
      }, () => {
        this.MsgService.successAlert('取消成功，请提醒评委重新登录！');
        this.getMaxStdInRoomNum();
        this.layoutPager.reload({ly_room_id: this.currentEntity.ly_room_id});
      });
    });
  }

  //播放视频
  startVideo(videoModal, video_file) {
    this.videoModal = videoModal;
    this.nextVideo(true, video_file);
  }

  nextVideo(firstLoad, video_file) {
    if (firstLoad) {
      this.initVideoPlayer();
    }
    aliPlayerUtil.changeSource(this.aliPlayer, video_file);
  }

  //视频初始化
  initVideoPlayer(url?) {
    this.bsModalWin = this.modalService.show(this.videoModal, { class: 'modal-9p' , backdrop: 'static', keyboard: false});
    this.aliPlayer = aliPlayerUtil.init('aliPlayer', url);
  }

  //隐藏视频窗口
  hideModal(){
    if(this.bsModalWin) this.bsModalWin.hide();
  }

  //视频暂停播放
  pauseVideo(){
    aliPlayerUtil.pause(this.aliPlayer);
  }

  //视频继续播放
  playVideo(){
    aliPlayerUtil.play(this.aliPlayer);
  }

}
