class DeviceActionWidgetControllerBase extends DeviceButtonLogicControllerBase
{
	protected var m_actions : array< weak< DeviceAction > >;
	protected var m_actionData : ResolveActionData;
	protected var m_isInactive : Bool;

	public virtual function Initialize( gameController : DeviceInkGameControllerBase, const widgetData : ref< SActionWidgetPackage > )
	{
		var i : Int32;
		var action : ScriptableDeviceAction;
		m_actions.Clear();
		if( widgetData.wasInitalized == false )
		{
			return;
		}
		AddAction( widgetData.action );
		for( i = 0; i < widgetData.dependendActions.Size(); i += 1 )
		{
			AddAction( widgetData.dependendActions[ i ] );
		}
		inkTextRef.SetLocalizedTextScript( m_displayNameWidget, widgetData.displayName );
		if( TDBID.IsValid( widgetData.iconTextureID ) )
		{
			SetTexture( m_iconWidget, widgetData.iconTextureID );
		}
		else if( inkImageRef.Get( m_iconWidget ) != NULL )
		{
			inkImageRef.SetTexturePart( m_iconWidget, widgetData.iconID );
		}
		action = ( ( ScriptableDeviceAction )( widgetData.action ) );
		if( action )
		{
			m_isInactive = action.IsInactive();
		}
		RegisterDeviceActionCallback( gameController );
		ResolveWidgetState( widgetData.widgetState );
		m_isInitialized = true;
	}

	public virtual function ClearButtonActions()
	{
		m_actions.Clear();
	}

	protected function RegisterDeviceActionCallback( gameController : DeviceInkGameControllerBase )
	{
		if( !( m_isInitialized ) )
		{
			m_targetWidget.RegisterToCallback( 'OnRelease', gameController, 'OnDeviceActionCallback' );
			m_targetWidget.RegisterToCallback( 'OnExecuteButtonAction', gameController, 'OnExecuteButtonAction' );
			RegisterAudioCallbacks( gameController );
		}
	}

	public function SetActions( const actions : ref< array< weak< DeviceAction > > > )
	{
		m_actions = actions;
	}

	public function AddAction( action : weak< DeviceAction > )
	{
		if( !( m_actions.Contains( action ) ) )
		{
			m_actions.PushBack( action );
		}
	}

	public function RemoveAction( action : weak< DeviceAction > )
	{
		m_actions.Remove( action );
	}

	public function GetActions() : array< weak< DeviceAction > >
	{
		return m_actions;
	}

	protected virtual function ResolveAction( const widgetData : ref< SActionWidgetPackage > ) {}

	public virtual function FinalizeActionExecution( executor : GameObject, action : DeviceAction ) {}

	public const virtual function CanExecuteAction() : Bool
	{
		return !( m_isInactive );
	}

	protected override function ResolveWidgetState( state : EWidgetState )
	{
		if( m_isInactive )
		{
			if( m_targetWidget )
			{
				m_targetWidget.SetState( 'Inactive' );
				m_targetWidget.SetInteractive( false );
			}
		}
		else
		{
			if( m_targetWidget )
			{
				m_targetWidget.SetState( 'Default' );
				m_targetWidget.SetInteractive( true );
			}
		}
		if( state == EWidgetState.ON )
		{
			if( inkImageRef.Get( m_toggleSwitchWidget ) )
			{
				inkImageRef.SetScale( m_toggleSwitchWidget, Vector2( 1.0, 1.0 ) );
			}
		}
		else if( state == EWidgetState.OFF )
		{
			if( inkImageRef.Get( m_toggleSwitchWidget ) )
			{
				inkImageRef.SetScale( m_toggleSwitchWidget, Vector2( -1.0, -1.0 ) );
			}
		}
	}

}

