import type { Block } from 'payload'
import { blockMetaFields } from '@/fields/blockMeta'
import { richTextEditor } from '@/fields/richTextEditor'

export const ContentListV1: Block = {
  slug: 'contentListV1',
  labels: { singular: 'Content List', plural: 'Content Lists' },
  fields: [
    {
      name: 'heading',
      type: 'richText',
      required: true,
      editor: richTextEditor,
    },
    { name: 'intro', type: 'textarea' },
    {
      name: 'ornament',
      type: 'upload',
      relationTo: 'media',
      required: false,
      admin: {
        description: 'Optional section ornament image.',
      },
    },
    {
      name: 'variant',
      type: 'select',
      required: true,
      defaultValue: 'media-stack',
      options: [
        { label: 'Card grid (packages)', value: 'card-grid' },
        { label: 'Media stack (vertical tiles)', value: 'media-stack' },
        { label: 'Media grid (Split text/images)', value: 'media-grid' },
        { label: 'Feature cards (Numbered/Icons)', value: 'feature-cards' },
        { label: 'Logo grid (Awards/Recognition)', value: 'logo-grid' },
      ],
      admin: { description: 'Controls layout intent. Frontend decides rendering.' },
    },
    {
      name: 'ctas',
      type: 'array',
      label: 'Section CTAs',
      admin: {
        description:
          'Buttons that appear in the section header area (e.g. the "Book Now" button on the right).',
      },
      maxRows: 2,
      fields: [
        { name: 'label', type: 'text', required: true },
        { name: 'href', type: 'text', required: true },
        {
          name: 'style',
          type: 'select',
          defaultValue: 'primary',
          options: [
            { label: 'Primary', value: 'primary' },
            { label: 'Outline', value: 'outline' },
          ],
        },
        {
          name: 'ctaId',
          type: 'text',
          admin: {
            description: 'Optional HTML id attribute for tracking or scroll targeting (e.g. "hero-book-now").',
          },
        },
      ],
    },
    {
      name: 'items',
      type: 'array',
      fields: [
        {
          name: 'image',
          type: 'upload',
          relationTo: 'media',
          required: false,
          admin: {
            description: 'Optional for some variants (e.g. Feature Cards).',
          },
        },
        { name: 'icon', type: 'upload', relationTo: 'media' },

        { name: 'eyebrow', type: 'richText', editor: richTextEditor },
        { name: 'title', type: 'richText', required: true, editor: richTextEditor },

        { name: 'priceLine', type: 'text' },

        {
          name: 'subline',
          type: 'richText',
          editor: richTextEditor,
          admin: {
            description: 'Short emphasised line (e.g. INCLUDING CONTINENTAL BREAKFAST)',
          },
        },

        {
          name: 'body',
          type: 'richText',
          editor: richTextEditor,
          admin: {
            description: 'Short descriptive content with formatting support',
          },
        },

        {
          name: 'cta',
          type: 'group',
          fields: [
            { name: 'label', type: 'text' },
            { name: 'href', type: 'text' },
            {
              name: 'ctaId',
              type: 'text',
              admin: {
                description: 'Optional HTML id attribute for tracking or scroll targeting (e.g. "hero-book-now").',
              },
            },
          ],
        },
      ],

      admin: { initCollapsed: true },
    },

    ...blockMetaFields,
  ],
}
