var ShellResources = function () {

    var _self = this;

    var _shell_wrapper = null;
    var _resource_wraper = null;
    var _parentIndex = -1;
    var _btn_close = null;

    this.init = function () {
        //  console.log("ShellResources:   init...")
        _shell_wrapper = $("#shell_wrapper");
        _resource_wraper = $("#resources_wraper");
        _parentIndex = parseInt(_resource_wraper.parent().attr('tabindex')) + 1 || -1;
        _btn_close = _resource_wraper.find(".close_btn")
        addEvents();
    }

    var addEvents = function () {
        //   console.log("ShellResources:   addEvents...")
        _btn_close.off("click").on("click", function () {
            _shell_wrapper.trigger("closeResources");
            var _data = {
                'popupName': 'Resources'
            }
            _shell_wrapper.trigger("closeResourcesGlobalPopup", _data);
            // $("#shell_wrapper").trigger("closeGlobalPopup"); 
        })

        _shell_wrapper.off("openResources").on("openResources", function (e) {
            e.stopPropagation();
            Utils.removeTabIndex()
            openResources();
        });

        _shell_wrapper.off("closeResources").on("closeResources", function (e) {
            e.stopPropagation();
            closeResources()
        });


    }


    var addTabIndex = function () {
        var _tabElements = {
            'elements': [{
                'selector': "#resources_popup_holder .modal-content"
            }, {
                'selector': ".modal-title"
            }, {
                'selector': "#resources_popup_holder .left-side",
                'alt': "A woman sitting on a chair using a laptop.",
                'aria-label': "A woman sitting on a chair using a laptop."
            },
            {
                'selector': "#resources_popup_holder ul li>a"
            },
            {
                'selector': _btn_close,
                'title': 'Close'
            },
            {
                'selector': '.uiClose',
                'aria-label': "Select the X to close this slide."
            }

            ],
            'sIndex': 1,
            'nIndex': 1
        };
        _shell_wrapper.trigger("addTabIndexing", _tabElements);
    }

    var openResources = function () {

        addTabIndex()

        let _resources_popup_holder = $("#resources_popup_holder .modal-content")

        let _lis_a = $("#resources_popup_holder ul li>a")

        _resources_popup_holder.trigger('focus');

        _btn_close.blur(function () {
            _resources_popup_holder.focus();
        })

        Utils.pauseTimer();
    }

    var closeResources = function () {
        //  Utils.addTabIndex();
        $("#shell_wrapper").trigger("closeGlobalPopup");
        //  Utils.resumeTimer();
    }

    return this;
};


$(document).ready(function () {
    var _shellResources = new ShellResources();
    _shellResources.init();
});