// 预设的高级感渐变色盘
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%)', // 浅绿蓝
];

// Generate a consistent gradient from a string
export 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];
}

// Calculate font size based on container size and text length
export function calculateFontSize(containerSize: number, textLength: number): number {
  // 增加 Padding 后的可用空间会变小，所以字体要稍微调小一点，保持呼吸感
  // 假设 padding 是 10%
  
  if (textLength <= 2) return containerSize * 0.35;
  if (textLength <= 4) return containerSize * 0.25;
  if (textLength <= 6) return containerSize * 0.18; // 两行，每行3个字
  if (textLength <= 9) return containerSize * 0.15; // 三行或两行
  if (textLength <= 15) return containerSize * 0.12;
  return containerSize * 0.10; // Very long text
}
