import { hasPermission, Role } from "@/lib/validation/permissions";
import { auth } from "@/server/auth";
import { api } from "@/trpc/server";
import { notFound } from "next/navigation";
import React from "react";
import ArticleEditor from "@/components/article/article-form";

async function Page({ params }: { params: Promise<{ slug: string }> }) {
  const { slug } = await params;
  const session = await auth();
  const isEditor = session?.user
    ? hasPermission(session.user.role, Role.EDITOR)
    : false;
  const article = await api.article.get({ slug: slug });
  if (!article || !isEditor) return notFound();
  return <ArticleEditor server_article={article} />;
}

export default Page;
