import type { Field } from 'payload'

type SnippetsFieldOptions = {
  description?: string
  label?: string
  name?: string
}

export const snippetsFields = (options?: SnippetsFieldOptions): Field => {
  const {
    name = 'snippets',
    label = 'Snippets',
    description = 'Paste raw snippets directly. Leave blank to skip a placement.',
  } = options || {}

  return {
    name,
    label,
    type: 'group',
    admin: {
      description,
    },
    fields: [
      {
        name: 'head',
        label: 'Head',
        type: 'textarea',
        admin: {
          description: 'Injected inside <head>.',
          rows: 6,
        },
      },
      {
        name: 'bodyTop',
        label: 'Body Top',
        type: 'textarea',
        admin: {
          description: 'Injected immediately after <body> opens.',
          rows: 6,
        },
      },
      {
        name: 'bodyBottom',
        label: 'Body Bottom',
        type: 'textarea',
        admin: {
          description: 'Injected before </body> closes.',
          rows: 6,
        },
      },
    ],
  }
}
