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) {
        function EnsureConfigurationHasHiddenControl(gadgetConfiguration) {
            var hashiddenControl = HasHiddenSetupControl(gadgetConfiguration);
            if (!hashiddenControl) {
                gadgetConfiguration.SetupItems.push(GetNewHiddenSetting());
            }
        }
        Gadget.EnsureConfigurationHasHiddenControl = EnsureConfigurationHasHiddenControl;
        function GetNewHiddenSetting(comment) {
            if (comment === void 0) { comment = ''; }
            var newHiddenSetting = {
                SetupControlId: Guid.emptyGuid(),
                Settings: [
                    {
                        Name: "Version",
                        Value: "2"
                    }]
            };
            return newHiddenSetting;
        }
        Gadget.GetNewHiddenSetting = GetNewHiddenSetting;
        function HasHiddenSetupControl(gadgetConfiguration) {
            var hasHiddenSetupControl = _.any(gadgetConfiguration.SetupItems, function (setupItem) {
                return Guid.isEmptyGuid(setupItem.SetupControlId);
            });
            return hasHiddenSetupControl;
        }
        Gadget.HasHiddenSetupControl = HasHiddenSetupControl;
        // Settings.Gadget.SettingGroup.Hidden
        Gadget.SettingGroup = $.extend(Gadget.SettingGroup, {
            Hidden: "00000000-0000-0000-0000-000000000000"
        });
        Gadget.LastEditTimeUtc = { id: Settings.Gadget.SettingGroup.Hidden, name: "LastEditTimeUtc" };
        Gadget.Version = { id: Settings.Gadget.SettingGroup.Hidden, name: "Version" };
    })(Gadget = Settings.Gadget || (Settings.Gadget = {}));
})(Settings || (Settings = {}));
/////////////////////////////////////////////////////////////////
// Hidden Setup Control
// This control contains either (a) settings used by the system
// to manage the gadget or (b) control settings that are normally
// editable but should be fixed for this gadget type. This
// setup control exists to manage the former. 
var Dashboards;
(function (Dashboards) {
    var SetupControl;
    (function (SetupControl) {
        var Hidden = (function (_super) {
            __extends(Hidden, _super);
            function Hidden() {
                _super.call(this, Settings.Gadget.SettingGroup.Hidden);
                this.title = 'Hidden';
            }
            Hidden.CreateInstance = function () {
                var instance = new Hidden();
                return instance;
            };
            Hidden.prototype.draw = function () {
                // we don't show anything so do nothing here
            };
            ;
            Hidden.prototype.isConfigured = function () {
                return true;
            };
            ;
            Hidden.prototype.isManagedSetting = function (name) {
                // we'll accept any hidden setting
                return true;
            };
            ;
            Hidden.prototype.beforeCommit = function () {
                // Update the hidden timestamp before the configuration is saved.
                // This piggybacks nicely on the standardized setup control flow.
                var updateTime = (new Date()).toISOString();
                // Javascript toISOString yields s.sssZ while .NET expects s.sssssssZ
                // so extend the date time string with four zeros.
                updateTime = updateTime.replace("Z", "0000Z");
                this.setting(Settings.Gadget.LastEditTimeUtc.name, updateTime);
            };
            ;
            return Hidden;
        }(Dashboards.Models.SetupControl));
        SetupControl.Hidden = Hidden;
    })(SetupControl = Dashboards.SetupControl || (Dashboards.SetupControl = {}));
})(Dashboards || (Dashboards = {}));
// Register the Setup Control
Dashboards.Controllers.SetupControl.Register({
    create: Dashboards.SetupControl.Hidden.CreateInstance,
    id: Settings.Gadget.SettingGroup.Hidden
});
//# sourceMappingURL=HiddenSetupControl.js.map