import type { JSX } from "react"

import { getMessages } from "@/modules/messaging/data-access"
import { MessageList } from "@/modules/messaging/components/message-list"

/**
 * P2-9: 消息列表区块（Server Component）。
 *
 * 独立获取数据，配合 Suspense + ErrorBoundary 实现流式渲染：
 * - 页面立即渲染，此区块异步加载
 * - 加载中显示 MessageListSkeleton
 * - 加载失败由 SectionErrorBoundary 捕获，不影响其他区块
 */
export async function MessageListSection({
  userId,
  canGroupSend = false,
}: {
  userId: string
  canGroupSend?: boolean
}): Promise<JSX.Element> {
  const result = await getMessages({ userId, type: "all", page: 1, pageSize: 50 })
  return <MessageList messages={result.items} currentUserId={userId} canGroupSend={canGroupSend} />
}
