import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { AuthService } from '../../services/auth.service';
import { AuthPasajerosService } from '../../services/auth-pasajeros.service';
import Swal from 'sweetalert2';

@Component({
  selector: 'app-login-pasajero',
  templateUrl: './login-pasajero.component.html',
  styleUrls: ['./login-pasajero.component.css']
})
export class LoginPasajeroComponent {
  correo: string = '';
  codigo: string = '';

  constructor(
    private router: Router,
    private authPasajeroService: AuthPasajerosService
  ){}

  login(){
    if (this.authPasajeroService.login(this.correo,this.codigo)) {
      const Toast = Swal.mixin({
        toast: true,
        position: 'top-right',
        iconColor: 'white',
        customClass: {
          popup: 'colored-toast'
        },
        showConfirmButton: false,
        timer: 1500,
        timerProgressBar: true
      })
      Toast.fire({
        icon: 'success',
        title: 'Inicio correcto'
      })

      if (this.authPasajeroService.getPasajeroRole()=='pasajero') {
        this.router.navigate(['./pago-reserva']);
      }
    }else{
      const Toast = Swal.mixin({
        toast: true,
        position: 'top-right',
        iconColor: 'white',
        customClass: {
          popup: 'colored-toast'
        },
        showConfirmButton: false,
        timer: 1500,
        timerProgressBar: true
      })
      Toast.fire({
        icon: 'error',
        title: 'Correo o codigo incorrectos!'
      })
    }
  }
}
