import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
import createMiddleware from 'next-intl/middleware'
import { routing } from './i18n/routing'

const intlMiddleware = createMiddleware(routing)

export default async function middleware(request: NextRequest) {
  const { pathname } = request.nextUrl
  if (pathname === '/ar/' || pathname === '/en/') {
    return NextResponse.next()
  }

  // Run intl middleware first
  const intlResponse = intlMiddleware(request)

  // All checks passed
  return intlResponse
}

export const config = {
  matcher: ['/', '/(en|ar)/:path*', '/((?!_next|_vercel|.*\\..*).*)']
}
