/*
 * File: Screen_Idle.c
 *
 * Created: Created: Saturday October 2025 20:32:05
 *   Author: Chris
 */


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

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

#include "Common_Screen_Elements.h"


// ============================================================================================
// Defines


// ============================================================================================
// Variables
extern const uint16_t _Image_Fad_Logo_Background_160x160[];


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

static void Screen_Init                (Screen_Transition_Direction direction_out, Screen_Transition_Direction direction_in, Easing type, uint32_t frame_duration);
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_Idle(Screen_Transition_Direction direction_out, Screen_Transition_Direction direction_in, Easing type, uint32_t frame_duration)
{
   Screen_Init(direction_out, direction_in, type, frame_duration);
}

void Screen_Init(Screen_Transition_Direction direction_out, Screen_Transition_Direction direction_in, Easing type, uint32_t frame_duration)
{
    // _Screen_Last                   = Screen_Init;    // We don't want that here...
    _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 //
    //////////////////////////////

    switch(_EEPROM_Content.Device_Configuration.Idle_Screen)
	{
		case IDLE_SCREEN_LOGO:
			Display_Objects_Add_Image(CENTER_MIDDLE, BOTH_IN_PERCENT, 50, 50, NOT_SELECTABLE, _Image_Fad_Logo_Background_160x160, 0, NO_STYLE, NO_ANIMATION);
			break;

		case IDLE_SCREEN_CURRENT_MODE: 
			Common_Screen_Element_Init_Current_Mode(Mode_Manager_Get_Current_Mode());
			break;

		case IDLE_SCREEN_MODE_ACTIVITY:
			Common_Screen_Element_Init_Mode_Activity(Mode_Manager_Get_Current_Mode());
			break;

		case IDLE_SCREEN_BLACK:
		default: break;
	}

    _Screen_Idle_Active = true;
    Display_Select_Object();
}

void Screen_Tick(void)
{
    switch(_EEPROM_Content.Device_Configuration.Idle_Screen)
	{
		case IDLE_SCREEN_MODE_ACTIVITY:
			Common_Screen_Element_Tick_Mode_Activity(Mode_Manager_Get_Current_Mode());
			break;

        case IDLE_SCREEN_LOGO:
        case IDLE_SCREEN_CURRENT_MODE:
		case IDLE_SCREEN_BLACK:
		default: break;
	}
}

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)
{
    _Screen_Idle_Active = false;
	_Screen_Last(TRANSITION_DOWN, TRANSITION_DOWN, SCREEN_TRANSITION_DEFAULT_EASING, SCREEN_TRANSITION_DEFAULT_FRAMES);
}

void Screen_Action_CCW(Object_ID object_id)
{
    _Screen_Idle_Active = false;
	_Screen_Last(TRANSITION_DOWN, TRANSITION_DOWN, SCREEN_TRANSITION_DEFAULT_EASING, SCREEN_TRANSITION_DEFAULT_FRAMES);
}

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)
{
    _Screen_Idle_Active = false;
	_Screen_Last(TRANSITION_DOWN, TRANSITION_DOWN, SCREEN_TRANSITION_DEFAULT_EASING, SCREEN_TRANSITION_DEFAULT_FRAMES);
}


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

