#include "main-menu.h"
#include <stdlib.h>
#include <stdio.h>

Main_Menu * Main_Menu_init(const int screenWidth, const int screenHeight){

    Main_Menu * self = malloc(sizeof(Main_Menu));

    Rectangle playGameBtn = {(screenWidth*32)/100, (screenHeight*35)/100, (screenWidth*30)/100, (screenHeight*5)/100};
    Rectangle smallPlayGameBtn = {3 + (screenWidth*32/100), 3 + (screenHeight*35/100), (screenWidth*30/100) - 6, (screenHeight*5/100) - 6};

    Menu_Button * playGame = Button_init(playGameBtn, smallPlayGameBtn, "\t\t\t PLAY", game_ui);

    Rectangle optionsBtn = {(screenWidth*32)/100, (screenHeight*45)/100, (screenWidth*30)/100, (screenHeight*5)/100};
    Rectangle smallOptionsBtn = {3 + (screenWidth*32/100), 3 + (screenHeight*45/100), (screenWidth*30/100) - 6, (screenHeight*5/100) - 6};
    
    Menu_Button * optionsMenu = Button_init(optionsBtn, smallOptionsBtn, "\t\tOPTIONS", options);

    self->buttonCount = 2;
    self->buttons = malloc(sizeof(Menu_Button) * self->buttonCount);
    self->buttons[game_ui] = playGame;
    self->buttons[options] = optionsMenu;

    return self;
}

Display Main_Menu_detect_click(Main_Menu * self, Vector2 * mousePos){
    for(int index = 0; index < self->buttonCount; index++){
        Menu_Button * currentBtn = self->buttons[index];
        if(CheckCollisionPointRec(*mousePos, currentBtn->button)){
            printf("returned %d\n", currentBtn->displayOnClick);
            return currentBtn->displayOnClick;
        }
    }
    return main_menu;
}

