/**
 * tdesign v0.39.1-alpha.1
 * (c) 2022 tdesign
 * @license MIT
 */

'use strict';

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

var helper = require('../../_chunks/dep-33ee4bce.js');
var tdesignIconsVue = require('tdesign-icons-vue');
var config = require('../../config.js');
var utils_classnames = require('../../utils/classnames.js');
var utils_ripple = require('../../utils/ripple.js');
var utils_mixins = require('../../utils/mixins.js');
var cascader_utils_helper = require('../utils/helper.js');
var cascader_utils_item = require('../utils/item.js');
var configProvider_configReceiver = require('../../config-provider/config-receiver.js');
var loading_index = require('../../loading/index.js');
var checkbox_index = require('../../checkbox/index.js');
var tooltip_index = require('../../tooltip/index.js');
require('../../_common/js/utils/set-style.js');
require('vue');
require('@babel/runtime/helpers/typeof');
require('lodash/isEmpty');
require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/helpers/defineProperty');
require('lodash/mergeWith');
require('../../config-provider/context.js');
require('lodash/merge');
require('../../_common/js/global-config/default-config.js');
require('../../_common/js/global-config/locale/zh_CN.js');
require('../../loading/loading.js');
require('../../loading/icon/gradient.js');
require('../../_common/js/loading/circle-adapter.js');
require('../../_common/js/utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../utils/easing.js');
require('../../utils/render-tnode.js');
require('lodash/isObject');
require('../../utils/transfer-dom.js');
require('../../loading/props.js');
require('../../utils/withInstall.js');
require('lodash/capitalize');
require('../../loading/plugin.js');
require('../../checkbox/group.js');
require('lodash/intersection');
require('../../checkbox/checkbox.js');
require('../../checkbox/props.js');
require('../../utils/helper.js');
require('lodash/camelCase');
require('../../utils/event.js');
require('../../checkbox/checkbox-group-props.js');
require('../../utils/map-props.js');
require('../../tooltip/tooltip.js');
require('../../tooltip/props.js');
require('../../popup/props.js');
require('../../popup/popup.js');
require('@popperjs/core');
require('../../popup/container.js');

var name = "".concat(config.prefix, "-cascader-item");
var ComponentClassName = "".concat(config.prefix, "-cascader__item");
var keepAnimationMixins = configProvider_configReceiver.getKeepAnimationMixins();
var Item = utils_mixins["default"](keepAnimationMixins).extend({
  name: name,
  directives: {
    ripple: utils_ripple["default"]
  },
  components: {
    Tooltip: tooltip_index.Tooltip
  },
  props: {
    node: {
      type: Object,
      "default": function _default() {
        return {};
      }
    },
    cascaderContext: {
      type: Object
    }
  },
  computed: {
    itemClass: function itemClass() {
      return cascader_utils_item.getCascaderItemClass(config.prefix, this.node, utils_classnames["default"], this.cascaderContext);
    },
    iconClass: function iconClass() {
      return cascader_utils_item.getCascaderItemIconClass(config.prefix, this.node, utils_classnames["default"], 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 ? cascader_utils_helper.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 = cascader_utils_item.getLabelIsEllipsis(node2, cascaderContext2.size);
      var labelNode = h("span", {
        "class": ["".concat(ComponentClassName, "-label")],
        "attrs": {
          "role": "label"
        }
      }, [label]);

      if (isEllipsis) {
        return h(tooltip_index.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_index.Checkbox, helper.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_index.Loading, {
      "class": iconClass,
      "attrs": {
        "size": "small"
      }
    }) : h(tdesignIconsVue.ChevronRightIcon, {
      "class": iconClass
    }))]);
  }
});

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