import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["onError"];
import { useCallback, useState, forwardRef } from 'react';
import { jsx as _jsx } from "react/jsx-runtime";

function withLiveValidateOnError(Form) {
  return /*#__PURE__*/forwardRef(function (_ref, ref) {
    var onError = _ref.onError,
        props = _objectWithoutProperties(_ref, _excluded);

    var _useState = useState(),
        _useState2 = _slicedToArray(_useState, 2),
        hasErrors = _useState2[0],
        setHasErrors = _useState2[1];

    var handleError = useCallback(function (errors) {
      setHasErrors(true);
      onError === null || onError === void 0 ? void 0 : onError(errors);
    }, [onError]);
    return /*#__PURE__*/_jsx(Form, _objectSpread(_objectSpread({
      ref: ref,
      liveValidate: hasErrors
    }, props), {}, {
      onError: handleError
    }));
  });
}

export default withLiveValidateOnError;
//# sourceMappingURL=withLiveValidateOnError.js.map