import { createRelay } from '@coveo/relay';
import { createSelector } from '@reduxjs/toolkit';
import { getAnalyticsNextApiBaseUrl } from '../platform-client.js';
import { getAnalyticsSource } from './analytics-selectors.js';
export const getRelayInstanceFromState = createSelector((state) => state.configuration.organizationId, (state) => state.configuration.environment, (state) => state.configuration.accessToken, (state) => state.configuration.analytics, (state) => getAnalyticsSource(state.configuration.analytics), (organizationId, environment, token, { trackingId, apiBaseUrl, enabled }, source) => createRelay({
    mode: enabled ? 'emit' : 'disabled',
    url: apiBaseUrl ?? getAnalyticsNextApiBaseUrl(organizationId, environment),
    token,
    trackingId: trackingId ?? null,
    source: source,
}));
