<template>
  <!-- eslint-disable max-len -->
  <div>
    <div class="container">
      <br />
      <div class="row">
        <div class="col-md-12 col-lg-8">
          <div class="title-box-d">
            <h1 class="title-d" style="text-align:left; font-size: 250%">
              Property User Defined Groups
            </h1>
          </div>
        </div>
      </div>
    </div>
    <div class="container">
      <div class="container">
        <listView
          :items="userDefinedGroups"
          :showNew="true"
          :editable="true"
          :deleteable="true"
          :displayColumns="columns"
          :sortKey="'rank'"
          @onEdit="Edit"
          @onDelete="Delete"
          @onNew="New"
        />
      </div>
    </div>
    <br />
  </div>
</template>
<script>
import { mapState, mapActions } from "vuex";
import listView from "../../shared/listView.vue";

export default {
  name: "UserDefinedGroup",
  components: {
    listView
  },
  data() {
    return {
      columns: ["description", "propertyUsageType", "rank"]
    };
  },
  mounted() {
    this.getUserDefinedGroups();
  },
  computed: {
    ...mapState("propertyAdmin", ["userDefinedGroups"])
  },
  methods: {
    ...mapActions("propertyAdmin", ["getUserDefinedGroups", "deleteUserDefinedGroup"]),
    New() {
      this.$router.push("/userDefinedGroups/userDefinedGroup");
    },
    Edit(item) {
      this.$router.push(`/userDefinedGroups/userDefinedGroup/${item.id}`);
    },
    Delete(item) {
      if (item.id === 0) {
        this.userDefinedGroups.pop(item);
      }
      this.deleteUserDefinedGroup(item.id);
    }
  }
};
</script>
