<template>
  <el-dropdown trigger="click" @command="onSwitch">
    <el-button text>{{ t('common.language') }}</el-button>
    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item command="zh-CN">{{ t('common.zh') }}</el-dropdown-item>
        <el-dropdown-item command="en">{{ t('common.en') }}</el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>

<script setup lang="ts">
import { useI18n } from 'vue-i18n'
import { setLocale } from '@/i18n'

const { t } = useI18n()

function onSwitch(locale: 'zh-CN' | 'en') {
  setLocale(locale)
}
</script>
