import { NextRequest, NextResponse } from 'next/server'

export const dynamic = 'force-dynamic'

const DEFAULT_THEME = {
  accent: '#f59e0b',
  accentDark: '#d97706',
  accentLight: '#fbbf24',
  bgPrimary: '#0a0a0f',
  bgSecondary: '#111118',
  bgCard: '#16161f',
  success: '#10b981',
  error: '#ef4444',
  info: '#3b82f6',
  purple: '#8b5cf6',
}

export async function GET() {
  try {
    const prisma = (await import('@/lib/prisma')).default
    const settings = await prisma.setting.findMany({
      where: { key: { startsWith: 'theme_' } },
    })

    const theme = { ...DEFAULT_THEME }
    for (const s of settings) {
      const key = s.key.replace('theme_', '') as keyof typeof theme
      if (key in theme) (theme as any)[key] = s.value
    }

    return NextResponse.json({ theme })
  } catch {
    return NextResponse.json({ theme: DEFAULT_THEME })
  }
}
