(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")) {
            // alert()

            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 class='item_0'>Alternate Employer</h6>
                        <ul>
                            <li class='item_1'>Additional Insured status does not apply to Workers’ Compensation and Employer’s Liability, instead, a client can ask to be included as an Alternate Employer on these policies.​</li>
                            <li class='item_2'>What does this mean for you?
                                <ul>
                                    <li class='item_3'>This gives the client the same coverage under our Workers’ Compensation and Employer’s Liability policy as us. </li> 
                                    <li class='item_4'>Even if the client is at fault for an employee’s injury, the employee cannot sue our client directly because of Exclusive Remedy protections. Instead, the client would be covered by our Employers’ Liability policy.​</li>
                                </ul>
                            </li>
                            <li class='item_5'><b>Example</b><br>
                                A client knowingly has Employbridge Talent operate a piece of faulty equipment. The Talent is injured due to the faulty equipment. The Talent’s medical costs are covered under our Workers’ Compensation policy. The Talent attempts to file a lawsuit against the client claiming negligence. If the client is included under our policy as an alternate employer, our insurance covers not only the medical costs, but also the lawsuit against the client including any legal bills and settlements even though the client provided the faulty equipment.​</li>
                        </ul>
                        <p class='item_6'><b>Note: In the U.S. punitive damages are not covered by insurance. Any punitive damages will be paid for by the branch.<b>​</p>
                          
                    </div>
                    <div class='closebgtn'>Close</div>
                </div>
                `,
            id: 'm01_l05_p03_07',
            triggered_by: '',
            triggers: '',
            userDataRef: {
                currentPageNo: 9
            },
            audio: [{
                id: "1",
                autoplay: true,
                url: './views/m01_l05_p03_07/m01_l05_p03_07.mp3',
                timeline: [{
                    'element': "#sub-sections-1 .item_0",
                    'sTime': 0,
                    'eTime': '',
                    'classIn': 'd-show ',
                    'classOut': ''
                }, {
                    'element': "#sub-sections-1 .item_1",
                    'sTime': 0.5,
                    'eTime': '',
                    'classIn': 'd-show ',
                    'classOut': ''
                }, {
                    'element': "#sub-sections-1 .item_2",
                    'sTime': 12,
                    'eTime': '',
                    'classIn': 'd-show ',
                    'classOut': ''
                }, {
                    'element': "#sub-sections-1 .item_3",
                    'sTime': 14,
                    'eTime': '',
                    'classIn': 'd-show ',
                    'classOut': ''
                }, {
                    'element': "#sub-sections-1 .item_4",
                    'sTime': 22,
                    'eTime': '',
                    'classIn': 'd-show ',
                    'classOut': ''
                }, {
                    'element': "#sub-sections-1 .item_5",
                    'sTime': 37,
                    'eTime': '',
                    'classIn': 'd-show ',
                    'classOut': ''
                }, {
                    'element': "#sub-sections-1 .item_6",
                    'sTime': 76,
                    'eTime': '',
                    'classIn': 'd-show ',
                    'classOut': ''
                }

                ],
                transcript: '<p>Additional Insured status does not apply to Workers’ Compensation and Employer’s Liability policies. However, a client can request to be included as an Alternate Employer on these policies.​</p> <p><b>So, what does this mean for you?</b></p><p>It means the client receives the same coverage under our Workers’ Compensation and Employer’s Liability policies as we do. Even if the client is at fault for an employee’s injury, the employee cannot sue the client directly, thanks to Exclusive Remedy protections. Instead, the client would be covered under our Employers’ Liability policy.​</p><p>Let us look at an example now.</p><p>A client knowingly allows Employbridge Talent to operate faulty equipment, resulting in an injury. The injured worker’s medical expenses are covered by our Workers’ Compensation policy.</p><p>If the worker then files a lawsuit against the client, claiming negligence, the outcome depends on the client’s status under our policy. If the client is listed as an Alternate Employer, our insurance doesn’t just cover the medical costs—it also covers the lawsuit itself, including legal fees and any settlements, even though the client was responsible for providing the faulty equipment.​</p>'
            }]
        }];
        return _data;
    };

    var _shell_wrapper = $('#shell_wrapper');


    _shell_wrapper.trigger("initPage");

})();