import { jsxs as _jsxs } from "react/jsx-runtime";
/*
 * Copyright (c) 2023-2025 Datalayer, Inc.
 * Distributed under the terms of the Modified BSD License.
 */
import { useState, useEffect } from 'react';
import { Text } from '@primer/react';
/**
 * Timer displaying the time as text.
 *
 * Duration should be provided in seconds.
 */
export function Timer(props) {
    const [remaining, setRemaining] = useState(props.duration);
    useEffect(() => {
        setRemaining(props.duration);
    }, [props.duration]);
    useEffect(() => {
        const timeoutIndex = setTimeout(() => {
            setRemaining(remaining - 1);
        }, 1000);
        return () => {
            clearTimeout(timeoutIndex);
        };
    }, [remaining]);
    return _jsxs(Text, { as: "span", children: [remaining.toFixed(0), "s"] });
}
export default Timer;
