<template>
  <a-select :class="prefixCls" v-model:value="text" :options="OPTIONS" @change="handleMenuClick"> </a-select>
</template>

<script lang="ts" setup>
  // import { Button, Dropdown, Menu, MenuItem } from 'ant-design-vue';
  // import { DownOutlined } from '@ant-design/icons-vue';
  import { useDesign } from '/@/hooks/web/useDesign';
  import { onMounted, ref } from 'vue';
  import { PageEnum } from '/@/enums/pageEnum';
  import { useRouter } from 'vue-router';
  import { useI18n } from '/@/hooks/web/useI18n';

  const { prefixCls } = useDesign('system-select');
  const router = useRouter();
  const { t } = useI18n();
  const text = ref('');

  function handleMenuClick(value) {
    router.push({ path: value });
  }

  // const OPTIONS = ref({
  //   [PageEnum.BASE_HOME]: t('routes.basic.baseHome'),
  //   [PageEnum.SECONDARY_HOME]: t('routes.basic.secondaryHome'),
  // });
  const OPTIONS = ref([
    {
      value: PageEnum.BASE_HOME,
      label: t('routes.basic.baseHome'),
    },
    {
      value: PageEnum.SECONDARY_HOME,
      label: t('routes.basic.secondaryHome'),
    },
  ]);

  onMounted(() => {
    // 由于BASE_HOME仅代表了一个页面，其他页面都隶属于SECONDARY_HOME，所以简单处理
    const isBaseHome = router.currentRoute.value.path === PageEnum.BASE_HOME;
    text.value = isBaseHome ? t('routes.basic.baseHome') : t('routes.basic.secondaryHome');
  });

  defineExpose({ OPTIONS, prefixCls, handleMenuClick });
</script>
<style lang="less" scoped>
  @prefix-cls: ~'@{namespace}-system-select';

  .@{prefix-cls} {
    margin-left: 10px;
    margin-top: 10px;
    width: 210px;
    position: relative;
    z-index: @layout-basic-z-index;
  }

  .@{prefix-cls}.ant-select {
    :deep(.ant-select-selector) {
      background-color: @primary-color;
      .ant-select-selection-item {
        color: @white;
      }
    }
    :deep(.ant-select-arrow) {
      color: @white;
    }
  }
</style>
