"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 trackEvent_1 = tslib_1.__importDefault(require("./trackEvent"));
const identifyUser_1 = tslib_1.__importDefault(require("./identifyUser"));
exports.destination = {
    name: 'Heap Web (Actions)',
    slug: 'actions-heap-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"',
            partnerAction: 'identifyUser',
            mapping: actions_core_1.defaultValues(identifyUser_1.default.fields)
        }
    ],
    settings: {
        appId: {
            label: 'Heap app ID',
            description: 'The app ID of the environment to which you want to send data. You can find this ID on the [Projects](https://heapanalytics.com/app/manage/projects) page.',
            type: 'string',
            required: true
        },
        disableTextCapture: {
            label: 'Global data redaction via Disabling Text Capture',
            description: 'Setting to true will redact all target text on your website. For more information visit the heap [docs page](https://developers.heap.io/docs/web#global-data-redaction-via-disabling-text-capture).',
            type: 'boolean',
            required: false
        },
        secureCookie: {
            label: 'Secure Cookie',
            description: 'This option is turned off by default to accommodate websites not served over HTTPS. If your application uses HTTPS, we recommend enabling secure cookies to prevent Heap cookies from being observed by unauthorized parties. For more information visit the heap [docs page](https://developers.heap.io/docs/web#securecookie).',
            type: 'boolean',
            required: false
        }
    },
    initialize: async ({ settings }, deps) => {
        if (window.heap) {
            return window.heap;
        }
        const config = {
            disableTextCapture: settings.disableTextCapture || false,
            secureCookie: settings.secureCookie || false
        };
        window.heap = window.heap || [];
        window.heap.appid = settings.appId;
        window.heap.config = config;
        await deps.loadScript(`https://cdn.heapanalytics.com/js/heap-${settings.appId}.js`);
        await deps.resolveWhen(() => Object.prototype.hasOwnProperty.call(window, 'heap'), 100);
        return window.heap;
    },
    actions: {
        trackEvent: trackEvent_1.default,
        identifyUser: identifyUser_1.default
    }
};
exports.default = shim_1.browserDestination(exports.destination);
//# sourceMappingURL=index.js.map