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

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var VueCompositionAPI = require('@vue/composition-api');
var omit = require('lodash/omit');
var components_cascader_components_Panel = require('./components/Panel.js');
var components_selectInput_index = require('../select-input/index.js');
var components_common_fakeArrow = require('../common/fake-arrow.js');
var components_cascader_props = require('./props.js');
var components_cascader_hooks_index = require('./hooks/index.js');
var hooks_useConfig = require('../../hooks/use-config.js');
var components_cascader_utils_effect = require('./utils/effect.js');
var components_cascader_utils_helper = require('./utils/helper.js');
var components_cascader_utils_className = require('./utils/className.js');
var components_configProvider_useConfig = require('../config-provider/useConfig.js');
require('./components/Item.js');
require('../../chunks/helper.js');
require('@ldesign/icons-vue');
require('../checkbox/index.js');
require('../checkbox/group.js');
require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/helpers/typeof');
require('lodash/intersection');
require('../checkbox/checkbox.js');
require('vue');
require('../../utils/render-node.js');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../checkbox/props.js');
require('../../utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('../../utils/event.js');
require('../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('lodash');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');
require('../../utils/mixins.js');
require('../../utils/map-props.js');
require('../../utils/with-install.js');
require('../../config.js');
require('../loading/index.js');
require('../loading/loading.js');
require('../loading/icon/gradient.js');
require('../../chunks/defineProperty-28395935.js');
require('../../chunks/set-style.js');
require('../../chunks/helper2.js');
require('../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../utils/easing.js');
require('../../utils/transfer-dom.js');
require('../loading/props.js');
require('../loading/plugin.js');
require('../../hooks/use-global-icon.js');
require('../../utils/ripple.js');
require('../../hooks/lnode.js');
require('lodash/isEmpty');
require('lodash/isFunction');
require('../../hooks/render-lnode.js');
require('lodash/isObject');
require('../select-input/select-input.js');
require('../popup/index.js');
require('../popup/popup.js');
require('@popperjs/core');
require('../popup/props.js');
require('../popup/container.js');
require('../select-input/props.js');
require('../select-input/hooks/use-single.js');
require('lodash/pick');
require('../../hooks/use-default-value.js');
require('../select-input/hooks/use-multiple.js');
require('../select-input/hooks/use-overlay-innerstyle.js');
require('lodash/isEqual');
require('../../chunks/tree-store.js');
require('@babel/runtime/helpers/classCallCheck');
require('@babel/runtime/helpers/createClass');
require('../../chunks/tree-node.js');
require('@babel/runtime/regenerator');
require('../../chunks/isArray-b0f0e351.js');
require('../../chunks/_isIndex-1bf92538.js');
require('../../chunks/isObjectLike-2443c6ff.js');
require('../../chunks/_commonjsHelpers-ea2bee21.js');
require('../../chunks/log.js');
require('../../hooks/use-vmodel.js');
require('lodash/isNumber');
require('lodash/cloneDeep');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);

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__default["default"](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 = VueCompositionAPI.defineComponent({
  name: "LCascader",
  props: _objectSpread({}, components_cascader_props["default"]),
  components: {
    LFakeArrow: components_common_fakeArrow["default"]
  },
  setup: function setup(props2, _ref) {
    var slots = _ref.slots,
        emit = _ref.emit;
    var COMPONENT_NAME = hooks_useConfig.usePrefixClass("cascader");
    var classPrefix = hooks_useConfig.usePrefixClass();

    var _useCommonClassName = hooks_useConfig.useCommonClassName(),
        STATUS = _useCommonClassName.STATUS;

    var overlayClassName = hooks_useConfig.usePrefixClass("cascader__popup");

    var _useConfig = components_configProvider_useConfig.useConfig("cascader"),
        global = _useConfig.global;

    var _useCascaderContext = components_cascader_hooks_index.useCascaderContext(props2),
        cascaderContext = _useCascaderContext.cascaderContext,
        isFilterable = _useCascaderContext.isFilterable;

    var displayValue = VueCompositionAPI.computed(function () {
      return props2.multiple ? components_cascader_utils_helper.getMultipleContent(cascaderContext.value) : components_cascader_utils_helper.getSingleContent(cascaderContext.value);
    });
    var panels = VueCompositionAPI.computed(function () {
      return components_cascader_utils_helper.getPanels(cascaderContext.value.treeNodes);
    });
    var inputPlaceholder = VueCompositionAPI.computed(function () {
      var _props2$placeholder;

      return cascaderContext.value.visible && !props2.multiple && components_cascader_utils_helper.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": components_cascader_utils_className.getFakeArrowIconClass(classPrefix, STATUS, cascaderContext),
          "isActive": visible2,
          "disabled": disabled
        }
      });
    };

    var setVisible = cascaderContext.setVisible,
        visible = cascaderContext.visible,
        inputVal = cascaderContext.inputVal,
        setInputVal = cascaderContext.setInputVal;
    return h(components_selectInput_index.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;
          components_cascader_utils_effect.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;

          components_cascader_utils_effect.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__default["default"](this.selectInputProps, ["onTagChange", "onInputChange", "onPopupVisibleChange", "onBlur", "onFocus", "onClear"]))),
      "scopedSlots": {
        panel: function panel() {
          return h(components_cascader_components_Panel["default"], {
            "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
      }
    });
  }
});

exports["default"] = _Cascader;
//# sourceMappingURL=cascader.js.map
