import type { Block } from 'payload'

/**
 * JobsBlock
 *
 * Zeigt Stellenanzeigen mit Filter- und Suchfunktion.
 * Unterstützt verschiedene Layouts und Filteroptionen.
 */
export const JobsBlock: Block = {
  slug: 'jobs-block',
  labels: {
    singular: 'Stellenanzeigen',
    plural: 'Stellenanzeigen',
  },
  imageURL: '/assets/blocks/jobs.png',
  fields: [
    {
      name: 'title',
      type: 'text',
      label: 'Überschrift',
      localized: true,
      defaultValue: 'Offene Stellen',
    },
    {
      name: 'subtitle',
      type: 'textarea',
      label: 'Untertitel',
      localized: true,
    },
    {
      name: 'introduction',
      type: 'richText',
      label: 'Einleitungstext',
      localized: true,
    },
    // Datenquelle
    {
      name: 'source',
      type: 'select',
      defaultValue: 'all',
      label: 'Stellen',
      options: [
        { label: 'Alle veröffentlichten', value: 'all' },
        { label: 'Nach Kategorie', value: 'category' },
        { label: 'Nach Abteilung', value: 'department' },
        { label: 'Nach Standort', value: 'location' },
        { label: 'Nur hervorgehobene', value: 'featured' },
        { label: 'Manuell auswählen', value: 'manual' },
      ],
    },
    {
      name: 'category',
      type: 'select',
      label: 'Kategorie',
      options: [
        { label: 'Pflege & Betreuung', value: 'care' },
        { label: 'Medizin', value: 'medical' },
        { label: 'Verwaltung', value: 'admin' },
        { label: 'IT & Technik', value: 'it' },
        { label: 'Marketing', value: 'marketing' },
        { label: 'Vertrieb', value: 'sales' },
        { label: 'Finanzen', value: 'finance' },
        { label: 'Personal', value: 'hr' },
        { label: 'Produktion', value: 'production' },
        { label: 'Logistik', value: 'logistics' },
      ],
      admin: {
        condition: (_, siblingData) => siblingData?.source === 'category',
      },
    },
    {
      name: 'department',
      type: 'text',
      label: 'Abteilung',
      admin: {
        condition: (_, siblingData) => siblingData?.source === 'department',
      },
    },
    {
      name: 'locationFilter',
      type: 'relationship',
      relationTo: 'locations',
      label: 'Standort',
      admin: {
        condition: (_, siblingData) => siblingData?.source === 'location',
      },
    },
    {
      name: 'selectedJobs',
      type: 'relationship',
      relationTo: 'jobs',
      hasMany: true,
      label: 'Stellen auswählen',
      admin: {
        condition: (_, siblingData) => siblingData?.source === 'manual',
      },
    },
    {
      name: 'limit',
      type: 'number',
      defaultValue: 10,
      min: 1,
      max: 50,
      label: 'Maximale Anzahl',
    },
    // Filter-UI
    {
      name: 'filters',
      type: 'group',
      label: 'Filter-Optionen',
      fields: [
        {
          name: 'showSearch',
          type: 'checkbox',
          defaultValue: true,
          label: 'Suchfeld',
        },
        {
          name: 'showCategoryFilter',
          type: 'checkbox',
          defaultValue: true,
          label: 'Kategorie-Filter',
        },
        {
          name: 'showTypeFilter',
          type: 'checkbox',
          defaultValue: true,
          label: 'Beschäftigungsart-Filter',
        },
        {
          name: 'showLocationFilter',
          type: 'checkbox',
          defaultValue: true,
          label: 'Standort-Filter',
        },
        {
          name: 'showWorkModelFilter',
          type: 'checkbox',
          defaultValue: false,
          label: 'Arbeitsmodell-Filter',
        },
        {
          name: 'filterLayout',
          type: 'select',
          defaultValue: 'horizontal',
          label: 'Filter-Layout',
          options: [
            { label: 'Horizontal', value: 'horizontal' },
            { label: 'Sidebar', value: 'sidebar' },
            { label: 'Dropdown', value: 'dropdown' },
          ],
        },
      ],
    },
    // Layout
    {
      name: 'layout',
      type: 'select',
      defaultValue: 'list',
      label: 'Layout',
      options: [
        { label: 'Liste', value: 'list' },
        { label: 'Karten', value: 'cards' },
        { label: 'Kompakt', value: 'compact' },
        { label: 'Akkordeon', value: 'accordion' },
      ],
    },
    {
      name: 'columns',
      type: 'select',
      defaultValue: '1',
      label: 'Spalten',
      options: [
        { label: '1 Spalte', value: '1' },
        { label: '2 Spalten', value: '2' },
        { label: '3 Spalten', value: '3' },
      ],
      admin: {
        condition: (_, siblingData) =>
          siblingData?.layout === 'cards' || siblingData?.layout === 'list',
      },
    },
    // Anzuzeigende Informationen
    {
      name: 'show',
      type: 'group',
      label: 'Anzeigen',
      fields: [
        {
          name: 'image',
          type: 'checkbox',
          defaultValue: false,
          label: 'Bild',
        },
        {
          name: 'department',
          type: 'checkbox',
          defaultValue: true,
          label: 'Abteilung',
        },
        {
          name: 'type',
          type: 'checkbox',
          defaultValue: true,
          label: 'Beschäftigungsart',
        },
        {
          name: 'location',
          type: 'checkbox',
          defaultValue: true,
          label: 'Standort',
        },
        {
          name: 'workModel',
          type: 'checkbox',
          defaultValue: true,
          label: 'Arbeitsmodell',
        },
        {
          name: 'salary',
          type: 'checkbox',
          defaultValue: false,
          label: 'Gehalt',
        },
        {
          name: 'summary',
          type: 'checkbox',
          defaultValue: true,
          label: 'Kurzbeschreibung',
        },
        {
          name: 'deadline',
          type: 'checkbox',
          defaultValue: false,
          label: 'Bewerbungsfrist',
        },
        {
          name: 'publishDate',
          type: 'checkbox',
          defaultValue: true,
          label: 'Veröffentlichungsdatum',
        },
        {
          name: 'badges',
          type: 'checkbox',
          defaultValue: true,
          label: 'Badges (Neu, Dringend)',
        },
      ],
    },
    // Badges
    {
      name: 'badges',
      type: 'group',
      label: 'Badge-Einstellungen',
      fields: [
        {
          name: 'newDays',
          type: 'number',
          defaultValue: 7,
          label: '"Neu" für X Tage',
          admin: {
            description: 'Wie viele Tage nach Veröffentlichung "Neu" anzeigen',
          },
        },
        {
          name: 'showUrgent',
          type: 'checkbox',
          defaultValue: true,
          label: '"Dringend" Badge',
        },
        {
          name: 'showFeatured',
          type: 'checkbox',
          defaultValue: true,
          label: '"Top" Badge für hervorgehobene',
        },
      ],
    },
    // Pagination
    {
      name: 'pagination',
      type: 'group',
      label: 'Pagination',
      fields: [
        {
          name: 'type',
          type: 'select',
          defaultValue: 'button',
          label: 'Typ',
          options: [
            { label: '"Mehr laden" Button', value: 'button' },
            { label: 'Pagination', value: 'pagination' },
            { label: 'Infinite Scroll', value: 'infinite' },
            { label: 'Alle anzeigen', value: 'none' },
          ],
        },
        {
          name: 'perPage',
          type: 'number',
          defaultValue: 10,
          label: 'Pro Seite',
          admin: {
            condition: (_, siblingData) =>
              siblingData?.type === 'pagination' || siblingData?.type === 'button',
          },
        },
      ],
    },
    // Styling
    {
      name: 'style',
      type: 'group',
      label: 'Darstellung',
      fields: [
        {
          name: 'bg',
          type: 'select',
          defaultValue: 'none',
          label: 'Hintergrund',
          options: [
            { label: 'Keiner', value: 'none' },
            { label: 'Hell', value: 'light' },
            { label: 'Dunkel', value: 'dark' },
          ],
        },
        {
          name: 'cardStyle',
          type: 'select',
          defaultValue: 'bordered',
          label: 'Karten-Stil',
          options: [
            { label: 'Einfach', value: 'simple' },
            { label: 'Mit Rahmen', value: 'bordered' },
            { label: 'Mit Schatten', value: 'shadow' },
          ],
        },
        {
          name: 'hoverEffect',
          type: 'select',
          defaultValue: 'lift',
          label: 'Hover-Effekt',
          options: [
            { label: 'Keiner', value: 'none' },
            { label: 'Anheben', value: 'lift' },
            { label: 'Hervorheben', value: 'highlight' },
          ],
        },
        {
          name: 'gap',
          type: 'select',
          defaultValue: '16',
          label: 'Abstand',
          options: [
            { label: 'Klein (8px)', value: '8' },
            { label: 'Normal (16px)', value: '16' },
            { label: 'Groß (24px)', value: '24' },
          ],
        },
      ],
    },
    // Empty State
    {
      name: 'emptyState',
      type: 'group',
      label: 'Keine Stellen',
      fields: [
        {
          name: 'title',
          type: 'text',
          label: 'Überschrift',
          localized: true,
          defaultValue: 'Aktuell keine offenen Stellen',
        },
        {
          name: 'message',
          type: 'textarea',
          label: 'Nachricht',
          localized: true,
          defaultValue: 'Schauen Sie später wieder vorbei oder senden Sie uns eine Initiativbewerbung.',
        },
        {
          name: 'showInitiativeLink',
          type: 'checkbox',
          defaultValue: true,
          label: 'Initiativbewerbungs-Link',
        },
        {
          name: 'initiativeText',
          type: 'text',
          label: 'Link-Text',
          localized: true,
          defaultValue: 'Initiativbewerbung senden',
          admin: {
            condition: (_, siblingData) => siblingData?.showInitiativeLink,
          },
        },
        {
          name: 'initiativeUrl',
          type: 'text',
          label: 'Link-URL',
          defaultValue: '/karriere/initiativbewerbung',
          admin: {
            condition: (_, siblingData) => siblingData?.showInitiativeLink,
          },
        },
      ],
    },
    // CTA
    {
      name: 'showAllJobsLink',
      type: 'checkbox',
      defaultValue: false,
      label: '"Alle Stellen" Link',
    },
    {
      name: 'allJobsText',
      type: 'text',
      label: 'Link-Text',
      localized: true,
      defaultValue: 'Alle offenen Stellen',
      admin: {
        condition: (_, siblingData) => siblingData?.showAllJobsLink,
      },
    },
    {
      name: 'allJobsUrl',
      type: 'text',
      label: 'Link-URL',
      defaultValue: '/karriere',
      admin: {
        condition: (_, siblingData) => siblingData?.showAllJobsLink,
      },
    },
  ],
}
