/**
 * ldesign v0.2.22
 * (c) 2022/12/7 16:21 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/useConfig.js';
import useFormDisabled from '../../hooks/useFormDisabled.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/withInstall.js';
import 'vue';
import 'lodash/capitalize';
import '../../config.js';
import '../select-input/select-input.js';
import '../../_chunks/dep-b0f1ed22.js';
import '../popup/index.js';
import '../../utils/map-props.js';
import '../popup/popup.js';
import '@popperjs/core';
import '../../_chunks/dep-c68dc4b6.js';
import '../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../_chunks/dep-eaa95999.js';
import '../../_chunks/dep-102361be.js';
import '../../utils/easing.js';
import '../../utils/render-node.js';
import 'lodash';
import '../../utils/helper.js';
import 'lodash/camelCase';
import '../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import 'lodash/merge';
import '../../_chunks/dep-b4fd1955.js';
import '../../utils/mixins.js';
import '../popup/props.js';
import '../popup/container.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/dep-1a6bca30.js';
import '../../utils/event.js';
import '../input/props.js';
import '../input/group.js';
import '../loading/index.js';
import '../loading/loading.js';
import '../../utils/transfer-dom.js';
import '../loading/props.js';
import '../loading/icon/gradient.js';
import '../../_chunks/dep-aacc31a3.js';
import '../loading/plugin.js';
import '../../hooks/lnode.js';
import 'lodash/isEmpty';
import 'lodash/isFunction';
import '../../hooks/render-lnode.js';
import '../../hooks/useDefaultValue.js';
import '../select-input/hooks/use-multiple.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/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 '../../hooks/useVModel.js';
import '../tag-input/hooks/use-hover.js';
import '../tag-input/hooks/use-drag-sorter.js';
import '../select-input/hooks/use-overlay-innerstyle.js';
import 'lodash/isEqual';
import '../../_chunks/dep-5bab082b.js';
import '../../_chunks/dep-a2743d97.js';
import '../../_chunks/dep-25603871.js';
import '../../_chunks/dep-128cad98.js';
import '../../_chunks/dep-52c80d08.js';
import '../../_chunks/dep-c3acb800.js';
import '../../_chunks/dep-387c3c4b.js';
import '../../_chunks/dep-40693b6f.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 '../../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() {
    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?.overlayClassName]
          },
          inputProps: {
            size: this.size,
            ...this.inputProps
          },
          tagInputProps: {
            size: this.size,
            ...this.tagInputProps
          },
          tagProps: {
            ...this.tagProps
          },
          onInputChange: (value, ctx) => {
            if (!this.isFilterable) return;
            setInputVal(`${value}`);
            this?.selectInputProps?.onInputChange?.(value, ctx);
          },
          onTagChange: (val, ctx) => {
            if (ctx.trigger === "enter") return;
            handleRemoveTagEffect(cascaderContext, ctx.index, this.onRemove);
            this?.selectInputProps?.onTagChange?.(val, ctx);
          },
          onPopupVisibleChange: (val, context) => {
            if (this.disabled) return;
            setVisible(val, context);
            this?.selectInputProps?.onPopupVisibleChange?.(val, context);
          },
          onBlur: (val, context) => {
            const ctx = {
              value: cascaderContext.value,
              e: context.e
            };
            this.onBlur?.(ctx);
            emit("blur", ctx);
            this?.selectInputProps?.onBlur?.(val, context);
          },
          onFocus: (val, context) => {
            const ctx = {
              value: cascaderContext.value,
              e: context.e
            };
            this.onFocus?.(ctx);
            emit("focus", ctx);
            this?.selectInputProps?.onFocus?.(val, context);
          },
          onClear: context => {
            closeIconClickEffect(cascaderContext);
            this?.selectInputProps?.onClear?.(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
