<template>
  <!-- eslint-disable max-len -->
  <main id="main" style="padding-bottom:50px; margin-top:-20px">
    <div class="container">
      <div class="container">
        <div class="row">
          <div class="col-md-12 col-lg-8">
            <div class="section-header">
              <h2>Carousel Items</h2>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="container">
      <listView
        :items="carouselList"
        :showNew="true"
        :deleteable="true"
        :displayColumns="columns"
        :displayFormats="formats"
        @onNew="New"
        @onDelete="Delete"
      />
    </div>
  </main>
</template>

<script>
import { mapState, mapActions } from "vuex";
import listView from "../../shared/listView.vue";

export default {
  name: "CarouselList",
  components: {
    listView
  },
  data() {
    return {
      columns: ["id", "header", "image"],
      formats: ["", "", "image"]
    };
  },
  methods: {
    ...mapActions("carousel", ["getCarouselList", "deleteCarousel"]),
    New() {
      this.$router.push("/carousel/details/0");
    },
    Edit(itemID) {
      this.$router.push({
        path: `/carousel/details/${itemID}`
      });
    },
    Delete(item) {
      this.deleteCarousel(item.id);
    }
  },
  mounted() {
    this.getCarouselList();
  },
  computed: {
    ...mapState("carousel", ["carouselList"])
  }
};
</script>
