"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useSecondsCountdown = void 0;
const react_1 = require("react");
const services_1 = require("../services");
/**
 *  Хук, предоставляющий функционал с текстом убывающих секунд
 */
const useSecondsCountdown = ({ targetDate, isInitialActive, seconds, }) => {
    const [textTime, setTextTime] = (0, react_1.useState)('');
    const [isCountDownActive, setCountDownActive] = (0, react_1.useState)(Boolean(isInitialActive));
    const [countDown] = (0, react_1.useState)(() => new services_1.UNSTABLE_SecondsCountdownService({
        targetDate,
        isInitialActive,
        seconds,
        onUpdateTextTime: setTextTime,
        onUpdateActivity: setCountDownActive,
    }));
    (0, react_1.useEffect)(() => () => countDown.destroy(), [countDown]);
    return {
        isActive: isCountDownActive,
        textTime: textTime || countDown.textTime,
        restart: countDown.restart,
    };
};
exports.useSecondsCountdown = useSecondsCountdown;
