/**
 * Initial state
 */
const initialState = {
  navRefs: {},
};

export const navRefSelectors = {
  getNavRef(state, ref) {
    return state.navRefs[ref] ?? "";
  },
};

export const navRefActions = {
  setNavRef(payload) {
    return {
      type: "SET_NAV_REF",
      payload,
    };
  },
};

export const navRefReducer = (state = initialState.navRefs, action) => {
  switch (action.type) {
    case "SET_NAV_REF":
      return {
        ...state,
        [action.payload.ref]: action.payload.clientId,
      };
  }

  return state;
};
