/**
 * ldesign v0.2.22
 * (c) 2022/12/7 16:21 built by swimly
 * @license MIT
 */

'use strict';

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

var components_tree_utils = require('../utils.js');
var components_tree_hooks_useTreeAction = require('./useTreeAction.js');
require('lodash/camelCase');

function useTreeEvents(props, context, state) {
  const {
    cache
  } = state;
  const {
    toggleExpanded,
    toggleActived,
    toggleChecked
  } = components_tree_hooks_useTreeAction["default"](props, context, state);
  const handleClick = evtState => {
    const {
      mouseEvent,
      event,
      node
    } = evtState;
    if (!node) return;
    cache.mouseEvent = mouseEvent;
    let shouldExpand = props.expandOnClickNode;
    let shouldActive = !props.disabled && !node.disabled;
    ["trigger", "ignore"].forEach(markName => {
      const mark = components_tree_utils.getMark(markName, event.target, event.currentTarget);
      const markValue = 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);
    const evtCtx = {
      node: node.getModel(),
      e: mouseEvent
    };
    if (shouldActive) {
      toggleActived(node);
      components_tree_utils.emitEvent(props, context, "click", evtCtx);
    }
    cache.mouseEvent = null;
  };
  const handleChange = evtState => {
    const {
      disabled
    } = props;
    const {
      node
    } = evtState;
    if (!node || disabled || node.disabled) return;
    toggleChecked(node);
  };
  return {
    handleChange,
    handleClick
  };
}

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