/*
 * File: Screen_Settings_MIDI_Config.c
 *
 * Created: Created: Thursday August 2025 15:53:58
 *   Author: Chris
 */

// ============================================================================================
// Includes
#include "../Screens.h"
#include "../UI_Control.h"
#include "../Display_Default_Configurations.h"

#include "../Display.h"
#include "../Display_Objects.h"

#include "../EEPROM_M24C64.h"


// ============================================================================================
// Defines
#define MENU_ENTRY_COUNT		4
#define MENU_CHAR_LENGTH		13


// ============================================================================================
// Variables
extern const unsigned char 	_Font_DejaVu_Sans_Mono_Bold_11x17[];
extern const unsigned char 	_Font_DejaVu_Sans_Mono_Bold_15x26[];

static int32_t _Selected_Item;

static char _Menu_Titles[MENU_ENTRY_COUNT][MENU_CHAR_LENGTH] = {
	{ "MIDI Channel " },
	{ "Select Octave" },
	{ "Skip Note Off" },
	{ "Back         " }
};


// ============================================================================================
// Function Declarations
void Screen_Setup_Settings_MIDI_Config(Screen_Transition_Direction direction_out, Screen_Transition_Direction direction_in, Easing type, uint32_t frame_duration, int32_t selected_item);

static void Screen_Tick                (void);
static void Screen_Click               (uint button_return_value);
static void Screen_Touch_Event         (int16_t x, int16_t y);
static void Screen_Action_CW           (Object_ID object_id);
static void Screen_Action_CCW          (Object_ID object_id);
static void Screen_On_Object_Focused   (Object_ID object_id);
static void Screen_On_Object_Defocused (Object_ID object_id);
static void Screen_On_Object_Select    (Object_ID object_id);
static void Screen_On_Object_Deselect  (Object_ID object_id);


/*******************************************************************
	Functions
*******************************************************************/
void Screen_Setup_Settings_MIDI_Config(Screen_Transition_Direction direction_out, Screen_Transition_Direction direction_in, Easing type, uint32_t frame_duration, int32_t selected_item)
{
	_Screen_Tick                   = Screen_Tick;
	_Screen_Click                  = Screen_Click;
	_Screen_Touch_Event            = Screen_Touch_Event;
	_Screen_Action_CW              = Screen_Action_CW;
	_Screen_Action_CCW             = Screen_Action_CCW;
	_Screen_On_Objects_Focused     = Screen_On_Object_Focused;
	_Screen_On_Objects_Defocused   = Screen_On_Object_Defocused;
	_Screen_On_Object_Select       = Screen_On_Object_Select;
	_Screen_On_Object_Deselect     = Screen_On_Object_Deselect;

	Display_Objects_Clear();
	Display_Screen_Transition_Start(direction_out, direction_in, type, frame_duration);


	//////////////////////////////
	// Add Display Objects here //
	//////////////////////////////
	Font_ID Font_Title = Display_Objects_Add_Font(_Font_DejaVu_Sans_Mono_Bold_11x17, 0);


	Display_Objects_Add_Text(CENTER_MIDDLE, X_IN_PERCENT_Y_IN_PIXEL, 50, 45, NOT_SELECTABLE, "MIDI Config", Font_Title, DISPLAY_COLOR_LIGHTGREY, NO_STYLE, NO_ANIMATION);
	Display_Objects_Add_Select_List((char*)_Menu_Titles, MENU_ENTRY_COUNT, MENU_CHAR_LENGTH, &_Selected_Item, &_Configuration_Default_Select_List);

	_Selected_Item = selected_item;

	Display_Select_First_Object();
	Display_Select_Object();
}

void Screen_Tick(void)
{

}

void Screen_Click(uint button_return_value)
{

}

void Screen_Touch_Event(int16_t x, int16_t y)
{

}

void Screen_Action_CW(Object_ID object_id)
{
	UI_Control_Selector_Inc(&_Selected_Item, 0, MENU_ENTRY_COUNT-1, false);
}

void Screen_Action_CCW(Object_ID object_id)
{
	UI_Control_Selector_Dec(&_Selected_Item, 0, MENU_ENTRY_COUNT-1, false);
}

void Screen_On_Object_Focused(Object_ID object_id)
{

}

void Screen_On_Object_Defocused(Object_ID object_id)
{

}

void Screen_On_Object_Select(Object_ID object_id)
{

}

void Screen_On_Object_Deselect(Object_ID object_id)
{
	switch (_Selected_Item)
	{
	case 0:		break;
	case 1:		break;
	case 2:		Screen_Setup_Select_Bool(TRANSITION_UP, TRANSITION_UP, SCREEN_TRANSITION_DEFAULT_EASING, SCREEN_TRANSITION_DEFAULT_FRAMES, "Skip Note Off?", 14, (uint8_t*)&_EEPROM_Content.Channel_MIDI_Configuration->Skip_Note_Off_Event, Screen_Setup_Settings_MIDI_Config, 2); 	break;
	case 3:		Screen_Setup_Settings_MIDI(TRANSITION_DOWN, TRANSITION_DOWN, SCREEN_TRANSITION_DEFAULT_EASING, SCREEN_TRANSITION_DEFAULT_FRAMES, 0);	break;
	}
	
    Display_Select_Object();
}


/*******************************************************************
	Internal Functions
*******************************************************************/

