"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.destination = void 0;
const tslib_1 = require("tslib");
const shim_1 = require("../../runtime/shim");
const actions_core_1 = require("@segment/actions-core");
const setCustomProperties_1 = tslib_1.__importDefault(require("./setCustomProperties"));
const trackEvent_1 = tslib_1.__importDefault(require("./trackEvent"));
const trackGoal_1 = tslib_1.__importDefault(require("./trackGoal"));
const trackPage_1 = tslib_1.__importDefault(require("./trackPage"));
exports.destination = {
    name: 'Wisepops',
    slug: 'actions-wisepops',
    mode: 'device',
    presets: [
        {
            name: 'Set User Traits as Custom Properties',
            subscribe: setCustomProperties_1.default.defaultSubscription,
            partnerAction: 'setCustomProperties',
            mapping: actions_core_1.defaultValues(setCustomProperties_1.default.fields)
        },
        {
            name: 'Set Group Traits as Custom Properties',
            subscribe: 'type = "group"',
            partnerAction: 'setCustomProperties',
            mapping: {
                traits: { '@path': '$.traits' },
                id: { '@path': '$.groupId' },
                idProperty: 'groupId',
                prefix: 'group',
            }
        },
        {
            name: trackEvent_1.default.title,
            subscribe: trackEvent_1.default.defaultSubscription,
            partnerAction: 'trackEvent',
            mapping: actions_core_1.defaultValues(trackEvent_1.default.fields)
        },
        {
            name: trackGoal_1.default.title,
            subscribe: trackGoal_1.default.defaultSubscription,
            partnerAction: 'trackGoal',
            mapping: actions_core_1.defaultValues(trackGoal_1.default.fields)
        },
        {
            name: trackPage_1.default.title,
            subscribe: trackPage_1.default.defaultSubscription,
            partnerAction: 'trackPage',
            mapping: actions_core_1.defaultValues(trackPage_1.default.fields)
        }
    ],
    settings: {
        websiteId: {
            description: "The identifier of your Wisepops' website. You can find it in [your setup code on Wisepops](https://app.wisepops.com/f/settings/websites).",
            label: 'Website Identifier',
            type: 'string',
            required: true
        }
    },
    initialize: async ({ settings }, deps) => {
        window.WisePopsObject = 'wisepops';
        window.wisepops =
            window.wisepops ||
                function (...arg) {
                    ;
                    (window.wisepops.q = window.wisepops.q || []).push(arg);
                };
        window.wisepops.l = Date.now();
        window.wisepops('options', { autoPageview: false });
        void deps.loadScript(`https://loader.wisepops.com/get-loader.js?plugin=segment&v=1&site=${settings.websiteId}`);
        return window.wisepops;
    },
    actions: {
        setCustomProperties: setCustomProperties_1.default,
        trackEvent: trackEvent_1.default,
        trackGoal: trackGoal_1.default,
        trackPage: trackPage_1.default,
    }
};
exports.default = shim_1.browserDestination(exports.destination);
//# sourceMappingURL=index.js.map