<template>
  <el-dropdown trigger="click" @command="handleSetLanguage">
    <div>{{ language }}</div>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item :disabled="language === 'zh'" command="zh">
        中文
      </el-dropdown-item>
      <el-dropdown-item :disabled="language === 'en'" command="en">
        English
      </el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script lang="ts">
import { Component, Vue, Watch } from "vue-property-decorator";
import { setLocale } from "@/lang";
import { setPageTitle } from "@/utils";
@Component
export default class extends Vue {
  get language() {
    switch (this.$i18n.locale) {
      case "zh":
        return "中文";
      default:
        return "English";
    }
  }

  private handleSetLanguage(lang: string) {
    setLocale(lang);
    setPageTitle(this.$route.meta.title);
    this.$message({
      message: "Switch Language Success",
      type: "success"
    });
  }
}
</script>
