import { Component, OnInit } from '@angular/core';
import { FlexTableComponent } from '../../../../shared/common/FlexTable.component';
import { FormBuilder, Validators } from '@angular/forms';

@Component({
  selector: 'app-cf-organization',
  templateUrl: './cf-organization.component.html',
  styleUrls: ['./cf-organization.component.scss']
})
export class CfOrganizationComponent extends FlexTableComponent implements OnInit {

  public query = {
    query: "",
    org_type: ""
  };

  QUERY_URL = "cf/cfOrganization/page.htm";
  ADD_URL = "cf/cfOrganization/add.htm";
  DELETE_URL= "cf/cfOrganization/delete.htm";
  GET_URL= "cf/cfOrganization/get.htm";
  EDIT_URL= "cf/cfOrganization/edit.htm";
  CITY_URL= "cf/cfCity/list.htm";

  examFlag = true;

  constructor( fb: FormBuilder) {
    super();
    this.formModel = fb.group({
      id: [''],
      org_name: ['', Validators.required],
      org_code: ['', Validators.compose([Validators.required, Validators.pattern("^[a-zA-Z0-9]+$")]) ],
      org_short_name: ['', Validators.required],
      org_standard_code:['', Validators.pattern("^[a-zA-Z0-9]+$")],
      org_type: ['', Validators.required],
      city_code: [''],
      contact_number: [''],
      org_address: [''],
      exam_flag: [''],
      remark: ['']
    });
  }

  ngOnInit() {
  }

  chooseExam(org_type: any) {
    if(Number(org_type) === 4) {
      this.examFlag = false;
    } else {
      this.examFlag = true;
    }
  }

  async preGoEditEvent(entity?){
    if(entity && entity.org_type === 4) {
      this.examFlag = false;
    } else {
      this.examFlag = true;
    }
    return true;
  }
}
