import type { Block } from 'payload'

/**
 * Background color options
 */
const backgroundColorOptions = [
  { label: 'Weiß', value: 'white' },
  { label: 'Ivory', value: 'ivory' },
  { label: 'Sand', value: 'sand' },
  { label: 'Hell (Grau)', value: 'light' },
  { label: 'Dunkel', value: 'dark' },
]

/**
 * SeriesBlock
 *
 * Zeigt Serien aus der Series Collection.
 * Verschiedene Layouts für Übersichtsseiten.
 */
export const SeriesBlock: Block = {
  slug: 'series-block',
  labels: {
    singular: 'Serien-Übersicht',
    plural: 'Serien-Übersichten',
  },
  imageURL: '/assets/blocks/series.png',
  fields: [
    // Header
    {
      name: 'title',
      type: 'text',
      label: 'Überschrift',
      localized: true,
    },
    {
      name: 'subtitle',
      type: 'text',
      label: 'Untertitel',
      localized: true,
    },

    // Layout
    {
      name: 'layout',
      type: 'select',
      defaultValue: 'grid',
      label: 'Layout',
      options: [
        { label: 'Grid', value: 'grid' },
        { label: 'Liste', value: 'list' },
        { label: 'Featured (Hero + Grid)', value: 'featured' },
      ],
    },
    {
      name: 'columns',
      type: 'select',
      defaultValue: '3',
      label: 'Spalten',
      options: [
        { label: '2 Spalten', value: '2' },
        { label: '3 Spalten', value: '3' },
        { label: '4 Spalten', value: '4' },
      ],
      admin: {
        condition: (_, siblingData) =>
          siblingData?.layout === 'grid' || siblingData?.layout === 'featured',
      },
    },

    // Display Options
    {
      name: 'showDescription',
      type: 'checkbox',
      defaultValue: true,
      label: 'Beschreibung anzeigen',
    },
    {
      name: 'showLogo',
      type: 'checkbox',
      defaultValue: true,
      label: 'Logo anzeigen',
    },
    {
      name: 'showTagline',
      type: 'checkbox',
      defaultValue: true,
      label: 'Tagline anzeigen',
    },
    {
      name: 'useBrandColors',
      type: 'checkbox',
      defaultValue: true,
      label: 'Markenfarben verwenden',
      admin: {
        description: 'Serien-spezifische Farben für Akzente nutzen',
      },
    },

    // Filtering
    {
      name: 'limit',
      type: 'number',
      defaultValue: 6,
      min: 1,
      max: 20,
      label: 'Anzahl',
      admin: {
        description: 'Maximale Anzahl der angezeigten Serien',
      },
    },

    // Styling
    {
      name: 'backgroundColor',
      type: 'select',
      defaultValue: 'white',
      options: backgroundColorOptions,
      label: 'Hintergrundfarbe',
    },

    // CTA
    {
      name: 'cta',
      type: 'group',
      label: 'Call-to-Action',
      fields: [
        {
          name: 'showCta',
          type: 'checkbox',
          defaultValue: false,
          label: 'CTA-Button anzeigen',
        },
        {
          name: 'ctaText',
          type: 'text',
          label: 'Button-Text',
          defaultValue: 'Alle Serien ansehen',
          localized: true,
          admin: {
            condition: (_, siblingData) => siblingData?.showCta,
          },
        },
        {
          name: 'ctaUrl',
          type: 'text',
          label: 'Button-Link',
          admin: {
            condition: (_, siblingData) => siblingData?.showCta,
          },
        },
      ],
    },
  ],
}
