import React from "react";
import { CategoryPageProps } from "../page";
import { api } from "@/trpc/server";
import { auth } from "@/server/auth";
import { hasPermission, Role } from "@/lib/validation/permissions";
import { notFound } from "next/navigation";
import CategoryForm from "@/components/category/category-form";
import ImageUploadButton from "@/components/image-upload-form";

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

export default Page;
