import type { ComponentSchema } from '@keystatic/core'
import { fields } from '@keystatic/core'

export const createPublishingField = (): ComponentSchema =>
  fields.object(
    {
      publishDate: fields.datetime({ label: 'Publish Date' }),
      editDate: fields.datetime({ label: 'Edit Date' }),
      status: fields.select({
        label: 'Status',
        options: [
          { label: 'Draft', value: 'draft' },
          { label: 'Published', value: 'published' },
          { label: 'Archived', value: 'archived' },
        ],
        defaultValue: 'draft',
      }),
      featured: fields.checkbox({
        label: 'Featured',
        description: 'Show on Homepage',
      }),
      tags: fields.array(
        fields.relationship({
          label: 'Tags',
          collection: 'tags',
        }),
        {
          label: 'Tags',
          itemLabel: (props) => props.value || 'Select Tag',
        }
      ),
      author: fields.relationship({
        label: 'Author',
        collection: 'authors',
      }),
    },
    {
      label: 'Publishing',
      layout: [4, 4, 4, 12, 12, 12],
    }
  )
