import { browserDestination } from '../../runtime/shim';
import { defaultValues } from '@segment/actions-core';
import trackEvent from './trackEvent';
import identifyUser from './identifyUser';
export const destination = {
    name: 'Iterate Web (Actions)',
    slug: 'actions-iterate',
    mode: 'device',
    presets: [
        {
            name: 'Track Event',
            subscribe: 'type = "track"',
            partnerAction: 'trackEvent',
            mapping: defaultValues(trackEvent.fields)
        },
        {
            name: 'Identify User',
            subscribe: 'type = "identify"',
            partnerAction: 'identifyUser',
            mapping: defaultValues(identifyUser.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,
        identifyUser
    }
};
export default browserDestination(destination);
//# sourceMappingURL=index.js.map