import { Menu, Moon, Search, Sun, X } from 'lucide-react'; import React, { useEffect, useState } from 'react'; import { t } from '../../i18n/translations'; import { localizedPath, switchLocalePath, type Locale } from '../../i18n/types'; import { formatStars, useLatestRelease } from '../../lib/releases'; import { SearchModal } from './SearchModal'; interface Props { locale: Locale; pathname: string; activeSection: string; } export const HeaderControls: React.FC = ({ locale, pathname, activeSection }) => { const strings = t(locale); const { data: release } = useLatestRelease(); const [dark, setDark] = useState(false); const [searchOpen, setSearchOpen] = useState(false); const [mobileOpen, setMobileOpen] = useState(false); useEffect(() => { const syncTheme = () => setDark(document.documentElement.getAttribute('data-theme') === 'dark'); syncTheme(); const onKey = (e: KeyboardEvent) => { if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'k') { e.preventDefault(); setSearchOpen((v) => !v); } }; document.addEventListener('astro:after-swap', syncTheme); window.addEventListener('keydown', onKey); return () => { document.removeEventListener('astro:after-swap', syncTheme); window.removeEventListener('keydown', onKey); }; }, []); const toggleTheme = () => { const next = !dark; setDark(next); document.documentElement.setAttribute('data-theme', next ? 'dark' : 'light'); try { localStorage.setItem('reims-landing-theme', next ? 'dark' : 'light'); } catch { // Ignore storage failures. } }; const targetLocale: Locale = locale === 'zh-CN' ? 'en-US' : 'zh-CN'; const langHref = switchLocalePath(pathname, targetLocale); const navItems = [ { key: 'features', label: strings.nav.features, href: localizedPath(locale, '/') }, { key: 'docs', label: strings.nav.docs, href: localizedPath(locale, '/docs/quick-start') }, { key: 'plugins', label: strings.nav.plugins, href: localizedPath(locale, '/plugins') }, { key: 'compatibility', label: strings.nav.compatibility, href: localizedPath(locale, '/compatibility') }, { key: 'changelog', label: strings.nav.changelog, href: localizedPath(locale, '/changelog') }, ]; return ( <>
{strings.nav.langSwitchLabel} {strings.nav.starPrefix} {formatStars(release.stars)}
{mobileOpen && (
)} ); };