import { useEffect, useState } from 'react';
/**
 * This hook returns the latest user preference
 * @param {UserPreferencesProvider} userPreferencesProvider an instance of UserPreferencesProvider
 * @example const { resolvedUserPreferences } = edUserPreferences(userPreferencesProvider)
 * @returns {ResolvedUserPreferences | null} the latest user preference
 */
export function useResolvedUserPreferences(userPreferencesProvider) {
  const [resolvedUserPreferences, setResolvedUserPreferences] = useState((userPreferencesProvider === null || userPreferencesProvider === void 0 ? void 0 : userPreferencesProvider.getPreferences()) || null);
  useEffect(() => {
    return userPreferencesProvider === null || userPreferencesProvider === void 0 ? void 0 : userPreferencesProvider.onUpdate(() => {
      setResolvedUserPreferences(userPreferencesProvider.getPreferences());
    });
  }, [userPreferencesProvider]);
  return {
    resolvedUserPreferences
  };
}