77 lines
2.9 KiB
TypeScript
77 lines
2.9 KiB
TypeScript
import type { EventBranding } from '@/guest/types/event-branding';
|
|
import type { EventBrandingPayload } from '@/guest/services/eventApi';
|
|
|
|
export function mapEventBranding(raw?: EventBrandingPayload | null): EventBranding | null {
|
|
if (!raw) {
|
|
return null;
|
|
}
|
|
|
|
const palette = raw.palette ?? {};
|
|
const typography = raw.typography ?? {};
|
|
const buttons = raw.buttons ?? {};
|
|
const logo = raw.logo ?? {};
|
|
const primary = palette.primary ?? raw.primary_color ?? '';
|
|
const secondary = palette.secondary ?? raw.secondary_color ?? '';
|
|
const background = palette.background ?? raw.background_color ?? '';
|
|
const surface = palette.surface ?? raw.surface_color ?? background;
|
|
const headingFont = typography.heading ?? raw.heading_font ?? raw.font_family ?? null;
|
|
const bodyFont = typography.body ?? raw.body_font ?? raw.font_family ?? null;
|
|
const sizePreset =
|
|
(typography.size as 's' | 'm' | 'l' | undefined)
|
|
?? (raw.font_size as 's' | 'm' | 'l' | undefined)
|
|
?? 'm';
|
|
const logoMode = logo.mode ?? raw.logo_mode ?? (logo.value || raw.logo_url ? 'upload' : 'emoticon');
|
|
const logoValue = logo.value ?? raw.logo_value ?? raw.logo_url ?? raw.icon ?? null;
|
|
const logoPosition = logo.position ?? raw.logo_position ?? 'left';
|
|
const logoSize = (logo.size as 's' | 'm' | 'l' | undefined) ?? (raw.logo_size as 's' | 'm' | 'l' | undefined) ?? 'm';
|
|
const buttonStyle =
|
|
(buttons.style as 'filled' | 'outline' | undefined)
|
|
?? (raw.button_style as 'filled' | 'outline' | undefined)
|
|
?? 'filled';
|
|
const buttonRadius =
|
|
typeof buttons.radius === 'number'
|
|
? buttons.radius
|
|
: typeof raw.button_radius === 'number'
|
|
? raw.button_radius
|
|
: 12;
|
|
const buttonPrimary = buttons.primary ?? raw.button_primary_color ?? primary ?? '';
|
|
const buttonSecondary = buttons.secondary ?? raw.button_secondary_color ?? secondary ?? '';
|
|
const linkColor = buttons.link_color ?? raw.link_color ?? secondary ?? '';
|
|
const welcomeMessage = raw.welcome_message ?? null;
|
|
|
|
return {
|
|
primaryColor: primary ?? '',
|
|
secondaryColor: secondary ?? '',
|
|
backgroundColor: background ?? '',
|
|
fontFamily: bodyFont,
|
|
logoUrl: logoMode === 'upload' ? (logoValue ?? null) : null,
|
|
palette: {
|
|
primary: primary ?? '',
|
|
secondary: secondary ?? '',
|
|
background: background ?? '',
|
|
surface: surface ?? background ?? '',
|
|
},
|
|
typography: {
|
|
heading: headingFont,
|
|
body: bodyFont,
|
|
sizePreset,
|
|
},
|
|
logo: {
|
|
mode: logoMode,
|
|
value: logoValue,
|
|
position: logoPosition,
|
|
size: logoSize,
|
|
},
|
|
buttons: {
|
|
style: buttonStyle,
|
|
radius: buttonRadius,
|
|
primary: buttonPrimary,
|
|
secondary: buttonSecondary,
|
|
linkColor,
|
|
},
|
|
mode: (raw.mode as 'light' | 'dark' | 'auto' | undefined) ?? 'auto',
|
|
useDefaultBranding: raw.use_default_branding ?? undefined,
|
|
welcomeMessage,
|
|
};
|
|
}
|