"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.extendTheme = extendTheme;

var _theme = require("./../theme");

var _lodash = _interopRequireDefault(require("lodash.mergewith"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

// import { updateComponentThemeMap } from '../utils/styled';
function isFunction(value) {
  return typeof value === 'function';
}

// function resolveComponentThemeAndUpdateMap(theme: any) {
//   if (theme.components) {
//     // Object.keys(theme.components).map((key?: string) => {
//     //   // updateComponentThemeMap(key, theme.components[key]);
//     // });
//   }
// }
function extendTheme(overrides, ...restOverrides) {
  function customizer(source, override) {
    if (isFunction(source)) {
      return (...args) => {
        const sourceValue = source(...args);
        const overrideValue = isFunction(override) ? override(...args) : override;
        return (0, _lodash.default)({}, sourceValue, overrideValue, customizer);
      };
    }

    return undefined;
  }

  let finalOverrides = [overrides, ...restOverrides].reduce((prevValue, currentValue) => {
    // console.log(prevValue, currentValue, 'value');
    // resolveComponentThemeAndUpdateMap(currentValue);
    return (0, _lodash.default)({}, prevValue, currentValue, customizer);
  }, _theme.theme); // TODO: Fix typings
  // @ts-ignore

  finalOverrides['customUserTheme'] = overrides;
  return finalOverrides;
}
//# sourceMappingURL=extendTheme.js.map