/**
 * 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');
require('lodash/camelCase');

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

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