"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;exports.__esModule = true;exports.ThemeFactory = void 0;var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _utils = require("../utils");


var _ThemeHelpers = require("./ThemeHelpers");
var _LightTheme = require("./themes/LightTheme");var

ThemeFactory = exports.ThemeFactory = /*#__PURE__*/function () {function ThemeFactory() {}ThemeFactory.













  create = function create(theme, baseTheme) {
    var base = baseTheme || this.defaultTheme;
    return this.constructTheme(base, theme);
  };ThemeFactory.

  overrideBaseTheme = function overrideBaseTheme(theme) {var _this = this;
    // copying theme variables
    ThemeFactory.getKeys(this.defaultTheme).forEach(function (variableName) {
      var descriptor = (0, _ThemeHelpers.findPropertyDescriptor)(theme, variableName);
      Object.defineProperty(_this.defaultTheme, variableName, descriptor);
    });

    // copying theme markers
    Object.values(_ThemeHelpers.REACT_UI_THEME_MARKERS).forEach(function (marker) {
      var descriptor = (0, _ThemeHelpers.findPropertyDescriptor)(theme, marker.key);
      Object.defineProperty(_this.defaultTheme, marker.key, descriptor);
    });
  };ThemeFactory.

  getKeys = function getKeys(theme) {
    var keys = [];
    while ((0, _utils.isNonNullable)(theme)) {
      Object.keys(theme).forEach(function (key) {
        if (!keys.includes(key)) {
          keys.push(key);
        }
      });
      // TODO: Enable `no-param-reassign` rule.
      // eslint-disable-next-line no-param-reassign
      theme = Object.getPrototypeOf(theme);
    }

    return keys.sort();
  };ThemeFactory.

  constructTheme = function constructTheme(base, theme) {
    var newTheme = Object.create(base);
    Object.keys(theme).forEach(function (propName) {
      var descriptor = Object.getOwnPropertyDescriptor(theme, propName);
      if (descriptor) {
        Object.defineProperty(newTheme, propName, descriptor);
      }
    });

    return Object.freeze(newTheme);
  };return (0, _createClass2.default)(ThemeFactory, null, [{ key: "defaultTheme", get: function get() {return this.overridableDefaultTheme;} }]);}(); /**
 * The default theme created with Object.create() is needed for the "overrideBaseTheme" to work.
 *
 * Themes should be frozen objects. But it is not possible to define properties on frozen objects.
 * So, an object created by Object.create({ *frozen_object* }) acts as frozen too,
 * but allows to apply Object.defineProperty to his own properties.
 */ThemeFactory.overridableDefaultTheme = Object.create(_LightTheme.LIGHT_THEME);