<template>
  <div>
    <div class="container">
      <div class="container">
        <div class="row">
          <div class="col-md-12 col-lg-8">
            <div class="title-box-d">
              <br />
              <h1 class="title-d" style="text-align:left; font-size: 250%">Menu Options</h1>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="container">
      <div class="form-group row">
        <div class="col-md-12">
          <ListView
            :items="menuOptions"
            :showColumnChooser="false"
            :editable="true"
            :deleteable="true"
            :displayColumns="columns"
            :displayHeaders="headers"
            @onEdit="Edit"
            @onDelete="Delete"
            @onNew="New"
          />
        </div>
      </div>
      <div v-if="wait" id="preloader"></div>
    </div>
  </div>
</template>

<script>
import Category from "../restaurants/restaurantMenuCateory";
import ListView from "../shared/listView";
import { mapState, mapActions } from "vuex";
import Log from "../../assets/Log";

export default {
  name: "RestaurantCategoryList",
  components: {
    ListView,
    Category
  },
  data() {
    return {
      wait: true,
      columns: [
        "categoryDescription",
        "description",
        "optionTypeDescription",
        "optionLimit",
        "isBasePrice",
        "rank"
      ],
      headers: [
        "Category",
        "Description",
        "Option Type",
        "Option Limit",
        "Base Price",
        "Rank"
      ],
      restautantId: Log.restaurantId()
    };
  },
  methods: {
    ...mapActions("menuOptions", ["getMenuOptions", "deleteMenuOption"]),
    New() {
      this.$router.push("/MenuOption/0");
    },
    Edit(item) {
      this.$router.push("/MenuOption/" + item.id);
    },
    Delete(item) {
      this.deleteMenuOption(item);
    }
  },
  computed: {
    ...mapState("menuOptions", ["menuOptions"]),
    CurrentCategory() {
      return this.category;
    }
  },
  mounted() {
    this.getMenuOptions(this.restautantId).then(() => {
      this.wait = false;
    });
  }
};
</script>