/**
 * 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.js';
import { getCascaderItemClass, getCascaderItemIconClass } from '../core/className.js';
import { Checkbox } from '../../checkbox/index.js';
import { Loading } from '../../loading/index.js';
import { usePrefixClass, useCommonClassName } from '../../hooks/useConfig.js';
import { useGlobalIcon } from '../../hooks/useGlobalIcon.js';
import useRipple from '../../hooks/useRipple.js';
import 'lodash/isNumber';
import 'lodash/isObject';
import 'lodash/isArray';
import 'lodash/isEmpty';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/defineProperty';
import '../../utils/withInstall.js';
import '../../checkbox/checkbox.js';
import '@babel/runtime/helpers/slicedToArray';
import '../../hooks/useVModel.js';
import 'lodash/kebabCase';
import '../../form/hooks.js';
import '../../hooks/tnode.js';
import 'lodash/isFunction';
import 'lodash/camelCase';
import '../../utils/render-tnode.js';
import 'lodash/isString';
import '../../checkbox/props.js';
import '../../checkbox/constants.js';
import '../../utils/set-style.js';
import '../../hooks/useKeepAnimation.js';
import '../../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import '../../_common/js/global-config/default-config.js';
import '../../_common/js/global-config/locale/zh_CN.js';
import '@babel/runtime/helpers/typeof';
import '../../_chunks/dep-512eb181.js';
import 'dayjs';
import '../../_chunks/dep-ac28b67c.js';
import '../../config-provider/useConfig.js';
import 'lodash/cloneDeep';
import '../../config-provider/type.js';
import '../../checkbox/group.js';
import 'lodash/intersection';
import 'lodash/isUndefined';
import '../../hooks/slot.js';
import '../../checkbox/checkbox-group-props.js';
import '../../checkbox/style';
import '../../checkbox/type.js';
import '../../loading/directive.js';
import '../../loading/plugin.js';
import '../../utils/dom.js';
import '../../utils/easing.js';
import '../../loading/loading.js';
import '../../hooks/useTeleport.js';
import '../../loading/props.js';
import '../../loading/icon/gradient.js';
import '../../_common/js/loading/circle-adapter.js';
import '../../_common/js/utils/set-style.js';
import '../../_common/js/utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import 'lodash/isNull';
import '../../loading/style';
import '../../loading/type.js';

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.js.map
