import { useColorScheme } from 'react-native';
import { Colors, type ThemeColors } from '../constants/Colors';

/**
 * Hook to get the current theme colors
 * @returns The colors for the current color scheme
 */
export function useThemeColors(): ThemeColors {
  const colorScheme = useColorScheme() ?? 'dark';
  return Colors[colorScheme];
}

/**
 * Hook to get a specific color from the theme
 * @param colorName - The name of the color to retrieve
 * @returns The color value for the current theme
 */
export function useThemeColor<K extends keyof ThemeColors>(
  colorName: K
): ThemeColors[K] {
  const colors = useThemeColors();
  return colors[colorName];
}

/**
 * Hook to get multiple colors from the theme
 * @param colorNames - Array of color names to retrieve
 * @returns Object with requested color values
 */
export function useThemeColorSet<K extends keyof ThemeColors>(
  colorNames: K[]
): Pick<ThemeColors, K> {
  const colors = useThemeColors();
  return colorNames.reduce((acc, name) => {
    acc[name] = colors[name];
    return acc;
  }, {} as Pick<ThemeColors, K>);
}

/**
 * Hook to check if the current theme is dark
 * @returns boolean indicating if dark mode is active
 */
export function useIsDarkMode(): boolean {
  const colorScheme = useColorScheme();
  return colorScheme === 'dark';
}
