"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const keyChain = require("./keyChain.cjs");
function initialDataIsCallback(initialData) {
  return typeof initialData === "function";
}
function dataReducer(state, action) {
  switch (action.type) {
    case "set-one":
      return Array.isArray(state) || Number.isInteger(action.propertyKey) ? (state || []).map((_, i) => i === action.propertyKey ? action.value : state[i]) : { ...state || {}, [action.propertyKey]: action.value };
    case "set-path":
      return keyChain.mergeDeepFromKeyChain(state, action.keyChain, action.value);
    case "set-all":
      return Array.isArray(action.data) ? [...action.data] : { ...action.data };
    default:
      return state;
  }
}
const hasTruthyProperty = (obj) => {
  if (!obj) {
    return false;
  }
  for (const key of Object.keys(obj)) {
    if (typeof obj[key] === "object" && obj[key] !== null) {
      if (hasTruthyProperty(obj[key]))
        return true;
    } else if (obj[key]) {
      return true;
    }
  }
  return false;
};
exports.dataReducer = dataReducer;
exports.hasTruthyProperty = hasTruthyProperty;
exports.initialDataIsCallback = initialDataIsCallback;
//# sourceMappingURL=data.cjs.map
