"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = useAlertAnalytics;
var _analytics = require("../analytics");
var _config = require("../config");
function useAlertAnalytics(_ref) {
  let {
    analytics,
    analyticsLabelOverride,
    onAnalyticsEvent = (0, _config.config)().defaultAnalyticsFunction,
    variation
  } = _ref;
  // Order matters! Content comes from the heading first and falls back to body if heading doesn't exist
  const [headingRef, bodyRef] = (0, _analytics.useAnalyticsContent)({
    onMount: content => {
      if (analytics !== true && (!(0, _config.config)().alertSendsAnalytics || analytics === false)) {
        return;
      }

      // Do not send analytics event for default alerts
      if (!variation) {
        return;
      }
      const eventHeadingText = analyticsLabelOverride ?? content;
      if (!eventHeadingText) {
        console.error('No content found for Alert analytics event');
        return;
      }
      onAnalyticsEvent({
        event_name: 'alert_impression',
        event_type: _analytics.EventType.UI_INTERACTION,
        event_action: 'alert impression',
        event_extension: _analytics.eventExtensionText,
        event_category: _analytics.EventCategory.UI_COMPONENTS,
        event_label: eventHeadingText,
        heading: eventHeadingText,
        type: variation
      });
    }
  });
  return {
    headingRef,
    bodyRef
  };
}