<template>
  <a-dropdown trigger="hover" @select="handleSelect">
    <div class="header-right-theme-item">
      <img class="icon-theme-img" src="../../../assets/theme.png" />
    </div>

    <template #content>
      <a-doption value="light">{{ $t('theme.light') }}</a-doption>
      <a-doption value="dark">{{ $t('theme.dark') }}</a-doption>
    </template>
  </a-dropdown>
</template>

<script setup>
import { setThemeDark, setThemeLight } from '../../../base/theme';

const props = defineProps({
  label: String
});

/**
 * 设置系统主题
 * @param {string} theme - 主题 dark/theme
 */
const handleThemeChange = (theme) => {
  if (theme === 'dark') {
    setThemeDark();
  }

  if (theme === 'light') {
    setThemeLight();
  }
};

const handleSelect = (value) => {
  handleThemeChange(value);
};
</script>

<style lang="css" scoped>
.header-right-theme-item {
  color: var(--color-text-2);
  width: 30px;
  height: 30px;
  border-radius: 20px;
  border: solid 1px var(--color-border-2);

  display: flex;
  justify-content: center;
  align-items: center;

  cursor: pointer;
}

.icon-theme-img {
  width: 16px;
}
</style>
