'use strict';

/**
 * @constructor
 */
class PageMgr {
    constructor() {
        this.modalMgr   = new ModalMgr();
        this.popupMgr   = new PopupMgr();
        this.$docTitle  = $('head>title');
        this.$loading   = $('.page-loading');
        this.$sidebar   = $('.page-sidebar');
        this.$content   = $('.page-content');
        this.$pageTitle = this.$content.find('.page-section-title');
    }

    /**
     * @returns {PageMgr}
     */
    toggleSidebar() {
        this.$sidebar.toggleClass('toggled');
        this.$content.toggleClass('toggled');

        return this;
    }

    /**
     * @param {Element} el
     *
     * @returns {PageMgr}
     */
    switchSection(el) {
        let section = el.getAttribute('data-section');
        switch (section) {
            case 'game-current-area':
            case 'game-results-area':
                this.toggleTitle(el);
                this.popupMgr.hide();
                this.hideAll();

                this.show(section);
        }

        return this;
    }

    /**
     * @returns {PageMgr}
     */
    hideAll() {
        this.$content.find('.container-fluid > .row > div:not(#notification-area)').addClass('hidden');
        this.$sidebar.find('li:not(.sidebar-brand)').removeClass('selected');

        return this;
    }

    /**
     * @param {string} id
     *
     * @returns {PageMgr}
     */
    show(id) {
        this.$content.find(`div#${id}`).removeClass('hidden');
        this.$sidebar.find(`li[data-section="${id}"]`).addClass('selected');

        return this;
    }

    /**
     * @param {Element} el
     *
     * @returns {PageMgr}
     */
    toggleTitle(el) {
        let prefix = this.$sidebar.find('.page-header').text();

        this.$docTitle.text(`${prefix} :: ${el.innerText}`);
        this.$pageTitle.text(el.innerText);

        return this;
    }

    /**
     * @param {boolean} enable
     *
     * @returns {PageMgr}
     */
    loadingMode(enable) {
        this.modalMgr.updateHTML('');
        this.modalMgr.hide();

        this.$loading.addClass('hidden');

        if (enable) {
            this.$loading.removeClass('hidden');
            this.modalMgr.show();
        }

        return this;
    }
}

@@ -873,30 +873,30 @@
    this.
-toggleTitle(el
+popupMgr.hide(
 );%0A     
@@ -907,38 +907,48 @@
        this.
-popupMgr.hide(
+toggleTitle(el.innerText
 );%0A         
@@ -1593,35 +1593,36 @@
   * @param %7B
-Element%7D el
+string%7D text
 %0A     *%0A    
@@ -1667,18 +1667,20 @@
 leTitle(
-el
+text
 ) %7B%0A    
@@ -1784,25 +1784,17 @@
 x%7D :: $%7B
-el.innerT
+t
 ext%7D%60);%0A
@@ -1822,25 +1822,17 @@
 le.text(
-el.innerT
+t
 ext);%0A%0A 
@@ -1956,32 +1956,32 @@
 gMode(enable) %7B%0A
+
         this.mod
@@ -2004,31 +2004,8 @@
 ('')
-;%0A        this.modalMgr
 .hid

improve page mgr