

class Client_Viewport_Header extends View_Browser {

	initElements() {
		super.initElements();
		this.enable();
	}

	handleSessionAuthenticated() {
		if (this.subviews.context_menu) {
			this.subviews.context_menu.show();
		}
	}

	handleSessionUnauthenticated() {
		if (this.subviews.context_menu) {
			this.subviews.context_menu.hide();
		}
	}

	handleSessionAuthenticatedChange(session) {
		if (session.isAuthenticated()) {
			this.handleSessionAuthenticated();
		} else {
			this.handleSessionUnauthenticated();
		}
	}

	coupleToSession(session) {
		session.on(
			'change:account_id',
			this.handleSessionAuthenticatedChange,
			this
		);

		this.handleSessionAuthenticatedChange(session);
	}

	
(session) {
		session.off(
			'change:account_id',
			this.handleSessionAuthenticatedChange,
			this
		);

		this.handleSessionUnauthenticated();
	}

	setSession(session) {
		if (this.session) {
			this.decoupleFromSession(this.session);
		}

		this.session = session;

		if (this.session) {
			this.coupleToSession(this.session);
		}
	}

}

ObjectHelper.extend(Client_Viewport_Header.prototype, {
	template: Client_Viewport_Header_Template_Index,
	sections: {
		context_menu: Client_Viewport_Header_View_ContextMenu
	}
});

module.exports = Client_Viewport_Header;

decoupleFromSession