'use client';

import DashboardPage from './pages/DashboardPage.js';
import UsersPage from './pages/UsersPage.js';
import UserEditPage from './pages/UserEditPage.js';
import ProfilePage from './pages/ProfilePage.js';
import RolesPage from './pages/RolesPage.js';
import RoleEditPage from './pages/RoleEditPage.js';

export default function AdminPagesClient({ params, user, dashboardStats = null }) {
  const parts = params?.admin || [];
  const page = parts[0] || 'dashboard';

  if (page === 'users' && parts[1] === 'edit' && parts[2]) {
    return <UserEditPage userId={parts[2]} user={user} />;
  }

  if (page === 'roles' && parts[1] === 'edit' && parts[2]) {
    return <RoleEditPage roleId={parts[2]} user={user} />;
  }

  if (page === 'roles' && parts[1] === 'new') {
    return <RoleEditPage roleId="new" user={user} />;
  }

  const corePages = {
    dashboard: () => <DashboardPage user={user} stats={dashboardStats} />,
    users: () => <UsersPage user={user} />,
    profile: () => <ProfilePage user={user} />,
    roles: () => <RolesPage user={user} />,
  };

  const CorePageComponent = corePages[page];
  return CorePageComponent ? <CorePageComponent /> : <DashboardPage user={user} stats={dashboardStats} />;
}
