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

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var upperFirst = require('lodash/upperFirst');
var isArray = require('lodash/isArray');
var tree_util = require('../util.js');
require('@babel/runtime/helpers/defineProperty');
require('vue');
require('lodash/pick');
require('lodash/isFunction');
require('lodash/isString');
require('lodash/isNumber');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var upperFirst__default = /*#__PURE__*/_interopDefaultLegacy(upperFirst);
var isArray__default = /*#__PURE__*/_interopDefaultLegacy(isArray);

function useExposeFunc(treeStore, expose) {
  var setItem = function setItem(value, options) {
    var node = treeStore.value.getNode(value);
    var spec = options;
    var keys = Object.keys(spec);
    if (node && spec) {
      ["expanded", "actived", "checked"].forEach(function (name) {
        if (keys.includes(name)) node["set".concat(upperFirst__default["default"](name))](spec[name], {
          directly: true
        });
      });
    }
  };
  var getItem = function getItem(value) {
    var node = treeStore.value.getNode(value);
    return node === null || node === void 0 ? void 0 : node.getModel();
  };
  var getItems = function getItems(value) {
    var nodes = treeStore.value.getNodes(value);
    return nodes.map(function (node) {
      return node.getModel();
    });
  };
  var appendTo = function appendTo(para, item) {
    var list = [];
    if (isArray__default["default"](item)) list = item;else list = [item];
    list.forEach(function (item2) {
      var val = (item2 === null || item2 === void 0 ? void 0 : item2.value) || "";
      var node = tree_util.getNode(treeStore.value, val);
      if (node) treeStore.value.appendNodes(para, node);else treeStore.value.appendNodes(para, item2);
    });
  };
  var insertBefore = function insertBefore(value, item) {
    var val = (item === null || item === void 0 ? void 0 : item.value) || "";
    var node = tree_util.getNode(treeStore.value, val);
    if (node) {
      treeStore.value.insertBefore(value, node);
    } else {
      treeStore.value.insertBefore(value, item);
    }
  };
  var insertAfter = function insertAfter(value, item) {
    var val = (item === null || item === void 0 ? void 0 : item.value) || "";
    var node = tree_util.getNode(treeStore.value, val);
    if (node) {
      treeStore.value.insertAfter(value, node);
    } else {
      treeStore.value.insertAfter(value, item);
    }
  };
  var remove = function remove(value) {
    return treeStore.value.remove(value);
  };
  var getIndex = function getIndex(value) {
    return treeStore.value.getNodeIndex(value);
  };
  var getParent = function getParent(value) {
    var node = treeStore.value.getParent(value);
    return node === null || node === void 0 ? void 0 : node.getModel();
  };
  var getParents = function getParents(value) {
    var nodes = treeStore.value.getParents(value);
    return nodes.map(function (node) {
      return node.getModel();
    });
  };
  var getPath = function getPath(value) {
    var node = treeStore.value.getNode(value);
    var pathNodes = [];
    if (node) pathNodes = node.getPath().map(function (node2) {
      return node2.getModel();
    });
    return pathNodes;
  };
  expose({
    setItem: setItem,
    getItem: getItem,
    getItems: getItems,
    appendTo: appendTo,
    insertBefore: insertBefore,
    insertAfter: insertAfter,
    remove: remove,
    getIndex: getIndex,
    getParent: getParent,
    getParents: getParents,
    getPath: getPath
  });
}

exports["default"] = useExposeFunc;
//# sourceMappingURL=useExposeFunc.js.map
