import { useEffect, useState } from "react";
import { getInitialTheme, applyTheme, toggleTheme } from "../utils/theme";

interface UseThemeReturn {
    theme: string;
    toggleTheme: () => void;
}

export function useTheme(): UseThemeReturn {
    const [theme, setTheme] = useState<string>(getInitialTheme);

    useEffect(() => {
        applyTheme(theme);
    }, [theme]);

    const handleToggle = () => {
        setTheme((prev) => toggleTheme(prev));
    };

    return { theme, toggleTheme: handleToggle };
}
