import { Component, OnInit } from "@angular/core";
import { FormControl, FormGroup, Validators } from "@angular/forms";
import { AddAction } from "../../models/add-action.enum";
import { ServiceComm } from "../../services/service-comm.service";
import { JumpTypeService } from "../../services/jump-type.service";

@Component({
  selector: "app-new-jump-type",
  templateUrl: "./new-jump-type.component.html",
  styleUrls: ["./new-jump-type.component.css"]
})
export class NewJumpTypeComponent implements OnInit {
  public addForm: FormGroup;

  constructor(private serviceComm: ServiceComm,
    private jumpTypeService: JumpTypeService) {
    this.addForm = new FormGroup(
      {
        jumptypeName: new FormControl("", Validators.required)
      },
      { updateOn: "blur" }
    );
  }

  ngOnInit() { }

  onSubmit(formData) {
    this.jumpTypeService.AddJumpType(formData.jumptypeName)
                        .subscribe(() => {
                          this.serviceComm.RefreshData(AddAction.JumpType);
                        });
  }
}
