var TopicList = function () {
    let _self = this;
    let _topic_list_wrapper = null;
    let _shell_wrapper = $("#shell_wrapper");
    this.init = function () {
        // console.log("TopicList:   init...");
        _topic_list_wrapper = $("#topic_list_wrapper");
        setTimeout(function () {
            //updateModuleStatus();
            addEvents();
        }, 300)
    }


    var updateModuleStatus = function () {
        let _menus = $(".topic_list .mTile")
        _menus.removeClass("active").addClass("not_attempted").removeClass("inprogress").removeClass("completed").removeClass("cMNo")

        let _moduleDetails = window['course']['data']['shellController'].getModulesDetails();
        console.log("---_moduleDetails"+JSON.stringify(_moduleDetails, null, 2));
        setTimeout(function () {
            $.each(_moduleDetails, function (i, module) {
                console.log("--i"+i)
                let mItem = $(".topic_list #topic_" + (i + 1));
                mItem.removeClass("active");
                console.log("---mItem"+mItem)
                if (module.status >= 1) {
                    mItem.addClass("active");
                    console.log("---module.status"+module.status)
                }
                mItem.removeClass("not_attempted").addClass(module.sClass);
                console.log("-----module.sClass"+module.sClass)
                console.log(module.mNo+"-----"+module.cMNo);
                if (module.mNo == module.cMNo) {
                    mItem.addClass(module.cMNo);
                }

            })
        }, 30)


    }

    var addEvents = function () {
        console.log("------")
       
        if ($("#tree_pTile_1_4").hasClass("completed") &&
            $("#tree_pTile_1_5").hasClass("completed") &&
            $("#tree_pTile_1_6").hasClass("completed")) {
                $("#topic_5").removeClass("not_attempted").addClass("active")
        }
        if ($("#tree_pTile_1_4").hasClass("completed")){
            $("#topic_2").addClass("completed")
        }
        if ($("#tree_pTile_1_5").hasClass("completed")){
            $("#topic_3").addClass("completed")
        }
        if ($("#tree_pTile_1_6").hasClass("completed")){
            $("#topic_4").addClass("completed")
        }
        if ($("#tree_pTile_1_7").hasClass("completed")){
            //$("#topic_5").addClass("completed")
        }

        var gotoPage;
        setTimeout(function () {
            $(".topic_list_p4 .mTile").off("click").on("click", function () {
                //let _tNo = parseInt($(this).attr("id").split("_")[1]) || 1;
                let _tNo = Number($(this).attr("num"));
                
                switch(_tNo) {
                    case 1:
                    gotoPage = "m01_l04_p03_01";
                      break;
                    case 2:
                    gotoPage = "m01_l04_p03_02";
                      break;
                      case 3:
                    gotoPage = "m01_l04_p03_03";
                      break;
                      case 4:
                    gotoPage = "m01_l04_p03_04";
                      break;
                  }

                let _data = {
                    mNo: _tNo,
                    pNo: 5
                }
                // $("#tree_pTil_" + mNo + "_2").trigger("click")
                //_shell_wrapper.trigger("gotoModule", _data)
                _shell_wrapper.trigger('jumpToPage', gotoPage);
            })
        }, 300)
    }
    return this;
};

