import { useMemo } from 'react';
import { useLocation } from 'react-router-dom';

import { getSportsPoolRoutes, sportsPoolRoutes } from '../routes';
import { getSportsPoolMobileBase } from '../utils';

/**
 * Returns route helpers scoped to the current context (desktop vs mobile WebView).
 *
 * - Desktop: base is `/${SPORTS_POOL_PATHS.ROOT}`
 * - Mobile:  base is `/${SPORTS_POOL_PATHS.MOBILE_ROOT}/<token>` (preserves the refresh token segment)
 *
 * Mobile route helpers are memoized by `pathname` so `getSportsPoolRoutes` is not
 * re-invoked every render (which would produce new function references each time).
 */
const useSportsPoolRoutes = () => {
  const { pathname } = useLocation();

  return useMemo(() => {
    const mobileBase = getSportsPoolMobileBase(pathname);
    return mobileBase ? getSportsPoolRoutes(mobileBase) : sportsPoolRoutes;
  }, [pathname]);
};

export default useSportsPoolRoutes;
