'use strict';

require('../../../../utils/index.cjs');
var array = require('../../../../utils/lang/array.cjs');
var get = require('../../../../utils/lang/get.cjs');
var set = require('../../../../utils/lang/set.cjs');

function getNamePath(path) {
  return array.toArray(path);
}
function getValue(store, namePath) {
  const value = get.get(store, namePath);
  return value;
}
function setValue(store, namePath, value, removeIfUndefined = false) {
  const newStore = set.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);
}

exports.cloneByNamePathList = cloneByNamePathList;
exports.containsNamePath = containsNamePath;
exports.getNamePath = getNamePath;
exports.getValue = getValue;
exports.matchNamePath = matchNamePath;
exports.setValue = setValue;
exports.setValues = setValues;
//# sourceMappingURL=valueUtil.cjs.map
