import { CollectionConfig } from 'payload' import { hide, isAdmin, isAdminOrEmployee } from '@/collections/access/admin' import { ParagraphBlock } from '@/collections/blocks/Paragraph' import { DocumentBlock } from '@/collections/blocks/Document' import { DonationBlock } from '@/collections/blocks/Donation' import { YoutubePlayerBlock } from '@/collections/blocks/YoutubePlayer' import { DonationAppeal } from '@/collections/blocks/DonationAppeal' import { isPublishedPublic } from '@/collections/access/public' export const Parish: CollectionConfig = { slug: 'parish', labels: { singular: { de: 'Gemeinde', }, plural: { de: 'Gemeinden', }, }, fields: [ { name: 'name', label: { de: 'Name', }, type: 'text', required: true, }, { name: 'slug', label: { de: 'URL slug', }, type: 'text', required: true, admin: { description: 'Slug der Gemeinde (z.B. "st-clara" → Gemeindeseite ist zu finden unter /gemeinde/st-clara)', components: { Field: '@/admin/components/SlugField/SlugField#SlugField', }, }, hooks: { beforeValidate: [ ({ value }) => typeof value === 'string' ? value.replace(/^\/+/, '') : value, ], }, }, { name: 'churches', label: { de: 'Kirchengebäuden', }, type: 'relationship', relationTo: 'church', hasMany: true, required: true, admin: { allowCreate: false, }, }, { name: 'contactPersons', label: { de: "Ansprechpartner" }, type: 'array', fields: [ { name: 'title', label: { de: 'Titel' }, type: 'text', required: true }, { name: 'description', label: { de: 'Umschreibung' }, type: 'textarea', required: true } ] }, { name: 'description', label: { de: 'Umschreibung', }, type: 'textarea', required: true, admin: { rows: 15, }, }, { name: 'history', label: { de: 'Geschichte', }, type: 'textarea', required: true, admin: { rows: 15, }, }, { name: 'content', label: { de: "Extra Kontent" }, type: 'blocks', blocks: [ ParagraphBlock, DocumentBlock, DonationBlock, YoutubePlayerBlock, DonationAppeal ] }, { name: 'contact', label: { de: 'Kontaktinformation', }, type: 'textarea', required: true, admin: { rows: 10, }, }, { name: 'photo', label: { de: "Hauptbild" }, type: 'upload', relationTo: 'media', required: true }, { name: 'gallery', label: { de: 'Weitere Bilder' }, type: 'array', fields: [ { name: 'photo', label: { de: 'Bild' }, type: 'upload', relationTo: 'media', required: true }, ], minRows: 3, maxRows: 12 } ], admin: { useAsTitle: 'name', hidden: hide, livePreview: { url: ({ data }) => `/api/draft?url=/gemeinde/${data.slug}`, }, }, versions: { drafts: { validate: true }, }, access: { read: isPublishedPublic(), create: isAdmin(), update: isAdminOrEmployee(), delete: isAdmin(), }, }