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";

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

  constructor(private serviceComm: ServiceComm) {
    this.addForm = new FormGroup({
      dzName: new FormControl("", Validators.required),
      gps: new FormControl("x.x,y.y", [
        Validators.required,
        Validators.pattern("d+.d+,d+.d+")
      ]),
      address: new FormControl("", Validators.required),
      contactMail: new FormControl("", [Validators.required, Validators.email]),
      isDz: new FormControl(true),
      isTunnel: new FormControl(false)
    });
  }

  ngOnInit() {}

  onSubmit(formData) {
    console.log(formData.status);
    console.warn("New data : ", formData);

    this.serviceComm.RefreshData(AddAction.Gear);
    this.addForm.reset();
  }
}
