/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @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 '../util.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';
import '../../utils/withInstall.js';
import '@babel/runtime/helpers/defineProperty';
import 'vue';
import 'lodash/capitalize';
import '../../loading/directive.js';
import 'lodash/isObject';
import 'lodash/mapKeys';
import 'lodash/isEqual';
import '../../loading/plugin.js';
import '../../config.js';
import '../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../utils/easing.js';
import '../../loading/loading.js';
import '../../utils/render-tnode.js';
import 'lodash/camelCase';
import 'lodash/kebabCase';
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 '../../_common/js/loading/circle-adapter.js';
import '../../_common/js/utils/set-style.js';
import '../../_common/js/utils/helper.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';
import 'lodash/isArray';
import '../../loading/style/css.js';
import '../../loading/type.js';

function useRenderIcon(props) {
  var classPrefix = usePrefixClass().value;
  var componentName = usePrefixClass("tree").value;
  var getFolderIcon = function getFolderIcon(h) {
    var _useGlobalIcon = useGlobalIcon({
        CaretRightSmallIcon: CaretRightSmallIcon
      }),
      CaretRightSmallIcon$1 = _useGlobalIcon.CaretRightSmallIcon;
    return h(CaretRightSmallIcon$1);
  };
  var handleMousedown = function handleMousedown(evt) {
    evt.preventDefault();
  };
  var renderIcon = function renderIcon(h) {
    var node = props.node,
      treeScope = props.treeScope;
    var scopedSlots = treeScope.scopedSlots;
    var treeProps = (treeScope === null || treeScope === void 0 ? void 0 : treeScope.treeProps) || {};
    var icon = treeProps.icon;
    var isDefaultIcon = false;
    var iconNode = null;
    if (icon === true) {
      if (scopedSlots !== null && scopedSlots !== void 0 && scopedSlots.icon) {
        iconNode = scopedSlots.icon({
          node: node === null || node === void 0 ? void 0 : 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: node
      });
    }
    var wrapIconNode = h("span", {
      "class": ["".concat(componentName, "__icon"), "".concat(classPrefix, "-folder-icon"), isDefaultIcon ? "".concat(componentName, "__icon--default") : ""],
      "attrs": {
        "trigger": "expand",
        "ignore": "active"
      },
      "on": {
        "mousedown": handleMousedown
      }
    }, [iconNode]);
    return wrapIconNode;
  };
  return {
    renderIcon: renderIcon
  };
}

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