import { useCallback } from "react";
import { useAnalytics } from "../../analyticsUtils";

export { useAnalytics } from "../../analyticsUtils";

import { useSendAnalyticsEventWithFunction } from "@applicaster/zapp-react-native-utils/analyticsUtils/helpers/hooks";

// @TODO it's possible to rewrite to use `item` from callback function and take `zappPipesData` from component context
export const useSendAnalyticsOnPress = (item, component, zappPipesData) => {
  const callbackSendAnalyticsEvent = useSendAnalyticsEventWithFunction();

  const { sendOnClickEvent } = useAnalytics({
    item,
    component,
    zappPipesData,
  });

  return useCallback(
    (item, index: number) => {
      return callbackSendAnalyticsEvent({
        sendAnalyticsFunction: sendOnClickEvent,

        extraProps: {
          item,
          index,
          component,
          zappPipesData,
        },
      });
    },
    [component, zappPipesData, callbackSendAnalyticsEvent]
  );
};
