import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["onError"];
import { forwardRef, useRef } from 'react';
import { jsx as _jsx } from "react/jsx-runtime";
export default function withScrollToError(Form) {
  return /*#__PURE__*/forwardRef(function (props, ref) {
    var onError = props.onError,
        otherProps = _objectWithoutProperties(props, _excluded);

    var formWrapperRef = useRef();

    var scrollOnError = function scrollOnError() {
      var _formWrapperRef$curre;

      //const errorListElement = document.getElementById('formula-validation-errors');
      var errorListElement = (_formWrapperRef$curre = formWrapperRef.current) === null || _formWrapperRef$curre === void 0 ? void 0 : _formWrapperRef$curre.querySelector('#' + 'formula-validation-errors');
      errorListElement === null || errorListElement === void 0 ? void 0 : errorListElement.focus();
      errorListElement === null || errorListElement === void 0 ? void 0 : errorListElement.scrollIntoView({
        behavior: 'smooth'
      });

      for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
        args[_key] = arguments[_key];
      }

      onError === null || onError === void 0 ? void 0 : onError.apply(void 0, args);
    };

    return /*#__PURE__*/_jsx("div", {
      ref: formWrapperRef,
      children: /*#__PURE__*/_jsx(Form, _objectSpread({
        ref: ref,
        onError: scrollOnError
      }, otherProps))
    });
  });
}
//# sourceMappingURL=withScrollToError.js.map