"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.destination = void 0;
const tslib_1 = require("tslib");
const shim_1 = require("../../runtime/shim");
const init_script_1 = require("./init-script");
const identifyUser_1 = tslib_1.__importDefault(require("./identifyUser"));
const actions_core_1 = require("@segment/actions-core");
const trackEvent_1 = tslib_1.__importDefault(require("./trackEvent"));
exports.destination = {
    name: 'CommandBar',
    slug: 'actions-commandbar',
    mode: 'device',
    settings: {
        orgId: {
            description: 'The ID of your CommandBar organization.',
            label: 'Organization ID',
            type: 'string',
            required: true
        },
        deploy: {
            description: 'If enabled, CommandBar will be deployed to your site automatically and you can remove the snippet from your source code.',
            label: 'Deploy via Segment',
            type: 'boolean',
            required: false
        }
    },
    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)
        }
    ],
    initialize: async ({ settings }, deps) => {
        if (!window.CommandBar) {
            init_script_1.initScript(settings.orgId);
        }
        await deps.resolveWhen(() => Object.prototype.hasOwnProperty.call(window, 'CommandBar'), 100);
        Object.assign(window.CommandBar, { then: undefined });
        return window.CommandBar;
    },
    actions: {
        identifyUser: identifyUser_1.default,
        trackEvent: trackEvent_1.default
    }
};
exports.default = shim_1.browserDestination(exports.destination);
//# sourceMappingURL=index.js.map