export default function generateColor(baseColor) {
  // 生成背景色
  const backgroundColor = {
    r: 255,
    g: 255,
    b: 255,
  };

  // 计算附加色 1
  const color1 = {
    r: 255,
    g: 255,
    b: 255,
  };
  color1.r -= Math.round((color1.r - baseColor.r) * 0.25);
  color1.g -= Math.round((color1.g - baseColor.g) * 0.25);
  color1.b -= Math.round((color1.b - baseColor.b) * 0.25);

  // 计算附加色 2
  const color2 = {
    r: 255,
    g: 255,
    b: 255,
  };
  color2.r -= Math.round((color2.r - baseColor.r) * 0.5);
  color2.g -= Math.round((color2.g - baseColor.g) * 0.5);
  color2.b -= Math.round((color2.b - baseColor.b) * 0.5);

  // 计算警告色
  const warningColor = {
    r: 255,
    g: 255,
    b: 255,
  };
  warningColor.r -= Math.round((warningColor.r - baseColor.r) * 0.3);
  warningColor.g -= Math.round((warningColor.g - baseColor.g) * 0.3);
  warningColor.b -= Math.round((warningColor.b - baseColor.b) * 0.3);

  // 计算成功色
  const successColor = {
    r: 255,
    g: 255,
    b: 255,
  };
  successColor.r -= Math.round((successColor.r - baseColor.r) * 0.2);
  successColor.g -= Math.round((successColor.g - baseColor.g) * 0.2);
  successColor.b -= Math.round((successColor.b - baseColor.b) * 0.2);

  // 计算失败色
  const failureColor = {
    r: 255,
    g: 255,
    b: 255,
  };
  failureColor.r -= Math.round((failureColor.r - baseColor.r) * 0.2);
  failureColor.g -= Math.round((failureColor.g - baseColor.g) * 0.2);
  failureColor.b -= Math.round((failureColor.b - baseColor.b) * 0.2);

  // 转换为十六进制颜色值
  function rgbToHex(rgbColor) {
    const { r, g, b } = rgbColor;
    const red = Math.round(r);
    const green = Math.round(g);
    const blue = Math.round(b);

    const hexRed = red.toString(16).padStart(2, "0");
    const hexGreen = green.toString(16).padStart(2, "0");
    const hexBlue = blue.toString(16).padStart(2, "0");

    return `#${hexRed}${hexGreen}${hexBlue}`;
  }

  const hexBaseColor = baseColor;
  const hexBackgroundColor = rgbToHex(backgroundColor);
  const hexColor1 = rgbToHex(color1);
  const hexColor2 = rgbToHex(color2);
  const hexWarningColor = rgbToHex(warningColor);
  const hexSuccessColor = rgbToHex(successColor);
  const hexFailureColor = rgbToHex(failureColor);

  return {
    baseColor: hexBaseColor,
    backgroundColor: hexBackgroundColor,
    color1: hexColor1,
    color2: hexColor2,
    warningColor: hexWarningColor,
    successColor: hexSuccessColor,
    failureColor: hexFailureColor,
  };
}

function generateColorScheme(baseColor) {
  // 将基础色转换为 RGB 格式
  const rgbBaseColor = hexToRGB(baseColor);

  // 生成配色方案
  const colorScheme = {
    baseColor: baseColor,
    backgroundColor: rgbBaseColor,
    color1: "",
    color2: "",
    warningColor: "",
    successColor: "",
    failureColor: "",
  };

  // 生成其他颜色
  const colors = [
    { name: "color1", offset: 0.25 },
    { name: "color2", offset: 0.5 },
    { name: "warningColor", offset: 0.3 },
    { name: "successColor", offset: 0.2 },
    { name: "failureColor", offset: 0.2 },
  ];

  for (const color of colors) {
    const newColor = generateOffsetColor(rgbBaseColor, color.offset);
    colorScheme[color.name] = rgbToHex(newColor);
  }

  return colorScheme;
}
