<template>
  <section id="intro">
    <div class="container">
      <div class="row">
        <div class="col-md-6">
          <div class="intro-content box text-center">
            <h2>Payment Option</h2>
            <select name="" id="" v-model="selectedOption" class="uniSelect form-control">
              <option value="CC">Credit/Debit Card</option>
              <option value="EFT">EFT</option>
            </select>
            <button class="btn-solid-blue mt-5" @click="pushToApi()">Continue</button>
          </div>
        </div>
      </div>
    </div>

    <carousel
      :nav="false"
      :dots="false"
      :items="1"
      :autoplay="true"
      :loop="true"
      :autoHeight="true"
      id="intro-carousel"
      style="margin-top:-50px;"
      :responsive="{ 0: { items: 1, nav: false }, 600: { items: 1, nav: false } }"
    >
      <img class="item" src="/img/intro-carousel/home-1.jpg" alt="" />
      <img class="item" src="/img/intro-carousel/16.jpg" alt="" />
      <img class="item" src="/img/intro-carousel/comm-1.jpg" alt="" />
      <img class="item" src="/img/intro-carousel/comm-4.jpg" alt="" />
      <img class="item" src="/img/intro-carousel/3.jpg" alt="" />
      <img class="item" src="/img/intro-carousel/home-5.jpg" alt="" />
    </carousel>
  </section>
</template>

<script>
/* eslint-disable */
import { mapState, mapActions, mapGetters } from "vuex";
import carousel from "vue-owl-carousel";
import Log from "../../assets/Log";
export default {
  components: {
    carousel
  },
  props: {
    week: {}
  },
  data() {
    return {
      boolLoaded: false,
      selectedOption: "CC"
    };
  },
  computed: {
    ...mapGetters("fees", ["getListingFee"])
  },
  methods: {
    ...mapActions("payment", ["addPayment"]),
    ...mapActions("myWeeks", ["editSave"]),
    pushToApi() {
      if (this.selectedOption == "CC") {
        this.paygateRedirect();
      } else {
        this.week.statusId = 1033; // change this value to link with status
        if (this.week.owner.telephone === "") {
          delete this.week.owner.telephone;
        }
        console.log(JSON.stringify(this.week));
        this.editSave(this.week).then(() => {
          this.$router.push({ name: "EFTPage", params: { week: this.week } });
        });
      }
    },
    paygateRedirect() {
      var amount = this.getListingFee.amount;
      var paymentObj = {
        timeshareWeekId: this.week.id, // this.sellItem.Id,
        propertyId: 0,
        creatydById: Log.getUser().id, //Log.getUser().id,
        amount: amount,
        paymentStatus: "",
        paymentToken: ""
      };

      this.addPayment(paymentObj).then(res => {
        this.$router.push({
          name: "PaymentGateway",
          params: {
            paymentReqId: res.PAY_REQUEST_ID,
            checksum: res.CHECKSUM
          }
        });
      });
    }
  }
};
</script>

<style lang="scss" scoped></style>
