import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import * as React from "react";
import { registerPlugins, getPlugins } from "../../plugins";
export var PageBuilderContext = /*#__PURE__*/React.createContext(null);
export var PageBuilderProvider = function PageBuilderProvider(_ref) {
  var _ref$theme = _ref.theme,
      bcTheme = _ref$theme === void 0 ? null : _ref$theme,
      children = _ref.children,
      rest = _objectWithoutProperties(_ref, ["theme", "children"]);

  var value = React.useMemo(function () {
    var theme = Object.assign.apply(Object, [{}, bcTheme].concat(_toConsumableArray(getPlugins("pb-theme").map(function (pl) {
      return pl.theme;
    })))); // For backwards compatibility, grab any page layouts defined in the theme and convert them to plugins

    if (theme.layouts) {
      registerPlugins(theme.layouts.map(function (l) {
        return {
          name: "pb-page-layout-".concat(l.name),
          type: "pb-page-layout",
          layout: l
        };
      }));
    }

    return _objectSpread({
      theme: theme
    }, rest);
  }, []);
  return /*#__PURE__*/React.createElement(PageBuilderContext.Provider, {
    value: value
  }, children);
};
export var PageBuilderConsumer = function PageBuilderConsumer(_ref2) {
  var children = _ref2.children;
  return /*#__PURE__*/React.createElement(PageBuilderContext.Consumer, null, function (props) {
    return /*#__PURE__*/React.cloneElement(children, {
      pageBuilder: props
    });
  });
};
//# sourceMappingURL=PageBuilderContext.js.map