"use client"; import { useEffect, useState } from "react"; import { useRouter } from "next/navigation"; import { useI18n } from "@/lib/i18n/useI18n"; const THEME_COOKIE = "mis_theme"; const SunIcon = ({ className }: { className?: string }) => ( ); const MoonIcon = ({ className }: { className?: string }) => ( ); type UtilityControlsProps = { className?: string; }; export function UtilityControls({ className }: UtilityControlsProps) { const router = useRouter(); const { locale, setLocale, t } = useI18n(); const [theme, setTheme] = useState<"dark" | "light">("dark"); useEffect(() => { const current = document.documentElement.getAttribute("data-theme"); if (current === "light" || current === "dark") { setTheme(current); } }, []); function applyTheme(next: "light" | "dark") { document.documentElement.setAttribute("data-theme", next); document.cookie = `${THEME_COOKIE}=${next}; Path=/; Max-Age=31536000; SameSite=Lax`; setTheme(next); } function toggleTheme() { applyTheme(theme === "light" ? "dark" : "light"); } function switchLocale(nextLocale: "en" | "es-MX") { setLocale(nextLocale); router.refresh(); } return (