var ShellController = function () {

    let _self = this;

    let _shell_wrapper = null;
    let _preloader = null;
    let _skipIntro_checkbox = null;

    let _isPausedByLearner = false;
    let _isPausedForActivity = false;
    let _isMutedByLearner = false;

    let _shell_body = null;
    let _timeOutPreLoadNextPage = null;

    let _left_sideNav_holder = null;
    let _shell_templateHolder = null;
    let _gHolder = null;

    let _exitHolder = null;
    let _bookmarkHolder = null;
    let _progressHolder = null;

    let _budgetHolder = null;
    let _notesHolder = null;

    let _hubHolder = null;
    let _resourcesHolder = null;
    let _hintHolder = null;
    let _helpHolder = null;

    let _menuHolder = null;

    let _modules = null;

    let _mTitle = null;

    let _cMNo = 1;
    let _tMNo = 1;

    let _pTiles = null;
    let _cPTile = null;
    let _cPNo = 1;
    let _tPNo = 1
    let _cPageIndexNo = 0;

    let _btn_prev = null;
    let _btn_next = null;

    let _courseProgress = null;
    let _courseProgressPercent = null;

    let _isLinear = true;

    let _isLocalBookmark = true;

    let _user_details = null;
    let _shellModel = null;
    let _mediaManager = null;

    let _LS = null;
    let _shellNavigation = null;

    let _cMList = {};
    let _pageLoadInterval = null;

    let _btn_resources = null;
    let _btn_transcript = null;

    let _btn_replay = null;
    let _popup_transcript = null;

    let skipTimerCall = false;

    var updatebadgearry = [0,0,0,0,0,0,0];

    let _isDebugging = false;

    let _shellMenu = null;
    let _leftMenu = null;
    let moduleDetails = []
    let _isAudio = "false"
    // var _simple_audio = null;


    let _aCommonPath = './shell/audio/';

    let _audioData = {
        'blank': {
            'url': _aCommonPath + 'blank.mp3',
        },
        'notification': {
            'url': _aCommonPath + 'notification.mp3'
        },
        'home_notification': {
            'url': _aCommonPath + 'notification.mp3'
        },
        'mail_notification': {
            'url': _aCommonPath + 'mail_notification.mp3'
        },
        'files_notification': {
            'url': _aCommonPath + 'notification.mp3'
        },
        'connect_notification': {
            'url': _aCommonPath + 'notification.mp3'
        },
        'chat_notification': {
            'url': _aCommonPath + 'chat_notification.mp3'
        },
        'activity_notification': {
            'url': _aCommonPath + 'notification.mp3'
        },
        'board_notification': {
            'url': _aCommonPath + 'notification.mp3'
        },
        'calendar_notification': {
            'url': _aCommonPath + 'notification.mp3'
        },
        'message_notification': {
            'url': _aCommonPath + 'notification.mp3'
        },
        'video_notification': {
            'url': _aCommonPath + 'video_notification.mp3'
        },
        'alert': {
            'url': _aCommonPath + 'alert.mp3'
        },
        'gPopupOpen': {
            'url': _aCommonPath + 'blank.mp3'
        },
        'gPopupClose': {
            'url': _aCommonPath + 'blank.mp3'
        }
    }

    var _module_heading = $("#shell_body .module_heading"),
        _page_heading = $("#shell_body .page_heading"),
        _cMTitle = "",
        _cPTitle = "";



    this.init = function (data) {

        _shellModel = data['shellModel'];
        _shellNavigation = data['shellNavigation'];
        _mediaManager = data['mediaManager'];
        _LS = data['LS'];

        resetVaribles();
        startCourse();
    }

    this.getCurrentMnoNdPno = function () {
        return {
            'mNo': _cMNo,
            'pNo': _cPNo
        };
    }

    this.updatebadgearryval = function () {
        return updatebadgearry;
    }

    this.getModulesDetails = function () {
        return moduleDetails
    }

    var resetVaribles = function () {

        _shell_wrapper = $("#shell_wrapper")
        _templateHolder = $("#templateHolder")

        _home_btn = $("#home_btn")
        _skipVideo_btn = $("#skipVideo_btn");
        _skipIntro_checkbox = $("#skipIntro_checkbox")

        _shell_header = $("#shell_header");

        _shell_body = $("#shell_body");

        _left_sideNav_holder = $("#left_sideNav_holder");
        _shell_templateHolder = $("#shell_templateHolder");

        _shell_steps_sidebar = $("#shell_steps_sidebar");
        _shell_footer_holder = $("#shell_footer_holder");

        _gHolder = $("#global_popup_holder");

        _budgetHolder = $("#budget_popup_holder");
        _notesHolder = $("#notes_popup_holder");

        _hubHolder = $("#hub_popup_holder");
        _resourcesHolder = $("#resources_popup_holder");
        _hintHolder = $("#hint_popup_holder");
        _helpHolder = $("#help_popup_holder");

        _bookmarkHolder = $("#bookmark_popup_holder");
        _exitHolder = $("#exit_popup_holder");
        _progressHolder = $("#progress_popup_holder");

        _menuHolder = $("#shell_footer_holder #menu_popup");

        _logo = $("#shell_header .logo");
        _cTitle = $("#shell_header .course_title");
        _mTitle = $("#shell_header .module_title");

        _btn_resources = $("#btn_resources");
        _btn_transcript = $("#btn_transcript");

        _btn_replay = $("#btn_replay");

        _popup_transcript = $("#transcript_popup");
        _audio_slidebar = $("#simple_audio_wrapper");

        _preloader = $("#preloader")

        _user_details = _shellModel.user_details;

        _modules = _shellModel.configData['modules'];

        _tMNo = _modules.length;

        _isLinear = (_shellModel.configData['isLinear'] == "false") ? false : true;
        _isDebugging = (_shellModel.configData['isDebugging'] == "false") ? false : true;

        _dummy_shell_body = $("<div>")

        _module_heading = $("#shell_body .module_heading")
        _page_heading = $("#shell_body .page_heading")


        addEvents();

    }



    var addEvents = function () {

        var _global_wrapper = $("#global_wrapper");
        try {
            removeAllEvents('#shell_wrapper');
            removeAllEvents('#templateHolder');
        } catch (err) {

        }

        _global_wrapper.off("takeFirstTimeLaunchData").on("takeFirstTimeLaunchData", function (e, _isFirstTimeLaunch) {
            isFirstTimeLaunch = _isFirstTimeLaunch;
        });

        _global_wrapper.trigger('getFirstTimeLaunchData');


        // _user_details = Utils.getUserDetails()

        var _shellWrapper = new ShellWrapper();
        _shellWrapper.init();

        addEventsOnShellWrapper();

        // Added this in shell controller loadLaunch method
        // loadSimpleAudio(function () { });

        _shell_wrapper.off("sendAudioDetails").on("sendAudioDetails", function (e, aData) {

            e.stopPropagation();

            try {

                let _type = aData['audioType'] || "blank"
                let _aData = _audioData[_type];

                _aData['transcript'] = _aData['transcript'] || _audioData['transcript'] || ""
                _aData['isNotification'] = true;
                _aData['callback'] = aData['callback'] || function () { }

                changeAudio(_aData);

            } catch (err) {
                Utils.error("sendAudioDetails:  " + err)
            }
        });

    }



    var addEventsForOpenAndClosGlobalPopup = function (popupName) {

        var _openEventName = "open" + popupName + "GlobalPopup";
        var _closeEventName = "close" + popupName + "GlobalPopup";

        _shell_wrapper.off(_openEventName).on(_openEventName, function (e, data) {
            e.stopPropagation();
            var _popupName = data['popupName'];
            var _holderName = $("#" + _popupName.toLowerCase() + "_popup_holder");
            if (_popupName == "Progress") {
                _shell_wrapper.trigger('beforeOpenProgress');
            }
            _shell_wrapper.trigger('pauseAudio');
            _holderName.fadeIn(function () {
                _holderName.find('.modal-content').show(0).removeClass('popupFadeOutUp').addClass('popupFadeInUp');
                // _shell_wrapper.trigger('sendAudioDetails', {audioType :'gPopupOpen'});
                _shell_wrapper.trigger('open' + _popupName);
                // updateStatus_BudgetTimeAndScore();
            });
        });


        _shell_wrapper.off(_closeEventName).on(_closeEventName, function (e, data) {
            e.stopPropagation();
            var _popupName = data['popupName']
            var _holderName = $("#" + _popupName.toLowerCase() + "_popup_holder");

            // _shell_wrapper.trigger('sendAudioDetails', {audioType :'gPopupClose'});

            _holderName.find('.modal-content').removeClass('popupFadeInUp').addClass('popupFadeOutUp');

            clearTimeout(_timerInstance);
            _timerInstance = setTimeout(function () {
                clearTimeout(_timerInstance);
                _holderName.fadeOut(function () {
                    _shell_wrapper.trigger('playAudio');
                    _shell_wrapper.trigger('close' + _popupName)
                    // updateStatus_BudgetTimeAndScore();
                });
                _holderName.find('.modal-content').hide();
                _shell_wrapper.trigger("zoomOutSkypeWindow");
            }, 600);
        });

        var _addEventName = "add" + popupName + "GlobalPopup"
        try {
            var _data = {
                for: popupName.toLowerCase(),
                isbtnClose: true
            }
            _shell_wrapper.trigger(_addEventName, _data);
        } catch (err) {

        }
    }


    var addEventsForGlobalPopups = function () {

        _shell_wrapper.off("bookmarkHandler").on("bookmarkHandler", function (e, data) {
            e.stopPropagation();
            _shell_wrapper.trigger("closeBookmarkGlobalPopup", data);
            getLessonStatus(data['isYes']);
           // _shell_wrapper.trigger("markModuleCompleted", 1);
        });

        _shell_wrapper.off("exitProject").on("exitProject", function (e) {
            e.stopPropagation();

            exitProject();
        });

        _shell_wrapper.off("replayIntroAnim").on("replayIntroAnim", function (e) {
            e.stopPropagation();
            //   updateUserData();
        });

        _shell_wrapper.off("closeGlobalPopup").on("closeGlobalPopup", function (e) {
            e.stopPropagation();
            closeGlobalPopup();
        });

        _shell_wrapper.off("openGlobalPopup").on("openGlobalPopup", function (e, data) {
            e.stopPropagation();
            closeGlobalPopup();
            updateGlobalPopup(data['for'], data['isClose_btn']);
        });

        _shell_wrapper.off("retakeCourse").on("retakeCourse", function (e) {
            e.stopPropagation();
            retakeCourse();
        });

        _shell_wrapper.off("retakeModule").on("retakeModule", function (e, mNo) {
            e.stopPropagation();
            retakeModule(mNo);
        });

        _shell_wrapper.off("gotoModule").on("gotoModule", function (e, data) {
            e.stopPropagation();
            gotoModule(data.mNo, data.pNo);
        });

        _shell_wrapper.off("resetModuleLevelData").on("resetModuleLevelData", function (e, mNo) {
            e.stopPropagation();
            resetModuleLevelData(mNo);
        });
        _shell_wrapper.off("moduleLevelWorkstationAction").on("moduleLevelWorkstationAction", function (e) {
            e.stopPropagation();
            moduleLevelWorkstationAction();
        });



        /* 
                _shell_wrapper.off("addNotesGlobalPopup").on("addNotesGlobalPopup", function (e, data) {
                    e.stopPropagation();
                    addNotesGlobalPopup(data['for'], data['isClose_btn']);
                });
               _shell_wrapper.off("addHubGlobalPopup").on("addHubGlobalPopup", function (e, data) {
                    e.stopPropagation();
                    addHubGlobalPopup(data['for'], data['isClose_btn']);
                });
        */
        _shell_wrapper.off("addResourcesGlobalPopup").on("addResourcesGlobalPopup", function (e, data) {
            e.stopPropagation();
            addResourcesGlobalPopup(data['for'], data['isClose_btn']);
        });

        /*  _shell_wrapper.off("addProgressGlobalPopup").on("addProgressGlobalPopup", function (e, data) {
              e.stopPropagation();
              addProgressGlobalPopup(data['for'], data['isClose_btn']);
          });
          /**
           * 
           


        _shell_wrapper.off("addHintGlobalPopup").on("addHintGlobalPopup", function (e, data) {
            e.stopPropagation();
            addHintGlobalPopup(data['for'], data['isClose_btn']);
        });

        _shell_wrapper.off("addBudgetGlobalPopup").on("addBudgetGlobalPopup", function (e, data) {
            e.stopPropagation();
            addBudgetGlobalPopup(data['for'], data['isClose_btn']);
        });
        */

        _shell_wrapper.off("addHelpGlobalPopup").on("addHelpGlobalPopup", function (e, data) {
            e.stopPropagation();
            addHelpGlobalPopup(data['for'], data['isClose_btn']);
        });



        _shell_wrapper.off("addExitGlobalPopup").on("addExitGlobalPopup", function (e, data) {
            e.stopPropagation();
            addExitGlobalPopup(data['for'], data['isClose_btn']);
        });

        _shell_wrapper.off("addBookmarkGlobalPopup").on("addBookmarkGlobalPopup", function (e, data) {
            e.stopPropagation();
            addBookmarkGlobalPopup(data['for'], data['isClose_btn']);
        });


        //  addEventsForOpenAndClosGlobalPopup("Notes");
        // addEventsForOpenAndClosGlobalPopup("Hub");
        addEventsForOpenAndClosGlobalPopup("Resources");
        //  addEventsForOpenAndClosGlobalPopup("Hint");
        //  addEventsForOpenAndClosGlobalPopup("Budget");
        //  addEventsForOpenAndClosGlobalPopup("Progress");

        addEventsForOpenAndClosGlobalPopup("Help");
        addEventsForOpenAndClosGlobalPopup("Exit");
        addEventsForOpenAndClosGlobalPopup("Bookmark");

        addEventOnSetting();

        addEventOnHelp()

    }

    var hideSomePopup = function () {

        try {
            Utils.hidePopup(".helpAssets");
            Utils.hidePopup(".settingAssets");
            Utils.hidePopup(".menuListAssets");
            Utils.hidePopup(".menuListwrapper")
            hidePopupOverLay_1();

        } catch (err) {

        }

        checkTranscriptOnOff()
    }

    var updateTitle = function () {

        _module_heading.html(_cMTitle);
        _page_heading.html(_cPTitle);

        let _moduleTitle = $("#templateHolder .module_heading");
        _moduleTitle.html(_cMTitle);


        let ___cPTitle = _cPTitle;
        if (_isDebugging) {
            ___cPTitle += ' >> ' + _cPTile.attr('data-pTile')
        }
        let _pageTitle = $("#templateHolder .pagetitle");
        _pageTitle.html(___cPTitle);
    }

    var addEventsOnShellWrapper = function () {

        try {

            addEventsForGlobalPopups();
            addEventsForTranscript();
            addEventsForAudio();

            _shell_wrapper.off("loadModule").on("loadModule", function (e, data) {

                e.stopPropagation();
                closeGlobalPopup();

                // updateStatus_BudgetTimeAndScore();
                loadModule(data['mNo'] || 1);

                setTimeout(function () {

                    // _cPNo = _modules[_cMNo - 1]['cPage'] || 1                
                    var _len = _cMList.length

                    let _cp = _cMList[_len - 1]['cP'] || 1

                    _cPNo = data['pNo'] || parseInt(_cp) || 1

                    $(_pTiles[_cPNo]).trigger("click");

                }, 100)


            });


            _shell_wrapper.off("updateScore").on("updateScore", function (e) {
                e.stopPropagation();
                try {
                    var _percent = parseInt(window['course']['evaluate_score']);
                    _LS.setScore(_percent);
                } catch (err) {

                }
            })

            _shell_wrapper.off("subPageCompleted").on("subPageCompleted", function (e, pData) {
                
                e.stopPropagation();
                var _mNo = parseInt(pData['mNo']);
                var _pNo = parseInt(pData['pNo']);
                var _pTile = pData['pTile'];

                setPageStatus(_mNo, _pNo, _pTile, 2);
            })

            _shell_wrapper.off("custmsetPageStatus").on("custmsetPageStatus", function (e, val1, val2, val3, val4) {
               
            //    console.log("mmmmmmmmm"+val1, val2, val3, val4);
                setPageStatus(val1, val2, val3, val4);
            });

            _shell_wrapper.off("updatebadge").on("updatebadge", function (e, val1, val2) {

                updatebadgearry[val1] = val2;
                 
            });

           

            _shell_wrapper.off("subPageLoaded").on("subPageLoaded", function (e, pData) {

                e.stopPropagation();
                var _mNo = parseInt(pData['mNo']);
                var _pNo = parseInt(pData['pNo']);
                var _pTile = pData['pTile'];
                setPageStatus(_mNo, _pNo, _pTile, 1);
            })

            _shell_wrapper.off("getModuleDetails").on("getModuleDetails", function (e) {
                e.stopPropagation();
                var _moduleDetails = getModuleData();
                _shell_wrapper.trigger("takeModuleDetails", _moduleDetails)
            });

            _shell_wrapper.off("getCModulePDetails").on("getCModulePDetails", function (e) {
                e.stopPropagation();
                _shell_wrapper.trigger("takeCModulePDetails", JSON.stringify(_user_details.suspend_data[_cMNo]));
            });

            _shell_wrapper.off("getUserDetails").on("getUserDetails", function (e) {
                e.stopPropagation();
                _shell_wrapper.trigger("sentUserDetails", _user_details)
            });

            _shell_wrapper.off("getPageDetails").on("getPageDetails", function (e, pageNo) {
                e.stopPropagation();
                let _userPageData = _user_details.suspend_data[_cMNo][pageNo - 1]
                _shell_wrapper.trigger("takePageDetails", _userPageData);
            });

            _shell_wrapper.off("getCurrentPageDetails").on("getCurrentPageDetails", function (e) {
                e.stopPropagation();
                let _userPageData = _cMList[_cPNo - 1]
                _shell_wrapper.trigger("takeCurrentPageDetails", _userPageData);
            });

            _shell_wrapper.off("setActivityData").on("setActivityData", function (e, _aDetails) {
                e.stopPropagation();
                Utils.removeTimer();
                let _userPageData = _cMList[_cPNo - 1];
                Object.assign(_userPageData, _aDetails);
                checkAndUpdateModuleScore();
                updateUserData();
            });

            _shell_wrapper.off("loadPrevModule").on("loadPrevModule", function (e) {
                e.stopPropagation();
                loadPrevModule()
            });

            _shell_wrapper.off("loadNextModule").on("loadNextModule", function (e) {
                e.stopPropagation();
                loadNextModule()
            });


            _shell_wrapper.off("pageLoaded").on("pageLoaded", function (e, data) {

                e.stopPropagation();
                Utils.isPageChanged = false;

                // console.clear();

                _leftMenu = null;
                _isAudio = "true";

                try {
                    _gHolder.hide();
                    _gHolder.removeClass('video_popup');
                } catch (err) {

                }

                showPreloader();

                $("#popupLoader").empty().removeClass().addClass("h-100 page-section").hide();
                $("#pdfPopupLoader").empty().removeClass().addClass("h-100 page-section").hide()

                clearTimeout(_pageLoadInterval);
                clearTimeout(_timeOutPreLoadNextPage);

                //  $('#global_wrapper').imagesLoaded({ background: true }, function() {

                //  });
                /*
                var imgLoad = imagesLoaded('#shell_templateHolder');

                imgLoad.on('always', function () {
                    // detect which image is broken
                    for (var i = 0, len = imgLoad.images.length; i < len; i++) {
                        var image = imgLoad.images[i];
                        var result = image.isLoaded ? 'loaded' : 'broken';
                    }
                });

                imgLoad.on('done', function (instance) {
                    imageLoaded();
                });
*/

                let _pData = _modules[_cMNo - 1]['pages'][_cPNo - 1];
                let _imgs = _pData['imgs'] || ["./shell/imgs/background-pattern.png"];

                Utils.preLoadImgs_1(_imgs, function () {
                    imageLoaded();
                })

                let preLoadNextPageImage = function () {
                    if (_cPNo < _tPNo - 1) {
                        let __pData = _modules[_cMNo - 1]['pages'][_cPNo];
                        let _imgs = __pData['imgs'] || ["./shell/imgs/background-pattern.png"];
                        Utils.preLoadImgs_1(_imgs, function () { })
                    }

                }

                let imageLoaded = function () {

                    _shell_templateHolder.show();
                    _preloader.fadeOut();

                    _modules[_cMNo - 1]['cPage'] = _cPNo;

                    setPageStatus(_cMNo, _cPNo, _cPTile, 1);
                    updateModuleStatus(_cMNo, 1)

                    _shell_wrapper.trigger("updateMediaNavigation", _pData);

                    _cMTitle = _modules[_cMNo - 1].title
                    _cPTitle = _pData.title;

                    updateTitle()

                    /* $(".help_menu_btn").off('click').on('click', function () {
                        $("#btn_hint").trigger('click');
                    }); */


                    _leftMenu = null;
                    _isAudio = _pData['isAudio'] || "false";

                    let __data = {
                        'mNo': _cMNo,
                        'pNo': _cPNo
                    }
                    _shellMenu.updateMenuStatus(__data)

                    hideSomePopup();

                    try {
                        clearTimeout(_pageLoadInterval);
                    } catch (err) {

                    }

                    try {

                        // _user_details = Utils.getUserDetails();

                        let _user = _user_details.userName;

                        UpdateUserDetail(_user['aid'])
                        UpdateWorkstationDetail(_user['wid'])

                    } catch (err) {
                        console.error('pageLoaded:  ', err.toString())
                    }


                    loadLeftSideMenu(_pData);

                    $("#popupLoader").hide().empty();
                    $("#pdfPopupLoader").hide().empty();
                    // getUserFirstName();
                    _shell_wrapper.trigger("updateDebugger", _isDebugging)

                    try {
                        if (data['callback']) {
                            data['callback']()
                        }
                    } catch (err) {

                    }

                    //  Utils.updateAvatar();
                    hidePreloader();
                    $("#skip_toMaincontent").focus();

                    _timeOutPreLoadNextPage = setTimeout(function () {
                        preLoadNextPageImage();
                    }, 2000);
                    //_btn_next.removeClass("blink");
                    _btn_next.removeClass("next_click");
                    _btn_blink.removeClass("blink");
                    console.log("----remove next_click")
                }


                if (!$(".nav_btns").hasClass("d-hide")) {
                    let _btn_gear = $("#btn_gear");
                    _btn_gear.trigger("click");
                };


            })

            _shell_wrapper.off("updateDebugger").on("updateDebugger", function (e, isTrue) {
                e.stopPropagation();
                _isDebugging = isTrue;
                _user_details['isDebugging'] = _isDebugging;

                if (_isDebugging) {
                    $(".shell_steps_sidebar").show();
                    $("#simple_audio_wrapper").show();
                    $("#simple_audio_holder").show();
                } else {
                    $(".shell_steps_sidebar").hide();
                    $("#simple_audio_wrapper").hide();
                    $("#simple_audio_holder").hide();
                }

                if (_isDebugging) {
                    $(".tree_pTile, #menu_list .mTile, .pTile").removeClass("disabled").addClass("active");
                }

            })

            _shell_wrapper.off("nextPageCompleted").on("nextPageCompleted", function (e) {
                e.stopPropagation();
                setPageStatus(_cMNo, _cPNo + 1, _cPTile, 2);
            })

            _shell_wrapper.off("pageCompleted").on("pageCompleted", function (e) {
              
                e.stopPropagation();
                setPageStatus(_cMNo, _cPNo, _cPTile, 2);
                $(".menuListIcon").removeClass("disabled");
                $("#popupLoader").empty().removeClass().addClass("h-100 page-section").hide();

                console.log(_tPNo+"----"+_cPNo)
                if ((_cMNo == 1) && (_cPNo == _tPNo)) {
                    console.log("---2 end")
                } else {
                    // _btn_next.addClass("blink");
                    enabledDisable(_btn_next, true);
                    _btn_next.addClass("next_click");
                    _btn_blink.addClass("blink");
                    console.log("----add next_click")
                }

                console.log("now----------pageCompleted: ", _cMNo, _cPNo, _cPTile, 2)

            })

            _shell_wrapper.off("markModuleCompleted").on("markModuleCompleted", function (e, mNo) {
                markAllPTilesCompleted(mNo);
            })

            _shell_wrapper.off("moduleCompleted").on("moduleCompleted", function (e) {

                e.stopPropagation();

                try {

                    markAllPTilesCompleted(_cMNo);

                    var _btn_play_pause_timer = $("#btn_play_pause_timer")
                    _btn_play_pause_timer.trigger("click");

                    //Utils.enabledDisable(_btn_play_pause_timer, false);

                    var _timerPopupoverlay = $("#timerPopupoverlay")
                    _timerPopupoverlay.hide();

                    checkAllModuleVisited()

                } catch (err) {

                }

            })

            _shell_wrapper.off("courseCompleted").on("courseCompleted", function (e) {
                e.stopPropagation();
                updateCousreCompletion()
            })

            _shell_wrapper.off("jumpToPage").on("jumpToPage", function (event, _pageRef) {
               
                event.stopPropagation();
                let __pageRef = $("#pTiles .page-link[data-ptile='" + _pageRef + "']");
                __pageRef.trigger("click");
            });

            _shell_wrapper.off("jumpToModulePage").on("jumpToModulePage", function (event, mNo, _pageRef) {
                event.stopPropagation();
                let __pageRef = $("#pTiles .page-link[data-ptile='" + _pageRef + "']");
                __pageRef.trigger("click");
            });

            _shell_wrapper.off("jumpToBack").on("jumpToBack", function (event, _pageRef) {
                event.stopPropagation();
                $("#btn_prev_1").trigger("click");
            });

            _shell_wrapper.off("jumpToNext").on("jumpToNext", function (event, _pageRef) {
                
                event.stopPropagation();
                $("#btn_next_1").trigger("click");
            });

            _shell_wrapper.off("updateCarWithAvatar").on("updateCarWithAvatar", function (event, _pageRef) {
                event.stopPropagation();
                $("#dash-board").addClass(_user_details.userName.cid).addClass(_user_details.userName.aid);
                $("#score-points").addClass('d-show').removeClass('d-hide');
            });

        } catch (err) {
            Utils.error(err);
        }
    }


    var updateCousreCompletion = function () {
        _user_details['sts'] = 2
        //  show_final_popup();
        try {
            _LS.setCourseStatus("completed");
        } catch (err) {

        }
        updateUserData()
    }

    var checkAllModuleVisited = function () {
        let _isAllVisited = false
        let _menuMVisitedLen = $('#menu_list .mTile.visited').length;
        let _menuMItem = $('#menu_list .mTile').length;

        if (_menuMItem == _menuMVisitedLen) {
            _isAllVisited = true;
            updateCousreCompletion()
        }
        return _isAllVisited
    }


    var checkTranscriptOnOff = function () {
        try {
            if ((_isAudio == "false")) {
                transcriptOnOff(false)
            } else {
                transcriptOnOff(true)
            }

        } catch (err) {
            console.error('pageLoaded:  ', err.toString())
        }
    }

    var loadLeftSideMenu = function (pData) {

        _leftMenu = pData['left_menu']
        _isAudio = pData['isAudio']

        if (_leftMenu) {
            let _data = {
                'uData': _user_details,
                'lsn_aNo': '',
                'lsn_btn': 'btn_' + _leftMenu,
                'mNo': _cMNo,
                'pNo': _cPNo,
                'isShow': true
            }
            _left_sideNav = Utils.getLeftSideNav();
            Utils.updateLeftSideNav(_data, function () {
                $("#" + _data['lsn_btn']).addClass("selected").removeClass("notifing");
                checkTranscriptOnOff();
            })
        }

    }

    var transcriptOnOff = function (isTrue) {
        let _btn = $("#btn_transcript")
        Utils.enabledDisable(_btn, isTrue)
        if (!isTrue) {
            _shell_wrapper.trigger("OffTranscript")
        }
    }

    var show_final_popup = function () {
        let _finalPopup = $("#finalPopup")
        _finalPopup.fadeIn(function () {

            var _aData = _data.audio[0];
            _aData["callback"] = function () {
                // _shell_wrapper.trigger("courseCompleted");
            }
            if (_simple_audio) {
                _simple_audio.changeAudio(_aData);
            }

            _finalPopup.show();
            addEventsONFinalPopup()
        });


    }

    var addEventsONFinalPopup = function () {
        $(".retakeBtn").off("click").on("click", function () {
            let _finalPopup = $("#finalPopup")
            _finalPopup.hide();
        })
        $(".exit_course_btn").off("click").on("click", function () {
            let _finalPopup = $("#finalPopup")
            _finalPopup.hide();
            _shell_wrapper.trigger("exitProject");
        })
    }

    var UpdateWorkstationDetail = function (wid) {
        try {
            var index = parseInt(wid.split("_")[1]);
            var newClass = "higtResWorkstation_" + index;
            $(".desktopbg").addClass(newClass)

            //PS
            var strAL = "This is workstation number " + index;
            $("." + newClass).attr("aria-label", strAL)
        } catch (err) {
            Utils.error("ShellWrapper:  pageLoaded:   ", err)
        }
    }

    var UpdateUserDetail = function (aid) {
        try {
            $(".avatar").addClass(aid)
        } catch (err) {
            Utils.error("ShellWrapper:  loadModule:   ", err)
        }
    }


    var changeAudio = function (aData) {
        try {
            if (_simple_audio) {
                var _audioData = aData;
                _audioData["callback"] = aData["callback"] || function () { }
                _simple_audio.updateMedia(_audioData);
            }
        } catch (err) {
            Utils.error("changeAudio:   " + err)
        }
    }




    var addEventOnSetting = function () {

        $(".settingIcon").off().on("click", function (e) {

            e.stopPropagation();

            let _btn = $(this)
            if (!_btn.hasClass("disabled")) {

                Utils.hidePopup(".menuListAssets")
                Utils.hidePopup(".menuListwrapper")
                Utils.togglePopup(".settingAssets")
                currentNavObj = $(".settingIcon");
                checkForPopup()

                $(".menuListIcon").removeClass("isOn");
                _btn.toggleClass("isOn")

                if (_btn.hasClass("isOn")) {
                    addHelpPopupTab()
                } else {
                    Utils.addTabIndex()
                }
            }
        });

        var addHelpPopupTab = function () {
            Utils.removeTabIndex();
            _tabElements = {
                'elements': [{
                    'selector': '#settingIcon'
                },
                {
                    'selector': '#btn_help '
                }
                ],
                'sIndex': 15
            }
            _shell_wrapper.trigger("addTabIndexing", _tabElements);
        }

        $(".menuListIcon").off().on("click", function (e) {

            e.stopPropagation();

            let _btn = $(this)
            if (!_btn.hasClass("disabled")) {

                Utils.togglePopup(".menuListwrapper");
                Utils.togglePopup(".menuListAssets");
                Utils.hidePopup(".settingAssets");
                //  addEventsOnModule();
                currentNavObj = $(".menuListIcon");

                checkForPopup()

                _shell_wrapper.trigger("OffTranscript")

                $(".settingIcon").removeClass("isOn");

                _btn.toggleClass("isOn");
                _shell_wrapper.trigger("pause");

                if (_btn.hasClass("isOn")) {
                    _shellMenu.addTabIndex()
                } else {
                    Utils.addTabIndex()
                }
            }

        })
    }

    var currentNavObj;

    var checkForPopup = function () {

        Utils.hidePopup(".helpAssets");

        let _settingAssets = $(".settingAssets.slideInDown.settingShow")
        let _menuListwrapper = $(".menuListwrapper.slideInDown.settingShow")

        if (_settingAssets.length >= 1 || _menuListwrapper.length >= 1) {
            $("#popupoverlay_1").show();
            $(".nav_btn_f").parent("li").addClass("disabled");
            $("li>.nav_btn_f").addClass("disabled");
            _shell_wrapper.trigger('pauseAudio');
            currentNavObj.attr('aria-expanded', 'true');
        } else {
            hidePopupOverLay_1()
            _shell_wrapper.trigger('playAudio');
            currentNavObj.attr('aria-expanded', 'false');
        }

        checkTranscriptOnOff()

    }

    var hidePopupOverLay_1 = function () {
        $(".nav_btn_f").parent("li").removeClass("disabled");
        $("li>.nav_btn_f").removeClass("disabled");
        $("#popupoverlay_1").hide()
    }

    var addEventOnHelp = function () {
        $(".helpIcon").off().on("click", function (e) {
            e.stopPropagation();
            Utils.hidePopup(".settingAssets")
            Utils.togglePopup(".helpAssets")
        })
    }

    var addEventsForAudio = function () {


        _shell_wrapper.off("mute").on("mute", function (e, data) {
            e.stopPropagation();
            _isMutedByLearner = false;
            _mediaManager.unMute();
        });

        _shell_wrapper.off("unmute").on("unmute", function (e, data) {
            e.stopPropagation();
            _isMutedByLearner = true;
            _mediaManager.mute();
        });

        _shell_wrapper.off("play").on("play", function (e, data) {
            e.stopPropagation();

            if (_isPausedForActivity) {
                $("#btn_play").removeClass("active").addClass("disabled")
                return false
            }
            _isPausedByLearner = false;
            _mediaManager.play();
        });

        _shell_wrapper.off("pause").on("pause", function (e, data) {
            e.stopPropagation();
            _isPausedByLearner = true;
            _mediaManager.pause();
        });


        _shell_wrapper.off("replay").on("replay", function (e, data) {

            Utils.removeTimer();
            e.stopPropagation();

            _isPausedByLearner = false;
            _isPausedForActivity = false;

            _mediaManager.replay();

            let _tile = $(_pTiles[_cPNo]);
            _tile.removeClass('cTile')
            gotoAndLoadPage(_tile);

            // _mediaManager.replay();
        });

        _shell_wrapper.off("playAudio").on("playAudio", function (e, data) {
            e.stopPropagation();
            if (_isPausedByLearner || _isPausedForActivity) {
                return false;
            }
            _shell_wrapper.trigger("play");
        });

        _shell_wrapper.off("pauseAudio").on("pauseAudio", function (e, data) {
            e.stopPropagation();
            _mediaManager.pause();
        });

        _shell_wrapper.off("PauseForActivity").on("PauseForActivity", function (e, data) {
            e.stopPropagation();
            _isPausedForActivity = true;
            _shell_wrapper.trigger("pauseAudio")
            $("#btn_play").addClass("disabled").removeClass("active")
        });

        _shell_wrapper.off("PlayForActivity").on("PlayForActivity", function (e, data) {
            e.stopPropagation();
            _isPausedForActivity = false;
            _shell_wrapper.trigger("playAudio");
            $("#btn_play").removeClass("disabled").addClass("active")
        });

        window.addEventListener('blur', function () {
            _shell_wrapper.trigger('pauseAudio');
        });
        window.addEventListener('focus', function () {
            _shell_wrapper.trigger('playAudio');
        });

    }

    var addEventsForTranscript = function () {

        let _transcript_popup = $("#transcript_popup")
        let _transcript_discription = $("#transcript_discription")

        _shell_wrapper.off("toggleTranscript").on("toggleTranscript", function (e, data) {
            e.stopPropagation();
            _transcript_popup.toggle();
            setTimeout(function () {
                _transcript_discription.focus()
            }, 100)
        });

        _shell_wrapper.off("checkTranscriptOnOff").on("checkTranscriptOnOff", function (e) {
            e.stopPropagation();
            checkTranscriptOnOff()
        });

        _shell_wrapper.off("OffTranscript").on("OffTranscript", function (e) {
            e.stopPropagation();
            _transcript_popup.hide();
        });

        _shell_wrapper.off("updateTranscript").on("updateTranscript", function (e, tData) {
            e.stopPropagation();
            if (tData == "") {
                _shell_wrapper.off("OffTranscript")
            }
            _transcript_discription.html(tData);
        });


    }

    var startCourse = function () {
        _shellNavigation.init();
        loadFirst();
    }



    var loadFirst = function () {

        showPreloader();

        _gHolder.hide();
        _gHolder.empty();

        _shell_wrapper.show();
        _shell_header.show();
        _shell_body.show();
        _shell_templateHolder.show();
        _shell_footer_holder.show();

        _user_details = Utils.getUserDetails() || _user_details

        try {
            let _isSelected = (_skipIntro_checkbox.hasClass('selected')) ? true : false
            _user_details.isFirstTime = !_isSelected;
        } catch (err) {
            Utils.error(err)
        }

        let _lesson_status = _user_details['lesson_status'] || ""


        if (_lesson_status == "") {
            createSuspendData(function () {
                updateLeftMenu()
            });
        } else {
            updateLeftMenu()
        }


    }


    var updateLeftMenu = function () {

        loadMenu('menu', false, function () {
            Utils.loadLeftSideNav(_user_details, function () {
                var _isTrue = false;
                if ((_isLocalBookmark || _isLMS) || (_lmsType == 'xAPI')) {
                    let _lesson_status = _user_details['lesson_status'] || ""
                    if (_lesson_status != "") {
                        _isTrue = true;
                        updateMenuStatus(function () {
                            try {
                                var _btn_bookmark = $("#shell_header #btn_bookmark");
                                _btn_bookmark.trigger("click");
                            } catch (err) {

                            }
                        })
                    } else {
                        getLessonStatus(_isTrue);
                    }
                } else {
                    getLessonStatus(_isTrue);
                }

            })
        });
    }

    var updatePageStatusForMenu = function (_pages, _mNo, callback) {

        let _len = _pages.length - 1
        let _mStatus = 0
        let _isAllVisit = true

        $.each(_pages, function (_pNo, item) {

            let status = parseInt(item['sts']) || 0

            if (_pNo < _len) {
                let _el_id = ("pTile_" + item['pr'])

                if (status != 0) {
                    _mStatus = 1
                }

                if (status < 2) {
                    _isAllVisit = false
                }

                updatePageStatus(_el_id, status)

            } else {

                if (_isAllVisit) {
                    _mStatus = 2
                }

                item['sts'] = _mStatus;
                updateModuleStatus(_mNo, _mStatus);

                if (callback) {
                    callback()
                }
            }

        })
    }

    var updateNextModuleForMenu = function (_modules, mn, callback) {
        var _pages = _modules[mn] || null;

        if (_pages) {
            updatePageStatusForMenu(_pages, mn, function () {
                let ___cMNo = parseInt(mn + 1)
                updateNextModuleForMenu(_modules, ___cMNo, callback)
            })
        } else {
            if (callback) {
                callback();
            }
        }

    }

    var updateMenuStatus = function (callback) {
        let _modules = _user_details['suspend_data'];
        updateNextModuleForMenu(_modules, 1, callback)
    }

    var getLessonStatus = function (isJump) {

        var _mNo = 1;
        var _pNo = 1;

        if (isJump) {
            var _lesson_status = (_user_details['lesson_status']);
            var _tempArr = (_lesson_status).split('_');
            _mNo = parseInt(_tempArr[0]);
            _pNo = parseInt(_tempArr[1]);
        }


        _mNo = _mNo || 1;
        loadModule(_mNo);

        $(_pTiles[_pNo]).trigger("click");

        let _obj = {
            "mNo": _mNo,
            "pNo": _pNo
        }
        _shellMenu.updateMenuStatus(_obj)

        tabIndexingOnShellNav()
        // tabIndexingOnGlobalPopup()
    }

    var tabIndexingOnShellNav = function () {

        var _tabElements = {

            'elements': [{
                'selector': '#skip_toMaincontent'
            },
            {
                'selector': '#skip_toNavigation'
            },
            {
                'selector': '#shell_header'
            },
            {
                'selector': '#shell_header .course_heading'
            },
            {
                'selector': ".breadcrum_wraper",
                "aria-label": "Breadcrumb"
            },
            {
                'selector': '#shell_header .module_heading'
            },
            {
                'selector': '#shell_header .page_heading'
            },
            {
                'selector': '#shell_header .header_right_nav .avatar'
            },
            {
                'selector': '#shell_header .header_right_nav #btn_transcript'
            },
            {
                'selector': '#transcript_popup #transcript_discription'
            },
            {
                'selector': '#transcript_popup .close',
                'role': 'button',
                'title': 'Close'
            },
            {
                'selector': '#shell_header .header_right_nav #btn_help'
            },
            {
                'selector': '#shell_header .header_right_nav #btn_unmute'
            }, {
                'selector': '#shell_header .header_right_nav #btn_mute'
            },
            {
                'selector': '#shell_header .header_right_nav #btn_pause'
            },
            {
                'selector': '#shell_header .header_right_nav #btn_play'
            },
            {
                'selector': '#shell_header .header_right_nav #btn_replay'
            },
            {
                'selector': '#shell_header .header_right_nav #settingIcon'
            },
            {
                'selector': '#shell_header .header_right_nav #menuListIcon'
            },
            {
                'selector': '#shell_header .header_right_nav #menu_list'
            },
            {
                'selector': '#shell_header .header_right_nav #btn_exit'
            },
            {
                'selector': '#popupLoader'
            },
            {
                'selector': '#pdfPopupLoader'
            }
            ],
            'sIndex': 1,
            'nIndex': 1,
        };
        _shell_wrapper.trigger("addTabIndexing", _tabElements);

    }

    var tabIndexingOnGlobalPopup = function () {
        var _tabElements = {
            'elements': [{
                'selector': '#popupLoader'
            },
            {
                'selector': '#pdfPopupLoader'
            },
            {
                'selector': '#bookmark_popup_holder'
            },
            {
                'selector': '#exit_popup_holder'
            },
            {
                'selector': '#resources_popup_holder'
            },
            {
                'selector': '#help_popup_holder'
            }

            ],
            'sIndex': 0,
            'nIndex': 0,
        };
        _shell_wrapper.trigger("addTabIndexing", _tabElements);

    }


    var destroyExcelSheet = function () {
        try {
            $('.excelData .jexcel').jexcel('destroy');
        } catch (e) { }
    }

    var loadModule = function (mNo) {

        _cPageIndexNo = 0;

        _cMNo = parseInt(mNo);
        _mTitle.html("<h4>" + _modules[_cMNo - 1]['title'] + "</h4>");

        var _pages = _modules[_cMNo - 1]['pages'];

        createPageTile(_cMNo, _pages);

        changeModule();

        setTimeout(function () {
            if (_cPNo == _pages.length) {
                skipTimerCall = true;
            }
            updateModuleLevelGlobalItems();
        }, 600)



    }

    var changeModule = function () {
        var _mData = getModuleData();
        _shell_wrapper.trigger("changeModule", _mData)
        return _mData
    }

    var getMinScore = function () {
        return _modules[_cMNo - 1]['mnsr'];
    }

    var getMaxScore = function () {
        return _modules[_cMNo - 1]['mxsr'];
    }

    var getBudgetedTime = function () {
        return _modules[_cMNo - 1]['budgetedTime'];
    }

    var updateBudgetData = function () {

        /*  try {
              var _budgetData = {
                  'budgetedTime': getBudgetedTime(),
                  'takenTime': getTakenTime()
              }
              _shell_wrapper.trigger("updateBudgetData", _budgetData);
          } catch (err) {

          }
          */

    }

    var updateNoteData = function () {
        try {
            var _notesData = _modules[_cMNo - 1]['notes']
            _shell_wrapper.trigger('updateNotesData', _notesData);
        } catch (err) {

        }
    }

    var getTakenTime = function () {
        var _takenTime = 0;
        try {
            if (_cMList) {
                var _length = _cMList.length;
                if (_length) {
                    var _mStatusData = _cMList[_length - 1];
                    _takenTime = _mStatusData['tT'] || 0;
                    return _takenTime;
                }
            }
        } catch (err) {

        }
    }

    var updateModuleLevelGlobalItems = function () {

        if (!skipTimerCall) {
            resetTimerOverlay();
            try {
                updateBudgetData();
            } catch (err) {

            }
        }
        skipTimerCall = false;


    }

    var addDocumentsEvent = function () {
        _shell_wrapper.off("openDocuments").on('openDocuments', function () {

        });
    }

    var updateStatus_BudgetTimeAndScore = function () {
        // checkAndUpdateModuleTime();
        checkAndUpdateModuleScore();
    }


    var getModuleData = function () {
        if (_cMList) {
            var _length = _cMList.length;
            if (_length) {
                var _mStatusData = _cMList[_length - 1];
                return _mStatusData;
            }
        }
    }

    var checkAndUpdateModuleTime = function () {
        try {
            var _module_timers = $("#shell_header #module_timer");
            var _tTime = $(_module_timers[0]).text();

            var _mStatusData = getModuleData();
            if (_mStatusData) {
                _mStatusData['tT'] = _tTime;
            }
        } catch (err) {
            Utils.error("shellController: checkAndUpdateModuleTime: ", err)
        }
    }

    var checkAndUpdateModuleScore = function () {

        try {

            let _length = _cMList.length;
            let _uTScore = 0;

            $.each(_cMList, function (pNo, pItem) {
                if (pNo < (_length - 1)) {
                    let _score = parseInt(pItem['sr']) || 0;
                    _uTScore += _score;
                }
            })

            let _mStatusData = getModuleData();
            if (_mStatusData) {
                _mStatusData['sr'] = _uTScore;
            }

            _shell_wrapper.trigger('updateModuleScore', _uTScore);

            try {
                let _percent = parseInt(_uTScore);
                _LS.setScore(_percent);
            } catch (err) {

            }

            // updateScoreCourseLevel(false);

        } catch (err) {
            Utils.error("shellController: checkAndUpdateModuleScore: ", err)
        }
    }

    var createModuleTile = function (modules) {

        $.each(modules, function (idx) {
            let _mNo = (idx + 1)
            if (_mNo == _cMNo) {
                loadModule(_mNo)
            }
        });
    }

    var updateViewForModule = function (mNo) {

        try {
            let _mTiles = $('#menu_list .mTile');
            _mTiles.removeClass('cMTile');
            let _mTile = $("#menu_list .mTile_" + mNo);
            _mTile.addClass('cMTile');
        } catch (err) {

        }

        try {
            let _mTiles = $('#menu_list ._mTile');
            _mTiles.removeClass('cMTile');
            let _mTile = $("#menu_list ._mTile_" + mNo);
            _mTile.addClass('cMTile');
        } catch (err) {

        }

        try {
            let _cardrive = $('#menu_list #cardrive');
            _cardrive.removeAttr('class');
            _cardrive.addClass("_mTile_" + mNo);
        } catch (err) {

        }
        updateModuleStatus(mNo, 1)

    }

    var createPageTile = function (mNo, pages) {

        //  var _pageList = _user_details['suspend_data'];

        _cMList = _user_details['suspend_data'][mNo]

        let _pTilesUl = $("#pTiles ul");
        _pTilesUl.empty();

        let _isClass = (_isLinear) ? "disabled" : "active";

        let _backTile = '<li class="page-item ' + _isClass + '"><a id = "btn_prev_1" class="btn_prev page-link ' + _isClass + '" data-pTile="previous" href="#" tabindex="0">Previous</a></li>';

        let _nextTile = '<li class="page-item ' + _isClass + '"><a id = "btn_next_1"  class="btn_next page-link ' + _isClass + '" data-pTile="next" href="#" tabindex="0">Next</a></li>';

        _pTilesUl.append(_backTile);

        _tPNo = pages.length;

        let _display_stepNo = 0;

        let _cp = _cMList[_tPNo - 1]['cP'] || 1

        _cPNo = parseInt(_cp) || 1

        let _btn_ref = {}

        $.each(pages, function (idx, page) {
            _cPageIndexNo++;

            let _pNo = parseInt(idx + 1);

            let _isDisplay = page["isDisplay"] || "true";
            let _isDisplayClass = (_isDisplay.toLowerCase() == "false") ? "tileHide" : "tileShow";

            let _stepSpan = ""
            let _isStep = page["isStep"] || "false";


            if (_isStep.toLowerCase() == "true") {
                _display_stepNo++
                _stepSpan = '<span>' + _display_stepNo + '</span>'
            }

            // let _isActive = page["isActive"] || "false";
            // let _pClass = (_isActive.toLowerCase() == "true") ? "active" : "disabled";

            let _status = getPageStatus(mNo, _pNo);

            let _sClass = (_status == 2) ? "completed" : (_status == 1) ? "inprogress" : "not_attempted"

            let _pClass = (!_isLinear) ? "active" : "disabled";
            _pClass = (_pNo == 1) ? "active" : _pClass;

            if (_sClass !== "not_attempted") {
                _pClass = "active"
            }

            _pClass = _pClass + ' ' + _isDisplayClass;

            let _pTile = '<li class="page-item ' + _pClass + '"><a id="pTile_' + mNo + '_' + _pNo + '" class="page-link pTile ' + _pClass + ' ' + _sClass + '" data-pTile=' + page["pageData"] + ' data-bgClass=' + page["bgClass"] + ' href="#" data-pTileNo=' + _cPageIndexNo + ' >' + _stepSpan + '</a></li>'

            _pTilesUl.append(_pTile);

            if (page['left_menu']) {
                _btn_ref["btn_" + page['left_menu']] = page['pageData']
            }

        });

        _pTilesUl.append(_nextTile);

        addEventsOnPageTile();

        resetLoadPage();

        //  checkAndUpdateAllPTilesVisited(mNo);
        //  checkAndUpdateAllMTilesVisited();

        try {
            let _data = {
                'btn_ref': _btn_ref,
                'mNo': mNo,
                'pNo': _cPNo
            }
            Utils.getLeftSideNav().updateLeftNavRef(_data)
        } catch (err) {

        }


    }


    var addEventsOnPageTile = function () {

        _btn_prev = $(".btn_prev");
        _btn_next = $(".btn_next");
        _btn_blink = $(".btn_next .blinkBg");

        _courseProgress = $("#courseProgress");
        _courseProgressPercent = $("#courseProgressPercent");

        _pTiles = $("#pTiles .page-link");

        _pTiles.off("click").on("click", function (e) {
            e.stopPropagation();

            let _tile = $(this);

            if (_tile.hasClass('cTile')) return;

            let _liTile = _tile.parent();

            if (_liTile.hasClass('active')) {
                let _dataTile = _tile.attr('data-pTile');
                if (_dataTile == 'previous') {
                    loadPreviousPage();
                    return;
                } else if (_dataTile == 'next') {
                    loadNextPage();
                    return;
                }

                gotoAndLoadPage(_tile);
            }
        }).removeClass('cTile')

    }

    var addEventsOnModule = function () {
        let _mTiles = $("#menu_list .visited");

        _mTiles.off("click").on("click", function (e) {

            e.stopPropagation();
            Utils.hidePopup(".menuListAssets")
            Utils.hidePopup(".menuListwrapper")

            _cMNo = parseInt($(this).attr("id").substring(6, 7));
            loadModule(_cMNo || 1);

        })
    }

    var loadPreviousPage = function () {
        let _pNo = parseInt(_cPNo) - 1;
        if (_pNo <= 0) {
            _cMNo = parseInt(_cMNo) - 1;
            loadModule(_cMNo || 1);
            _pNo = _tPNo
        }
        $(_pTiles[_pNo]).trigger("click");
    }


    var loadNextPage = function () {


        let _pNo = parseInt(_cPNo) + 1;
        if (_pNo > _tPNo) {
            _cMNo = parseInt(_cMNo) + 1;
            loadModule(_cMNo || 1);
            _pNo = 1
        }
        $(_pTiles[_pNo]).trigger("click");
    }

    var loadNextModule = function () {
        _cPNo = parseInt(_tPNo);
        loadNextPage();
    }

    var loadPrevModule = function () {
        _cPNo = 1;
        loadPreviousPage()
    }


    var gotoAndLoadPage = function (tile) {
       
        if (tile) {
            if (tile.hasClass('cTile')) return;
            _pTiles.removeClass('cTile');
            Utils.enabledDisable(_pTiles, true)
            let _dataTile = tile.attr('data-pTile');

            _cPTile = tile;

            if (childWinRef) {
                childWinRef.closeFromParentWin();
                childWinRef.close();
                childWinRef = null;
            }

            loadPage(_dataTile);
        }
    }


    var removeTemplateEvents = function () {
        try {
            // removeAllEvents('#templateHolder');
            let __templateHolder = $('#templateHolder')[0]
            let _events = Utils.getEvents(__templateHolder)
            $.each(_events, function (key, val) {
                $('#templateHolder').off(key)
            });
        } catch (err) {

        }
    }

    var rsetGlobalVaribles = function () {

        Utils.isPageChanged = true;

        _shell_wrapper.off('fillTheValues');
        _shell_wrapper.off("mediaReadyToPlay");
        _shell_wrapper.off("mediaCanplaythrough");
        _shell_wrapper.off("markcompletepage");
        _shell_wrapper.off("popup_close");
        _shell_wrapper.off("activityResult");
        _shell_wrapper.off("closeActivity")
        _shell_wrapper.off("startEvents_3")
        _shell_wrapper.off("start_mcms_mcss_1")
        _shell_wrapper.off("initPage");
        _shell_wrapper.off("takePageDetails")
        _shell_wrapper.off("sentUserDetails")
        _shell_wrapper.off("componentDidMount")
        _shell_wrapper.off("clearAlertTimerInstance")
        _shell_wrapper.off("activityResult_3")

        removeAllEvents('#templateHolder');
        _shell_wrapper.removeAttr('class')
        _shell_wrapper.addClass("shell_wrapper")

        destroyMedia();

    }

    var destroyMedia = function () {

        try {
            _mediaManager.stop();
        } catch (err) {
            // Utils.error("ShellController: destroyMedia:")
        }
    }

    var resetLoadPage = function () {

        rsetGlobalVaribles();

        _shell_templateHolder.show();
        _gHolder.hide();
        _shell_templateHolder.empty();

        let _popupoverlay = $("#popupoverlay");
        _popupoverlay.hide();

        $("#pdfPopupLoader").empty().hide();
        $("#popupLoader").empty().hide();
        //$(".btn_next").removeClass("blink");
        $(".btn_next .blinkBg").removeClass("blink");

        try {
            Utils.removeTimer()
        } catch (err) {

        }
        // Utils.removeTabIndex()
    }

    var enabledDisable = function (_btn, isActive) {
        if (isActive) {
            _btn.addClass('active').removeClass("disabled");
            _btn.parent().addClass("active").removeClass('disabled');
        } else {
            _btn.removeClass('active').addClass("disabled");
            _btn.parent().removeClass("active").addClass('disabled');
        }
    }

    var updateNavigation = function () {

        _btn_prev = $(".btn_prev");
        _btn_next = $(".btn_next");

        let _tempArr = _cPTile.attr('id').split('_')

        _cMNo = parseInt(_tempArr[1]);
        _cPNo = parseInt(_tempArr[2]);

        updateViewForModule(_cMNo);

        try {
            enabledDisable(_btn_prev, true);
            if (_isLinear) {
                enabledDisable(_btn_next, false);
            } else {
                enabledDisable(_btn_next, true);
            }

            _cPTile.addClass('cTile');
            Utils.enabledDisable(_cPTile, false)

          

            if (_cMNo == 1 && _cPNo == 1) {
                enabledDisable(_btn_prev, false);
            } else if (_cMNo == _tMNo && _cPNo == _tPNo) {
                enabledDisable(_btn_next, false);
            }

            if ((_cMNo == _tMNo)) {
                enabledDisable(_btn_next, false);
            } else if ((_cMNo != 1) && (_cPNo == 1)) {
                enabledDisable(_btn_next, false);
            }

              if (_cPTile.hasClass('completed')) {
                enabledDisable(_btn_next, true);
            }
        } catch (err) {
            Utils.error("ShellController: updateNavigation:", err)
        }

    }


    var checkAllPTilesVisited = function () {
        return _checkAllPTilesVisited(_cMNo);
    }

    var _checkAllPTilesVisited = function (mNo) {
        let _isTrue = true;
        try {
            var _cMList = _user_details['suspend_data'][mNo];
            let _len = _cMList.length - 1
            $.each(_cMList, function (index, item) {
                if (index < _len) {
                    if (parseInt(item['sts']) < 2) {
                        _isTrue = false;
                    }
                }
            })

        } catch (err) {
            Utils.error("ShellController: _checkAllPTilesVisited:", err)
        }

        return _isTrue;
    }

    var getPageStatus = function (mNo, pNo) {
        let _status = 0;

        try {
            let _pObj = _cMList[parseInt(pNo) - 1]
            _status = _pObj['sts'] || 0

        } catch (err) {
            Utils.error("ShellController: getPageStatus:", err)
        }

        return _status
    }

    var setPageStatus = function (mNo, pNo, pTile, status) {

        //  Utils.clear();

        let _mNo = parseInt(mNo);
        let _pNo = parseInt(pNo);

        let _status = parseInt(status);
        let __status = getPageStatus(mNo, pNo);

        if (_status == 1 && __status == 2) {
            _shell_wrapper.trigger('fillTheValues');
        }

        if (__status >= _status) {
            _status = __status
        } else {
            try {
                _cMList[_pNo - 1]['sts'] = _status;
                _cMList[_pNo - 1]['badge'] = updatebadgearry;
               
            } catch (err) {
                Utils.error("ShellController: setPageStatus:", err)
            }
        };

        _user_details['suspend_data'][_mNo] = _cMList;

        updateStatus(pTile, _status);

        updateUserData();

    }


    var updateStatus = function (el, status) {
        // console.log("+++++++"+JSON.stringify(el, null, 2))
        updatePageStatus_1(el, status);

        let _el_id = $(el).attr("id");
        let _sClass = updatePageStatus(_el_id, status);

        let _isTrue = _checkAllPTilesVisited(_cMNo)
        _status = (_isTrue) ? 2 : 1
        updateModuleStatus(_cMNo, _status)

        updateLMSStatus(_sClass)
    }


    var checkAndUpdateModuleStatus = function (_mNo, _status) {

        let _cMList = _user_details['suspend_data'][_mNo];

        let _mStatusData = {
            sts: _status || 0
        }

        var _length = _cMList.length;
        if (_length) {
            _mStatusData = _cMList[_length - 1];
        }

        if (_mStatusData['sts'] <= _status) {
            _mStatusData['sts'] = _status
        }

        _status = _mStatusData['sts'];
        return _status
    }

    var updateModuleStatus = function (_mNo, status) {


        let _status = checkAndUpdateModuleStatus(_mNo, status);

        let _sClass = 'not_attempted';

        let el = $('#menu_list .mTile_' + _mNo);
        let _el = $('#menu_list ._mTile_' + _mNo);

        try {

            _el.removeClass(_sClass);
            el.removeClass(_sClass);

            if (_status == 1) {
                _sClass = "inprogress";
                enabledDisable(el, true);
                el.removeClass("disabled").addClass("active");
                _el.removeClass("disabled").addClass("active");;
            } else if (_status == 2) {
                el.removeClass("inprogress");
                _el.removeClass("inprogress");
                _sClass = "completed";
                el.addClass('visited').removeClass("disabled").addClass("active");
                _el.addClass('visited').removeClass("disabled").addClass("active");;
                enabledDisable(el, true);
            }

            el.addClass(_sClass);
            _el.addClass(_sClass);

        } catch (err) {
            Utils.error("ShellController: updateModuleStatus updateStatus:", err)
        }

        moduleDetails[_mNo - 1] = {
            "mNo": _mNo,
            "status": _status,
            "sClass": _sClass,
            "cMNo": _cMNo
        }
        // console.log("moduleDetails: ", moduleDetails)
    }

    var updatePageStatus_1 = function (el, status) {

        let _sClass = 'not_attempted';
        //  console.log("updatePageStatus_1:    ", el)
        try {

            let _el = $(el)

            _el.removeClass(_sClass)

            if (status == 1) {
                _sClass = "inprogress";
                enabledDisable(_el, true);

            } else if (status == 2) {

                _el.removeClass("inprogress")
                enabledDisable(_el, true);
                _sClass = "completed";
                checkForNextPTile(_cPNo + 1)
            }

            _el.addClass(_sClass);

        } catch (err) {
            //  console.log("ShellController 1: updatePageStatus_1 updateStatus:", err)
        }


    }

    var updatePageStatus = function (_el_id, status) {

        let _sClass = 'not_attempted';

        try {

            let __el = $("#tree_" + _el_id);
            //  console.log("updatePageStatus: ", _el_id); 
            __el.removeClass(_sClass);
            //  enabledDisable(__el, false);

            if (status == 1) {
                _sClass = "inprogress";
                enabledDisable(__el, true);
            } else if (status == 2) {
                __el.removeClass("inprogress")
                enabledDisable(__el, true);
                _sClass = "completed";
                checkForNextPTile(_cPNo + 1)
            }
            __el.addClass(_sClass)

        } catch (err) {
            //  console.log("ShellController: updatePageStatus :", err)
        }

        updateCourseProgress();
        return _sClass
    }

    var updateCourseProgress = function () {

        try {
            let _vPNo = $(".tree_pTile.completed").length
            _user_details['vPNo'] = _vPNo;
            let _tPNo = _user_details['tPNo']

            let _progress = parseInt(_vPNo * 100 / parseInt(_tPNo));

            _user_details['cProgress'] = _progress;
            _courseProgress.attr('value', _progress);
            _courseProgressPercent.text(Utils.addZero(_progress) + "%");

        } catch (err) {

        }

        updatePageCount();
    }


    let updatePageCount = function () {

        try {
            // let _currentPage = $("#currentPage");
            // let _cPNo = _user_details['cPNo']
            // _currentPage.text(Utils.addZero(_cPNo));

            let _totalPages = $("#totalPages");
            let _tPNo = _user_details['tPNo']
            _totalPages.text("/" + Utils.addZero(_tPNo));

        } catch (err) {

        }

    }

    var updateLMSStatus = function (_sClass) {
        try {
            if (_lmsType == 'xAPI') {
                // let _pages = _modules[_cMNo - 1]['pages'],
                //  _title = _pages[_cPNo - 1]['title'];
                if (_cMTitle !== "") {
                    let _title = (_user_details['cName'] + " : " + _cMTitle + " > " + _cPTitle).toString();
                    _LS.setPageStatus(_title, _sClass);
                }
            }
        } catch (err) {
            Utils.error("_lmsType-xAPI: updateStatus:", err)
        }

    }



    var markAllPTilesCompleted = function (mNo) {

        try {

            let _pageList = _user_details['suspend_data'][mNo];

            $.each(_pageList, function (index, item) {

                let _status = 2;
                item['sts'] = _status;

                let _pNo = parseInt(index) + 1;
                let _tile = $(_pTiles[_pNo]);
                updatePageStatus_1(_tile, _status);

                if (_status !== 0 || _pNo == 1) {
                    enabledDisable(_tile, true);
                } else {
                    enabledDisable(_tile, !_isLinear);
                }

                if (item['pr'] != undefined) {
                    let _tree_pTile = ("#tree_pTile_" + item['pr']);
                    //    console.log(_tree_pTile, item['pr'])
                    updatePageStatus_1(_tree_pTile, _status);
                }

            })

        } catch (err) {
            // console.log("ShellController: checkAndUpdateAllPTilesVisited:", err)
        }

        updateModuleStatus(mNo, 2);

        updateCourseProgress();
    }

    var checkForNextPTile = function (nPNo) {
        // let _tile = $(_pTiles[nPNo]);
        // enabledDisable(_tile, true);
        try {
            let _pTile = $('#tree_pTile_' + _cMNo + '_' + nPNo)
            enabledDisable(_pTile, true);
        } catch (err) {
            Utils.error("ShellController: checkAndUpdateAllPTilesVisited:", err)
        }
    }



    var loadPage = function (pRef) {

        //  destroyExcelSheet(); 
        MediaManager.stop();

        $("#popupLoader").hide().empty().removeClass().addClass("h-100 page-section")

        resetLoadPage();


        showPreloader();

        _shell_templateHolder.hide().empty();

        let _src = "./views/" + pRef + "/" + pRef + ".html";

        _btn_resources.addClass('disabled');

        $("#btn_workstation").addClass('disabled');
        $("#btn_hint").removeClass('disabled');
        $("#btn_help").removeClass('disabled');

        _btn_transcript.show();
        _btn_replay.show();

        _left_sideNav_holder.removeClass("show")
        _left_sideNav_holder.hide();

        _popup_transcript.hide();
        _bookmarkHolder.hide();

        _shell_wrapper.trigger("clearZoomOutTimerInstance");
        _shell_wrapper.trigger("clearAlertTimerInstance");

        try {
            let _aData = _audioData.blank;
            _aData['callback'] = function () { }
            changeAudio(_aData);
        } catch (err) {
            Utils.error("sendAudioDetails:  " + err)
        }

        try {
            Utils.removeTimer()

        } catch (err) {

        }

        _btn_next = $(".btn_next");
        enabledDisable(_btn_next, false);

        let _start_index = 545;

        _shell_wrapper.addClass("page_" + _cPNo).addClass("module_" + _cMNo)


        _shell_templateHolder.load(_src, function (responseTxt, statusTxt, jqXHR) {

            if (statusTxt == "success") {

                _isPausedByLearner = false;
                _isPausedForActivity = false;
                $("#btn_play").removeClass("disabled").addClass("active");

                let _pageSection = $(".page-section")
                _pageSection.addClass("page_" + pRef + ' h-100');
                _pageSection.addClass("page_" + _cPNo).addClass("module_" + _cMNo)


                let _bgClass = _cPTile.attr('data-bgClass') || '';

                //  if (_cMNo>1) {
                $(".prog-bar").removeClass("d-hide")
                $(".page-nav").removeClass("d-hide")
                //  }
                if (_bgClass != '') {
                    _pageSection.addClass('activity').addClass(_user_details.userName.aid).addClass(_user_details.userName.cid).addClass(_bgClass);
                }

                let _tabElements = {
                    'elements': [{
                        'selector': $("#left_sideNav_holder .btn")
                    },
                    {
                        'selector': $(".page_" + pRef),
                    }
                    ],
                    'sIndex': _start_index,
                    'nIndex': 1
                };

                _shell_wrapper.trigger("addTabIndexing", _tabElements);

                tabIndexingOnShellNav();

                updateNavigation();

            }

            if (statusTxt == "error") {
                Utils.error("Error: " + jqXHR.status + " " + jqXHR.statusText);
            }

        });

    }

    var showPreloader = function () {
        _preloader.show()
    }

    var hidePreloader = function () {
        _preloader.fadeOut()
    }


    var loadMenu = function (pRef, isCloseVisible, callback) {
        Utils.loadGlobalTemplate(_menuHolder, pRef, function () {
            try {
                _shellMenu = new ShellMenu();
                let _mObj = {
                    "modules": _modules,
                    "cMNo": _cMNo,
                    "cPNo": _cPNo,
                    "isLinear": _isLinear || false
                }
                _shellMenu.init(_mObj);

                if (!isCloseVisible) {
                    $("#return_btn").hide();
                }
                // showGlobalPopup();
            } catch (err) {
                Utils.error("ShellController: loadMenu:", err)
            }

            if (callback) {
                callback()
            }
        })

    }

    var retakeCourse = function () {
        //_cPNo = _modules[_cMNo - 1]['cPage'] || 1;
        resetCourseLevelData();

        let _pNo = 1,
            _cMNo = 1;
        loadModule(_cMNo);

        $(_pTiles[_pNo]).trigger("click");

        updateUserData();
    }

    var retakeModule = function (mNo) {
        //_cPNo = _modules[_cMNo - 1]['cPage'] || 1;
        resetCourseLevelData();
        let _pNo = 1,
            _cMNo = mNo || 1;
        loadModule(_cMNo);

        $(_pTiles[_pNo]).trigger("click");

        updateUserData();
    }

    var gotoModule = function (mNo, pNo) {
        if (_cMNo != mNo) {
            _cMNo = mNo || 1;
            loadModule(_cMNo);
        }
        let _pNo = pNo || 1
        $(_pTiles[_pNo]).trigger("click");
    }

    var moduleLevelWorkstationAction = function () {

    }

    var resetTimerOverlay = function () {
        let _btn = $("#btn_play_pause_timer");
        Utils.enabledDisable(_btn, true);
        _btn.addClass('pause').removeClass('play').attr('title', 'Coffee break');

        let _timerPopupoverlay = $("#timerPopupoverlay");
        _timerPopupoverlay.hide();

    }

    var resetCourseLevelData = function () {
        updateScoreCourseLevel(true);
        resetTimerOverlay();
    }

    var resetModuleLevelTracking = function (cMList) {
        let _length = cMList.length;
        $.each(cMList, function (pNo, pItem) {
            if (pNo < (_length - 1)) {
                pItem['sr'] = 0;
                pItem['tOut'] = 0;
                pItem['result'] = 0;
                pItem['aD'] = {};
            } else {
                let _mStatusData = cMList[_length - 1];
                _mStatusData['sr'] = 0
                _mStatusData['tT'] = "00:00:00";
            }
        })
    }

    var addExitGlobalPopup = function (pRef, isCloseVisible) {
        Utils.loadGlobalTemplate(_exitHolder, pRef, function () {
            try {
                if (!isCloseVisible) {
                    $("#return_btn").hide();
                }
                _exitHolder.hide();
            } catch (err) {
                Utils.error("ShellController: addExitGlobalPopup:", err)
            }
        })
    }

    var addBookmarkGlobalPopup = function (pRef, isCloseVisible) {
        Utils.loadGlobalTemplate(_bookmarkHolder, pRef, function () {
            try {
                if (!isCloseVisible) {
                    $("#return_btn").hide();
                }
                _bookmarkHolder.hide();
            } catch (err) {
                Utils.error("ShellController: addBookmarkGlobalPopup:", err)
            }
        })
    }

    var addProgressGlobalPopup = function (pRef, isCloseVisible) {
        Utils.loadGlobalTemplate(_progressHolder, pRef, function () {
            try {
                if (!isCloseVisible) {
                    $("#return_btn").hide();
                }
                _progressHolder.hide();
            } catch (err) {
                Utils.error("ShellController: addProgressGlobalPopup:", err)
            }
        })
    }


    var addBudgetGlobalPopup = function (pRef, isCloseVisible) {

        Utils.loadGlobalTemplate(_budgetHolder, pRef, function () {
            try {
                if (!isCloseVisible) {
                    $("#return_btn").hide();
                }
                _budgetHolder.hide();
                updateBudgetData();
            } catch (err) {
                Utils.error("ShellController: addBudgetGlobalPopup:", err)
            }
        })
    }

    var addNotesGlobalPopup = function (pRef, isCloseVisible) {
        Utils.loadGlobalTemplate(_notesHolder, pRef, function () {
            try {
                if (!isCloseVisible) {
                    $("#return_btn").hide();
                }
                _notesHolder.hide();
            } catch (err) {
                Utils.error("ShellController: addNotesGlobalPopup:", err)
            }
        })
    }


    var addHubGlobalPopup = function (pRef, isCloseVisible) {
        Utils.loadGlobalTemplate(_hubHolder, pRef, function () {
            try {
                if (!isCloseVisible) {
                    $("#return_btn").hide();
                }
                _hubHolder.find(".modal-body").append(_menuHolder);
                _hubHolder.hide();
            } catch (err) {
                Utils.error("ShellController: addHubGlobalPopup:", err)
            }
        })
    }


    var addResourcesGlobalPopup = function (pRef, isCloseVisible) {
        Utils.loadGlobalTemplate(_resourcesHolder, pRef, function () {
            try {
                if (!isCloseVisible) {
                    $("#return_btn").hide();
                }
                _resourcesHolder.hide();
            } catch (err) {
                Utils.error("ShellController: addResourcesGlobalPopup:", err)
            }
        })
    }

    var addHintGlobalPopup = function (pRef, isCloseVisible) {
        Utils.loadGlobalTemplate(_hintHolder, pRef, function () {
            try {
                if (!isCloseVisible) {
                    $("#return_btn").hide();
                }
                _hintHolder.hide();
            } catch (err) {
                Utils.error("ShellController: addHintGlobalPopup:", err)
            }
        })
    }

    var addHelpGlobalPopup = function (pRef, isCloseVisible) {
        Utils.loadGlobalTemplate(_helpHolder, pRef, function () {
            try {
                if (!isCloseVisible) {
                    $("#return_btn").hide();
                }
                _helpHolder.hide();
            } catch (err) {
                Utils.error("ShellController: addHelpGlobalPopup:", err)
            }
        })
    }


    var updateGlobalPopup = function (pRef, isCloseVisible) {
        Utils.loadGlobalTemplate(_gHolder, pRef, function () {
            try {
                if (!isCloseVisible) {
                    $("#return_btn").hide();
                }
                showGlobalPopup();
            } catch (err) {
                Utils.error("ShellController: updateGlobalPopup:", err)
            }
        })

    }

    var showGlobalPopup = function () {
        if (_mediaManager) {
            _mediaManager.pause();
        }
        _gHolder.show();

    }

    var closeGlobalPopup = function () {
        _shell_templateHolder.show();
        hideGlobalPopups();
        _shell_wrapper.trigger('playAudio');
        Utils.addTabIndex()
    }

    var hideGlobalPopups = function () {

        _gHolder.hide();

        _budgetHolder.hide();
        _notesHolder.hide();

        _hubHolder.hide();
        _resourcesHolder.hide();
        _hintHolder.hide();
        _progressHolder.hide();
        _helpHolder.hide();

        _exitHolder.hide();
        _bookmarkHolder.hide();

        hideSomePopup();
    }

    var exitProject = function () {

        updateUserData();

        try {
            _LS.quit();
        } catch (err) { }

        _shell_templateHolder.show();
        hideGlobalPopups();

        window.close();
    }


    var updateUserData = function () {
        try {
            let _mStatusData = getModuleData();
            if (_mStatusData) {
                _mStatusData['cP'] = _cPNo;
            }
        } catch (err) {

        }
        updateTrakingData();

    }


    var updateTrakingData = function () {
        try {
            // updateStatus_BudgetTimeAndScore();
            _user_details['lesson_status'] = _cMNo + '_' + _cPNo;
            let _uData = JSON.stringify(_user_details);
            _LS.setUserData(_uData);
            _LS.setCourseProgressData('course-data', _uData);
        } catch (err) {

        }
    }

    var updateScoreCourseLevel = function (isReset) {
        let _totalScore = 0;
        try {
            let _moduleList = _user_details['suspend_data'];
            $.each(_moduleList, function (mNo, cMList) {
                let _length = cMList.length;
                let _mStatusData = cMList[_length - 1];
                if (isReset) {
                    resetModuleLevelTracking(cMList);
                }
                _totalScore += parseInt(_mStatusData['sr'] || 0);
            })
        } catch (err) {

        }

        // _shell_wrapper.trigger('updateModuleScore', _totalScore);
        //  $("#score-points").html(_totalScore);

        try {
            let _percent = parseInt(_totalScore);
            _LS.setScore(_percent);
        } catch (err) {

        }
        return _totalScore;

    }

    var createSuspendData = function (callback) {

        let _pageList = {};
        let _pIndex = 0;

        _user_details['sts'] = 1;
        _user_details['cPNo'] = 1;
        _user_details['tPNo'] = 1;
        _user_details['vPNo'] = 0;
        _user_details['cProgress'] = 0;
        _user_details['badge'] = updatebadgearry;

        $.each(_modules, function (mNo) {
            let _mItem = $(this)[0]
            let _pages = _mItem['pages'];
            let _mNo = parseInt(mNo) + 1

            let __mItem = {
                'mNo': _mNo,
                'sts': 0,
                'cP': 1,
                // 'tT': "00:00:00",
                'sr': 0,
                // 'bT': _mItem['budgetedTime'] || "00:00:60",
                // 'mnsr': _mItem['mnsr'] || 100,
                // 'mxsr': _mItem['mxsr'] || -100
            }
            _pageList[_mNo] = [];

            // updateModuleStatus(_mNo, 0)

            $.each(_pages, function (pNo, page) {
                let _pItem = $(this)[0];
                let _pNo = parseInt(pNo) + 1;
                if(page['showInMenu'] =="mDisabled"){

                }else{
                    _pIndex++;
                }
                
                let __pItem = {
                    'pr': _mNo + '_' + _pNo,
                    'sts': 0,
                    'sr': 0,
                    'aD': {},
                    'badge': []
                }
                // __mItem['page'] = __pItem
                _pageList[_mNo].push(__pItem);
            })
            _pageList[_mNo].push(__mItem);
        })

        _user_details['tPNo'] = _pIndex;

        _user_details['suspend_data'] = _pageList;

        if (callback) {
            callback()
        }
    }


    var objectFindByKey = function (arr, key, value) {
        for (let i = 0; i < arr.length; i++) {
            if (arr[i][key] === value) {
                return arr[i];
            }
        }
        return null;
    }



    return this;
}