class ComputerBannerWidgetController extends DeviceInkLogicControllerBase
{
	[ category = "Widget Refs" ]
	protected editable var m_titleWidget : inkTextRef;
	[ category = "Widget Refs" ]
	protected editable var m_textContentWidget : inkTextRef;
	[ category = "Widget Refs" ]
	protected editable var m_videoContentWidget : inkVideoRef;
	[ category = "Widget Refs" ]
	protected editable var m_imageContentWidget : inkImageRef;
	[ category = "Widget Refs" ]
	protected editable var m_bannerButtonWidget : inkWidgetRef;
	private var m_bannerData : SBannerWidgetPackage;
	private var m_lastPlayedVideo : ResRef;

	public virtual function Initialize( gameController : ComputerInkGameController, const widgetData : ref< SBannerWidgetPackage > )
	{
		inkTextRef.SetText( m_titleWidget, widgetData.title );
		inkTextRef.SetText( m_textContentWidget, widgetData.description );
		ResolveContent( widgetData.content );
		RegisterBannerCallback( gameController );
		m_bannerData = widgetData;
		m_isInitialized = true;
	}

	protected function ResolveContent( content : ResRef )
	{
		if( m_lastPlayedVideo == content && inkVideoRef.IsPlayingVideo( m_videoContentWidget ) )
		{
			inkVideoRef.SetVisible( m_videoContentWidget, true );
			return;
		}
		StopVideo();
		inkVideoRef.SetVideoPath( m_videoContentWidget, content );
		inkImageRef.SetVisible( m_imageContentWidget, false );
		inkVideoRef.SetVisible( m_videoContentWidget, true );
		inkVideoRef.Play( m_videoContentWidget );
		inkVideoRef.SetLoop( m_videoContentWidget, true );
		m_lastPlayedVideo = content;
	}

	public function StopVideo()
	{
		inkVideoRef.Stop( m_videoContentWidget );
		inkVideoRef.SetVisible( m_videoContentWidget, false );
	}

	protected function RegisterBannerCallback( gameController : DeviceInkGameControllerBase )
	{
		var controller : DeviceButtonLogicControllerBase;
		if( !( m_isInitialized ) )
		{
			if( inkWidgetRef.Get( m_bannerButtonWidget ) )
			{
				controller = ( ( DeviceButtonLogicControllerBase )( inkWidgetRef.GetController( m_bannerButtonWidget ) ) );
				if( controller )
				{
					controller.RegisterAudioCallbacks( gameController );
				}
			}
			GetRootWidget().RegisterToCallback( 'OnRelease', gameController, 'OnShowFullBannerCallback' );
		}
	}

	public function GetBannerData() : SBannerWidgetPackage
	{
		return m_bannerData;
	}

}

