/**
 * ldesign v0.2.2
 * (c) 2022年9月20日 swimly
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, computed } from '@vue/composition-api';
import omit from 'lodash/omit';
import Panel from './components/Panel.js';
import { SelectInput } from '../select-input/index.js';
import LFakeArrow from '../common/fake-arrow.js';
import props from './props.js';
import { useCascaderContext } from './hooks/index.js';
import { usePrefixClass, useCommonClassName } from '../../hooks/use-config.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 './components/Item.js';
import '../../_chunks/dep-b13ef886.js';
import '@ldesign/icons-vue';
import '../checkbox/index.js';
import '../checkbox/group.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/typeof';
import 'lodash/intersection';
import '../checkbox/checkbox.js';
import 'vue';
import '../../utils/render-node.js';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../checkbox/props.js';
import '../../utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import '../../utils/event.js';
import '../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import 'lodash';
import '../config-provider/context.js';
import '../../_chunks/dep-a0f2090c.js';
import '../../utils/mixins.js';
import '../../utils/map-props.js';
import '../../utils/with-install.js';
import '../../config.js';
import '../loading/index.js';
import '../loading/loading.js';
import '../loading/icon/gradient.js';
import '../../_chunks/dep-33b15d9d.js';
import '../../_chunks/dep-85e8b23b.js';
import '../../_chunks/dep-fc383775.js';
import '../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../utils/easing.js';
import '../../utils/transfer-dom.js';
import '../loading/props.js';
import '../loading/plugin.js';
import '../../hooks/use-global-icon.js';
import '../../utils/ripple.js';
import '../../hooks/lnode.js';
import 'lodash/isEmpty';
import 'lodash/isFunction';
import '../../hooks/render-lnode.js';
import 'lodash/isObject';
import '../select-input/select-input.js';
import '../popup/index.js';
import '../popup/popup.js';
import '@popperjs/core';
import '../popup/props.js';
import '../popup/container.js';
import '../select-input/props.js';
import '../select-input/hooks/use-single.js';
import 'lodash/pick';
import '../../hooks/use-default-value.js';
import '../select-input/hooks/use-multiple.js';
import '../select-input/hooks/use-overlay-innerstyle.js';
import 'lodash/isEqual';
import '../../_chunks/dep-360db93c.js';
import '@babel/runtime/helpers/classCallCheck';
import '@babel/runtime/helpers/createClass';
import '../../_chunks/dep-40125abf.js';
import '@babel/runtime/regenerator';
import '../../_chunks/dep-d204d516.js';
import '../../_chunks/dep-64cbbe92.js';
import '../../_chunks/dep-5c5da9dd.js';
import '../../_chunks/dep-53d4956d.js';
import '../../_chunks/dep-a65fe6e9.js';
import '../../hooks/use-vmodel.js';
import 'lodash/isNumber';
import 'lodash/cloneDeep';

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: "LCascader",
  props: _objectSpread({}, props),
  components: {
    LFakeArrow: LFakeArrow
  },
  setup: function setup(props2, _ref) {
    var slots = _ref.slots,
        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),
        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);
    });
    return {
      COMPONENT_NAME: COMPONENT_NAME,
      overlayClassName: overlayClassName,
      panels: panels,
      displayValue: displayValue,
      inputPlaceholder: inputPlaceholder,
      isFilterable: isFilterable,
      STATUS: STATUS,
      classPrefix: classPrefix,
      cascaderContext: cascaderContext,
      slots: slots,
      emit: emit
    };
  },
  render: function render() {
    var _this$popupProps,
        _this = this;

    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,
        STATUS = this.STATUS,
        classPrefix = this.classPrefix,
        cascaderContext = this.cascaderContext,
        slots = this.slots,
        emit = this.emit;

    var renderSuffixIcon = function renderSuffixIcon() {
      var visible2 = cascaderContext.visible,
          disabled = cascaderContext.disabled;
      return h("l-fake-arrow", {
        "attrs": {
          "overlayClassName": getFakeArrowIconClass(classPrefix, STATUS, cascaderContext),
          "isActive": visible2,
          "disabled": disabled
        }
      });
    };

    var setVisible = cascaderContext.setVisible,
        visible = cascaderContext.visible,
        inputVal = cascaderContext.inputVal,
        setInputVal = cascaderContext.setInputVal;
    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: this.collapsedItems,
        readonly: this.readonly,
        disabled: this.disabled,
        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"
          } : "",
          overlayInnerClassName: [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 === 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: function 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: 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 === 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: 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 === 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: function 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: 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
            }
          });
        },
        collapsedItems: slots.collapsedItems
      }
    });
  }
});

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