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.MultiSource
        Gadget.SettingGroup = $.extend(Gadget.SettingGroup, {
            MultiSource: "874f3d20-4c96-4f6a-b1ca-9e72050b36b2"
        });
        Gadget.MultiSelectSources = { id: Settings.Gadget.SettingGroup.MultiSource, name: "MultiSelectSources" };
        Gadget.HideInactiveSources = { id: Settings.Gadget.SettingGroup.MultiSource, name: "HideInactiveSources" };
        Gadget.SourceMode = { id: Settings.Gadget.SettingGroup.MultiSource, name: "SourceMode" };
    })(Gadget = Settings.Gadget || (Settings.Gadget = {}));
})(Settings || (Settings = {}));
var Dashboards;
(function (Dashboards) {
    var SetupControl;
    (function (SetupControl) {
        var MultiSource = (function (_super) {
            __extends(MultiSource, _super);
            function MultiSource() {
                _super.call(this, Settings.Gadget.SettingGroup.MultiSource);
                this.multiSourceSelector = null;
                this.title = i18n.loc.s('Gadgets', 'MultiSourceSetupControl_Title');
            }
            MultiSource.CreateInstance = function () {
                var instance = new MultiSource();
                return instance;
            };
            MultiSource.prototype.draw = function () {
                var _this = this;
                this.$container.empty();
                TemplateUtil.LocAndLoad(MultiSource.SetupControlTemplateUri, new Core.CallBack(function (template) {
                    _this.$container.html(template);
                    _this.render();
                }, this));
            };
            MultiSource.prototype.isConfigured = function () {
                return this.selectedSources.length > 0;
            };
            MultiSource.prototype.isManagedSetting = function (name) {
                var managed = false;
                switch (name) {
                    case Settings.Gadget.MultiSelectSources.name:
                    case Settings.Gadget.HideInactiveSources.name:
                    case Settings.Gadget.SourceMode.name:
                        managed = true;
                        break;
                }
                ;
                return managed;
            };
            MultiSource.prototype.onFocus = function () {
                if (!this.multiSourceSelector) {
                    var isRealtimeOnlySetting = this.setting(Settings.Gadget.HideInactiveSources.name);
                    var isRealtimeOnly = false;
                    if (isRealtimeOnlySetting && isRealtimeOnlySetting.toLowerCase() == 'true') {
                        isRealtimeOnly = true;
                    }
                    this.multiSourceSelector = new Controls.Smp.MultiSourceSelect(this.$container.find('.sourceSelection'));
                    this.multiSourceSelector.initialize({
                        hideInactiveSources: isRealtimeOnly,
                        sourceMode: Controls.Smp.SourceSelectorMode.SourceNode,
                        isSmallRender: this.isSmallRenderWindow()
                    }, this.selectedSources);
                }
            };
            MultiSource.prototype.onBlur = function () {
            };
            MultiSource.prototype.destroy = function () {
                if (this.multiSourceSelector) {
                    this.multiSourceSelector.unloadControl();
                    this.multiSourceSelector = null;
                }
                _super.prototype.destroy.call(this);
            };
            MultiSource.prototype.isValid = function () {
                if (this.multiSourceSelector) {
                    // If we have a selector, use these values.  Else use what we have.
                    this.selectedSources = this.multiSourceSelector.getSelection();
                    this.setting(Settings.Gadget.MultiSelectSources.name, JSON.stringify(this.selectedSources));
                }
                return true;
            };
            MultiSource.prototype.render = function () {
                // We must call this AFTER we are visible to ensure our loading block is centered...
                // Bind Source
                this.selectedSources = [];
                var sourcesJsonString = this.setting(Settings.Gadget.MultiSelectSources.name);
                if (sourcesJsonString) {
                    this.selectedSources = JSON.parse(sourcesJsonString);
                }
            };
            MultiSource.SetupControlTemplateUri = 'Content/Gadgets/_baseSetupControls/MultiSourceSelectSetupControlTemplate.html';
            return MultiSource;
        }(Dashboards.Models.SetupControl));
        SetupControl.MultiSource = MultiSource;
    })(SetupControl = Dashboards.SetupControl || (Dashboards.SetupControl = {}));
})(Dashboards || (Dashboards = {}));
// Register the Setup Control
Dashboards.Controllers.SetupControl.Register({
    create: Dashboards.SetupControl.MultiSource.CreateInstance,
    id: Settings.Gadget.SettingGroup.MultiSource
});
//# sourceMappingURL=MultiSourceSelectSetupControl.js.map