import { mapActions, mapGetters } from 'vuex'
import { getValue } from '@/helpers/variable-handling'

export default {
  data() {
    return {
      isEWalletActivated: false,
      isBankInfoExpired: false,
    }
  },
  methods: {
    ...mapActions(['loadEWalletDetails']),
    async initMixin() {
      await this.loadEWalletDetails().then(res => {
        if (res) {
          this.isEWalletActivated = res.active === 1
          this.isBankInfoExpired = Boolean(res.bank_info_expired)

          if (!this.isEWalletActivated) {
            this.$router.replace({ name: 'EWalletActivation' })
          }
        }
      })
    },
  },
  computed: {
    ...mapGetters(['getEWalletDetails']),
    getEWalletBalance() {
      return this.getEWalletDetails.balance || '0'
    },
    requiredBankAccountSetup() {
      return (
        !Number.isInteger(getValue(this.getMyAccountMemberDetails, 'banking.payment_data.selected')) ||
        this.isBankInfoExpired
      )
    },
  },
}
