import { useEffect, useState } from 'react';
import styles from './styles.module.scss';

function CountdownTimer() {
    const [timeLeft, setTimeLeft] = useState<number>(600); // 10 минут в секундах

    useEffect(() => {
        const timer = setInterval(() => {
            setTimeLeft((prevTime) => {
                if (prevTime <= 0) {
                    clearInterval(timer);
                    return 0;
                }
                return prevTime - 1;
            });
        }, 1000);

        return () => clearInterval(timer);
    }, []);

    const minutes = Math.floor(timeLeft / 60);
    const seconds = timeLeft % 60;

    return (
        <span className={styles.timer}>
            Reserved for {String(minutes).padStart(2, '0')}:{String(seconds).padStart(2, '0')}
        </span>
    );
}

export default CountdownTimer;