export const COLOR_MAP: Record<string, string> = {
  "white": "#ffffff",
  "black": "#1a1a1a",
  "grey": "#808080",
  "gray": "#808080",
  "red": "#ef4444",
  "blue": "#3b82f6",
  "green": "#22c55e",
  "yellow": "#eab308",
  "orange": "#f97316",
  "purple": "#a855f7",
  "pink": "#ec4899",
  "silver": "#c0c0c0",
  "gold": "#ffd700",
  "transparent": "#f3f4f6",
  "natural": "#f5f5dc",
  "haki": "#4b5320",
  "olive": "#808000",
  "transparent_red": "#ef444488",
  "transparent_blue": "#3b82f688",
};

export const getHexColor = (colorName?: string) => {
  if (!colorName) return "#808080";
  if (colorName.startsWith("#")) return colorName;
  const normalized = colorName.toLowerCase().replace(/\s+/g, '_');
  return COLOR_MAP[normalized] || "#808080";
};

export const isLightColor = (hex: string) => {
  const color = hex.startsWith("#") ? hex : getHexColor(hex);
  const rgb = parseInt(color.slice(1, 7), 16);
  const r = (rgb >> 16) & 0xff;
  const g = (rgb >> 8) & 0xff;
  const b = (rgb >> 0) & 0xff;
  const luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;
  return luma > 200; // Threshold for very light colors
};
