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

        /*if(_modules[_cMNo - 1]['showInMenu'] =="mDisabled"){
             
        }else{

        }*/

    }

    var stepStart = function () {
        enabledDisable($(".btn_next"), false);
        Utils.updateAudio(_data.audio[0], lastStep)
    }

    var lastStep = function () {
        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();
        setTimeout(function(){
            enabledDisable($(".btn_next"), false);
        },200)
        enabledDisable(_btn_next, false);

    }


    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'>
                        <ul class="setBox">
                            <li class='animate item_1'>
                                <p class="titleBox">What does it mean?</p>
                                <p class="desc">A limitation of liability caps a company's exposure in lawsuits or claims.​</p>
                            </li>
                            <li class='animate item_2'>
                                <p class="titleBox">What is our potential exposure?</p>
                                <p class="desc">Without a limitation of liability, our exposure could be unlimited, as we would not have any limitation on any liability.</p>
                            </li>
                            <li class='animate item_3'>
                                <p class="titleBox">How does it help you and your branch?</p>
                                <p class="desc">A limitation of liability caps potential payouts for claims, protecting the branch's P&L and enabling allocation for potential liabilities.​</p>
                            </li>
                        </ul>       
                    </div>
                    <div class='closebgtn'>Close</div>
                </div>
                `,
            id: 'm01_l01_p07_01',
            disableNav: true,
            triggered_by: '',
            triggers: '',
            userDataRef: {
                currentPageNo: 5
            },
            audio: [{
                id: "1",
                autoplay: true,
                url: './views/m01_l01_p07_01/m01_l01_p07_01.mp3',
                timeline: [{
                        'element': ".blueBox",
                        'sTime': 0.2,
                        'eTime': '',
                        'classIn': 'blueUp',
                        'classOut': ''
                    },{
                        'element': "#sub-sections-1 .item_1",
                        'sTime': 0.5,
                        'eTime': '',
                        'classIn': 'd-show fadeInLeft',
                        'classOut': ''
                    },
                    {
                        'element': "#sub-sections-1 .item_2",
                        'sTime': 11.5,
                        'eTime': '',
                        'classIn': 'd-show fadeInLeft',
                        'classOut': ''
                    },
                    {
                        'element': "#sub-sections-1 .item_3",
                        'sTime': 22,
                        'eTime': '',
                        'classIn': 'd-show fadeInLeft',
                        'classOut': ''
                    }
                ],
                transcript: '<p><b>What does limitation of liability mean?</b></p><p>It is a contractual provision that limits the amount of exposure a company faces in the event a lawsuit is filed, or a claim is made against the company.​</p> <p><b>What is our potential exposure?</b> </p> <p>Without a limitation of liability, our exposure could be unlimited, as we would not have any limitation on any liability.</p> <p><b>How does limitation of liability help you and your branch?</b></p> <ul> <li>If a limitation of liability is included, it caps the potential amount that could be paid to resolve a client or third-party claim.</li> <li>This protects the branch\'s P&L and allows the branch to set aside the potential amount if a claim is made.</li></ul>'
            }]
        }];
        return _data;
    };

    var _shell_wrapper = $('#shell_wrapper');


    _shell_wrapper.trigger("initPage");

})();