var Dashboards;
(function (Dashboards) {
    var EnergyGadgets;
    (function (EnergyGadgets) {
        // The predefined equivalencies object. This parses the settings for a gadget
        // into a collection of IPredefinedEquivalency objects which are then used
        // by the Energy Equivalency gadget.
        var PredefinedEquivalencies = (function () {
            function PredefinedEquivalencies(settings) {
                var _this = this;
                this.Equivalencies = new Array();
                // interate each setting, building up the equivalencies
                _.each(settings, function (setting) {
                    var name = String(setting.Name);
                    if (!name.startsWith('Conversion_'))
                        return;
                    // make sure there are two underscores
                    var firstUnderscore = name.indexOf('_');
                    var secondUnderscore = name.lastIndexOf('_');
                    if (firstUnderscore === secondUnderscore)
                        return;
                    // get the setting key and type
                    var key = name.substring(firstUnderscore + 1, secondUnderscore);
                    var type = name.substring(secondUnderscore + 1);
                    // if the string starts with RESX_, then we need to localize the value
                    var value = setting.Value;
                    if (value.startsWith('RESX_')) {
                        value = i18n.loc.unencoded('EnergyGadgets', value);
                    }
                    // find an equivalency with this key already (if it exists)
                    var equivalency = _this.getEquivalency(key);
                    if (equivalency == undefined) {
                        equivalency = new EnergyGadgets.PredefinedEquivalency();
                        equivalency.key = key;
                        _this.Equivalencies.push(equivalency);
                    }
                    switch (type) {
                        case 'Name':
                            equivalency.name = value;
                            break;
                        case 'Description':
                            equivalency.description = value;
                            break;
                        case 'Multiplier':
                            equivalency.multiplier = parseFloat(value);
                            break;
                        case 'Symbol':
                            equivalency.symbol = value;
                            break;
                        case 'SymbolBeforeValue':
                            equivalency.symbolBeforeValue = value === 'true';
                            break;
                        case 'DecimalPlaces':
                            equivalency.decimalPlaces = parseInt(value);
                            break;
                    }
                });
            }
            PredefinedEquivalencies.prototype.getEquivalency = function (key) {
                var equivalencyMatch = null;
                _.each(this.Equivalencies, function (equivalency) {
                    if (equivalency.key === key) {
                        equivalencyMatch = equivalency;
                    }
                });
                return equivalencyMatch;
            };
            PredefinedEquivalencies.prototype.getEquivalencies = function () {
                return this.Equivalencies;
            };
            return PredefinedEquivalencies;
        }());
        EnergyGadgets.PredefinedEquivalencies = PredefinedEquivalencies;
    })(EnergyGadgets = Dashboards.EnergyGadgets || (Dashboards.EnergyGadgets = {}));
})(Dashboards || (Dashboards = {}));
//# sourceMappingURL=PredefinedEquivalencies.js.map