import type { CollectionConfig } from 'payload'
import { publicRead, isLoggedIn } from '@/access'

export const Persoenlichkeiten: CollectionConfig = {
    slug: 'persoenlichkeiten',
    access: {
        read:   () => true,
        create: ({ req }) => ['admin', 'editor'].includes(req.user?.role ?? ''),
        update: ({ req }) => ['admin', 'editor'].includes(req.user?.role ?? ''),
        delete: ({ req }) => req.user?.role === 'admin',
    },
    labels: {
        singular: 'Persönlichkeit',
        plural: 'Persönlichkeiten',
    },
    admin: {
        useAsTitle: 'name',
        defaultColumns: ['name', 'kategorie', 'updatedAt'],
        group: 'Donauschwaben',
    },
    fields: [
        {
            name: 'name',
            type: 'text',
            required: true,
            localized: true,
        },
        {
            name: 'slug',
            type: 'text',
            required: true,
            localized: true,
            admin: {
                description: 'URL-freundlicher Name, z.B. nikolaus-lenau',
            },
        },
        {
            name: 'kategorie',
            type: 'select',
            required: true,
            localized: false,
            options: [
                { label: 'Autor:in', value: 'autor' },
                { label: 'Politiker:in', value: 'politiker' },
                { label: 'Denker:in', value: 'denker' },
                { label: 'Architekt:in', value: 'architekt' },
                { label: 'Sonstige', value: 'sonstige' },
            ],
        },
        {
            name: 'bild',
            type: 'upload',
            relationTo: 'media',
            localized: false,
        },
        {
            name: 'kurzbiografie',
            type: 'textarea',
            localized: true,
            admin: {
                description: 'Kurze Beschreibung für Listenansicht (max. 300 Zeichen)',
            },
        },
        {
            name: 'biografie',
            type: 'richText',
            localized: true,
        },
        {
            name: 'geboren',
            type: 'date',
            localized: false,
        },
        {
            name: 'gestorben',
            type: 'date',
            localized: false,
            admin: {
                description: 'Leer lassen wenn noch lebend',
            },
        },
        {
            name: 'geburtsort',
            type: 'text',
            localized: true,
        },
    ],
}