import { RealtimeRefresh } from "@/components/app-runtime";
import {
  AppShell,
  ConversationList,
  PageNav,
  StatusBar,
} from "@/components/app-ui";
import { requirePageSession } from "@/lib/boss-auth";
import { getConversationFolderView } from "@/lib/boss-projections";
import { readState } from "@/lib/boss-data";

export const dynamic = "force-dynamic";

export default async function ConversationFolderPage({
  params,
}: {
  params: Promise<{ folderKey: string }>;
}) {
  await requirePageSession();
  const { folderKey } = await params;
  const state = await readState();
  const folder = getConversationFolderView(state, decodeURIComponent(folderKey));

  return (
    <AppShell bottomNav={false}>
      {folder ? (
        <RealtimeRefresh
          projectIds={folder.threads.map((thread) => thread.projectId)}
          deviceId={folder.deviceId}
          events={["conversation.updated", "project.messages.updated"]}
        />
      ) : null}
      <StatusBar />
      <PageNav title={folder?.folderLabel ?? "项目线程"} backHref="/conversations" />
      {folder ? (
        <ConversationList conversations={folder.threads} />
      ) : (
        <div className="px-[18px] pb-6 text-[13px] text-[#8C8C8C]">未找到项目线程。</div>
      )}
    </AppShell>
  );
}
