<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%">Restaurant User Roles</h1>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="container">
      <div class="form-group row">
        <div class="col-md-12">
          <ListView
            :items="roles"
            :showColumnChooser="false"
            :editable="true"
            :hideSearch="true"
            :deleteable="true"
            :displayColumns="columns"
            @onEdit="Edit"
            @onDelete="Delete"
            @onNew="New"
          />
        </div>
      </div>
      <div v-if="wait" id="preloader"></div>
    </div>
  </div>
</template>

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

export default {
  name: "RestaurantUserRoles",
  components: {
    ListView
  },
  data() {
    return {
      wait: false,
      restaurantId: Log.restaurantId(),
      columns: ["roleName"]
    };
  },
  methods: {
    ...mapActions("restaurantRoles", ["getRoles", "removeRole"]),
    New() {
      this.$router.push("/RestaurantRole/0");
    },
    Edit(item) {
      this.$router.push(`/RestaurantRole/${item.id}`);
    },
    Delete(item) {
      this.removeRole(item);
    }
  },
  computed: {
    ...mapState("restaurantRoles", ["roles"])
  },
  mounted() {
    this.getRoles(this.restaurantId).then(() => {
      this.wait = false;
    });
  }
};
</script>