<template>
  <div>
    <Header />
    <h1 class="my-5">Inicia Sesión</h1>
    <div class="row d-flex justify-content-center">
      <div class="col-12 col-md-8 col-lg-6 col-xl-6">
        <form class="row d-flex justify-content-center">
          <input
            type="text"
            v-model="email"
            class="form-control col-8"
            name="login"
            placeholder="Usuario"
          />
          <input
            type="password"
            v-model="password"
            class="form-control col-8 my-3"
            name="login"
            placeholder="Contraseña"
          />
          <input
            type="button"
            @click="login"
            class="btn bg-primary text-white col-5"
            value="Ingresar"
          />
        </form>
      </div>
    </div>
  </div>
</template>

<script>
import Header from "./../components/header.vue";
import axios from "axios";
import config from "../config/config.js";
import Swal from 'sweetalert2'
export default {
  data() {
    return {
      email: "",
      password: ""
      
    };
  },
  methods: {
    login() {
      const datos = {
        usuario: this.email,
        password: this.password
      }
      axios.post( `${config.api}/loginAdmin`,  datos ).then(async response =>{
          localStorage.setItem('tokenPortal', response.data.token);
          await Swal.fire(
                'Bienvenido',
                    '',
                    'success'
                );
          this.$router.replace('/panelAdmin');

      }).catch(() =>{
          Swal.fire({
              icon: 'error',
              title: 'El usuario o la contraseña es incorrecta',
              text: `Intentalo de nuevo.`,
          });
      });
    }
  },
  components: {
    Header
  },
 
};
</script>

<style></style>
