(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_5").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_02',
            userDataRef: {
                currentPageNo: 6
            },
            popupData: [
                {
                    id: "1",
                    description: "<h5 class='secTitle'>Additional Insured</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'>A client can file a claim on our insurance without our permission or knowledge.</li> <li  class='item-3'>A client can file a claim on our insurance even if it was their fault that the incident occurred.  </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>  </ul> </div>",
                    hasVideo: false
                },
                {
                    id: "2",
                    description: "<h5 class='secTitle'>Additional Insured</h5><div class='sub-sections' id='sub-sections-2'><div class='leftSide'><div class='midDesc'><b>Example 1</b><ul class='bulletlist'><li class='item-1-1'>A client employee and Employbridge Talent are involved in a forklift accident that caused injury to a third party.</li><li class='item-1-2'>The client employee was at fault and caused the incident. </li><li class='item-1-3'>If the client is granted additional insured status, our insurance could cover the claim, even if our Talent did not cause the incident.</li></ul></div></div><div class='rightSide'><div class='midDesc'><b>Example 2</b><ul class='bulletlist'><li class='item-2-1'>A client employee causes harm to Employbridge Talent. ​</li><li class='item-2-2'>The Talent files a lawsuit against the client. </li><li class='item-2-3'>If the client is granted additional insured status, our insurance could cover the claim and pay for the legal bills even though the client employee is the person who caused the harm.</li></ul></div></div></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_02/m01_l05_p03_02_01.mp3',
                    timeline: [{
                        'element': "#sub-sections-1 .item-1",
                        'sTime': 0.5,
                        'eTime': '',
                        'classIn': 'd-show',
                        'classOut': ''
                    },
                    {
                        'element': "#sub-sections-1 .item-2",
                        'sTime': 24,
                        'eTime': '',
                        'classIn': 'd-show',
                        'classOut': ''
                    },
                    {
                        'element': "#sub-sections-1 .item-3",
                        'sTime': 29,
                        'eTime': '',
                        'classIn': 'd-show',
                        'classOut': ''
                    },
                    {
                        'element': "#sub-sections-1 .item-4",
                        'sTime': 35,
                        'eTime': '',
                        'classIn': 'd-show',
                        'classOut': ''
                    }
                    ],
                    title: "",
                    description: "",
                    transcript: '<p>Clients occasionally request additional insured status for general liability. This is not something we want to grant. If we make a client an additional insured on our policy, this allows the client to make a claim under our policy, even if we were not at fault and we do not get to decide if we want to extend that coverage on a case-by-case basis.​</p><p><b>What does this mean for you?</b></p><ul><li>A client can file a claim on our insurance without our permission or knowledge.​</li><li>A client can file a claim on our insurance even if it was their fault that the incident occurred. </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></ul>'
                },
                {
                    id: "3",
                    autoplay: true,
                    url: './views/m01_l05_p03_02/m01_l05_p03_02_02.mp3',
                    timeline: [
                        {
                            'element': "#sub-sections-2 .item-1-1",
                            'sTime': 0.5,
                            'eTime': '',
                            'classIn': 'd-show',
                            'classOut': ''
                        },
                        {
                            'element': "#sub-sections-2 .item-1-2",
                            'sTime': 11,
                            'eTime': '',
                            'classIn': 'd-show',
                            'classOut': ''
                        },
                        {
                            'element': "#sub-sections-2 .item-1-3",
                            'sTime': 15,
                            'eTime': '',
                            'classIn': 'd-show',
                            'classOut': ''
                        },
                        {
                            'element': "#sub-sections-2 .item-2-1",
                            'sTime': 23,
                            'eTime': '',
                            'classIn': 'd-show',
                            'classOut': ''
                        },
                        {
                            'element': "#sub-sections-2 .item-2-2",
                            'sTime': 28,
                            'eTime': '',
                            'classIn': 'd-show',
                            'classOut': ''
                        },
                        {
                            'element': "#sub-sections-2 .item-2-3",
                            'sTime': 31,
                            'eTime': '',
                            'classIn': 'd-show',
                            'classOut': ''
                        }],
                    title: "",
                    description: "",
                    transcript: '<p>Let us look at some examples of how additional insured applies.</p><ul><li>A client employee and Employbridge Talent are involved in a forklift accident that caused injury to a third party. The client employee was at fault and caused the incident. If the client is granted additional insured status, our insurance covers the claim, even if our Talent did not cause the incident.</li><li>A client employee causes harm to Employbridge Talent. The Talent files a lawsuit against the client. If the client is granted additional insured status, our insurance covers the claim and pay for the legal bills even though the client employee is the person who caused the harm!</li></ul>'
                }
            ]
        }];
        return _data;
    };

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