<template>
  <b-table
    class="mb-6"
    :data="data"
    :loading="isLoadingTable"
    :per-page="25"
    :total="total"
    hoverable
    paginated
    striped
  >
    <b-table-column field="programa" label="Software" v-slot="props" centered>
      <p>
        {{ props.row.programa.programa }}
      </p>
    </b-table-column>

    <b-table-column field="activo" label="Status" v-slot="props" centered>
      <BotonDesactivar
        :activarDesactivar="activarDesactivar"
        :data="props.row"
        :msjWarning="`¿Estás segur@ de querer ${
          row.activo || row.mostrar ? 'desactivar' : 'activar'
        } este tipo de software?`"
      />
    </b-table-column>
  </b-table>
</template>

<script>
import BotonDesactivar from '@/components/botones/BotonDesactivar'

export default {
  components: { BotonDesactivar },
  props: {
    data: { type: Array, required: true, default: () => [] },
    isLoadingTable: { type: Boolean, required: true, default: false },
    obtenerProgramas: {
      type: Function,
      required: true,
      default: () => {},
    },
    updateIsLoading: { type: Function, required: true, default: () => {} },
    total: { type: Number, required: true, default: 0 },
  },
  methods: {
    activarDesactivar(institucionPrograma) {
      const data = {
        id_institucion_programa: institucionPrograma.id_institucion_programa,
        mostrar: !institucionPrograma.mostrar,
      }

      this.updateIsLoading(true)
      axios
        .put(
          `${process.env.api}/institucion-programa/`,
          data,
          this.$getToken.token()
        )
        .then((res) => {
          this.obtenerProgramas()
          this.updateIsLoading(false)
          this.$alertsGenericos.imprimirMensaje(this.$buefy, res.data.message)
        })
        .catch((err) => {
          this.updateIsLoading(false)
          this.$alertsGenericos.imprimirError(this.$buefy, err.response.data)
        })
    },
  },
}
</script>
