import { Game } from './game';

interface GameApi {
  readonly phase: string;
  readonly hearts: number;
  readonly gems: number;
  readonly slimes: number;
  readonly grassCut: number;
  readonly potsBroken: number;
  attack(): void;
  teleport(x: number, z: number): void;
  start(): void;
  debug: {
    pos(): [number, number];
    nearestGrass(): [number, number] | null;
    nearestSlime(): [number, number] | null;
    totalSlimeHp(): number;
    slimeHits(): number;
    grassRemaining(): number;
  };
}

declare global {
  interface Window {
    __game: GameApi;
  }
}

const game = new Game(document.getElementById('app')!);

window.__game = {
  get phase() { return game.phase; },
  get hearts() { return game.hearts; },
  get gems() { return game.gems; },
  get slimes() { return game.slimes.alive; },
  get grassCut() { return game.stats.grassCut; },
  get potsBroken() { return game.stats.potsBroken; },
  attack: () => game.debugAttack(),
  teleport: (x: number, z: number) => game.teleport(x, z),
  start: () => game.startGame(),
  debug: {
    pos: () => [game.hero.x, game.hero.z],
    nearestGrass: () => game.grass.nearest(game.hero.x, game.hero.z),
    nearestSlime: () => game.slimes.nearest(game.hero.x, game.hero.z),
    totalSlimeHp: () => game.slimes.totalHp,
    slimeHits: () => game.stats.slimeHits,
    grassRemaining: () => game.grass.remaining,
  },
};

game.run();
