"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = useHelpDrawerAnalytics;
var _analytics = require("../analytics");
var _config = require("../config");
function useHelpDrawerAnalytics(_ref) {
  let {
    analytics,
    analyticsLabelOverride,
    onAnalyticsEvent = (0, _config.config)().defaultAnalyticsFunction
  } = _ref;
  function sendHelpDrawerEvent(content, eventAttributes) {
    if (analytics !== true && (!(0, _config.config)().helpDrawerSendsAnalytics || analytics === false)) {
      return;
    }
    const eventHeadingText = analyticsLabelOverride ?? content;
    if (!eventHeadingText) {
      console.error('No content found for Help Drawer 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 => {
      sendHelpDrawerEvent(content, {
        event_name: 'help_drawer_opened',
        event_action: 'opened help drawer'
      });
    },
    onUnmount: content => {
      sendHelpDrawerEvent(content, {
        event_name: 'help_drawer_closed',
        event_action: 'closed help drawer'
      });
    }
  });
  return headingRef;
}