// packages/preferences/src/store/reducer.ts
import { combineReducers } from "@wordpress/data";
function defaults(state = {}, action) {
  if (action.type === "SET_PREFERENCE_DEFAULTS") {
    const { scope, defaults: values } = action;
    return {
      ...state,
      [scope]: {
        ...state[scope],
        ...values
      }
    };
  }
  return state;
}
function withPersistenceLayer(reducer) {
  let persistenceLayer;
  return (state, action) => {
    if (action.type === "SET_PERSISTENCE_LAYER") {
      const { persistenceLayer: persistence, persistedData } = action;
      persistenceLayer = persistence;
      return persistedData;
    }
    const nextState = reducer(state, action);
    if (action.type === "SET_PREFERENCE_VALUE") {
      persistenceLayer?.set(nextState);
    }
    return nextState;
  };
}
var preferences = withPersistenceLayer((state = {}, action) => {
  if (action.type === "SET_PREFERENCE_VALUE") {
    const { scope, name, value } = action;
    return {
      ...state,
      [scope]: {
        ...state[scope],
        [name]: value
      }
    };
  }
  return state;
});
var reducer_default = combineReducers({
  defaults,
  preferences
});
export {
  reducer_default as default,
  defaults,
  preferences
};
//# sourceMappingURL=reducer.mjs.map
