/**
 * Shared colour utilities.
 *
 * `hueFromString` is used by `Artwork` (gradient placeholders) and `Genres`
 * (genre-card gradients). Previously duplicated in both files — extracted here
 * as the single source of truth.
 */

/**
 * Deterministic hash → hue from an arbitrary string, clamped to the warm band
 * (amber → rust → deep red, 8°..52°). Free-running 0..359 hues produced blue,
 * teal and violet placeholder tiles that fight the warm room Ethos asks for;
 * a 44° window keeps tiles distinguishable without leaving the palette.
 */
export function hueFromString(s: string): number {
  let h = 0;
  for (let i = 0; i < s.length; i++) h = (h * 31 + s.charCodeAt(i)) | 0;
  return 8 + (Math.abs(h) % 45);
}

/**
 * Build a two-stop diagonal HSL gradient from a seed string. Used by genre
 * cards and artwork placeholders so they get a distinct but deterministic
 * colour per name.
 */
export function gradientFromSeed(
  seed: string,
  sat = 48,
  light = 23,
  light2 = 11,
  hueOffset = 55,
): string {
  const hue = hueFromString(seed);
  return `linear-gradient(160deg, hsl(${hue},${sat}%,${light}%), hsl(${(hue + hueOffset) % 360},${Math.max(sat - 8, 20)}%,${light2}%))`;
}
