/** @type {import('next').NextConfig} */
const isProd = process.env.NODE_ENV === "production";
const nextConfig = {
  // output: "export", // Comment this line when not building the project
  typescript: {
    ignoreBuildErrors: true,
  },
  reactStrictMode: false,
  trailingSlash: true,
  // swcMinify: true,
  basePath: isProd ? "" : undefined,
  assetPrefix: isProd ? "" : undefined,
  // plugins: isProd ? ['transform-remove-console'] : [],
  images: {
    loader: "imgix",
    path: "/",
  },
  experimental: {
    serverActions: {
      bodySizeLimit: '20mb',
    },
  },
  //  compiler: {
  //   removeConsole: true,
  // },
  // async headers() {
  //   return [
  //     {
  //       source: '/(.*)',
  //       headers: [
  //         {
  //           key: 'Strict-Transport-Security',
  //           value: 'max-age=31536000; includeSubDomains',
  //         },
  //         {
  //           key: 'X-Frame-Options',
  //           value: 'SAMEORIGIN', // or 'DENY' depending on your requirements
  //         },
  //         {
  //           key: 'X-Content-Type-Options',
  //           value: 'nosniff',
  //         },
  //       ],
  //     },
  //   ];
  // },
  // async headers() {
  //   return [
  //     {
  //       source: '/(.*)',
  //       headers: [
  //         {
  //           key: 'Strict-Transport-Security',
  //           value: 'max-age=31536000; includeSubDomains',
  //         },
  //         {
  //           key: 'X-Frame-Options',
  //           value: 'SAMEORIGIN',
  //         },
  //         {
  //           key: 'X-Content-Type-Options',
  //           value: 'nosniff',
  //         },
  //         {
  //           key: 'Content-Security-Policy',
  //           value: [
  //             "frame-src 'self' https://*.paynearme.com https://applepay.cdn-apple.com",
  //             "connect-src 'self' https://*.paynearme.com https://www.googletagmanager.com",
  //           ].join('; '),
  //         },
  //       ],
  //     },
  //   ];
  // },
  async headers() {
    return [
      {
        source: '/.well-known/apple-developer-merchantid-domain-association',
        headers: [
          {
            key: 'Content-Type',
            value: 'text/plain',
          },
          {
            key: 'Content-Disposition',
            value: 'inline',
          },
        ],
      },
      {
        source: '/(.*)',
        headers: [
          // Security headers
          {
            key: 'Strict-Transport-Security',
            value: 'max-age=31536000; includeSubDomains',
          },
          {
            key: 'X-Frame-Options',
            value: 'SAMEORIGIN',
          },
          {
            key: 'X-Content-Type-Options',
            value: 'nosniff',
          },
          // CORS — allow all origins
          {
            key: 'Access-Control-Allow-Origin',
            value: '*',
          },
          {
            key: 'Access-Control-Allow-Methods',
            value: 'GET, POST, PUT, PATCH, DELETE, OPTIONS',
          },
          {
            key: 'Access-Control-Allow-Headers',
            value: '*',
          },
          // CSP — allow all
          {
            key: 'Content-Security-Policy',
            value: [
              "frame-src *",
              "connect-src *",
              "script-src 'self' 'unsafe-inline' 'unsafe-eval' *",
              "img-src 'self' data: blob: *",
              "style-src 'self' 'unsafe-inline' *",
              "font-src 'self' data: *",
            ].join('; '),
          },
        ],
      },
    ];
  },
};

module.exports = nextConfig;
