import store from "@/store";
import baseMixin from "@/mixins/base-mixin";
import { storeActions } from "@/constants/store-actions";
import { getDeviceIdValue } from "@/helpers/heritage-integration/cookie-helper";
import { experimentTriggers } from "@/constants/experiments";
import { applicationConfig } from "@/constants/application-config";

export async function runExperiments(nextPageName) {
    if (!store.getters.applicationUser.triggeredSiteEntry) {
        await baseMixin.methods.dispatchStoreActionWithLogging(
            storeActions.RUN_EXPERIMENTS_FOR_TRIGGER,
            {
                deviceId: getDeviceIdValue(),
                triggerEvent: experimentTriggers.SITE_ENTRY,
                triggerValue: applicationConfig.SITE_ENTRY_TRIGGER_VALUE,
            },
            nextPageName
        );
    }

    await baseMixin.methods.dispatchStoreActionWithLogging(
        storeActions.RUN_EXPERIMENTS_FOR_TRIGGER,
        {
            deviceId: getDeviceIdValue(),
            triggerEvent: experimentTriggers.PAGE_ENTRY,
            triggerValue: nextPageName,
        },
        nextPageName
    );
}
