import {Component, OnInit, ViewChild} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {ExamVideoDistComponent} from '../exam-video-dist/exam-video-dist.component';
import { ExamVideoCancelComponent } from '../exam-video-cancel/exam-video-cancel.component';
import { BsModalService } from 'ngx-bootstrap/modal';
import { AjaxService } from '../../../../../core/service/ajax.service';
import { MsgService } from '../../../../../core/service/msg.service';
import { FramePageComponent } from '../../../../frame/core/page/frame.page';
import { FrameAjax } from '../../../../../core/frame/ajax/frame-ajax/frame-ajax';

@Component({
  selector: 'app-exam-video-total',
  templateUrl: './exam-video-total.component.html',
  styleUrls: ['./exam-video-total.component.scss']
})
export class ExamVideoTotalComponent extends FramePageComponent implements OnInit {
  agentArray = [];
  ly_agent_id;

  @ViewChild('ajax', {static: false}) ajax: FrameAjax;

  constructor(private activateInfo: ActivatedRoute, private router: Router, private modalService: BsModalService) {
    super(modalService);
    this.modalComponent = ExamVideoDistComponent;
  }

  ngOnInit() {
    // 获取所有考点
    AjaxService.requestArray('exam/checkin/init/agent.htm', {}, (array) => {
      this.agentArray = array;
      if (this.agentArray.length === 1) {
        this.ly_agent_id = this.agentArray[0].ly_agent_id;
        this.ajax.reload({ly_agent_id: this.ly_agent_id});
      }
    });
  }


  // onModalClose() {
  //   this.ajax.reload({ly_agent_id: this.ly_agent_id});
  // }

  initVideo() {
    MsgService.confirmAlert('该操作应该在所有视频上传完成时候进行，确定进行此操作吗？',() => {
      AjaxService.request('exam/video/dist/init.htm',{ly_agent_id: this.ly_agent_id},()=>{
        MsgService.successAlert('视频分发初始化任务完成，可进行视频分发操作！');
      }, {RequestWithLoading : true})
    })
  }


  recycleVideo() {
    MsgService.confirmAlert('该操作将会回收当天未考的考生，确定进行此操作吗？', () => {
      AjaxService.request('exam/video/dist/recycle.htm', {
        ly_agent_id: this.ly_agent_id
      }, () => {
        MsgService.successAlert('回收成功！');
      }, {RequestWithLoading: true})
    });
  }

  //取消任务分发
  cancelTaskModal() {
    this.onModalClose = () => {
      this.ajax.reload({ly_agent_id: this.ly_agent_id});
    };
    this.showComponentModal(ExamVideoCancelComponent, {ResponseEntity: this.ly_agent_id}, {class: 'modal-5'});
  }

  onModalClose() {
    this.ajax.reload({ly_agent_id: this.ly_agent_id});
  }
}

