'use client';

import { createContext, useContext, useCallback, ReactNode } from 'react';

interface NavBadgesContextType {
  refreshNavBadges: () => Promise<void>;
}

const NavBadgesContext = createContext<NavBadgesContextType | null>(null);

export function useNavBadgesRefresh(): (() => Promise<void>) | null {
  const ctx = useContext(NavBadgesContext);
  return ctx?.refreshNavBadges ?? null;
}

interface NavBadgesProviderProps {
  children: ReactNode;
  refreshNavBadges: () => Promise<void>;
}

export function NavBadgesProvider({ children, refreshNavBadges }: NavBadgesProviderProps) {
  const value = { refreshNavBadges: useCallback(refreshNavBadges, [refreshNavBadges]) };
  return (
    <NavBadgesContext.Provider value={value}>
      {children}
    </NavBadgesContext.Provider>
  );
}
