// This Source Code Form is subject to the terms of the Mozilla Public
// License, v2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/
/* eslint-disable react-hooks/rules-of-hooks */
import React from "react";
const refreshInterval = 500;
export function createRenderDelaySampler() {
    const [frameDelays, setFrameDelays] = React.useState([]);
    const [averageFrameDelay, setAverageFrameDelay] = React.useState(0);
    React.useEffect(() => {
        const interval = setInterval(() => {
            setAverageFrameDelay(frameDelays.reduce((a, b) => a + b, 0) / frameDelays.length);
            setFrameDelays([]);
        }, refreshInterval);
        return () => {
            clearInterval(interval);
        };
    }, [frameDelays]);
    const addFrameTime = (frameTime) => {
        setFrameDelays(currentFrameDelays => [...currentFrameDelays, performance.now() - frameTime]);
    };
    return { averageFrameDelay, addFrameTime };
}
//# sourceMappingURL=measure-render-delay.js.map