import { isMyKeyChainItem, keyStringFromKeyChain } from "./keyChain.js";
const touchedStateForKeyChain = (state, keyChain) => {
  return state.filter((s) => isMyKeyChainItem(s, keyStringFromKeyChain(keyChain, "dots")));
};
const touchedStateReducer = (state, action) => {
  switch (action.type) {
    case "set-touched":
      if (action.touched) {
        const key = keyStringFromKeyChain(action.keyChain, "dots");
        if (state.includes(key)) {
          return state;
        }
        return [...state.filter((k) => k !== key), key];
      }
      {
        const toRemove = touchedStateForKeyChain(state, action.keyChain);
        if (!state.some((k) => toRemove.includes(k))) {
          return state;
        }
        return state.filter((k) => !toRemove.includes(k));
      }
    case "reset-touched":
      return [];
    default:
      return state;
  }
};
export {
  touchedStateForKeyChain,
  touchedStateReducer
};
//# sourceMappingURL=touchedState.js.map
