import React from "react";
export default function useAspectRatioDimension(width = 0, height = 0, borderWeight = 0, targetFit = "clientHeight") {
    const [scale, setScale] = React.useState(1);
    const containerRef = React.useRef(null);
    const calculateScale = React.useCallback(() => {
        if (containerRef.current &&
            containerRef.current[targetFit] <
                borderWeight + (targetFit === "clientHeight" ? height : width)) {
            setScale(containerRef.current[targetFit] /
                (borderWeight + (targetFit === "clientHeight" ? height : width)));
        }
    }, [width, height]);
    React.useEffect(() => {
        calculateScale();
        // for some reason, the initial width of the containerRef is not reliable
        const timeout = setTimeout(calculateScale, 100);
        return () => clearTimeout(timeout);
    }, [calculateScale]);
    return { scale, width, height, containerRef };
}
//# sourceMappingURL=useAspectRatioDimension.js.map