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

export const createMetaField = (): ComponentSchema =>
  fields.object(
    {
      publicationDate: fields.datetime({
        label: 'Publication Date',
        defaultValue: { kind: 'now' },
      }),
      updateDate: fields.datetime({ label: 'Update Date' }),
      status: fields.select({
        label: 'Status',
        defaultValue: 'draft',
        options: [
          { label: 'Draft', value: 'draft' },
          { label: 'Published', value: 'published' },
          { label: 'Archived', value: 'archived' },
        ],
      }),
      isFeatured: 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: 'Meta Information',
      layout: [4, 4, 4, 12, 12, 12],
    }
  );
