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

'use strict';

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

var hooks_useConfig = require('../../hooks/useConfig.js');
var tree_util = require('../util.js');
require('@vue/composition-api');
require('../../config-provider/useConfig.js');
require('../../config-provider/context.js');
require('lodash/merge');
require('lodash/mergeWith');
require('../../_common/js/global-config/default-config.js');
require('../../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('../../_chunks/dep-7c884501.js');
require('dayjs');
require('@babel/runtime/helpers/defineProperty');
require('lodash/camelCase');

function useTreeAction(props, context, state) {
  var treeState = state;
  var store = treeState.store;
  var componentName = hooks_useConfig.usePrefixClass("tree").value;
  var setExpanded = function setExpanded(item, isExpanded) {
    var node = tree_util.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 (tree_util.pathMatchClass("".concat(componentName, "__icon"), target, currentTarget)) evtCtx.trigger = "icon-click";
    }
    tree_util.emitEvent(props, context, "expand", expanded, evtCtx);
    return expanded;
  };
  var toggleExpanded = function toggleExpanded(item) {
    var node = tree_util.getNode(store, item);
    return setExpanded(node, !node.isExpanded());
  };
  var setActived = function setActived(item, isActived) {
    var node = tree_util.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";
    tree_util.emitEvent(props, context, "active", actived, evtCtx);
    return actived;
  };
  var toggleActived = function toggleActived(item) {
    var node = tree_util.getNode(store, item);
    return setActived(node, !node.isActived());
  };
  var setChecked = function setChecked(item, isChecked, ctx) {
    var node = tree_util.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";
    tree_util.emitEvent(props, context, "change", checked, evtCtx);
    return checked;
  };
  var toggleChecked = function toggleChecked(item, ctx) {
    var node = tree_util.getNode(store, item);
    return setChecked(node, !node.isChecked(), ctx);
  };
  return {
    setExpanded: setExpanded,
    toggleExpanded: toggleExpanded,
    setActived: setActived,
    toggleActived: toggleActived,
    setChecked: setChecked,
    toggleChecked: toggleChecked
  };
}

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