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

export function middleware(request: NextRequest) {
  const localeCookie = request.cookies.get('locale');

  if (localeCookie?.value) {
    return NextResponse.next();
  }

  const response = NextResponse.next();
  response.cookies.set('locale', 'en', {
    path: '/',
    maxAge: 60 * 60 * 24 * 365,
    sameSite: 'lax',
  });

  return response;
}

export const config = {
  matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],
};
