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

import { usePrefixClass } from '../../../hooks/useConfig.js';
import { Checkbox } from '../../checkbox/index.js';
import { getTNode } from '../utils.js';
import useItemEvents from './useItemEvents.js';
import '@vue/composition-api';
import '../../config-provider/useConfig.js';
import '../../config-provider/context.js';
import 'lodash/merge';
import 'lodash/mergeWith';
import '../../../chunks/zh_CN.js';
import '../../config-provider/type.js';
import '../../../utils/map-props.js';
import 'vue';
import '../../../utils/withInstall.js';
import 'lodash/capitalize';
import '../../../config.js';
import '../../checkbox/group.js';
import '../../../chunks/helper.js';
import '../../../chunks/_commonjsHelpers.js';
import 'lodash/intersection';
import '../../../chunks/index.js';
import '../../../chunks/log.js';
import '../../../chunks/_commonjsHelpers-fe796db6.js';
import '../../../utils/event.js';
import '../../../utils/helper.js';
import 'lodash/camelCase';
import '../../config-provider/config-receiver.js';
import '../../../utils/mixins.js';
import '../../checkbox/checkbox.js';
import '../../../utils/render-node.js';
import 'lodash';
import '../../checkbox/props.js';
import '../../checkbox/style';
import '../../checkbox/type.js';

function useRenderLabel(props, context) {
  const classPrefix = usePrefixClass().value;
  const componentName = usePrefixClass("tree").value;
  const {
    handleChange
  } = useItemEvents(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 = 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(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
  };
}

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