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

'use strict';

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

var helper = require('../../_chunks/dep-c3e1ffac.js');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var VueCompositionAPI = require('@vue/composition-api');
var isBoolean = require('lodash/isBoolean');
var hooks_useConfig = require('../../hooks/useConfig.js');
var checkbox_index = require('../../checkbox/index.js');
var tree_util = require('../util.js');
var tree_hooks_useItemEvents = require('./useItemEvents.js');
require('../../config-provider/useConfig.js');
require('../../config-provider/context.js');
require('lodash/merge');
require('lodash/mergeWith');
require('../../_common/js/global-config/default-config.js');
require('../../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('../../_chunks/dep-7c884501.js');
require('dayjs');
require('../../utils/map-props.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('vue');
require('../../utils/withInstall.js');
require('lodash/capitalize');
require('../../checkbox/group.js');
require('@babel/runtime/helpers/toConsumableArray');
require('lodash/intersection');
require('../../utils/event.js');
require('../../utils/helper.js');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/camelCase');
require('../../config-provider/config-receiver.js');
require('../../utils/mixins.js');
require('../../checkbox/checkbox.js');
require('../../utils/render-tnode.js');
require('lodash/kebabCase');
require('../../checkbox/props.js');
require('../../checkbox/checkbox-group-props.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var isBoolean__default = /*#__PURE__*/_interopDefaultLegacy(isBoolean);

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__default["default"](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 = hooks_useConfig.usePrefixClass().value;
  var componentName = hooks_useConfig.usePrefixClass("tree").value;
  var _useItemEvents = tree_hooks_useItemEvents["default"](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 = tree_util.getTNode(label, {
        createElement: h,
        node: node
      });
    }
    var labelClasses = ["".concat(componentName, "__label"), _defineProperty__default["default"]({}, "".concat(classPrefix, "-is-active"), node.isActivable() ? node.actived : false)];
    var shouldStopLabelTrigger = VueCompositionAPI.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__default["default"](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_index.Checkbox, helper.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
  };
}

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