import _extends from "@babel/runtime/helpers/esm/extends";
import useMemo from "rc-util/es/hooks/useMemo";
import shallowEqual from 'shallowequal';
export default function useTheme(theme, parentTheme) {
  var themeConfig = theme || {};
  var parentThemeConfig = parentTheme || {};
  var mergedTheme = useMemo(function () {
    if (!theme) {
      return parentTheme;
    } // Override


    var mergedOverride = _extends({}, parentThemeConfig.components);

    Object.keys(theme.components || {}).forEach(function (componentName) {
      mergedOverride[componentName] = _extends(_extends({}, mergedOverride[componentName]), theme.components[componentName]);
    }); // Base token

    var merged = _extends(_extends(_extends({}, parentThemeConfig), themeConfig), {
      token: _extends(_extends({}, parentThemeConfig.token), themeConfig.token),
      override: mergedOverride
    });

    return merged;
  }, [themeConfig, parentThemeConfig], function (prev, next) {
    return prev.some(function (prevTheme, index) {
      var nextTheme = next[index];
      return !shallowEqual(prevTheme, nextTheme);
    });
  });
  return mergedTheme;
}