import { ShellPage } from "@/components/page-templates";
import { TablePlaceholder } from "@/components/placeholders";
import { assignConversation, getInboxWorkspace } from "@/lib/inbox-ops";

export default async function AgentUnassignedPage() {
  const data = await getInboxWorkspace({ scope: "agent", filter: "unassigned" });

  return (
    <ShellPage shell="agent" title="Unassigned Queue" description="Queue yang bisa diambil agent jika diizinkan.">
      <TablePlaceholder
        title="Queue"
        columns={["Contact", "Last message", "Waiting time", "Action"]}
        rows={data.conversations.map((item) => [
          <>
            <p>{item.name}</p>
            <p className="text-xs text-outline">{item.phone}</p>
          </>,
          item.snippet,
          item.time,
          <form key={item.id} action={assignConversation} className="inline">
            <input type="hidden" name="conversationId" value={item.id} />
            <input type="hidden" name="nextPath" value="/agent/inbox/unassigned" />
            <button className="rounded-full bg-surface-container-low px-3 py-2 text-xs" type="submit">
              Take assignment
            </button>
          </form>
        ])}
      />
    </ShellPage>
  );
}
