<template>
  <div class="topContainer">
    <img @click="tapImg" style="height: 60px" src="@/assets/images/xue_icon.png" alt="" />
    <div class="rightContainer">
      <a :href="urlApple" class="download">
        <img style="width: 18px; height: 18px; margin-right: 8px" :src="appImg" alt="" />
        {{ $t('下载') }}
      </a>
      <a :href="urlAndroid" style="margin-right: 150px; margin-left: 40px" class="download">
        <img style="width: 18px; height: 18px; margin-right: 8px" :src="androidImg" alt="" />
        {{ $t('下载') }}
      </a>
      <span @click="switchLanguage(langString)" style="padding-right: 40px; font-weight: 600">{{
        currentLanguage
      }}</span>
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue'
import { ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { useRouter } from 'vue-router'
import appImg from '@/assets/images/apple.png'
import androidImg from '@/assets/images/android.png'
// 使用 vue-i18n 的 useI18n 钩子
const { locale } = useI18n()

// console.log(useI18n())
const urlApple =
  'https://apps.apple.com/cn/app/%E9%9B%AA%E7%9B%88%E6%8A%95%E9%A1%BE-%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E6%8E%8C%E6%8F%A1/id6618148867'

const urlAndroid = 'https://xueyingapp2he1download.s3.ap-east-1.amazonaws.com/index.html'

const language = ref('English')
const langString = ref('en-US')
const router = useRouter()
function tapImg() {
  router.push({ path: '/' })
}
function switchLanguage(lang) {
  if (lang === 'en-US') {
    langString.value = 'zh-CN'
  } else if (lang === 'zh-CN') {
    langString.value = 'en-US'
  }
  locale.value = lang
}

const currentLanguage = computed(() => {
  if (locale.value === 'zh-CN') {
    language.value = 'English'
  } else if (locale.value === 'en-US') {
    language.value = '简体中文'
  }

  return language.value
})
</script>

<style scoped>
.topContainer {
  width: 100%;
  height: 90px;
  background-image: url(@/assets/images/bg-header.gif);
  justify-content: space-between;
  padding-left: 40px;
  align-items: center;
  display: flex;
}
.rightContainer {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}
.download {
  width: 150px;
  height: 60px;
  display: flex;
  border: 1px solid white;
  border-radius: 8px;
  justify-content: center;
  align-items: center;
  /* padding: 15px 30px; */
  flex-direction: row;
  margin-left: 0px;
  color: #fff;
  text-decoration: none;
}
</style>
