<template>
  <b-table
    class="mb-6"
    :data="data"
    :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 BotonEliminar from '@/components/botones/BotonEliminar'

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

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