/**
 * useAnalytics - Hook for analytics event tracking.
 *
 * Usage:
 *   const { trackEvent, trackPageView } = useAnalytics();
 *   trackEvent('button_clicked', { button_id: 'submit' });
 *
 * ⚠️ AUTO-GENERATED BY PRISM — DO NOT EDIT
 */

import { useContext } from 'react';
import { AnalyticsContext, type AnalyticsContextValue } from '../contexts/AnalyticsProvider';

/**
 * Hook to access analytics tracking functions.
 *
 * Must be used within an <AnalyticsProvider>.
 *
 * @returns Analytics context with trackEvent and trackPageView functions.
 */
export function useAnalytics(): AnalyticsContextValue {
  const context = useContext(AnalyticsContext);
  if (!context) {
    throw new Error('useAnalytics must be used within an <AnalyticsProvider>');
  }
  return context;
}
{% if has_custom_events %}

// Type-safe helpers for custom events
{% for event in custom_events %}

/**
 * Track "{{ event.name }}" event{% if event.description %} — {{ event.description }}{% endif %}.
 */
export function track{{ event.name | replace('_', ' ') | title | replace(' ', '') }}(
  trackEvent: AnalyticsContextValue['trackEvent'],
{% if event.properties %}
  properties: { {{ event.properties | map('regex_replace', '(.+)', '\\1: unknown') | join('; ') }} },
{% endif %}
) {
  trackEvent('{{ event.name }}'{% if event.properties %}, properties{% endif %});
}
{% endfor %}
{% endif %}
