import { useContext } from 'react' import AppContext from '@/contexts/AppContext' export interface ThemeConfig { /** 当前主题 */ theme: 'light' | 'dark' /** 是否为深色模式 */ isDark: boolean /** 是否为浅色模式 */ isLight: boolean /** 切换主题 */ toggleTheme: () => void /** 设置为浅色主题 */ setLight: () => void /** 设置为深色主题 */ setDark: () => void } /** * 主题 Hook * 从 AppContext 获取主题状态和切换函数 */ export const useTheme = (): ThemeConfig => { const { theme, toggleTheme } = useContext(AppContext) const setLight = () => { if (theme !== 'light') toggleTheme() } const setDark = () => { if (theme !== 'dark') toggleTheme() } return { theme, isDark: theme === 'dark', isLight: theme === 'light', toggleTheme, setLight, setDark, } }