"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.FormProvider = void 0;

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _react = _interopRequireWildcard(require("react"));

var _shared = require("choerodon-ui/shared");

var _ConfigContext = _interopRequireDefault(require("../../../lib/config-provider/ConfigContext"));

var _utils = require("../../../lib/configure/utils");

var _TooltipUtils = require("../../../lib/_util/TooltipUtils");

var FormContext = (0, _shared.getContext)(_shared.Symbols.ProFormContext, {
  getConfig: _utils.getConfig,
  getPrefixCls: _utils.getPrefixCls,
  getProPrefixCls: _utils.getProPrefixCls,
  getCustomizable: _utils.getCustomizable,
  getTooltip: _TooltipUtils.getTooltip,
  getTooltipTheme: _TooltipUtils.getTooltipTheme,
  getTooltipPlacement: _TooltipUtils.getTooltipPlacement
});

var BaseFormProvider = function FormProvider(props) {
  var children = props.children,
      value = props.value;

  var _useContext = (0, _react.useContext)(_ConfigContext["default"]),
      getGlobalConfig = _useContext.getConfig,
      getGlobalPrefixCls = _useContext.getPrefixCls,
      getGlobalProPrefixCls = _useContext.getProPrefixCls,
      getGlobalCustomizable = _useContext.getCustomizable,
      getGlobalTooltip = _useContext.getTooltip,
      getGlobalTooltipTheme = _useContext.getTooltipTheme,
      getGlobalTooltipPlacement = _useContext.getTooltipPlacement;

  var newValue = (0, _react.useMemo)(function () {
    return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, value), {}, {
      getConfig: getGlobalConfig,
      getPrefixCls: getGlobalPrefixCls,
      getProPrefixCls: getGlobalProPrefixCls,
      getCustomizable: getGlobalCustomizable,
      getTooltip: getGlobalTooltip,
      getTooltipTheme: getGlobalTooltipTheme,
      getTooltipPlacement: getGlobalTooltipPlacement
    });
  }, [value, getGlobalConfig, getGlobalPrefixCls, getGlobalProPrefixCls, getGlobalCustomizable, getGlobalTooltip, getGlobalTooltipTheme, getGlobalTooltipPlacement]);
  return /*#__PURE__*/_react["default"].createElement(FormContext.Provider, {
    value: newValue
  }, children);
};

BaseFormProvider.displayName = 'FormProvider';
var FormProvider = /*#__PURE__*/(0, _react.memo)(BaseFormProvider);
exports.FormProvider = FormProvider;
var _default = FormContext;
exports["default"] = _default;
//# sourceMappingURL=FormContext.js.map
