/**
 * Copyright (c) 2021 Dominic Masters
 * 
 * This software is released under the MIT License.
 * https://opensource.org/licenses/MIT
 */

#pragma once
#include "../libs.h"
#include "menu.h"
#include "grid.h"
#include "label.h"
#include "rectangle.h"

/** Colour of the selection box for the text menu */
#define TEXTMENU_SELECTION_COLOR ((pixel_t){.r=0xFF,.g=0xFF,.b=0xFF,.a=0x64})

/** Callback type for when an item is selected */
typedef void textmenucallback_t(void *user, uint8_t i, char *text);

typedef struct {
  menu_t menu;
  grid_t grid;
  font_t *font;
  rectangle_t rectangle;

  char *texts[MENU_ITEMS_MAX];
  label_t labels[MENU_ITEMS_MAX];

  textmenucallback_t *onSelect;
  void *user;
} textmenu_t;

/** Callback to be notified from the menu when the menu items are selected. */
void _textMenuOnSelect(void *user, uint8_t i);

/**
 * Initialize a text menu item.
 * 
 * @param menu Menu to initialize.
 * @param font Font to use during initialization.
 */
void textMenuInit(textmenu_t *menu, font_t *font);

/**
 * Add text to a menu list.
 * 
 * @param menu Menu to add to.
 * @param item Text to add (must be a constant value).
 * @return The grid subsystem item.
 */
menuitem_t * textMenuAdd(textmenu_t *menu, char *item);

/**
 * Render a text menu list.
 * 
 * @param menu Menu to render.
 * @param shader Shader to use.
 * @param x X position of the menu.
 * @param y Y position of the menu.
 */
void textMenuRender(textmenu_t *menu, shaderprogram_t *shader,float x, float y);

/**
 * Dispose/Cleanup a text menu.
 * 
 * @param menu Text menu to dispose.
 */
void textMenuDispse(textmenu_t *menu);