"use client";
import { useLanguage } from "@/components/LanguageContext";
import { useEffect, useState } from "react";
import { motion } from "framer-motion";
import { useSplitFlapAudio } from "@/components/ui/split-flap-text";
import { cn } from "@/lib/utils";
export function LanguageToggle() {
const { language, toggleLanguage } = useLanguage();
const [mounted, setMounted] = useState(false);
const audio = useSplitFlapAudio();
// Prevent hydration mismatch
useEffect(() => {
const frame = requestAnimationFrame(() => {
setMounted(true);
});
return () => cancelAnimationFrame(frame);
}, []);
if (!mounted) {
return (
);
}
const isAr = language === "ar";
const handleToggle = (targetLang: "en" | "ar") => {
if (language === targetLang) return;
// Play satisfying mechanical click sound
if (audio && !audio.isMuted) {
audio.playClick();
}
toggleLanguage();
};
return (
{/* Sliding background container */}
{/* English Button */}
{/* Arabic Button */}
);
}