import {Component, OnInit} from '@angular/core';
import {DomSanitizer} from '@angular/platform-browser';
import {FormBuilder, Validators} from '@angular/forms';
import { FrameDetailComponent } from '../../../../frame/core/detail/frame.detail';
import { BsModalRef } from 'ngx-bootstrap/modal';

@Component({
  selector: 'app-conf-variety-detail',
  templateUrl: './conf-variety-detail.component.html',
  styleUrls: ['./conf-variety-detail.component.scss']
})
export class ConfVarietyDetailComponent extends FrameDetailComponent implements OnInit {

  constructor(bsModalRef: BsModalRef, fb: FormBuilder, sanitizer: DomSanitizer) {
    super(bsModalRef, sanitizer);
    this.detailForm = fb.group({
      'variety_id': [null, Validators.compose([Validators.required, Validators.min(1), Validators.max(99999999)])],
      'variety_name': [null, Validators.compose([Validators.required, Validators.minLength(1), Validators.maxLength(128)])],
      'variety_code': [null, Validators.compose([Validators.required, Validators.maxLength(16)])],
      'allow_same_tracks': [null, Validators.required],
      'auto_accompany': [null, Validators.required],
      'variety_order': [null, Validators.compose([Validators.required, Validators.min(1), Validators.max(99)])],

      'full_flag': [null, Validators.required],
      'single_subject_variety': [null, Validators.required],
      'variety_enrol_explain': [null, Validators.maxLength(2000)]
    });
  }

  ngOnInit() {

  }

  initDefautEntity() {
    if (this.detailMode === 'add') {
      this.currentEntity.allow_same_tracks = 'InActive';
      this.currentEntity.auto_accompany = 'InActive';
      this.currentEntity.single_subject_variety = 'Active';
      this.currentEntity.full_flag = 'Active';

    }
  }
}
