import type { Field, GlobalConfig } from 'payload' import { userMeetsRole } from '../../modules/access/index.js' import { generalFields } from './fields/general.js' import { themeFields } from './fields/theme.js' type BuildSiteSettingsArgs = { /** Extra fields injected by the client project */ additionalFields?: Field[] /** "Maintenance" tab (maintenance mode) — given when the pages module is on. */ constructionFields?: Field[] /** "E-mails" tab — given with `forms: { emailLayout: true }`. */ emailFields?: Field[] /** "Search engines" tab — search-engine verification, AI assistants, llms.txt note (seo module). */ searchFields?: Field[] /** * Fields for the "System pages" tab — page assignments by role (homepage, * privacy policy, collection archives). Assembled by the caller, which is the * only place that knows which modules are enabled. The tab is omitted when * this is empty. */ systemPageFields?: Field[] } /** * Builds the SiteSettings global. * * Composes tabs out of field groups; it deliberately doesn't know where those * groups come from. Earlier it imported the pages and content modules directly, * which meant a global — a presentation-layer concern — had an opinion about * blogs. Now the plugin's composition root passes fields in, and adding a new * kind of page assignment needs no change here. * * Uses unnamed tabs — data stays flat (siteSettings.siteName, not * siteSettings.general.siteName). Client-provided fields land in their own * "More" tab so core data paths never shift. Tab labels are presentation only. */ export function buildSiteSettings({ additionalFields, constructionFields, emailFields, searchFields, systemPageFields, }: BuildSiteSettingsArgs = {}): GlobalConfig { return { slug: 'site-settings', access: { read: () => true, // Editors and admins only — a plain 'user' account (open sign-up) must // not rewrite the brand, homepage or construction mode. update: ({ req }) => userMeetsRole(req, 'editor'), }, admin: { group: { en: 'Settings', pl: 'Ustawienia' }, }, fields: [ { type: 'tabs', tabs: [ { fields: generalFields, label: { en: 'General', pl: 'Ogólne' }, }, { fields: themeFields, label: { en: 'Theme', pl: 'Motyw' }, }, ...(systemPageFields?.length ? [{ fields: systemPageFields, label: { en: 'System pages', pl: 'Strony systemowe' } }] : []), ...(searchFields?.length ? [{ fields: searchFields, label: { en: 'Search engines', pl: 'Wyszukiwarki' } }] : []), ...(emailFields?.length ? [{ fields: emailFields, label: { en: 'E-mails', pl: 'E-maile' } }] : []), ...(constructionFields?.length ? [{ fields: constructionFields, label: { en: 'Maintenance', pl: 'Prace techniczne' } }] : []), ...(additionalFields?.length ? [{ fields: additionalFields, label: { en: 'More', pl: 'Więcej' } }] : []), ], }, ], label: { en: 'Site settings', pl: 'Ustawienia witryny' }, } }