/*
 * File: Screen_Select_RGB.c
 *
 * Created: Created: Friday August 2025 13:35:25
 *   Author: Chris
 */

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

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


// ============================================================================================
// Variables
static Object_ID    _RGB_Selector_Object;
static RGB_Color*   _RGB_Color;

static uint8_t      _Current_Component;
static uint8_t*     _Color;


// ============================================================================================
// Function Declarations
void Screen_Setup_Select_RGB(Screen_Transition_Direction direction_out, Screen_Transition_Direction direction_in, Easing type, uint32_t frame_duration, RGB_Color* rgb_color);

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_Select_RGB(Screen_Transition_Direction direction_out, Screen_Transition_Direction direction_in, Easing type, uint32_t frame_duration, RGB_Color* rgb_color)
{
	_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 //
	//////////////////////////////

    _Current_Component = 0;
    _RGB_Color = rgb_color;
    _Color = &(rgb_color->Array[_Current_Component]);

	// Create the RGB selector object
    _RGB_Selector_Object = Display_Objects_Add_Select_RGB(
        _RGB_Color,                         // Pointer to color to modify
        &_Current_Component,                // Indicater for active RGB Base Color
        &_Configuration_Default_Select_RGB  // Use configuration
    );

    Display_Select_Object();

    UI_Control_Acceleration_Reset();
    UI_Control_Acceleration_Set_Enabled(true);
}

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)
{
    int32_t Color = *_Color;
    UI_Control_Selector_Inc(&Color, 0, UINT8_MAX, false);
    *_Color = (uint8_t)Color;
}

void Screen_Action_CCW(Object_ID object_id)
{
    int32_t Color = *_Color;
    UI_Control_Selector_Dec(&Color, 0, UINT8_MAX, false);
    *_Color = (uint8_t)Color;
}

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)
{
	if(_Current_Component < 2) {
        _Current_Component++;

        _Color = &(_RGB_Color->Array[_Current_Component]);

        Display_Select_Object();
        return;
    }
    
    // Screen_Setup_Menu_Main(TRANSITION_DOWN, TRANSITION_DOWN, INOUT_SINE, 15, false, 1);
}


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

