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

'use strict';

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

var vue = require('vue');
var iconsVueNext = require('@ldesign/icons-vue-next');
var cascader_core_helper = require('../core/helper.js');
var cascader_core_className = require('../core/className.js');
var checkbox_index = require('../../checkbox/index.js');
var loading_index = require('../../loading/index.js');
var hooks_useConfig = require('../../hooks/useConfig.js');
var hooks_useGlobalIcon = require('../../hooks/useGlobalIcon.js');
var hooks_useRipple = require('../../hooks/useRipple.js');
require('lodash/isNumber');
require('lodash/isObject');
require('lodash/isArray');
require('lodash/isEmpty');
require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/helpers/defineProperty');
require('../../utils/withInstall.js');
require('../../checkbox/checkbox.js');
require('@babel/runtime/helpers/slicedToArray');
require('../../hooks/useVModel.js');
require('lodash/kebabCase');
require('../../form/hooks.js');
require('../../hooks/tnode.js');
require('lodash/isFunction');
require('lodash/camelCase');
require('../../utils/render-tnode.js');
require('lodash/isString');
require('../../checkbox/props.js');
require('../../checkbox/constants.js');
require('../../utils/set-style.js');
require('../../hooks/useKeepAnimation.js');
require('../../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('../../_common/js/global-config/default-config.js');
require('../../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('../../_chunks/dep-7f0559c3.js');
require('dayjs');
require('../../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('../../checkbox/group.js');
require('lodash/intersection');
require('lodash/isUndefined');
require('../../hooks/slot.js');
require('../../checkbox/checkbox-group-props.js');
require('../../loading/directive.js');
require('../../loading/plugin.js');
require('../../utils/dom.js');
require('../../utils/easing.js');
require('../../loading/loading.js');
require('../../hooks/useTeleport.js');
require('../../loading/props.js');
require('../../loading/icon/gradient.js');
require('../../_common/js/loading/circle-adapter.js');
require('../../_common/js/utils/set-style.js');
require('../../_common/js/utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('lodash/isNull');

function _isSlot(s) {
  return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !vue.isVNode(s);
}
var props = {
  node: {
    type: Object,
    "default": function _default() {
      return {};
    }
  },
  cascaderContext: {
    type: Object
  },
  onChange: Function,
  onClick: Function,
  onMouseenter: Function
};
var Item = vue.defineComponent({
  name: "TCascaderItem",
  props: props,
  setup: function setup(props2) {
    var liRef = vue.ref();
    hooks_useRipple["default"](liRef);
    var COMPONENT_NAME = hooks_useConfig.usePrefixClass("cascader__item");
    var classPrefix = hooks_useConfig.usePrefixClass();
    var _useGlobalIcon = hooks_useGlobalIcon.useGlobalIcon({
        ChevronRightIcon: iconsVueNext.ChevronRightIcon
      }),
      ChevronRightIcon = _useGlobalIcon.ChevronRightIcon;
    var _useCommonClassName = hooks_useConfig.useCommonClassName(),
      STATUS = _useCommonClassName.STATUS,
      SIZE = _useCommonClassName.SIZE;
    var itemClass = vue.computed(function () {
      return cascader_core_className.getCascaderItemClass(classPrefix.value, props2.node, SIZE.value, STATUS.value, props2.cascaderContext);
    });
    var iconClass = vue.computed(function () {
      return cascader_core_className.getCascaderItemIconClass(classPrefix.value, props2.node, STATUS.value, props2.cascaderContext);
    });
    function RenderLabelInner(node, cascaderContext) {
      var inputVal = cascaderContext.inputVal;
      var labelText = inputVal ? cascader_core_helper.getFullPathLabel(node) : node.label;
      if (inputVal) {
        var texts = labelText.split(inputVal);
        var doms = [];
        for (var index = 0; index < texts.length; index++) {
          doms.push(vue.createVNode("span", {
            "key": index
          }, [texts[index]]));
          if (index === texts.length - 1) break;
          doms.push(vue.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 = vue.createVNode("span", {
        "title": cascaderContext.inputVal ? cascader_core_helper.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 vue.createVNode(checkbox_index.Checkbox, vue.mergeProps({
        "checked": node.checked,
        "indeterminate": node.indeterminate,
        "disabled": node.isDisabled() || value.length >= max && max !== 0,
        "name": String(node.value),
        "stopLabelTrigger": !!node.children,
        "title": inputVal ? cascader_core_helper.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 vue.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 ? vue.createVNode(loading_index.Loading, {
        "class": iconClass.value,
        "size": "small"
      }, null) : vue.createVNode(ChevronRightIcon, {
        "class": iconClass.value
      }, null))]);
    };
  }
});

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