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

import _typeof from '@babel/runtime/helpers/typeof';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, computed } from '@vue/composition-api';
import omit from 'lodash/omit';
import { SelectInput } from '../select-input/index.js';
import FakeArrow from '../common-components/fake-arrow.js';
import { usePrefixClass, useCommonClassName } from '../hooks/useConfig.js';
import useFormDisabled from '../hooks/useFormDisabled.js';
import { renderTNodeJSX } from '../utils/render-tnode.js';
import props from './props.js';
import { useCascaderContext } from './hooks.js';
import { handleRemoveTagEffect, closeIconClickEffect } from './core/effect.js';
import { getMultipleContent, getSingleContent, getPanels } from './core/helper.js';
import { getFakeArrowIconClass } from './core/className.js';
import Panel from './components/Panel.js';
import { useConfig } from '../config-provider/useConfig.js';
import '../utils/withInstall.js';
import 'vue';
import 'lodash/capitalize';
import '../select-input/select-input.js';
import '../_chunks/dep-c89aafbb.js';
import '../popup/index.js';
import '../utils/map-props.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '../popup/popup.js';
import '@popperjs/core';
import '../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../utils/easing.js';
import '../utils/helper.js';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/camelCase';
import '../_common/js/utils/set-style.js';
import '../config-provider/config-receiver.js';
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 '../_chunks/dep-be599ec8.js';
import 'dayjs';
import '../_chunks/dep-67ff4010.js';
import '../config-provider/type.js';
import '../utils/mixins.js';
import '../utils/event.js';
import '../popup/props.js';
import '../popup/container.js';
import 'lodash/isFunction';
import '../popup/utils.js';
import '../popup/trigger.js';
import '../popup/style/css.js';
import '../popup/type.js';
import '../popup/plugin.js';
import 'lodash/kebabCase';
import '../select-input/props.js';
import '../select-input/useSingle.js';
import 'lodash/isObject';
import 'lodash/pick';
import '../input/index.js';
import '../input/input.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@ldesign/icons-vue';
import '../_common/js/utils/helper.js';
import 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';
import 'lodash/isArray';
import '../_common/js/log/index.js';
import '../_common/js/log/log.js';
import '../input/props.js';
import '../input/input-group.js';
import '../input/style/css.js';
import '../input/type.js';
import '../loading/index.js';
import '../loading/directive.js';
import 'lodash/mapKeys';
import 'lodash/isEqual';
import '../loading/plugin.js';
import '../config.js';
import '../loading/loading.js';
import '../utils/transfer-dom.js';
import '../loading/props.js';
import '../loading/icon/gradient.js';
import '../_common/js/loading/circle-adapter.js';
import '../loading/style/css.js';
import '../loading/type.js';
import '../hooks/tnode.js';
import 'lodash/isEmpty';
import '../hooks/render-tnode.js';
import '../hooks/useDefaultValue.js';
import '../select-input/useMultiple.js';
import '../tag-input/index.js';
import '../tag-input/tag-input.js';
import '../hooks/useGlobalIcon.js';
import '../tag-input/props.js';
import '../tag-input/hooks/useTagScroll.js';
import '../tag-input/useTagList.js';
import '../tag/index.js';
import '../tag/tag.js';
import '../tag/props.js';
import '../tag/check-tag.js';
import '../tag/check-tag-props.js';
import '../tag/style/css.js';
import '../tag/type.js';
import '../hooks/useVModel.js';
import '../tag-input/hooks/useHover.js';
import '../tag-input/hooks/useDragSorter.js';
import '../tag-input/style/css.js';
import '../tag-input/type.js';
import '../tag-input/interface.js';
import '../select-input/useOverlayInnerStyle.js';
import '../select-input/style/css.js';
import '../select-input/type.js';
import '../_common/js/tree/tree-store.js';
import '@babel/runtime/helpers/classCallCheck';
import '@babel/runtime/helpers/createClass';
import 'lodash/difference';
import 'lodash/isPlainObject';
import 'mitt';
import '../_common/js/tree/tree-node.js';
import '@babel/runtime/helpers/asyncToGenerator';
import '@babel/runtime/regenerator';
import 'lodash/uniqueId';
import 'lodash/isNil';
import 'lodash/get';
import '../_common/js/tree/tree-node-model.js';
import 'lodash/isBoolean';
import 'lodash/cloneDeep';
import './components/Item.js';
import '../checkbox/index.js';
import '../checkbox/group.js';
import 'lodash/intersection';
import '../checkbox/checkbox.js';
import '../checkbox/props.js';
import '../checkbox/checkbox-group-props.js';
import '../checkbox/style/css.js';
import '../checkbox/type.js';
import '../utils/ripple.js';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var DEFAULT_KEYS = {
  label: "label",
  value: "value",
  children: "children"
};
var _Cascader = defineComponent({
  name: "TCascader",
  props: _objectSpread({}, props),
  setup: function setup(props2, _ref) {
    var emit = _ref.emit;
    var COMPONENT_NAME = usePrefixClass("cascader");
    var classPrefix = usePrefixClass();
    var _useCommonClassName = useCommonClassName(),
      STATUS = _useCommonClassName.STATUS;
    var overlayClassName = usePrefixClass("cascader__popup");
    var _useConfig = useConfig("cascader"),
      global = _useConfig.global;
    var _useCascaderContext = useCascaderContext(props2),
      innerValue = _useCascaderContext.innerValue,
      cascaderContext = _useCascaderContext.cascaderContext,
      isFilterable = _useCascaderContext.isFilterable;
    var displayValue = computed(function () {
      return props2.multiple ? getMultipleContent(cascaderContext.value) : getSingleContent(cascaderContext.value);
    });
    var panels = computed(function () {
      return getPanels(cascaderContext.value.treeNodes);
    });
    var inputPlaceholder = computed(function () {
      var _props2$placeholder;
      return cascaderContext.value.visible && !props2.multiple && getSingleContent(cascaderContext.value) || ((_props2$placeholder = props2.placeholder) !== null && _props2$placeholder !== void 0 ? _props2$placeholder : global.value.placeholder);
    });
    var _useFormDisabled = useFormDisabled(),
      formDisabled = _useFormDisabled.formDisabled;
    var isDisabled = computed(function () {
      return formDisabled.value || cascaderContext.value.disabled;
    });
    return {
      COMPONENT_NAME: COMPONENT_NAME,
      overlayClassName: overlayClassName,
      panels: panels,
      innerValue: innerValue,
      displayValue: displayValue,
      inputPlaceholder: inputPlaceholder,
      isFilterable: isFilterable,
      isDisabled: isDisabled,
      STATUS: STATUS,
      classPrefix: classPrefix,
      cascaderContext: cascaderContext,
      emit: emit
    };
  },
  render: function render() {
    var _this = this,
      _this$popupProps;
    var h = arguments[0];
    var COMPONENT_NAME = this.COMPONENT_NAME,
      overlayClassName = this.overlayClassName,
      panels = this.panels,
      displayValue = this.displayValue,
      inputPlaceholder = this.inputPlaceholder,
      isFilterable = this.isFilterable,
      isDisabled = this.isDisabled,
      STATUS = this.STATUS,
      classPrefix = this.classPrefix,
      cascaderContext = this.cascaderContext,
      emit = this.emit;
    var renderSuffixIcon = function renderSuffixIcon() {
      var suffixIcon = renderTNodeJSX(_this, "suffixIcon");
      if (suffixIcon) return suffixIcon;
      var visible2 = cascaderContext.visible;
      return h(FakeArrow, {
        "attrs": {
          "overlayClassName": getFakeArrowIconClass(classPrefix, STATUS, cascaderContext),
          "isActive": visible2,
          "disabled": isDisabled
        }
      });
    };
    var renderCollapsedItems = function renderCollapsedItems() {
      var cascaderValue = _this.innerValue || [];
      var keys = _this.keys || DEFAULT_KEYS;
      var value = Array.isArray(cascaderValue) ? cascaderValue : [cascaderValue];
      var cascaderOptions = value.map(function (item) {
        var tmpValue = _typeof(item) === "object" ? item[keys.value] : item;
        return cascaderContext.treeStore.getNode(tmpValue).data;
      });
      return renderTNodeJSX(_this, "collapsedItems", {
        params: {
          value: cascaderOptions,
          collapsedSelectedItems: cascaderOptions.slice(0, _this.minCollapsedNum),
          count: value.length - _this.minCollapsedNum
        }
      });
    };
    var setVisible = cascaderContext.setVisible,
      visible = cascaderContext.visible,
      inputVal = cascaderContext.inputVal,
      setInputVal = cascaderContext.setInputVal;
    var slots = this.$scopedSlots;
    return h(SelectInput, {
      "class": COMPONENT_NAME,
      "props": _objectSpread({}, _objectSpread({
        value: displayValue,
        inputValue: visible ? inputVal : "",
        popupVisible: visible,
        keys: this.keys,
        allowInput: isFilterable,
        minCollapsedNum: this.minCollapsedNum,
        collapsedItems: renderCollapsedItems,
        label: this.label,
        suffix: this.suffix,
        tag: this.tag,
        readonly: this.readonly,
        disabled: isDisabled,
        clearable: this.clearable,
        placeholder: inputPlaceholder,
        multiple: this.multiple,
        loading: this.loading,
        status: this.status,
        tips: this.tips,
        suffixIcon: function suffixIcon() {
          return renderSuffixIcon();
        },
        popupProps: _objectSpread(_objectSpread({}, this.popupProps), {}, {
          overlayInnerStyle: panels.length && !this.loading ? {
            width: "auto"
          } : "",
          overlayClassName: [overlayClassName, (_this$popupProps = this.popupProps) === null || _this$popupProps === void 0 ? void 0 : _this$popupProps.overlayClassName]
        }),
        inputProps: _objectSpread({
          size: this.size
        }, this.inputProps),
        tagInputProps: _objectSpread({
          size: this.size
        }, this.tagInputProps),
        tagProps: _objectSpread({}, this.tagProps),
        onInputChange: function onInputChange(value, ctx) {
          var _this$selectInputProp, _this$selectInputProp2;
          if (!_this.isFilterable) return;
          setInputVal("".concat(value));
          _this === null || _this === void 0 ? void 0 : (_this$selectInputProp = _this.selectInputProps) === null || _this$selectInputProp === void 0 ? void 0 : (_this$selectInputProp2 = _this$selectInputProp.onInputChange) === null || _this$selectInputProp2 === void 0 ? void 0 : _this$selectInputProp2.call(_this$selectInputProp, value, ctx);
        },
        onTagChange: function onTagChange(val, ctx) {
          var _this$selectInputProp3, _this$selectInputProp4;
          if (ctx.trigger === "enter") return;
          handleRemoveTagEffect(cascaderContext, ctx.index, _this.onRemove);
          (_this$selectInputProp3 = _this.selectInputProps) === null || _this$selectInputProp3 === void 0 ? void 0 : (_this$selectInputProp4 = _this$selectInputProp3.onTagChange) === null || _this$selectInputProp4 === void 0 ? void 0 : _this$selectInputProp4.call(_this$selectInputProp3, val, ctx);
        },
        onPopupVisibleChange: function onPopupVisibleChange(val, context) {
          var _this$selectInputProp5, _this$selectInputProp6;
          if (_this.disabled) return;
          setVisible(val, context);
          (_this$selectInputProp5 = _this.selectInputProps) === null || _this$selectInputProp5 === void 0 ? void 0 : (_this$selectInputProp6 = _this$selectInputProp5.onPopupVisibleChange) === null || _this$selectInputProp6 === void 0 ? void 0 : _this$selectInputProp6.call(_this$selectInputProp5, val, context);
        },
        onBlur: function onBlur(val, context) {
          var _this$onBlur, _this$selectInputProp7, _this$selectInputProp8;
          var ctx = {
            value: cascaderContext.value,
            e: context.e
          };
          (_this$onBlur = _this.onBlur) === null || _this$onBlur === void 0 ? void 0 : _this$onBlur.call(_this, ctx);
          emit("blur", ctx);
          (_this$selectInputProp7 = _this.selectInputProps) === null || _this$selectInputProp7 === void 0 ? void 0 : (_this$selectInputProp8 = _this$selectInputProp7.onBlur) === null || _this$selectInputProp8 === void 0 ? void 0 : _this$selectInputProp8.call(_this$selectInputProp7, val, context);
        },
        onFocus: function onFocus(val, context) {
          var _this$onFocus, _this$selectInputProp9, _this$selectInputProp10;
          var ctx = {
            value: cascaderContext.value,
            e: context.e
          };
          (_this$onFocus = _this.onFocus) === null || _this$onFocus === void 0 ? void 0 : _this$onFocus.call(_this, ctx);
          emit("focus", ctx);
          (_this$selectInputProp9 = _this.selectInputProps) === null || _this$selectInputProp9 === void 0 ? void 0 : (_this$selectInputProp10 = _this$selectInputProp9.onFocus) === null || _this$selectInputProp10 === void 0 ? void 0 : _this$selectInputProp10.call(_this$selectInputProp9, val, context);
        },
        onClear: function onClear(context) {
          var _this$selectInputProp11, _this$selectInputProp12;
          closeIconClickEffect(cascaderContext);
          (_this$selectInputProp11 = _this.selectInputProps) === null || _this$selectInputProp11 === void 0 ? void 0 : (_this$selectInputProp12 = _this$selectInputProp11.onClear) === null || _this$selectInputProp12 === void 0 ? void 0 : _this$selectInputProp12.call(_this$selectInputProp11, context);
        }
      }, omit(this.selectInputProps, ["onTagChange", "onInputChange", "onPopupVisibleChange", "onBlur", "onFocus", "onClear"]))),
      "scopedSlots": {
        panel: function panel() {
          return h(Panel, {
            "attrs": {
              "empty": _this.empty,
              "trigger": _this.trigger,
              "loading": _this.loading,
              "loadingText": _this.loadingText,
              "cascaderContext": cascaderContext
            },
            "scopedSlots": {
              empty: slots.empty,
              loadingText: slots.loadingText
            }
          });
        },
        tips: slots.tips,
        tag: slots.tag,
        suffix: slots.suffix
      }
    });
  }
});

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