"use strict";

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

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

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

var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _react = require("react");

var _jsxRuntime = require("react/jsx-runtime");

var _excluded = ["onError"];

function withLiveValidateOnError(Form) {
  return /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
    var onError = _ref.onError,
        props = (0, _objectWithoutProperties2["default"])(_ref, _excluded);

    var _useState = (0, _react.useState)(),
        _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
        hasErrors = _useState2[0],
        setHasErrors = _useState2[1];

    var handleError = (0, _react.useCallback)(function (errors) {
      setHasErrors(true);
      onError === null || onError === void 0 ? void 0 : onError(errors);
    }, [onError]);
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(Form, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
      ref: ref,
      liveValidate: hasErrors
    }, props), {}, {
      onError: handleError
    }));
  });
}

var _default = withLiveValidateOnError;
exports["default"] = _default;
//# sourceMappingURL=withLiveValidateOnError.cjs.map