import { NextResponse } from 'next/server';
import pool from '../../../lib/db';

export const dynamic = 'force-dynamic';

export async function GET() {
  try {
    const [rows] = await pool.execute(
      `SELECT id, current_page, progress, status, plan, utm_ad, created_at, updated_at
       FROM onboarding_users
       ORDER BY updated_at DESC
       LIMIT 500`,
    );
    return NextResponse.json({ users: rows });
  } catch (error) {
    console.error('Dashboard API error:', error);
    return NextResponse.json({ error: 'Internal error' }, { status: 500 });
  }
}
