import type { RouteLocationNormalizedLoaded } from 'vue-router' import { controllerIdFromPath } from './controllerRoutes' import { t } from './i18n' import { recordCrumb } from '../state/useBreadcrumbs' import { activeEntry } from '../state/useNavigation' import { settingsEntry, settingsLinkFor } from '../state/useSettings' const PRODUCT_TITLE = 'SummerCMS' /** The visible page indicator used before the SummerCMS product name. */ export function pageIndicator(route: RouteLocationNormalizedLoaded): string { if (route.name === 'login') { return t('backend::lang.auth.title') } if (route.name === 'settings') { return t('backend::lang.settings.title') } if (route.name === 'account') { return t('backend::lang.myaccount.menu_label') } if (route.name === 'settings-form') { return settingsEntry(String(route.params.code ?? ''))?.label ?? String(route.params.code ?? '') } if (route.name === 'home') { return t('backend::lang.nav.empty') } if (route.name === 'not-found') { return t('backend::lang.page.not_found') } const plugin = activeEntry(String(route.params.vendor ?? ''), String(route.params.plugin ?? '')) const controller = controllerIdFromPath(route.path) const section = plugin?.sideMenu.find((item) => item.controller === controller) const controllerLabel = section?.label ?? plugin?.label ?? settingsLinkFor(controller)?.label ?? '' if (route.name === 'create' || route.name === 'record' || route.name === 'preview') { return recordCrumb.value || controllerLabel } return controllerLabel } /** Browser title matching WinterCMS's "Current page | Product" pattern. */ export function documentTitleForRoute(route: RouteLocationNormalizedLoaded): string { const indicator = pageIndicator(route).trim() return indicator === '' ? PRODUCT_TITLE : `${indicator} | ${PRODUCT_TITLE}` }