import { augmentAnalyticsWithAtomicVersion, augmentWithExternalMiddleware, getNextAnalyticsConfig } from "../../common/interface/analytics-config.js";
function getAnalyticsConfig(searchEngineConfig, enabled) {
    switch(searchEngineConfig.analytics?.analyticsMode){
        case 'next':
            return getNextAnalyticsConfig(searchEngineConfig, enabled);
        default:
            return getLegacyAnalyticsConfig(searchEngineConfig, enabled);
    }
}
function getLegacyAnalyticsConfig(searchEngineConfig, enabled) {
    const analyticsClientMiddleware = (event, payload)=>augmentAnalytics(event, payload, searchEngineConfig);
    const defaultConfiguration = {
        analyticsClientMiddleware,
        enabled,
        documentLocation: document.location.href,
        ...document.referrer && {
            originLevel3: document.referrer
        }
    };
    if (searchEngineConfig.analytics) return {
        ...defaultConfiguration,
        ...searchEngineConfig.analytics,
        analyticsClientMiddleware
    };
    return defaultConfiguration;
}
function augmentAnalytics(event, payload, config) {
    let result = augmentWithExternalMiddleware(event, payload, config);
    result = augmentAnalyticsWithAtomicVersion(result);
    return result;
}
export { getAnalyticsConfig };
