import { createContext, useContext, useState } from "react"

export const CountdownContext = createContext<{
    countdown: number;
    setCountdown: (countdown: number) => void;
}>({
    countdown: 0,
    setCountdown: () => {}
})

export const useCountdown = () => {
    const ctx = useContext(CountdownContext);
    if (!ctx) throw new Error("useCountdown 必须在 CountdownProvider 内部使用");
    return ctx;
}

export const CountdownProvider = ({ children }: { children: React.ReactNode }) => {
    const [countdown, setCountdown] = useState(0);

    return (
        <CountdownContext.Provider value={{ countdown, setCountdown }}>
            {children}
        </CountdownContext.Provider>
    )
}