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

@Component({
  selector: 'app-internal-contact-us',
  templateUrl: './internal-contact-us.component.html',
  styleUrls: ['./internal-contact-us.component.css']
})
export class InternalContactUsComponent 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('خطأ في السيرفر ، سيتم المعالجه لاخقاً');
      }
    )
  }

}
