import { useDispatch } from "react-redux";
import { usePostOnboardingContext } from "./usePostOnboardingContext";
import { useCallback } from "react";
import { useFeatureFlags } from "../../featureFlags";
import { initPostOnboarding, postOnboardingSetFinished } from "../actions";
/**
 * Use this to initialize AND navigate to the post onboarding hub for a given
 * device model.
 *
 * @param deviceModelId
 * @returns a function that can be called to initialize the post
 * onboarding for the given device model and navigate to the post onboarding
 * hub.
 * TODO: unit test this
 */
export function useStartPostOnboardingCallback() {
    const dispatch = useDispatch();
    const { getFeature } = useFeatureFlags();
    const { getPostOnboardingActionsForDevice, navigateToPostOnboardingHub } = usePostOnboardingContext();
    return useCallback((options) => {
        const { deviceModelId, mock = false, fallbackIfNoAction, resetNavigationStack } = options;
        const actions = getPostOnboardingActionsForDevice(deviceModelId, mock).filter(actionWithState => !actionWithState.featureFlagId || getFeature(actionWithState.featureFlagId)?.enabled);
        dispatch(initPostOnboarding({
            deviceModelId,
            actionsIds: actions.map(action => action.id),
        }));
        if (actions.length === 0) {
            dispatch(postOnboardingSetFinished());
            if (fallbackIfNoAction)
                fallbackIfNoAction();
            return;
        }
        navigateToPostOnboardingHub(resetNavigationStack);
    }, [dispatch, getFeature, getPostOnboardingActionsForDevice, navigateToPostOnboardingHub]);
}
//# sourceMappingURL=useStartPostOnboardingCallback.js.map