import type { Block } from 'payload'

/**
 * Timeline Block (erweitert)
 * Chronologische Darstellung von Ereignissen
 */
export const TimelineBlock: Block = {
  slug: 'timeline-block',
  labels: {
    singular: 'Timeline',
    plural: 'Timelines',
  },
  fields: [
    {
      name: 'title',
      type: 'text',
      label: 'Überschrift',
      localized: true,
    },
    {
      name: 'subtitle',
      type: 'text',
      label: 'Untertitel',
      localized: true,
    },
    {
      name: 'layout',
      type: 'select',
      defaultValue: 'vertical',
      label: 'Layout',
      options: [
        { label: 'Vertikal (Standard)', value: 'vertical' },
        { label: 'Alternierend (links/rechts)', value: 'alternating' },
        { label: 'Horizontal (Zeitleiste)', value: 'horizontal' },
      ],
    },
    {
      name: 'showConnector',
      type: 'checkbox',
      defaultValue: true,
      label: 'Verbindungslinie anzeigen',
    },
    {
      name: 'markerStyle',
      type: 'select',
      defaultValue: 'dot',
      label: 'Marker-Stil',
      options: [
        { label: 'Punkt', value: 'dot' },
        { label: 'Nummer', value: 'number' },
        { label: 'Icon', value: 'icon' },
        { label: 'Jahr/Datum', value: 'date' },
      ],
    },
    {
      name: 'items',
      type: 'array',
      label: 'Einträge',
      minRows: 1,
      fields: [
        {
          name: 'year',
          type: 'text',
          label: 'Jahr/Datum',
          admin: {
            description: 'z.B. "2024", "Januar 2024", "15.03.2024"',
          },
        },
        {
          name: 'title',
          type: 'text',
          required: true,
          label: 'Titel',
          localized: true,
        },
        {
          name: 'description',
          type: 'textarea',
          label: 'Beschreibung',
          localized: true,
        },
        {
          name: 'icon',
          type: 'text',
          label: 'Icon',
          admin: {
            description: 'Emoji oder Icon-Name',
          },
        },
        {
          name: 'image',
          type: 'upload',
          relationTo: 'media',
          label: 'Bild (optional)',
        },
        {
          name: 'link',
          type: 'group',
          label: 'Link (optional)',
          fields: [
            {
              name: 'label',
              type: 'text',
              label: 'Link-Text',
              localized: true,
            },
            {
              name: 'href',
              type: 'text',
              label: 'URL',
            },
          ],
        },
      ],
    },
    {
      name: 'backgroundColor',
      type: 'select',
      defaultValue: 'white',
      label: 'Hintergrund',
      options: [
        { label: 'Weiß', value: 'white' },
        { label: 'Hell (Grau)', value: 'light' },
        { label: 'Dunkel', value: 'dark' },
      ],
    },
  ],
}
