import { prisma } from "@/lib/db";
import HostsClient from "./client";

export const dynamic = "force-dynamic";

export default async function HostsPage() {
  const hosts = await prisma.host.findMany({
    orderBy: { createdAt: "desc" },
    include: { _count: { select: { agents: true } } },
  });
  return (
    <div className="space-y-4">
      <h1 className="text-xl font-semibold">Hosts</h1>
      <HostsClient initial={hosts.map((h) => ({
        id: h.id,
        name: h.name,
        host: h.host,
        port: h.port,
        username: h.username,
        authType: h.authType,
        hasAuth: !!(h.passwordEnc || h.privateKeyEnc),
        notes: h.notes,
        agents: h._count.agents,
        lastSeenAt: h.lastSeenAt?.toISOString() || null,
      }))} />
    </div>
  );
}
