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-conf-major-detail',
  templateUrl: './conf-major-detail.component.html',
  styleUrls: ['./conf-major-detail.component.scss']
})
export class ConfMajorDetailComponent extends FrameDetailComponent implements OnInit {

  constructor(bsModalRef: BsModalRef, fb: FormBuilder) {
    super(bsModalRef);
    this.detailForm = fb.group({
      'major_id': [null, Validators.compose([Validators.required, Validators.min(1), Validators.max(999999)])],
      'major_name': [null, Validators.compose([Validators.required, Validators.minLength(2), Validators.maxLength(128)])],
      'major_code': [null, Validators.compose([Validators.required, Validators.maxLength(16)])],
      'major_status': [null, Validators.required],
      'major_category_id': [null, Validators.required],
      'major_order': [null, Validators.compose([Validators.required, Validators.min(1), Validators.max(99)])],
      'enrol_aspect_limit': [null, Validators.compose([Validators.required, Validators.min(0), Validators.max(99)])],
      'major_enrol_explain': [null, Validators.maxLength(2000)]
    });
  }

  ngOnInit() {
  }

  initDefautEntity() {
    if (this.detailMode === 'add') {
      this.currentEntity.major_status = 'Active';
      this.currentEntity.enrol_aspect_limit = 0;
    }
  }
}
