"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 identify_1 = tslib_1.__importDefault(require("./identify"));
const track_1 = tslib_1.__importDefault(require("./track"));
const group_1 = tslib_1.__importDefault(require("./group"));
const alias_1 = tslib_1.__importDefault(require("./alias"));
exports.destination = {
    name: 'Screeb Web (Actions)',
    slug: 'actions-screeb-web',
    mode: 'device',
    settings: {
        websiteId: {
            description: 'Your website ID (given in Screeb app).',
            label: 'Website ID',
            type: 'string',
            required: true
        }
    },
    presets: [
        {
            name: 'Identify',
            subscribe: 'type = "identify"',
            partnerAction: 'identify',
            mapping: actions_core_1.defaultValues(identify_1.default.fields)
        },
        {
            name: 'Track',
            subscribe: 'type = "track"',
            partnerAction: 'track',
            mapping: actions_core_1.defaultValues(track_1.default.fields)
        },
        {
            name: 'Group',
            subscribe: 'type = "group"',
            partnerAction: 'group',
            mapping: actions_core_1.defaultValues(group_1.default.fields)
        },
        {
            name: 'Alias',
            subscribe: 'type = "alias"',
            partnerAction: 'alias',
            mapping: actions_core_1.defaultValues(alias_1.default.fields)
        }
    ],
    initialize: async ({ settings }, deps) => {
        const preloadFunction = function (...args) {
            if (window.$screeb.q) {
                window.$screeb.q.push(args);
            }
        };
        window.$screeb = preloadFunction;
        window.$screeb.q = [];
        await deps.loadScript('https://t.screeb.app/tag.js');
        await deps.resolveWhen(() => window.$screeb !== preloadFunction, 500);
        window.$screeb('init', settings.websiteId);
        return window.$screeb;
    },
    actions: {
        identify: identify_1.default,
        track: track_1.default,
        group: group_1.default,
        alias: alias_1.default
    }
};
exports.default = shim_1.browserDestination(exports.destination);
//# sourceMappingURL=index.js.map