import { DashboardShell } from '../../../components/dashboard-shell';
import { UsersManagementBoard } from '../../../components/users-management-board';
import { requireAuthToken } from '../../../lib/auth';
import { fetchRoles, fetchUsers } from '../../../lib/api';

export default async function UsersPage() {
  const token = await requireAuthToken();
  const [users, roles] = await Promise.all([fetchUsers(token, { page: 1, limit: 10 }), fetchRoles(token)]);

  return (
    <DashboardShell currentPath="/dashboard/users">
      <UsersManagementBoard
        initialUsers={users.items}
        initialTotal={users.total}
        initialPage={users.page}
        initialPageSize={users.pageSize}
        initialTotalPages={users.totalPages}
        availableRoles={roles.map((role) => ({
          id: role.id,
          name: role.name,
        }))}
      />
    </DashboardShell>
  );
}
