import { Component, OnInit } from '@angular/core';
import {FrameAbstractComponent} from '../../../frame/FrameAbstractComponent';
import {FormBuilder, Validators} from '@angular/forms';
import {CustomValidators} from 'ng2-validation';
import {FrameRequest} from '../../../../shared/frame/frame-request';

@Component({
  selector: 'app-cf-major',
  templateUrl: './cf-major.component.html',
  styleUrls: ['./cf-major.component.scss']
})
export class CfMajorComponent  extends FrameAbstractComponent {

  initMajor = { major_aspect_limit: 1, major_status: 'Active'};
  categoryArray: any;

  constructor(fb: FormBuilder) {
    super();
    this.valForm = fb.group({
      'major_name': [null, Validators.compose([Validators.required, CustomValidators.rangeLength([1, 32])])],
      'category_id': [null, Validators.required],
      'major_status': [null, Validators.required]
    });
  }

  optrMajor(step: string, entity: string , url?: string) {
    FrameRequest.requestArray('cf/category/all.htm', {}, (array) => {
      this.categoryArray = array;
      this.goViewStep(step, entity, url);
    });
  }

}
