"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const flatten_1 = require("../utils/flatten");
const action = {
    title: 'Track Custom Behavioral Event',
    description: 'Send a custom behavioral event to HubSpot.',
    platform: 'web',
    defaultSubscription: 'type = "track"',
    fields: {
        name: {
            description: 'The internal event name assigned by HubSpot. This can be found in your HubSpot account. If the "Format Custom Behavioral Event Names" setting is enabled, Segment will automatically convert your Segment event name into the expected HubSpot internal event name format.',
            label: 'Event Name',
            type: 'string',
            required: true,
            default: {
                '@path': '$.event'
            }
        },
        properties: {
            description: 'A list of key-value pairs that describe the event.',
            label: 'Event Properties',
            type: 'object',
            required: false,
            default: {
                '@path': '$.properties'
            }
        }
    },
    perform: (_hsq, event) => {
        let { name, properties } = event.payload;
        if (event.settings.formatCustomBehavioralEventNames) {
            name = `pe${event.settings.portalId}_${name.replace(/[\s.]+/g, '_').toLocaleLowerCase()}`;
        }
        properties = properties && flatten_1.flatten(properties, '', [], (key) => key.replace(/[\s.]+/g, '_').toLocaleLowerCase());
        _hsq.push(['trackCustomBehavioralEvent', { name, properties }]);
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map