import Sprite from '../sprite';

class Room1 {
	private readonly canvas: HTMLCanvasElement;
	public readonly width = 400;
	public readonly height = 400;
	// public readonly width = 100;
	// public readonly height = 100;

	constructor(sprite: Sprite) {
		this.canvas = document.createElement('canvas');
		this.canvas.width = this.width;
		this.canvas.height = this.height;
		const blockSize = 16;

		const ctx = this.canvas.getContext('2d') as CanvasRenderingContext2D;

		for (let i = 0; i < this.width / blockSize; i++) {
			for (let j = 0; j < this.height / blockSize; j++) {
				const floor = Math.round(Math.random() * 7) + 1;
				sprite.draw(ctx, i * blockSize, j * blockSize, `floor_${floor}`);
			}
		}

		for (let i = 0; i < this.height / blockSize; i++) {
			sprite.draw(
				ctx,
				this.width - blockSize,
				i * blockSize,
				'wall_side_mid_left',
			);

			sprite.draw(ctx, 0, i * blockSize, 'wall_side_mid_right');
		}

		for (let i = 0; i < this.width / blockSize; i++) {
			sprite.draw(
				ctx,
				i * blockSize,
				this.height - blockSize,
				'wall_inner_corner_t_top_rigth',
			);
			sprite.draw(
				ctx,
				i * blockSize,
				4 - blockSize,
				'wall_inner_corner_t_top_rigth',
			);
		}

		// sprite.draw(ctx, 0, 0, 'wall_inner_corner_t_top_rigth');

		sprite.draw(
			ctx,
			0,
			this.height - blockSize,
			'wall_inner_corner_l_top_left',
		);
		sprite.draw(
			ctx,
			this.width - blockSize,
			this.height - blockSize,
			'wall_inner_corner_l_top_rigth',
		);
	}

	destroy() {
		// this.canvas = null;
	}

	draw(ctx: CanvasRenderingContext2D) {
		if (this.canvas) {
			ctx.drawImage(this.canvas, 0, 0);
		}
	}
}

export default Room1;
