// Copyright 1999-2025. WebPros International GmbH. All rights reserved.

import { useLayoutEffect, useRef, useState } from 'react';
import { useResizeObserver } from '../../hooks';
export const useContentOverflow = _ref => {
  let {
    contentRef,
    hiddenElementRef,
    maxHeight
  } = _ref;
  const [isOverflowing, setIsOverflowing] = useState(false);
  const checkHeight = () => {
    const contentElement = contentRef.current;
    const hiddenElement = hiddenElementRef.current;
    if (!contentElement || !hiddenElement) return;
    setIsOverflowing(contentElement.scrollHeight > hiddenElement.getBoundingClientRect().height);
  };
  const checkHeightRef = useRef(checkHeight);
  checkHeightRef.current = checkHeight;
  useLayoutEffect(() => {
    checkHeightRef.current();
  }, [maxHeight]);
  useResizeObserver({
    ref: contentRef,
    onResize: checkHeight
  });
  return isOverflowing;
};