import { ComponentSchema, 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',
      }),
      tags: fields.array(
        fields.relationship({
          label: 'Tags',
          collection: 'tags',
        }),
        {
          label: 'Tags',
          itemLabel: (props): string => props.value || 'Select Tag',
        }
      ),
      author: fields.relationship({
        label: 'Author',
        collection: 'authors',
      }),
    },
    {
      label: 'Meta Information',
    }
  );
