"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.usePostOnboardingDeeplinkHandler = void 0;
const react_1 = require("react");
const devices_1 = require("@ledgerhq/devices");
const useStartPostOnboardingCallback_1 = require("./useStartPostOnboardingCallback");
const usePostOnboardingEntryPointVisibleOnWallet_1 = require("./usePostOnboardingEntryPointVisibleOnWallet");
const usePostOnboardingHubState_1 = require("./usePostOnboardingHubState");
function usePostOnboardingDeeplinkHandler(navigateToHome, navigateToPostOnboardingHub) {
    const handleInitPostOnboarding = (0, useStartPostOnboardingCallback_1.useStartPostOnboardingCallback)();
    const isPostOnboardingVisible = (0, usePostOnboardingEntryPointVisibleOnWallet_1.usePostOnboardingEntryPointVisibleOnWallet)();
    const { deviceModelId: postOnboardingDeviceModelId } = (0, usePostOnboardingHubState_1.usePostOnboardingHubState)();
    return (0, react_1.useCallback)((device) => {
        if (!device) {
            navigateToHome();
            return;
        }
        if (isPostOnboardingVisible && device === postOnboardingDeviceModelId) {
            navigateToPostOnboardingHub();
        }
        else if (device in devices_1.DeviceModelId) {
            handleInitPostOnboarding({
                deviceModelId: device,
                mock: false,
                fallbackIfNoAction: () => navigateToHome(),
            });
        }
        else {
            navigateToHome();
        }
    }, [
        handleInitPostOnboarding,
        isPostOnboardingVisible,
        navigateToHome,
        navigateToPostOnboardingHub,
        postOnboardingDeviceModelId,
    ]);
}
exports.usePostOnboardingDeeplinkHandler = usePostOnboardingDeeplinkHandler;
//# sourceMappingURL=usePostOnboardingDeeplinkHandler.js.map