import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
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) {
  var _useState = useState((userPreferencesProvider === null || userPreferencesProvider === void 0 ? void 0 : userPreferencesProvider.getPreferences()) || null),
    _useState2 = _slicedToArray(_useState, 2),
    resolvedUserPreferences = _useState2[0],
    setResolvedUserPreferences = _useState2[1];
  useEffect(function () {
    return userPreferencesProvider === null || userPreferencesProvider === void 0 ? void 0 : userPreferencesProvider.onUpdate(function () {
      setResolvedUserPreferences(userPreferencesProvider.getPreferences());
    });
  }, [userPreferencesProvider]);
  return {
    resolvedUserPreferences: resolvedUserPreferences
  };
}