'use client';
/**
 * UserBadge — 顶部右上角当前用户
 * 只显示名称和角色，不显示 token 余额
 */
import { useAuthStore } from '@/stores/authStore';
import { useRouter } from 'next/navigation';

const ROLE_LABELS: Record<string, string> = {
  admin: '管理员',
  supervisor: '组长',
  operator: '运营',
};

export default function UserBadge() {
  const { user, role, logout } = useAuthStore();
  const router = useRouter();

  if (!user) return null;

  function handleLogout() {
    logout();
    router.replace('/login');
  }

  return (
    <div className="flex items-center gap-3">
      <span className="text-white text-sm">
        {role ? ROLE_LABELS[role] : ''} · {user.username}
      </span>
      <button
        onClick={handleLogout}
        aria-label="退出登录"
        className="text-white/80 text-xs hover:text-white transition-colors"
      >
        退出
      </button>
    </div>
  );
}
