/**
 * Color utility functions for EPG theming
 * Provides helpers for converting hex colors to rgba strings
 */

/**
 * Converts a hex color to RGB components
 * @param hex - Hex color string (e.g., "#ff6b35" or "ff6b35")
 * @returns RGB object with r, g, b values (0-255)
 */
export function hexToRgb(hex: string): { r: number; g: number; b: number } {
  const cleanHex = hex.replace('#', '');
  const r = parseInt(cleanHex.substring(0, 2), 16);
  const g = parseInt(cleanHex.substring(2, 4), 16);
  const b = parseInt(cleanHex.substring(4, 6), 16);
  return { r, g, b };
}

/**
 * Converts a hex color to rgba string with specified opacity
 * @param hex - Hex color string (e.g., "#ff6b35")
 * @param opacity - Opacity value (0-1)
 * @returns RGBA string (e.g., "rgba(255, 107, 53, 0.3)")
 */
export function hexToRgba(hex: string, opacity: number): string {
  const { r, g, b } = hexToRgb(hex);
  return `rgba(${r}, ${g}, ${b}, ${opacity})`;
}

/**
 * Validates if a string is a valid hex color
 * @param hex - String to validate
 * @returns true if valid hex color
 */
export function isValidHex(hex: string): boolean {
  return /^#?[0-9A-Fa-f]{6}$/.test(hex);
}
