//
//  Me.swift
//  Mangosta
//
//  Created by Sergio Abraham on 12/30/16.
//  Copyright © 2016 Inaka. All rights reserved.
//

import Foundation

class Me: UITableViewController {
	weak var xmppController: XMPPController!
	
	@IBOutlet weak var accountJID: UILabel!
	
	override func viewDidLoad() {
		super.viewDidLoad()

		self.xmppController = XMPPController.sharedInstance
		// TODO: when implementing vCard XEP-0054 add the FN field here
		self.accountJID.text = self.xmppController?.xmppStream.myJID?.bare()
	}
    
	@IBAction func signOut(_ sender: AnyObject) {
		
        self.xmppController.disconnect()
        
        AuthenticationModel.remove()
        
        self.presentLogInView()
		#if MangostaREST
			AppDelegate().mongooseRESTController = nil
		#endif
	}
	
	func presentLogInView() {
		let storyboard = UIStoryboard(name: "LogIn", bundle: nil)
		let loginController = storyboard.instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController
		
		self.navigationController?.present(loginController, animated: true, completion: nil
		)
	}
}
