/** @type {import('next').NextConfig} */
const nextConfig = {
  images: {
    unoptimized: true,
  },
  async redirects() {
    return [
      {
        source: '/favicon.ico',
        destination: '/icon.svg',
        permanent: false,
      },
    ];
  },
  async rewrites() {
    // Proxy /api/* to Django backend. Uses NEXT_PUBLIC_API_BASE_URL from .env.local
    // Remove the trailing /api since the source already includes it
    const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL?.replace(/\/api$/, "");
    if (!baseUrl) return [];
    return [
      {
        source: "/api/:path*",
        destination: `${baseUrl}/api/:path*`,
      },
    ];
  },
}

export default nextConfig
