/**
 * ldesign v0.3.13
 * (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-3f21269a.mjs';
import '../../_chunks/dep-eba0ea6e.mjs';
import '../../_chunks/dep-469b4ae0.mjs';
import '../../_chunks/dep-255303ba.mjs';
import '../../_chunks/dep-3da99438.mjs';
import '../../_chunks/dep-a8bcacea.mjs';
import '../../_chunks/dep-b57180d0.mjs';
import '../../_chunks/dep-888e80c4.mjs';
import '../../_chunks/dep-334a4f6b.mjs';
import '../../_chunks/dep-e5eb9f23.mjs';
import '../../_chunks/dep-9fe2ef12.mjs';
import '../../_chunks/dep-672e7d1a.mjs';
import '../../_chunks/dep-4d7a675b.mjs';
import '../../_chunks/dep-5717e263.mjs';
import '../../_chunks/dep-2e7f59b1.mjs';
import '../../_chunks/dep-1434aa15.mjs';
import '../../_chunks/dep-c8d7b6b4.mjs';
import '../../_chunks/dep-9262ee2f.mjs';
import '../../_chunks/dep-bf1e33c8.mjs';
import '../../_chunks/dep-b8d7992c.mjs';
import '../../_chunks/dep-2db7b3ec.mjs';
import '../../utils/withInstall.mjs';
import '../../checkbox/checkbox.mjs';
import '../../_chunks/dep-84acf3c2.mjs';
import '../../hooks/useVModel.mjs';
import '../../_chunks/dep-9a85dac1.mjs';
import '../../_chunks/dep-1372b2d3.mjs';
import '../../_chunks/dep-42cc3015.mjs';
import '../../_chunks/dep-2bc37d52.mjs';
import '../../form/hooks.mjs';
import '../../hooks/tnode.mjs';
import '../../_chunks/dep-406cd044.mjs';
import '../../_chunks/dep-327559e8.mjs';
import '../../_chunks/dep-b2235f26.mjs';
import '../../_chunks/dep-8b989474.mjs';
import '../../utils/render-tnode.mjs';
import '../../_chunks/dep-876fb3ec.mjs';
import '../../checkbox/props.mjs';
import '../../checkbox/constants.mjs';
import '../../utils/set-style.mjs';
import '../../hooks/useKeepAnimation.mjs';
import '../../_chunks/dep-40d69a9c.mjs';
import '../../_chunks/dep-9cf86cf1.mjs';
import '../../_chunks/dep-bc1d737a.mjs';
import '../../_chunks/dep-855db8bc.mjs';
import '../../_chunks/dep-a87f3e4c.mjs';
import '../../_chunks/dep-1e566bb5.mjs';
import '../../_chunks/dep-42a19209.mjs';
import '../../_chunks/dep-dcc83161.mjs';
import '../../_chunks/dep-0fc02184.mjs';
import '../../_chunks/dep-f1994936.mjs';
import '../../_chunks/dep-345e1be3.mjs';
import '../../_common/js/global-config/default-config.mjs';
import '../../_common/js/global-config/locale/zh_CN.mjs';
import '../../_chunks/dep-9888611c.mjs';
import '../../_chunks/dep-697a1365.mjs';
import '../../config-provider/useConfig.mjs';
import '../../_chunks/dep-095107f7.mjs';
import '../../_chunks/dep-c989dff3.mjs';
import '../../_chunks/dep-8d3e9aa3.mjs';
import '../../config-provider/type.mjs';
import '../../checkbox/group.mjs';
import '../../_chunks/dep-85ed244c.mjs';
import '../../_chunks/dep-c42916c7.mjs';
import '../../_chunks/dep-78847b2e.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-60fae668.mjs';
import '../../_chunks/dep-ed5ebb35.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
