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

@Component({
  selector: 'app-cf-subject-page',
  templateUrl: './cf-subject-page.component.html',
  styleUrls: ['./cf-subject-page.component.scss']
})
export class CfSubjectPageComponent extends FramePageComponent implements OnInit {
  schoolArray = [];
  batchArray = [];
  query = {
    school_id : '',
    batch_id : ''
  };
  constructor(modalService: BsModalService) {
    super(modalService);
    this.modalComponent = CfSubjectPageDetailComponent;
  }

  ngOnInit() {
    this.AjaxService.requestArray('./cf/school/list.htm', {}, (array) => {
      this.schoolArray = array;
      if (this.schoolArray.length === 1) {
        this.query.school_id = this.schoolArray[0].school_id;
        this.queryBatchArray();
      }
    });
    this.onModalClose = () => {
      this.pager.reload();
    };
  }

  queryBatchArray() {

    AjaxService.requestArray('cf/batch/list.htm',{school_id: this.query.school_id},(array)=>{
      this.batchArray = array;
      if (this.batchArray.length >= 1) {
        this.query.batch_id = this.batchArray[0].batch_id;
        this.requestData();
      }
    });
  }

  requestData() {

    // this.pager.pagerParams.batch_id = this.query.batch_id;
    this.pager.reload(this.query);
  }


}
