import { resolvedFieldNames } from '../picker-view/utils';
export var parseState = function parseState(props) {
  var value = props.value,
      defaultValue = props.defaultValue;
  var currentValue = [];
  return {
    value: value || defaultValue,
    currentValue: currentValue
  };
};
export var parseItems = function parseItems(options, value, fieldNames) {
  var field = resolvedFieldNames(fieldNames);
  var items = [];

  var traverse = function traverse(memo) {
    var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
    memo.forEach(function (option) {
      var children = option[field.children];
      var currentValue = value[depth];

      if (option[field.value] === currentValue) {
        items[depth] = option;

        if (Array.isArray(children) && children.length > 0) {
          traverse(children, depth + 1);
        }
      }
    });
  };

  traverse(options);
  return items;
};