import { NextResponse } from 'next/server';
import fs from 'fs';
import path from 'path';

export const dynamic = 'force-static';

export async function GET() {
  try {
    const fontsDir = path.join(process.cwd(), 'public/fonts/figlet-fonts');
    const files = fs.readdirSync(fontsDir);

    const fonts = files
      .filter(file => file.endsWith('.flf'))
      .map(file => {
        const name = file.replace('.flf', '');
        return {
          name,
          fileName: file,
          path: `/fonts/figlet-fonts/${file}`,
        };
      })
      .sort((a, b) => a.name.localeCompare(b.name));

    return NextResponse.json(fonts);
  } catch (error) {
    console.error('Error reading fonts directory:', error);
    return NextResponse.json({ error: 'Failed to load fonts' }, { status: 500 });
  }
}
