"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 trackEvent_1 = tslib_1.__importDefault(require("./trackEvent"));
const identifyUser_1 = tslib_1.__importDefault(require("./identifyUser"));
exports.destination = {
    name: 'Iterate Web (Actions)',
    slug: 'actions-iterate',
    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: {
        apiKey: {
            label: 'Embed API Key',
            description: 'The Embed API Key for your account. You can find this on your settings pages.',
            type: 'string',
            required: true
        }
    },
    initialize: async ({ settings }, deps) => {
        window.iterateSettings = {
            apiKey: settings.apiKey,
            installOnLoad: false
        };
        window.IterateObjectName = 'Iterate';
        const iteratePlaceholder = function (...args) {
            iteratePlaceholder.command(args);
        };
        iteratePlaceholder.loaded = false;
        iteratePlaceholder.q = [];
        iteratePlaceholder.command = function (args) {
            iteratePlaceholder.q.push(args);
        };
        window.Iterate = iteratePlaceholder;
        await deps.loadScript('https://platform.iteratehq.com/loader.js');
        await deps.resolveWhen(() => !Object.prototype.hasOwnProperty.call(window.Iterate, 'loaded'), 100);
        return window.Iterate;
    },
    actions: {
        trackEvent: trackEvent_1.default,
        identifyUser: identifyUser_1.default
    }
};
exports.default = shim_1.browserDestination(exports.destination);
//# sourceMappingURL=index.js.map