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

export const Testimonial: Block = {
  slug: 'testimonial',
  labels: {
    singular: 'Testimonial Section',
    plural: 'Testimonial Sections',
  },
  fields: [
    {
      name: 'heading',
      type: 'richText',
      required: true,
      editor: richTextEditor,
    },
    {
      name: 'layout',
      type: 'select',
      defaultValue: 'slider',
      options: [
        { label: 'Grid', value: 'grid' },
        { label: 'Slider', value: 'slider' },
        { label: 'Single', value: 'single' },
      ],
    },
    {
      name: 'ratings',
      type: 'array',
      admin: {
        description: 'Rating platforms (e.g. Tripadvisor, Google) to show at the top.',
      },
      fields: [
        { name: 'platform-icon', type: 'upload', relationTo: 'media', required: true },
        {
          name: 'platform-name',
          type: 'text',
          admin: { placeholder: 'tripadvisor' },
        },
        { name: 'score', type: 'text', required: true, admin: { placeholder: 'e.g. 4.4' } },
        { name: 'label', type: 'text', admin: { placeholder: 'e.g. Rated - GLOBAL EXCELLENCE' } },
      ],
    },
    {
      name: 'items',
      type: 'array',
      minRows: 1,
      required: true,
      fields: [
        {
          name: 'quote',
          type: 'richText',
          required: true,
          editor: richTextEditor,
        },
        {
          name: 'author',
          type: 'text',
          required: true,
        },
        {
          name: 'rating',
          type: 'number',
          min: 1,
          max: 5,
          defaultValue: 5,
          admin: {
            description: 'Rating given by the author (1-5 stars)',
          },
        },
        {
          name: 'role',
          type: 'text',
        },
        {
          name: 'company',
          type: 'text',
        },
        {
          name: 'avatar',
          type: 'upload',
          relationTo: 'media',
        },
      ],
    },
    ...blockMetaFields,
  ],
}
