const defaultAdminUploadsUrl = "https://admin.codesitex.com/admin";
const configuredAdminUploadsUrl =
  process.env.ADMIN_UPLOADS_BASE_URL ||
  process.env.NEXT_PUBLIC_ADMIN_UPLOADS_BASE_URL ||
  defaultAdminUploadsUrl;

const adminUploadsUrl = (() => {
  try {
    return new URL(configuredAdminUploadsUrl);
  } catch {
    return new URL(defaultAdminUploadsUrl);
  }
})();

/** @type {import('next').NextConfig} */
const nextConfig = {
  output: 'standalone',
  images: {
    remotePatterns: [
      {
        protocol: adminUploadsUrl.protocol.replace(":", ""),
        hostname: adminUploadsUrl.hostname,
        port: adminUploadsUrl.port || undefined,
        pathname: `${adminUploadsUrl.pathname.replace(/\/$/, "")}/**`,
      },
    ],
  },
};

export default nextConfig;