<template>
  <section>
    <b-table
      :data="gridData"
      :columns="gridSetting"
      :paginated="gridData.length == 0 ? false : pageAble != false"
      :per-page="gridPage ? gridPage : 50"
      :checked-rows.sync="checkedRows"
      :selected.sync="selected"
      :row-class="row => (setRowClass(row) ? 'is-checked' : '')"
      checkable
      class="my-table2"
      @check="select($event)"
      @click="click($event)"
    />
  </section>
</template>

<script>
export default {
  props: {
    gridSetting: Array,
    gridData: Array,
    gridPage: Number,
    pageAble: {
      default: true,
      type: Boolean,
    },
  },
  data() {
    return {
      checkedRows: [],
      selectedNum: [],
      selected: {},
    };
  },
  watch: {
    checkedRows() {
      this.$emit('grid-checked', this.checkedRows);
    },
  },
  methods: {
    select(event) {
      this.selectedNum = event.map((ev) => ev.postNum);
    },
    click(event) {
      this.$emit('grid-clicked', event);
    },
    setRowClass(row) {
      return this.selectedNum.includes(row.postNum);
    },
    resetCheckedRows() {
      this.checkedRows = [];
      this.selectedNum = [];
    },
  },
};
</script>
