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

import { getMark, emitEvent } from '../util.js';
import useTreeAction from './useTreeAction.js';
import '@babel/runtime/helpers/defineProperty';
import 'lodash/camelCase';
import '../../hooks/useConfig.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-be599ec8.js';
import 'dayjs';
import '../../_chunks/dep-67ff4010.js';
import '../../config-provider/type.js';

function useTreeEvents(props, context, state) {
  var treeState = state;
  var _useTreeAction = useTreeAction(props, context, state),
    toggleExpanded = _useTreeAction.toggleExpanded,
    toggleActived = _useTreeAction.toggleActived,
    toggleChecked = _useTreeAction.toggleChecked;
  var handleClick = function handleClick(evtState) {
    var mouseEvent = evtState.mouseEvent,
      event = evtState.event,
      node = evtState.node;
    if (!node || !mouseEvent) return;
    treeState.mouseEvent = mouseEvent;
    var shouldExpand = props.expandOnClickNode;
    var shouldActive = !props.disabled && !node.disabled;
    ["trigger", "ignore"].forEach(function (markName) {
      var mark = getMark(markName, event.target, event.currentTarget);
      var markValue = (mark === null || mark === void 0 ? void 0 : mark.value) || "";
      if (markValue.includes("expand")) {
        if (markName === "trigger") shouldExpand = true;else if (markName === "ignore") shouldExpand = false;
      }
      if (markValue.includes("active")) {
        if (markName === "ignore") shouldActive = false;
      }
    });
    if (shouldExpand) toggleExpanded(node);
    if (shouldActive) toggleActived(node);
    var evtCtx = {
      node: node.getModel(),
      e: mouseEvent
    };
    emitEvent(props, context, "click", evtCtx);
    treeState.mouseEvent = null;
  };
  var handleChange = function handleChange(evtState, ctx) {
    var disabled = props.disabled;
    var node = evtState.node;
    if (!node || disabled || node.disabled) return;
    toggleChecked(node, ctx);
  };
  return {
    handleChange: handleChange,
    handleClick: handleClick
  };
}

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