<template>
  <!-- eslint-disable max-len -->
  <section class="collapse-items">
    <div class="container">
      <div class="row">
        <div class="col-sm-12">
          <div class="tobuy-img-box">
            <img src="img/buy2.jpg" alt="Timeshare To Buy" class="img-fluid title-img" />
          </div>
          <div class="sinse-box title-title">
            <h3 class="sinse-title">Timeshare To Buy</h3>
          </div>
        </div>
        <div class="container col-md-10">
          <hr />
          <div class="row">
            <div class="col-md-12 text-left">
              <p>
                The resorts have been listed in their relevant provinces.
                Please select the resort for which you would like to view
                the available weeks and then select the weeks that interest
                you on the resort page.
              </p>
              <p>
                Arrival and departure dates are indicated but please note
                that these dates may vary annually.
              </p>
              <p>
                As with any property related sale, upon purchasing the holiday
                of your choice, there will be a transfer fee payable for the
                change of ownership. This fee will depend on the relevant resort
                or managing agent.
              </p>
            </div>
          </div>
          <hr />
          <div class="row mb-4">
            <div class="container col-md-4">
              <div class="accordion" id="accordionExample">
                <div class="card" v-for="(region, r) in availRegion" :key="r">
                  <a
                    class="mb-0 color-text-a"
                    data-toggle="collapse"
                    :data-target="'#collapse' + region.regionCode"
                    aria-expanded="false"
                    :aria-controls="'collapse' + region.regionCode"
                    @mouseover="updateMapProvince(region.regionName)"
                  >
                    <div :id="'header' + region.regionCode">
                      <h5
                        class="btn btn-link font-weight-bold color-b"
                      >{{ region.regionName + ' (' + region.available + ')' }}</h5>
                    </div>
                  </a>
                  <div
                    :id="'collapse' + region.regionCode"
                    class="collapse secondary"
                    :aria-labelledby="'header' + region.regionCode"
                    data-parent="#accordionExample"
                    style="background-color:#E3E3E3"
                  >
                    <div class="card-body">
                      <div
                        v-for="(resort, i) in region.resorts"
                        :key="i"
                        @click="routerGoTo('/resort/' + resort.resortCode)"
                        @mouseover="updateMap(resort)"
                      >
                        <p class="mb-0 card-item">
                          <a
                            class="cursor-pointer"
                            href="#"
                          >{{resort.resortName + ' (' + resort.available + ')'}}</a>
                          <br />
                        </p>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <div class="col-md-8">
              <div class="tab-content" id="myTabContent">
                <div
                  class="tab-pane fade show active"
                  id="directions"
                  role="tabpanel"
                  aria-labelledby="directions-tab"
                >
                  <iframe
                    :src="mapUrl"
                    width="100%"
                    height="600"
                    frameborder="0"
                    style="border-radius:10px"
                    allowfullscreen
                  ></iframe>
                  <br />
                  <small>
                    <a :href="mapUrl" class="map-url" target="_blank">See map bigger</a>
                  </small>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </section>
</template>
<script>
import { mapState, mapActions } from 'vuex';

export default {
  name: 'TimeshareToBuy',
  data() {
    return {
      myMap: 'SouthAfrica',
      myZoom: 5,
    };
  },
  mounted() {
    console.log(4);
    this.init();
  },
  computed: {
    ...mapState('timeshareBuy', ['detailedRegion', 'resort', 'availRegion']),
    mapUrl() {
      return `http://maps.google.com/maps?q=${this.myMap}&z=${this.myZoom}&output=embed`;
    },
    regions() {
      return _.sortBy(this.detailedRegion, r => r.regionName);
    },
  },
  methods: {
    ...mapActions('timeshareBuy', [
      'init',
      'getAvail',
      'getRegions',
      'getResort',
    ]),
    routerGoTo(goTo) {
      this.$router.push(goTo);
    },
    updateMap(resort) {
      this.myMap = 'SouthAfrica';
      this.myMap = `${resort.lat},${resort.long}`;
      this.myZoom = 10;
    },
    updateMapProvince(province) {
      this.myMap = province.replace(/\s/g, '');
      this.myZoom = 7;
    },
  },
};
</script>
<style scoped>
.map-url {
  color: #60cbeb;
  text-align: left;
}
.card-item {
  font-size: 100%;
}
.card-item:hover {
  background-color: rgba(255, 255, 255, 0.75);
  border-radius: 5px;
  cursor: pointer;
}
</style>
