import type { CollectionConfig } from 'payload'

import { anyone } from '../access/anyone'
import { authenticated } from '../access/authenticated'
import { slugField } from 'payload'

export const Categories: CollectionConfig = {
  slug: 'categories',
  access: {
    create: authenticated,
    delete: authenticated,
    read: anyone,
    update: authenticated,
  },
  admin: {
    useAsTitle: 'title',
    defaultColumns: ['title', 'type', 'icon', 'updatedAt'],
  },
  fields: [
    {
      name: 'title',
      type: 'text',
      required: true,
      localized: true,
    },
    {
      name: 'description',
      type: 'textarea',
      localized: true,
      admin: {
        description: 'Category description for archive pages and SEO',
      },
    },
    slugField({
      position: undefined,
    }),
    {
      name: 'type',
      type: 'select',
      required: true,
      options: [
        { label: 'Project Category', value: 'project' },
        { label: 'Post Category', value: 'post' },
        { label: 'Skill Category', value: 'skill' },
      ],
      admin: {
        position: 'sidebar',
        description: 'What type of content this category is for',
      },
    },
    {
      name: 'icon',
      type: 'text',
      admin: {
        position: 'sidebar',
        description: 'Icon name (e.g., code, shield, cloud)',
      },
    },
    {
      name: 'color',
      type: 'text',
      admin: {
        position: 'sidebar',
        description: 'Hex color for UI badges/tags (e.g., #3B82F6)',
      },
    },
    {
      name: 'order',
      type: 'number',
      admin: {
        position: 'sidebar',
        description: 'Custom sort order (lower numbers appear first)',
      },
    },
  ],
}
