<!--
 * @Author: Jason Liu
 * @Date: 2025-02-06 15:22:24
 * @Desc: 
-->
<template>
  <a-dropdown
    v-if="enabled"
    class="set_lang_button"
  >
    <a
      href="javascript:void(0)"
      class="ant_lang_button"
    >
      <win-icon type="icon_lang" /> {{ $t('语言设置') }} <a-icon type="down" />
    </a>
    <a-menu
      slot="overlay"
      :key="lanKey"
      :defaultSelectedKeys="[$winexI18n.LanName]"
      @click="changeLang"
    >
      <template v-for="item in $winexI18n.languageTypes">
        <a-menu-item :key="item.value">
          <span>{{ item.name }}</span>
        </a-menu-item>
      </template>
    </a-menu>
  </a-dropdown>
</template>

<script>
  export default {
    created() {
      $winexI18n.$bus.$on('changeLan', () => {
        this.enabled = $winexI18n.enabled;
      });
    },
    data() {
      return {
        enabled: $winexI18n.enabled,
        viewName: undefined,
        lanKey: 0,
      };
    },
    methods: {
      changeLang(e) {
        if (e.key != $winexI18n.LanName) {
          this.lanKey++;
          if (!window.__POWERED_BY_QIANKUN__ && top === window) {
            localStorage.setItem('language', e.key);
            window.location.reload();
            return;
          }
          $winexI18n.changeLan(e.key);
        }
      },
    },
  };
</script>

<style lang="less" scoped>
  .set_lang_button {
    position: absolute;
    right: 60px;
    top: 60px;
  }
</style>
