import { ServerCard } from "@/components/cards/ServerCard";
import { NavigationToolbar } from "@/components/common/NavigationToolbar";
import ServerInviteList from "@/components/pages/inspector/InviteList";
import { fetchInvites, fetchServerById } from "@/lib/db";
import { notFound } from "next/navigation";

export default async function ServerInvites({ params }: { params: { id: string } }) {
    const server = await fetchServerById(params.id);
    if (!server) return notFound();

    const { invites, channels, users } = await fetchInvites({
      type: "Server",
      server: params.id,
    });

    return (
    <div className="flex flex-col gap-2">
      <NavigationToolbar>Inspecting Server Invites</NavigationToolbar>
      <ServerCard server={server} subtitle={`${invites.length} invite${invites.length == 1 ? '' : 's'}`} />
      <ServerInviteList invites={invites} server={server} channels={channels} users={users} />
    </div>
  )
}
