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

import { getNode, emitEvent } from '../utils.js';
import 'lodash/camelCase';

function useTreeAction(props, context, state) {
  const {
    cache,
    store
  } = state;
  const setExpanded = (item, isExpanded) => {
    const node = getNode(store, item);
    const expanded = node.setExpanded(isExpanded);
    const evtCtx = {
      node: node.getModel(),
      e: cache.mouseEvent
    };
    emitEvent(props, context, "expand", expanded, evtCtx);
    return expanded;
  };
  const toggleExpanded = item => {
    const node = getNode(store, item);
    return setExpanded(node, !node.isExpanded());
  };
  const setActived = (item, isActived) => {
    const node = getNode(store, item);
    const actived = node.setActived(isActived);
    const evtCtx = {
      node: node.getModel(),
      e: cache.mouseEvent
    };
    emitEvent(props, context, "active", actived, evtCtx);
    return actived;
  };
  const toggleActived = item => {
    const node = getNode(store, item);
    return setActived(node, !node.isActived());
  };
  const setChecked = (item, isChecked) => {
    const node = getNode(store, item);
    const checked = node.setChecked(isChecked);
    const evtCtx = {
      node: node.getModel()
    };
    emitEvent(props, context, "change", checked, evtCtx);
    return checked;
  };
  const toggleChecked = item => {
    const node = getNode(store, item);
    return setChecked(node, !node.isChecked());
  };
  return {
    setExpanded,
    toggleExpanded,
    setActived,
    toggleActived,
    setChecked,
    toggleChecked
  };
}

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