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

import { CaretRightSmallIcon } from '@ldesign/icons-vue';
import { usePrefixClass } from '../../../hooks/useConfig.js';
import { useGlobalIcon } from '../../../hooks/useGlobalIcon.js';
import { Loading } from '../../loading/index.js';
import { getTNode } from '../utils.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';
import '../../../utils/withInstall.js';
import 'vue';
import 'lodash/capitalize';
import '../../../config.js';
import '../../loading/loading.js';
import '../../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../../chunks/index.js';
import '../../../chunks/log.js';
import '../../../chunks/_commonjsHelpers-fe796db6.js';
import '../../../utils/easing.js';
import '../../../utils/render-node.js';
import 'lodash';
import '../../../utils/transfer-dom.js';
import '../../config-provider/config-receiver.js';
import '../../../utils/mixins.js';
import '../../loading/props.js';
import '../../loading/icon/gradient.js';
import '../../../chunks/defineProperty-19da3d4c.js';
import '../../../chunks/set-style.js';
import '../../../chunks/helper2.js';
import '../../loading/style/css.js';
import '../../loading/type.js';
import '../../loading/plugin.js';
import 'lodash/camelCase';

function useRenderIcon(props) {
  const classPrefix = usePrefixClass().value;
  const componentName = usePrefixClass("tree").value;
  const getFolderIcon = h => {
    const {
      CaretRightSmallIcon: CaretRightSmallIcon$1
    } = useGlobalIcon({
      CaretRightSmallIcon: CaretRightSmallIcon
    });
    return h(CaretRightSmallIcon$1);
  };
  const renderIcon = h => {
    const {
      node,
      treeScope
    } = props;
    const {
      scopedSlots
    } = treeScope;
    const treeProps = treeScope?.treeProps || {};
    const {
      icon
    } = treeProps;
    let isDefaultIcon = false;
    let iconNode = null;
    if (icon === true) {
      if (scopedSlots?.icon) {
        iconNode = scopedSlots.icon({
          node: node?.getModel()
        });
      } else if (!node.vmIsLeaf) {
        isDefaultIcon = true;
        iconNode = getFolderIcon(h);
        if (node.loading && node.expanded) iconNode = h(Loading);
      } else {
        iconNode = "";
      }
    } else if (icon) {
      iconNode = getTNode(icon, {
        createElement: h,
        node
      });
    }
    const wrapIconNode = h("span", {
      "class": [`${componentName}__icon`, `${classPrefix}-folder-icon`, isDefaultIcon ? `${componentName}__icon--default` : ""],
      "attrs": {
        "trigger": "expand",
        "ignore": "active"
      }
    }, [iconNode]);
    return wrapIconNode;
  };
  return {
    renderIcon
  };
}

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