#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));

    //Init of the play game btn
    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};
    Rectangle playGameTextBox = {smallPlayGameBtn.x + smallPlayGameBtn.width/3, smallPlayGameBtn.y, smallPlayGameBtn.width, smallPlayGameBtn.height};
    Menu_Button * playGame = Menu_Button_init(playGameBtn, smallPlayGameBtn,playGameTextBox, "PLAY", game_ui);

    //Init of the options btn
    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};
    Rectangle optionsTextBox = {smallOptionsBtn.x + smallOptionsBtn.width/4, smallOptionsBtn.y, smallOptionsBtn.width, smallOptionsBtn.height};

    Menu_Button * optionsMenu = Menu_Button_init(optionsBtn, smallOptionsBtn,optionsTextBox, "OPTIONS", 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)){
            return currentBtn->displayOnClick;
        }
    }
    return main_menu;
}

void Main_Menu_delete(Main_Menu * self){
    for(int index = 0; index < self->buttonCount; index++){
        Menu_Button_delete(self->buttons[index]);
    }
    free(self->buttons);
    free(self);
}

