var AjaxMethod;
(function (AjaxMethod) {
    AjaxMethod["POST"] = "POST";
    AjaxMethod["GET"] = "GET";
})(AjaxMethod || (AjaxMethod = {}));
var AjaxOptions = (function () {
    function AjaxOptions(fileds) {
        if (fileds) {
            Object.assign(this, fileds);
        }
    }
    return AjaxOptions;
}());
var AjaxService = (function () {
    function AjaxService() {
    }
    AjaxService.prototype.send = function (options) {
        var that = this;
        var call = $.ajax({
            url: options.url,
            type: options.method,
            data: options.data,
            success: function (d) {
                if (options.callback) {
                    options.callback(d);
                }
                if (options.successMsg) {
                    DevExpress.ui.notify(options.successMsg, "success", 5000);
                }
            },
            error: function (d) {
                if (options.errorCallback) {
                    options.errorCallback(d);
                }
                if (options.errorMsg) {
                    DevExpress.ui.notify(options.errorMsg, "error", 5000);
                }
            }
        });
        return call;
    };
    return AjaxService;
}());

var BaseView = (function () {
    function BaseView() {
        this.BindLayoutMenu();
        this.LogDbCallsErrors();
    }
    BaseView.prototype.BindLayoutMenu = function () {
        if (document.location.href.indexOf('Scheduler') <= -1 && (document.location.href.indexOf('Reports') > -1 || document.location.href.indexOf('Visualize') > -1)) {
            $('#reportsMenuDx').addClass('active');
            $('#usersMenuDx').removeClass('active');
            $('#logsMenuDx').removeClass('active');
            if (this.IsDefined($('#scheduleMenuDx'))) {
                $('#scheduleMenuDx').removeClass('active');
            }
        }
        else if (document.location.href.indexOf('Management') > -1 ||
            document.location.href.indexOf('ConnectionProfiles') > -1 ||
            document.location.href.indexOf('Settings') > -1) {
            $('#reportsMenuDx').removeClass('active');
            $('#usersMenuDx').addClass('active');
            $('#logsMenuDx').removeClass('active');
            if (this.IsDefined($('#scheduleMenuDx'))) {
                $('#scheduleMenuDx').removeClass('active');
            }
        }
        else if (document.location.href.indexOf('Logs') > -1) {
            $('#reportsMenuDx').removeClass('active');
            $('#usersMenuDx').removeClass('active');
            $('#logsMenuDx').addClass('active');
            if (this.IsDefined($('#scheduleMenuDx'))) {
                $('#scheduleMenuDx').removeClass('active');
            }
        }
        else if (document.location.href.indexOf('Scheduler') > -1) {
            $('#reportsMenuDx').removeClass('active');
            $('#usersMenuDx').removeClass('active');
            $('#logsMenuDx').removeClass('active');
            if (this.IsDefined($('#scheduleMenuDx'))) {
                $('#scheduleMenuDx').addClass('active');
            }
        }
        $('#reportsMenuDx').on("click", function (e) {
            document.location.href = "/Reports/Index";
        });
        $('#usersMenuDx').on("click", function (e) {
            document.location.href = "/Management/Index";
        });
        $('#logsMenuDx').on("click", function (e) {
            document.location.href = "/Logs/Index";
        });
        if (this.IsDefined($('#scheduleMenuDx'))) {
            $('#scheduleMenuDx').on("click", function (e) {
                document.location.href = "/Reports/Scheduler";
            });
        }
    };
    BaseView.prototype.IsNotEmpty = function (obj) {
        return this.IsDefined(obj) && obj !== "" && obj !== " ";
    };
    BaseView.prototype.IsDefined = function (obj) {
        return typeof obj !== 'undefined' && obj !== null;
    };
    BaseView.prototype.LogDbCallsErrors = function () {
        var that = this;
        DevExpress.data.setErrorHandler(function (error) {
            that.StatusCheck().done(function () {
                DevExpress.ui.notify("Error occured: " + error.message, "error", 5500);
            });
        });
    };
    BaseView.prototype.StatusCheck = function () {
        return $.ajax({
            url: '/Visualize/StatusCheck',
            type: "GET",
            statusCode: {
                401: function () {
                    window.location.reload();
                }
            }
        });
    };
    BaseView.prototype.LogError = function (msg, time, height) {
        DevExpress.ui.notify({ message: msg, height: height }, "error", time != null ? time : 5500);
    };
    BaseView.prototype.Info = function (msg, time, height) {
        DevExpress.ui.notify({ message: msg, height: height }, "info", this.IsDefined(time) ? time : 5500);
    };
    BaseView.prototype.Loading = function (text) {
        var loadingPanel = $('#wrLoadingPanel').dxLoadPanel("instance");
        return loadingPanel;
    };
    BaseView.prototype.IsMobile = function () {
        var currentWidth = $(window).width();
        return currentWidth < 992;
    };
    return BaseView;
}());
document.addEventListener("DOMContentLoaded", function documentReady() {
    this.removeEventListener("DOMContentLoaded", documentReady);
    var view = new BaseView();
});

var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var VisualizeView = (function (_super) {
    __extends(VisualizeView, _super);
    function VisualizeView() {
        var _this = _super.call(this) || this;
        _this.disableClick = true;
        _this.isFullscreen = false;
        _this.columnSetup = false;
        var that = _this;
        if (_this.IsDefined($('#embedDx'))) {
            $('#embedDx').on("click", function (e) {
                $('#embedCodePopupDx').dxPopup("instance").show();
            });
        }
        if (_this.IsDefined($('#memoryRefreshDx'))) {
            var clear = setTimeout(function () {
                $('#memoryRefreshDx').removeClass("disable-click");
                clearInterval(clear);
            }, 3000);
            $('#memoryRefreshDx').on("click", function (e) {
                $('#memoryRefreshDx').addClass("disable-click");
                var refreshUrl = document.location.href.replace('MemoryReport', 'MemoryRefresh');
                document.location.replace(refreshUrl);
            });
        }
        if (_this.IsDefined($('#reportRefreshDx'))) {
            var clear2 = setTimeout(function () {
                $('#reportRefreshDx').removeClass("disable-click");
                clearInterval(clear2);
            }, 3000);
            $('#reportRefreshDx').on("click", function (e) {
                $('#reportRefreshDx').addClass("disable-click");
                var params = (new URL(document.location.href)).search;
                document.location.replace('/Visualize/ReportRefresh' + params);
            });
        }
        return _this;
    }
    VisualizeView.prototype.OnFirstStatusCheck = function (s, e) {
        _super.prototype.StatusCheck.call(this);
    };
    VisualizeView.prototype.OnDashboardTitleToolbarUpdated = function (s) {
        s.options.actionItems.unshift({
            type: "button",
            icon: "dx-dashboard-maximize-item",
            hint: "Fullscreen",
            click: function (element) {
                if (this.isFullscreen) {
                    this.isFullscreen = false;
                    $("#menuDashDx").removeAttr('style');
                    $("#headerDx").removeAttr('style');
                    $('.container-fluid').removeAttr('style');
                }
                else {
                    this.isFullscreen = true;
                    $("#menuDashDx").attr('style', 'display:none!important');
                    $('#headerDx').attr('style', 'display:none!important');
                    $('.container-fluid').attr('style', 'height:100%!important');
                }
            }
        });
    };
    VisualizeView.prototype.OnColumnSetup = function (e) {
        var that = this;
        if (!this.columnSetup) {
            var columns = e.component.getVisibleColumns();
            var ds = e.component.getDataSource();
            this.customizeColumns(columns, e.component, ds);
            e.component.repaintRows();
        }
    };
    VisualizeView.prototype.customizeColumns = function (columns, grid, ds) {
        var that = this;
        var index = 0;
        columns.forEach(function (column) {
        });
    };
    VisualizeView.prototype.isValidDate = function (value) {
        var dateWrapper = new Date(value);
        return !isNaN(dateWrapper.getDate());
    };
    VisualizeView.prototype.OnReportStatusCheck = function (s, e) {
        if (e && e.Error && e.Error.jqXHR && e.Error.jqXHR.statusText === "error" && e.Error.jqXHR.status === 401) {
            window.location.reload();
        }
    };
    return VisualizeView;
}(BaseView));
var View = window.View || {};
document.addEventListener("DOMContentLoaded", function documentReady() {
    this.removeEventListener("DOMContentLoaded", documentReady);
    View = window.View = new VisualizeView();
});

var GridHeaderFilterExtension = (function () {
    var Model = DevExpress.Dashboard.Model;
    var Designer = DevExpress.Dashboard.Designer;

    // 1. Model
    var enabledHeaderFilterProperty = {
        ownerType: Model.GridItem,
        propertyName: 'headerFilterEnabled',
        defaultValue: true,
        valueType: 'boolean'
    };

    Model.registerCustomProperty(enabledHeaderFilterProperty);

    // 2. Viewer
    function onItemWidgetOptionsPrepared(args) {
        if (args.dashboardItem instanceof Model.GridItem) {
            args.options['headerFilter'] = {
                //visible: args.dashboardItem.customProperties.getValue(enabledHeaderFilterProperty.propertyName)
                visible:true
            };
        }
    };

    // 3. Designer
    //function onCustomizeSections(args) {
    //    args.addSection({
    //        title: 'Header Filter (Custom)',
    //        items: [{
    //            dataField: enabledHeaderFilterProperty.propertyName,
    //            label: {
    //                text: 'Header Filter'
    //            },
    //            template: Designer.FormItemTemplates.buttonGroup,
    //            editorOptions: {
    //                keyExpr: 'value',
    //                items: [{
    //                    value: true,
    //                    text: 'On'
    //                }, {
    //                    value: false,
    //                    text: 'Off'
    //                }]
    //            }
    //        }]
    //    });
    //};

    // 4. Event Subscription
    function GridHeaderFilterExtension(dashboardControl) {
        this.name = "GridHeaderFilter",
            this.start = function () {
                var viewerApiExtension = dashboardControl.findExtension('viewerApi');
                if (viewerApiExtension) {
                    viewerApiExtension.on('itemWidgetOptionsPrepared', onItemWidgetOptionsPrepared);
                }
                //var optionsPanelExtension = dashboardControl.findExtension("itemOptionsPanel");
                //if (optionsPanelExtension) {
                //    optionsPanelExtension.on('customizeSections', onCustomizeSections);
                //}
            },
            this.stop = function () {
                var viewerApiExtension = dashboardControl.findExtension('viewerApi');
                if (viewerApiExtension) {
                    viewerApiExtension.off('itemWidgetOptionsPrepared', onItemWidgetOptionsPrepared);
                }
                //var optionsPanelExtension = dashboardControl.findExtension("itemOptionsPanel");
                //if (optionsPanelExtension) {
                //    optionsPanelExtension.off('customizeSections', onCustomizeSections);
                //}
            }
    }
    return GridHeaderFilterExtension;
}());