"use client"; import { useTheme } from "next-themes"; import { useEffect, useState } from "react"; import { motion } from "framer-motion"; import { Sun, Moon } from "lucide-react"; import { useSplitFlapAudio } from "@/components/ui/split-flap-text"; import { cn } from "@/lib/utils"; export function ThemeToggle() { const { resolvedTheme, setTheme } = useTheme(); const [mounted, setMounted] = useState(false); const audio = useSplitFlapAudio(); // Prevent hydration mismatch useEffect(() => { const frame = requestAnimationFrame(() => { setMounted(true); }); return () => cancelAnimationFrame(frame); }, []); if (!mounted) { return (
); } const isDark = resolvedTheme === "dark"; const handleToggle = (targetTheme: "light" | "dark") => { if (resolvedTheme === targetTheme) return; // Play satisfying mechanical click sound if (audio && !audio.isMuted) { audio.playClick(); } setTheme(targetTheme); }; return (
{/* Sliding background container (GPU accelerated via x transform) */} {/* Light Mode Button */} {/* Dark Mode Button */}
); }