(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);

        _shell_wrapper.trigger('pageLoaded', _init_obj);
    }

    var lastStep = function () {

        enabledDisable(_btn_next, false);
        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_tab_2', function () {
            _activity_1_init();
        });
    }

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

        });
        if ($("#tree_pTile_1_4").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");
        }
        pageInit();
    }


    var getData = function (_userDetails) {
        var _data = [{
            section: "<div id='activity-holder'></div>",
            id: 'm01_l02_p03_01',
            userDataRef: {
                currentPageNo: 5
            },
            audio: [{
                id: "1",
                autoplay: true,
                url: './shell/audio/blank_2sec.mp3',
                timeline: [{
                    'element': ".pageInstruction",
                    'sTime': 0.5,
                    'eTime': '',
                    'classIn': 'd-show',
                    'classOut': ''
                }],
                transcript: ''
            },
            {
                id: "2",
                autoplay: true,
                url: './views/m01_l02_p03_01/m01_l02_p03_01_01.mp3',
                timeline: [],
                transcript: '<p><b>What does it mean?</b></p><p>Indemnification is a promise to defend a party against future claims or losses. It could be compared to our company agreeing to act as an insurer against future claims or losses, i.e. we will bear the costs. The provision is negotiable and the parties can agree what types of claims or losses will be covered. </p>'
            },
            {
                id: "3",
                autoplay: true,
                url: './views/m01_l02_p03_01/m01_l02_p03_01_02.mp3',
                timeline: [ {

                        'element': ".revealTxt .ol_list_1",

                        'sTime': 0.5,

                        'eTime': '',

                        'classIn': 'd-show fadeInDown',

                        'classOut': ''

                    },{

                        'element': ".revealTxt .ol_list_2",

                        'sTime': 72,

                        'eTime': '',

                        'classIn': 'd-show fadeInDown',

                        'classOut': ''

                    }],
                transcript: '<p><b>What is our potential exposure?</b></p> <ol><li>This will depend on how the indemnity is written:<ul class="disc"> <li>If we are asked to indemnify a client for the actions or inactions of Talent on assignment, this means we will have to reimburse the client for ANYTHING the Talent does or should have done.​</li> <li>If we are asked to indemnify a client for the negligence or willful misconduct of Talent on assignment, this means we will have to reimburse the client if the Talent accidentally or intentionally causes damage.</li> <li>If we are asked to indemnify a client for the gross negligence or willful misconduct of Talent on assignment, this means we would have to reimburse the client if the Talent knew or should have known their actions would cause harm (gross negligence), or if the Talent intentionally causes harm.  <ol class="a"> <li>This is our preferred standard. Why? <ul class="circle"> <li>Because the client is supervising the Talent and we are not there to prevent normal accidents, but we understand our obligation to the client if someone we send out intentionally or recklessly causes harm.​</li> <li>It is the same standard most clients would expect of their own employees. </li> </ul> </li> </ol>    </li> </ul> </li> <li>In addition, we ask clients to agree that we do not have to provide an indemnity if a claim arises due to the client\'s breach of the agreement, violation of law, or negligence or willful misconduct (the "Carve Out"). <ul> <li>This seems fair—why should we be responsible for the actions of the client or its personnel?</li> </ul> </li> </ol>'
            },
            {
                id: "4",
                autoplay: true,
                url: './views/m01_l02_p03_01/m01_l02_p03_01_03.mp3',
                timeline: [],
                transcript: '<p><b>How does it help you and your branch?</b></p><ul><li>Having a properly structured indemnity protects the branch\'s P&L and allows the branch to forecast for future costs correctly.</li> <li>It also provides clarity if there is an accident on a site as each party will understand who is responsible for the costs.</li> </ul>'
            }
            ]
        }];
        return _data;
    };

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