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

    <b-table-column field="modulo" label="Módulo" v-slot="props" centered>
      <p>{{ props.row.modulo.modulo }}</p>
    </b-table-column>

    <b-table-column
      field="tipo"
      label="Tipo de carrito"
      v-slot="props"
      centered
    >
      <p>{{ props.row.tipoCarrito.tipo_carrito }}</p>
    </b-table-column>

    <b-table-column field="status" label="Status" v-slot="props" centered>
      <p class="is-size-6 tag" :class="chooseTag(props.row.activo)">
        {{ props.row.activo ? 'Activo' : 'Inactivo' }}
      </p>
    </b-table-column>

    <template #detail="props">
      <EquiposCarrito :carrito="props.row" />
    </template>
  </b-table>
</template>

<script>
import EquiposCarrito from '@/components/tablas/EquiposCarrito'

export default {
  components: { EquiposCarrito },
  props: {
    carritos: { type: Array, required: true, default: () => [] },
    isLoadingTable: { type: Boolean, required: true, default: false },
    onPageChange: { type: Function, required: true, default: () => {} },
    page: { type: Number, required: true, default: 1 },
    total: { type: Number, required: true, default: 0 },
  },
  data() {
    return {
      carritoSeleccionado: {},
    }
  },
  methods: {
    chooseTag(activo) {
      return activo ? 'is-success' : 'is-danger'
    },
  },
  watch: {
    carritoSeleccionado() {
      this.$router.push(
        `/carritos/buscar_carrito/${this.carritoSeleccionado.id_carrito}`
      )
    },
  },
}
</script>

<style>
.pointer {
  cursor: pointer;
}
</style>
