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

<script>
  export default {
    created() {
      $winexI18n.$bus.$on('changeLan', () => {
        this.enabled = $winexI18n.enabled;
      });
    },
    data() {
      return {
        enabled: $winexI18n.enabled,
        viewName: undefined,
        types: [],
      };
    },
    methods: {
      changeLang(e) {
        if (e.key != $winexI18n.LanName) {
          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_menu {
    /deep/.ant-menu-submenu {
      .ant-menu-item {
        height: 32px;
        line-height: 32px;
        &:hover {
          background: #e6f7ff;
        }
      }
      .ant-menu-submenu-title {
        height: 32px;
        line-height: 32px;
        padding: 0 12px;
        &:hover {
          background: #e6f7ff;
        }
      }
    }
  }
</style>
