import React__default from 'react';
import _pt from 'prop-types';
import { useThemeUI, ThemeProvider as ThemeProvider$1 } from '../../../node_modules/theme-ui/dist/index.esm.esm.js';
import { getTheme } from '../../theme/index.esm.js';

function ThemeProvider(_ref) {
  var children = _ref.children,
      theme = _ref.theme;
  var themeValue = React__default.useMemo(function () {
    var baseTheme = getTheme();

    if (typeof theme === "function") {
      return theme(baseTheme);
    }

    return theme || baseTheme;
  }, [theme, getTheme]);
  return /*#__PURE__*/React__default.createElement(ThemeProvider$1, {
    theme: themeValue
  }, children);
} // To distinguish from Theme UI's ThemeProvider

ThemeProvider.propTypes = {
  children: _pt.node
};
ThemeProvider.displayName = "GatsbyInterfaceThemeProvider";
function useTheme() {
  // @ts-ignore
  return useThemeUI().theme;
}
ThemeProvider.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "GatsbyInterfaceThemeProvider",
  "props": {
    "children": {
      "required": false,
      "tsType": {
        "name": "ReactReactNode",
        "raw": "React.ReactNode"
      },
      "description": ""
    },
    "theme": {
      "required": false,
      "tsType": {
        "name": "union",
        "raw": "Theme | ((baseTheme: Theme) => Theme)",
        "elements": [{
          "name": "Theme"
        }, {
          "name": "unknown"
        }]
      },
      "description": ""
    }
  }
};

if (typeof STORYBOOK_REACT_CLASSES !== "undefined") {
  STORYBOOK_REACT_CLASSES["src/components/ThemeProvider/ThemeProvider.tsx"] = {
    name: "ThemeProvider",
    docgenInfo: ThemeProvider.__docgenInfo,
    path: "src/components/ThemeProvider/ThemeProvider.tsx"
  };
}

export default ThemeProvider;
export { useTheme };
//# sourceMappingURL=ThemeProvider.esm.js.map
