import React from 'react'; import { render } from '@react-email/render'; import { NextResponse } from 'next/server'; import { templateMap } from '../../../../emails/registry'; import { resolveLocale } from '../../../../emails/i18n/types'; import type { ShopSummaryPeriod } from '../../../../emails/shop-summary'; export async function GET( request: Request, context: { params: Promise<{ template: string }> } ) { const { template } = await context.params; const entry = templateMap[template]; if (!entry) { return NextResponse.json({ error: 'Template not found' }, { status: 404 }); } const { searchParams } = new URL(request.url); const locale = resolveLocale(searchParams.get('locale') || undefined); const period = (searchParams.get('period') || entry.defaultProps?.period || 'weekly') as ShopSummaryPeriod; const html = await render( React.createElement(entry.component, { locale, ...(entry.id === 'shop-summary' ? { period } : {}), ...entry.defaultProps, }) ); return new NextResponse(html, { headers: { 'Content-Type': 'text/html; charset=utf-8', }, }); }