import type { CollectionConfig } from 'payload' import { independentDocListFilter } from '@/payload/admin/localized-list-filter' import { getDocLocaleDefault, resolveDocLocale, syncDocLocaleWithRequestLocale } from '@/payload/doc-locale-hook' const statusField = { name: 'status', label: { en: 'Status', zh: '状态' }, type: 'select' as const, localized: true, defaultValue: 'draft', options: [ { label: 'Draft / 草稿', value: 'draft' }, { label: 'Review / 待审核', value: 'review' }, { label: 'Published / 已发布', value: 'published' }, { label: 'Archived / 已归档', value: 'archived' }, ], required: true, } export const Downloads: CollectionConfig = { slug: 'downloads', hooks: { beforeChange: [syncDocLocaleWithRequestLocale], beforeValidate: [syncDocLocaleWithRequestLocale], }, admin: { baseFilter: independentDocListFilter('title'), defaultColumns: ['title', 'product', 'type', 'version', 'status', 'updatedAt'], description: 'Firmware packages, manuals, software installers, and release notes tied to products. English and Chinese download entries are maintained as separate documents.', group: { en: 'Catalog', zh: '产品' }, useAsTitle: 'title', }, labels: { plural: { en: 'Downloads', zh: '下载' }, singular: { en: 'Download', zh: '下载条目' }, }, access: { read: ({ req }) => { const locale = resolveDocLocale(req) if (!locale) return true return { docLocale: { equals: locale } } }, }, fields: [ { name: 'docLocale', label: { en: 'Doc Locale', zh: '文档语言' }, type: 'select', required: true, defaultValue: getDocLocaleDefault, options: [ { label: 'English / 英文', value: 'en' }, { label: '简体中文', value: 'zh' }, ], admin: { condition: () => false, }, }, { name: 'title', label: { en: 'Title', zh: '标题' }, type: 'text', required: true, localized: true }, { name: 'type', label: { en: 'Type', zh: '分类' }, type: 'select', localized: true, required: true, options: [ { label: 'Firmware / 固件', value: 'firmware' }, { label: 'Manual / 说明书', value: 'manual' }, { label: 'Software / 软件', value: 'software' }, { label: 'Other / 其他', value: 'other' }, ], }, { name: 'product', label: { en: 'Product', zh: '关联产品' }, type: 'relationship', relationTo: 'products', required: true }, { name: 'version', label: { en: 'Version', zh: '版本号' }, type: 'text', localized: true }, { name: 'releaseDate', label: { en: 'Release Date', zh: '发布日期' }, type: 'date', localized: true }, { name: 'file', label: { en: 'File', zh: '安装包/文件' }, type: 'upload', relationTo: 'files', localized: true }, { name: 'checksum', label: { en: 'Checksum', zh: '校验值' }, type: 'text', localized: true }, { name: 'changelog', label: { en: 'Changelog', zh: '更新日志' }, type: 'richText', localized: true }, { name: 'notes', label: { en: 'Notes', zh: '附加说明' }, type: 'richText', localized: true }, { name: 'visibility', label: { en: 'Visibility', zh: '显示设置' }, type: 'group', localized: true, fields: [ { name: 'showInDownloadsCenter', label: { en: 'Show in Downloads Center', zh: '在下载中心显示' }, type: 'checkbox', defaultValue: true, admin: { description: 'Controls whether this item appears in the downloads center and per-product download pages.', }, }, ], }, statusField, ], }