/**
 * Portfolio Color Palette System
 * Provides colors for visualizing portfolio allocations across multiple projects.
 */

export const portfolioColorPalette = [
  '#3B82F6', // Blue 500
  '#06B6D4', // Cyan 500
  '#10B981', // Green 500
  '#14B8A6', // Teal 500
  '#8B5CF6', // Violet 500
  '#6366F1', // Indigo 500
  '#0EA5E9', // Sky 500
  '#22C55E', // Green 400
  '#84CC16', // Lime 500
  '#F59E0B', // Amber 500
  '#EC4899', // Pink 500
  '#EF4444', // Red 500
];

export function getProjectColor(index: number): string {
  return portfolioColorPalette[index % portfolioColorPalette.length];
}

export function getProjectColors(count: number): string[] {
  return Array.from({ length: count }, (_, i) => getProjectColor(i));
}

export function hexToRgb(hex: string): { r: number; g: number; b: number } | null {
  const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
  return result
    ? {
        r: parseInt(result[1], 16),
        g: parseInt(result[2], 16),
        b: parseInt(result[3], 16),
      }
    : null;
}

export function hexToRgba(hex: string, opacity: number): string {
  const rgb = hexToRgb(hex);
  if (!rgb) return hex;
  return `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${opacity})`;
}
