acupedia-store-ui/src/components/layout/StoreHeader.tsx

134 lines
6.0 KiB
TypeScript

import React from 'react';
import { Sparkles, LogIn, UserPlus, BookOpen, CheckCircle } from 'lucide-react';
import type { UserProfile } from '../../types';
interface StoreHeaderProps {
activeTab: 'storefront' | 'subscriptions' | 'logged-out';
onSwitchTab: (tab: 'storefront' | 'subscriptions' | 'logged-out') => void;
loggedInUser: UserProfile | null;
onOpenProfile: () => void;
onOpenAuth: (mode: 'login' | 'register') => void;
}
export const StoreHeader: React.FC<StoreHeaderProps> = ({
activeTab,
onSwitchTab,
loggedInUser,
onOpenProfile,
onOpenAuth,
}) => {
return (
<header className="w-full bg-[#0A0A0E] text-slate-300 border-b border-slate-800 px-4 sm:px-6 py-3 sm:py-4 shadow-lg flex-shrink-0">
<div className="flex items-center justify-between">
<div className="flex items-center gap-6">
<div
onClick={() => onSwitchTab('storefront')}
className="flex items-center gap-3 cursor-pointer group"
>
<div className="h-10 w-10 rounded-xl bg-gradient-to-tr from-indigo-500 to-cyan-400 flex items-center justify-center shadow-md shadow-indigo-500/20 group-hover:scale-105 transition-transform">
<Sparkles className="h-5 w-5 text-white" />
</div>
<div>
<h1 className="text-base font-black tracking-tight text-white flex items-center gap-1">
ACUPEDIA
</h1>
<p className="text-[9px] text-slate-400 font-bold tracking-widest uppercase">TCM PLATFORM</p>
</div>
</div>
{/* Desktop Navigation Tabs */}
<nav className="hidden sm:flex items-center bg-slate-900/80 border border-slate-800 rounded-xl p-1 gap-1">
<button
onClick={() => onSwitchTab('storefront')}
className={`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-bold transition-colors ${
activeTab === 'storefront'
? 'bg-indigo-600 text-white shadow-sm'
: 'text-slate-400 hover:text-slate-200'
}`}
>
<BookOpen className="h-3.5 w-3.5" /> Storefront
</button>
<button
onClick={() => onSwitchTab('subscriptions')}
className={`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-bold transition-colors ${
activeTab === 'subscriptions'
? 'bg-indigo-600 text-white shadow-sm'
: 'text-slate-400 hover:text-slate-200'
}`}
>
<CheckCircle className="h-3.5 w-3.5" /> My Subscriptions
{loggedInUser?.active_subscriptions && loggedInUser.active_subscriptions.length > 0 && (
<span className="bg-indigo-900 text-indigo-200 text-[10px] px-1.5 py-0.2 rounded-full ml-0.5">
{loggedInUser.active_subscriptions.length}
</span>
)}
</button>
</nav>
</div>
<div className="flex items-center gap-3">
{loggedInUser ? (
<button
onClick={onOpenProfile}
className="flex items-center gap-3 hover:text-white transition-colors group focus:outline-none"
>
<div className="text-right hidden sm:block">
<p className="text-xs font-bold text-white truncate max-w-[150px]">
{loggedInUser.display_name || loggedInUser.email}
</p>
</div>
<div className="h-9 w-9 rounded-lg bg-indigo-950/60 border border-indigo-500/30 flex items-center justify-center text-indigo-400 font-bold text-sm group-hover:border-indigo-400 transition-colors">
{(loggedInUser.display_name || loggedInUser.email || 'U')[0].toUpperCase()}
</div>
</button>
) : (
<div className="flex gap-2">
<button
onClick={() => onOpenAuth('login')}
className="flex items-center justify-center gap-1.5 px-3 py-1.5 rounded-xl text-xs font-bold bg-slate-800 hover:bg-slate-700 text-slate-300 transition-colors"
>
<LogIn className="h-3.5 w-3.5" /> Login
</button>
<button
onClick={() => onOpenAuth('register')}
className="flex items-center justify-center gap-1.5 px-3 py-1.5 rounded-xl text-xs font-bold bg-indigo-600 hover:bg-indigo-500 text-white transition-colors shadow shadow-indigo-600/10"
>
<UserPlus className="h-3.5 w-3.5" /> Join
</button>
</div>
)}
</div>
</div>
{/* Mobile Navigation Tabs */}
<nav className="sm:hidden flex items-center bg-slate-900/90 border border-slate-800 rounded-xl p-1 mt-3 gap-1 w-full">
<button
onClick={() => onSwitchTab('storefront')}
className={`flex-1 flex items-center justify-center gap-1.5 px-3 py-2 rounded-lg text-xs font-bold transition-colors ${
activeTab === 'storefront'
? 'bg-indigo-600 text-white shadow-sm'
: 'text-slate-400 hover:text-slate-200'
}`}
>
<BookOpen className="h-3.5 w-3.5" /> Storefront
</button>
<button
onClick={() => onSwitchTab('subscriptions')}
className={`flex-1 flex items-center justify-center gap-1.5 px-3 py-2 rounded-lg text-xs font-bold transition-colors ${
activeTab === 'subscriptions'
? 'bg-indigo-600 text-white shadow-sm'
: 'text-slate-400 hover:text-slate-200'
}`}
>
<CheckCircle className="h-3.5 w-3.5" /> My Subscriptions
{loggedInUser?.active_subscriptions && loggedInUser.active_subscriptions.length > 0 && (
<span className="bg-indigo-900 text-indigo-200 text-[10px] px-1.5 py-0.2 rounded-full ml-1 font-semibold">
{loggedInUser.active_subscriptions.length}
</span>
)}
</button>
</nav>
</header>
);
};