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

import { isVNode, defineComponent, ref, computed, createVNode, mergeProps } from 'vue';
import { ChevronRightIcon } from '@ldesign/icons-vue-next';
import { getFullPathLabel } from '../core/helper.mjs';
import { getCascaderItemClass, getCascaderItemIconClass } from '../core/className.mjs';
import { Checkbox } from '../../checkbox/index.mjs';
import { Loading } from '../../loading/index.mjs';
import { usePrefixClass, useCommonClassName } from '../../hooks/useConfig.mjs';
import { useGlobalIcon } from '../../hooks/useGlobalIcon.mjs';
import useRipple from '../../hooks/useRipple.mjs';
import '../../_chunks/dep-6eea369f.mjs';
import '../../_chunks/dep-a0b4a044.mjs';
import '../../_chunks/dep-c959a6fb.mjs';
import '../../_chunks/dep-b4041200.mjs';
import '../../_chunks/dep-c31e1d9e.mjs';
import '../../_chunks/dep-0f0c89ff.mjs';
import '../../_chunks/dep-e3b14d70.mjs';
import '../../_chunks/dep-bd03960e.mjs';
import '../../_chunks/dep-44f056cd.mjs';
import '../../_chunks/dep-a9c8a5d5.mjs';
import '../../_chunks/dep-10085c61.mjs';
import '../../_chunks/dep-1b058de3.mjs';
import '../../_chunks/dep-39cc276d.mjs';
import '../../_chunks/dep-6b22dd27.mjs';
import '../../_chunks/dep-8f777748.mjs';
import '../../_chunks/dep-05fa17c9.mjs';
import '../../_chunks/dep-66d6733b.mjs';
import '../../_chunks/dep-92e7085e.mjs';
import '../../_chunks/dep-e091cfd9.mjs';
import '../../_chunks/dep-cfcedf47.mjs';
import '../../_chunks/dep-eb20e23f.mjs';
import '../../utils/withInstall.mjs';
import '../../checkbox/checkbox.mjs';
import '../../_chunks/dep-55846619.mjs';
import '../../hooks/useVModel.mjs';
import '../../_chunks/dep-c4e1a112.mjs';
import '../../_chunks/dep-74848b92.mjs';
import '../../_chunks/dep-37ba476d.mjs';
import '../../_chunks/dep-be27d184.mjs';
import '../../form/hooks.mjs';
import '../../hooks/tnode.mjs';
import '../../_chunks/dep-f6649a46.mjs';
import '../../_chunks/dep-1fe0ad42.mjs';
import '../../_chunks/dep-d54f2690.mjs';
import '../../_chunks/dep-59c8420d.mjs';
import '../../utils/render-tnode.mjs';
import '../../_chunks/dep-1cf2b129.mjs';
import '../../checkbox/props.mjs';
import '../../checkbox/constants.mjs';
import '../../utils/set-style.mjs';
import '../../hooks/useKeepAnimation.mjs';
import '../../_chunks/dep-99920870.mjs';
import '../../_chunks/dep-79821ff2.mjs';
import '../../_chunks/dep-0bfbf721.mjs';
import '../../_chunks/dep-ae357f26.mjs';
import '../../_chunks/dep-352691c2.mjs';
import '../../_chunks/dep-2cfd5b3a.mjs';
import '../../_chunks/dep-c852a61a.mjs';
import '../../_chunks/dep-c7e9ce16.mjs';
import '../../_chunks/dep-3afa94cf.mjs';
import '../../_chunks/dep-ba3c0b2e.mjs';
import '../../_chunks/dep-ee57d235.mjs';
import '../../_common/js/global-config/default-config.mjs';
import '../../_common/js/global-config/locale/zh_CN.mjs';
import '../../_chunks/dep-6b4aa943.mjs';
import '../../_chunks/dep-d52291a9.mjs';
import '../../config-provider/useConfig.mjs';
import '../../_chunks/dep-44417261.mjs';
import '../../_chunks/dep-bf74f1c2.mjs';
import '../../_chunks/dep-23a0f453.mjs';
import '../../config-provider/type.mjs';
import '../../checkbox/group.mjs';
import '../../_chunks/dep-0492e83e.mjs';
import '../../_chunks/dep-5d966cee.mjs';
import '../../_chunks/dep-30451c48.mjs';
import '../../hooks/slot.mjs';
import '../../checkbox/checkbox-group-props.mjs';
import '../../checkbox/style/css.mjs';
import '../../checkbox/type.mjs';
import '../../loading/directive.mjs';
import '../../loading/plugin.mjs';
import '../../utils/dom.mjs';
import '../../utils/easing.mjs';
import '../../loading/loading.mjs';
import '../../hooks/useTeleport.mjs';
import '../../loading/props.mjs';
import '../../loading/icon/gradient.mjs';
import '../../_common/js/loading/circle-adapter.mjs';
import '../../_common/js/utils/set-style.mjs';
import '../../_common/js/utils/helper.mjs';
import '../../_chunks/dep-b6a73f93.mjs';
import '../../_chunks/dep-6f89b77e.mjs';
import '../../loading/style/css.mjs';
import '../../loading/type.mjs';

function _isSlot(s) {
  return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !isVNode(s);
}
var props = {
  node: {
    type: Object,
    "default": function _default() {
      return {};
    }
  },
  cascaderContext: {
    type: Object
  },
  onChange: Function,
  onClick: Function,
  onMouseenter: Function
};
var Item = defineComponent({
  name: "TCascaderItem",
  props: props,
  setup: function setup(props2) {
    var liRef = ref();
    useRipple(liRef);
    var COMPONENT_NAME = usePrefixClass("cascader__item");
    var classPrefix = usePrefixClass();
    var _useGlobalIcon = useGlobalIcon({
        ChevronRightIcon: ChevronRightIcon
      }),
      ChevronRightIcon$1 = _useGlobalIcon.ChevronRightIcon;
    var _useCommonClassName = useCommonClassName(),
      STATUS = _useCommonClassName.STATUS,
      SIZE = _useCommonClassName.SIZE;
    var itemClass = computed(function () {
      return getCascaderItemClass(classPrefix.value, props2.node, SIZE.value, STATUS.value, props2.cascaderContext);
    });
    var iconClass = computed(function () {
      return getCascaderItemIconClass(classPrefix.value, props2.node, STATUS.value, props2.cascaderContext);
    });
    function RenderLabelInner(node, cascaderContext) {
      var inputVal = cascaderContext.inputVal;
      var labelText = inputVal ? getFullPathLabel(node) : node.label;
      if (inputVal) {
        var texts = labelText.split(inputVal);
        var doms = [];
        for (var index = 0; index < texts.length; index++) {
          doms.push(createVNode("span", {
            "key": index
          }, [texts[index]]));
          if (index === texts.length - 1) break;
          doms.push(createVNode("span", {
            "key": "".concat(index, "filter"),
            "class": "".concat(COMPONENT_NAME.value, "-label--filter")
          }, [inputVal]));
        }
        return doms;
      }
      return labelText;
    }
    function RenderLabelContent(node, cascaderContext) {
      var label = RenderLabelInner(node, cascaderContext);
      var labelCont = createVNode("span", {
        "title": cascaderContext.inputVal ? getFullPathLabel(node) : node.label,
        "class": ["".concat(COMPONENT_NAME.value, "-label"), "".concat(COMPONENT_NAME.value, "-label--ellipsis")],
        "role": "label"
      }, [label]);
      return labelCont;
    }
    function RenderCheckBox(node, cascaderContext) {
      var checkProps = cascaderContext.checkProps,
        value = cascaderContext.value,
        max = cascaderContext.max,
        inputVal = cascaderContext.inputVal;
      var label = RenderLabelInner(node, cascaderContext);
      return createVNode(Checkbox, mergeProps({
        "checked": node.checked,
        "indeterminate": node.indeterminate,
        "disabled": node.isDisabled() || value.length >= max && max !== 0,
        "name": String(node.value),
        "stopLabelTrigger": !!node.children,
        "title": inputVal ? getFullPathLabel(node) : node.label,
        "onChange": function onChange() {
          props2.onChange();
        }
      }, checkProps), _isSlot(label) ? label : {
        "default": function _default() {
          return [label];
        }
      });
    }
    return function () {
      var cascaderContext = props2.cascaderContext,
        node = props2.node;
      return createVNode("li", {
        "ref": liRef,
        "class": itemClass.value,
        "onClick": function onClick(e) {
          e.stopPropagation();
          props2.onClick();
        },
        "onMouseenter": function onMouseenter(e) {
          e.stopPropagation();
          props2.onMouseenter();
        }
      }, [cascaderContext.multiple ? RenderCheckBox(node, cascaderContext) : RenderLabelContent(node, cascaderContext), node.children && (node.loading ? createVNode(Loading, {
        "class": iconClass.value,
        "size": "small"
      }, null) : createVNode(ChevronRightIcon$1, {
        "class": iconClass.value
      }, null))]);
    };
  }
});

export { Item as default };
//# sourceMappingURL=Item.mjs.map
