import { Component } from '@angular/core';
import {IonicPage, LoadingController, NavController, NavParams, ViewController} from 'ionic-angular';
import {UserService} from "../../services/user.service";
import {Pata} from "../../pata";

/**
 * Generated class for the AyudaPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@Component({
  selector: 'page-ayuda',
  templateUrl: 'ayuda.html',
})
export class AyudaPage {

  public comment: string = '';
  public whatsapp: number = 0;
  public email: string = '';

  private userId:string;
  constructor(public navCtrl: NavController,
              public navParams: NavParams,
              private userService: UserService,
              private service: Pata,
              private loadingCtrl: LoadingController,
              private viewCtrl: ViewController)
  {
    //this.userId = this.navParams.get('userId')

    let loading = this.loadingCtrl.create();
    loading.present();

    this.userService.getHelpdesk().subscribe((data: any) => {
        loading.dismiss();
        this.whatsapp = data.whatsapp;
        this.email = data.email;
      },
      error => {
        loading.dismiss();
        console.log('Change.error: ' + JSON.stringify(error));
        this.service.logError(null, "Error al intentar cambiar la contraseña");
      }
    )

  }

  ionViewDidLoad() {
  }
  sendWhatsapp() {
    window.open("https://wa.me/"+this.whatsapp, '_system');
  }
  sendEmail() {
    window.open("mailto:"+this.email, '_system');
  }
  dismiss(data) {
    this.viewCtrl.dismiss(data);
  }

  enviarMensaje(){

    let loading = this.loadingCtrl.create({
      content: 'cargando...'
    });
    loading.present();
    
    this.userService.sendHelpdesk(this.comment).subscribe(
      (data: any) => {
        loading.dismiss();
        this.service.showOk(data.msg);
        this.comment = '';
      },
      error => {
        loading.dismiss();
        console.log('Change.error: ' + JSON.stringify(error));
        this.service.logError(null, "Error al enviar el mensaje");
      }
    )
  }
}
