<template>
    <div>
        <el-dropdown trigger="click" @command="handleSetLang">
            <div class="size-icon--style">
                <svg-icon class-name="size-icon" icon-class="langen" style="font-size:14px;" />
            </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 lang="ts">
import useAppStore from '@/store/modules/app';
import { computed, ref } from 'vue';
// import { useRoute, useRouter } from 'vue-router';

const appStore = useAppStore();
const lang = computed(() => appStore.language);
const { proxy } = getCurrentInstance() as any;
const mitter = proxy.mitter
const langOptions = ref([
    { label: '中文', value: 'zh-cn' },
    { label: 'English', value: 'en' },
]);

function handleSetLang(currentLanguage: any) {
    proxy!.$modal.loading('正在设置语言，请稍候...');
    appStore.setLanguage(currentLanguage)
    mitter.emit('changeLang', currentLanguage)
    setTimeout(() => {
        proxy!.$modal.closeLoading()
    }, 500);
}
</script>

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