import { auth } from "@/lib/auth";
import { userService } from "@/services/users/user.service";
import Navigation from "./Navigation";

interface UserData {
  username: string;
  avatar: string | null;
  hp: number;
  maxHp: number;
  xp: number;
  maxXp: number;
  level: number;
}

export default async function NavigationWrapper() {
  const session = await auth();

  let userData: UserData | null = null;
  const isAdmin = session?.user?.role === "ADMIN";

  if (session?.user?.id) {
    const user = await userService.getUserById(session.user.id, {
      username: true,
      avatar: true,
      hp: true,
      maxHp: true,
      xp: true,
      maxXp: true,
      level: true,
    });

    if (user) {
      userData = user;
    }
  }

  return <Navigation initialUserData={userData} initialIsAdmin={isAdmin} />;
}
