import React from 'react'; import { useNavigate, useLocation } from 'react-router-dom'; import { useEventContext } from '../../context/EventContext'; import { NavKey } from '../components/BottomNav'; import { resolveTabTarget } from '../lib/tabHistory'; import { adminPath } from '../../constants'; export function useMobileNav(currentSlug?: string | null) { const navigate = useNavigate(); const location = useLocation(); const { activeEvent } = useEventContext(); const slug = currentSlug ?? activeEvent?.slug ?? null; const go = React.useCallback( (key: NavKey) => { const target = resolveTabTarget(key, slug); // Tap-to-reset: If we are already at the target, and it is the home tab, // and we are not at the dashboard root, then go to dashboard. if (key === 'home' && location.pathname === target && target !== adminPath('/mobile/dashboard')) { navigate(adminPath('/mobile/dashboard')); return; } navigate(target); }, [navigate, location.pathname, slug] ); return { go, slug }; }