Spaces:
Sleeping
Sleeping
File size: 18,572 Bytes
049b896 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | import React, { useState } from 'react';
import { User, AppNotification } from '../types';
import { Menu, X, Bell, Search, Globe, Shield, User as UserIcon, LogOut, LayoutDashboard, ChevronDown } from 'lucide-react';
import { TRANSLATIONS, Language } from '../translations';
interface HeaderProps {
currentUser: User;
onLogout: () => void;
onLoginSimulate: () => void;
currentView: string;
setCurrentView: (view: string) => void;
notifications: AppNotification[];
onMarkNotificationRead: (id: string) => void;
onClearNotifications: () => void;
onSearch: (query: string) => void;
currentLanguage: string;
setLanguage: (lang: any) => void;
}
const LANGUAGES = [
{ code: 'UZ', name: "O'zbek" },
{ code: 'RU', name: "Русский" },
{ code: 'EN', name: "English" }
];
export const Header: React.FC<HeaderProps> = ({
currentUser,
onLogout,
onLoginSimulate,
currentView,
setCurrentView,
notifications,
onMarkNotificationRead,
onClearNotifications,
onSearch,
currentLanguage,
setLanguage,
}) => {
const [mobileMenuOpen, setMobileMenuOpen] = useState(false);
const [notifDropdownOpen, setNotifDropdownOpen] = useState(false);
const [langDropdownOpen, setLangDropdownOpen] = useState(false);
const [searchString, setSearchString] = useState('');
const unreadNotifs = notifications.filter((n) => !n.read);
const handleSearchSubmit = (e: React.FormEvent) => {
e.preventDefault();
onSearch(searchString);
};
const t = TRANSLATIONS[currentLanguage as Language] || TRANSLATIONS['EN'];
const navItems = [
{ id: 'home', label: t.navHome },
{ id: 'register', label: t.navRegister },
{ id: 'games', label: t.navGames },
{ id: 'pro-league', label: t.navProLeague },
{ id: 'results', label: t.navResults },
{ id: 'profile', label: t.navProfile },
];
return (
<header className="sticky top-0 z-40 bg-white/5 backdrop-blur-md border-b border-white/10 font-sans shadow-lg shadow-black/40">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div className="flex items-center justify-between h-20">
{/* Logo */}
<div className="flex items-center gap-2 cursor-pointer" onClick={() => { setCurrentView('home'); setMobileMenuOpen(false); }}>
<div className="w-10 h-10 rounded-xl bg-gradient-to-br from-cyan-400 to-purple-600 p-[1.5px] shadow-[0_0_15px_rgba(34,211,238,0.4)] active:scale-95 transition-transform">
<div className="w-full h-full bg-[#020205]/60 backdrop-blur-md rounded-[10px] flex items-center justify-center font-extrabold text-white text-lg tracking-wider font-mono">
<span className="text-cyan-400">N</span>E
</div>
</div>
<div>
<span className="text-lg font-black tracking-widest text-white uppercase font-mono bg-clip-text">
NOVA<span className="text-transparent bg-clip-text bg-gradient-to-r from-cyan-400 to-purple-500">ESPORTS</span>
</span>
<span className="block text-[9px] text-cyan-400 tracking-widest uppercase font-bold">{t.webPlatform}</span>
</div>
</div>
{/* Desktop Navigation Links */}
<nav className="hidden lg:flex space-x-1.5 xl:space-x-4">
{navItems.map((item) => (
<button
key={item.id}
onClick={() => {
setCurrentView(item.id);
setMobileMenuOpen(false);
}}
className={`px-3 py-2 rounded-lg text-xs font-bold tracking-wider uppercase transition-all duration-150 cursor-pointer ${
currentView === item.id
? 'bg-white/10 text-cyan-400 border border-white/20'
: 'text-slate-300 hover:text-white hover:bg-white/5'
}`}
id={`nav-${item.id}`}
>
{item.label}
</button>
))}
{/* Quick Clan Navigation indicator */}
{currentUser && currentUser.id !== 'guest' && (
<button
onClick={() => {
setCurrentView('clan');
setMobileMenuOpen(false);
}}
className={`px-3 py-2 rounded-lg text-xs font-bold tracking-wider uppercase transition-all duration-150 cursor-pointer flex items-center gap-1 border ${
currentView === 'clan'
? 'bg-purple-950/40 border-purple-500/50 text-purple-400'
: 'text-purple-400/80 border-white/10 hover:text-purple-300 hover:bg-white/5'
}`}
id="nav-clan"
>
<Shield className="w-3.5 h-3.5" />
{currentLanguage === 'UZ' ? 'Klan Yaratish' : currentLanguage === 'RU' ? 'Создать клан' : 'Clan Alliance'}
</button>
)}
</nav>
{/* Right Header Toolbar (Search, Notifications, Lang, Auth) */}
<div className="hidden lg:flex items-center space-x-3">
{/* Search Input Bar */}
<form onSubmit={handleSearchSubmit} className="relative">
<input
type="text"
placeholder={t.searchPlaceholder}
value={searchString}
onChange={(e) => {
setSearchString(e.target.value);
onSearch(e.target.value);
}}
className="w-40 xl:w-52 bg-white/5 hover:bg-white/10 focus:bg-white/10 border border-white/10 hover:border-white/20 focus:border-cyan-400 rounded-lg pl-3 pr-8 py-1.5 text-xs text-white outline-none focus:ring-1 focus:ring-cyan-500/30 transition-all font-sans"
/>
<button type="submit" className="absolute right-2.5 top-2 text-slate-400 hover:text-white cursor-pointer">
<Search className="w-3.5 h-3.5" />
</button>
</form>
{/* Notification Trigger Dropdown */}
<div className="relative">
<button
onClick={() => {
setNotifDropdownOpen(!notifDropdownOpen);
setLangDropdownOpen(false);
}}
className="p-2 text-slate-300 hover:text-white rounded-lg bg-white/5 border border-white/10 hover:bg-white/10 transition-colors cursor-pointer relative"
aria-label="Open notifications"
id="header-notif-bell"
>
<Bell className="w-4 h-4" />
{unreadNotifs.length > 0 && (
<span className="absolute top-1.5 right-1.5 w-2 h-2 rounded-full bg-red-500 animate-ping" />
)}
</button>
{/* Notification Box */}
{notifDropdownOpen && (
<div className="absolute right-0 mt-2.5 w-80 bg-slate-950/80 border border-white/10 rounded-xl shadow-2xl overflow-hidden backdrop-blur-md z-50 animate-in fade-in slide-in-from-top-2 duration-150">
<div className="p-3 bg-white/5 border-b border-white/10 flex justify-between items-center">
<span className="text-xs font-bold text-white tracking-wider font-mono">{t.telemetryTitle}</span>
{notifications.length > 0 && (
<button
onClick={onClearNotifications}
className="text-[10px] text-cyan-400 hover:text-cyan-300 transition-colors font-bold uppercase"
>
{t.flushAll}
</button>
)}
</div>
<div className="max-h-60 overflow-y-auto divide-y divide-white/10 custom-scrollbar">
{notifications.length === 0 ? (
<div className="p-6 text-center text-slate-500 text-xs">{t.noNotifs}</div>
) : (
notifications.map((notif) => (
<div
key={notif.id}
onClick={() => onMarkNotificationRead(notif.id)}
className={`p-3 text-left transition-colors cursor-pointer hover:bg-white/5 ${
!notif.read ? 'bg-cyan-400/10 border-l-2 border-cyan-400' : ''
}`}
>
<div className="flex justify-between items-start gap-1">
<span className="text-[11px] font-bold text-white">{notif.title}</span>
<span className="text-[9px] text-slate-500 shrink-0">{notif.time}</span>
</div>
<p className="text-[11px] text-slate-400 mt-1 font-sans">{notif.message}</p>
</div>
))
)}
</div>
</div>
)}
</div>
{/* Language Selector Dropdown */}
<div className="relative">
<button
onClick={() => {
setLangDropdownOpen(!langDropdownOpen);
setNotifDropdownOpen(false);
}}
className="px-2.5 py-1.5 text-xs text-slate-300 hover:text-white rounded-lg bg-white/5 border border-white/10 flex items-center gap-1.5 hover:bg-white/10 transition-colors cursor-pointer"
id="header-lang-trigger"
>
<Globe className="w-3.5 h-3.5" />
<span className="font-mono font-bold leading-none">{currentLanguage}</span>
<ChevronDown className="w-3 h-3 text-slate-500" />
</button>
{langDropdownOpen && (
<div className="absolute right-0 mt-2 w-32 bg-slate-950/80 border border-white/10 rounded-lg shadow-xl backdrop-blur-md overflow-hidden z-50">
<div className="py-1">
{LANGUAGES.map((lang) => (
<button
key={lang.code}
onClick={() => {
setLanguage(lang.code);
setLangDropdownOpen(false);
}}
className={`w-full text-left px-3 py-1.5 text-xs transition-colors flex items-center justify-between cursor-pointer ${
currentLanguage === lang.code ? 'text-cyan-400 bg-white/10 font-bold' : 'text-slate-300 hover:text-white hover:bg-white/5'
}`}
>
<span>{lang.name}</span>
<span className="text-[9px] font-mono text-slate-500">{lang.code}</span>
</button>
))}
</div>
</div>
)}
</div>
{/* User Profile Avatar / Action Button */}
{currentUser ? (
<div
onClick={() => setCurrentView('profile')}
className="flex items-center gap-2.5 pl-2.5 border-l border-white/15 py-1 hover:opacity-90 cursor-pointer"
>
<div className="text-right">
<span className="block text-xs font-bold text-slate-200 tracking-wide">{currentUser.username}</span>
<span className="block text-[10px] text-cyan-400 font-mono font-semibold">{currentUser.points} {t.playPoints}</span>
</div>
<div className="w-9 h-9 rounded-full bg-gradient-to-br from-cyan-400 to-purple-600 flex items-center justify-center text-sm font-bold shadow-md shadow-purple-600/15 overflow-hidden">
{currentUser.avatar && (currentUser.avatar.startsWith('http://') || currentUser.avatar.startsWith('https://')) ? (
<img src={currentUser.avatar} className="w-full h-full object-cover rounded-full" alt="avatar" referrerPolicy="no-referrer" />
) : (
<span>{currentUser.avatar || '👤'}</span>
)}
</div>
</div>
) : (
<button
onClick={onLoginSimulate}
className="bg-gradient-to-r from-cyan-600 to-cyan-500 text-white font-bold px-4 py-2 rounded-lg text-xs uppercase tracking-wide cursor-pointer transition-transform duration-100 hover:scale-105"
>
{t.gamerIn}
</button>
)}
</div>
{/* Mobile menu trigger */}
<div className="flex items-center lg:hidden gap-3">
{/* Quick Notify Bell for Mobile */}
<div className="relative">
<button
onClick={() => setCurrentView('profile')}
className="p-1.5 text-slate-300 hover:text-white rounded bg-white/5 border border-white/10 hover:bg-white/10"
>
<span className="relative inline-block">
<Bell className="w-4 h-4" />
{unreadNotifs.length > 0 && (
<span className="absolute -top-1 -right-1 w-2 h-2 rounded-full bg-red-500 shrink-0" />
)}
</span>
</button>
</div>
<button
onClick={() => setMobileMenuOpen(!mobileMenuOpen)}
className="text-slate-300 hover:text-inherit p-2 rounded transition-colors bg-white/5 border border-white/10 hover:bg-white/10 cursor-pointer"
aria-label="Toggle Menu"
>
{mobileMenuOpen ? <X className="w-6 h-6" /> : <Menu className="w-6 h-6" />}
</button>
</div>
</div>
</div>
{/* Mobile Drawer Navigation overlay */}
{mobileMenuOpen && (
<div className="lg:hidden bg-slate-950/80 backdrop-blur-md border-b border-white/10 p-5 space-y-4 animate-in fade-in duration-200">
<form onSubmit={handleSearchSubmit} className="relative">
<input
type="text"
placeholder={t.searchPlaceholder}
value={searchString}
onChange={(e) => {
setSearchString(e.target.value);
onSearch(e.target.value);
}}
className="w-full bg-white/5 border border-white/10 rounded-lg pl-3 pr-8 py-2 text-xs text-white outline-none focus:border-cyan-400"
/>
<button type="submit" className="absolute right-3 top-2.5 text-slate-400">
<Search className="w-4 h-4" />
</button>
</form>
<div className="flex flex-col space-y-2">
{navItems.map((item) => (
<button
key={item.id}
onClick={() => {
setCurrentView(item.id);
setMobileMenuOpen(false);
}}
className={`py-2 px-3 text-left rounded-lg text-xs font-bold tracking-wider uppercase transition-colors ${
currentView === item.id
? 'bg-white/10 text-cyan-400 border-l-4 border-cyan-400'
: 'text-slate-300 hover:bg-white/5'
}`}
>
{item.label}
</button>
))}
{currentUser && currentUser.id !== 'guest' && (
<button
onClick={() => {
setCurrentView('clan');
setMobileMenuOpen(false);
}}
className={`py-2 px-3 text-left rounded-lg text-xs font-bold tracking-wider uppercase text-purple-400 flex items-center gap-1.5 ${
currentView === 'clan' ? 'bg-purple-950/40 border-l-4 border-purple-500' : ''
}`}
>
<Shield className="w-3.5 h-3.5" />
{currentLanguage === 'UZ' ? 'Klan Yaratish' : currentLanguage === 'RU' ? 'Создать клан' : 'Clan Alliance'}
</button>
)}
</div>
<div className="border-t border-white/10 pt-4 flex items-center justify-between">
{currentUser ? (
<div className="flex items-center gap-2.5">
<div className="w-8 h-8 rounded-full bg-cyan-600 flex items-center justify-center text-xs font-bold text-white overflow-hidden">
{currentUser.avatar && (currentUser.avatar.startsWith('http://') || currentUser.avatar.startsWith('https://')) ? (
<img src={currentUser.avatar} className="w-full h-full object-cover rounded-full" alt="avatar" referrerPolicy="no-referrer" />
) : (
<span>{currentUser.avatar || '👤'}</span>
)}
</div>
<div>
<span className="block text-xs font-bold text-white">{currentUser.username}</span>
<span className="block text-[10px] text-cyan-450 text-cyan-400 font-mono font-semibold">{currentUser.points} {t.playPoints}</span>
</div>
</div>
) : (
<button
onClick={() => {
onLoginSimulate();
setMobileMenuOpen(false);
}}
className="w-full bg-cyan-600 text-white font-bold py-2 rounded text-xs uppercase"
>
{t.gamerIn}
</button>
)}
<div className="flex gap-2">
<button
onClick={() => {
const nextLang = currentLanguage === 'EN' ? 'UZ' : currentLanguage === 'UZ' ? 'RU' : 'EN';
setLanguage(nextLang);
}}
className="px-2 py-1 bg-white/5 border border-white/10 rounded text-[10px] text-slate-300 font-mono"
>
LANG: {currentLanguage}
</button>
{currentUser && (
<button
onClick={() => {
onLogout();
setMobileMenuOpen(false);
}}
className="p-1 px-2.5 bg-white/5 border border-white/10 hover:bg-white/10 text-slate-400 hover:text-white rounded flex items-center gap-1 text-[10px]"
>
<LogOut className="w-3 h-3" /> {t.exit}
</button>
)}
</div>
</div>
</div>
)}
</header>
);
};
|