import { collection, fields } from '@keystatic/core';

export default collection({
  label: 'Authors',
  slugField: 'name',
  path: 'content/taxonomy/authors/*',
  format: { data: 'json' },
  schema: {
    name: fields.slug({ name: { label: 'Name' } }),
    avatar: fields.image({
      label: 'Avatar',
      directory: 'public/images/authors',
      publicPath: '/images/authors',
    }),
    description: fields.text({ label: 'Description', multiline: true }),
    contacts: fields.array(
      fields.object({
        type: fields.select({
          label: 'Contact Type',
          defaultValue: 'email',
          options: [
            {
              value: 'email',
              label: 'E-Mail',
            },
            {
              value: 'discord',
              label: 'Discord',
            },
            {
              value: 'other',
              label: 'Other',
            },
          ],
        }),
        url: fields.text({
          label: 'URL',
        }),
      }),
      {
        label: 'Contact Type',
        itemLabel: (props) => `${props.fields.type.value}`,
      }
    ),
  },
});
