(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();

            }
        }

        _shell_wrapper.trigger('pageLoaded', _initData);
        enabledDisable(_btn_next, false);
        enabledDisable(_btn_prev, false);
    }

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

    var lastStep = function () {

        let _data = {
            mNo: 1,
            pNo: 3
        }
        
        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");
        enabledDisable(_btn_next, false);
        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'>
                        <h5>Sample Language Specifying the Limitation of Liability Clause</h5>
                        <div class='paperBG'>
                            <img src='./views/m01_l01_p07_02/paperBG2X.png' class='paperImg '>
                            <p>NOTWITHSTANDING ANYTHING TO THE CONTRARY WITHIN THIS​ AGREEMENT, THE ENTIRE LIABILITY OF VENDOR UNDER THIS​ AGREEMENT, OR ANY MATTER RELATING TO THIS AGREEMENT,​ REGARDLESS OF THE FORM OF ANY CLAIM OR ACTION OR THEORY OF​ LIABILITY (INCLUDING, BUT NOT LIMITED TO CONTRACT, TORT OR​ WARRANTY) SHALL BE LIMITED TO DIRECT DAMAGES NOT TO EXCEED​ THE LESSER OF: (1) THE TOTAL AMOUNTS PAID BY CLIENT TO VENDOR​ HEREUNDER DURING THE SIX-MONTH PERIOD PRIOR TO THE​ APPLICABLE CLAIM; OR (2) ONE MILLION DOLLARS ($1,000,000.00).</p>
                        </div>     
                    </div>
                    <div class='closebgtn'>Close</div>
                </div>
                `,
            id: 'm01_l01_p07_02',
            triggered_by: '',
            triggers: '',
            userDataRef: {
                currentPageNo: 3
            },
            audio: [{
                id: "1",
                autoplay: true,
                url: './views/m01_l01_p07_02/m01_l01_p07_02.mp3',
                timeline: [
                    {
                        'element': ".blueBox",
                        'sTime': 0.2,
                        'eTime': '',
                        'classIn': 'blueUp',
                        'classOut': ''
                    }
                ],
                transcript: '<p>Here is a sample language specifying the limitation of liability clause.</p>'
            }]
        }];
        return _data;
    };

    var _shell_wrapper = $('#shell_wrapper');


    _shell_wrapper.trigger("initPage");

})();