import { withSentryConfig } from "@sentry/nextjs";
import type { NextConfig } from "next";
import { withSerwist } from "@serwist/turbopack";

const nextConfig: NextConfig = {
  // Docker runs the traced runtime emitted to `.next/standalone`.
  output: "standalone",
  images: {
    remotePatterns: [
      {
        protocol: "https",
        hostname: "platform-lookaside.fbsbx.com",
      },
      {
        protocol: "https",
        hostname: "graph.facebook.com",
      },
      {
        protocol: "https",
        hostname: "**.supabase.co",
        pathname: "/storage/v1/object/public/**",
      },
      {
        protocol: "https",
        hostname: "dbapi.banlv-ai.com",
        pathname: "/storage/v1/object/public/**",
      },
      {
        protocol: "https",
        hostname: "free.picui.cn",
      },
    ],
  },
};

const shouldUploadSentrySourcemaps =
  process.env.CI !== "true" || process.env.SENTRY_UPLOAD_SOURCEMAPS === "1";

export default withSentryConfig(withSerwist(nextConfig), {
  org: "shenzhen-banlv-zhidao-technolo",
  project: "javascript-nextjs",
  silent: !process.env.CI,
  telemetry: false,
  widenClientFileUpload: true,
  // Validation builds keep source maps local; release jobs opt in to upload.
  sourcemaps: {
    disable: !shouldUploadSentrySourcemaps,
  },
  webpack: {
    automaticVercelMonitors: true,
    treeshake: {
      removeDebugLogging: true,
    },
  },
});
