<template>
  <el-dropdown class="lang-select" @command="handleSetLanguage">
    <svg-icon icon-class="language" />
    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item :disabled="language === 'zh-cn'" command="zh-cn">
          中文
        </el-dropdown-item>
        <el-dropdown-item :disabled="language === 'en'" command="en">
          English
        </el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>

<script setup lang="ts">
import { computed, getCurrentInstance } from 'vue';
import useStore from '@/store';
import { useI18n } from 'vue-i18n';

const { app } = useStore();
const language = computed(() => app.language);

const { locale } = useI18n();
const { proxy }: any = getCurrentInstance();
function handleSetLanguage(lang: string) {
  locale.value = lang;
  app.setLanguage(lang);
  if (lang == 'en') {
    proxy.$ElMessage.success('Switch Language Successful!');
  } else {
    proxy.$ElMessage.success('切换语言成功');
  }
}
</script>

<style lang="scss" scoped>
.lang-select{
  cursor: pointer;
  font-size: 20px;
}
</style>
