import { createCanvas } from "@common/display/canvas";
import { gameLoop } from "@common/game";

type State = ReturnType<typeof setup>;

const setup = () => {
    const canvas = createCanvas(800, 600);
    const ctx = canvas.getContext("2d");

    if (!ctx) {
        throw new Error("Failed to get canvas context");
    }

    return {
        canvas,
        ctx,
    };
};

const frame = (dt: number, state: State) => {
    const { ctx } = state;
    ctx.fillStyle = "blue";
    ctx.fillRect(0, 0, 800, 600);   
};

export default gameLoop(setup, frame);