class VendorItemActionWidgetController extends DeviceActionWidgetControllerBase
{
	[ category = "Widget Refs" ]
	protected editable var m_priceWidget : inkTextRef;
	[ category = "Widget Refs" ]
	protected editable var m_priceContainer : inkWidgetRef;
	[ category = "Widget Refs" ]
	protected editable var m_moneyStatusContainer : inkWidgetRef;
	[ category = "Widget Refs" ]
	protected editable var m_processingStatusContainer : inkWidgetRef;

	public override function Initialize( gameController : DeviceInkGameControllerBase, const widgetData : ref< SActionWidgetPackage > )
	{
		var action : DispenceItemFromVendor;
		var textParams : inkTextParams;
		super.Initialize( gameController, widgetData );
		action = ( ( DispenceItemFromVendor )( widgetData.action ) );
		inkWidgetRef.SetVisible( m_moneyStatusContainer, false );
		inkWidgetRef.SetVisible( m_processingStatusContainer, false );
		if( action )
		{
			textParams = new inkTextParams;
			textParams.AddNumber( "COST", action.GetPrice() );
			textParams.AddLocalizedString( "ED", "LocKey#884" );
			inkTextRef.SetLocalizedTextScript( m_priceWidget, "LocKey#45350", textParams );
		}
	}

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

	protected function ProcessPayment( action : DispenceItemFromVendor, executor : GameObject )
	{
		if( action )
		{
			m_targetWidget.SetInteractive( false );
			if( action.CanPay( executor ) )
			{
				PlayLibraryAnimation( 'pay' ).RegisterToCallback( inkanimEventType.OnFinish, this, 'OnPaymentProcessed' );
			}
			else
			{
				PlayLibraryAnimation( 'no_money' ).RegisterToCallback( inkanimEventType.OnFinish, this, 'OnNoMoneyShowed' );
			}
		}
	}

	protected event OnPaymentProcessed( e : inkAnimProxy )
	{
		e.UnregisterFromCallback( inkanimEventType.OnFinish, this, 'OnPaymentProcessed' );
		m_targetWidget.SetInteractive( true );
	}

	protected event OnNoMoneyShowed( e : inkAnimProxy )
	{
		e.UnregisterFromCallback( inkanimEventType.OnFinish, this, 'OnNoMoneyShowed' );
		m_targetWidget.SetInteractive( true );
	}

}

