import { useEffect, useState } from 'react';

export const useSliderHeights = (layout, size) => {
    const [height, setHeight] = useState(0);
    const allHeights = [];

    // heights should reset when some props change
    useEffect(() => {
        setHeight(0);
    }, [layout, size, setHeight]);

    // store the heights reported by the children
    const reportHeight = (tileIndex, reportedHeight) => {
        if (reportedHeight) {
            allHeights.push(reportedHeight);
        }
        setHeight(Math.max(...allHeights));
    };
    return [height, reportHeight];
};
