<template>
  <div>
    <el-dropdown trigger="click" @command="handleSetLang">
      <div class="size-icon--style">
        <i class="iconfont icon-zhongyingwen langimg"></i>
      </div>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item v-for="item of langOptions" :key="item.value" :disabled="lang === item.value"
            :command="item.value">
            {{ item.label }}
          </el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>

<script setup>
import useAppStore from "@/store/modules/app";

const appStore = useAppStore();
const lang = computed(() => appStore.lang);
const route = useRoute();
const router = useRouter();
const { proxy } = getCurrentInstance();
const langOptions = ref([
  { label: "中文", value: "zh-CN" },
  { label: "English", value: "en-US" },
]);

function handleSetLang(lang) {
  proxy.$modal.loading(proxy.tLang('tip','正在设置语言，请稍候') + "...");
  appStore.setLang(lang);
  setTimeout("window.location.reload()", 1000);
}
</script>

<style lang='scss' scoped>
.size-icon--style {
  font-size: 18px;
  line-height: 50px;
  padding: 0 7px;
}
.langimg {
  font-size: 36px;
}
</style>