import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
import { TOOLBAR_DOCKING_POSITIONS } from './user-preferences';
export var mergeUserPreferences = function mergeUserPreferences(userPreferences, defaultPreferences) {
  var newResolvedUserPreferences = _objectSpread(_objectSpread({}, defaultPreferences), Object.fromEntries(Object.entries(userPreferences).filter(function (_ref) {
    var _ref2 = _slicedToArray(_ref, 2),
      key = _ref2[0],
      value = _ref2[1];
    if (key === 'toolbarDockingPosition') {
      return TOOLBAR_DOCKING_POSITIONS.includes(value);
    }
    return value !== undefined && value !== null;
  })));
  return newResolvedUserPreferences;
};

/**
 * Compare two user preferences objects
 * @param {ResolvedUserPreferences} left a ResolvedUserPreferences
 * @param {ResolvedUserPreferences} right a ResolvedUserPreferences
 * @returns true if the user preferences are the same, false otherwise
 * @example
 * const userPreferences1 = {
 *   toolbarDockingPosition: 'top',
 * };
 * const userPreferences2 = {
 *   toolbarDockingPosition: 'top',
 * };
 * compareUserPreferences(userPreferences1, userPreferences2); // true
 */
export var areUserPreferencesEqual = function areUserPreferencesEqual(left, right) {
  return Object.entries(left).every(function (_ref3) {
    var _ref4 = _slicedToArray(_ref3, 2),
      key = _ref4[0],
      value = _ref4[1];
    return value === right[key];
  });
};