"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useTimer = void 0;
const react_1 = require("react");
const useTimer = (seconds) => {
    const [time, setTime] = (0, react_1.useState)(seconds);
    (0, react_1.useEffect)(() => {
        const startTime = Date.now();
        const int = setInterval(() => {
            const t = Math.ceil(seconds - (Date.now() - startTime) / 1000);
            if (t <= 0) {
                clearInterval(int);
                setTime(0);
            }
            else {
                setTime(t);
            }
        }, 100);
        return () => {
            if (int)
                clearInterval(int);
        };
    }, [seconds]);
    return time;
};
exports.useTimer = useTimer;
//# sourceMappingURL=useTimer.js.map