#pragma once
#include "ui-input.hh"


/*= COMMON ACTION DEFINITIONS ================================================*/

struct T_KeyboardShortcut
{
	char character;
	T_KbdMods modifiers;

	explicit constexpr T_KeyboardShortcut(
			char character ,
			T_KbdMods modifiers = { } ) noexcept
		: character{ character } , modifiers{ modifiers }
	{}

	// Writes the keyboard shortcut to a buffer
	void toString( char* buffer , size_t size ) const noexcept;

	// Equality operators
	bool operator ==( T_KeyboardShortcut const& other ) const noexcept
		{ return other.character == character && other.modifiers == modifiers; }
	bool operator !=( T_KeyboardShortcut const& other ) const noexcept
		{ return other.character != character || other.modifiers != modifiers; }
};
namespace ebcl { M_DECLARE_HASH( T_KeyboardShortcut ); }

struct T_UIAction
{
	// Function to call when the action is executed
	using F_ActionHandler = std::function< void( void ) >;
	// Function that checks whether the action is enabled
	using F_ActionChecker = std::function< bool( void ) >;

	T_String id;
	T_String text;		// Text, if different from the identifier
	char const* icon{ nullptr };
	T_Optional< T_KeyboardShortcut > shortcut;
	F_ActionHandler handler;
	F_ActionChecker enabled;

	T_UIAction( char const* id ,
			F_ActionHandler handler ) noexcept
		: id( T_String::Pooled( id ) ) ,
			handler( std::move( handler ) )
	{ assert( this->handler ); }
	T_UIAction( T_String const& id ,
			F_ActionHandler handler ) noexcept
		: id( id ) , handler( std::move( handler ) )
	{ assert( this->handler ); }

	T_UIAction& setShortcut( const T_KeyboardShortcut sc ) noexcept
		{ shortcut = sc; return *this; }
	T_UIAction& setText( T_String const& t ) noexcept
		{ text = t; return *this; }
	T_UIAction& setIcon( char const* const i ) noexcept
		{ icon = i; return *this; }
	T_UIAction& setEnabledCheck( F_ActionChecker check ) noexcept
		{ enabled = std::move( check ); return *this; }

	void menuItem( ) const noexcept;
	void tbButton( ) const noexcept;
};