(function () {

    var _shell_wrapper = null,
        _data = null,
        _userDetails = null,
        _shell_wrapper = $('#shell_wrapper');

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

    _shell_wrapper.off("initPage").on("initPage", function (e) {
        _shell_wrapper.off("initPage");
        _shell_wrapper.off("takePageDetails").on("takePageDetails", function (e, pageData) {
            e.stopPropagation();
            updateDom();
        });

        _shell_wrapper.off("sentUserDetails").on("sentUserDetails", function (e, userData) {
            e.stopPropagation();
            _userDetails = userData;
            _data = getData(_userDetails)[0];
            _shell_wrapper.trigger('getPageDetails', _data.userDataRef.currentPageNo);
        });

        _shell_wrapper.trigger('getUserDetails');

    });

    var updateDom = function () {
        _shell_wrapper.off("componentDidMount").on("componentDidMount", function (e) {
            e.stopPropagation();
            pageInit();
        });

        Utils.loadTemplate('#templateHolder', 'simple_start', function () {
            var _simple_start = new Simple_Start();
            _simple_start.init(getData(_userDetails));
        });
    }


    var pageInit = function () {

        //    console.log("pageInit")
        $(".fadeInUpPage").addClass("pageAnim");

        let _initData = {
            'callback': function () {
                clearTimeout(_timerInstance);
                _shell_wrapper.off("clearAlertTimerInstance").on("clearAlertTimerInstance", function (e) {
                    clearTimeout(_timerInstance);
                    _shell_wrapper.off("clearAlertTimerInstance");
                });

                stepStart();

            }
        }

        enabledDisable(_btn_next, false);
        enabledDisable(_btn_prev, false);

        _shell_wrapper.trigger('pageLoaded', _initData);

    }

    var stepStart = function () {
        var mytitle = `<a id=pTile_5_4 class=page-link pTile tileShow cTile active completed data-ptile=m01_l04_p03 data-bgclass=undefined href=# data-ptileno=19 aria-hidden=true disabled=disabled><span>19</span></a>`;

        _shell_wrapper.trigger("custmsetPageStatus", [5, 4, mytitle, 2]);


        enabledDisable($(".btn_next"), false);
        Utils.updateAudio(_data.audio[0], lastStep)
    }

    var lastStep = function () {
        let _data = {
            mNo: 6,
            pNo: 1
        }

        enabledDisable(_btn_next, false);
        enabledDisable(_btn_prev, false);
        if ($("#tree_pTile_1_8").hasClass("completed")) {
            let _data = {
                mNo: 1,
                pNo: 3
            }
            let btn = $(".closebgtn");
            btn.off("click").on("click", function () {
                btn.off("click");
                _shell_wrapper.trigger("gotoModule", _data)
            }).addClass("active");
        }
        Utils.pageCompleted();
        _shell_wrapper.trigger("moduleCompleted");
        // _shell_wrapper.trigger("gotoModule", _data)


    }


    var getData = function (_userDetails) {
        var _data = [{
            section: `
                <h2 class='pagetitle d-hide'>Learning Objctives</h2>
               <div class = 'sub-sections blueBox' id = 'sub-sections-1'>
                    <div class='leftSide'>
                        <h3 class="cong_title">Congratulations!!!</h3>
                        <h3 class="cong_txt">You have completed this unit.</h3>
                    </div>
                    <div class='rightSide'>
                        <img src='./views/m01_l05_p03_05/rightSide.png' class='img-fluid'> 
                    </div>

                </div>
                `,
            id: 'm01_l05_p03_05',
            triggered_by: '',
            triggers: '',
            userDataRef: {
                currentPageNo: 9
            },
            audio: [{
                id: "1",
                autoplay: true,
                url: './views/m01_l05_p03_05/m01_l05_p03_05.mp3',
                timeline: [
                ],
                transcript: '<p>Congratulations!!! You have completed this unit.</p><p>If you have questions about this training, please contact the email IDs provided in the Resources section of this course.</p><p>If you have any feedback or suggestions regarding this training, please email <u>legal@employbridge.com</u></p>'
            }]
        }];
        return _data;
    };

    var _shell_wrapper = $('#shell_wrapper');


    _shell_wrapper.trigger("initPage");

})();