"use strict";

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

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

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

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

var _react = require("react");

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

var _excluded = ["onError"];

function withScrollToError(Form) {
  return /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
    var onError = props.onError,
        otherProps = (0, _objectWithoutProperties2["default"])(props, _excluded);
    var formWrapperRef = (0, _react.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__*/(0, _jsxRuntime.jsx)("div", {
      ref: formWrapperRef,
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Form, (0, _objectSpread2["default"])({
        ref: ref,
        onError: scrollOnError
      }, otherProps))
    });
  });
}
//# sourceMappingURL=withScrollToError.cjs.map