import formatSlug from "@/utils/payload/formatSlug";
import type { CollectionConfig } from "payload";

export const BlogCategories: CollectionConfig = {
  slug: "blogCategories",
  labels: { plural: "Categories", singular: "Category" },
  fields: [
    {
      name: "name",
      type: "text",
      required: true,
    },
    {
      name: "slug",
      type: "text",
      admin: {
        position: "sidebar",
      },
      hooks: {
        beforeValidate: [formatSlug("name")],
      },
    },
    {
      name: "parent_category",
      label: "Parent Category",
      type: "relationship",
      relationTo: "blogCategories",
    },
    {
      name: "description",
      type: "textarea",
    },
  ],
  admin: {
    hideAPIURL: true,
    group: "Blogs",
    useAsTitle: "name",
  },
};
