"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.destination = void 0;
const tslib_1 = require("tslib");
const shim_1 = require("../../runtime/shim");
const identifyUser_1 = tslib_1.__importDefault(require("./identifyUser"));
const signoutUser_1 = tslib_1.__importDefault(require("./signoutUser"));
const trackEvent_1 = tslib_1.__importDefault(require("./trackEvent"));
const updateUserId_1 = tslib_1.__importDefault(require("./updateUserId"));
const actions_core_1 = require("@segment/actions-core");
exports.destination = {
    name: 'Sprig (Actions)',
    slug: 'sprig-web',
    mode: 'device',
    presets: [
        {
            name: 'Identify User',
            subscribe: 'type = "identify"',
            partnerAction: 'identifyUser',
            mapping: actions_core_1.defaultValues(identifyUser_1.default.fields)
        },
        {
            name: 'Sign Out User',
            subscribe: 'type = "track" and event = "Signed Out"',
            partnerAction: 'signoutUser',
            mapping: actions_core_1.defaultValues(signoutUser_1.default.fields)
        },
        {
            name: 'Track Event',
            subscribe: 'type = "track" and event != "Signed Out"',
            partnerAction: 'trackEvent',
            mapping: actions_core_1.defaultValues(trackEvent_1.default.fields)
        },
        {
            name: 'Update User ID',
            subscribe: 'type = "alias"',
            partnerAction: 'updateUserId',
            mapping: actions_core_1.defaultValues(updateUserId_1.default.fields)
        }
    ],
    settings: {
        envId: {
            description: 'Your environment ID (production or development).',
            label: 'Environment ID',
            type: 'string',
            required: true
        },
        debugMode: {
            description: 'Enable debug mode for testing purposes.',
            label: 'Debug mode',
            type: 'boolean',
            required: false,
            default: false
        }
    },
    actions: {
        identifyUser: identifyUser_1.default,
        signoutUser: signoutUser_1.default,
        trackEvent: trackEvent_1.default,
        updateUserId: updateUserId_1.default
    },
    initialize: async ({ settings }, deps) => {
        if (!window.Sprig || !window.Sprig.envId) {
            window.Sprig = function (...args) {
                S._queue && S._queue.push(args);
            };
            const S = window.Sprig;
            S.envId = settings.envId;
            S.debugMode = !!settings.debugMode;
            S._queue = [];
            S._segment = 1;
            window.UserLeap = S;
            await deps.loadScript(`https://cdn.sprig.com/shim.js?id=${S.envId}`);
        }
        return window.Sprig;
    }
};
exports.default = shim_1.browserDestination(exports.destination);
//# sourceMappingURL=index.js.map