import { Component, OnInit } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { Router } from '@angular/router';

@Component({
  selector: 'app-upload',
  templateUrl: './upload.component.html',
  styleUrls: ['./upload.component.scss']
})
export class UploadComponent implements OnInit {

 
  phoneInvalid: boolean = false;
  formData: any = {};
  myForm: FormGroup;
  loading: boolean = true

  constructor(private router: Router) { }

  navigateTo(destination: any) {
    this.router.navigate([destination])
  }
  validatePhoneNumber() {
    const phonePattern = /^[0-9]{10}$/;
    const phoneInput = this.myForm.controls.phone;
    this.phoneInvalid = !phonePattern.test(phoneInput.value);
  }

  // goToHome(){
  //   window.location.href = 'https://www.thrickodithanamscb.in/index.html#hero';
  // }
  // goToContactUs(){
  //   window.location.href = 'https://www.thrickodithanamscb.in/index.html#contact';
  // }
  
preSave(){
  if(this.formData.name == '' || this.formData.name == undefined){
   // console.log("1");
    
    return false
  }
  if(this.formData.phone == '' || this.formData.phone == undefined || this.formData.phone.length > 10 || this.formData.phone.length < 10){
   // console.log("ph");
    return false
  }
  if(this.formData.email == '' || this.formData.email == undefined){
  // console.log("e");
    return false
  }
  return true
}

  submitForm() {
    if(this.preSave())
    console.log(this.formData); 
  }
  
  deleteInput(inputFieldId: string) {
    const inputField = document.getElementById(inputFieldId) as HTMLInputElement;
    if (inputField) {
      inputField.value = '';
    }
  }
  ngOnInit(): void {
    this.loading = false
  }

}
