<template lang="pug">
  div
    br
    br
    br
    br
    .row
      .col-4.offset-4
        h1 Iniciar Sesión
        br
        br
        form
          .form-group.left
            label(for="text") Usuario
            input#email.form-control(type="text" v-model="user")
          .form-group.left
            label(for="email") Contraseña
            input#email.form-control(type="password" v-model="pass")
          button.btn.btn-primary(type="submit" v-on:click="Login") Iniciar Sesión
        br  
        br
        br
        br
</template>

<script>
import axios from 'axios'
import config from '../config/config.js'
export default {
    data() {
        return {
            pass: '',
            user: '',
        }
    },
    methods: {
        Login: function(e) {
            e.preventDefault()
            axios
                .post(
                    `${config.api}/loggin_admin`,
                    {
                        usuario: this.user,
                        password: this.pass,
                    }
                )
                .then(response => {
                    // eslint-disable-next-line
                    console.log(response.data)
                    window.localStorage.mesa = response.data.mesa
                    window.localStorage.id = response.data.id_admin

                    this.$router.push('/admin')
                })
                .catch(error => {
                    // eslint-disable-next-line
                    console.log(error.data)
                })
        },
    },
}
</script>

<style scoped>
.left {
    text-align: left;
}
</style>