import { theme as defaultTheme } from './../theme';
import mergeWith from 'lodash.mergewith'; // 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]);
//     // });
//   }
// }
export 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 mergeWith({}, sourceValue, overrideValue, customizer);
      };
    }

    return undefined;
  }

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

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