/**
 * Mapea un string a un color de la paleta usando hash DJB-31 deterministico.
 *
 * Hash: h = (h * 31 + charCodeAt(i)) >>> 0  (unsigned 32-bit).
 * El indice es h % palette.length.
 *
 * @throws Error si palette esta vacio.
 */
export function stringHashPalette(s: string, palette: string[]): string {
  if (palette.length === 0) throw new Error("palette must not be empty");
  let h = 0;
  for (let i = 0; i < s.length; i++) {
    h = (h * 31 + s.charCodeAt(i)) >>> 0;
  }
  return palette[h % palette.length];
}
