/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

import { defineComponent, computed } from '@vue/composition-api';
import omit from 'lodash/omit';
import { SelectInput } from '../select-input/index.js';
import FakeArrow from '../common/fake-arrow.js';
import { usePrefixClass, useCommonClassName } from '../../hooks/use-config.js';
import useFormDisabled from '../../hooks/use-form-disabled.js';
import props from './props.js';
import { useCascaderContext } from './hooks/index.js';
import Panel from './components/Panel.js';
import { handleRemoveTagEffect, closeIconClickEffect } from './utils/effect.js';
import { getMultipleContent, getSingleContent, getPanels } from './utils/helper.js';
import { getFakeArrowIconClass } from './utils/className.js';
import { useConfig } from '../config-provider/useConfig.js';
import '../../utils/with-install.js';
import 'vue';
import 'lodash';
import '../../config.js';
import '../select-input/select-input.js';
import '../../chunks/helper.js';
import '../../chunks/_commonjsHelpers.js';
import '../popup/index.js';
import '../../utils/map-props.js';
import '../popup/popup.js';
import '@popperjs/core';
import '../../chunks/set-style.js';
import '../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../chunks/index.js';
import '../../chunks/log.js';
import '../../chunks/_commonjsHelpers-2e6815bd.js';
import '../../utils/easing.js';
import '../../utils/render-node.js';
import '../../utils/helper.js';
import 'lodash/camelCase';
import '../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import '../../chunks/zh_CN.js';
import '../config-provider/type.js';
import '../../utils/mixins.js';
import '../popup/props.js';
import '../popup/container.js';
import '../popup/style/css.js';
import '../popup/type.js';
import '../select-input/props.js';
import '../select-input/hooks/use-single.js';
import 'lodash/isObject';
import 'lodash/pick';
import '../input/index.js';
import '../input/input.js';
import '@ldesign/icons-vue';
import 'lodash/kebabCase';
import '../../chunks/helper2.js';
import '../../chunks/defineProperty-838e4192.js';
import '../../utils/event.js';
import '../input/props.js';
import '../input/group.js';
import '../input/style/css.js';
import '../input/type.js';
import '../loading/index.js';
import '../loading/loading.js';
import '../../utils/transfer-dom.js';
import '../loading/props.js';
import '../loading/icon/gradient.js';
import '../loading/style/css.js';
import '../loading/type.js';
import '../loading/plugin.js';
import '../../hooks/lnode.js';
import 'lodash/isEmpty';
import 'lodash/isFunction';
import '../../hooks/render-lnode.js';
import '../../hooks/use-default-value.js';
import '../select-input/hooks/use-multiple.js';
import '../tag-input/index.js';
import '../tag-input/tag-input.js';
import '../../hooks/use-global-icon.js';
import '../tag-input/props.js';
import '../tag-input/hooks/use-tag-scroll.js';
import '../tag-input/hooks/use-tag-list.js';
import '../tag/index.js';
import '../tag/tag.js';
import '../tag/props.js';
import '../tag/check-tag.js';
import '../tag/style/css.js';
import '../tag/type.js';
import '../../hooks/use-vmodel.js';
import '../tag-input/hooks/use-hover.js';
import '../tag-input/hooks/use-drag-sorter.js';
import '../tag-input/style/css.js';
import '../tag-input/type.js';
import '../select-input/hooks/use-overlay-innerstyle.js';
import '../select-input/style/css.js';
import '../select-input/type.js';
import 'lodash/isEqual';
import '../../chunks/tree-store.js';
import '../../chunks/get-5e1abd10.js';
import '../../chunks/isArray-cd7357b9.js';
import '../../chunks/isSymbol-a38a5184.js';
import '../../chunks/isObjectLike-c22c7e3b.js';
import '../../chunks/isFunction-91acade7.js';
import '../../chunks/tree-node.js';
import '../../chunks/_isIndex-52887d1e.js';
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/style/css.js';
import '../checkbox/type.js';
import '../../utils/ripple.js';
import 'lodash/isNumber';
import 'lodash/cloneDeep';

var _Cascader = defineComponent({
  name: "LCascader",
  components: {
    LFakeArrow: FakeArrow
  },
  props: {
    ...props
  },
  setup(props2, _ref) {
    let {
      slots,
      emit
    } = _ref;
    const COMPONENT_NAME = usePrefixClass("cascader");
    const classPrefix = usePrefixClass();
    const {
      STATUS
    } = useCommonClassName();
    const overlayClassName = usePrefixClass("cascader__popup");
    const {
      global
    } = useConfig("cascader");
    const {
      cascaderContext,
      isFilterable
    } = useCascaderContext(props2);
    const displayValue = computed(() => props2.multiple ? getMultipleContent(cascaderContext.value) : getSingleContent(cascaderContext.value));
    const panels = computed(() => getPanels(cascaderContext.value.treeNodes));
    const inputPlaceholder = computed(() => cascaderContext.value.visible && !props2.multiple && getSingleContent(cascaderContext.value) || (props2.placeholder ?? global.value.placeholder));
    const {
      formDisabled
    } = useFormDisabled();
    const isDisabled = computed(() => formDisabled.value || cascaderContext.value.disabled);
    return {
      COMPONENT_NAME,
      overlayClassName,
      panels,
      displayValue,
      inputPlaceholder,
      isFilterable,
      isDisabled,
      STATUS,
      classPrefix,
      cascaderContext,
      slots,
      emit
    };
  },
  render() {
    var _this$popupProps;
    const h = arguments[0];
    const {
      COMPONENT_NAME,
      overlayClassName,
      panels,
      displayValue,
      inputPlaceholder,
      isFilterable,
      isDisabled,
      STATUS,
      classPrefix,
      cascaderContext,
      slots,
      emit
    } = this;
    const renderSuffixIcon = () => {
      const {
        visible: visible2
      } = cascaderContext;
      return h("l-fake-arrow", {
        "attrs": {
          "overlayClassName": getFakeArrowIconClass(classPrefix, STATUS, cascaderContext),
          "isActive": visible2,
          "disabled": isDisabled
        }
      });
    };
    const {
      setVisible,
      visible,
      inputVal,
      setInputVal
    } = cascaderContext;
    return h(SelectInput, {
      "class": COMPONENT_NAME,
      "props": {
        ...{
          value: displayValue,
          inputValue: visible ? inputVal : "",
          popupVisible: visible,
          keys: this.keys,
          allowInput: isFilterable,
          minCollapsedNum: this.minCollapsedNum,
          collapsedItems: this.collapsedItems,
          readonly: this.readonly,
          disabled: isDisabled,
          clearable: this.clearable,
          placeholder: inputPlaceholder,
          multiple: this.multiple,
          loading: this.loading,
          status: this.status,
          tips: this.tips,
          suffixIcon: () => renderSuffixIcon(),
          popupProps: {
            ...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: {
            size: this.size,
            ...this.inputProps
          },
          tagInputProps: {
            size: this.size,
            ...this.tagInputProps
          },
          tagProps: {
            ...this.tagProps
          },
          onInputChange: (value, ctx) => {
            var _this$selectInputProp, _this$selectInputProp2;
            if (!this.isFilterable) return;
            setInputVal(`${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: (val, ctx) => {
            var _this$selectInputProp3, _this$selectInputProp4;
            if (ctx.trigger === "enter") return;
            handleRemoveTagEffect(cascaderContext, ctx.index, this.onRemove);
            this === null || this === void 0 ? void 0 : (_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: (val, context) => {
            var _this$selectInputProp5, _this$selectInputProp6;
            if (this.disabled) return;
            setVisible(val, context);
            this === null || this === void 0 ? void 0 : (_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: (val, context) => {
            var _this$onBlur, _this$selectInputProp7, _this$selectInputProp8;
            const 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 === null || this === void 0 ? void 0 : (_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: (val, context) => {
            var _this$onFocus, _this$selectInputProp9, _this$selectInputProp10;
            const 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 === null || this === void 0 ? void 0 : (_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: context => {
            var _this$selectInputProp11, _this$selectInputProp12;
            closeIconClickEffect(cascaderContext);
            this === null || this === void 0 ? void 0 : (_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: () => h(Panel, {
          "attrs": {
            "empty": this.empty,
            "trigger": this.trigger,
            "loading": this.loading,
            "loadingText": this.loadingText,
            "cascaderContext": cascaderContext
          },
          "scopedSlots": {
            empty: slots.empty,
            loadingText: slots.loadingText
          }
        }),
        collapsedItems: slots.collapsedItems
      }
    });
  }
});

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