class DropPointTerminalInkGameController extends DeviceInkGameControllerBase
{
	private editable var m_sellAction : inkWidgetRef;
	private editable var m_statusText : inkTextRef;
	private var m_onGlitchingStateChangedListener : CallbackHandle;

	protected override function SetupWidgets()
	{
		if( !( m_isInitialized ) )
		{
			m_rootWidget.SetVisible( false );
		}
	}

	public override function UpdateActionWidgets( const widgetsData : ref< array< SActionWidgetPackage > > )
	{
		var i : Int32;
		var widget : inkWidget;
		for( i = 0; i < widgetsData.Size(); i += 1 )
		{
			if( widgetsData[ i ].wasInitalized == true )
			{
				widget = GetActionWidget( widgetsData[ i ] );
				if( widget == NULL )
				{
					widget = AddActionWidget( inkWidgetRef.Get( m_sellAction ), widgetsData[ i ] );
				}
				InitializeActionWidget( widget, widgetsData[ i ] );
			}
		}
	}

	public override function Refresh( state : EDeviceStatus )
	{
		SetupWidgets();
		RequestActionWidgetsUpdate();
		switch( state )
		{
			case EDeviceStatus.ON:
				TurnOn();
			break;
			case EDeviceStatus.OFF:
				TurnOff();
			break;
			case EDeviceStatus.UNPOWERED:
				break;
			case EDeviceStatus.DISABLED:
				break;
			default:
				break;
		}
		super.Refresh( state );
	}

	protected override function RegisterBlackboardCallbacks( blackboard : IBlackboard )
	{
		super.RegisterBlackboardCallbacks( blackboard );
		if( blackboard )
		{
			m_onGlitchingStateChangedListener = blackboard.RegisterListenerVariant( GetOwner().GetBlackboardDef().GlitchData, this, 'OnGlitchingStateChanged' );
		}
	}

	protected override function UnRegisterBlackboardCallbacks( blackboard : IBlackboard )
	{
		super.UnRegisterBlackboardCallbacks( blackboard );
		if( blackboard )
		{
			blackboard.UnregisterListenerVariant( GetOwner().GetBlackboardDef().GlitchData, m_onGlitchingStateChangedListener );
		}
	}

	protected event OnActionWidgetSpawned( widget : inkWidget, userData : IScriptable )
	{
		widget.SetInteractive( true );
		super.OnActionWidgetSpawned( widget, userData );
	}

	protected override function GetOwner() : DropPoint
	{
		return ( ( DropPoint )( GetOwnerEntity() ) );
	}

	private override function StopGlitchingScreen()
	{
		Refresh( GetOwner().GetDeviceState() );
	}

	public function TurnOff()
	{
		m_rootWidget.SetVisible( false );
	}

	public function TurnOn()
	{
		m_rootWidget.SetVisible( true );
		if( !( GetOwner().GetDropPointSystem().IsEnabled() ) )
		{
			inkTextRef.SetLocalizedTextScript( m_statusText, "LocKey#20482" );
			m_rootWidget.SetState( 'Inactive' );
			inkWidgetRef.SetInteractive( m_sellAction, false );
		}
		else
		{
			inkTextRef.SetLocalizedTextScript( m_statusText, "LocKey#42350" );
			m_rootWidget.SetState( 'Default' );
			inkWidgetRef.SetInteractive( m_sellAction, true );
		}
	}

}

