/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @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 '../../_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 useItemEvents(props, context) {
  var node = props.node;
  var classPrefix = usePrefixClass().value;
  var handleChange = function handleChange(_, ctx) {
    var event = new Event("change");
    var state = {
      event: event,
      node: node
    };
    context.emit("change", state, ctx);
  };
  var clicked = false;
  var handleClick = function handleClick(evt) {
    var _srcTarget$className, _srcTarget$className$;
    var expandOnClickNode = props.expandOnClickNode;
    var srcTarget = evt.target;
    var isBranchTrigger = node.children && expandOnClickNode && (srcTarget.className === "".concat(classPrefix, "-checkbox__input") || srcTarget.tagName.toLowerCase() === "input");
    if (clicked || isBranchTrigger) return;
    clicked = true;
    setTimeout(function () {
      clicked = false;
    });
    if (expandOnClickNode && node.children && ((_srcTarget$className = srcTarget.className) === null || _srcTarget$className === void 0 ? void 0 : (_srcTarget$className$ = _srcTarget$className.indexOf) === null || _srcTarget$className$ === void 0 ? void 0 : _srcTarget$className$.call(_srcTarget$className, "".concat(classPrefix, "-tree__label"))) !== -1) evt.preventDefault();
    var state = {
      mouseEvent: evt,
      event: evt,
      node: node,
      path: node.getPath()
    };
    context.emit("click", state);
  };
  return {
    handleChange: handleChange,
    handleClick: handleClick
  };
}

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