/**
 * @type {import('next').NextConfig}
 */

const output = 'standalone';
const securityHeaders = [
  { key: 'Content-Security-Policy', value: "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self' data:; connect-src 'self' https: wss:; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'; upgrade-insecure-requests" },
  { key: 'Referrer-Policy', value: 'strict-origin-when-cross-origin' },
  { key: 'Permissions-Policy', value: 'camera=(), geolocation=(), payment=(), usb=()' },
  { key: 'X-Content-Type-Options', value: 'nosniff' },
  { key: 'X-Frame-Options', value: 'DENY' },
  { key: 'Strict-Transport-Security', value: 'max-age=31536000; includeSubDomains' },
];

const nextConfig = {
trailingSlash: true,
  distDir: 'build',
  output,
  outputFileTracingRoot: process.cwd(),
  basePath: "",
  images: {
    unoptimized: true,
    remotePatterns: [
      {
        protocol: 'https',
        hostname: '**',
      },
    ],
  },
  async headers() {
    const rules = [{ source: '/(.*)', headers: securityHeaders }];
    const noIndexHeader = { key: 'X-Robots-Tag', value: 'noindex, nofollow, noarchive' };

    if (process.env.NEXT_PUBLIC_DEMO_MODE === 'true') {
      rules[0].headers = [...securityHeaders, noIndexHeader];
      return rules;
    }

    rules.push({
      source: '/(dashboard|clients|intake-leads|session-memory|start-session|client-portal|profile|workspace-settings|users|roles|permissions)/(.*)',
      headers: [noIndexHeader],
    });
    return rules;
  },
 
}

export default nextConfig
