import React, { useContext } from "react";
import { useFavoriteNeighborhoods } from "./hooks/useFavoriteNeighborhoods";
import { TrackingPipelineEvents, AnalyticsEvents, } from "./types";
import { useTracking } from "~/tracking";
import useEffectOnce from "~/hooks/useEffectOnce";
import { useStateManagerContext } from "~/context/stateManager";
const NeighborhoodFeaturedContext = React.createContext({});
const useNeighborhoodFeatured = () => useContext(NeighborhoodFeaturedContext);
const NeighborhoodFeaturedProvider = ({ children, }) => {
    var _a, _b;
    const { sdkState } = useStateManagerContext();
    const tracking = useTracking();
    useEffectOnce(() => {
        tracking.postEvent({
            eventType: TrackingPipelineEvents.SDK_VIEWED,
        });
        tracking.trackAnalyticsEvent({
            eventName: AnalyticsEvents.SDK_VIEWED,
        });
    });
    const { data, isFetched, isLoading } = useFavoriteNeighborhoods({
        externalId: (_a = sdkState.globalOptions) === null || _a === void 0 ? void 0 : _a.externalId,
    });
    if (!((_b = sdkState.globalOptions) === null || _b === void 0 ? void 0 : _b.externalId)) {
        throw new Error("externalId is required to launch the SDK");
    }
    return (React.createElement(NeighborhoodFeaturedContext.Provider, { value: {
            isFetched,
            isLoading,
            neighborhoods: data,
        } }, children));
};
export { useNeighborhoodFeatured, NeighborhoodFeaturedProvider };
//# sourceMappingURL=context.js.map