var inspiniaHelper = (function() {
    
    function InspiniaHelper() {
        this.menuCollapseState = null; // expanded | collapsed
        this.isTouchDevice = null;
        this.pointer = {
            isMouse: false,
            isTouch: false
        };
    }

    InspiniaHelper.prototype.init = function () {
        this.handleTouchCapability();
        this.detectPointerType();
    };

    InspiniaHelper.prototype.collapseMainMenu = function(isUserAction) {
        if (!$('body').hasClass('mini-navbar')) {
                $('body').addClass('mini-navbar');
        }
        if (isUserAction) {
            this.cachedMenuCollapseState = 'collapsed';
        }
    };

    InspiniaHelper.prototype.expandMainMenu = function(cacheState) {
        if ($('body').hasClass('mini-navbar')) {
                $('body').removeClass('mini-navbar');
        }
        if (cacheState) {
            this.cachedMenuCollapseState = 'expanded';
        }
    };

    InspiniaHelper.prototype.toggleMainMenu = function(cacheState) {
        if ($('body').hasClass('mini-navbar')) {
            this.expandMainMenu(cacheState);
        }
        else {
            this.collapseMainMenu(cacheState);
        }
    };

    InspiniaHelper.prototype.handleTouchCapability = function() {
        this.isTouchDevice = ('ontouchstart' in window) || (navigator.maxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0);
        if (this.isTouchDevice && !$("body").hasClass("touch-device")) {
            $("body").addClass("touch-device");
        }
        else if (!this.isTouchDevice && $("body").hasClass("touch-device")) {
            $("body").removeClass("touch-device");
        }
    };

    InspiniaHelper.prototype.detectPointerType = function () {
        var self = this;
        $('body').get(0).addEventListener('pointerdown', (event) => {
            self.pointer.isMouse = false;
            self.pointer.isTouch = false;
            switch (event.pointerType) {
                case 'touch':
                case 'pen':
                    self.pointer.isTouch = true;
                    break;
                case 'mouse':
                default:
                    self.pointer.isMouse = true;
                    break;
            }
        });
    };


    return new InspiniaHelper();
})();