"use strict";

const events = require("events");
const systemColors = require('./build/Release/system-colors');
//systemColors.onChange(callback)
//systemColors.isHighContrastEnabled()
//systemColors.getSystemColors()

var SystemColors = (function () {
    function SystemColors() {
        this._lastColors = systemColors.getSystemColors();
        this._lastHighContrastEnabled = systemColors.isHighContrastEnabled();
        systemColors.onChange(function SystemColors_onChange() {
            var colors = systemColors.getSystemColors();
            var colorsChanged = Object.keys(colors).some(colorName => {
                return colors[colorName] != this._lastColors[colorName]
            });
            if (colorsChanged) {
                this._lastColors = colors;
            }
            
            var highContrastEnabled = systemColors.isHighContrastEnabled();
            var highContrastChanged = highContrastEnabled != this._lastHighContrastEnabled;
            if (highContrastChanged) {
                this._lastHighContrastEnabled = highContrastEnabled;
            }
            
            if (colorsChanged || highContrastChanged) {
                this.emit("change");
            }
        }.bind(this));
    }
    
    // extend EventEmitter
    SystemColors.prototype = events.EventEmitter.prototype;

    SystemColors.prototype.getSystemColors = function SystemColors_getSystemColors() {
        return this._lastColors;
    };

    SystemColors.prototype.isHighContrastEnabled = function SystemColors_isHighContrastEnabled() {
        return this._lastHighContrastEnabled;
    };
    
    return SystemColors;
})();

module.exports.SystemColors = SystemColors;
