import React, { createContext, useContext, useMemo } from "react";
import { DEFAULT_NAV } from "../utils/ptwNavUrl.js";

const PtwNavigationContext = createContext(null);

export function PtwNavigationProvider({ activeNav, navigate, goBack, children }) {
  const value = useMemo(
    () => ({
      activeNav,
      navigate,
      goBack,
      showBack: activeNav !== DEFAULT_NAV
    }),
    [activeNav, navigate, goBack]
  );

  return (
    <PtwNavigationContext.Provider value={value}>
      {children}
    </PtwNavigationContext.Provider>
  );
}

export function usePtwNavigation() {
  return useContext(PtwNavigationContext);
}
