import { __read } from "tslib";
import { ActionMonitor } from '../../monitors/action';
import { applyMonitor } from '../../utils';
import { getPluginConfig } from './utils';
export var ACTION_MONITOR_PLUGIN_NAME = 'action';
var defaultConfig = {
    types: ["click" /* CLICK */],
};
export function ActionMonitorBasePlugin(client, config) {
    if (config === void 0) { config = defaultConfig; }
    var _a = __read(applyMonitor(ActionMonitor, config, client.report.bind(client)), 3), tearDown = _a[0], applyOtherReport = _a[1], startAction = _a[2];
    var listenOtherReport = function (ev) {
        var actionId = applyOtherReport(ev);
        actionId && ev.extra && (ev.extra.action_id = actionId);
        return ev;
    };
    client.on('report', listenOtherReport);
    client.provide('startAction', startAction);
    client.on('beforeDestroy', function () {
        tearDown();
        client.off('report', listenOtherReport);
    });
}
export function ActionMonitorPlugin(client) {
    client.on('init', function () {
        var config = getPluginConfig(client, ACTION_MONITOR_PLUGIN_NAME, defaultConfig);
        if (!config) {
            return;
        }
        ActionMonitorBasePlugin(client, config);
    });
}
//# sourceMappingURL=action.js.map