import useCookieContext from "@/hooks/useCookieContext";
import { CategoryType } from "@/contexts/CookieConsent";

const useShouldTrackAnalytics = (): boolean => {
  const cookieContext = useCookieContext();

  const shouldTrackAnalytics = () => {
    const statisticsPref: CategoryType | undefined =
      cookieContext.preferences.find(({ key }) => key === "statistics");

    return (statisticsPref && statisticsPref.enabled) || false;
  };

  return shouldTrackAnalytics();
};

export default useShouldTrackAnalytics;
