(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_4_5 class=page-link pTile tileShow cTile active completed data-ptile=m01_l03_p03 data-bgclass=undefined href=# data-ptileno=16 aria-hidden=true disabled=disabled><span>16</span></a>`;
 
        _shell_wrapper.trigger("custmsetPageStatus", [1, 5, mytitle, 2]);

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

    var lastStep = function () {
        let _data = {
            mNo: 5,
            pNo: 1
        }
        Utils.pageCompleted();

        enabledDisable(_btn_next, false);
        enabledDisable(_btn_prev, false);
_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_l03_p03_06/rightSide.png' class='img-fluid'> 
                    </div>

                </div>
                `,
            id: 'm01_l03_p03_06',
            triggered_by: '',
            triggers: '',
            userDataRef: {
                currentPageNo: 11
            },
            audio: [{
                id: "1",
                autoplay: true,
                url: './views/m01_l03_p03_06/m01_l03_p03_06.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");

})();