import createJiti from "jiti"

import { login } from "./constants/routes/handleAuth.js"
import { myPages } from "./constants/routes/myPages.js"

const jiti = createJiti(new URL(import.meta.url).pathname)
jiti("./env/server")
jiti("./env/client")

/** @type {import('next').NextConfig} */
const nextConfig = {
  poweredByHeader: false,
  eslint: { ignoreDuringBuilds: true },
  images: {
    remotePatterns: [
      {
        protocol: "https",
        hostname: "eu-images.contentstack.com",
        pathname: "/v3/assets/**",
      },
      {
        protocol: "https",
        hostname: "imagevault-stage.scandichotels.com",
      },
      {
        protocol: "https",
        hostname: "imagevault.scandichotels.com",
      },
    ],
  },

  logging: {
    fetches: {
      fullUrl: true,
    },
  },

  output: "standalone",

  webpack: function (config, options) {
    config.module.rules.push({
      test: /\.(graphql|gql)/,
      exclude: /node_modules/,
      loader: "graphql-tag/loader",
    })

    return config
  },
  rewrites() {
    return {
      beforeFiles: [
        { source: login.da, destination: "/da/login" },
        { source: login.de, destination: "/de/login" },
        { source: login.fi, destination: "/fi/login" },
        { source: login.no, destination: "/no/login" },
        { source: login.sv, destination: "/sv/login" },

        {
          source: `${myPages.da}/:path*`,
          destination: `/da/my-pages/:path*`,
        },
        {
          source: `${myPages.de}/:path*`,
          destination: `/de/my-pages/:path*`,
        },
        {
          source: `${myPages.fi}/:path*`,
          destination: `/fi/my-pages/:path*`,
        },
        {
          source: `${myPages.no}/:path*`,
          destination: `/no/my-pages/:path*`,
        },
        {
          source: `${myPages.sv}/:path*`,
          destination: `/sv/my-pages/:path*`,
        },
      ],
    }
  },
}

export default nextConfig
