<template>
  <div class="container">
    <Ticket
      :imprimirMensaje="imprimirMensaje"
      :imprimirError="imprimirError"
      :imprimirWarning="imprimirWarning"
      :updateIsLoading="updateIsLoading"
    />

    <b-loading :is-full-page="true" v-model="isLoading" :can-cancel="false" />
  </div>
</template>

<script>
import Ticket from '../../components/admin/ticket.vue'

export default {
  components: {
    Ticket,
  },
  data() {
    return {
      isLoading: false,
    }
  },
  methods: {
    updateIsLoading(booleanValue) {
      this.isLoading = booleanValue
    },
    imprimirError(err = {}, title = '¡Hubo un error!', onConfirm = () => {}) {
      this.$buefy.dialog.alert({
        ariaRole: 'alertdialog',
        ariaModal: true,
        type: 'is-danger',
        title,
        message: err.message,
        confirmText: 'Entendido',
        hasIcon: true,
        iconPack: 'mdi',
        icon: 'alert-octagon',
        onConfirm: () => onConfirm(),
      })
      if (err.err && err.err === 'token error') {
        localStorage.clear()
        this.$router.push('/')
      }
    },
    imprimirMensaje(
      message,
      title = '¡Acción confirmada!',
      onConfirm = () => {}
    ) {
      this.$buefy.dialog.alert({
        ariaRole: 'alertdialog',
        ariaModal: true,
        type: 'is-success',
        title,
        message,
        confirmText: 'Ok',
        hasIcon: true,
        iconPack: 'mdi',
        icon: 'check-circle',
        onConfirm: () => onConfirm(),
      })
    },
    imprimirWarning(
      message,
      onConfirm = () => {},
      title = '¡Espera un minuto!',
      onCancel = () => {}
    ) {
      this.$buefy.dialog.alert({
        ariaRole: 'alertdialog',
        ariaModal: true,
        type: 'is-warning',
        title,
        message,
        confirmText: 'Confirmar',
        canCancel: true,
        cancelText: 'Cancelar',
        hasIcon: true,
        iconPack: 'mdi',
        icon: 'help-circle',
        onConfirm: () => onConfirm(),
        onCancel: () => onCancel(),
      })
    },
  },
}
</script>

<style></style>
