<template>
    <div class="card p-card pb-3 mb-3 mx-2">
    <h4 class="card-custom-title">
      {{ $t(i18nConst.myPageRewardsTitle) }}
    </h4>
    <hr>
    <div class="row">
      <div class="col-12 d-flex justify-content-center">
        <div class="text-center">
          <p style="font-weight: bold;">{{ $t(i18nConst.myPageRewardsTotalClaimableRewards) }}</p>
        </div>
      </div>
      <div class="col-12 d-flex justify-content-between">
        <div>
            <img src="@/assets/logo_blackback.png" class="img-metadex" />
        </div>
        <div class="text-end">
          <p v-if="rewards">{{utils.formatDisplayAmountMetadexWithEthers(rewards)}}</p>
        </div>
      </div>
      <div class="col-12 d-flex justify-content-center">
        <div class="text-center">
          <p style="font-weight: bold;">{{ $t(i18nConst.myPageRewardsMetadexPrice) }}</p>
        </div>
      </div>
      <div class="col-12 d-flex justify-content-between">
        <div>
        </div>
        <div class="text-end">
          <p>{{ utils.formatDisplayAmount(metadexToUsdcPrice) }}</p>
        </div>
      </div>
      <div class="col-12 d-flex justify-content-center">
        <button v-if="!actionInProgress" type="button" class="btn btn-primary w-100 mb-4" :class="rewards > 0 ? '' : 'disabled'" @click="claimRewards">{{ $t(i18nConst.myPageRewardsBtnClaimAllRewards) }}</button>
        
        <button v-else id="confirm-buy-btn" type="button" class="btn btn-primary disabled w-100 mb-4">
          <span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
        </button>
          
      </div>
    </div>
  </div>
</template>

<script>
import {mapGetters} from "vuex";
import web3Utils from "@/utils/web3.utils.js";
import i18nConstantes from "@/constantes/i18n.constantes.js";
import typeActions from "@/store/typeActions";

export default {
    name: "MyPageRewards",
    data() {
        return {
            utils: web3Utils,
            i18nConst: i18nConstantes,
        };
    },
    computed: {
        ...mapGetters("liquidityPool", ["metadexToUsdcPrice"]),
        ...mapGetters("rewards", ["rewards", "actionInProgress"]),
    },
    methods: {
        claimRewards() {
            this.$store.dispatch(typeActions.claimRewards);    
        }
    },
    async mounted() {
        this.$store.dispatch(typeActions.updateMetadexToUsdcPrice);
        this.$store.dispatch(typeActions.getRewardsAmount);
    },
}
</script>

<style lang="scss" scoped>
.img-metadex {
  width: 30px;
  margin-right: 0.3rem;
}
</style>