<template>
  <b-table
    class="mb-6"
    :current-page="page"
    :data="data"
    :loading="isLoadingTable"
    :per-page="25"
    :row-class="(row, index) => 'pointer'"
    :selected.sync="moduloSeleccionado"
    :total="total"
    @page-change="onPageChange"
    backend-pagination
    detailed
    hoverable
    paginated
    show-detail-icon
    striped
  >
    <b-table-column field="modulo" label="Módulo" v-slot="props" centered>
      <p>{{ props.row.modulo }}</p>
    </b-table-column>

    <b-table-column field="activo" label="Activo" v-slot="props" centered>
      <p>{{ props.row.activo ? 'Activo' : 'Inactivo' }}</p>
    </b-table-column>

    <!-- <template #detail>
      <TablaCarritos
        :operador="admin"
        :carritos="carritos"
        :isLoadingTable="isLoadingTable"
      />
    </template> -->
  </b-table>
</template>

<script>
import TablaCarritos from '@/components/tablas/TablaEquipos'

export default {
  components: { TablaCarritos },
  props: {
    data: { type: Array, required: true, default: () => [] },
    isLoadingTable: { type: Boolean, required: true, default: false },
    obtenerModulos: { type: Function, required: true, default: () => {} },
    total: { type: Number, required: true, default: 0 },
  },
  data() {
    return {
      page: 1,
      moduloSeleccionado: {},
    }
  },
  methods: {
    onPageChange(page) {
      this.page = page
      this.obtenerModulos(this.page)
    },
  },
  watch: {
    moduloSeleccionado() {
      this.$router.push(
        `/operador/carritos/buscar_carrito/${this.moduloSeleccionado.id_carrito}`
      )
    },
  },
}
</script>
