import { revalidateTag } from 'next/cache'
import { type GlobalConfig } from 'payload'

export const ContactForm: GlobalConfig = {
  slug: 'contactForm',
  fields: [
    {
      name: 'title',
      type: 'text',
      localized: true,
      label: 'Title',
      required: true,
    },
    {
      name: 'phone',
      type: 'text',
      localized: true,
      label: 'Phone',
      required: true,
    },
    {
      name: 'mail',
      type: 'text',
      localized: true,
      label: 'Mail',
      required: true,
    },
    {
      name: 'address',
      type: 'text',
      localized: true,
      label: 'Address',
      required: true,
    },
    {
      name: 'bg',
      type: 'upload',
      relationTo: 'media',
      label: 'Background',
      required: true,
    },
    {
      name: 'workingHours',
      type: 'text',
      localized: true,
      label: 'Working hours',
      required: true,
    },
  ],
  hooks: {
    afterChange: [
      () => {
        revalidateTag('global_contactForm')
      },
    ],
  },
}
