<template>
  <div>
    <div v-if="isBondingOnline" class="row">
      <div id="bc-graph" class="col-sm-12 col-md-6 mb-4">
        <bc-graph></bc-graph>
      </div>
      <div id="bc-buy-sell" class="col-sm-12 col-md-6">
        <div class="row">
          <div class="col-12">
            <div class="card text-bg-light mb-2">
              <div class="card-body">
                <div class="row d-flex justify-content-around">
                  <div class="col-6">
                    <button id="buy-btn" :class="isBuy ? 'btn-meta-1' : 'btn-meta-2'" class="btn w-100" type="button"
                            @click="rotateBuySell($event)">{{
                        $t(i18nConst.bondingBuy)
                      }}
                    </button>
                  </div>
                  <div class="col-6">
                    <button id="sell-btn" :class="!isBuy ? 'btn-meta-1' : 'btn-meta-2'" class="btn w-100" type="button"
                            @click="rotateBuySell($event)">{{
                        $t(i18nConst.bondingSell)
                      }}
                    </button>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div :class="{ 'rotate-buy': isBuy, 'rotate-sell': !isBuy }" class="flip-card-inner container">
          <bc-buy v-if="allowanceBuyMetadex > 0 && isBuy" :governanceToken="governanceToken" :reserveToken="reserveToken" class="bc-buy" style="z-index:-1">
          </bc-buy>
          <bc-allowance-buy-metadex v-if="allowanceBuyMetadex <= 0 && isBuy" class="bc-buy" style="z-index:-1"></bc-allowance-buy-metadex>
          <!-- <lp-buy v-if="isBuy" class="bc-buy" style="z-index:-1"></lp-buy> -->
          <bc-sell v-if="allowanceSellMetadex > 0 && !isBuy" :governanceToken="governanceToken" :reserveToken="reserveToken" class="bc-sell"></bc-sell>
          <bc-allowance-sell-metadex v-if="allowanceSellMetadex <= 0 && !isBuy" class="bc-sell"></bc-allowance-sell-metadex>
          <!-- <lp-sell v-else class="bc-sell" style="z-index:-1" :governanceToken="governanceToken" :reserveToken="reserveToken"></lp-sell> -->
        </div>
      </div>
    </div>
    <div v-else class="row mb-4">
      <div class="col-md-12">
        <div class="card">
          <h2 class="bonding-offline-title">{{ $t(i18nConst.bondingOfflineTitle) }}</h2>
        </div>
      </div>
    </div>
    <vesting></vesting>
    <!-- <div class="row mb-4">
      <div class="col-12">
        <div class="card">
          <h4 class="card-custom-title">
            {{ $t(i18nConst.bondingPendingTransactions) }}
          </h4>
          <hr>
        </div>
      </div>
    </div>
    <div class="row mb-4">
      <div class="col-12">
        <div class="card">
          <h4 class="card-custom-title">
            {{ $t(i18nConst.bondingCompleteTransactions) }}
          </h4>
          <hr>
        </div>
      </div>
    </div>
    <div class="row mb-4">
      <div class="col-12">
        <div class="card">
          <h4 class="card-custom-title">
            {{ $t(i18nConst.bondingTransactionHistory) }}
          </h4>
          <hr>
        </div>
      </div>
    </div> -->
  </div>
</template>

<script>
import BcBuy from '../components/bonding/BcBuy.vue';
//import LpBuy from '../components/liquidityPool/LpBuy.vue';
import BcSell from '../components/bonding/BcSell.vue';
//import LpSell from '../components/liquidityPool/LpSell.vue';
import BcGraph from '../components/bonding/BcGraph.vue';
import Vesting from "../components/bonding/vesting/Vesting.vue";
import BcAllowanceSellMetadex from "../components/bonding/BcAllowanceSellMetadex.vue";
import BcAllowanceBuyMetadex from "../components/bonding/BcAllowanceBuyMetadex.vue";
import i18nConstantes from "@/constantes/i18n.constantes.js";
import constantes from "@/constantes/constantes.js";
import typeActions from "@/store/typeActions";
import {mapGetters} from "vuex";

export default {
  data() {
    return {
      i18nConst: i18nConstantes,
      constantes: constantes,
      reserveToken: 'USDC',
      governanceToken: 'METADEX',
      isBuy: true
    }
  },
  components: {
    BcBuy,
    BcSell,
    BcGraph,
    Vesting,
    BcAllowanceSellMetadex,
    BcAllowanceBuyMetadex,
    // LpBuy,
    // LpSell
  },
  computed: {
    ...mapGetters("bonding", [
      "isBondingOnline",
    ]),
    ...mapGetters("global", ["allowanceSellMetadex","allowanceBuyMetadex"]),
  },
  methods: {
    rotateBuySell(event) {
      this.isBuy = event.target.id === 'buy-btn' ? true : false;
    }
  },
  mounted() {
    this.$store.dispatch(typeActions.checkBondingOnline);
    this.$store.dispatch(typeActions.getAllowanceSellMetadex);
    this.$store.dispatch(typeActions.getAllowanceBuyMetadex);
    this.$store.dispatch(typeActions.getTotalSupply);
    this.$store.dispatch(typeActions.getBuyPrice);
  }
};
</script>

<style>
.card-bc-item {
  padding: 0.8rem;
  border-radius: 0.3rem;
}

.card-bc-item:hover {
  background-color: var(--grey-custom);
}

.flip-card-inner {
  position: relative;
  transition: transform 0.5s;
  transform-style: preserve-3d;
}

.rotate-sell {
  transform: rotateY(180deg);
  padding: unset;
  margin-left: -0.7rem;
  margin-bottom: 1rem;
}

.rotate-buy {
  transform: rotateY(0);
  padding: unset;
  margin-left: 0.7rem;
  margin-bottom: 1rem;
}

.bc-buy,
.bc-sell {
  /*position: absolute;*/
  width: 100%;
  height: 100%;
  -webkit-backface-visibility: hidden;
  /* Safari */
  backface-visibility: hidden;
}

.bc-sell {
  transform: rotateY(180deg);
}


#bc-buy-sell {
  perspective: 1000px;
}

.bonding-offline-title {
  margin: 2rem;
  text-align: center;
}
</style>
