import { EventCategory, EventType, useAnalyticsContent, eventExtensionText } from '../analytics';
import { config } from '../config';
export default function useHelpDrawerAnalytics(_ref) {
  let {
    analytics,
    analyticsLabelOverride,
    onAnalyticsEvent = config().defaultAnalyticsFunction
  } = _ref;
  function sendHelpDrawerEvent(content, eventAttributes) {
    if (analytics !== true && (!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: EventType.UI_INTERACTION,
      event_category: EventCategory.UI_COMPONENTS,
      event_label: eventHeadingText,
      event_extension: eventExtensionText,
      heading: eventHeadingText,
      ...eventAttributes
    });
  }
  const [headingRef] = 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;
}