import getUrlState from './getUrlState';
import objectToParamString from './objectToParamString';
const setUrlState = function setUrlState(opts) {
  const {
    state: newState,
    stateMode = 'query'
  } = opts;
  const oldState = getUrlState({
    stateMode
  });
  const fullState = {
    ...oldState,
    ...newState
  };
  const stateString = objectToParamString(fullState);
  const url = new URL(window.location.href);
  if (stateMode === 'query') {
    url.search = stateString;
  } else {
    url.hash = `#${stateString}`;
  }
  window.history.pushState({
    path: url.href
  }, '', url.href);
  return fullState;
};
export default setUrlState;