<template>
  <div>
    <div class="container">
      <div class="row">
        <div class="col-md-12" style="margin-bottom: 1em">
          <h1>Users</h1>
        </div>
      </div>
      <div class="form-group row">
        <div class="col-md-12">
          <ListView
            :items="restaurantUsers"
            :showColumnChooser="false"
            :editable="false"
            :deleteable="false"
            :showNew="false"
            :displayColumns="columns"
            @onRowClick="SelectUser"
          />
        </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: "RestaurantUserLookup",
  components: {
    ListView,
  },
  data() {
    return {
      wait: true,
      columns: ["emailAddress", "firstName", "surname", "cellphone"],
      restaurantId: Log.restaurantId(),
    };
  },
  methods: {
    ...mapActions("restaurantUser", ["getUsers"]),
    SelectUser(item) {
      this.$emit("SelectedUser", item);
    },
  },
  computed: {
    ...mapState("restaurantUser", ["restaurantUsers"]),
  },
  mounted() {
    this.getUsers(this.restaurantId).then(() => {
      this.wait = false;
    });
  },
};
</script>