// Procedural NMS-flavored naming. Seeded so a planet always gets the same names.
import { Rng } from './noise.js';

const PRE = ['Ye', 'Zha', 'Olu', 'Kor', 'Vael', 'Nyx', 'Thal', 'Ouma', 'Sib', 'Aza',
  'Drel', 'Phae', 'Wuu', 'Ixa', 'Qel', 'Mor', 'Tuva', 'Esh', 'Holu', 'Cyn'];
const MID = ['mur', 'kar', 'len', 'sib', 'dra', 'wen', 'tos', 'pha', 'gol', 'rin',
  'val', 'nos', ' thu', 'bek', 'ria', 'sho', 'lun', 'der', 'qua', 'mer'];
const SUF = ['ra', 'tau', 'on', 'is', 'ux', 'eth', 'ia', 'or', 'um', 'ek', 'ai', 'os'];
const GREEK = ['Tau', 'Prime', 'Minor', 'IX', 'VII', 'Majoris', 'Secundus', 'b', 'd', 'Reach', 'IV'];

const BIOME_ADJ = ['Toxic', 'Frozen', 'Scorched', 'Verdant', 'Irradiated', 'Tranquil', 'Tempestuous',
  'Hollow', 'Lush', 'Barren', 'Crystalline', 'Humming', 'Bleached', 'Drowned', 'Volcanic', 'Pastel'];
const BIOME_NOUN = ['Expanse', 'Wastes', 'Garden World', 'Steppe', 'Reach', 'Basin', 'Flats',
  'Highlands', 'Bloom', 'Sprawl', 'Hollows', 'Marches', 'Drift', 'Shelf'];

const FLORA_A = ['Bladderwort', 'Glasswing', 'Ember', 'Frostcap', 'Hollow', 'Murmur', 'Spindle',
  'Lantern', 'Velvet', 'Cinder', 'Tideglass', 'Whisper', 'Razor', 'Dusk', 'Coral', 'Static',
  'Hush', 'Prism', 'Marrow', 'Gloam'];
const FLORA_B = ['Helix', 'Frond', 'Bloom', 'Polyp', 'Stalk', 'Crown', 'Vine', 'Bulb', 'Fan',
  'Spire', 'Cluster', 'Lily', 'Sprout', 'Thorn', 'Cap', 'Husk', 'Reed', 'Gourd'];
const FLORA_SUF = ['', '', '', ' (juv.)', ' Variant', ' Major', ' Minor', ' sp.'];

const MINERAL = ['Crystallite', 'Aurorite', 'Voidshard', 'Plasmite', 'Glimmerstone'];

function syl(rng) {
  let s = rng.pick(PRE);
  if (rng.chance(0.55)) s += rng.pick(MID).trim();
  s += rng.pick(SUF);
  return s.charAt(0).toUpperCase() + s.slice(1);
}

export function planetName(seed) {
  const rng = new Rng(seed ^ 0x9e3779b9);
  let n = syl(rng);
  if (rng.chance(0.7)) n += '-' + rng.pick(GREEK);
  return n;
}

export function biomeTag(seed) {
  const rng = new Rng(seed ^ 0x51ed270b);
  return rng.pick(BIOME_ADJ) + ' ' + rng.pick(BIOME_NOUN);
}

export function systemName(seed) {
  const rng = new Rng(seed ^ 0x27d4eb2f);
  return syl(rng) + ' ' + rng.pick(['Cluster', 'System', 'Verge', 'Field', 'Anomaly']);
}

// Stable per-species name generator: index -> name within a planet.
export function floraName(seed, idx) {
  const rng = new Rng((seed ^ 0x85ebca6b) + idx * 2654435761);
  return rng.pick(FLORA_A) + ' ' + rng.pick(FLORA_B) + rng.pick(FLORA_SUF);
}

export function mineralName(seed) {
  const rng = new Rng(seed ^ 0xc2b2ae35);
  return rng.pick(MINERAL);
}
