import type { CSSProperties } from 'react'; import type { FontMap, Theme, ThemeRadius } from './types'; const buttonRadius: Record = { none: '0px', small: '4px', medium: '10px', large: '16px', full: '9999px', }; const cardRadius: Record = { none: '0px', small: '6px', medium: '14px', large: '22px', full: '28px', }; const fallbackFont = 'ui-sans-serif, system-ui, sans-serif'; function family(key: string, fonts: FontMap): string { const name = fonts[key]; return name ? `'${name}', ${fallbackFont}` : fallbackFont; } /** Turn a plan theme into the CSS variables every section reads. */ export function themeStyle(theme: Theme, fonts: FontMap): CSSProperties { return { '--sf-bg': theme.colors.background, '--sf-surface': theme.colors.surface, '--sf-fg': theme.colors.foreground, '--sf-muted': theme.colors.muted, '--sf-primary': theme.colors.primary, '--sf-primary-fg': theme.colors.primaryForeground, '--sf-accent': theme.colors.accent, '--sf-border': theme.colors.border, '--sf-radius': buttonRadius[theme.radius] ?? buttonRadius.medium, '--sf-radius-card': cardRadius[theme.radius] ?? cardRadius.medium, '--sf-font-heading': family(theme.fonts.heading, fonts), '--sf-font-body': family(theme.fonts.body, fonts), } as CSSProperties; } /** Web address that loads the theme's fonts. */ export function fontStylesheetUrl(theme: Theme, fonts: FontMap): string | null { const keys = [...new Set([theme.fonts.heading, theme.fonts.body])].filter( (key) => key in fonts, ); if (keys.length === 0) { return null; } const families = keys.map((key) => `${key}:400,500,600,700`).join('|'); return `https://fonts.bunny.net/css?family=${families}&display=swap`; } const ringgit = new Intl.NumberFormat('en-MY', { style: 'currency', currency: 'MYR', }); export function formatPrice(amount: number): string { return ringgit.format(amount); }