"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
Object.defineProperty(exports, "editorAnalyticsChannel", {
  enumerable: true,
  get: function get() {
    return _editorAnalyticsChannel.editorAnalyticsChannel;
  }
});
exports.fireAnalyticsEvent = void 0;
var _analyticsQueue = require("./analytics-queue");
var _editorAnalyticsChannel = require("./editorAnalyticsChannel");
var fireAnalyticsEvent = exports.fireAnalyticsEvent = function fireAnalyticsEvent(createAnalyticsEvent, options) {
  return function (_ref) {
    var payload = _ref.payload,
      _ref$channel = _ref.channel,
      channel = _ref$channel === void 0 ? _editorAnalyticsChannel.editorAnalyticsChannel : _ref$channel;
    if (!createAnalyticsEvent) {
      return;
    }
    if (options !== null && options !== void 0 && options.immediate) {
      var _createAnalyticsEvent;
      (_createAnalyticsEvent = createAnalyticsEvent(payload)) === null || _createAnalyticsEvent === void 0 || _createAnalyticsEvent.fire(channel);
      return;
    }
    var queue = _analyticsQueue.AnalyticsQueue.get();
    queue.schedule(function () {
      var _createAnalyticsEvent2;
      return (_createAnalyticsEvent2 = createAnalyticsEvent(payload)) === null || _createAnalyticsEvent2 === void 0 ? void 0 : _createAnalyticsEvent2.fire(channel);
    });
  };
};
// eslint-disable-next-line @atlaskit/editor/no-re-export