import { SimCommandBlockTerrain } from '../../sim/commands/SimCommandBlockTerrain';
import { SimCommandCreateTower } from '../../sim/commands/SimCommandCreateTower';
import { Hex } from '../../util/Hex';
import { VisMain } from '../VisMain';
import { HexInteractionInputHandler } from './HexInteractionInputHandler';
import { InputHandler } from './InputHandler';

export class DefaultInputHandler implements InputHandler {
	visMain: VisMain;

	constructor(visMain: VisMain) {
		this.visMain = visMain;
	}

	onKeyDown(event: KeyboardEvent): boolean {
		if (event.code === 'Escape') {
			if (this.visMain.inputHandlers.length > 1) {
				this.visMain.inputHandlers.pop();
				this.visMain.visLevel.setHoveredHex(null);
				event.preventDefault();
				return true;
			}
		} else if (event.code === 'Space') {
			if (this.visMain.active) {
				this.visMain.stop();
			} else {
				this.visMain.start();
			}
			return true;
		} else if (event.code === 'KeyT') {
			this.visMain.inputHandlers.push(new HexInteractionInputHandler(this.visMain, (hex) => new SimCommandCreateTower(hex, 0)));
			return true;
		} else if (event.code === 'KeyB') {
			this.visMain.inputHandlers.push(new HexInteractionInputHandler(this.visMain, (hex) => new SimCommandBlockTerrain(hex)));
			return true;
		}
		return false;
	}

	onMouseDown(event: MouseEvent, hex: Hex): boolean {
		return false;
	}

	onMouseMove(event: MouseEvent, hex: Hex): boolean {
		return false;
	}
}
