import { redirect } from "next/navigation";

import { auth } from "@/auth";
import { getAiSettingsView } from "@/lib/ai-settings";
import { ChatPageClient } from "@/components/chat/chat-page-client";

export default async function ChatPage() {
  const session = await auth();
  if (!session?.user) redirect("/login");

  const aiSettings = await getAiSettingsView();
  const aiConfigured = !!(aiSettings.apiUrl && aiSettings.model);

  // No board data fetched here -- sendChatMessage (lib/actions/chat-ai.ts)
  // gathers and re-serializes the user's full context itself on every
  // turn, so this page only needs the aiConfigured gate.
  return <ChatPageClient aiConfigured={aiConfigured} />;
}
