var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var Settings;
(function (Settings) {
    var Gadget;
    (function (Gadget) {
        // Settings.Gadget.SettingGroup.Summary
        Gadget.SettingGroup = $.extend(Gadget.SettingGroup, {
            ConsumptionRankingSetup: "7435cf50-d628-4d96-8c23-e51dcbd5a260"
        });
        Gadget.BarPosition = { id: Settings.Gadget.SettingGroup.ConsumptionRankingSetup, name: "BarPosition" };
        Gadget.SortOrder = { id: Settings.Gadget.SettingGroup.ConsumptionRankingSetup, name: "SortOrder" };
        Gadget.LegendName = { id: Settings.Gadget.SettingGroup.ConsumptionRankingSetup, name: "LegendName" };
        Gadget.ShowLegend = { id: Settings.Gadget.SettingGroup.ConsumptionRankingSetup, name: "ShowLegend" };
        Gadget.ShowTotal = { id: Settings.Gadget.SettingGroup.ConsumptionRankingSetup, name: "ShowTotal" };
    })(Gadget = Settings.Gadget || (Settings.Gadget = {}));
})(Settings || (Settings = {}));
var Dashboards;
(function (Dashboards) {
    var SetupControl;
    (function (SetupControl) {
        var ConsumptionRankingSetup = (function (_super) {
            __extends(ConsumptionRankingSetup, _super);
            function ConsumptionRankingSetup() {
                _super.call(this, Settings.Gadget.SettingGroup.ConsumptionRankingSetup);
                this.title = i18n.loc.s('ISO50001Gadgets', 'Consumption_Ranking_Setup');
            }
            ConsumptionRankingSetup.CreateInstance = function () {
                var instance = new ConsumptionRankingSetup();
                return instance;
            };
            ConsumptionRankingSetup.prototype.draw = function () {
                var _this = this;
                this.$container.empty();
                TemplateUtil.LocAndLoad(ConsumptionRankingSetup.SetupControlTemplateUri, new Core.CallBack(function (template) {
                    _this.$container.html(template);
                    _this.render();
                }, this));
            };
            ConsumptionRankingSetup.prototype.isConfigured = function () {
                return true;
            };
            ConsumptionRankingSetup.prototype.isManagedSetting = function (name) {
                var managed = false;
                switch (name) {
                    case Settings.Gadget.BarPosition.name:
                    case Settings.Gadget.SortOrder.name:
                    case Settings.Gadget.LegendName.name:
                    case Settings.Gadget.ShowLegend.name:
                    case Settings.Gadget.ShowTotal.name:
                        managed = true;
                        break;
                }
                ;
                return managed;
            };
            ConsumptionRankingSetup.prototype.beforeCommit = function () {
                var barPosition = this.$container.find('#bar-position').prop('checked');
                this.setting(Settings.Gadget.BarPosition.name, barPosition);
                var sortOrder = this.$container.find('#sort-order').prop('checked');
                this.setting(Settings.Gadget.SortOrder.name, sortOrder);
                var legendName = this.$container.find('#legend-name').val();
                this.setting(Settings.Gadget.LegendName.name, legendName);
                var showTotal = this.$container.find('#show-total').prop('checked');
                this.setting(Settings.Gadget.ShowTotal.name, showTotal.toString());
            };
            ConsumptionRankingSetup.prototype.render = function () {
                var $barPosition = this.$container.find('#bar-position');
                $barPosition.prop('checked', (this.setting(Settings.Gadget.BarPosition.name).toString().toLowerCase() === 'true'));
                var $sortOrder = this.$container.find('#sort-order');
                $sortOrder.prop('checked', (this.setting(Settings.Gadget.SortOrder.name).toString().toLowerCase() === 'true'));
                if (this.setting(Settings.Gadget.ShowLegend.name).toString() === 'true') {
                    var legendName = this.$container.find('#legend-name');
                    legendName.val(this.setting(Settings.Gadget.LegendName.name).toString());
                }
                else {
                    this.$container.find('#legend-name').hide();
                    this.$container.find('#legend-name-label').hide();
                }
                var showTotalChecked = this.setting(Settings.Gadget.ShowTotal.name);
                var showTotal = _.isUndefined(showTotalChecked) || _.isNull(showTotalChecked) ? true : showTotalChecked.toString().toLowerCase() === 'true';
                this.$container.find('#show-total').prop('checked', showTotal);
            };
            ConsumptionRankingSetup.SetupControlTemplateUri = 'Content/Gadgets/ConsumptionRanking/ConsumptionRankingSetup.html';
            return ConsumptionRankingSetup;
        }(Dashboards.Models.SetupControl));
        SetupControl.ConsumptionRankingSetup = ConsumptionRankingSetup;
    })(SetupControl = Dashboards.SetupControl || (Dashboards.SetupControl = {}));
})(Dashboards || (Dashboards = {}));
// Register the Setup Control
Dashboards.Controllers.SetupControl.Register({
    create: Dashboards.SetupControl.ConsumptionRankingSetup.CreateInstance,
    id: Settings.Gadget.SettingGroup.ConsumptionRankingSetup
});
//# sourceMappingURL=ConsumptionRankingSetup.js.map