import type { TenantEvent } from '../api'; export type BrandingPalette = { colors: string[]; font?: string; }; export function extractBrandingPalette(settings: TenantEvent['settings'] | null | undefined): BrandingPalette { const colors: string[] = []; let font: string | undefined; if (settings && typeof settings === 'object') { const brand = (settings as Record).branding; if (brand && typeof brand === 'object') { const palette = (brand as Record).palette as Record | undefined; const colorPalette = palette ?? (brand as Record).colors; if (colorPalette && typeof colorPalette === 'object') { const paletteRecord = colorPalette as Record; for (const key of Object.keys(paletteRecord)) { const value = paletteRecord[key]; if (typeof value === 'string' && value.trim().length) { colors.push(value); } } } const directColors = [ (brand as Record).primary_color, (brand as Record).secondary_color, (brand as Record).background_color, ]; directColors.forEach((value) => { if (typeof value === 'string' && value.trim()) { colors.push(value); } }); const typography = (brand as Record).typography as Record | undefined; const fontValue = (brand as Record).font_family ?? (typography?.body as string | undefined) ?? (typography?.heading as string | undefined); if (typeof fontValue === 'string' && fontValue.trim()) { font = fontValue.trim(); } } } return { colors, font, }; }