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

import { usePrefixClass } from '../../hooks/useConfig.js';
import { getNode, pathMatchClass, emitEvent } from '../util.js';
import '@vue/composition-api';
import '../../config-provider/useConfig.js';
import '../../config-provider/context.js';
import 'lodash/merge';
import 'lodash/mergeWith';
import '../../_common/js/global-config/default-config.js';
import '../../_common/js/global-config/locale/zh_CN.js';
import '@babel/runtime/helpers/typeof';
import '../../_chunks/dep-2cb61c79.js';
import 'dayjs';
import '@babel/runtime/helpers/defineProperty';
import 'lodash/camelCase';

function useTreeAction(props, context, state) {
  var treeState = state;
  var store = treeState.store;
  var componentName = usePrefixClass("tree").value;
  var setExpanded = function setExpanded(item, isExpanded) {
    var node = getNode(store, item);
    var expanded = node.setExpanded(isExpanded, {
      directly: true
    });
    var mouseEvent = treeState.mouseEvent;
    var evtCtx = {
      node: node.getModel(),
      e: mouseEvent,
      trigger: "setItem"
    };
    if (mouseEvent) {
      evtCtx.trigger = "node-click";
      var target = mouseEvent.target;
      var currentTarget = mouseEvent.currentTarget;
      if (pathMatchClass("".concat(componentName, "__icon"), target, currentTarget)) evtCtx.trigger = "icon-click";
    }
    emitEvent(props, context, "expand", expanded, evtCtx);
    return expanded;
  };
  var toggleExpanded = function toggleExpanded(item) {
    var node = getNode(store, item);
    return setExpanded(node, !node.isExpanded());
  };
  var setActived = function setActived(item, isActived) {
    var node = getNode(store, item);
    var actived = node.setActived(isActived, {
      directly: true
    });
    var mouseEvent = treeState.mouseEvent;
    var evtCtx = {
      node: node.getModel(),
      e: mouseEvent,
      trigger: "setItem"
    };
    if (mouseEvent) evtCtx.trigger = "node-click";
    emitEvent(props, context, "active", actived, evtCtx);
    return actived;
  };
  var toggleActived = function toggleActived(item) {
    var node = getNode(store, item);
    return setActived(node, !node.isActived());
  };
  var setChecked = function setChecked(item, isChecked, ctx) {
    var node = getNode(store, item);
    var checked = node.setChecked(isChecked, {
      directly: true
    });
    var mouseEvent = ctx === null || ctx === void 0 ? void 0 : ctx.e;
    var evtCtx = {
      node: node.getModel(),
      e: mouseEvent,
      trigger: "setItem"
    };
    if (mouseEvent) evtCtx.trigger = "node-click";
    emitEvent(props, context, "change", checked, evtCtx);
    return checked;
  };
  var toggleChecked = function toggleChecked(item, ctx) {
    var node = getNode(store, item);
    return setChecked(node, !node.isChecked(), ctx);
  };
  return {
    setExpanded: setExpanded,
    toggleExpanded: toggleExpanded,
    setActived: setActived,
    toggleActived: toggleActived,
    setChecked: setChecked,
    toggleChecked: toggleChecked
  };
}

export { useTreeAction as default };
//# sourceMappingURL=useTreeAction.js.map
