/**
 * tdesign v0.41.7
 * (c) 2022 tdesign
 * @license MIT
 */

import { h as helper } from '../../_chunks/dep-37d5b9c4.js';
import { ChevronRightIcon } from 'tdesign-icons-vue';
import { prefix } from '../../config.js';
import ClASSNAMES from '../../utils/classnames.js';
import Ripple from '../../utils/ripple.js';
import mixins from '../../utils/mixins.js';
import { getFullPathLabel } from '../utils/helper.js';
import { getCascaderItemClass, getCascaderItemIconClass, getLabelIsEllipsis } from '../utils/item.js';
import { getKeepAnimationMixins } from '../../config-provider/config-receiver.js';
import { Loading } from '../../loading/index.js';
import { Checkbox } from '../../checkbox/index.js';
import { Tooltip } from '../../tooltip/index.js';
import '../../_common/js/utils/set-style.js';
import 'vue';
import '@babel/runtime/helpers/typeof';
import 'lodash/isEmpty';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/defineProperty';
import 'lodash/mergeWith';
import '../../config-provider/context.js';
import 'lodash/merge';
import '../../_common/js/global-config/default-config.js';
import '../../_common/js/global-config/locale/zh_CN.js';
import '../../config-provider/type.js';
import '../../loading/loading.js';
import '../../loading/icon/gradient.js';
import '../../_common/js/loading/circle-adapter.js';
import '../../_common/js/utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import '../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../utils/easing.js';
import '../../utils/render-tnode.js';
import '../../utils/transfer-dom.js';
import '../../loading/props.js';
import '../../utils/withInstall.js';
import 'lodash/capitalize';
import './style/index.js';
import '../../loading/type.js';
import '../../loading/plugin.js';
import '../../checkbox/group.js';
import 'lodash/intersection';
import '../../checkbox/checkbox.js';
import '../../checkbox/props.js';
import '../../utils/helper.js';
import 'lodash/camelCase';
import '../../utils/event.js';
import '../../checkbox/checkbox-group-props.js';
import '../../utils/map-props.js';
import '../../checkbox/type.js';
import '../../tooltip/tooltip.js';
import 'lodash/isFunction';
import '../../tooltip/props.js';
import '../../popup/props.js';
import '../../popup/popup.js';
import '@popperjs/core';
import '../../popup/container.js';
import '../../tooltip/type.js';

var name = "".concat(prefix, "-cascader-item");
var ComponentClassName = "".concat(prefix, "-cascader__item");
var keepAnimationMixins = getKeepAnimationMixins();
var Item = mixins(keepAnimationMixins).extend({
  name: name,
  directives: {
    ripple: Ripple
  },
  components: {
    Tooltip: Tooltip
  },
  props: {
    node: {
      type: Object,
      "default": function _default() {
        return {};
      }
    },
    cascaderContext: {
      type: Object
    }
  },
  computed: {
    itemClass: function itemClass() {
      return getCascaderItemClass(prefix, this.node, ClASSNAMES, this.cascaderContext);
    },
    iconClass: function iconClass() {
      return getCascaderItemIconClass(prefix, this.node, ClASSNAMES, this.cascaderContext);
    }
  },
  render: function render() {
    var _this = this;

    var h = arguments[0];
    var node = this.node,
        itemClass = this.itemClass,
        iconClass = this.iconClass,
        cascaderContext = this.cascaderContext;

    var handleClick = function handleClick(e) {
      e.stopPropagation();
      var ctx = {
        e: e,
        node: node
      };

      _this.$emit("click", ctx);
    };

    var handleChange = function handleChange(e) {
      var ctx = {
        e: e,
        node: node
      };

      _this.$emit("change", ctx);
    };

    var handleMouseenter = function handleMouseenter(e) {
      e.stopPropagation();
      var ctx = {
        e: e,
        node: node
      };

      _this.$emit("mouseenter", ctx);
    };

    function RenderLabelInner(node2, cascaderContext2) {
      var filterActive = cascaderContext2.filterActive,
          inputVal = cascaderContext2.inputVal;
      var labelText = filterActive ? getFullPathLabel(node2) : node2.label;

      if (filterActive) {
        var texts = labelText.split(inputVal);
        var doms = [];

        for (var index = 0; index < texts.length; index++) {
          doms.push(h("span", {
            "key": index
          }, [texts[index]]));
          if (index === texts.length - 1) break;
          doms.push(h("span", {
            "key": "".concat(index, "filter"),
            "attrs": {
              "className": "".concat(name, "-label--filter")
            }
          }, [inputVal]));
        }

        return doms;
      }

      return labelText;
    }

    function RenderLabelContent(node2, cascaderContext2) {
      var label = RenderLabelInner(node2, cascaderContext2);
      var isEllipsis = getLabelIsEllipsis(node2, cascaderContext2.size);
      var labelNode = h("span", {
        "class": ["".concat(ComponentClassName, "-label")],
        "attrs": {
          "role": "label"
        }
      }, [label]);

      if (isEllipsis) {
        return h(Tooltip, {
          "attrs": {
            "content": node2.label,
            "placement": "top-left"
          }
        }, [labelNode]);
      }

      return labelNode;
    }

    function RenderCheckBox(node2, cascaderContext2, handleChange2) {
      var checkProps = cascaderContext2.checkProps,
          value = cascaderContext2.value,
          max = cascaderContext2.max,
          size = cascaderContext2.size;
      var label = RenderLabelInner(node2, cascaderContext2);
      return h(Checkbox, helper([{
        "attrs": {
          "checked": node2.checked,
          "indeterminate": node2.indeterminate,
          "disabled": node2.isDisabled() || value.length >= max && max !== 0,
          "name": node2.value,
          "size": size
        },
        "on": {
          "change": handleChange2
        }
      }, checkProps]), [label]);
    }

    return h("li", {
      "directives": [{
        name: "ripple",
        value: this.keepAnimation.ripple
      }],
      "class": itemClass,
      "on": {
        "click": handleClick,
        "mouseenter": handleMouseenter
      }
    }, [cascaderContext.multiple ? RenderCheckBox(node, cascaderContext, handleChange) : RenderLabelContent(node, cascaderContext), node.children && (node.loading ? h(Loading, {
      "class": iconClass,
      "attrs": {
        "size": "small"
      }
    }) : h(ChevronRightIcon, {
      "class": iconClass
    }))]);
  }
});

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