import { redirect, notFound } from "next/navigation";
import { loadCurrentDid } from "@/data/queries";
import { loadDraftDetail } from "@/data/drafts/queries";
import { DraftEditor } from "./DraftEditor";

export default async function DraftPage({ params }: { params: Promise<{ rkey: string }> }) {
  const { rkey } = await params;

  const did = await loadCurrentDid();
  if (!did) {
    redirect("/login");
  }

  const draft = await loadDraftDetail(rkey);
  if (!draft) {
    notFound();
  }

  return <DraftEditor rkey={rkey} initialDraft={draft} />;
}
