"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.destination = void 0;
const tslib_1 = require("tslib");
const shim_1 = require("../../runtime/shim");
const init_script_1 = require("./init-script");
const actions_core_1 = require("@segment/actions-core");
const trackEvent_1 = tslib_1.__importDefault(require("./trackEvent"));
const identifyUser_1 = tslib_1.__importDefault(require("./identifyUser"));
exports.destination = {
    name: 'VWO Web Mode (Actions)',
    slug: 'actions-vwo-web',
    mode: 'device',
    presets: [
        {
            name: 'Track Event',
            subscribe: 'type = "track"',
            partnerAction: 'trackEvent',
            mapping: actions_core_1.defaultValues(trackEvent_1.default.fields)
        },
        {
            name: 'Identify User',
            subscribe: 'type = "identify"',
            partnerAction: 'identifyUser',
            mapping: actions_core_1.defaultValues(identifyUser_1.default.fields)
        }
    ],
    settings: {
        vwoAccountId: {
            description: 'Your VWO account ID, used for fetching your VWO async smart code.',
            label: 'VWO Account ID',
            type: 'number',
            required: true
        },
        settingsTolerance: {
            description: 'The maximum amount of time (in milliseconds) to wait for test settings before VWO will simply display your original page.',
            label: 'Settings Tolerance',
            type: 'number',
            default: 2000
        },
        libraryTolerance: {
            description: 'The maximum amount of time (in milliseconds) to wait for VWO’s full library to be downloaded before simply displaying your original page.',
            label: 'Library Tolerance',
            type: 'number',
            default: 2500
        },
        useExistingJquery: {
            description: 'If your page already includes JQuery, you can set this to “true”. Otherwise, VWO will include JQuery onto the page for you. VWO needs JQuery on the page to function correctly. ',
            label: 'Use Existing JQuery',
            type: 'boolean',
            default: false
        },
        addSmartcode: {
            description: 'When enabled, Segment will load the VWO SmartCode onto the webpage. When disabled, you will have to manually add SmartCode to your webpage. The setting is enabled by default, however we recommended manually adding SmartCode to the webpage to avoid flicker issues.',
            label: 'Add Asynchronous SmartCode',
            type: 'boolean',
            default: true
        }
    },
    initialize: async ({ settings }, deps) => {
        if (settings.addSmartcode != false) {
            init_script_1.initScript({
                vwoAccountId: settings.vwoAccountId,
                settingsTolerance: settings.settingsTolerance,
                libraryTolerance: settings.libraryTolerance,
                useExistingJquery: settings.useExistingJquery
            });
        }
        await deps.resolveWhen(() => Object.prototype.hasOwnProperty.call(window, 'VWO'), 100);
        return window.VWO;
    },
    actions: {
        trackEvent: trackEvent_1.default,
        identifyUser: identifyUser_1.default
    }
};
exports.default = shim_1.browserDestination(exports.destination);
//# sourceMappingURL=index.js.map