import { AuthServiceService } from './../../shared/auth-service.service';
import { ActivatedRoute, Params } from '@angular/router';
import { Component, OnInit, ViewChild } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { NgForm } from '@angular/forms';
import { ToastrService } from 'ngx-toastr';
import { NgxSpinnerService } from 'ngx-spinner';

@Component({
  selector: 'app-external-contact-us',
  templateUrl: './external-contact-us.component.html',
  styleUrls: ['./external-contact-us.component.css']
})
export class ExternalContactUsComponent implements OnInit {

  constructor(private route: ActivatedRoute, 
    private authSer: AuthServiceService,
    private spinner: NgxSpinnerService,
    private toastr: ToastrService,
    private http: HttpClient) { }

  contactId:number;
  checkSaveButton:boolean = false;

  @ViewChild('f') contactForm: NgForm;


  ngOnInit() {
  
    this.authSer.homeActivate = false;
    this.route.params.subscribe(
      (params: Params) => {
        this.contactId = params['contactId'];
      }
    );

    this.spinner.hide();

  }

  onSubmitted() {
    this.checkSaveButton = true;
    console.log(this.contactForm);
    this.http.post(this.authSer.pathApi + '/add_contact_message', this.contactForm.value).subscribe(
      (responce) => {
        console.log(responce);
        this.toastr.success('تم الارسال بنجاح');
        this.contactForm.reset();
      },
      (error) => {
        console.log(error);
        this.checkSaveButton = false;
        this.toastr.error('خطأ في السيرفر ، سيتم المعالجه لاخقاً');
      }
    )
  }

}
