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

// next js bug
export function middleware(request: NextRequest) {
  if (request.method === 'POST') {
    if (!request.headers.has('next-action')) {
      console.log('[Middleware] Blocked POST without Next-Action header')
      return new NextResponse('Method Not Allowed', { status: 405 })
    }
  }

  return NextResponse.next()
}

export const config = {
  // All pages with contact forms — exclude /api and /admin (Payload CMS)
  matcher: ['/((?!api|admin|_next/static|_next/image|favicon.ico).*)'],
}
