(function () {

    var _shell_wrapper = null,
        _data = null,
        _userDetails = null,
        _shell_wrapper = $('#shell_wrapper');

    let _pageData = {
        'aD': {},
        'pr': "",
        'sr': 0,
        'sts': 0
    };

    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();
            _pageData = pageData || _pageData;
            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 () {
        clearTimeout(_timerInstance);
        _shell_wrapper.off("componentDidMount").on("componentDidMount", function (e) {
            e.stopPropagation();
            _activity_1();
        });

        Utils.loadTemplate('#templateHolder', 'simple_start', function () {
            Utils.log('simple_start: templateHolder')
            var _simple_start = new Simple_Start();
            _simple_start.init(getData(_userDetails));
        });

    }

    var pageInit = function () {
        clearTimeout(_timerInstance);
        let _init_obj = {
            'callback': function () {
                Utils.updateAudio(_data.audio[0], function () {
                    let _tabs = $(".text_model_style .tabclick");
                    _tabs.removeClass('disabled').addClass('active');

                    let _aD = _pageData['aD'];
                    $.each(_tabs, function (index, item) {
                        //  console.log(index, item, _aD[index+1]);
                        try {
                            if (_aD[index + 1]) {
                                //  $(item).addClass("visiteded");
                            }
                        } catch (err) {

                        }
                    })

                    lastStep();
                })
                addEvents();
            }
        }

        enabledDisable(_btn_next, false);
        enabledDisable(_btn_prev, false);
        if ($("#tree_pTile_1_6").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', _init_obj);
    }

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

        enabledDisable(_btn_next, false);
        enabledDisable(_btn_prev, false);

        let btn = $(".closebgtn");
        btn.off("click").on("click", function () {
            btn.off("click");
            _shell_wrapper.trigger("gotoModule", _data)
        })

        Utils.pageCompleted();
        setTimeout(function () {
            enabledDisable($(".btn_next"), false);
        }, 200)


    }

    var addEvents = function () {
        _shell_wrapper.off("tabClicked").on("tabClicked", function (e, data) {
            let _aD = _pageData['aD'];
            _aD[data.qNo] = data.r;
            _shell_wrapper.trigger("setActivityData", _pageData);
        });
    }

    var _activity_1 = function () {
        Utils.loadTemplate('#activity-holder', 'simple_next_back', function () {
            _activity_1_init();
        });
    }

    var _activity_1_init = function () {
        var _activity = new init_activity();
        _activity.init(_data, function () {

        });
        pageInit();
    }


    var getData = function (_userDetails) {
        var _data = [{
            section: "<div id='activity-holder'></div>",
            id: 'm01_l05_p03_03',
            userDataRef: {
                currentPageNo: 7
            },
            popupData: [
                {
                    id: "1",
                    description: "<h5 class='secTitle'>Waiver of Subrogation</h5><div class='sub-sections' id='sub-sections-1'><p class='item-1'>What does this mean for you?</p><ul class='bulletlist'><li class='item-2'>Even if the client is at fault, our insurance company cannot recoup costs from the client's insurance company.​</li><li class='item-3'>We are taking on the risk from the client.</li><li class='item-4'>We have a $500,000 deductible on our General Liability policy. This means that any cost up to $500,000 will be paid for by the branch.​</li><li class='item-5'>We have a $2,000,000 deductible on our Workers Compensation policy. This will affect your WC modifier and rates for current and future business.​</li></ul></div>",
                    hasVideo: false
                },
                {
                    id: "2",
                    description: "<h5 class='secTitle'>Waiver of Subrogation</h5><div class='sub-sections' id='sub-sections-2'><p class='bold item-2-1'>Example 1:</p><p class='item-2-2'>A client employee injures Employbridge Talent. With a waiver of subrogation, our workers compensation insurance policy pays for the entire claim. Without a waiver of subrogation, our workers compensation insurance can subrogate against the client's insurance to pay for part of the claim. This would reduce the branch's claims costs.​</p><p class='bold item-2-3'>Example 2:</p><p  class='item-2-4'>A client directs Employbridge Talent to a task, resulting in injury or property damage to a third party. With a waiver of subrogation, our general liability insurance policy pays for the entire claim, even though the client was the one who directed our Talent to do the task. With a waiver of subrogation, our general liability insurance can subrogate against the client's insurance to pay for part of the claim. This will directly impact the branch's P&L.​</p></div>",
                    hasVideo: false
                }
            ],
            audio: [
                {
                    id: "1",
                    autoplay: true,
                    url: './shell/audio/blank.mp3',
                    timeline: [{
                        'element': ".pageInstruction",
                        'sTime': 4,
                        'eTime': '',
                        'classIn': 'd-show',
                        'classOut': ''
                    }],
                    title: "",
                    description: "",
                    transcript: ''
                },
                {
                    id: "2",
                    autoplay: true,
                    url: './views/m01_l05_p03_03/m01_l05_p03_03_01.mp3',
                    timeline: [{
                        'element': "#sub-sections-1 .item-1",
                        'sTime': 0.5,
                        'eTime': '',
                        'classIn': 'd-show',
                        'classOut': ''
                    },
                    {
                        'element': "#sub-sections-1 .item-2",
                        'sTime': 15,
                        'eTime': '',
                        'classIn': 'd-show',
                        'classOut': ''
                    },
                    {
                        'element': "#sub-sections-1 .item-3",
                        'sTime': 22,
                        'eTime': '',
                        'classIn': 'd-show',
                        'classOut': ''
                    },
                    {
                        'element': "#sub-sections-1 .item-4",
                        'sTime': 25,
                        'eTime': '',
                        'classIn': 'd-show',
                        'classOut': ''
                    },
                    {
                        'element': "#sub-sections-1 .item-5",
                        'sTime': 35,
                        'eTime': '',
                        'classIn': 'd-show',
                        'classOut': ''
                    }
                    ],
                    title: "",
                    description: "",
                    transcript: '<p>Waiver of subrogation means that our insurance company cannot try to recover damages from a liable third party. This is most often requested for Workers Compensation and General Liability by clients. ​ </p><p><b>What does this mean for you?</b></p><ul><li>Even if the client is at fault, our insurance company cannot recoup costs from the client\'s insurance company.</li><li>We are taking on the risk from the client.</li><li>We have a $500,000 deductible on our General Liability policy. This means that any cost up to $500,000 will be paid for by the branch.</li><li>We have a $2,000,000 deductible on our Workers Compensation policy. This will affect your WC modifier and rates for current and future business.</li></ul>'
                },
                {
                    id: "3",
                    autoplay: true,
                    url: './views/m01_l05_p03_03/m01_l05_p03_03_02.mp3',
                    timeline: [
                        {
                            'element': "#sub-sections-2 .item-2-1",
                            'sTime': 0.5,
                            'eTime': '',
                            'classIn': 'd-show',
                            'classOut': ''
                        },
                        {
                            'element': "#sub-sections-2 .item-2-2",
                            'sTime': 4,
                            'eTime': '',
                            'classIn': 'd-show',
                            'classOut': ''
                        },
                        {
                            'element': "#sub-sections-2 .item-2-3",
                            'sTime': 28,
                            'eTime': '',
                            'classIn': 'd-show',
                            'classOut': ''
                        },
                        {
                            'element': "#sub-sections-2 .item-2-4",
                            'sTime': 29,
                            'eTime': '',
                            'classIn': 'd-show',
                            'classOut': ''
                        }],
                    title: "",
                    description: "",
                    transcript: '<p>Let us look at some examples of how waiver of subrogation applies.</p><ul><li>A client employee injures Employbridge Talent. With a waiver of subrogation, our workers compensation insurance policy pays for the entire claim. Without a waiver of subrogation, our workers compensation insurance can subrogate against the client\'s insurance to pay for part of the claim. This would reduce the branch\'s claims costs. </li><li>A client directs Employbridge Talent to a task, resulting in injury or property damage to a third party. With a waiver of subrogation, our general liability insurance policy pays for the entire claim, even though the client was the one who directed our Talent to do the task. With a waiver of subrogation, our general liability insurance can subrogate against the client\'s insurance to pay for part of the claim. This will directly impact the branch\'s P&L.</li></ul>'
                }
            ]
        }];
        return _data;
    };

    _shell_wrapper.trigger("initPage");
})();