"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = useScrollToElement;
var _element = require("@wordpress/element");
/**
 * WordPress dependencies
 */

/** @typedef {import('@wordpress/element').RefObject} RefObject */
/**
 * Hook to scroll to a specified element by taking into account the Keyboard
 * and the Header.
 *
 * @param {RefObject} scrollViewRef   Scroll view reference.
 * @param {Function}  scrollToSection Function to scroll.
 * @return {Function[]} Function to scroll to an element.
 */
function useScrollToElement(scrollViewRef, scrollToSection) {
  /**
   * Function to scroll to an element.
   *
   * @param {RefObject} elementRef Ref of the element.
   */
  const scrollToElement = (0, _element.useCallback)(elementRef => {
    if (!scrollViewRef.current || !elementRef) {
      return;
    }
    elementRef.current.measureLayout(scrollViewRef.current, (_x, y, _width, height) => {
      if (height || y) {
        scrollToSection(Math.round(y), height);
      }
    }, () => {});
  }, [scrollViewRef, scrollToSection]);
  return [scrollToElement];
}
//# sourceMappingURL=use-scroll-to-element.native.js.map