// Complete Bambu Lab color database with hex codes
// Re-exports catalog-aligned color groupings

import { BAMBU_LAB_CATALOG } from './bambuLabCatalog';

// Flat hex lookup (for backwards compatibility)
export const bambuLabColors: Record<string, string> = {
  // PLA Basic
  "Jade White": "#FFFFFF",
  "Black": "#000000",
  "White": "#FFFFFF",
  "Red": "#E53935",
  "Blue": "#1E88E5",
  "Green": "#43A047",
  "Yellow": "#FDD835",
  "Orange": "#FB8C00",
  "Purple": "#5E43B7",
  "Pink": "#F55A74",
  "Gray": "#8E9089",
  "Brown": "#9D432C",
  "Light Blue": "#61B0FF",
  "Light Gray": "#D0D2D4",
  "Sky Blue": "#73B2E5",
  "Navy Blue": "#0C2340",
  "Magenta": "#EC008C",
  "Beige": "#F7E6DE",
  "Bambu Green": "#00AE42",
  "Scarlet Red": "#DE4343",
  "Lemon Yellow": "#F7D959",
  "Cyan": "#0086D6",
  "Sakura Pink": "#E8AFCF",
  "Cobalt Blue": "#0055B8",
  "Mistletoe Green": "#3F8E43",
  "Dark Red": "#BB3D43",
  "Hot Pink": "#F5547D",
  "Lavender": "#B5AAD5",
  "Sunflower Yellow": "#FEC601",
  "Pumpkin Orange": "#FF8E16",
  "Lime": "#C5ED48",
  "Blue Grey": "#5B6579",
  "Gold": "#E4BD68",
  "Bright Green": "#BDCF00",
  "Maroon Red": "#0A2989",
  "Turquoise": "#00B1B7",
  "Bronze": "#847D48",
  "Silver": "#A6A9AA",
  "Dark Gray": "#555555",

  // PLA Basic Gradient
  "Neon City": "#0047BB",
  "Midnight Blaze": "#0047BB",
  "South Beach": "#468791",
  "Arctic Whisper": "#ECF7F8",
  "Cotton Candy Cloud": "#E9E2EC",
  "Ocean to Meadow": "#A1E4CA",
  "Solar Breeze": "#F3D9D5",
  "Velvet Eclipse": "#000000",
  "Dawn Radiance": "#C472A1",
  "Dusk Glare": "#F6B790",
  "Blueberry Bubblegum": "#BADCF4",
  "Blue Hawaii": "#739FE6",
  "Gilded Rose": "#ED982C",
  "Pink Citrus": "#F8C4BC",
  "Mint Lime": "#BAF382",

  // PLA Matte
  "Matte Ivory White": "#FFFFF0",
  "Matte Charcoal": "#333333",
  "Matte Scarlet Red": "#DE4343",
  "Matte Marine Blue": "#0078BF",
  "Matte Mandarin Orange": "#F99963",
  "Matte Ash Gray": "#9B9EA0",
  "Matte Desert Tan": "#E8DBB7",
  "Matte Nardo Gray": "#747474",
  "Matte Apple Green": "#C6E188",
  "Matte Bone White": "#C8C5B6",
  "Matte Caramel": "#A4845C",
  "Matte Dark Blue": "#042F56",
  "Matte Dark Brown": "#7D6556",
  "Matte Dark Chocolate": "#4A3729",
  "Matte Dark Green": "#68724D",
  "Matte Dark Red": "#BB3D43",
  "Matte Grass Green": "#7CB342",
  "Matte Ice Blue": "#A3D8E1",
  "Matte Lemon Yellow": "#F7D959",
  "Matte Lilac Purple": "#AE96D4",
  "Matte Plum": "#851A52",
  "Matte Sakura Pink": "#E8AFCF",
  "Matte Sky Blue": "#73B2E5",
  "Matte Latte Brown": "#D3B7A7",
  "Matte Terracotta": "#A25A37",

  // PLA Silk+
  "Candy Green": "#408619",
  "Candy Red": "#BB3A2E",
  "Mint": "#A5DAB7",
  "Titan Gray": "#606367",
  "Rose Gold": "#B29593",
  "Champagne": "#EBD0B1",
  "Baby Blue": "#AEC3ED",

  // PLA Silk Multi-Color
  "Silk Aurora Purple": "#7F3696",
  "Silk Phantom Blue": "#00629B",
  "Silk Mystic Magenta": "#720062",

  // PLA Metal
  "Iron Gray Metallic": "#6B6C6F",
  "Iridium Gold Metallic": "#B39B84",
  "Cobalt Blue Metallic": "#39699E",
  "Copper Brown Metallic": "#AA6443",
  "Oxide Green Metallic": "#1D7C6A",

  // PLA Sparkle
  "Onyx Black Sparkle": "#2D2B28",
  "Classic Gold Sparkle": "#E4BD68",
  "Crimson Red Sparkle": "#792B36",
  "Royal Purple Sparkle": "#483D8B",
  "Slate Gray Sparkle": "#8E9089",
  "Alpine Green Sparkle": "#3F5443",

  // PLA Galaxy
  "Nebulae": "#424379",

  // PLA Marble
  "White Marble": "#F7F3F0",
  "Red Granite": "#AD4E38",

  // PLA Glow
  "Glow Blue": "#7AC0E9",
  "Glow Green": "#A1FFAC",
  "Glow Orange": "#FF9D5B",
  "Glow Pink": "#F17B8F",
  "Glow Yellow": "#F8FF80",

  // PLA Wood
  "Ochre Yellow": "#BC8B39",
  "White Oak": "#D2CCA2",
  "Clay Brown": "#8E621A",

  // PLA CF
  "Burgundy Red": "#951E23",
  "Jeans Blue": "#6E88BC",
  "Lava Gray": "#4D5054",
  "Matcha Green": "#5C9748",
  "Royal Blue": "#2842AD",
  "Iris Purple": "#69398E",

  // PETG HF
  "Cream": "#F3E0B8",
  "Forest Green": "#415520",
  "Lake Blue": "#4672E4",
  "Lime Green": "#8EE43D",
  "Peanut Brown": "#7E5A1F",

  // PETG Translucent
  "Clear": "#FAFAFA",
  "Translucent Gray": "#B8B8B8",
  "Translucent Brown": "#C89A74",
  "Translucent Purple": "#C5A8D8",
  "Translucent Orange": "#FFB380",
  "Translucent Olive": "#A4B885",
  "Translucent Pink": "#F9B8D0",
  "Translucent Light Blue": "#A8D8F0",
  "Translucent Tea": "#D9C7A8",

  // PETG CF
  "Brick Red": "#9F332A",
  "Indigo Blue": "#324585",
  "Malachite Green": "#16B08E",
  "Violet Purple": "#583061",

  // ABS
  "ABS Azure": "#489FDF",
  "ABS Black": "#000000",
  "ABS Blue": "#0A2989",
  "ABS Olive": "#748C45",
  "ABS Tangerine Yellow": "#FFC72C",
  "ABS Navy Blue": "#0C2340",
  "ABS Orange": "#FF6A13",
  "ABS Bambu Green": "#00AE42",
  "ABS Red": "#C12E1F",
  "ABS White": "#FFFFFF",
  "ABS Silver": "#A6A9AA",
  "ABS GF Yellow": "#FDD835",
  "ABS GF Orange": "#F48438",

  // TPU
  "Flesh": "#E8C4A2",
  "Light Cyan": "#B9E3DF",
  "Neon Orange": "#F68A1B",
  "Blaze": "#E78390",
  "Frozen": "#A6DEF3",
  "Grape Jelly": "#6B2D75",
  "Crystal Blue": "#5BC0EB",
  "Quicksilver": "#A6A9AA",
  "Cocoa Brown": "#6F5034",
  "TPU 95A HF Yellow": "#F3E600",

  // PC
  "Clear Black": "#5A5161",
  "Transparent": "#FFFFFF",
};

// Colors grouped by finish type — derived from catalog
export const colorsByFinish: Record<string, string[]> = {};

// Build colorsByFinish from catalog
for (const [, finishes] of Object.entries(BAMBU_LAB_CATALOG)) {
  for (const [finishName, finishData] of Object.entries(finishes)) {
    if (!colorsByFinish[finishName]) {
      colorsByFinish[finishName] = [];
    }
    for (const color of finishData.colors) {
      if (!colorsByFinish[finishName].includes(color.name)) {
        colorsByFinish[finishName].push(color.name);
      }
    }
  }
}

// Sort each finish's colors
for (const finish of Object.keys(colorsByFinish)) {
  colorsByFinish[finish].sort();
}

// Function to get hex code for a color
export function getColorHex(colorName: string): string {
  return bambuLabColors[colorName] || "#000000";
}

// Function to get colors for a specific finish
export function getColorsForFinish(finish: string): string[] {
  return colorsByFinish[finish] || [];
}
