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

const supportedLocales = ['tr', 'en', 'de', 'fr']
const defaultLocale = 'de'

export function middleware(request: NextRequest) {
  // Mevcut dili al
  let locale = request.cookies.get('NEXT_LOCALE')?.value || defaultLocale

  // Geçerli bir dil değilse varsayılan dili kullan
  if (!supportedLocales.includes(locale)) {
    locale = defaultLocale
  }

  // Yanıta dil bilgisini ekle
  const response = NextResponse.next()
  response.cookies.set('NEXT_LOCALE', locale)

  return response
}

export const config = {
  matcher: [
    /*
     * Match all request paths except for the ones starting with:
     * - api (API routes)
     * - _next/static (static files)
     * - _next/image (image optimization files)
     * - favicon.ico (favicon file)
     */
    '/((?!api|_next/static|_next/image|favicon.ico).*)',
  ],
} 