import {Component, OnInit} from '@angular/core';
import {FormBuilder, Validators} from '@angular/forms';
import {DomSanitizer} from '@angular/platform-browser';
import { BsModalRef } from 'ngx-bootstrap/modal';
import { FrameDetailComponent } from '../../../../frame/core/detail/frame.detail';
@Component({
  selector: 'app-exam-judge-detail',
  templateUrl: './exam-judge-detail.component.html',
  styleUrls: ['./exam-judge-detail.component.scss']
})
export class ExamJudgeDetailComponent extends FrameDetailComponent implements OnInit {

  constructor(bsModalRef: BsModalRef, fb: FormBuilder, sanitizer: DomSanitizer) {
    super(bsModalRef, sanitizer);
    this.detailForm = fb.group({
      'judge_name': [null, Validators.compose([Validators.required])],
      'judge_mobile': [null, Validators.compose([Validators.required, Validators.minLength(2), Validators.maxLength(11)])],
      'judge_sex': [null],
      'judge_school': [null],
      'judge_school_flag': [null, Validators.compose([Validators.required])],
      'judge_title': [null],
      'chief_flag': [null, Validators.compose([Validators.required])],
      'extract_flag': [null, Validators.compose([Validators.required])],
      'judge_breeds': [null],
      'bank_name': [null],
      'bank_addr': [null],
      'bank_card': [null],
      'judge_desc': [null],
      'judge_tel': [null],
      'judge_breeds_array': [null]
    });
  }

  ngOnInit() {
  }

  initDefautEntity() {
    if (this.detailMode === 'add') {
      this.currentEntity.agent_id = this.ResponseMap.ly_agent_id;
      this.currentEntity.chief_flag = 'InActive';
      this.currentEntity.extract_flag = 'Active';
      this.currentEntity.judge_school_flag = 'InActive';
      this.currentEntity.judge_sex = '保密';
    } else {
      if (this.currentEntity.judge_breeds !== undefined)
        this.currentEntity.judge_breeds_array = this.currentEntity.judge_breeds.split(',');
    }
  }

  beforeSubmitForm(): boolean {
    if (this.currentEntity.judge_breeds_array !== undefined) {
      this.currentEntity.judge_breeds = this.currentEntity.judge_breeds_array.join();
    }
    return true;
  }

}
