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

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var iconsVue = require('@ldesign/icons-vue');
var hooks_useConfig = require('../../../hooks/useConfig.js');
var hooks_useGlobalIcon = require('../../../hooks/useGlobalIcon.js');
var components_loading_index = require('../../loading/index.js');
var components_tree_utils = require('../utils.js');
require('@vue/composition-api');
require('../../config-provider/useConfig.js');
require('../../config-provider/context.js');
require('lodash/merge');
require('lodash/mergeWith');
require('../../../chunks/zh_CN.js');
require('../../../utils/withInstall.js');
require('vue');
require('lodash/capitalize');
require('../../../config.js');
require('../../loading/loading.js');
require('../../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../../chunks/log.js');
require('../../../chunks/_commonjsHelpers-fe796db6.js');
require('../../../utils/easing.js');
require('../../../utils/render-node.js');
require('lodash');
require('../../../utils/transfer-dom.js');
require('../../config-provider/config-receiver.js');
require('../../../utils/mixins.js');
require('../../loading/props.js');
require('../../loading/icon/gradient.js');
require('../../../chunks/defineProperty-19da3d4c.js');
require('../../../chunks/set-style.js');
require('../../../chunks/helper2.js');
require('../../loading/plugin.js');
require('lodash/camelCase');

function useRenderIcon(props) {
  const classPrefix = hooks_useConfig.usePrefixClass().value;
  const componentName = hooks_useConfig.usePrefixClass("tree").value;
  const getFolderIcon = h => {
    const {
      CaretRightSmallIcon
    } = hooks_useGlobalIcon.useGlobalIcon({
      CaretRightSmallIcon: iconsVue.CaretRightSmallIcon
    });
    return h(CaretRightSmallIcon);
  };
  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(components_loading_index.Loading);
      } else {
        iconNode = "";
      }
    } else if (icon) {
      iconNode = components_tree_utils.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
  };
}

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