import React, { useContext } from "react";
import { useMyNeighborhoods } from "./hooks/useMyNeighborhoods";
import { TrackingPipelineEvents, AnalyticsEvents, } from "./types";
import { useTracking } from "~/tracking";
import useEffectOnce from "~/hooks/useEffectOnce";
import { useStateManagerContext } from "~/context/stateManager";
const NeighborhoodShowcaseContext = React.createContext({});
const useNeighborhoodShowcase = () => useContext(NeighborhoodShowcaseContext);
const NeighborhoodShowcaseProvider = ({ 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 } = useMyNeighborhoods();
    if (!((_a = sdkState.globalOptions) === null || _a === void 0 ? void 0 : _a.externalId)) {
        throw new Error("externalId is required to launch the SDK");
    }
    return (React.createElement(NeighborhoodShowcaseContext.Provider, { value: {
            isLoading,
            isFetched,
            myNeighborhoods: data,
            singleNeighborhoodURLSchema: (_b = sdkState.options) === null || _b === void 0 ? void 0 : _b.singleNeighborhoodURLSchema,
        } }, children));
};
export { useNeighborhoodShowcase, NeighborhoodShowcaseProvider };
//# sourceMappingURL=context.js.map