<template>
  <div>
    <section class="intro-single">
      <div class="container">
        <div class="row">
          <div class="col-md-12 col-lg-8">
            <div class="title-single-box">
              <h2 class="title-single">Property Type</h2>
            </div>
          </div>
        </div>
      </div>
    </section>
    <div class="container">
      <div class="row mb-3">
        <div class="col-md-12">
          <form id="mainForm">
            <div class="form-group row">
              <div class="col-md-4">
                <label>Description</label>
                <input
                  class="form-control"
                  type="text"
                  name="description"
                  id="description"
                  v-model="propertyType.description"
                />
              </div>
              <div class="col-md-4">
                <label>Property Type</label>
                <select
                  class="form-control"
                  name="UsageType"
                  id="UsageType"
                  v-model="propertyType.usageType"
                >
                  <option value="0">Residential</option>
                  <option value="1">Commercial</option>
                  <option value="2">Both</option>
                </select>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
    <button
      type="button"
      @click="SubmitData()"
      class="btn btn-b-n"
      style="width: 85px; height:40px;"
    >Save</button> |
    <button
      type="button"
      @click="Close()"
      class="btn btn-b-n"
      style="width: 85px; height:40px;"
    >Close</button>
  </div>
</template>

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

export default {
  name: 'PropertyType',
  data() {
    return {};
  },
  mounted() {
    this.clearPropertyType();
    if (this.$route.params.id > 0) {
      this.getPropertyType(this.$route.params.id);
    }
  },
  computed: {
    ...mapState('propertyTypes', ['propertyType']),
  },
  methods: {
    ...mapActions('propertyTypes', [
      'getPropertyType',
      'savePropertyType',
      'updatePropertyType',
      'clearPropertyType',
    ]),
    SubmitData() {
      if (this.propertyType.id > 0) {
        this.updatePropertyType(this.propertyType);
      } else {
        this.savePropertyType(this.propertyType);
      }
      this.$router.push('/propertyTypes/list');
    },
    Close() {
      this.$router.push('/propertyTypes/list');
    },
  },
};
</script>
