import { __rest } from "tslib";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { forwardRef, useContext } from 'react';
import clsx from 'clsx';
import RcForm from 'rc-field-form';
import ConfigProviderContext from '../config-provider/ConfigProviderContext';
import { FormContext } from './FormContext';
const Form = forwardRef((props, ref) => {
  const {
    prefixCls,
    createNamespace
  } = useContext(ConfigProviderContext);
  const [bem] = createNamespace('form', prefixCls);

  const {
    className,
    style,
    layout,
    footer,
    children,
    colon,
    border,
    labelAlign,
    inputAlign,
    showValidateMessage
  } = props,
        formProps = __rest(props, ["className", "style", "layout", "footer", "children", "colon", "border", "labelAlign", "inputAlign", "showValidateMessage"]);

  return _jsx(FormContext.Provider, Object.assign({
    value: {
      layout,
      colon,
      border,
      showValidateMessage,
      inputAlign,
      labelAlign
    }
  }, {
    children: _jsxs(RcForm, Object.assign({
      className: clsx(bem(), className),
      style: style,
      ref: ref
    }, formProps, {
      children: [children, footer && _jsx("div", Object.assign({
        className: clsx(bem('footer'))
      }, {
        children: footer
      }))]
    }))
  }));
});
Form.defaultProps = {
  showValidateMessage: true
};
export default Form;