import { _ as _defineProperty } from '../../../defineProperty-CrCYjjU3.js';
import { useEffect } from 'react';
import { pick, prop, dissoc, mergeDeepLeft } from 'ramda';
import { STORAGE_KEY } from '../constants/constants.js';
import withImmutableActions from '../withImmutableActions/withImmutableActions.js';
import { getFromLocalStorage, setToLocalStorage } from '../../utils/general.js';
import { create } from 'zustand';
import { useShallow } from 'zustand/shallow';
import '../../../typeof-D-UKOauR.js';
import '../../../objectWithoutProperties-DN7d1SzH.js';
import '../../../slicedToArray-DmsZvA_9.js';
import '../../../unsupportedIterableToArray-Dqz8Y8_I.js';
import '../../../asyncToGenerator-CPKhuIh2.js';
import '@bigbinary/neeto-atoms';
import 'i18next';
import '@bigbinary/neeto-cist';
import 'qs';

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), true).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; }
var getLocalStorageData = function getLocalStorageData() {
  return getFromLocalStorage(STORAGE_KEY) || {};
};
var setLocalStorageData = function setLocalStorageData(data) {
  return setToLocalStorage(STORAGE_KEY, data);
};

/** @type {import("neetocommons/react-utils").ZustandStoreHook} */
var useCheckpointStore = create(withImmutableActions(function (set) {
  return {
    checkpoints: {},
    setCheckpoint: function setCheckpoint(key, path) {
      return set(mergeDeepLeft({
        checkpoints: _defineProperty({}, key, path)
      }));
    },
    removeCheckpoint: function removeCheckpoint(key) {
      return set(function (state) {
        return {
          checkpoints: dissoc(key, state.checkpoints)
        };
      });
    }
  };
}));
var useRegisterNavigationCheckpoint = function useRegisterNavigationCheckpoint(key) {
  var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window.location.pathname + window.location.search;
  var persistInLocalStorage = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  var setCheckpoint = useCheckpointStore(prop("setCheckpoint"));
  useEffect(function () {
    setCheckpoint(key, path);
    if (persistInLocalStorage) {
      var localStorageData = getLocalStorageData();
      setLocalStorageData(_objectSpread(_objectSpread({}, localStorageData), {}, _defineProperty({}, key, path)));
    }
  }, [key, path, persistInLocalStorage]);
};
var useNavigationCheckpoints = function useNavigationCheckpoints() {
  for (var _len = arguments.length, keys = new Array(_len), _key = 0; _key < _len; _key++) {
    keys[_key] = arguments[_key];
  }
  var getCheckpoints = useCheckpointStore(useShallow(function (store) {
    return pick(keys, store.checkpoints);
  }));
  var localStorageData = getLocalStorageData();
  var localStorageCheckpoints = pick(keys, localStorageData);
  return _objectSpread(_objectSpread({}, getCheckpoints), localStorageCheckpoints);
};
var useRemoveNavigationCheckpoint = function useRemoveNavigationCheckpoint() {
  var removeCheckpoint = useCheckpointStore(prop("removeCheckpoint"));
  return function (key) {
    removeCheckpoint(key);
    var localStorageData = getLocalStorageData();
    setLocalStorageData(dissoc(key, localStorageData));
  };
};

export { useRegisterNavigationCheckpoint as default, useNavigationCheckpoints, useRemoveNavigationCheckpoint };
//# sourceMappingURL=useRegisterNavigationCheckpoint.js.map
