import '../../../../utils/index.mjs';
import { toArray } from '../../../../utils/lang/array.mjs';
import { get } from '../../../../utils/lang/get.mjs';
import { set } from '../../../../utils/lang/set.mjs';

function getNamePath(path) {
  return toArray(path);
}
function getValue(store, namePath) {
  const value = get(store, namePath);
  return value;
}
function setValue(store, namePath, value, removeIfUndefined = false) {
  const newStore = set(store, namePath, value, removeIfUndefined);
  return newStore;
}
function containsNamePath(namePathList, namePath) {
  return namePathList && namePathList.some((path) => matchNamePath(path, namePath));
}
function isObject(obj) {
  return typeof obj === "object" && obj !== null && Object.getPrototypeOf(obj) === Object.prototype;
}
function internalSetValues(store, values) {
  const newStore = Array.isArray(store) ? [...store] : { ...store };
  if (!values)
    return newStore;
  Object.keys(values).forEach((key) => {
    const prevValue = newStore[key];
    const value = values[key];
    const recursive = isObject(prevValue) && isObject(value);
    newStore[key] = recursive ? internalSetValues(prevValue, value || {}) : value;
  });
  return newStore;
}
function setValues(store, ...restValues) {
  return restValues.reduce(
    (current, newStore) => internalSetValues(current, newStore),
    store
  );
}
function cloneByNamePathList(store, namePathList) {
  let newStore = {};
  namePathList.forEach((namePath) => {
    const value = getValue(store, namePath);
    newStore = setValue(newStore, namePath, value);
  });
  return newStore;
}
function matchNamePath(namePath, changedNamePath) {
  if (!namePath || !changedNamePath || namePath.length !== changedNamePath.length)
    return false;
  return namePath.every((nameUnit, i) => changedNamePath[i] === nameUnit);
}

export { cloneByNamePathList, containsNamePath, getNamePath, getValue, matchNamePath, setValue, setValues };
//# sourceMappingURL=valueUtil.mjs.map
