import { useCallback, useEffect, useState } from "react";
import { addCssClassName } from ".";
import useIntersectionObserver from "./useIntersectionObserver";
const defaultObserverOptions = {
  threshold: [0, 1]
};
const useVisible = (initialVisible, observerOptions = defaultObserverOptions) => {
  const [visible, setVisible] = useState(initialVisible);
  const forceVisible = () => {
    setVisible(true);
  };
  useEffect(() => {
    if (initialVisible) {
      forceVisible();
    }
  }, [initialVisible]);
  const handleIntersection = useCallback(
    (entries) => {
      entries.filter((entry) => entry.isIntersecting).forEach((entry) => {
        const target = entry.target;
        addCssClassName(target, "rc-lazyload__loaded");
        setVisible(true);
      });
    },
    [setVisible, visible]
  );
  const ref = useIntersectionObserver(observerOptions, handleIntersection);
  return [ref, visible];
};
var stdin_default = useVisible;
export {
  stdin_default as default
};
