"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 trackEvent_1 = tslib_1.__importDefault(require("./trackEvent"));
const identifyUser_1 = tslib_1.__importDefault(require("./identifyUser"));
const identifyCompany_1 = tslib_1.__importDefault(require("./identifyCompany"));
const actions_core_1 = require("@segment/actions-core");
exports.destination = {
    name: 'Intercom Web (Actions)',
    slug: 'actions-intercom-web',
    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" or type = "page"',
            partnerAction: 'identifyUser',
            mapping: actions_core_1.defaultValues(identifyUser_1.default.fields)
        },
        {
            name: 'Identify Company',
            subscribe: 'type = "group"',
            partnerAction: 'identifyCompany',
            mapping: actions_core_1.defaultValues(identifyCompany_1.default.fields)
        }
    ],
    settings: {
        appId: {
            description: 'The app_id of your Intercom app which will indicate where to store any data.',
            label: 'App ID',
            type: 'string',
            required: true
        },
        activator: {
            description: 'By default, Intercom will inject their own inbox button onto the page, but you can choose to use your own custom button instead by providing a CSS selector, e.g. #my-button. You must have the "Show the Intercom Inbox" setting enabled for this to work. The default value is #IntercomDefaultWidget.',
            label: 'Custom Inbox Button Selector',
            type: 'string',
            required: false,
            default: '#IntercomDefaultWidget'
        },
        richLinkProperties: {
            description: 'A list of rich link property keys.',
            label: 'Rich Link Properties',
            type: 'string',
            multiple: true,
            required: false
        },
        apiBase: {
            description: 'The regional API to use for processing the data',
            label: 'Regional Data Hosting',
            type: 'string',
            choices: [
                {
                    label: 'US',
                    value: 'https://api-iam.intercom.io'
                },
                {
                    label: 'EU',
                    value: 'https://api-iam.eu.intercom.io'
                },
                {
                    label: 'Australia',
                    value: 'https://api-iam.au.intercom.io'
                }
            ],
            default: 'https://api-iam.intercom.io',
            required: false
        }
    },
    initialize: async ({ settings }, deps) => {
        init_script_1.initScript({ appId: settings.appId });
        const preloadedIntercom = window.Intercom;
        init_script_1.initialBoot(settings.appId, { api_base: settings.apiBase });
        await deps.resolveWhen(() => window.Intercom !== preloadedIntercom, 100);
        window.Intercom.richLinkProperties = settings.richLinkProperties;
        window.Intercom.appId = settings.appId;
        window.Intercom.activator = settings.activator;
        return window.Intercom;
    },
    actions: {
        trackEvent: trackEvent_1.default,
        identifyUser: identifyUser_1.default,
        identifyCompany: identifyCompany_1.default
    }
};
exports.default = shim_1.browserDestination(exports.destination);
//# sourceMappingURL=index.js.map