import React, { useState, useEffect, useRef } from 'react' import type { CSSProperties } from 'react' import { NavLink } from 'react-router-dom' import { Search, Menu, X, ChevronDown, Radar, Leaf, Globe, Cpu, BarChart3, Video, Mic, CalendarDays, Users, Eye, Phone, type LucideIcon } from 'lucide-react' import { motion, AnimatePresence } from 'framer-motion' import { useLang } from '@/context/LangContext' /* ─── tokens ─── */ const T = { paper: 'var(--paper)', paper2: 'var(--paper-2)', ink: 'var(--ink)', ink3: 'var(--ink-3)', ink4: 'var(--ink-4)', ink5: 'var(--ink-5)', ruleThin: 'var(--rule-thin)', red: 'var(--red)', } as const type Section = { fa: string; en: string; to: string; Icon: LucideIcon } /* ─── dropdown sections under رادار آینده ─── */ const SECTIONS: Section[] = [ { fa: 'آینده‌پژوهی و رصد هوشمند', en: 'Foresight & Intelligence', to: '/radar/foresight', Icon: Radar }, { fa: 'پایداری و فولاد سبز', en: 'Sustainability & Green Steel', to: '/radar/sustainability', Icon: Leaf }, { fa: 'ژئوپلیتیک و اقتصاد جهانی', en: 'Geopolitics & Global Economy', to: '/radar/geopolitics', Icon: Globe }, { fa: 'فناوری و نوآوری', en: 'Technology & Innovation', to: '/radar/technology', Icon: Cpu }, { fa: 'بازار و زنجیره فولاد', en: 'Market & Steel Chain', to: '/radar/market', Icon: BarChart3 }, ] /* ─── dropdown sections under رسانه و رویداد ─── */ const MEDIA: Section[] = [ { fa: 'ویدیوکست و پادکست', en: 'Videocast & Podcast', to: '#', Icon: Video }, { fa: 'نشست‌های تخصصی', en: 'Expert Sessions', to: '#', Icon: Mic }, { fa: 'رویدادها', en: 'Events', to: '#', Icon: CalendarDays }, ] /* ─── dropdown sections under درباره ما ─── */ const ABOUT: Section[] = [ { fa: 'تیم ما', en: 'Our Team', to: '/about#team', Icon: Users }, { fa: 'چشم‌انداز ما', en: 'Our Vision', to: '/about#vision', Icon: Eye }, { fa: 'تماس با ما', en: 'Contact Us', to: '/contact', Icon: Phone }, ] /* ─── top-level nav items ─── */ type TopNav = { fa: string; en: string; to?: string; dropdown?: 'radar' | 'media' | 'about' } const TOP_NAV: TopNav[] = [ { fa: 'رادار آینده', en: 'Radar', dropdown: 'radar' }, { fa: 'آمار و داده', en: 'Stats & Data', to: '/pulse' }, { fa: 'در یک نگاه', en: 'At a Glance', to: '/at-a-glance' }, { fa: 'رسانه و رویداد', en: 'Media & Events', dropdown: 'media' }, { fa: 'شبکه خبرگان', en: 'Expert Network', to: '/experts' }, { fa: 'درباره ما', en: 'About', dropdown: 'about' }, ] const META_LEFT: { fa: string; en: string }[] = [ { fa: 'درباره ما', en: 'About' }, { fa: 'کارشناسان', en: 'Experts' }, { fa: 'همکاری', en: 'Careers' }, { fa: 'رسانه', en: 'Press' }, ] /* ─── generic nav dropdown card ─── */ function NavDropdown({ lang, label, sections }: { lang: 'fa' | 'en'; label: string; sections: Section[] }) { const [open, setOpen] = useState(false) const ref = useRef(null) useEffect(() => { const handler = (e: MouseEvent) => { if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false) } document.addEventListener('mousedown', handler) return () => document.removeEventListener('mousedown', handler) }, []) return (
{open && ( {sections.map((item, i) => ( setOpen(false)} style={(): CSSProperties => ({ display: 'flex', alignItems: 'center', gap: 12, padding: '15px 20px', textDecoration: 'none', color: '#3d3d3d', background: 'transparent', borderBottom: i < sections.length - 1 ? '1px solid rgba(7,29,73,0.07)' : 'none', transition: 'background 100ms', fontSize: 14, fontWeight: 600, })} onMouseEnter={e => { (e.currentTarget as HTMLElement).style.background = 'rgba(7,29,73,0.03)' }} onMouseLeave={e => { (e.currentTarget as HTMLElement).style.background = 'transparent' }} > {lang === 'fa' ? item.fa : item.en} ))} )}
) } /* ─── plain nav item with chevron ─── */ function PlainNavItem({ label, to }: { label: string; to: string }) { const [hovered, setHovered] = useState(false) const style: CSSProperties = { display: 'flex', alignItems: 'center', gap: 4, fontSize: 13, fontWeight: 600, color: hovered ? T.ink : T.ink3, textDecoration: 'none', padding: '6px 0', whiteSpace: 'nowrap', transition: 'color 120ms', borderBottom: '2px solid transparent', } const handlers = { onMouseEnter: () => setHovered(true), onMouseLeave: () => setHovered(false), } // internal app route → client-side nav; otherwise plain anchor (hash / external) const isInternal = to.startsWith('/') return isInternal ? ( {label} ) : ( {label} ) } /* ─── drawer item ─── */ function DrawerNavItem({ to, label, onClose }: { to: string; label: string; onClose: () => void }) { const [hovered, setHovered] = useState(false) return ( setHovered(true)} onMouseLeave={() => setHovered(false)} style={({ isActive }: { isActive: boolean }): CSSProperties => ({ display: 'block', padding: '13px 20px', fontSize: 14, fontWeight: 600, color: isActive || hovered ? T.paper : T.ink, background: isActive ? T.ink : hovered ? T.paper2 : 'transparent', textDecoration: 'none', borderBottom: `1px solid ${T.ruleThin}`, transition: 'background 120ms, color 120ms', })} > {label} ) } /* ─── MAIN ─── */ export default function Header() { const [mobileOpen, setMobileOpen] = useState(false) const [isMobile, setIsMobile] = useState(false) const [searchOpen, setSearchOpen] = useState(false) const searchInputRef = useRef(null) const { lang, toggle: toggleLang } = useLang() useEffect(() => { const mq = window.matchMedia('(max-width: 1023px)') const handler = (e: MediaQueryListEvent | MediaQueryList) => setIsMobile(e.matches) handler(mq); mq.addEventListener('change', handler) return () => mq.removeEventListener('change', handler) }, []) useEffect(() => { document.body.style.overflow = mobileOpen ? 'hidden' : '' return () => { document.body.style.overflow = '' } }, [mobileOpen]) useEffect(() => { if (searchOpen) searchInputRef.current?.focus() }, [searchOpen]) return (
{/* Brand */}
اندیشکده فولاد آینده The Steel Futures Institute
{/* Desktop Nav */} {!isMobile && ( )} {/* Actions */}
{!isMobile && ( <> {lang === 'fa' ? 'ورود / ثبت‌نام' : 'Login / Register'} )} {isMobile && ( )}
{/* Search */} {searchOpen && (
e.key === 'Escape' && setSearchOpen(false)} style={{ width: '100%', border: `1px solid ${T.ink}`, padding: '12px 16px', fontSize: 14, background: T.paper, color: T.ink, outline: 'none', borderRadius: 0, fontFamily: 'inherit', direction: 'rtl', }} />
)}
{/* Mobile Drawer */} {mobileOpen && ( <> setMobileOpen(false)} style={{ position: 'fixed', inset: 0, background: 'rgba(7,29,73,0.55)', zIndex: 100 }} />
اندیشکده فولاد آینده
{lang === 'fa' ? 'اشتراک سازمانی' : 'Membership'} {lang === 'fa' ? 'ورود' : 'Login'}
{META_LEFT.map(item => ( {lang === 'fa' ? item.fa : item.en} ))}
)}
) } /* ─── buttons ─── */ function RedCtaButton({ children, style: extraStyle }: { children: React.ReactNode; style?: CSSProperties }) { const [hovered, setHovered] = useState(false) return ( ) } function OutlineButton({ children, style: extraStyle }: { children: React.ReactNode; style?: CSSProperties }) { const [hovered, setHovered] = useState(false) return ( ) }