class WeaponVendorActionWidgetController extends DeviceActionWidgetControllerBase
{
	[ category = "Widget Refs" ]
	protected editable var m_buttonText : inkTextRef;
	[ category = "Widget Refs" ]
	protected editable var m_standardButtonContainer : inkWidgetRef;
	[ category = "Widget Refs" ]
	protected editable var m_hoveredButtonContainer : inkWidgetRef;
	private var m_buttonState : ButtonStatus;
	private var m_hoverState : HoverStatus;
	private var m_isBusy : Bool;

	public override function Initialize( gameController : DeviceInkGameControllerBase, const widgetData : ref< SActionWidgetPackage > )
	{
		var action : DispenceItemFromVendor;
		super.Initialize( gameController, widgetData );
		action = ( ( DispenceItemFromVendor )( widgetData.action ) );
		inkWidgetRef.SetVisible( m_hoveredButtonContainer, false );
		if( action )
		{
			inkTextRef.SetLocalizedTextScript( m_buttonText, "LocKey#48362" );
		}
	}

	public override function FinalizeActionExecution( executor : GameObject, action : DeviceAction )
	{
		var contextAction : DispenceItemFromVendor;
		contextAction = ( ( DispenceItemFromVendor )( action ) );
		if( contextAction )
		{
			m_isBusy = true;
		}
	}

	public function Processing()
	{
		m_buttonState = ButtonStatus.PROCESSING;
		m_targetWidget.SetInteractive( true );
		inkTextRef.SetLocalizedTextScript( m_buttonText, "LocKey#49630" );
		if( m_hoverState == HoverStatus.DEFAULT )
		{
			m_targetWidget.SetState( 'Processing' );
		}
		else
		{
			m_targetWidget.SetState( 'ProcessingHover' );
		}
	}

	public function NoMoney()
	{
		m_buttonState = ButtonStatus.DISABLED;
		inkTextRef.SetLocalizedTextScript( m_buttonText, "LocKey#48361" );
		if( m_hoverState == HoverStatus.DEFAULT )
		{
			m_targetWidget.SetState( 'Disabled' );
		}
		else
		{
			m_targetWidget.SetState( 'DisabledHover' );
		}
	}

	public function IsProcessing() : Bool
	{
		return m_isBusy;
	}

	public function ResetToDefault()
	{
		m_buttonState = ButtonStatus.DEFAULT;
		m_targetWidget.SetInteractive( true );
		inkTextRef.SetLocalizedTextScript( m_buttonText, "LocKey#48362" );
		m_isBusy = false;
		if( m_hoverState == HoverStatus.DEFAULT )
		{
			m_targetWidget.SetState( 'Default' );
		}
		else
		{
			m_targetWidget.SetState( 'Hover' );
		}
	}

	protected event OnProcessed( e : inkAnimProxy )
	{
		e.UnregisterFromCallback( inkanimEventType.OnFinish, this, 'OnProcessed' );
		ResetToDefault();
	}

	protected event OnHoverOver( e : inkPointerEvent )
	{
		inkWidgetRef.SetVisible( m_standardButtonContainer, false );
		inkWidgetRef.SetVisible( m_hoveredButtonContainer, true );
		m_hoverState = HoverStatus.HOVER;
		if( m_buttonState == ButtonStatus.DEFAULT )
		{
			m_targetWidget.SetState( 'Hover' );
		}
		else if( m_buttonState == ButtonStatus.PROCESSING )
		{
			m_targetWidget.SetState( 'ProcessingHover' );
		}
		else
		{
			m_targetWidget.SetState( 'DisabledHover' );
		}
	}

	protected event OnHoverOut( e : inkPointerEvent )
	{
		inkWidgetRef.SetVisible( m_standardButtonContainer, true );
		inkWidgetRef.SetVisible( m_hoveredButtonContainer, false );
		m_hoverState = HoverStatus.DEFAULT;
		if( m_buttonState == ButtonStatus.DEFAULT )
		{
			m_targetWidget.SetState( 'Default' );
		}
		else if( m_buttonState == ButtonStatus.PROCESSING )
		{
			m_targetWidget.SetState( 'Processing' );
		}
		else
		{
			m_targetWidget.SetState( 'Disabled' );
		}
	}

}

enum ButtonStatus
{
	DEFAULT = 0,
	PROCESSING = 1,
	DISABLED = 2,
}

enum HoverStatus
{
	DEFAULT = 0,
	HOVER = 1,
}

