import type { GlobalConfig } from 'payload'
import { adminOrEditor, anyRole } from '@/access/roles'
import { snippetsFields } from '@/fields/snippetsFields'
import { logGlobalChange } from '@/hooks/auditLog'

export const Scripts: GlobalConfig = {
  slug: 'scripts',
  label: 'Scripts & Snippets',
  access: {
    read: anyRole,
    update: adminOrEditor,
  },
  fields: [
    snippetsFields({
      description:
        'Global snippets are applied on every page. Page-level snippets can be added from each page SEO tab.',
    }),
  ],
  hooks: {
    afterChange: [logGlobalChange('scripts')],
  },
}
