import { CollectionConfig } from 'payload'
import { isAdminOrEmployee } from '@/collections/access/admin'

export const Worship: CollectionConfig = {
  slug: 'worship',
  labels: {
    singular: {
      de: 'Gottesdienst',
    },
    plural: {
      de: 'Gottesdienst',
    },
  },
  fields: [
    {
      name: 'date',
      label: {
        de: 'Datum',
      },
      type: 'date',
      required: true,
      admin: {
        date: {
          pickerAppearance: 'dayAndTime',
        },
      },
    },
    {
      name: 'location',
      label: {
        de: 'Location',
      },
      type: 'relationship',
      relationTo: 'church',
      required: true,
    },
    {
      name: 'type',
      label: {
        de: 'Categorie',
      },
      type: 'radio',
      options: [
        {
          label: 'Heilige Messe',
          value: 'MASS',
        },
        {
          label: 'Familien Messe',
          value: 'FAMILY',
        },
        {
          label: 'Wort-Gottes-Feier',
          value: 'WORD',
        },
      ],
      required: true,
    },
    {
      name: 'title',
      type: 'text',
      required: false,
      label: {
        de: 'Titel'
      }
    },
    {
      name: 'cancelled',
      type: 'checkbox',
      required: true,
      defaultValue: false,
      label: {
        de: 'Abgesagt',
      },
    },
    {
      name: 'liturgicalDay',
      type: 'text',
      required: false,
      label: {
        de: 'Liturgischer Tag',
      },
    },
    {
      name: 'celebrant',
      type: 'text',
      required: false,
      label: {
        de: 'Zelebrant'
      }
    },
    {
      name: 'description',
      type: 'textarea',
      label: {
        de: 'Hinweise',
      },
    },
  ],
  admin: {
    defaultColumns: ["date", 'location', 'type', 'celebrant'],
    listSearchableFields: ['date', 'location']
  },
  access: {
    read: () => true,
    create: isAdminOrEmployee(),
    update: isAdminOrEmployee(),
    delete: isAdminOrEmployee(),
  },
}
