import createNextIntlPlugin from 'next-intl/plugin';
import withMintelConfig from '@mintel/next-config';

const withNextIntl = createNextIntlPlugin();

/** @type {import('next').NextConfig} */
const nextConfig = {
  output: 'standalone',
  async redirects() {
    return [
      // Blog redirects
      {
        source: '/blog',
        destination: '/en/blog',
        permanent: true,
      },
      // Contact redirects
      {
        source: '/contact',
        destination: '/en/contact',
        permanent: true,
      },
      // Team redirects
      {
        source: '/team',
        destination: '/en/team',
        permanent: true,
      },
      // Products redirects
      {
        source: '/products',
        destination: '/en/products',
        permanent: true,
      },
      // Blog post redirects (English)
      {
        source: '/posts/100-renewable-energy-only-with-the-right-cable-infrastructure.html',
        destination: '/en/blog/100-renewable-energy-only-with-the-right-cable-infrastructure',
        permanent: true,
      },
      {
        source: '/posts/billion-euro-package-for-infrastructure-the-cable-boom-is-coming.html',
        destination: '/en/blog/billion-euro-package-for-infrastructure-the-cable-boom-is-coming',
        permanent: true,
      },
      {
        source: '/posts/cable-abbreviations-decoded-the-key-to-choosing-the-right-cable.html',
        destination: '/en/blog/cable-abbreviations-decoded-the-key-to-choosing-the-right-cable',
        permanent: true,
      },
      {
        source: '/posts/cable-drum-quality-the-foundation-of-cable-reliability.html',
        destination: '/en/blog/cable-drum-quality-the-foundation-of-cable-reliability',
        permanent: true,
      },
      {
        source: '/posts/cable-drum-safety-ensuring-smooth-operations-and-accident-free-environments.html',
        destination: '/en/blog/cable-drum-safety-ensuring-smooth-operations-and-accident-free-environments',
        permanent: true,
      },
      {
        source: '/posts/climate-neutral-by-2050-what-we-need-to-do-to-achieve-this-goal.html',
        destination: '/en/blog/climate-neutral-by-2050-what-we-need-to-do-to-achieve-this-goal',
        permanent: true,
      },
      {
        source: '/posts/cost-comparison-copper-vs-aluminum-cables-in-wind-farms-which-is-worthwhile-in-the-long-term.html',
        destination: '/en/blog/cost-comparison-copper-vs-aluminum-cables-in-wind-farms-which-is-worthwhile-in-the-long-term',
        permanent: true,
      },
      {
        source: '/posts/expanding-the-grid-by-2025-building-the-foundation-for-a-successful-energy-transition.html',
        destination: '/en/blog/expanding-the-grid-by-2025-building-the-foundation-for-a-successful-energy-transition',
        permanent: true,
      },
      {
        source: '/posts/eye-opening-realities-of-green-energy-transformation.html',
        destination: '/en/blog/eye-opening-realities-of-green-energy-transformation',
        permanent: true,
      },
      {
        source: '/posts/focus-on-wind-farm-construction-three-typical-cable-challenges.html',
        destination: '/en/blog/focus-on-wind-farm-construction-three-typical-cable-challenges',
        permanent: true,
      },
      {
        source: '/posts/from-smart-to-sustainable-this-is-what-the-energy-industry-will-look-like-in-the-near-future.html',
        destination: '/en/blog/from-smart-to-sustainable-this-is-what-the-energy-industry-will-look-like-in-the-near-future',
        permanent: true,
      },
      {
        source: '/posts/green-energy-starts-underground-and-with-a-plan.html',
        destination: '/en/blog/green-energy-starts-underground-and-with-a-plan',
        permanent: true,
      },
      {
        source: '/posts/how-the-cable-industry-is-driving-sustainability-and-renewable-energies-forward.html',
        destination: '/en/blog/how-the-cable-industry-is-driving-sustainability-and-renewable-energies-forward',
        permanent: true,
      },
      {
        source: '/posts/how-the-right-cables-quietly-power-the-green-energy-revolution.html',
        destination: '/en/blog/how-the-right-cables-quietly-power-the-green-energy-revolution',
        permanent: true,
      },
      {
        source: '/posts/how-to-choose-the-right-cable-for-your-next-project.html',
        destination: '/en/blog/how-to-choose-the-right-cable-for-your-next-project',
        permanent: true,
      },
      {
        source: '/posts/is-wind-energy-really-enough-a-deeper-dive-behind-the-headlines.html',
        destination: '/en/blog/is-wind-energy-really-enough-a-deeper-dive-behind-the-headlines',
        permanent: true,
      },
      {
        source: '/posts/klz-in-the-directory-of-wind-energy-2025.html',
        destination: '/en/blog/klz-in-the-directory-of-wind-energy-2025',
        permanent: true,
      },
      {
        source: '/posts/na2xsf2y-three-conductor-medium-voltage-cable-available.html',
        destination: '/en/blog/na2xsf2y-three-conductor-medium-voltage-cable-available',
        permanent: true,
      },
      {
        source: '/posts/recycling-of-cable-drums-sustainability-in-wind-power-projects.html',
        destination: '/en/blog/recycling-of-cable-drums-sustainability-in-wind-power-projects',
        permanent: true,
      },
      {
        source: '/posts/securing-the-future-with-h1z2z2-k-our-solar-cable-for-intersolar-2025.html',
        destination: '/en/blog/securing-the-future-with-h1z2z2-k-our-solar-cable-for-intersolar-2025',
        permanent: true,
      },
      {
        source: '/posts/the-art-of-cable-logistics-moving-the-backbone-of-modern-energy-networks.html',
        destination: '/en/blog/the-art-of-cable-logistics-moving-the-backbone-of-modern-energy-networks',
        permanent: true,
      },
      {
        source: '/posts/the-best-underground-cables-for-wind-power-and-solar-order-from-us-now.html',
        destination: '/en/blog/the-best-underground-cables-for-wind-power-and-solar-order-from-us-now',
        permanent: true,
      },
      {
        source: '/posts/the-perfect-cable-inquiry-how-to-save-yourself-unnecessary-queries.html',
        destination: '/en/blog/the-perfect-cable-inquiry-how-to-save-yourself-unnecessary-queries',
        permanent: true,
      },
      {
        source: '/posts/this-what-you-need-to-know-about-renewable-energies-in-2025.html',
        destination: '/en/blog/this-what-you-need-to-know-about-renewable-energies-in-2025',
        permanent: true,
      },
      {
        source: '/posts/welcome-to-the-future-of-klz-our-new-website-is-live.html',
        destination: '/en/blog/welcome-to-the-future-of-klz-our-new-website-is-live',
        permanent: true,
      },
      {
        source: '/posts/what-makes-a-first-class-cable-find-out-here.html',
        destination: '/en/blog/what-makes-a-first-class-cable-find-out-here',
        permanent: true,
      },
      {
        source: '/posts/which-cables-for-wind-power-differences-from-low-to-extra-high-voltage-explained-2.html',
        destination: '/en/blog/which-cables-for-wind-power-differences-from-low-to-extra-high-voltage-explained-2',
        permanent: true,
      },
      {
        source: '/posts/why-the-n2xsf2y-is-the-ideal-cable-for-your-energy-project.html',
        destination: '/de/blog/why-the-n2xsf2y-is-the-ideal-cable-for-your-energy-project',
        permanent: true,
      },
      {
        source: '/posts/why-wind-farm-grid-connection-cables-must-withstand-extreme-loads.html',
        destination: '/en/blog/why-wind-farm-grid-connection-cables-must-withstand-extreme-loads',
        permanent: true,
      },
      // Product redirects (English)
      {
        source: '/products/power-cables/high-voltage-cables/n2xsfl2y',
        destination: '/en/products/n2xsfl2y-hv',
        permanent: true,
      },
      {
        source: '/products/power-cables/high-voltage-cables/na2xsfl2y-3',
        destination: '/en/products/na2xsfl2y-hv',
        permanent: true,
      },
      {
        source: '/products/power-cables/low-voltage-cables/n2x2y',
        destination: '/en/products/n2x2y',
        permanent: true,
      },
      {
        source: '/products/power-cables/low-voltage-cables/n2xy',
        destination: '/en/products/n2xy',
        permanent: true,
      },
      {
        source: '/products/power-cables/low-voltage-cables/na2x2y',
        destination: '/en/products/na2x2y',
        permanent: true,
      },
      {
        source: '/products/power-cables/low-voltage-cables/na2xy',
        destination: '/en/products/na2xy',
        permanent: true,
      },
      {
        source: '/products/power-cables/low-voltage-cables/nay2y',
        destination: '/en/products/nay2y',
        permanent: true,
      },
      {
        source: '/products/power-cables/low-voltage-cables/naycwy',
        destination: '/en/products/naycwy',
        permanent: true,
      },
      {
        source: '/products/power-cables/low-voltage-cables/nayy',
        destination: '/en/products/nayy',
        permanent: true,
      },
      {
        source: '/products/power-cables/low-voltage-cables/ny2y',
        destination: '/en/products/ny2y',
        permanent: true,
      },
      {
        source: '/products/power-cables/low-voltage-cables/nycwy',
        destination: '/en/products/nycwy',
        permanent: true,
      },
      {
        source: '/products/power-cables/low-voltage-cables/nyy',
        destination: '/en/products/nyy',
        permanent: true,
      },
      {
        source: '/products/power-cables/medium-voltage-cables/n2xs2y',
        destination: '/en/products/n2xs2y',
        permanent: true,
      },
      {
        source: '/products/power-cables/medium-voltage-cables/n2xsf2y',
        destination: '/en/products/n2xsf2y',
        permanent: true,
      },
      {
        source: '/products/power-cables/medium-voltage-cables/n2xsfl2y-3',
        destination: '/en/products/n2xsfl2y-mv',
        permanent: true,
      },
      {
        source: '/products/power-cables/medium-voltage-cables/na2xs2y',
        destination: '/en/products/na2xs2y',
        permanent: true,
      },
      {
        source: '/products/power-cables/medium-voltage-cables/na2xsf2y',
        destination: '/en/products/na2xsf2y',
        permanent: true,
      },
      {
        source: '/products/power-cables/medium-voltage-cables/na2xsfl2y',
        destination: '/en/products/na2xsfl2y-mv',
        permanent: true,
      },
      {
        source: '/products/power-cables/medium-voltage-cables/na2xsy',
        destination: '/en/products/na2xsy',
        permanent: true,
      },
      {
        source: '/products/solar-cables/h1z2z2-k',
        destination: '/en/products/h1z2z2-k',
        permanent: true,
      },
      // Product redirects (German)
      {
        source: '/de/produkte/solarkabel/h1z2z2-k',
        destination: '/de/produkte/h1z2z2-k',
        permanent: true,
      },
      {
        source: '/de/produkte/stromkabel/niederspannungskabel/naycwy-2',
        destination: '/de/produkte/naycwy',
        permanent: true,
      },
      {
        source: '/de/produkte/stromkabel/niederspannungskabel/ny2y-2',
        destination: '/de/produkte/ny2y',
        permanent: true,
      },
      // VCF redirects
      {
        source: '/vcf/klaus-mintel',
        destination: '/klaus-mintel.vcf',
        permanent: true,
      },
      {
        source: '/vcf/michael-bodemer',
        destination: '/michael-bodemer.vcf',
        permanent: true,
      },
    ];
  },
  images: {
    remotePatterns: [
      {
        protocol: 'https',
        hostname: 'klz-cables.com',
        port: '',
        pathname: '/wp-content/uploads/**',
      },
    ],
    dangerouslyAllowSVG: true,
    contentDispositionType: 'attachment',
    contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;",
  },
  async rewrites() {
    const umamiUrl =
      process.env.UMAMI_API_ENDPOINT ||
      process.env.UMAMI_SCRIPT_URL ||
      process.env.NEXT_PUBLIC_UMAMI_SCRIPT_URL ||
      'https://analytics.infra.mintel.me';
    const glitchtipUrl = process.env.SENTRY_DSN
      ? new URL(process.env.SENTRY_DSN).origin
      : 'https://errors.infra.mintel.me';

    const directusUrl = process.env.INTERNAL_DIRECTUS_URL || process.env.DIRECTUS_URL || 'https://cms.klz-cables.com';

    return [
      {
        source: '/cms/:path*',
        destination: `${directusUrl}/:path*`,
      },
    ];
  },
};

const nextIntlConfig = withNextIntl(nextConfig);

export default withMintelConfig(nextIntlConfig);
