import createMDX from '@next/mdx'

import type { NextConfig } from 'next'

const nextConfig: NextConfig = {
  basePath: process.env.BASEPATH ?? '',
  trailingSlash:false,
  reactStrictMode: true,
  images:{
    remotePatterns: [
      {
        protocol: process.env.NEXT_PUBLIC_API_URL?.split('://')[0] as 'http' | 'https',
        hostname: process.env.NEXT_PUBLIC_API_URL?.split('://')[1].split(':')[0] as string,
        port: process.env.NEXT_PUBLIC_API_URL?.split('://')[1].split(':')[1] as string,
        pathname: '/storage/**',
      },
    ],
  },
  async rewrites() {
    return [
      {
        source: '/storage/:path*',
        destination: `${process.env.NEXT_PUBLIC_API_URL || 'http://127.0.0.1:8001'}/storage/:path*`,
      },
      {
        source: '/:path*.xml',
        destination: `${process.env.NEXT_PUBLIC_API_URL || 'http://127.0.0.1:8001'}/storage/:path*.xml`,
      },
    ]
  },
  pageExtensions: ['js', 'jsx', 'md', 'mdx', 'ts', 'tsx']
}

const withMDX = createMDX({
  extension: /\.(md|mdx)$/
})

export default withMDX(nextConfig)
