"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/hooks/useResizeObserver.tsx
var _lodashes = require('lodash-es');
var _react = require('react');
function useResizeObserver(resizeProperties) {
  const resizeObserver = _react.useRef.call(void 0, null);
  const [rect, setRect] = _react.useState.call(void 0, null);
  const [selectedProperties, setSelectedProperties] = _react.useState.call(void 0, null);
  const mounted = _react.useRef.call(void 0, false);
  _react.useEffect.call(void 0, () => {
    mounted.current = true;
    return () => {
      mounted.current = false;
    };
  }, []);
  const onResize = _react.useCallback.call(void 0, 
    (entries) => {
      setTimeout(() => {
        if (mounted.current) {
          const changedRect = entries[0].contentRect;
          setRect(changedRect);
        } else if (resizeObserver.current) {
          resizeObserver.current.disconnect();
        }
      }, 0);
    },
    [setRect]
  );
  const ref = _react.useCallback.call(void 0, 
    (node) => {
      if (node && node instanceof Element && resizeProperties && resizeProperties.length > 0) {
        resizeObserver.current = new ResizeObserver(onResize);
        resizeObserver.current.observe(node);
      }
    },
    [onResize, resizeProperties]
  );
  _react.useEffect.call(void 0, () => {
    if (resizeProperties) {
      const selectedProps = _lodashes.pick.call(void 0, rect, resizeProperties);
      if (JSON.stringify(selectedProperties) !== JSON.stringify(selectedProps)) {
        setSelectedProperties(selectedProps);
      }
    }
  }, [rect, resizeProperties, setSelectedProperties, selectedProperties]);
  return {
    ref,
    rect: selectedProperties
  };
}



exports.useResizeObserver = useResizeObserver;
