// 预设的渐变色（12 条即可，可按喜好改）
const GRADIENTS = [
  'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
  'linear-gradient(135deg, #2af598 0%, #009efd 100%)',
  'linear-gradient(135deg, #b721ff 0%, #21d4fd 100%)',
  'linear-gradient(135deg, #ff9a9e 0%, #fecfef 99%, #fecfef 100%)',
  'linear-gradient(135deg, #f093fb 0%, #f5576c 100%)',
  'linear-gradient(135deg, #4facfe 0%, #00f2fe 100%)',
  'linear-gradient(135deg, #43e97b 0%, #38f9d7 100%)',
  'linear-gradient(135deg, #fa709a 0%, #fee140 100%)',
  'linear-gradient(135deg, #30cfd0 0%, #330867 100%)',
  'linear-gradient(135deg, #a18cd1 0%, #fbc2eb 100%)',
  'linear-gradient(135deg, #fbc2eb 0%, #a6c1ee 100%)',
  'linear-gradient(135deg, #8fd3f4 0%, #84fab0 100%)',
];

// 根据字符串得到固定渐变
function stringToColor(str: string): string {
  let hash = 0;
  for (let i = 0; i < str.length; i++) {
    hash = str.charCodeAt(i) + ((hash << 5) - hash);
  }
  const index = Math.abs(hash) % GRADIENTS.length;
  return GRADIENTS[index];
}

// 按字数算字号（可选，和图标一起用时复现完整效果）
function calculateFontSize(containerSize: number, textLength: number): number {
  if (textLength <= 2) return containerSize * 0.35;
  if (textLength <= 4) return containerSize * 0.25;
  if (textLength <= 6) return containerSize * 0.18;
  if (textLength <= 9) return containerSize * 0.15;
  if (textLength <= 15) return containerSize * 0.12;
  return containerSize * 0.1;
}

export { stringToColor, calculateFontSize };
