/**
 * Main Application Component
 * 主应用组件
 */

import { useLocation, useNavigate } from "react-router-dom";
import { useMemo } from "react";
import { AppRoutes } from "./routes/AppRoutes";
import { useAuth } from "./providers";
import { getNavItems } from "./constants/navigation";

/**
 * Application root component
 * Manages routing and global state
 */
export default function App() {
  const location = useLocation();
  const navigate = useNavigate();
  const { isAuthenticated, login, logout, user } = useAuth();

  // Generate navigation items based on current location
  const navItems = useMemo(
    () => getNavItems(location.pathname, navigate, user),
    [location.pathname, navigate, user]
  );
  const displayName = user?.workspaceName
    ? `${user.username || "User"} · ${user.workspaceName}`
    : user?.username || "User";

  return (
    <AppRoutes
      isAuthenticated={isAuthenticated}
      userName={displayName}
      user={user}
      navItems={navItems}
      onLogin={login}
      onLogout={logout}
    />
  );
}

