class SocialPanelGameController extends gameuiMenuGameController
{
	private editable var m_SocialPanelContactsListRef : inkWidgetRef;
	private editable var m_SocialPanelContactsDetailsRef : inkWidgetRef;
	private var m_ContactsList : weak< SocialPanelContactsList >;
	private var m_ContactDetails : weak< SocialPanelContactsDetails >;
	private var m_RootWidget : weak< inkWidget >;
	private var m_JournalMgr : weak< JournalManager >;

	protected event OnInitialize()
	{
		var owner : weak< GameObject >;
		m_RootWidget = GetRootWidget();
		m_ContactsList = ( ( SocialPanelContactsList )( inkWidgetRef.GetController( m_SocialPanelContactsListRef ) ) );
		m_ContactDetails = ( ( SocialPanelContactsDetails )( inkWidgetRef.GetController( m_SocialPanelContactsDetailsRef ) ) );
		m_ContactsList.RegisterToCallback( 'OnContactChangedRequest', this, 'OnContactChangedRequest' );
		owner = ( ( GameObject )( GetPlayerControlledObject() ) );
		m_JournalMgr = GameInstance.GetJournalManager( owner.GetGame() );
		RefreshView();
	}

	protected event OnUninitialize()
	{
		if( m_ContactsList )
		{
			m_ContactsList.UnregisterFromCallback( 'OnContactChangedRequest', this, 'OnContactChangedRequest' );
		}
	}

	private function RefreshView()
	{
		var entries : array< weak< JournalEntry > >;
		var contactInfo : array< SocialPanelContactInfo >;
		var currentContact : weak< JournalContact >;
		var i, limit : Int32;
		var context : JournalRequestContext;
		context.stateFilter.active = true;
		m_JournalMgr.GetContacts( context, entries );
		for( i = 0, limit = entries.Size(); i < limit; i += 1 )
		{
			currentContact = ( ( JournalContact )( entries[ i ] ) );
			if( currentContact )
			{
				contactInfo.PushBack( SocialPanelContactInfo( m_JournalMgr.GetEntryHash( currentContact ), currentContact ) );
			}
		}
		m_ContactsList.RefreshContactsList( contactInfo );
	}

	protected event OnContactChangedRequest( e : weak< inkWidget > )
	{
		DisplayContact( m_ContactsList.GetClickedContact() );
	}

	public function DisplayContact( contactToShow : weak< JournalContact > )
	{
		if( contactToShow )
		{
			if( m_ContactsList.ChooseContact( m_JournalMgr.GetEntryHash( contactToShow ) ) )
			{
				m_ContactDetails.ShowContact( contactToShow, m_JournalMgr );
			}
		}
	}

}

struct SocialPanelContactInfo
{
	var Hash : Int32;
	var Contact : weak< JournalContact >;
}

