import {Component, OnInit} from '@angular/core';
import {DomSanitizer} from '@angular/platform-browser';
import {FrameService} from '../../../../../core/frame/frame.service';
import {FormBuilder, Validators} from '@angular/forms';
import {BsModalRef} from 'ngx-bootstrap';
import {FrameEditComponent} from '../../../../frame/core/FrameEditComponent';
import {FrameDeptDetailComponent} from '../../../../frame/dept/frame-dept-detail/frame-dept-detail.component';
import {AjaxService} from '../../../../../core/ajax/ajax.service';
import {ConfFeePageComponent} from '../../fee/conf-fee-page/conf-fee-page.component';

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

  majorArray = [];
  feeArray = [];

  constructor(bsModalRef: BsModalRef, fb: FormBuilder, sanitizer: DomSanitizer) {
    super(bsModalRef, sanitizer);
    this.valForm = fb.group({
      'aspect_name': [null, Validators.compose([Validators.required, Validators.minLength(2), Validators.maxLength(128)])],
      'aspect_code': [null, Validators.compose([Validators.required, Validators.maxLength(16)])],
      'aspect_status': [null, Validators.required],
      'fee_amount': [null, Validators.required],
      'aspect_score': [null, Validators.required],
      'aspect_desc': [null, Validators.maxLength(256)],
      'aspect_notice': [null, Validators.maxLength(2000)]
    });
    /*AjaxService.requestArray('conf/major/all.htm', {}, (array) => {
      this.majorArray = array;
    });
    AjaxService.requestArray('conf/fee/all.htm', {}, (array) => {
      for (const fee of array) {
        fee.fee_note = ConfFeePageComponent.getFeeConfig(fee);
      }
      this.feeArray = array;
    });*/
  }

  ngOnInit() {
    /*setTimeout(() => {
      this.deptArray = FrameDeptDetailComponent.makeOptrDeptArray(this.ResponseArray);
    }, 10);*/
  }

  initDefautEntity() {
    if (this.editModel === 'add') {
      this.currentEntity.aspect_status = 'Active';
    }
  }

  beforeSubmitForm() {
    if (this.currentEntity.aspect_notice !== undefined)
      this.currentEntity.aspect_notice = encodeURIComponent(this.currentEntity.aspect_notice);
    return true;
  }
}
