var _excluded = ["shallow", "children", "prefix", "className", "style"];
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
import React, { createContext, useContext } from 'react';
import { useResponsiveFormLayout } from './useResponsiveFormLayout';
import { usePrefixCls } from '../__builtins__';
import cls from 'classnames';
export var FormLayoutDeepContext = /*#__PURE__*/createContext({});
export var FormLayoutShallowContext = /*#__PURE__*/createContext({});
export var useFormDeepLayout = function useFormDeepLayout() {
  return useContext(FormLayoutDeepContext);
};
export var useFormShallowLayout = function useFormShallowLayout() {
  return useContext(FormLayoutShallowContext);
};
export var useFormLayout = function useFormLayout() {
  return _objectSpread(_objectSpread({}, useFormDeepLayout()), useFormShallowLayout());
};
export var FormLayout = function FormLayout(_ref) {
  var _cls;
  var shallow = _ref.shallow,
    children = _ref.children,
    prefix = _ref.prefix,
    className = _ref.className,
    style = _ref.style,
    otherProps = _objectWithoutProperties(_ref, _excluded);
  var _useResponsiveFormLay = useResponsiveFormLayout(otherProps),
    ref = _useResponsiveFormLay.ref,
    props = _useResponsiveFormLay.props;
  var deepLayout = useFormDeepLayout();
  var formPrefixCls = usePrefixCls('form', {
    prefix: prefix
  });
  var layoutPrefixCls = usePrefixCls('formily-layout', {
    prefix: prefix
  });
  var layoutClassName = cls(layoutPrefixCls, (_cls = {}, _defineProperty(_cls, "".concat(formPrefixCls, "-").concat(props.layout), true), _defineProperty(_cls, "".concat(formPrefixCls, "-rtl"), props.direction === 'rtl'), _defineProperty(_cls, "".concat(formPrefixCls, "-").concat(props.size), props.size), _cls), className);
  var renderChildren = function renderChildren() {
    var newDeepLayout = _objectSpread({}, deepLayout);
    if (!shallow) {
      Object.assign(newDeepLayout, props);
    } else {
      if (props.size) {
        newDeepLayout.size = props.size;
      }
      if (props.colon) {
        newDeepLayout.colon = props.colon;
      }
    }
    return /*#__PURE__*/React.createElement(FormLayoutDeepContext.Provider, {
      value: newDeepLayout
    }, /*#__PURE__*/React.createElement(FormLayoutShallowContext.Provider, {
      value: shallow ? props : undefined
    }, children));
  };
  return /*#__PURE__*/React.createElement("div", {
    ref: ref,
    className: layoutClassName,
    style: style
  }, renderChildren());
};
FormLayout.defaultProps = {
  shallow: true
};
FormLayout.useFormDeepLayout = useFormDeepLayout;
FormLayout.useFormShallowLayout = useFormShallowLayout;
FormLayout.useFormLayout = useFormLayout;
export default FormLayout;