216 lines
8.9 KiB
TypeScript
216 lines
8.9 KiB
TypeScript
import React from 'react';
|
|
import { Share2, Globe, Send, Link2, History, Users, LogOut, Shield } from 'lucide-react';
|
|
import { SupportedLang, TRANSLATIONS } from '../data/translations';
|
|
import { AuthUser } from '../types/auth';
|
|
|
|
export type ActiveTab = 'studio' | 'connect' | 'history';
|
|
|
|
interface NavbarProps {
|
|
activeTab: ActiveTab;
|
|
setActiveTab: (tab: ActiveTab) => void;
|
|
lang: SupportedLang;
|
|
setLang: (lang: SupportedLang) => void;
|
|
connectedCount: number;
|
|
currentUser: AuthUser | null;
|
|
onOpenUserManager?: () => void;
|
|
onLogout?: () => void;
|
|
}
|
|
|
|
export const Navbar: React.FC<NavbarProps> = ({
|
|
activeTab,
|
|
setActiveTab,
|
|
lang,
|
|
setLang,
|
|
connectedCount,
|
|
currentUser,
|
|
onOpenUserManager,
|
|
onLogout
|
|
}) => {
|
|
const t = TRANSLATIONS[lang];
|
|
|
|
return (
|
|
<header className="sticky top-0 z-40 bg-slate-950/90 backdrop-blur-md border-b border-slate-800/80">
|
|
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
|
<div className="flex items-center justify-between h-16">
|
|
|
|
{/* Logo & Brand Name: Ecohub BD */}
|
|
<div
|
|
onClick={() => setActiveTab('studio')}
|
|
className="flex items-center gap-3 cursor-pointer group"
|
|
>
|
|
<div className="w-10 h-10 rounded-xl bg-gradient-to-tr from-emerald-500 via-teal-500 to-blue-600 flex items-center justify-center shadow-lg shadow-emerald-500/20 ring-1 ring-white/20 group-hover:scale-105 transition-transform">
|
|
<Share2 className="w-5 h-5 text-white" />
|
|
</div>
|
|
<div>
|
|
<div className="flex items-center gap-2">
|
|
<span className="font-extrabold text-lg tracking-tight text-white">
|
|
Ecohub <span className="text-emerald-400">BD</span>
|
|
</span>
|
|
<span className="px-2 py-0.5 text-[10px] font-bold tracking-wider uppercase bg-emerald-500/10 text-emerald-400 border border-emerald-500/30 rounded-full">
|
|
Studio Pro
|
|
</span>
|
|
</div>
|
|
<p className="text-[11px] text-slate-400 hidden sm:block truncate max-w-xs">
|
|
{t.tagline}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Clean Navigation Tabs */}
|
|
<nav className="hidden md:flex items-center gap-1 bg-slate-900/80 p-1 rounded-xl border border-slate-800">
|
|
<button
|
|
onClick={() => setActiveTab('studio')}
|
|
className={`flex items-center gap-2 px-3.5 py-1.5 rounded-lg text-xs font-semibold transition-all ${
|
|
activeTab === 'studio'
|
|
? 'bg-emerald-600 text-white shadow-sm shadow-emerald-600/30'
|
|
: 'text-slate-400 hover:text-slate-200 hover:bg-slate-800/50'
|
|
}`}
|
|
>
|
|
<Send className="w-4 h-4" />
|
|
<span>{t.nav.studio}</span>
|
|
</button>
|
|
|
|
<button
|
|
onClick={() => setActiveTab('connect')}
|
|
className={`flex items-center gap-2 px-3.5 py-1.5 rounded-lg text-xs font-semibold transition-all relative ${
|
|
activeTab === 'connect'
|
|
? 'bg-emerald-600 text-white shadow-sm shadow-emerald-600/30'
|
|
: 'text-slate-400 hover:text-slate-200 hover:bg-slate-800/50'
|
|
}`}
|
|
>
|
|
<Link2 className="w-4 h-4" />
|
|
<span>{t.nav.connect}</span>
|
|
<span className="w-2 h-2 rounded-full bg-emerald-400 animate-pulse" />
|
|
</button>
|
|
|
|
<button
|
|
onClick={() => setActiveTab('history')}
|
|
className={`flex items-center gap-2 px-3.5 py-1.5 rounded-lg text-xs font-semibold transition-all ${
|
|
activeTab === 'history'
|
|
? 'bg-emerald-600 text-white shadow-sm shadow-emerald-600/30'
|
|
: 'text-slate-400 hover:text-slate-200 hover:bg-slate-800/50'
|
|
}`}
|
|
>
|
|
<History className="w-4 h-4" />
|
|
<span>{t.nav.history}</span>
|
|
</button>
|
|
</nav>
|
|
|
|
{/* Right Controls: User Profile + Language Switcher + Logout */}
|
|
<div className="flex items-center gap-2 sm:gap-2.5">
|
|
|
|
{/* Authenticated User Status & Role */}
|
|
{currentUser && (
|
|
<div className="flex items-center gap-2 bg-slate-900 border border-slate-800 rounded-xl p-1 pr-2.5">
|
|
<img
|
|
src={currentUser.avatarUrl || `https://api.dicebear.com/7.x/initials/svg?seed=${currentUser.username}`}
|
|
alt={currentUser.name}
|
|
className="w-7 h-7 rounded-lg object-cover ring-1 ring-white/10 shrink-0"
|
|
/>
|
|
<div className="hidden sm:block text-left">
|
|
<div className="flex items-center gap-1.5">
|
|
<span className="text-xs font-bold text-white leading-none">{currentUser.username}</span>
|
|
<span
|
|
className={`px-1.5 py-0.2 rounded text-[9px] font-bold uppercase font-mono ${
|
|
currentUser.role === 'admin'
|
|
? 'bg-purple-500/20 text-purple-300 border border-purple-500/30'
|
|
: 'bg-blue-500/20 text-blue-300 border border-blue-500/30'
|
|
}`}
|
|
>
|
|
{currentUser.role === 'admin' ? 'Admin' : 'Publisher'}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Admin-only: Users management modal button */}
|
|
{currentUser.role === 'admin' && onOpenUserManager && (
|
|
<button
|
|
onClick={onOpenUserManager}
|
|
className="p-1.5 rounded-lg bg-slate-800 hover:bg-slate-700 text-emerald-400 hover:text-emerald-300 transition-colors ml-1"
|
|
title={lang === 'bn' ? 'ব্যবহারকারী পরিচালনা' : 'Manage Users'}
|
|
>
|
|
<Users className="w-3.5 h-3.5" />
|
|
</button>
|
|
)}
|
|
|
|
{/* Logout button */}
|
|
{onLogout && (
|
|
<button
|
|
onClick={onLogout}
|
|
className="p-1.5 rounded-lg text-slate-400 hover:text-rose-400 hover:bg-rose-500/10 transition-colors ml-0.5"
|
|
title={lang === 'bn' ? 'লগআউট' : 'Logout'}
|
|
>
|
|
<LogOut className="w-3.5 h-3.5" />
|
|
</button>
|
|
)}
|
|
</div>
|
|
)}
|
|
|
|
{/* Language Selector: EN | বাংলা | 中文 */}
|
|
<div className="flex items-center bg-slate-900 p-0.5 rounded-xl border border-slate-800">
|
|
<button
|
|
onClick={() => setLang('en')}
|
|
className={`px-2 py-1 rounded-lg text-xs font-semibold transition-colors ${
|
|
lang === 'en' ? 'bg-emerald-600 text-white' : 'text-slate-400 hover:text-slate-200'
|
|
}`}
|
|
title="English"
|
|
>
|
|
EN
|
|
</button>
|
|
<button
|
|
onClick={() => setLang('bn')}
|
|
className={`px-2 py-1 rounded-lg text-xs font-semibold transition-colors ${
|
|
lang === 'bn' ? 'bg-emerald-600 text-white' : 'text-slate-400 hover:text-slate-200'
|
|
}`}
|
|
title="বাংলা (Bengali)"
|
|
>
|
|
বাংলা
|
|
</button>
|
|
<button
|
|
onClick={() => setLang('zh')}
|
|
className={`px-2 py-1 rounded-lg text-xs font-semibold transition-colors ${
|
|
lang === 'zh' ? 'bg-emerald-600 text-white' : 'text-slate-400 hover:text-slate-200'
|
|
}`}
|
|
title="简体中文 (Chinese)"
|
|
>
|
|
中文
|
|
</button>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{/* Mobile Navigation bar */}
|
|
<div className="flex md:hidden overflow-x-auto py-2 gap-1 border-t border-slate-800/80 no-scrollbar">
|
|
<button
|
|
onClick={() => setActiveTab('studio')}
|
|
className={`px-3 py-1 rounded-lg text-xs font-medium whitespace-nowrap ${
|
|
activeTab === 'studio' ? 'bg-emerald-600 text-white' : 'text-slate-400'
|
|
}`}
|
|
>
|
|
{t.nav.studio}
|
|
</button>
|
|
<button
|
|
onClick={() => setActiveTab('connect')}
|
|
className={`px-3 py-1 rounded-lg text-xs font-medium whitespace-nowrap ${
|
|
activeTab === 'connect' ? 'bg-emerald-600 text-white' : 'text-slate-400'
|
|
}`}
|
|
>
|
|
{t.nav.connect}
|
|
</button>
|
|
<button
|
|
onClick={() => setActiveTab('history')}
|
|
className={`px-3 py-1 rounded-lg text-xs font-medium whitespace-nowrap ${
|
|
activeTab === 'history' ? 'bg-emerald-600 text-white' : 'text-slate-400'
|
|
}`}
|
|
>
|
|
{t.nav.history}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
);
|
|
};
|
|
|