import { NextResponse } from 'next/server';
import { getThemeSettings } from '@theme/data/server/theme';

export const dynamic = 'force-dynamic';
export const revalidate = 0;

export async function GET() {
  try {
    const settings = await getThemeSettings();
    return NextResponse.json(settings, {
      headers: {
        'Cache-Control': 'no-store, must-revalidate',
        'Pragma': 'no-cache'
      }
    });
  } catch (error) {
    console.error('Error in theme-settings API:', error);
    // Return empty object with 200 so checkout falls back to settings.js silently
    // without surfacing as a 5xx in monitoring tools.
    return NextResponse.json(
      {},
      {
        status: 200,
        headers: {
          'Cache-Control': 'no-store, must-revalidate',
          'Pragma': 'no-cache'
        }
      }
    );
  }
}
