export function withGradial(nextConfig = {}, options = {}) {
    const assetPrefix = options.assetPrefix || '/.gradial-dam';
    const userRewrites = nextConfig.rewrites;
    return {
        ...nextConfig,
        rewrites: async () => {
            const gradialRewrites = [
                {
                    source: `${assetPrefix}/:path*`,
                    destination: `/api/aci-assets${assetPrefix}/:path*`,
                },
            ];
            if (!userRewrites)
                return gradialRewrites;
            const userResult = await (typeof userRewrites === 'function' ? userRewrites() : userRewrites);
            if (Array.isArray(userResult)) {
                return [...gradialRewrites, ...userResult];
            }
            return {
                ...userResult,
                beforeFiles: [...gradialRewrites, ...(userResult.beforeFiles ?? [])],
            };
        },
    };
}
