import React from 'react';
import { Analytics as BaseAnalytics } from '../_utils/genericAnalyticsClient';
var defaultTrackEvent = function defaultTrackEvent(e, params) {
  console.log('analytics::trackEvent', e, params);
};

/**
 * @deprecatedSince 11
 * @deprecated
 */
export var AnalyticsContext = /*#__PURE__*/React.createContext({});

/**
 * @deprecatedSince 11
 * @deprecated
 */
export function AnalyticsProvider(_ref) {
  var analytics = _ref.analytics,
    children = _ref.children;
  return /*#__PURE__*/React.createElement(AnalyticsContext.Provider, {
    value: {
      trackEvent: (analytics === null || analytics === void 0 ? void 0 : analytics.trackEvent) || defaultTrackEvent
    }
  }, children);
}
var isAnalyticsHydrated = function isAnalyticsHydrated(analytics) {
  return Object.keys(analytics).length > 0;
};

/**
 * @deprecatedSince 11
 * @deprecated
 */
export var useAnalyticsContext = function useAnalyticsContext() {
  var context = React.useContext(AnalyticsContext);
  if (!isAnalyticsHydrated(context)) {
    throw new Error('Must wrap app in Analytics.Provider');
  }
  return context;
};

/**
 * @deprecatedSince 11
 * @deprecated Use fetch instead. Previous implementation:
 * - https://github.com/procore/core/blob/%40procore/core-react%4010.30.0/packages/core-react/src/decorators/Analytics.tsx
 * - https://github.com/procore/core/blob/%40procore/core-react%4010.30.0/packages/core-react/src/utils/genericAnalyticsClient.ts
 */
export var Analytics = {
  Client: BaseAnalytics,
  Consumer: AnalyticsContext.Consumer,
  Provider: AnalyticsProvider,
  Context: AnalyticsContext
};
//# sourceMappingURL=Analytics.js.map