<template>
  <b-table
    class="pb-6"
    :data="horasExcepcion"
    :loading="isLoadingTable"
    hoverable
    striped
  >
    <b-table-column
      field="horaInicio"
      label="Hora inicio"
      v-slot="props"
      centered
    >
      <p>{{ props.row.hora_inicio }}</p>
    </b-table-column>

    <b-table-column field="horaFin" label="Hora fin" v-slot="props" centered>
      <p>{{ props.row.hora_fin }}</p>
    </b-table-column>

    <b-table-column field="eliminar" label="Eliminar" v-slot="props" centered>
      <BotonEliminar
        :eliminar="eliminarHoraExcepcion"
        :row="props.row"
        :msjWarning="`¿Estás segur@ de querer eliminar esta hora excepción?`"
      />
    </b-table-column>
  </b-table>
</template>

<script>
import axios from 'axios'
import BotonEliminar from '@/components/botones/BotonEliminar'

export default {
  components: { BotonEliminar },
  props: {
    horasExcepcion: { type: Array, required: true, default: () => [] },
    obtenerHorasExcepcion: {
      type: Function,
      required: true,
      default: () => {},
    },
    isLoadingTable: { type: Boolean, required: true, default: false },
    updateIsLoading: { type: Function, required: true },
  },
  methods: {
    eliminarHoraExcepcion(horaExcepcion) {
      const data = {
        id_hora_excepcion: horaExcepcion.id_hora_excepcion,
      }

      this.updateIsLoading(true)
      return axios
        .delete(
          `${process.env.api}/hora-excepcion`,
          this.$getToken.tokenDelete(data)
        )
        .then((res) => {
          this.obtenerHorasExcepcion()
          this.updateIsLoading(false)
          this.$alertsGenericos.imprimirMensaje(this.$buefy, res.data.message)
        })
        .catch((err) => {
          this.updateIsLoading(false)
          this.$alertsGenericos.imprimirError(
            this.$buefy,
            this.$router,
            err.response.data
          )
        })
    },
  },
}
</script>
