(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);
        if ($("#tree_pTile_1_4").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");
        }

        _shell_wrapper.trigger('pageLoaded', _initData);

    }

    var stepStart = function () {
        Utils.updateAudio(_data.audio[0], lastStep)
    }

    var lastStep = function () {

        let _data = {
            mNo: 1,
            pNo: 3
        }

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

        let btn = $(".closebgtn");
        // btn.addClass("d-show")
        btn.off("click").on("click", function () {
            btn.off("click");
            _shell_wrapper.trigger("gotoModule", _data)
        }).addClass("active");


        // let btn = $("#continue-btn");
        // btn.addClass("d-show")
        // btn.off("click").on("click", function () {
        //     btn.off("click");
        //     _shell_wrapper.trigger('jumpToNext');
        // }).addClass("active");
        Utils.pageCompleted();
    }


    var getData = function (_userDetails) {
        var _data = [{
            section: `
                <h2 class="pagetitle subPageTitle">The Limitation of Liabilities Room</h2>
                <div class = 'sub-sections blueBox' id = 'sub-sections-1'>
                    <span class="iconMark"> </span>
                    <div class='midDesc'>
                        <h6>What is liability insurance?</h6>
                        <p class='bold item_0'>Types of liability insurance policies are:</p>
                        <ul>
                            <li class='item_1'>General Liability</li>
                            <li class='item_2'>Automobile Liability​</li>
                            <li class='item_3'>Employers Liability</li>
                            <li class='item_4'>Umbrella/Excess Liability </li>
                        </ul>
                        <p class='item_5'>These policies provide coverage for claims made by third parties for bodily injury and/or property
damage, resulting from an accident or occurrence for which Employbridge is legally liable.​</p>     
                    </div>
                    <div class='closebgtn'>Close</div>
                </div>
                `,
            id: 'm01_l05_p03_01',
            triggered_by: '',
            triggers: '',
            userDataRef: {
                currentPageNo: 5
            },
            audio: [{
                id: "1",
                autoplay: true,
                url: './views/m01_l05_p03_01/m01_l05_p03_01.mp3',
                timeline: [{
                    'element': "#sub-sections-1 .item_0",
                    'sTime': 9,
                    'eTime': '',
                    'classIn': 'd-show fadeInLeft',
                    'classOut': ''
                }, {
                    'element': "#sub-sections-1 .item_1",
                    'sTime': 13,
                    'eTime': '',
                    'classIn': 'd-show fadeInLeft',
                    'classOut': ''
                }, {
                    'element': "#sub-sections-1 .item_2",
                    'sTime': 14.5,
                    'eTime': '',
                    'classIn': 'd-show fadeInLeft',
                    'classOut': ''
                }, {
                    'element': "#sub-sections-1 .item_3",
                    'sTime': 16.5,
                    'eTime': '',
                    'classIn': 'd-show fadeInLeft',
                    'classOut': ''
                }, {
                    'element': "#sub-sections-1 .item_4",
                    'sTime': 18,
                    'eTime': '',
                    'classIn': 'd-show fadeInLeft',
                    'classOut': ''
                }, {
                    'element': "#sub-sections-1 .item_5",
                    'sTime': 21,
                    'eTime': '',
                    'classIn': 'd-show fadeInLeft',
                    'classOut': ''
                },
                ],
                transcript: '<p><b>What is liability insurance?​</b></p><p>Liability insurance comprises a variety of different insurance policies, which cover operational risks. Examples of the types of liability insurance policies are:</p><ul><li>General Liability</li><li>Automobile Liability</li><li>Employers Liability</li><li>Umbrella/Excess Liability </li></ul><p>In general, these policies provide coverage for claims made by third parties for bodily injury and/or property damage, resulting from an accident or occurrence for which Employbridge is legally liable.​</p>'
            }]
        }];
        return _data;
    };

    var _shell_wrapper = $('#shell_wrapper');


    _shell_wrapper.trigger("initPage");

})();