"use client"
import { useTheme } from "next-themes"
import { useEffect, useState } from "react"
import { Button } from "@/components/ui/button"
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"
// Remove this import:
// import { Moon, Sun } from 'lucide-react'
// Add this import:
import { Sun, Moon } from "lucide-react"
export function ThemeToggle() {
const { setTheme, theme, resolvedTheme } = useTheme()
const [mounted, setMounted] = useState(false)
// Only render the toggle after mounting to avoid hydration mismatch
useEffect(() => {
setMounted(true)
}, [])
// Force theme update when theme changes
useEffect(() => {
if (!mounted) return
// Force theme update
const actualTheme = theme === "system" ? resolvedTheme || "light" : theme || "light"
// Remove both theme classes first
document.documentElement.classList.remove("light", "dark")
// Add the correct theme class
document.documentElement.classList.add(actualTheme)
document.documentElement.style.colorScheme = actualTheme
console.log("Theme toggled to:", theme, "Resolved theme:", actualTheme)
}, [theme, resolvedTheme, mounted])
if (!mounted) {
return (
)
}
return (
{
setTheme("light")
console.log("Setting theme to light")
}}
className="flex items-center text-xs px-2 py-1.5 cursor-pointer"
>
Light
{theme === "light" && ✓}
{
setTheme("dark")
console.log("Setting theme to dark")
}}
className="flex items-center text-xs px-2 py-1.5 cursor-pointer"
>
Dark
{theme === "dark" && ✓}
)
}