import type { BlockbreakerBrickColor } from "./blockbreaker";

export const BLOCKBREAKER_BIOME_IDS = [
  "prism-circuit",
  "ember-foundry",
  "frost-vault",
  "void-grid",
  "verdant-reactor",
] as const;

export type BlockbreakerBiomeId = typeof BLOCKBREAKER_BIOME_IDS[number];
export type BlockbreakerBiomeFixture = "crystal" | "forge" | "spire" | "monolith" | "reactor";

export interface BlockbreakerArenaBiome {
  id: BlockbreakerBiomeId;
  name: string;
  fixture: BlockbreakerBiomeFixture;
  background: string;
  fog: string;
  ambient: string;
  sky: string;
  ground: string;
  keyLight: string;
  fillLightA: string;
  fillLightB: string;
  foundation: string;
  floor: string;
  playfield: string;
  wall: string;
  wallEmissive: string;
  boundary: string;
  railA: string;
  railB: string;
  midline: string;
  fixtureColor: string;
  fixtureEmissive: string;
  ambientIntensity: number;
  hemisphereIntensity: number;
  keyLightIntensity: number;
  fillLightIntensityA: number;
  fillLightIntensityB: number;
  wallEmissiveIntensity: number;
  floorRoughness: number;
  floorMetalness: number;
  bricks: Readonly<Record<BlockbreakerBrickColor, string>>;
}

export const BLOCKBREAKER_BIOMES: readonly BlockbreakerArenaBiome[] = [
  {
    id: "prism-circuit",
    name: "Prism Circuit",
    fixture: "crystal",
    background: "#163640",
    fog: "#214b55",
    ambient: "#dffcff",
    sky: "#efffff",
    ground: "#24535b",
    keyLight: "#f4ffff",
    fillLightA: "#8cefff",
    fillLightB: "#fff0bd",
    foundation: "#173c44",
    floor: "#2d6972",
    playfield: "#367985",
    wall: "#39717c",
    wallEmissive: "#143a43",
    boundary: "#b9f8ff",
    railA: "#9ef6ff",
    railB: "#fff2c2",
    midline: "#e8feff",
    fixtureColor: "#49a6b7",
    fixtureEmissive: "#70efff",
    ambientIntensity: 0.72,
    hemisphereIntensity: 2.3,
    keyLightIntensity: 3.15,
    fillLightIntensityA: 5.5,
    fillLightIntensityB: 4.8,
    wallEmissiveIntensity: 0.32,
    floorRoughness: 0.58,
    floorMetalness: 0.08,
    bricks: {
      cyan: "#42ddff",
      amber: "#ffc247",
      magenta: "#ff55ad",
      lime: "#8bf065",
    },
  },
  {
    id: "ember-foundry",
    name: "Ember Foundry",
    fixture: "forge",
    background: "#2a0d0a",
    fog: "#4b1b11",
    ambient: "#ffd7a8",
    sky: "#ffb45c",
    ground: "#240a0b",
    keyLight: "#ffe0b2",
    fillLightA: "#ff5b32",
    fillLightB: "#ffc54d",
    foundation: "#250b0a",
    floor: "#5a2416",
    playfield: "#7a321e",
    wall: "#52241d",
    wallEmissive: "#6a170c",
    boundary: "#ffb15f",
    railA: "#ff6a38",
    railB: "#ffd15c",
    midline: "#ffe2a6",
    fixtureColor: "#5d2117",
    fixtureEmissive: "#ff5a26",
    ambientIntensity: 0.58,
    hemisphereIntensity: 1.85,
    keyLightIntensity: 2.75,
    fillLightIntensityA: 6.4,
    fillLightIntensityB: 5.4,
    wallEmissiveIntensity: 0.48,
    floorRoughness: 0.76,
    floorMetalness: 0.18,
    bricks: {
      cyan: "#54dcff",
      amber: "#ffbd3d",
      magenta: "#ff5b78",
      lime: "#d7ff5c",
    },
  },
  {
    id: "frost-vault",
    name: "Frost Vault",
    fixture: "spire",
    background: "#071a2f",
    fog: "#143b56",
    ambient: "#dff8ff",
    sky: "#c6f4ff",
    ground: "#10233d",
    keyLight: "#ffffff",
    fillLightA: "#55dfff",
    fillLightB: "#9b8cff",
    foundation: "#09192a",
    floor: "#1c4c67",
    playfield: "#255f7c",
    wall: "#24455f",
    wallEmissive: "#0d4662",
    boundary: "#d4fbff",
    railA: "#6be9ff",
    railB: "#b5a7ff",
    midline: "#ffffff",
    fixtureColor: "#5b9db9",
    fixtureEmissive: "#9defff",
    ambientIntensity: 0.66,
    hemisphereIntensity: 2.05,
    keyLightIntensity: 3.35,
    fillLightIntensityA: 5.3,
    fillLightIntensityB: 4.2,
    wallEmissiveIntensity: 0.38,
    floorRoughness: 0.42,
    floorMetalness: 0.16,
    bricks: {
      cyan: "#38e4ff",
      amber: "#ffd36f",
      magenta: "#b47cff",
      lime: "#6ef2c0",
    },
  },
  {
    id: "void-grid",
    name: "Void Grid",
    fixture: "monolith",
    background: "#05020f",
    fog: "#120526",
    ambient: "#cebaff",
    sky: "#8d65ff",
    ground: "#0a0313",
    keyLight: "#e8dcff",
    fillLightA: "#784cff",
    fillLightB: "#ff38c7",
    foundation: "#07020e",
    floor: "#160a2b",
    playfield: "#211044",
    wall: "#1d1030",
    wallEmissive: "#280966",
    boundary: "#b68cff",
    railA: "#7d5cff",
    railB: "#ff4ccc",
    midline: "#d9c4ff",
    fixtureColor: "#16082e",
    fixtureEmissive: "#8d5cff",
    ambientIntensity: 0.44,
    hemisphereIntensity: 1.48,
    keyLightIntensity: 2.45,
    fillLightIntensityA: 6.2,
    fillLightIntensityB: 5.7,
    wallEmissiveIntensity: 0.64,
    floorRoughness: 0.34,
    floorMetalness: 0.28,
    bricks: {
      cyan: "#41d8ff",
      amber: "#ffac45",
      magenta: "#ff4bd0",
      lime: "#a1ff4f",
    },
  },
  {
    id: "verdant-reactor",
    name: "Verdant Reactor",
    fixture: "reactor",
    background: "#0d211a",
    fog: "#193f31",
    ambient: "#e1ffe3",
    sky: "#b8ffc9",
    ground: "#102217",
    keyLight: "#f2ffe8",
    fillLightA: "#63e6a3",
    fillLightB: "#d8ff67",
    foundation: "#0d1f18",
    floor: "#25543d",
    playfield: "#2d684a",
    wall: "#294f3f",
    wallEmissive: "#0d4b2d",
    boundary: "#b9ffd2",
    railA: "#67f4a7",
    railB: "#e7ff73",
    midline: "#f1ffd0",
    fixtureColor: "#245642",
    fixtureEmissive: "#76f7a9",
    ambientIntensity: 0.62,
    hemisphereIntensity: 2.02,
    keyLightIntensity: 2.9,
    fillLightIntensityA: 5.1,
    fillLightIntensityB: 4.6,
    wallEmissiveIntensity: 0.42,
    floorRoughness: 0.68,
    floorMetalness: 0.06,
    bricks: {
      cyan: "#4be3ff",
      amber: "#ffca52",
      magenta: "#ff6fb5",
      lime: "#99f75d",
    },
  },
];

function mixSeed(seed: number) {
  let mixed = Math.floor(Number(seed)) >>> 0;
  mixed ^= mixed >>> 16;
  mixed = Math.imul(mixed, 0x7feb352d);
  mixed ^= mixed >>> 15;
  mixed = Math.imul(mixed, 0x846ca68b);
  mixed ^= mixed >>> 16;
  return mixed >>> 0;
}

export function blockbreakerBiomeForSeed(seed: number) {
  return BLOCKBREAKER_BIOMES[mixSeed(seed) % BLOCKBREAKER_BIOMES.length];
}
