import { computed } from 'vue'
import { useThemeStore, type ThemeMode } from '@/store/theme'
import type { ThemeColorKey } from '@/assets/styles/theme/presets'

/**
 * 主题 Composable - 简化主题相关操作
 */
export function useTheme() {
  const themeStore = useThemeStore()

  const isDark = computed(() => themeStore.isDark)
  const primaryColor = computed(() => themeStore.currentColors.primary)
  const themeMode = computed(() => themeStore.config.mode)
  const colorScheme = computed(() => themeStore.config.colorScheme)

  function toggleDark() {
    themeStore.toggleDarkMode()
  }

  function setMode(mode: ThemeMode) {
    themeStore.setMode(mode)
  }

  function setColorScheme(scheme: ThemeColorKey) {
    themeStore.setColorScheme(scheme)
  }

  return {
    isDark,
    primaryColor,
    themeMode,
    colorScheme,
    toggleDark,
    setMode,
    setColorScheme
  }
}
