"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
exports.useDialogAnalytics = useDialogAnalytics;
var _analytics = require("../analytics");
var _config = require("../config");
function useDialogAnalytics(_ref) {
  let {
    analytics,
    analyticsLabelOverride,
    onAnalyticsEvent = (0, _config.config)().defaultAnalyticsFunction
  } = _ref;
  function sendDialogEvent(content, eventAttributes) {
    if (analytics !== true && (!(0, _config.config)().dialogSendsAnalytics || analytics === false)) {
      return;
    }
    const eventHeadingText = analyticsLabelOverride ?? content;
    if (!eventHeadingText) {
      console.error('No content found for Dialog analytics event');
      return;
    }
    onAnalyticsEvent({
      event_type: _analytics.EventType.UI_INTERACTION,
      event_category: _analytics.EventCategory.UI_COMPONENTS,
      event_label: eventHeadingText,
      event_extension: _analytics.eventExtensionText,
      heading: eventHeadingText,
      ...eventAttributes
    });
  }
  const [headingRef] = (0, _analytics.useAnalyticsContent)({
    onMount: content => {
      sendDialogEvent(content, {
        event_name: 'modal_impression',
        event_action: 'modal impression'
      });
    },
    onUnmount: content => {
      sendDialogEvent(content, {
        event_name: 'modal_closed',
        event_action: 'closed modal'
      });
    }
  });
  return headingRef;
}
var _default = useDialogAnalytics;
exports.default = _default;