import type { Block } from 'payload'

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

/**
 * Category options matching the Favorites collection
 */
const categoryFilterOptions = [
  { label: 'Alle Kategorien', value: 'all' },
  { label: 'Fashion', value: 'fashion' },
  { label: 'Beauty', value: 'beauty' },
  { label: 'Travel', value: 'travel' },
  { label: 'Tech', value: 'tech' },
  { label: 'Home', value: 'home' },
]

/**
 * FavoritesBlock
 *
 * Zeigt Favoriten/Affiliate-Produkte aus der Favorites Collection.
 * Unterstützt verschiedene Layouts und Filteroptionen.
 */
export const FavoritesBlock: Block = {
  slug: 'favorites-block',
  labels: {
    singular: 'Favoriten',
    plural: 'Favoriten',
  },
  imageURL: '/assets/blocks/favorites.png',
  fields: [
    // Header
    {
      name: 'title',
      type: 'text',
      label: 'Überschrift',
      localized: true,
    },
    {
      name: 'subtitle',
      type: 'text',
      label: 'Untertitel',
      localized: true,
    },

    // Filtering
    {
      name: 'category',
      type: 'select',
      defaultValue: 'all',
      options: categoryFilterOptions,
      label: 'Kategorie-Filter',
      admin: {
        description: 'Nur Favoriten dieser Kategorie anzeigen',
      },
    },
    {
      name: 'showFeaturedOnly',
      type: 'checkbox',
      defaultValue: false,
      label: 'Nur Featured anzeigen',
      admin: {
        description: 'Nur als "Featured" markierte Favoriten anzeigen',
      },
    },
    {
      name: 'limit',
      type: 'number',
      defaultValue: 8,
      min: 1,
      max: 50,
      label: 'Anzahl',
      admin: {
        description: 'Maximale Anzahl der angezeigten Favoriten',
      },
    },

    // Layout
    {
      name: 'layout',
      type: 'select',
      defaultValue: 'grid',
      label: 'Layout',
      options: [
        { label: 'Grid', value: 'grid' },
        { label: 'Liste', value: 'list' },
        { label: 'Karussell', value: 'carousel' },
      ],
    },
    {
      name: 'columns',
      type: 'select',
      defaultValue: '4',
      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 === 'carousel',
      },
    },

    // Display Options
    {
      name: 'showPrice',
      type: 'checkbox',
      defaultValue: true,
      label: 'Preis anzeigen',
    },
    {
      name: 'showBadge',
      type: 'checkbox',
      defaultValue: true,
      label: 'Badge anzeigen',
    },
    {
      name: 'showDescription',
      type: 'checkbox',
      defaultValue: false,
      label: 'Beschreibung anzeigen',
    },
    {
      name: 'showCategory',
      type: 'checkbox',
      defaultValue: false,
      label: 'Kategorie anzeigen',
    },

    // 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 Favoriten ansehen',
          localized: true,
          admin: {
            condition: (_, siblingData) => siblingData?.showCta,
          },
        },
        {
          name: 'ctaUrl',
          type: 'text',
          label: 'Button-Link',
          admin: {
            condition: (_, siblingData) => siblingData?.showCta,
          },
        },
      ],
    },
  ],
}
