<template>
  <TablaDias
    :dias="dias"
    :isLoadingTable="isLoadingTable"
    :obtenerDias="obtenerDias"
    :updateIsLoading="updateIsLoading"
  />
</template>

<script>
import axios from 'axios'
import TablaDias from '@/components/tablas/TablaDias'

export default {
  components: { TablaDias },
  props: {
    updateIsLoading: { type: Function, required: true },
    idInstitucion: { type: Number, required: true, default: false },
  },
  data() {
    return {
      dias: [],
      isLoadingTable: false,
    }
  },
  methods: {
    obtenerDias() {
      this.isLoadingTable = true
      return axios
        .get(
          `${process.env.api}/institucion-dia?id_institucion=${this.idInstitucion}`,
          this.$getToken.token()
        )
        .then((res) => {
          this.dias = res.data
          this.isLoadingTable = false
        })
        .catch((err) => {
          this.isLoadingTable = false
          this.$alertsGenericos.imprimirError(
            this.$buefy,
            this.$router,
            err.response.data
          )
        })
    },
  },
  created() {
    this.obtenerDias()
  },
}
</script>
