import path from 'path'
import type { CollectionConfig } from 'payload'
import { fileURLToPath } from 'url'

const dirname = path.dirname(fileURLToPath(import.meta.url))

// Images used on the site: the hero, the lesson scene, course posters. Stored on disk (a Docker volume).
export const Media: CollectionConfig = {
  slug: 'media',
  labels: { singular: { ar: 'صورة', en: 'Image' }, plural: { ar: 'الصور', en: 'Images' } },
  admin: { group: { ar: 'المحتوى', en: 'Content' } },
  access: { read: () => true },
  fields: [
    {
      name: 'alt',
      type: 'text',
      required: true,
      localized: true,
      label: { ar: 'وصف الصورة (لقارئات الشاشة)', en: 'Alternative text (for screen readers)' },
    },
  ],
  upload: {
    staticDir: process.env.MEDIA_DIR || path.resolve(dirname, '../../media'),
    mimeTypes: ['image/*'],
    imageSizes: [
      { name: 'card', width: 640, height: 360, position: 'centre' },
      { name: 'wide', width: 1280 },
    ],
    adminThumbnail: 'card',
  },
}
