"use client" import { Bell, Gamepad2, LogOut, Menu, MessageSquare, Search, Settings, ShoppingBag, User, Wallet, } from "lucide-react" import Link from "next/link" import { usePathname, useRouter } from "next/navigation" import { useState } from "react" import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar" import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" import { Input } from "@/components/ui/input" import { Sheet, SheetContent, SheetHeader, SheetTitle, SheetTrigger } from "@/components/ui/sheet" import { currentUser, mockShops } from "@/lib/mock" import type { UserRole } from "@/lib/types" import { cn } from "@/lib/utils" import { useAuthStore } from "@/store/auth" import { useNotificationStore } from "@/store/notifications" const roleLabels: Record = { consumer: "消费者", player: "打手", owner: "店主", } export function Header() { const [mobileOpen, setMobileOpen] = useState(false) const pathname = usePathname() const router = useRouter() const { isAuthenticated, currentRole, verifiedRoles, switchRole, logout } = useAuthStore() const navLinks = currentRole === "consumer" ? [ { href: "/", label: "首页" }, { href: "/search", label: "找陪玩" }, { href: "/community", label: "社区" }, { href: "/chat", label: "消息" }, ] : [ { href: "/", label: "首页" }, { href: "/community", label: "社区" }, { href: "/orders", label: "订单" }, { href: "/chat", label: "消息" }, { href: "/dashboard", label: "管理后台" }, ] const availableRoles = (Object.entries(roleLabels) as [UserRole, string][]).filter(([role]) => verifiedRoles.includes(role), ) const handleRoleSwitch = (role: UserRole) => { switchRole(role) router.push(role === "consumer" ? "/" : "/dashboard") setMobileOpen(false) } const unreadCount = useNotificationStore( (state) => state.notifications.filter((notification) => !notification.read).length, ) const handleSearch = (e: React.FormEvent) => { e.preventDefault() const formData = new FormData(e.currentTarget) const q = formData.get("q") as string if (q.trim()) router.push(`/search?q=${encodeURIComponent(q.trim())}`) } return (
聚玩
{isAuthenticated ? ( <> 切换身份 {availableRoles.map(([role, label]) => ( handleRoleSwitch(role)} className={cn(currentRole === role && "bg-accent")} > {label} ))} {currentUser.nickname} s.owner.id === currentUser.id)?.id ?? "shop1"}` : `/user/${currentUser.id}` } > 个人主页 我的订单 消息 钱包 {(currentRole === "player" || currentRole === "owner") && ( 管理后台 )} 设置 退出登录 ) : (
)} 聚玩
{isAuthenticated && (
{currentUser.nickname[0]}

{currentUser.nickname}

{roleLabels[currentRole]}

)} {isAuthenticated && (

切换身份

{availableRoles.map(([role, label]) => ( ))}
)} {!isAuthenticated && (
)}
) }