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

'use strict';

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

var helper = require('../../_chunks/dep-99705d51.js');
var isFunction = require('lodash/isFunction');
var tdesignIconsVue = require('tdesign-icons-vue');
var config = require('../../config.js');
var utils_classnames = require('../../utils/classnames.js');
var configProvider_configReceiver = require('../../config-provider/config-receiver.js');
var utils_mixins = require('../../utils/mixins.js');
var utils_renderTnode = require('../../utils/render-tnode.js');
var tag_index = require('../../tag/index.js');
var loading_index = require('../../loading/index.js');
var input_index = require('../../input/index.js');
var commonComponents_fakeArrow = require('../../common-components/fake-arrow.js');
var cascader_utils_inputContent = require('../utils/inputContent.js');
var cascader_utils_helper = require('../utils/helper.js');
var cascader_props = require('../props.js');
require('@babel/runtime/helpers/defineProperty');
require('vue');
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('@babel/runtime/helpers/typeof');
require('../../tag/tag.js');
require('../../tag/props.js');
require('../../utils/event.js');
require('../../utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/camelCase');
require('../../tag/check-tag.js');
require('../../tag/check-tag-props.js');
require('../../utils/withInstall.js');
require('lodash/capitalize');
require('../../utils/map-props.js');
require('../../loading/loading.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('../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../utils/easing.js');
require('../../utils/transfer-dom.js');
require('../../loading/props.js');
require('../../loading/plugin.js');
require('../../input/addon.js');
require('../../input/input.js');
require('@babel/runtime/helpers/toConsumableArray');
require('lodash/kebabCase');
require('../../input/props.js');
require('../../input/input-group.js');
require('lodash/isEmpty');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var isFunction__default = /*#__PURE__*/_interopDefaultLegacy(isFunction);

var name = "".concat(config.prefix, "-cascader");
var cascaderGlobalConfig = configProvider_configReceiver["default"]("cascader");
var InputContent = utils_mixins["default"](cascaderGlobalConfig).extend({
  name: "".concat(name, "-input-content"),
  props: {
    cascaderContext: {
      type: Object
    },
    placeholder: cascader_props["default"].placeholder,
    listeners: {
      type: Object
    },
    collapsedItems: cascader_props["default"].collapsedItems
  },
  components: {
    Tag: tag_index.Tag,
    Input: input_index.Input,
    CloseCircleFilledIcon: tdesignIconsVue.CloseCircleFilledIcon
  },
  data: function data() {
    return {
      isHover: false
    };
  },
  computed: {
    closeIconClass: function closeIconClass() {
      return cascader_utils_inputContent.getCloseIconClass(config.prefix, utils_classnames["default"], this.cascaderContext);
    },
    fakeArrowIconClass: function fakeArrowIconClass() {
      return cascader_utils_inputContent.getFakeArrowIconClass(config.prefix, utils_classnames["default"], this.cascaderContext);
    },
    cascaderInnerClasses: function cascaderInnerClasses() {
      return cascader_utils_inputContent.getCascaderInnerClasses(config.prefix, utils_classnames["default"], this.cascaderContext);
    },
    closeShow: function closeShow() {
      return cascader_utils_inputContent.getCloseShow(this.isHover, this.cascaderContext);
    },
    singleContent: function singleContent() {
      return cascader_utils_inputContent.getSingleContent(this.cascaderContext);
    },
    multipleContent: function multipleContent() {
      return cascader_utils_inputContent.getMultipleContent(this.cascaderContext);
    },
    showPlaceholder: function showPlaceholder() {
      return cascader_utils_inputContent.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 cascader_utils_inputContent.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(config.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_index.Tag, {
          "attrs": {
            "closable": !disabled,
            "disabled": disabled,
            "size": size
          },
          "key": index,
          "on": {
            "close": function close(ctx) {
              ctx.e.stopPropagation();
              cascader_utils_inputContent.handleRemoveTagEffect(cascaderContext, node, onRemove);
            }
          }
        }, [showAllLevels ? cascader_utils_helper.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(config.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 ? utils_renderTnode.renderTNodeJSX(this, "collapsedItems", {
        params: {
          value: renderCollItems(),
          collapsedSelectedItems: renderCollItems().slice(minCollapsedNum),
          count: renderCollItems().length - minCollapsedNum
        }
      }) : h(tag_index.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_index.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__default["default"](onFocus) && onFocus({
                value: value,
                e: context === null || context === void 0 ? void 0 : context.e
              });
            },
            "blur": function blur(v, context) {
              return isFunction__default["default"](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();
        cascader_utils_inputContent.closeIconClickEffect(_this4.cascaderContext);
      };

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

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

      return h(commonComponents_fakeArrow["default"], {
        "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.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.stopPropagation();
          cascader_utils_inputContent.innerContentClickEffect(cascaderContext);
        }
      }
    }]), [this.renderContent(), this.renderSuffixIcon()]);
  }
});

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