import { browserDestination } from '../../runtime/shim';
import { initScript } from './init-script';
import identifyUser from './identifyUser';
import { defaultValues } from '@segment/actions-core';
import trackEvent from './trackEvent';
export const 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: defaultValues(trackEvent.fields)
        },
        {
            name: 'Identify User',
            subscribe: 'type = "identify"',
            partnerAction: 'identifyUser',
            mapping: defaultValues(identifyUser.fields)
        }
    ],
    initialize: async ({ settings }, deps) => {
        if (!window.CommandBar) {
            initScript(settings.orgId);
        }
        await deps.resolveWhen(() => Object.prototype.hasOwnProperty.call(window, 'CommandBar'), 100);
        Object.assign(window.CommandBar, { then: undefined });
        return window.CommandBar;
    },
    actions: {
        identifyUser,
        trackEvent
    }
};
export default browserDestination(destination);
//# sourceMappingURL=index.js.map