import type { NextConfig } from "next";
import createNextIntlPlugin from "next-intl/plugin";

const withNextIntl = createNextIntlPlugin({
  experimental: {
    createMessagesDeclaration: "./messages/en.json",
  },
});

const nextConfig: NextConfig = {
  reactCompiler: true,
  allowedDevOrigins: ["*.trycloudflare.com", "127.0.2.2"],
  images: {
    formats: ["image/avif", "image/webp"],
    qualities: [75],
    minimumCacheTTL: 31_536_000,
    // Paliers alignés sur mobile / tablette / desktop (+ retina) — pas de 4K inutile.
    deviceSizes: [640, 750, 828, 1080, 1200, 1366, 1920, 2048],
    imageSizes: [16, 32, 48, 64, 96, 128, 256, 384],
  },
  experimental: {
    // `lucide-react` is absent on purpose: Next 16 already appends it to this
    // list itself (`server/config.js`, alongside `date-fns`, `lodash-es`,
    // `@heroicons/react`…), so naming it here only duplicated a default.
    optimizePackageImports: [
      "next-intl",
      "@base-ui/react",
      "zod",
      "next-mdx-remote",
      "gray-matter",
      "remark-gfm",
      "reading-time",
      "fuse.js",
    ],
  },
  async headers() {
    return [
      {
        source: "/:path*",
        headers: [
          {
            key: "Referrer-Policy",
            value: "strict-origin-when-cross-origin",
          },
          {
            key: "Permissions-Policy",
            value: "browsing-topics=(), interest-cohort=()",
          },
        ],
      },
      {
        source: "/_next/image",
        headers: [{ key: "X-Robots-Tag", value: "noimageai" }],
      },
    ];
  },
};

export default withNextIntl(nextConfig);
