<template>
  <div>
    <!-- <van-cell
      :title="$t('platform.my.lang-select.title')"
      :value="language"
      icon-prefix="ibps-icon"
      icon="language"
      is-link
      size="large"
      @click="show = true"
    /> -->
    <!-- <van-popup v-model="show" class="ibps-border-r-6" position="bottom">
      <van-picker
        show-toolbar
        title="选择语言"
        :visible-item-count="columns.length"
        :columns="columns"
        @cancel="handleCancel"
        @confirm="handleSetLanguage"
      />
    </van-popup> -->

    <van-action-sheet
      v-model="show"
      :actions="actions"
      :cancel-text="$t('cancel')"
      @cancel="handleCancel"
    />
  </div>
</template>

<script>

export default {
  data() {
    return {
      show: false,
      columns: [{
        text: '中文',
        lang: 'zh-CN',
        disabled: this.$i18n.locale === 'zh-CN'
      },
      {
        text: '繁体中文',
        lang: 'zh-TW',
        disabled: this.$i18n.locale === 'zh-TW'
      },
      {
        text: 'English',
        lang: 'en-US',
        disabled: this.$i18n.locale === 'en-US'
      }],
      actions: [{
        lang: 'zh-CN',
        name: '中文',
        callback: this.handleSetLanguage,
        disabled: this.$i18n.locale === 'zh-CN'
      },
      {
        lang: 'zh-TW',
        name: '繁体中文',
        callback: this.handleSetLanguage,
        disabled: this.$i18n.locale === 'zh-TW'
      },
      {
        lang: 'en-US',
        name: 'English',
        callback: this.handleSetLanguage,
        disabled: this.$i18n.locale === 'en-US'
      }]
    }
  },
  computed: {
    language() {
      return this.$t('_name')
    }
  },
  methods: {
    handleCancel() {
      this.show = false
    },
    handleSetLanguage({ lang }) {
      this.$i18n.locale = lang
      this.$notify({
        type: 'success',
        message: this.$t('platform.my.lang-select.switchLang')
      })
      this.show = false
      setTimeout(() => {
        this.$store.dispatch('ibps/app/setLanguage', lang)
        location.reload()
        // this.$router.push({ path: '/refresh' })
      }, 1000)
    }
  }
}
</script>

