import type { Block } from 'payload'

export const ShowcaseBlock: Block = {
  slug: 'showcase',
  labels: { singular: 'Showcase', plural: 'Showcases' },
  fields: [
    {
      name: 'heading',
      type: 'text',
      label: 'Heading',
    },
    {
      name: 'subheading',
      type: 'text',
      label: 'Subheading',
    },
    {
      name: 'items',
      type: 'array',
      label: 'Items',
      minRows: 1,
      fields: [
        {
          name: 'image',
          type: 'upload',
          relationTo: 'media',
          label: 'Image (optional)',
        },
        {
          name: 'imageUrl',
          type: 'text',
          label: 'Image click URL (optional)',
        },
        {
          name: 'title',
          type: 'text',
          label: 'Title',
          required: true,
        },
        {
          name: 'description',
          type: 'textarea',
          label: 'Description',
        },
        {
          name: 'tags',
          type: 'array',
          label: 'Tags',
          fields: [{ name: 'tag', type: 'text', label: 'Tag', required: true }],
        },
        {
          name: 'links',
          type: 'array',
          label: 'Links',
          fields: [
            { name: 'label', type: 'text', label: 'Label', required: true },
            { name: 'url', type: 'text', label: 'URL', required: true },
            {
              name: 'newTab',
              type: 'checkbox',
              label: 'Open in new tab',
              defaultValue: true,
            },
          ],
        },
      ],
    },
  ],
}
