import type { CollectionConfig } from 'payload'
// TODO: ScriptSectionBlock causes admin UI rendering issues - needs investigation
// import { ScriptSectionBlock } from '../blocks/ScriptSectionBlock'
import { isYouTubeManager, hasYouTubeAccess } from '../lib/youtubeAccess'

/**
 * YtScriptTemplates - Minimal Version
 */
export const YtScriptTemplates: CollectionConfig = {
  slug: 'yt-script-templates',
  dbName: 'yt_script_tpl',
  labels: {
    singular: 'Script Template',
    plural: 'Script Templates',
  },
  admin: {
    group: 'YouTube',
    useAsTitle: 'name',
  },
  access: {
    read: hasYouTubeAccess,
    create: isYouTubeManager,
    update: isYouTubeManager,
    delete: isYouTubeManager,
  },
  fields: [
    {
      name: 'name',
      type: 'text',
      required: true,
      localized: true,
      label: 'Name',
    },
    {
      name: 'channel',
      type: 'relationship',
      relationTo: 'youtube-channels',
      required: true,
      label: 'Channel',
    },
    {
      name: 'series',
      type: 'text',
      required: true,
      label: 'Series',
    },
    {
      name: 'format',
      type: 'select',
      required: true,
      label: 'Format',
      options: [
        { label: 'Short (45-60s)', value: 'short' },
        { label: 'Longform (8-16 Min)', value: 'longform' },
      ],
    },
    {
      name: 'description',
      type: 'textarea',
      label: 'Description',
      localized: true,
    },
    // TODO: Blocks field disabled - causes admin UI rendering issues
    // {
    //   name: 'blocks',
    //   type: 'blocks',
    //   label: 'Template Sections',
    //   blocks: [ScriptSectionBlock],
    // },
  ],
  timestamps: true,
}
