/** The church's branding from the backend, for the server-rendered frame of every page. */ export type BrandingData = { name: string; shortName: string | null; logoUrl: string | null; colours: { primary: string; accent: string | null }; signupEnabled: boolean; setupNeeded: boolean; }; const api = (process.env.ACCOUNTS_API_URL || "http://127.0.0.1:5200").replace(/\/+$/, ""); export async function loadBranding(): Promise { try { const res = await fetch(`${api}/api/v2/branding`, { cache: "no-store" }); if (res.ok) return (await res.json()) as BrandingData; } catch { // The backend is starting or down: plain defaults, the page still works. } return { name: "Sign in", shortName: null, logoUrl: null, colours: { primary: "#1f4e79", accent: null }, signupEnabled: true, setupNeeded: false }; } /** "#1f4e79" → "31 78 121" (Tailwind's rgb(var(--brand) / alpha)), and a darker shade for hover. */ export function rgbVars(hex: string): { brand: string; dark: string } { const m = /^#([0-9a-f]{6})$/i.exec(hex) ?? ["", "1f4e79"]; const n = parseInt(m[1]!, 16); const [r, g, b] = [(n >> 16) & 255, (n >> 8) & 255, n & 255]; const d = (x: number) => Math.round(x * 0.8); return { brand: `${r} ${g} ${b}`, dark: `${d(r)} ${d(g)} ${d(b)}` }; }