"use client" import { Moon, Sun, Check, SunMoon } from "lucide-react" import { useTheme } from "next-themes" import { useEffect, useState } from "react" import { authClient } from "@/lib/auth/auth-client" import { Button } from "@/components/ui/button" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" import { cn } from "@/lib/utils" const themes = [ { id: "light", icon: Sun, label: "Light" }, { id: "dark", icon: Moon, label: "Dark" }, { id: "system", icon: SunMoon, label: "System" }, ] as const export function ModeToggle() { const { theme } = useTheme() const [mounted, setMounted] = useState(false) useEffect(() => setMounted(true), []) const handleThemeChange = async (newTheme: "light" | "system" | "dark") => { await authClient.updateUser({ theme: newTheme }) } return ( {themes.map((t) => { const ThemeIcon = t.icon const isActive = theme === t.id return ( handleThemeChange(t.id)} className={cn( "group gap-2 p-2 cursor-pointer rounded-lg mb-1 last:mb-0 transition-colors", isActive ? "bg-primary/10 text-primary border border-primary/20" : "focus:bg-accent hover:bg-accent/50 border border-transparent" )} >
{t.label} {isActive && (
)}
) })}
) }