import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';
import { useRouteRegistry } from './routeRegistryStore';
/**
 * Registers the current route in the registry and keeps the current path in sync.
 * Returns the current location so callers can reuse it without calling useLocation again.
 */
export const useRegisterRoute = ({ isPublic, attemptSilentAuth }) => {
    const location = useLocation();
    const registerRoute = useRouteRegistry((state) => state.registerRoute);
    const setPath = useRouteRegistry((state) => state.setPath);
    const syncRouteRegistration = () => {
        const path = location.pathname;
        setPath(path);
        registerRoute(path, Object.assign({ isPublic }, (attemptSilentAuth !== undefined ? { attemptSilentAuth } : {})));
    };
    useEffect(syncRouteRegistration, [
        attemptSilentAuth,
        isPublic,
        location.pathname,
        registerRoute,
        setPath
    ]);
    return location;
};
//# sourceMappingURL=useRegisterRoute.js.map