import type { InvoiceTemplate } from "../types"; const templates = new Map(); // Register built-in templates (lazy import to avoid loading all at once) let registered = false; async function ensureRegistered(): Promise { if (registered) return; const { mandalaTemplate } = await import("./mandala"); const { minimalTemplate } = await import("./minimal"); templates.set("mandala", mandalaTemplate); templates.set("minimal", minimalTemplate); registered = true; } export function getTemplate(name: string): InvoiceTemplate { // Synchronous lookup — templates must be registered first // For built-in templates, they self-register on import const template = templates.get(name); if (!template) { const available = Array.from(templates.keys()).join(", "); throw new Error( `Unknown template "${name}". Available: ${available || "none (call ensureTemplatesLoaded() first)"}`, ); } return template; } export async function ensureTemplatesLoaded(): Promise { await ensureRegistered(); } export function listTemplates(): InvoiceTemplate[] { return Array.from(templates.values()); } export function registerTemplate(template: InvoiceTemplate): void { templates.set(template.name, template); }