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

import { usePrefixClass } from '../../../hooks/useConfig.js';
import '@vue/composition-api';
import '../../config-provider/useConfig.js';
import '../../config-provider/context.js';
import 'lodash/merge';
import 'lodash/mergeWith';
import '../../../chunks/zh_CN.js';
import '../../config-provider/type.js';

function useItemEvents(props, context) {
  const {
    node
  } = props;
  const classPrefix = usePrefixClass().value;
  const handleChange = () => {
    const event = new Event("change");
    const state = {
      event,
      node
    };
    context.emit("change", state);
  };
  let clicked = false;
  const handleClick = evt => {
    const {
      expandOnClickNode
    } = props;
    const srcTarget = evt.target;
    const isBranchTrigger = node.children && expandOnClickNode && (srcTarget.className === `${classPrefix}-checkbox__input` || srcTarget.tagName.toLowerCase() === "input");
    if (clicked || isBranchTrigger) return;
    clicked = true;
    setTimeout(() => {
      clicked = false;
    });
    if (expandOnClickNode && node.children && srcTarget.className?.indexOf?.(`${classPrefix}-tree__label`) !== -1) evt.preventDefault();
    const state = {
      mouseEvent: evt,
      event: evt,
      node,
      path: node.getPath()
    };
    context.emit("click", state);
  };
  return {
    handleChange,
    handleClick
  };
}

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