"use client"; import { createContext, useContext, useState, type ReactNode } from "react"; import type { Locale } from "@/core/i18n"; export interface I18nContextType { locale: Locale; setLocale: (locale: Locale) => void; } export const I18nContext = createContext(null); export function I18nProvider({ children, initialLocale, }: { children: ReactNode; initialLocale: Locale; }) { const [locale, setLocale] = useState(initialLocale); const handleSetLocale = (newLocale: Locale) => { setLocale(newLocale); document.cookie = `locale=${newLocale}; path=/; max-age=31536000`; }; return ( {children} ); } export function useI18nContext() { const context = useContext(I18nContext); if (!context) { throw new Error("useI18n must be used within I18nProvider"); } return context; }