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

export default {
  data() {
    return {
      showResetPinModal: false,
    }
  },
  computed: {
    ...mapGetters(['getMyAccountMemberDetails']),
    getMemberContactInfo() {
      return {
        phoneNumber: getValue(this.getMyAccountMemberDetails, 'contact_info.mobile_1_num'),
        countryCode: getValue(this.getMyAccountMemberDetails, 'contact_info.mobile_1_country_code_id'),
      }
    },
  },
  deactivated() {
    this.closeModal()
  },
  methods: {
    openResetSecurityPinModal(ref = 'resetSecurityPinModal') {
      let self = this

      this.$swal({
        type: 'warning',
        title: self.$t('Common.Security.ResetSecurityPinConfirmationText'),
        showConfirmButton: true,
        showCancelButton: true,
        confirmButtonText: self.$t('EWallet.ResetSecurityPin'),
        cancelButtonText: self.$t('Common.Dismiss'),
      }).then(res => {
        self.showResetPinModal = res.value || false

        if (res.value) {
          self.$nextTick(() => {
            if (self.$refs[ref] && self.getMemberContactInfo.countryCode && self.getMemberContactInfo.phoneNumber) {
              self.$refs[ref].show()
            } else {
              self.$swal({
                type: 'error',
                title: self.$t('Common.UnexpectedErrorHeader.Title'),
                text: self.$t('Common.Error.ActionFailure.HelpText'),
              })
            }
          })
        }
      })
    },
    closeModal() {
      this.showResetPinModal = false
    },
  },
}
