/**
 * tdesign v0.41.7
 * (c) 2022 tdesign
 * @license MIT
 */

'use strict';

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

var helper = require('../_chunks/dep-99705d51.js');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var Vue = require('vue');
var isEqual = require('lodash/isEqual');
var config = require('../config.js');
var _common_js_tree_treeStore = require('../_common/js/tree/tree-store.js');
var utils_event = require('../utils/event.js');
var utils_helper = require('../utils/helper.js');
var cascader_utils_helper = require('./utils/helper.js');
var cascader_utils_cascader = require('./utils/cascader.js');
var cascader_components_Panel = require('./components/Panel.js');
var popup_index = require('../popup/index.js');
var cascader_components_InputContent = require('./components/InputContent.js');
var cascader_interface = require('./interface.js');
var cascader_props = require('./props.js');
require('@babel/runtime/helpers/classCallCheck');
require('@babel/runtime/helpers/createClass');
require('lodash/difference');
require('lodash/camelCase');
require('lodash/isPlainObject');
require('../_common/js/tree/tree-node.js');
require('@babel/runtime/helpers/asyncToGenerator');
require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/regenerator');
require('lodash/uniqueId');
require('lodash/get');
require('../_common/js/tree/tree-node-model.js');
require('lodash/pick');
require('../_common/js/log/log.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('@babel/runtime/helpers/typeof');
require('lodash/isEmpty');
require('../utils/render-tnode.js');
require('../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('../utils/mixins.js');
require('./utils/panel.js');
require('lodash/isNumber');
require('./components/Item.js');
require('tdesign-icons-vue');
require('../utils/classnames.js');
require('../utils/ripple.js');
require('../_common/js/utils/set-style.js');
require('./utils/item.js');
require('../loading/index.js');
require('../loading/loading.js');
require('../loading/icon/gradient.js');
require('../_common/js/loading/circle-adapter.js');
require('../_common/js/utils/helper.js');
require('../utils/dom.js');
require('raf');
require('lodash/isString');
require('../utils/easing.js');
require('../utils/transfer-dom.js');
require('../loading/props.js');
require('../utils/withInstall.js');
require('lodash/capitalize');
require('../loading/plugin.js');
require('../checkbox/index.js');
require('../checkbox/group.js');
require('lodash/intersection');
require('../checkbox/checkbox.js');
require('../checkbox/props.js');
require('../checkbox/checkbox-group-props.js');
require('../utils/map-props.js');
require('../tooltip/index.js');
require('../tooltip/tooltip.js');
require('lodash/isFunction');
require('../tooltip/props.js');
require('../popup/props.js');
require('../popup/popup.js');
require('@popperjs/core');
require('../popup/container.js');
require('../tag/index.js');
require('../tag/tag.js');
require('../tag/props.js');
require('../tag/check-tag.js');
require('../tag/check-tag-props.js');
require('../input/index.js');
require('../input/addon.js');
require('../input/input.js');
require('lodash/kebabCase');
require('../input/props.js');
require('../input/input-group.js');
require('../common-components/fake-arrow.js');
require('./utils/inputContent.js');

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

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue);
var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);

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 name = "".concat(config.prefix, "-cascader");
var _Cascader = Vue__default["default"].extend({
  name: "TCascader",
  components: {
    Popup: popup_index.Popup,
    Panel: cascader_components_Panel["default"],
    InputContent: cascader_components_InputContent["default"]
  },
  props: _objectSpread({}, cascader_props["default"]),
  data: function data() {
    return {
      formDisabled: void 0,
      inputWidth: 0,
      visible: false,
      treeStore: null,
      inputVal: "",
      scopeVal: this.defaultValue,
      treeNodes: [],
      filterActive: false,
      expend: []
    };
  },
  computed: {
    tDisabled: function tDisabled() {
      return this.formDisabled || this.disabled;
    },
    stateFns: function stateFns() {
      var _this = this;

      return {
        setTreeNodes: function setTreeNodes(nodes) {
          _this.treeNodes = nodes;
        },
        setValue: function setValue(val, source, node) {
          if (isEqual__default["default"](val, _this.scopeVal)) return;
          utils_event.emitEvent(_this, "change", val, {
            source: source,
            node: node
          });
        },
        setVisible: function setVisible(val) {
          _this.visible = val;
        },
        setFilterActive: function setFilterActive(val) {
          _this.filterActive = val;
        },
        setInputVal: function setInputVal(val) {
          _this.inputVal = val;
        },
        setExpend: function setExpend(val) {
          _this.expend = val;
        },
        setInputWidth: function setInputWidth(val) {
          _this.inputWidth = val;
        }
      };
    },
    cascaderContext: function cascaderContext() {
      var value = this.scopeVal;
      var _this$size = this.size,
          size = _this$size === void 0 ? "medium" : _this$size,
          _this$checkStrictly = this.checkStrictly,
          checkStrictly = _this$checkStrictly === void 0 ? false : _this$checkStrictly,
          _this$lazy = this.lazy,
          lazy = _this$lazy === void 0 ? true : _this$lazy,
          _this$multiple = this.multiple,
          multiple = _this$multiple === void 0 ? false : _this$multiple,
          _this$filterable = this.filterable,
          filterable = _this$filterable === void 0 ? false : _this$filterable,
          _this$clearable = this.clearable,
          clearable = _this$clearable === void 0 ? false : _this$clearable,
          _this$checkProps = this.checkProps,
          checkProps = _this$checkProps === void 0 ? {} : _this$checkProps,
          _this$max = this.max,
          max = _this$max === void 0 ? 0 : _this$max,
          tDisabled = this.tDisabled,
          _this$showAllLevels = this.showAllLevels,
          showAllLevels = _this$showAllLevels === void 0 ? true : _this$showAllLevels,
          _this$minCollapsedNum = this.minCollapsedNum,
          minCollapsedNum = _this$minCollapsedNum === void 0 ? 0 : _this$minCollapsedNum,
          loading = this.loading,
          _this$valueType = this.valueType,
          valueType = _this$valueType === void 0 ? "single" : _this$valueType;
      var visible = this.visible,
          treeStore = this.treeStore,
          treeNodes = this.treeNodes,
          filterActive = this.filterActive,
          inputVal = this.inputVal,
          inputWidth = this.inputWidth;
      return _objectSpread({
        valueType: valueType,
        loading: loading,
        size: size,
        disabled: tDisabled,
        checkStrictly: checkStrictly,
        lazy: lazy,
        multiple: multiple,
        filterable: filterable,
        checkProps: checkProps,
        clearable: clearable,
        showAllLevels: showAllLevels,
        max: max,
        value: value,
        visible: visible,
        treeStore: treeStore,
        treeNodes: treeNodes,
        filterActive: filterActive,
        inputVal: inputVal,
        inputWidth: inputWidth,
        minCollapsedNum: minCollapsedNum
      }, this.stateFns);
    }
  },
  watch: {
    value: {
      handler: function handler(val) {
        var valueType = this.valueType,
            multiple = this.multiple;
        if (isEqual__default["default"](val, this.scopeVal)) return;
        this.scopeVal = cascader_utils_helper.getValue(val, valueType, multiple);
        this.updateExpend();
        this.updatedTreeNodes();
      }
    },
    inputVal: function inputVal() {
      var _this$cascaderContext = this.cascaderContext,
          value = _this$cascaderContext.value,
          setExpend = _this$cascaderContext.setExpend;

      if (!cascader_utils_helper.getTreeValue(value).length) {
        setExpend([]);
      }

      this.updatedTreeNodes();
    },
    filterActive: function filterActive() {
      var filterActive = this.cascaderContext.filterActive;

      if (!filterActive) {
        this.inputVal = "";
      }
    }
  },
  mounted: function mounted() {
    var _this2 = this;

    var value = this.value,
        multiple = this.multiple,
        _this$cascaderContext2 = this.cascaderContext,
        setValue = _this$cascaderContext2.setValue,
        showAllLevels = _this$cascaderContext2.showAllLevels,
        valueType = this.valueType;

    if (multiple && !Array.isArray(value) || !multiple && Array.isArray(value) && !showAllLevels) {
      var val = multiple ? [] : "";
      setValue(val, "invalid-value");
      console.warn("TDesign Cascader Warn:", "cascader props value invalid, v-model automatic calibration");
    }

    if (!cascader_utils_helper.isEmptyValues(value)) {
      this.scopeVal = cascader_utils_helper.getValue(value, valueType, multiple);
    }

    this.init();
    ["checkStrictly", "tDisabled", "keys", "lazy", "load", "options", "valueMode"].forEach(function (key) {
      _this2.$watch(key, function () {
        _this2.init();
      });
    });
  },
  provide: function provide() {
    return {
      tCascader: this
    };
  },
  methods: {
    init: function init() {
      var _this3 = this;

      var tDisabled = this.tDisabled,
          keys = this.keys,
          _this$checkStrictly2 = this.checkStrictly,
          checkStrictly = _this$checkStrictly2 === void 0 ? false : _this$checkStrictly2,
          _this$lazy2 = this.lazy,
          lazy = _this$lazy2 === void 0 ? true : _this$lazy2,
          load = this.load,
          options = this.options,
          _this$valueMode = this.valueMode,
          valueMode = _this$valueMode === void 0 ? "onlyLeaf" : _this$valueMode;
      if (!options || Array.isArray(options) && !options.length) return;
      this.treeStore = new _common_js_tree_treeStore.TreeStore({
        keys: keys || {},
        checkable: true,
        checkStrictly: checkStrictly,
        expandMutex: true,
        expandParent: true,
        disabled: tDisabled,
        load: load,
        lazy: lazy,
        valueMode: valueMode,
        onLoad: function onLoad() {
          setTimeout(function () {
            _this3.treeStore.refreshNodes();

            _this3.updatedTreeNodes();
          }, 0);
        }
      });
      this.treeStore.append(options);
      this.$nextTick(function () {
        _this3.updateExpend();

        _this3.updatedTreeNodes();
      });
    },
    updatedTreeNodes: function updatedTreeNodes() {
      var _this$cascaderContext3 = this.cascaderContext,
          inputVal = _this$cascaderContext3.inputVal,
          treeStore = _this$cascaderContext3.treeStore,
          setTreeNodes = _this$cascaderContext3.setTreeNodes;
      cascader_utils_cascader.treeNodesEffect(inputVal, treeStore, setTreeNodes);
    },
    updateExpend: function updateExpend() {
      var _this$cascaderContext4 = this.cascaderContext,
          treeStore = _this$cascaderContext4.treeStore,
          value = _this$cascaderContext4.value,
          expend = this.expend;
      if (!treeStore) return;
      cascader_utils_cascader.treeStoreExpendEffect(treeStore, value, expend);
      treeStore.replaceChecked(cascader_utils_helper.getTreeValue(value));
    }
  },
  render: function render() {
    var _this4 = this;

    var h = arguments[0];
    var visible = this.visible,
        trigger = this.trigger,
        empty = this.empty,
        $attrs = this.$attrs,
        cascaderContext = this.cascaderContext,
        $scopedSlots = this.$scopedSlots,
        placeholder = this.placeholder,
        collapsedItems = this.collapsedItems;
    var popupProps = this.popupProps;
    var listeners = {};
    cascader_interface.EVENT_NAME_WITH_KEBAB.forEach(function (eventName) {
      listeners[utils_helper.getPropsApiByEvent(eventName)] = function () {
        for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
          args[_key] = arguments[_key];
        }

        utils_event.emitEvent.apply(void 0, [_this4, eventName].concat(args));
      };
    });
    return h(popup_index.Popup, helper.helper([{
      "class": "".concat(name, "__popup"),
      "attrs": {
        "overlayClassName": "".concat(name, "__dropdown"),
        "placement": "bottom-left",
        "visible": visible,
        "trigger": (popupProps === null || popupProps === void 0 ? void 0 : popupProps.trigger) || "click",
        "expandAnimation": true
      }
    }, {
      "props": popupProps
    }, {
      "attrs": {
        "content": function content() {
          return h("panel", {
            "attrs": {
              "empty": empty,
              "trigger": trigger,
              "cascaderContext": cascaderContext
            },
            "scopedSlots": {
              empty: $scopedSlots.empty
            }
          });
        }
      }
    }]), [h(cascader_components_InputContent["default"], helper.helper([{}, $attrs, {
      "attrs": {
        "cascaderContext": cascaderContext,
        "placeholder": placeholder,
        "listeners": listeners,
        "collapsedItems": collapsedItems
      },
      "scopedSlots": {
        collapsedItems: $scopedSlots.collapsedItems
      }
    }]))]);
  }
});

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