<template>
  <b-field class="column mb-0 pb-0" label="Status" :class="columnSize">
    <b-select
      icon="store"
      :loading="isLoadingSelect"
      v-model="idStatus"
      expanded
      rounded
    >
      <option :disabled="deshabilitarOptVacia" :value="0">
        Selecciona una opción
      </option>

      <option
        v-for="(s, index) in catalogoStatus"
        :key="index"
        :value="s.id_status"
      >
        {{ s.status }}
      </option>
    </b-select>
  </b-field>
</template>

<script>
import axios from 'axios'

export default {
  props: {
    deshabilitarOptVacia: { typeof: Boolean, required: false, default: true },
    idInstitucion: { type: Number, required: true, default: 0 },
    idStatusPadre: { type: Number, required: true, default: 0 },
    columnSize: { typeof: String, required: false, default: '' },
  },
  data: () => {
    return {
      catalogoStatus: [],
      isLoadingSelect: false,
      idStatus: 0,
    }
  },
  methods: {
    obtenerCatalogoStatus() {
      this.isLoadingSelect = true
      this.catalogoStatus = []
      axios
        .get(`${process.env.api}/status`, this.$getToken.token())
        .then((res) => {
          this.catalogoStatus = res.data
          this.$emit('catalogo-status', this.catalogoStatus)
          this.isLoadingSelect = false
        })
        .catch((err) => {
          this.isLoadingSelect = false
        })
    },
  },
  watch: {
    idStatus(statusSeleccionado) {
      this.$emit('status-seleccionado', statusSeleccionado)
    },
    idStatusPadre(nuevoStatus) {
      this.idStatus = nuevoStatus
    },
  },
  created() {
    this.obtenerCatalogoStatus()
  },
}
</script>

<style scoped></style>
