/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import camelCase from 'lodash/camelCase';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function emitEvent(props, context, evtName) {
  var apiName = camelCase("on-".concat(evtName));
  evtName.replace(/^on/, "").toLowerCase();
  for (var _len = arguments.length, args = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
    args[_key - 3] = arguments[_key];
  }
  if (typeof props[apiName] === "function") props[apiName].apply(props, args);
  context.emit.apply(context, [evtName].concat(args));
}
function getParentsToRoot(element, root) {
  var list = [];
  var el = element;
  while (el && el.parentNode) {
    list.push(el);
    if (el === root) break;
    el = el.parentNode;
  }
  return list;
}
function getParentMarks(name, element, root) {
  var list = getParentsToRoot(element, root);
  return list.map(function (el) {
    var mark = {
      name: name,
      value: (el === null || el === void 0 ? void 0 : el.getAttribute(name)) || "",
      el: el
    };
    return mark;
  }).filter(function (mark) {
    return mark.value;
  });
}
function getMark(name, element, root) {
  var list = getParentMarks(name, element, root);
  var info = list.pop() || null;
  return info;
}
function pathMatchClass(name, element, root) {
  var list = getParentsToRoot(element, root);
  var rs = list.some(function (el) {
    return el.classList.contains(name);
  });
  return rs;
}
function getTNode(prop, options) {
  var _conf$node;
  var tnode = null;
  var item = null;
  var conf = _objectSpread({}, 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) {
  var lineModel = {
    top: false,
    right: false,
    bottom: false,
    left: false
  };
  var nodeChildren = [];
  if (Array.isArray(node.children)) nodeChildren = node.children;
  var childNode = nodes[index - 1] || null;
  var 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) {
  var node = null;
  var 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 { emitEvent, getLineModel, getMark, getNode, getParentMarks, getParentsToRoot, getTNode, isTreeNodeValue, pathMatchClass };
//# sourceMappingURL=util.js.map
