import { NextRequest, NextResponse } from 'next/server';
import { getLandingPage } from '@/lib/db';

export async function GET(
  _req: NextRequest,
  { params }: { params: { id: string } }
) {
  try {
    const page = getLandingPage(params.id);
    if (!page || !page.opt_in_html) {
      return new NextResponse('Not found', { status: 404 });
    }
    return new NextResponse(page.opt_in_html, {
      headers: { 'Content-Type': 'text/html; charset=utf-8' },
    });
  } catch (err: unknown) {
    const message = err instanceof Error ? err.message : 'Unknown error';
    return NextResponse.json({ error: message }, { status: 500 });
  }
}
