class PhoneMessagePopupEvent extends Event
{
	var m_data : JournalNotificationData;
}

class PhoneMessageHidePopupEvent extends Event
{
}

class PhoneMessageNotificationsGameController extends inkGameController
{
	private var m_maxMessageSize : Int32;
	default m_maxMessageSize = 60;
	private editable var m_title : inkTextRef;
	private editable var m_text : inkTextRef;
	private editable var m_actionText : inkTextRef;
	private editable var m_actionPanel : weak< inkWidget >;
	private var m_player : weak< PlayerPuppet >;
	private var m_animationProxy : inkAnimProxy;
	private var m_data : weak< JournalNotificationData >;

	protected event OnInitialize()
	{
		m_data = ( ( JournalNotificationData )( GetRootWidget().GetUserData( 'JournalNotificationData' ) ) );
		m_player = ( ( PlayerPuppet )( GetOwnerEntity() ) );
		m_player.RegisterInputListener( this, 'NotificationOpenSMS' );
		ShowNotification();
	}

	protected event OnUninitialize()
	{
		m_player.UnregisterInputListener( this );
	}

	protected event OnAction( action : ListenerAction, consumer : ListenerActionConsumer )
	{
		if( ListenerAction.GetType( action ) == gameinputActionType.BUTTON_RELEASED )
		{
			if( ListenerAction.GetName( action ) == 'NotificationOpenSMS' )
			{
				ShowPopup();
			}
		}
	}

	private function ShowPopup()
	{
		var evt : PhoneMessagePopupEvent;
		evt = new PhoneMessagePopupEvent;
		evt.m_data = new JournalNotificationData;
		evt.m_data.journalEntry = m_data.journalEntry;
		evt.m_data.journalEntryState = m_data.journalEntryState;
		evt.m_data.className = m_data.className;
		evt.m_data.queueName = 'modal_popup';
		evt.m_data.notificationName = 'base\gameplay\gui\widgets\notifications\phone_message_popup.inkwidget';
		evt.m_data.isBlocking = true;
		QueueEvent( evt );
	}

	private function ShowNotification()
	{
		var entry : weak< JournalPhoneMessage >;
		var contact : weak< JournalContact >;
		var text : String;
		entry = ( ( JournalPhoneMessage )( m_data.journalEntry ) );
		contact = ( ( JournalContact )( GameInstance.GetJournalManager( m_player.GetGame() ).GetParentEntry( entry ) ) );
		inkTextRef.SetText( m_title, contact.GetLocalizedName( GameInstance.GetJournalManager( m_player.GetGame() ) ) );
		text = entry.GetText();
		if( StrLen( text ) > m_maxMessageSize )
		{
			text = StrLeft( text, m_maxMessageSize ) + "...";
		}
		inkTextRef.SetText( m_text, text );
		PlayIntroAnimation();
	}

	private function PlayIntroAnimation()
	{
		m_animationProxy = PlayLibraryAnimation( 'Outro' );
		m_animationProxy.RegisterToCallback( inkanimEventType.OnFinish, this, 'OnOutroAnimFinished' );
	}

	protected event OnOutroAnimFinished( anim : inkAnimProxy )
	{
		var fakeData : inkGameNotificationData;
		m_data.token.TriggerCallback( fakeData );
	}

}

