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

  constructor(bsModalRef: BsModalRef, fb: FormBuilder) {
    super(bsModalRef);
    this.detailForm = fb.group({
      'category_id': [null, Validators.compose([Validators.required, Validators.min(1), Validators.max(99)])],
      'category_name': [null, Validators.compose([Validators.required, Validators.minLength(2), Validators.maxLength(128)])],
      'category_code': [null, Validators.compose([Validators.required, Validators.maxLength(16)])],
      'category_status': [null, Validators.required],
      'category_order': [null, Validators.compose([Validators.required, Validators.min(1), Validators.max(99)])],
      'enrol_major_limit': [null, Validators.compose([Validators.required, Validators.min(0), Validators.max(99)])],
      'enrol_aspect_limit': [null, Validators.compose([Validators.required, Validators.min(0), Validators.max(99)])],
      'category_enrol_explain': [null, Validators.maxLength(2000)]
    });
  }

  ngOnInit() {
  }

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