<template>
  <div>
    <template v-for="(item, index) in getShareQrList">
      <share-card
        :key="index"
        :link="item.link"
        :title="item.title"
        :share-platform="item.platforms"
        :qr-link-title="item.qrLinkTitle"
      />
    </template>
  </div>
</template>
<script>
import { mapGetters } from 'vuex'
import AppSettings from '@/config/app-settings'
import { ENROLMENT_URL } from '@/config/defaults'
import MemberPortalShare from '@/config/member-portal-share'
import ShareCard from '@/app/share-qr-code/home/components/blocks/shareCard'

export default {
  name: 'Shareqrcode',
  components: {
    ShareCard,
  },
  computed: {
    ...mapGetters(['getMemberDetails']),
    getMemberId() {
      return this.$helpers.getValue(this.getMemberDetails, 'member_id', '')
    },
    getCardList() {
      return [
        {
          key: 'retail_referral',
          title: this.$t('ShareQR.RetailReferral'),
          order: 1,
          link: `${process.env.VUE_APP_EKG_BASE_URL}?referral=${this.getMemberId}`,
          show: AppSettings.retailPrice.enable && !AppSettings.evo.enable,
        },
        {
          key: 'elken',
          title: this.$t('Common.Elken'),
          order: 2,
          link: `${process.env.VUE_APP_EK_BASE_URL}?sponsor=${this.getMemberId}`,
          show: AppSettings.evo.enable,
        },
        {
          key: 'elken_global',
          title: this.$t('Common.ElkenGlobal.Title'),
          order: 3,
          link: `${process.env.VUE_APP_EKG_BASE_URL}?sponsor=${this.getMemberId}`,
          show: !AppSettings.evo.enable,
        },
        {
          key: 'eshop',
          title: this.$t('Common.Eshop'),
          order: 4,
          link: `${window.location.origin}${ENROLMENT_URL}/sponsor/${this.getMemberId}`,
        },
      ].filter(card => card.show !== false)
    },
    getShareQrList() {
      return this.getCardList
        .map(card => {
          let platforms = MemberPortalShare.socials.map(social => {
            return social.url ? { ...social, url: social.url + card.link } : { ...social }
          })

          let qrLinkTitle =
            (card.key === 'retail_referral' && this.$t('ShareQR.ScanMe')) || this.$t('ShareQR.ScanToEnrol')

          return {
            qrLinkTitle,
            platforms,
            link: card.link,
            title: card.title,
            order: card.order,
          }
        })
        .sort((a, b) => a.order - b.order)
    },
  },
}
</script>
