import type { Block } from 'payload'

/**
 * Posts List Block
 * Zeigt Blog-Artikel, News oder andere Post-Typen an
 */
export const PostsListBlock: Block = {
  slug: 'posts-list-block',
  labels: {
    singular: 'Blog/News Liste',
    plural: 'Blog/News Listen',
  },
  fields: [
    {
      name: 'title',
      type: 'text',
      label: 'Überschrift',
      localized: true,
    },
    {
      name: 'subtitle',
      type: 'text',
      label: 'Untertitel',
      localized: true,
    },
    {
      name: 'postType',
      type: 'select',
      required: true,
      defaultValue: 'blog',
      label: 'Beitragstyp',
      options: [
        { label: 'Blog-Artikel', value: 'blog' },
        { label: 'News/Aktuelles', value: 'news' },
        { label: 'Pressemitteilungen', value: 'press' },
        { label: 'Ankündigungen', value: 'announcement' },
        { label: 'Alle Beiträge', value: 'all' },
      ],
    },
    {
      name: 'layout',
      type: 'select',
      defaultValue: 'grid',
      label: 'Layout',
      options: [
        { label: 'Grid (Karten)', value: 'grid' },
        { label: 'Liste', value: 'list' },
        { label: 'Featured + Grid', value: 'featured' },
        { label: 'Kompakt (Sidebar)', value: 'compact' },
        { label: 'Masonry', value: 'masonry' },
      ],
    },
    {
      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: (data, siblingData) =>
          siblingData?.layout === 'grid' ||
          siblingData?.layout === 'featured' ||
          siblingData?.layout === 'masonry',
      },
    },
    {
      name: 'limit',
      type: 'number',
      defaultValue: 6,
      min: 1,
      max: 24,
      label: 'Anzahl Beiträge',
    },
    {
      name: 'showFeaturedOnly',
      type: 'checkbox',
      defaultValue: false,
      label: 'Nur hervorgehobene anzeigen',
    },
    {
      name: 'filterByCategory',
      type: 'relationship',
      relationTo: 'categories',
      hasMany: true,
      label: 'Nach Kategorien filtern',
      admin: {
        description: 'Leer = alle Kategorien',
      },
    },
    {
      name: 'showExcerpt',
      type: 'checkbox',
      defaultValue: true,
      label: 'Kurzfassung anzeigen',
    },
    {
      name: 'showDate',
      type: 'checkbox',
      defaultValue: true,
      label: 'Datum anzeigen',
    },
    {
      name: 'showAuthor',
      type: 'checkbox',
      defaultValue: false,
      label: 'Autor anzeigen',
    },
    {
      name: 'showCategory',
      type: 'checkbox',
      defaultValue: true,
      label: 'Kategorie anzeigen',
    },
    {
      name: 'showPagination',
      type: 'checkbox',
      defaultValue: false,
      label: 'Pagination anzeigen',
    },
    {
      name: 'showReadMore',
      type: 'checkbox',
      defaultValue: true,
      label: '"Alle anzeigen" Link',
    },
    {
      name: 'readMoreLabel',
      type: 'text',
      defaultValue: 'Alle Beiträge anzeigen',
      localized: true,
      admin: {
        condition: (data, siblingData) => siblingData?.showReadMore,
      },
    },
    {
      name: 'readMoreLink',
      type: 'text',
      defaultValue: '/blog',
      admin: {
        condition: (data, siblingData) => siblingData?.showReadMore,
      },
    },
    {
      name: 'backgroundColor',
      type: 'select',
      defaultValue: 'white',
      label: 'Hintergrund',
      options: [
        { label: 'Weiß', value: 'white' },
        { label: 'Hell (Grau)', value: 'light' },
        { label: 'Dunkel', value: 'dark' },
      ],
    },
  ],
}
