/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

export { emitEvent } from '../../utils/event.js';
import '../../utils/helper.js';
import 'lodash/camelCase';

function getParentsToRoot(element, root) {
  const list = [];
  let el = element;
  while (el && el.parentNode) {
    list.push(el);
    if (el === root) break;
    el = el.parentNode;
  }
  return list;
}
function getParentMarks(name, element, root) {
  const list = getParentsToRoot(element, root);
  return list.map(el => {
    const mark = {
      name,
      value: (el === null || el === void 0 ? void 0 : el.getAttribute(name)) || "",
      el
    };
    return mark;
  }).filter(mark => mark.value);
}
function getMark(name, element, root) {
  const list = getParentMarks(name, element, root);
  const info = list.pop() || null;
  return info;
}
function getTNode(prop, options) {
  var _conf$node;
  let tnode = null;
  let item = null;
  const conf = {
    ...options
  };
  if (typeof prop === "function") item = prop(conf.createElement, (_conf$node = conf.node) === null || _conf$node === void 0 ? void 0 : _conf$node.getModel());else if (typeof prop === "string") item = prop;
  if (typeof item === "string") tnode = item;else if (item) tnode = item;
  return tnode;
}
function getLineModel(nodes, node, index) {
  const lineModel = {
    top: false,
    right: false,
    bottom: false,
    left: false
  };
  let nodeChildren = [];
  if (Array.isArray(node.children)) nodeChildren = node.children;
  const childNode = nodes[index - 1] || null;
  const nodeItemIndex = childNode ? childNode.getIndex() : 0;
  if (index === 0) {
    lineModel.left = !!node.parent;
    lineModel.bottom = node.children && node.expanded;
    lineModel.right = node.parent && !node.children;
  } else if (index === 1) {
    lineModel.top = true;
    lineModel.right = true;
    lineModel.bottom = nodeItemIndex < nodeChildren.length - 1;
  } else if (nodeItemIndex < nodeChildren.length - 1) {
    lineModel.top = true;
    lineModel.bottom = true;
  }
  return lineModel;
}
function isTreeNodeValue(item) {
  return typeof item === "string" || typeof item === "number";
}
function getNode(store, item) {
  let node = null;
  let val = null;
  if (typeof item === "string" || typeof item === "number") val = item;else if (item && isTreeNodeValue(item.value)) val = item.value;
  node = store.getNode(val);
  return node;
}

export { getLineModel, getMark, getNode, getParentMarks, getParentsToRoot, getTNode, isTreeNodeValue };
//# sourceMappingURL=utils.js.map
