import { InboxPlaceholder } from "@/components/placeholders";
import { ShellPage } from "@/components/page-templates";
import {
  addConversationNote,
  assignConversation,
  getInboxWorkspace,
  replyToConversation,
  setConversationTags,
  updateConversationStatus
} from "@/lib/inbox-ops";

const allowedFilters = ["all", "open", "pending", "resolved", "unassigned"] as const;

export default async function AgentInboxPage({
  searchParams
}: {
  searchParams: Promise<{ conversationId?: string; filter?: string }>;
}) {
  const params = await searchParams;
  const filter =
    params?.filter && allowedFilters.includes(params.filter as (typeof allowedFilters)[number])
      ? (params.filter as (typeof allowedFilters)[number])
      : "all";

  const data = await getInboxWorkspace({
    scope: "agent",
    conversationId: params?.conversationId,
    filter
  });

  return (
    <ShellPage shell="agent" title="My Inbox" description="Assigned conversations, notes, tags, dan reply composer versi agent.">
      <InboxPlaceholder
        conversations={data.conversations}
        selectedConversation={data.selectedConversation}
        defaultPath={data.defaultPath}
        role={data.role}
        filter={data.filter}
        canSelfAssign={data.canSelfAssign}
        assignConversation={assignConversation}
        updateConversationStatus={updateConversationStatus}
        replyToConversation={replyToConversation}
        addConversationNote={addConversationNote}
        setConversationTags={setConversationTags}
      />
    </ShellPage>
  );
}
