(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_7").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  class='item_0'>Workers’ Compensation & Employer’s Liability​</h6>
                        
                        <ul>    
                            <li class='item_1'>Workers’ Compensation 
                                <ul class='subList'>
                                    <li class='item_2'>Provides benefits to injured employees.</li>
                                    <li class='item_3'>Covers medical expenses and lost wages.</li>
                                </ul>
                            </li>

                            <li class='item_4'>Employer’s Liability
                                <ul class='subList'>
                                    <li class='item_5'>Provides coverage to Employbridge for lawsuits filed by injured employees
claiming that the injury was caused by Employbridge’s negligence.​</li>
                                    <li class='item_6'>Covers legal costs and settlement agreements.</li>
                                </ul>
                            </li>
                        </ul>
                          
                    </div>
                    <div class='closebgtn'>Close</div>
                </div>
                `,
            id: 'm01_l05_p03_06',
            triggered_by: '',
            triggers: '',
            userDataRef: {
                currentPageNo: 8
            },
            audio: [{
                id: "1",
                autoplay: true,
                url: './views/m01_l05_p03_06/m01_l05_p03_06.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': 1,
                    'eTime': '',
                    'classIn': 'd-show ',
                    'classOut': ''
                }, {
                    'element': "#sub-sections-1 .item_3",
                    'sTime': 5,
                    'eTime': '',
                    'classIn': 'd-show ',
                    'classOut': ''
                }, {
                    'element': "#sub-sections-1 .item_4",
                    'sTime': 11,
                    'eTime': '',
                    'classIn': 'd-show ',
                    'classOut': ''
                }, {
                    'element': "#sub-sections-1 .item_5",
                    'sTime': 14,
                    'eTime': '',
                    'classIn': 'd-show ',
                    'classOut': ''
                }, {
                    'element': "#sub-sections-1 .item_6",
                    'sTime': 24,
                    'eTime': '',
                    'classIn': 'd-show ',
                    'classOut': ''
                },
                ],
                transcript: '<p>Workers’ Compensation provides essential benefits to employees who are injured on the job. This includes coverage for medical expenses and compensation for lost wages during recovery.​</p> <p>In addition, Employer’s Liability offers protection to Employbridge in the event of a lawsuit. If an injured employee claims their injury resulted from the company\'s negligence, this coverage helps pay for legal defense costs and any resulting settlements.​</p>'
            }]
        }];
        return _data;
    };

    var _shell_wrapper = $('#shell_wrapper');


    _shell_wrapper.trigger("initPage");

})();