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

      <option v-for="(s, index) in catalogoStatus" :key="index" :value="s">
        {{ 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 },
    statusPadre: { type: Object, required: true, default: () => ({}) },
    columnSize: { typeof: String, required: false, default: '' },
  },
  data: () => {
    return {
      catalogoStatus: [],
      isLoadingSelect: false,
      status: {},
      objVacio: {},
    }
  },
  methods: {
    obtenerCatalogoStatus() {
      this.isLoadingSelect = true
      this.catalogoStatus = []
      axios
        .get(`${process.env.api}/status`)
        .then((res) => {
          this.catalogoStatus = res.data
          this.$emit('catalogo-status', this.catalogoStatus)
          this.isLoadingSelect = false
        })
        .catch((err) => {
          this.isLoadingSelect = false
        })
    },
  },
  watch: {
    status(statusSeleccionado) {
      this.$emit('status-seleccionado', statusSeleccionado)
    },
    statusPadre(nuevoStatus) {
      if (this.$objIsEmpty(nuevoStatus)) this.status = this.objVacio
    },
  },
  created() {
    this.status = this.objVacio
    this.obtenerCatalogoStatus()
  },
}
</script>

<style scoped></style>
