/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @license MIT
 */

import { h as helper } from '../../_chunks/dep-c89aafbb.js';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { computed } from '@vue/composition-api';
import isBoolean from 'lodash/isBoolean';
import { usePrefixClass } from '../../hooks/useConfig.js';
import { Checkbox } from '../../checkbox/index.js';
import { getTNode } from '../util.js';
import useItemEvents from './useItemEvents.js';
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/map-props.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import 'vue';
import '../../utils/withInstall.js';
import 'lodash/capitalize';
import '../../checkbox/group.js';
import '@babel/runtime/helpers/toConsumableArray';
import 'lodash/intersection';
import '../../utils/event.js';
import '../../utils/helper.js';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/camelCase';
import '../../config-provider/config-receiver.js';
import '../../utils/mixins.js';
import '../../checkbox/checkbox.js';
import '../../utils/render-tnode.js';
import 'lodash/kebabCase';
import '../../checkbox/props.js';
import '../../checkbox/checkbox-group-props.js';
import '../../checkbox/style/css.js';
import '../../checkbox/type.js';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function useRenderLabel(props, context) {
  var classPrefix = usePrefixClass().value;
  var componentName = usePrefixClass("tree").value;
  var _useItemEvents = useItemEvents(props, context),
    handleChange = _useItemEvents.handleChange;
  var renderLabel = function renderLabel(h) {
    var node = props.node,
      treeScope = props.treeScope,
      expandOnClickNode = props.expandOnClickNode;
    var scopedSlots = treeScope.scopedSlots;
    var treeProps = (treeScope === null || treeScope === void 0 ? void 0 : treeScope.treeProps) || {};
    var label = treeProps.label,
      disableCheck = treeProps.disableCheck;
    var checkProps = (treeProps === null || treeProps === void 0 ? void 0 : treeProps.checkProps) || {};
    var labelNode = null;
    if (label === true) {
      if (scopedSlots !== null && scopedSlots !== void 0 && scopedSlots.label) {
        labelNode = scopedSlots.label({
          node: node === null || node === void 0 ? void 0 : node.getModel()
        });
      } else {
        labelNode = node.label || "";
      }
    } else {
      labelNode = getTNode(label, {
        createElement: h,
        node: node
      });
    }
    var labelClasses = ["".concat(componentName, "__label"), _defineProperty({}, "".concat(classPrefix, "-is-active"), node.isActivable() ? node.actived : false)];
    var shouldStopLabelTrigger = computed(function () {
      var _node$children;
      var isNormalBranchNode = Array.isArray(node.children) && ((_node$children = node.children) === null || _node$children === void 0 ? void 0 : _node$children.length) > 0;
      var isLazyLoadChildBranchNode = isBoolean(node.children) && node.children;
      var isBranchNode = isNormalBranchNode || isLazyLoadChildBranchNode;
      return expandOnClickNode && isBranchNode;
    });
    if (node.vmCheckable) {
      var checkboxDisabled = false;
      if (typeof disableCheck === "function") checkboxDisabled = disableCheck(node.getModel());else checkboxDisabled = !!disableCheck;
      if (node.vmIsLocked && !node.vmIsRest) checkboxDisabled = true;
      if (node.isDisabled()) checkboxDisabled = true;
      var itemCheckProps = _objectSpread(_objectSpread({}, checkProps), {}, {
        disabled: checkboxDisabled
      });
      labelNode = h(Checkbox, helper([{
        "class": labelClasses,
        "attrs": {
          "checked": node.checked,
          "indeterminate": node.indeterminate,
          "disabled": node.isDisabled(),
          "name": String(node.value),
          "stopLabelTrigger": shouldStopLabelTrigger.value,
          "ignore": "expand,active"
        },
        "on": {
          "change": handleChange
        }
      }, {
        "props": itemCheckProps
      }]), [labelNode]);
    } else {
      var inner = h("span", {
        "style": "position: relative"
      }, [labelNode]);
      labelNode = node.isActivable() ? h("span", {
        "key": "1",
        "class": labelClasses,
        "attrs": {
          "title": node.label
        }
      }, [inner]) : h("span", {
        "key": "2",
        "class": labelClasses,
        "attrs": {
          "title": node.label
        }
      }, [inner]);
    }
    return labelNode;
  };
  return {
    renderLabel: renderLabel
  };
}

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