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

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, computed, createVNode, mergeProps } from 'vue';
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 '../form/hooks.js';
import Panel from './components/Panel.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 { useConfig } from '../config-provider/useConfig.js';
import '../utils/withInstall.js';
import '../select-input/select-input.js';
import '../popup/index.js';
import '../popup/popup.js';
import '@babel/runtime/helpers/slicedToArray';
import '@popperjs/core';
import 'lodash/isString';
import 'lodash/isFunction';
import 'lodash/isObject';
import '../utils/dom.js';
import '../_chunks/dep-512eb181.js';
import 'lodash/isArray';
import '../utils/easing.js';
import '../utils/render-tnode.js';
import 'lodash/isEmpty';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../_common/js/utils/set-style.js';
import '../hooks/useVModel.js';
import '../popup/props.js';
import '../popup/container.js';
import '@babel/runtime/helpers/toConsumableArray';
import 'lodash/isUndefined';
import '../hooks/useResizeObserver.js';
import '../popup/style';
import '../popup/type.js';
import 'lodash/cloneDeep';
import '../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '@babel/runtime/helpers/typeof';
import 'dayjs';
import '../_chunks/dep-ac28b67c.js';
import '../config-provider/type.js';
import '../hooks/index.js';
import '../hooks/icon.js';
import '../hooks/slot.js';
import '../hooks/tnode.js';
import '../hooks/useCommonClassName.js';
import '../hooks/useDefaultValue.js';
import '../hooks/useDestroyOnClose.js';
import '../hooks/useKeepAnimation.js';
import '../hooks/useRipple.js';
import '../utils/set-style.js';
import '../hooks/useVirtualScroll.js';
import '../select-input/props.js';
import '../select-input/useSingle.js';
import 'lodash/pick';
import '../input/index.js';
import '../input/input.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@ldesign/icons-vue-next';
import '../hooks/useGlobalIcon.js';
import '../input/props.js';
import '../input/useInput.js';
import '../form/const.js';
import '../input/useLengthLimit.js';
import 'lodash/isNumber';
import '../_common/js/log/index.js';
import '../_common/js/log/log.js';
import '../_common/js/utils/helper.js';
import 'lodash/isNull';
import '../input/useInputEventHandler.js';
import '../input/useInputWidth.js';
import '../input/input-group.js';
import '../input/input-group-props.js';
import '../input/style';
import '../input/type.js';
import '../loading/index.js';
import '../loading/directive.js';
import '../loading/plugin.js';
import '../loading/loading.js';
import '../hooks/useTeleport.js';
import '../loading/props.js';
import '../loading/icon/gradient.js';
import '../_common/js/loading/circle-adapter.js';
import '../loading/style';
import '../loading/type.js';
import '../select-input/useMultiple.js';
import '../tag-input/index.js';
import '../tag-input/tag-input.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';
import '../tag/type.js';
import '../tag-input/hooks/useHover.js';
import '../tag-input/hooks/useDragSorter.js';
import '../tag-input/style';
import '../tag-input/type.js';
import '../select-input/useOverlayInnerStyle.js';
import '../select-input/style';
import '../select-input/type.js';
import './components/Item.js';
import '../checkbox/index.js';
import '../checkbox/checkbox.js';
import '../checkbox/props.js';
import '../checkbox/constants.js';
import '../checkbox/group.js';
import 'lodash/intersection';
import '../checkbox/checkbox-group-props.js';
import '../checkbox/style';
import '../checkbox/type.js';
import 'lodash/isEqual';
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';

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 _Cascader = defineComponent({
  name: "TCascader",
  props: _objectSpread({}, props),
  setup: function setup(props2, _ref) {
    var slots = _ref.slots;
    var disabled = useFormDisabled();
    var COMPONENT_NAME = usePrefixClass("cascader");
    var classPrefix = usePrefixClass();
    var _useCommonClassName = useCommonClassName(),
      STATUS = _useCommonClassName.STATUS;
    var overlayClassName = usePrefixClass("cascader__popup");
    var _useConfig = useConfig("cascader"),
      globalConfig = _useConfig.globalConfig;
    var _useCascaderContext = useCascaderContext(props2),
      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 : globalConfig.value.placeholder);
    });
    var renderSuffixIcon = function renderSuffixIcon() {
      var _cascaderContext$valu = cascaderContext.value,
        visible = _cascaderContext$valu.visible,
        disabled2 = _cascaderContext$valu.disabled;
      return createVNode(FakeArrow, {
        "overlayClassName": getFakeArrowIconClass(classPrefix.value, STATUS.value, cascaderContext.value),
        "isActive": visible,
        "disabled": disabled2
      }, null);
    };
    return function () {
      var _props2$popupProps;
      var _cascaderContext$valu2 = cascaderContext.value,
        setVisible = _cascaderContext$valu2.setVisible,
        visible = _cascaderContext$valu2.visible,
        inputVal = _cascaderContext$valu2.inputVal,
        setInputVal = _cascaderContext$valu2.setInputVal;
      return createVNode(SelectInput, mergeProps({
        "class": COMPONENT_NAME.value,
        "value": displayValue.value,
        "inputValue": visible ? inputVal : "",
        "popupVisible": visible,
        "keys": props2.keys,
        "allowInput": isFilterable.value,
        "min-collapsed-num": props2.minCollapsedNum,
        "collapsed-items": props2.collapsedItems,
        "readonly": props2.readonly,
        "disabled": props2.disabled,
        "clearable": props2.clearable,
        "placeholder": inputPlaceholder.value,
        "multiple": props2.multiple,
        "loading": props2.loading,
        "status": props2.status,
        "tips": props2.tips,
        "suffixIcon": function suffixIcon() {
          return renderSuffixIcon();
        },
        "popupProps": _objectSpread(_objectSpread({}, props2.popupProps), {}, {
          overlayInnerStyle: panels.value.length && !props2.loading ? {
            width: "auto"
          } : "",
          overlayClassName: [overlayClassName.value, (_props2$popupProps = props2.popupProps) === null || _props2$popupProps === void 0 ? void 0 : _props2$popupProps.overlayClassName]
        }),
        "inputProps": _objectSpread({
          size: props2.size
        }, props2.inputProps),
        "tagInputProps": _objectSpread({
          size: props2.size
        }, props2.tagInputProps),
        "tagProps": _objectSpread({}, props2.tagProps),
        "onInputChange": function onInputChange(value, ctx) {
          var _props2$selectInputPr, _props2$selectInputPr2;
          if (!isFilterable.value) return;
          setInputVal("".concat(value));
          props2 === null || props2 === void 0 ? void 0 : (_props2$selectInputPr = props2.selectInputProps) === null || _props2$selectInputPr === void 0 ? void 0 : (_props2$selectInputPr2 = _props2$selectInputPr.onInputChange) === null || _props2$selectInputPr2 === void 0 ? void 0 : _props2$selectInputPr2.call(_props2$selectInputPr, value, ctx);
        },
        "onTagChange": function onTagChange(val, ctx) {
          var _props2$selectInputPr3, _props2$selectInputPr4;
          if (ctx.trigger === "enter") return;
          handleRemoveTagEffect(cascaderContext.value, ctx.index, props2.onRemove);
          props2 === null || props2 === void 0 ? void 0 : (_props2$selectInputPr3 = props2.selectInputProps) === null || _props2$selectInputPr3 === void 0 ? void 0 : (_props2$selectInputPr4 = _props2$selectInputPr3.onTagChange) === null || _props2$selectInputPr4 === void 0 ? void 0 : _props2$selectInputPr4.call(_props2$selectInputPr3, val, ctx);
        },
        "onPopupVisibleChange": function onPopupVisibleChange(val, context) {
          var _props2$selectInputPr5, _props2$selectInputPr6;
          if (disabled.value) return;
          setVisible(val, context);
          props2 === null || props2 === void 0 ? void 0 : (_props2$selectInputPr5 = props2.selectInputProps) === null || _props2$selectInputPr5 === void 0 ? void 0 : (_props2$selectInputPr6 = _props2$selectInputPr5.onPopupVisibleChange) === null || _props2$selectInputPr6 === void 0 ? void 0 : _props2$selectInputPr6.call(_props2$selectInputPr5, val, context);
        },
        "onBlur": function onBlur(val, context) {
          var _props2$onBlur, _props2$selectInputPr7, _props2$selectInputPr8;
          (_props2$onBlur = props2.onBlur) === null || _props2$onBlur === void 0 ? void 0 : _props2$onBlur.call(props2, {
            value: cascaderContext.value.value,
            e: context.e
          });
          props2 === null || props2 === void 0 ? void 0 : (_props2$selectInputPr7 = props2.selectInputProps) === null || _props2$selectInputPr7 === void 0 ? void 0 : (_props2$selectInputPr8 = _props2$selectInputPr7.onBlur) === null || _props2$selectInputPr8 === void 0 ? void 0 : _props2$selectInputPr8.call(_props2$selectInputPr7, val, context);
        },
        "onFocus": function onFocus(val, context) {
          var _props2$onFocus, _props2$selectInputPr9, _props2$selectInputPr10;
          (_props2$onFocus = props2.onFocus) === null || _props2$onFocus === void 0 ? void 0 : _props2$onFocus.call(props2, {
            value: cascaderContext.value.value,
            e: context.e
          });
          props2 === null || props2 === void 0 ? void 0 : (_props2$selectInputPr9 = props2.selectInputProps) === null || _props2$selectInputPr9 === void 0 ? void 0 : (_props2$selectInputPr10 = _props2$selectInputPr9.onFocus) === null || _props2$selectInputPr10 === void 0 ? void 0 : _props2$selectInputPr10.call(_props2$selectInputPr9, val, context);
        },
        "onClear": function onClear(context) {
          var _props2$selectInputPr11, _props2$selectInputPr12;
          closeIconClickEffect(cascaderContext.value);
          props2 === null || props2 === void 0 ? void 0 : (_props2$selectInputPr11 = props2.selectInputProps) === null || _props2$selectInputPr11 === void 0 ? void 0 : (_props2$selectInputPr12 = _props2$selectInputPr11.onClear) === null || _props2$selectInputPr12 === void 0 ? void 0 : _props2$selectInputPr12.call(_props2$selectInputPr11, context);
        }
      }, omit(props2.selectInputProps, ["onTagChange", "onInputChange", "onPopupVisibleChange", "onBlur", "onFocus", "onClear"])), {
        panel: function panel() {
          return createVNode(Panel, {
            "empty": props2.empty,
            "visible": visible,
            "trigger": props2.trigger,
            "loading": props2.loading,
            "loadingText": props2.loadingText,
            "cascaderContext": cascaderContext.value
          }, {
            empty: slots.empty,
            loadingText: slots.loadingText
          });
        },
        collapsedItems: slots.collapsedItems
      });
    };
  }
});

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