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

import { h as helper } from '../../_chunks/dep-1ec74b8b.js';
import isFunction from 'lodash/isFunction';
import { CloseCircleFilledIcon } from 'tdesign-icons-vue';
import { prefix } from '../../config.js';
import ClASSNAMES from '../../utils/classnames.js';
import getConfigReceiverMixins from '../../config-provider/config-receiver.js';
import mixins from '../../utils/mixins.js';
import { renderTNodeJSX } from '../../utils/render-tnode.js';
import { Tag } from '../../tag/index.js';
import { Loading } from '../../loading/index.js';
import { Input } from '../../input/index.js';
import FakeArrow from '../../common-components/fake-arrow.js';
import { getCloseIconClass, getFakeArrowIconClass, getCascaderInnerClasses, getCloseShow, getSingleContent, getMultipleContent, getPlaceholderShow, outerClickListenerEffect, handleRemoveTagEffect, closeIconClickEffect, innerContentClickEffect } from '../utils/inputContent.js';
import { getFullPathLabel } from '../utils/helper.js';
import props from '../props.js';
import '@babel/runtime/helpers/defineProperty';
import 'vue';
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 '@babel/runtime/helpers/typeof';
import 'lodash/isObject';
import '../../tag/tag.js';
import '../../tag/props.js';
import '../../utils/event.js';
import '../../utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/camelCase';
import '../../tag/check-tag.js';
import '../../tag/check-tag-props.js';
import '../../utils/withInstall.js';
import 'lodash/capitalize';
import '../../utils/map-props.js';
import './style/index.js';
import '../../tag/type.js';
import '../../loading/loading.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 '../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../utils/easing.js';
import '../../utils/transfer-dom.js';
import '../../loading/props.js';
import '../../loading/type.js';
import '../../loading/plugin.js';
import '../../input/addon.js';
import '../../input/input.js';
import '@babel/runtime/helpers/toConsumableArray';
import 'lodash/kebabCase';
import '../../input/props.js';
import '../../input/input-group.js';
import '../../input/type.js';
import 'lodash/isEmpty';

var name = "".concat(prefix, "-cascader");
var cascaderGglobalConfig = getConfigReceiverMixins("cascader");
var InputContent = mixins(cascaderGglobalConfig).extend({
  name: "".concat(name, "-input-content"),
  props: {
    cascaderContext: {
      type: Object
    },
    placeholder: props.placeholder,
    listeners: {
      type: Object
    },
    collapsedItems: props.collapsedItems
  },
  components: {
    Tag: Tag,
    Input: Input,
    CloseCircleFilledIcon: CloseCircleFilledIcon
  },
  data: function data() {
    return {
      isHover: false
    };
  },
  computed: {
    closeIconClass: function closeIconClass() {
      return getCloseIconClass(prefix, ClASSNAMES, this.cascaderContext);
    },
    fakeArrowIconClass: function fakeArrowIconClass() {
      return getFakeArrowIconClass(prefix, ClASSNAMES, this.cascaderContext);
    },
    cascaderInnerClasses: function cascaderInnerClasses() {
      return getCascaderInnerClasses(prefix, ClASSNAMES, this.cascaderContext);
    },
    closeShow: function closeShow() {
      return getCloseShow(this.isHover, this.cascaderContext);
    },
    singleContent: function singleContent() {
      return getSingleContent(this.cascaderContext);
    },
    multipleContent: function multipleContent() {
      return getMultipleContent(this.cascaderContext);
    },
    showPlaceholder: function showPlaceholder() {
      return getPlaceholderShow(this.cascaderContext, this.singleContent, this.multipleContent);
    }
  },
  mounted: function mounted() {
    var _this = this;

    document.addEventListener("click", function (event) {
      _this.outerClickListenerFn(event);
    });
    setTimeout(function () {
      _this.getInputWidth();
    });
  },
  beforeDestroy: function beforeDestroy() {
    var _this2 = this;

    document.removeEventListener("click", function (event) {
      _this2.outerClickListenerFn(event);
    });
  },
  inject: {
    tCascader: {
      "default": void 0
    }
  },
  methods: {
    getInputWidth: function getInputWidth() {
      var _this$$refs$inputCont = this.$refs.inputContent.getBoundingClientRect(),
          width = _this$$refs$inputCont.width;

      var setInputWidth = this.cascaderContext.setInputWidth;
      setInputWidth(width);
    },
    outerClickListenerFn: function outerClickListenerFn(event) {
      return outerClickListenerEffect(this.$refs.inputContent, this.cascaderContext, event);
    },
    renderContent: function renderContent() {
      var h = this.$createElement;
      var placeholder = this.placeholder,
          showPlaceholder = this.showPlaceholder;
      var content = !showPlaceholder ? this.InnerContent() : h("span", {
        "class": "".concat(prefix, "-cascader__placeholder")
      }, [placeholder || this.t(this.global.placeholder)]);
      return content;
    },
    InnerContent: function InnerContent() {
      var _this3 = this;

      var h = this.$createElement;
      var cascaderContext = this.cascaderContext,
          placeholder = this.placeholder,
          singleContent = this.singleContent,
          multipleContent = this.multipleContent,
          listeners = this.listeners,
          collapsedItems = this.collapsedItems;
      var multiple = cascaderContext.multiple,
          size = cascaderContext.size,
          disabled = cascaderContext.disabled,
          filterable = cascaderContext.filterable,
          setFilterActive = cascaderContext.setFilterActive,
          visible = cascaderContext.visible,
          inputVal = cascaderContext.inputVal,
          setInputVal = cascaderContext.setInputVal,
          minCollapsedNum = cascaderContext.minCollapsedNum,
          value = cascaderContext.value,
          showAllLevels = cascaderContext.showAllLevels;
      var onFocus = listeners.onFocus,
          onBlur = listeners.onBlur,
          onRemove = listeners.onRemove;

      var renderSelfTag = function renderSelfTag(node, index) {
        return h(Tag, {
          "attrs": {
            "closable": !disabled,
            "disabled": disabled,
            "size": size
          },
          "key": index,
          "on": {
            "close": function close(ctx) {
              ctx.e.stopPropagation();
              handleRemoveTagEffect(cascaderContext, node, onRemove);
            }
          }
        }, [showAllLevels ? getFullPathLabel(node) : node.label]);
      };

      var renderCollItems = function renderCollItems() {
        var tempList = [];
        multipleContent.forEach(function (node) {
          tempList.push(node.data);
        });
        return tempList;
      };

      var generalContent = !multiple ? h("span", {
        "class": "".concat(prefix, "-cascader__content")
      }, [singleContent]) : h("span", [minCollapsedNum > 0 && multipleContent.length > minCollapsedNum ? h("span", [multipleContent.slice(0, minCollapsedNum).map(function (node, index) {
        return renderSelfTag(node, index);
      }), collapsedItems || this.$scopedSlots.collapsedItems ? renderTNodeJSX(this, "collapsedItems", {
        params: {
          value: renderCollItems(),
          collapsedSelectedItems: renderCollItems().slice(minCollapsedNum),
          count: renderCollItems().length - minCollapsedNum
        }
      }) : h(Tag, {
        "attrs": {
          "size": size,
          "disabled": disabled
        }
      }, ["+", multipleContent.length - minCollapsedNum])]) : multipleContent.map(function (node, index) {
        return renderSelfTag(node, index);
      })]);
      var inputPlaceholder = multiple ? multipleContent.map(function (node) {
        return node.label;
      }).join("\u3001") : singleContent;

      var filterContent = function filterContent() {
        return h(Input, {
          "attrs": {
            "size": size,
            "placeholder": inputPlaceholder || placeholder || _this3.t(_this3.global.placeholder),
            "value": inputVal,
            "autofocus": visible
          },
          "on": {
            "change": function change(value2) {
              setInputVal(value2);
              setFilterActive(!!value2);
            },
            "focus": function focus(v, context) {
              return isFunction(onFocus) && onFocus({
                value: value,
                e: context === null || context === void 0 ? void 0 : context.e
              });
            },
            "blur": function blur(v, context) {
              return isFunction(onBlur) && onBlur({
                value: value,
                e: context === null || context === void 0 ? void 0 : context.e
              });
            }
          }
        });
      };

      return filterable && visible ? filterContent() : generalContent;
    },
    renderSuffixIcon: function renderSuffixIcon() {
      var _this4 = this;

      var h = this.$createElement;
      var closeShow = this.closeShow,
          closeIconClass = this.closeIconClass,
          fakeArrowIconClass = this.fakeArrowIconClass,
          _this$cascaderContext = this.cascaderContext,
          size = _this$cascaderContext.size,
          visible = _this$cascaderContext.visible,
          disabled = _this$cascaderContext.disabled,
          loading = _this$cascaderContext.loading;

      var closeIconClick = function closeIconClick(context) {
        context.e.stopPropagation();
        closeIconClickEffect(_this4.cascaderContext);
      };

      if (loading) {
        return h("span", {
          "class": "".concat(prefix, "-cascader-icon")
        }, [h(Loading, {
          "attrs": {
            "size": "small"
          }
        })]);
      }

      if (closeShow) {
        return h("transition", {
          "attrs": {
            "name": "".concat(prefix, "-cascader-close-icon-fade"),
            "appear": true
          }
        }, [h(CloseCircleFilledIcon, {
          "class": closeIconClass,
          "attrs": {
            "size": size
          },
          "on": {
            "click": closeIconClick
          }
        })]);
      }

      return h(FakeArrow, {
        "attrs": {
          "overlayClassName": fakeArrowIconClass,
          "isActive": visible,
          "disabled": disabled
        }
      });
    }
  },
  render: function render() {
    var _this5 = this;

    var h = arguments[0];
    var $attrs = this.$attrs,
        cascaderContext = this.cascaderContext;
    return h("div", helper([{
      "ref": "inputContent",
      "class": this.cascaderInnerClasses
    }, $attrs, {
      "on": {
        "mouseenter": function mouseenter() {
          _this5.isHover = true;
        },
        "mouseleave": function mouseleave() {
          _this5.isHover = false;
        },
        "click": function click(e) {
          e.preventDefault();
          innerContentClickEffect(cascaderContext);
        }
      }
    }]), [this.renderContent(), this.renderSuffixIcon()]);
  }
});

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