#include <stdlib.h>
#include <assert.h>
#include <stdio.h>

#include "presentation/states/state_ingame.h"
#include "presentation/states/state_main_menu.h"

#include "raylib.h"

int main() {
    InitWindow(1280, 720, "snejk");
    SetTargetFPS(60);
    SetExitKey(KEY_NULL);

    bool should_quit_game = false;

    Presentation_State_Ingame_Context presentation_state_ingame_ctx = (Presentation_State_Ingame_Context) {
    };
    Presentation_State_Main_Menu_Context presentation_state_main_menu_ctx = {
        .should_quit_game = &should_quit_game,
    };

    presentation_state_ingame_init(&presentation_state_ingame_ctx);
    presentation_state_main_menu_init(&presentation_state_main_menu_ctx);
    
    presentation_state_machine_go_to(&presentation_state_main_menu);

    while(true) {
        if(WindowShouldClose() || should_quit_game) {
            break;
        }

        // Tick.
        if(presentation_state_machine.current != NULL && presentation_state_machine.current->tick != NULL) {
            presentation_state_machine.current->tick(presentation_state_machine.current);
        }
        
        // Render.
        BeginDrawing();
        {
            if(presentation_state_machine.current != NULL && presentation_state_machine.current->render != NULL) {
                presentation_state_machine.current->render(presentation_state_machine.current);
            }
        }
        EndDrawing();
    }

    assert(presentation_state_machine_go_to(NULL));
    CloseWindow();
    
    return 0;
}