"use client"; import { useTheme } from "@/components/theme-provider"; import { cn } from "@/lib/utils"; import { Moon, Sun } from "lucide-react"; import { useRef } from "react"; interface ThemeToggleProps { className?: string; } export function ThemeToggle({ className }: ThemeToggleProps) { const { theme } = useTheme(); const buttonRef = useRef(null); const toggleTheme = () => { // Instead of directly changing the theme, dispatch a custom event const newTheme = theme === "light" ? "dark" : "light"; // Dispatch custom event with the new theme window.dispatchEvent( new CustomEvent('themeToggleRequest', { detail: { theme: newTheme } }) ); }; return ( ); }