/* eslint-disable operator-linebreak */
/* eslint-disable @typescript-eslint/no-var-requires */
const { withPlugins } = require('next-composed-plugins');
const withLess = require('next-with-less');
const withGraphQL = require('next-plugin-graphql');
const { devices } = require('./@packages/ui/screens');

/** @type {import('next').NextConfig} */
const nextConfig = {
  basePath: process.env.NEXT_PUBLIC_BASE_PATH,
  output: 'standalone',
  swcMinify: true,
  reactStrictMode: true,
  eslint: {
    ignoreDuringBuilds: true,
  },
  compiler: {
    styledComponents: true,
  },
  images: {
    deviceSizes: devices,
  },
  rewrites:
    process.env.NODE_ENV === 'development' &&
    async function rewrites() {
      return [
        {
          source: process.env.NEXT_PUBLIC_URL_CRM_GRAPHQL_PROXY,
          destination: process.env.NEXT_PUBLIC_URL_CRM_GRAPHQL_DIRECT,
        },
        {
          source: process.env.NEXT_PUBLIC_URL_GET_USER_PROXY,
          destination: process.env.NEXT_PUBLIC_URL_GET_USER_DIRECT,
        },
        {
          source: process.env.NEXT_PUBLIC_URL_CORE_FINGAP_PROXY,
          destination: process.env.NEXT_PUBLIC_URL_CORE_FINGAP_DIRECT,
        },
      ];
    },
};

const plugins = [withLess, withGraphQL];

const config = {
  ...nextConfig,
  lessLoaderOptions: {
    lessOptions: {
      modifyVars: {
        'primary-color': process.env.NEXT_PUBLIC_COLOR_PRIMARY,
      },
    },
  },
};

module.exports = withPlugins(config, plugins);
