(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_8").hasClass("completed")) {
            let _data = {
                mNo: 1,
                pNo: 4
            }
            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 () {
        enabledDisable($(".btn_next"), false);
        Utils.updateAudio(_data.audio[0], lastStep)
    }

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

        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 () {
        //     alert("ok")
        //     btn.off("click");
        //     _shell_wrapper.trigger('jumpToNext');
        // }).addClass("active");
        Utils.pageCompleted();
        setTimeout(function () {
            enabledDisable($(".btn_next"), false);
        }, 200)


    }


    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 class='secTitle'>Meal Period Rounding</h6>
                        <ul class="setBox">
                            <li class='animate item_1'>
                                 Meal Period Rounding occurs when a time clock is set to round the time an employee clocks in or out for their meal break to a certain time. ​     
                            </li>
                            <li class='animate item_2'>
                                Under federal law, any "break" of less than 30 minutes is generally considered to be compensable time.  ​  
                            </li>
                            <li class='animate item_3'>
                                 Employbridge does not allow meal period rounding. It is strictly prohibited for companies in California.​
                            </li>
                        </ul>       
                    </div>
                    <div class='closebgtn'>Close</div>
                </div>
                `,
            id: 'm01_l03_p03_04',
            triggered_by: '',
            triggers: '',
            userDataRef: {
                currentPageNo: 9
            },
            audio: [{
                id: "1",
                autoplay: true,
                url: './views/m01_l03_p03_04/m01_l03_p03_04.mp3',
                timeline: [{
                    'element': "#sub-sections-1 .item_1",
                    'sTime': 0.5,
                    'eTime': '',
                    'classIn': 'd-show fadeInDown',
                    'classOut': ''
                },
                {
                    'element': "#sub-sections-1 .item_2",
                    'sTime': 64,
                    'eTime': '',
                    'classIn': 'd-show fadeInDown',
                    'classOut': ''
                },
                {
                    'element': "#sub-sections-1 .item_3",
                    'sTime': 91,
                    'eTime': '',
                    'classIn': 'd-show fadeInDown',
                    'classOut': ''
                }
                ],
                transcript: '<p><b>What is Meal Period Rounding?</b></p><p>As with other types of rounding, Meal Period Rounding occurs when a time clock is set to round the time an employee clocks in or out for their meal break to a certain time. There is no requirement that an employer pay for meal breaks as long as certain criteria are met: (1) minimum of 30 minutes and (2) the employee must be relieved of all duties during the full break. ​</p><p>Please note that some states, like California, mandate a 30-minute meal period after a certain number of hours worked. In California, an employee must receive a 30-minute break before the end of the fifth hour of work.</p><p>If an employer rounds unpaid meal periods to the nearest increment, it raises questions as to whether or not employees were allowed their full 30-minute unpaid meal break. If an employer cannot prove that employees received their full 30-minute meal break and that the employee was compensated for all time worked, the employer can be liable under both federal and state law.</p><p>Under federal law, any "break" of less than 30 minutes is generally considered to be compensable time. If an employee is only getting a 20-minute break, that time should be compensated. Likewise, if the system is automatically deducting 30 minutes for a meal period but an employee is only actually getting 20 minutes, this is also a violation of federal wage and hour law.</p><p>Employbridge does not allow meal period rounding. It is absolutely prohibited for companies in California.</p>'
            }]
        }];
        return _data;
    };

    var _shell_wrapper = $('#shell_wrapper');


    _shell_wrapper.trigger("initPage");

})();