<template>
  <!-- eslint-disable max-len -->
  <div>
    <div class="container">
      <section class="intro-single">
        <div class="container">
          <div class="row">
            <div class="col-md-12 col-lg-8">
              <div class="title-single-box">
                <h1 class="title-single">Property Types</h1>
              </div>
            </div>
          </div>
        </div>
      </section>
    </div>
    <div class="container">
      <button type="button" @click="New()" class="btn btn-b-n" style="width: 85px; height:40px;">New</button>
    </div>
    <div class="container">
      <table class="table table-bordered">
        <thead>
          <tr>
            <th>Description</th>
            <th>Property Type</th>
            <th></th>
            <th></th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="(item, i) in propertyTypes" :key="i">
            <td>{{ item.description }}</td>
            <td v-if="item.usageType === 0">Residential</td>
            <td v-else>Commercial</td>
            <td>
              <button
                type="button"
                @click="Edit(item.id)"
                class="btn btn-b-n"
                style="width: 85px; height:40px;"
              >Edit</button>
            </td>
            <td>
              <button
                type="button"
                @click="Delete(item.id)"
                class="btn btn-b-n"
                style="width: 85px; height:40px;"
              >Delete</button>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</template>

<script>
import { mapState, mapActions } from 'vuex';

export default {
  name: 'PropertyTypeList',
  data() {
    return {};
  },
  methods: {
    ...mapActions('propertyTypes', ['getPropertyTypes', 'deletePropertyType']),
    New() {
      this.$router.push('/propertyType/new');
    },
    Edit(itemID) {
      this.$router.push({
        path: `/propertyType/${itemID}`,
      });
    },
    Delete(id) {
      this.deletePropertyType(id);
    },
  },
  mounted() {
    this.getPropertyTypes();
  },
  computed: {
    ...mapState('propertyTypes', ['propertyTypes']),
  },
};
</script>
