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

'use strict';

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

var hooks_useConfig = require('../../../hooks/useConfig.js');
var components_checkbox_index = require('../../checkbox/index.js');
var components_tree_utils = require('../utils.js');
var components_tree_hooks_useItemEvents = require('./useItemEvents.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/map-props.js');
require('vue');
require('../../../utils/withInstall.js');
require('lodash/capitalize');
require('../../../config.js');
require('../../checkbox/group.js');
require('../../../chunks/helper.js');
require('lodash/intersection');
require('../../../chunks/log.js');
require('../../../chunks/_commonjsHelpers-fe796db6.js');
require('../../../utils/event.js');
require('../../../utils/helper.js');
require('lodash/camelCase');
require('../../config-provider/config-receiver.js');
require('../../../utils/mixins.js');
require('../../checkbox/checkbox.js');
require('../../../utils/render-node.js');
require('lodash');
require('../../checkbox/props.js');

function useRenderLabel(props, context) {
  const classPrefix = hooks_useConfig.usePrefixClass().value;
  const componentName = hooks_useConfig.usePrefixClass("tree").value;
  const {
    handleChange
  } = components_tree_hooks_useItemEvents["default"](props, context);
  const renderLabel = h => {
    const {
      node,
      treeScope,
      expandOnClickNode
    } = props;
    const {
      scopedSlots
    } = treeScope;
    const treeProps = treeScope?.treeProps || {};
    const {
      label,
      disableCheck
    } = treeProps;
    const checkProps = treeProps?.checkProps || {};
    let labelNode = null;
    if (label === true) {
      if (scopedSlots?.label) {
        labelNode = scopedSlots.label({
          node: node?.getModel()
        });
      } else {
        labelNode = node.label || "";
      }
    } else {
      labelNode = components_tree_utils.getTNode(label, {
        createElement: h,
        node
      });
    }
    const labelClasses = [`${componentName}__label`, {
      [`${classPrefix}-is-active`]: node.isActivable() ? node.actived : false
    }];
    if (node.vmCheckable) {
      let checkboxDisabled = false;
      if (typeof disableCheck === "function") checkboxDisabled = disableCheck(node.getModel());else checkboxDisabled = !!disableCheck;
      if (node.isDisabled()) checkboxDisabled = true;
      const itemCheckProps = {
        ...checkProps,
        disabled: checkboxDisabled
      };
      labelNode = h(components_checkbox_index.Checkbox, {
        "class": labelClasses,
        "attrs": {
          "checked": node.checked,
          "indeterminate": node.indeterminate,
          "disabled": node.isDisabled(),
          "name": String(node.value),
          "stopLabelTrigger": expandOnClickNode && Array.isArray(node.children) && node.children?.length > 0,
          "ignore": "expand,active"
        },
        "on": {
          "change": handleChange
        },
        "props": {
          ...itemCheckProps
        }
      }, [labelNode]);
    } else {
      const inner = h("span", {
        "style": "position: relative"
      }, [labelNode]);
      labelNode = node.isActivable() ? h("span", {
        "key": "1",
        "class": labelClasses
      }, [inner]) : h("span", {
        "key": "2",
        "class": labelClasses
      }, [inner]);
    }
    return labelNode;
  };
  return {
    renderLabel
  };
}

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