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

import { h as helper } from '../_chunks/dep-37d5b9c4.js';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, ref, computed } from '@vue/composition-api';
import baseTableProps from './base-table-props.js';
import primaryTableProps from './primary-table-props.js';
import enhancedTableProps from './enhanced-table-props.js';
import _PrimaryTable from './primary-table.js';
import useTreeData from './hooks/useTreeData.js';
import useTreeSelect from './hooks/useTreeSelect.js';
import { BASE_TABLE_ALL_EVENTS } from './base-table.js';
import 'lodash/get';
import 'lodash/omit';
import '../hooks/tnode.js';
import 'lodash/isEmpty';
import 'lodash/isFunction';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../hooks/render-tnode.js';
import 'lodash/isString';
import 'lodash/isObject';
import './hooks/useColumnController.js';
import '@babel/runtime/helpers/slicedToArray';
import '@babel/runtime/helpers/toConsumableArray';
import 'tdesign-icons-vue';
import 'lodash/intersection';
import '../checkbox/index.js';
import '../checkbox/group.js';
import '@babel/runtime/helpers/typeof';
import 'vue';
import '../config.js';
import '../checkbox/checkbox.js';
import '../utils/render-tnode.js';
import '../utils/classnames.js';
import '../checkbox/props.js';
import '../utils/helper.js';
import '../utils/event.js';
import '../checkbox/checkbox-group-props.js';
import '../utils/map-props.js';
import '../utils/withInstall.js';
import 'lodash/capitalize';
import './style/css.js';
import '../checkbox/type.js';
import '../dialog/plugin.js';
import '../dialog/dialog.js';
import 'lodash/throttle';
import '../button/index.js';
import '../button/button.js';
import '../loading/index.js';
import '../loading/loading.js';
import '../loading/icon/gradient.js';
import '../_common/js/loading/circle-adapter.js';
import '../_common/js/utils/set-style.js';
import '../_common/js/utils/helper.js';
import '../utils/dom.js';
import 'raf';
import '../utils/easing.js';
import '../utils/transfer-dom.js';
import '../loading/props.js';
import '../loading/type.js';
import '../loading/plugin.js';
import '../button/props.js';
import '../utils/ripple.js';
import '../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../config-provider/type.js';
import '../utils/mixins.js';
import '../button/type.js';
import '../dialog/actions.js';
import '../dialog/props.js';
import '../hooks/useDestroyOnClose.js';
import './hooks/useTableHeader.js';
import './hooks/useMultiHeader.js';
import './hooks/useClassName.js';
import '../config-provider/useConfig.js';
import 'lodash/cloneDeep';
import './ellipsis.js';
import 'lodash/debounce';
import '../popup/index.js';
import '../popup/popup.js';
import '@popperjs/core';
import '../popup/props.js';
import '../popup/container.js';
import '../popup/type.js';
import '../hooks/useDefaultValue.js';
import './utils.js';
import './hooks/useRowExpand.js';
import './hooks/useRowSelect.js';
import '../radio/index.js';
import '../radio/radio.js';
import '../radio/props.js';
import '../radio/group.js';
import 'lodash/isNumber';
import '../radio/radio-group-props.js';
import '../radio/radio-button.js';
import '../radio/type.js';
import '../_common/js/log/index.js';
import '../_common/js/log/log.js';
import './hooks/useSorter.js';
import './sorter-button.js';
import '../tooltip/index.js';
import '../tooltip/tooltip.js';
import '../tooltip/props.js';
import '../tooltip/type.js';
import './hooks/useFilter.js';
import './filter-controller.js';
import '../input/index.js';
import '../input/addon.js';
import '../input/input.js';
import '../input/props.js';
import '../input/input-group.js';
import '../input/type.js';
import '../config-provider/index.js';
import '../config-provider/config-provider.js';
import './hooks/useDragSort.js';
import 'sortablejs';
import '../_common/js/utils/swapDragArrayElement.js';
import './hooks/useAsyncLoading.js';
import './hooks/useEditableCell.js';
import './editable-cell.js';
import 'lodash/set';
import './tr.js';
import 'lodash/upperFirst';
import 'lodash/pick';
import './hooks/useFixed.js';
import '../_common/js/utils/getScrollbarWidth.js';
import './hooks/useLazyLoad.js';
import '../_common/js/utils/observe.js';
import '../form/form-model.js';
import '@babel/runtime/helpers/asyncToGenerator';
import '@babel/runtime/regenerator';
import '../_chunks/dep-8600dc2e.js';
import './hooks/useColumnResize.js';
import './hooks/usePagination.js';
import '../pagination/index.js';
import '../pagination/pagination.js';
import '../input-number/index.js';
import '../input-number/input-number.js';
import '../input-number/props.js';
import '../input-number/type.js';
import '../select/index.js';
import '../select/select.js';
import '../tag/index.js';
import '../tag/tag.js';
import '../tag/props.js';
import '../tag/check-tag.js';
import '../tag/check-tag-props.js';
import '../tag/type.js';
import '../common-components/fake-arrow.js';
import '../select/option.js';
import '../select/option-props.js';
import '../select/props.js';
import '../select/optionGroup.js';
import '../select/option-group-props.js';
import '../select/type.js';
import '../pagination/props.js';
import '../pagination/type.js';
import '../hooks/useVirtualScroll.js';
import './tbody.js';
import './hooks/useStyle.js';
import '../hooks/useCommonClassName.js';
import '../affix/index.js';
import '../affix/affix.js';
import '../affix/props.js';
import '../affix/type.js';
import './thead.js';
import './tfoot.js';
import './hooks/tree-store.js';
import '@babel/runtime/helpers/classCallCheck';
import '@babel/runtime/helpers/createClass';

var _excluded = ["store", "dataSource", "formatTreeColumn", "swapData"];

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 PRIMARY_B_EVENTS = ["change", "page-change", "expand-change", "filter-change", "sort-change", "data-change", "async-loading-click"];
var PRIMARY_ALL_EVENTS = BASE_TABLE_ALL_EVENTS.concat(PRIMARY_B_EVENTS);
var _EnhancedTable = defineComponent({
  name: "TEnhancedTable",
  props: _objectSpread(_objectSpread(_objectSpread({}, baseTableProps), primaryTableProps), enhancedTableProps),
  setup: function setup(props, context) {
    var _useTreeData = useTreeData(props, context),
        store = _useTreeData.store,
        dataSource = _useTreeData.dataSource,
        formatTreeColumn = _useTreeData.formatTreeColumn,
        swapData = _useTreeData.swapData,
        treeInstanceFunctions = _objectWithoutProperties(_useTreeData, _excluded);

    var treeDataMap = ref(store.value.treeDataMap);

    var _useTreeSelect = useTreeSelect(props, treeDataMap),
        onInnerSelectChange = _useTreeSelect.onInnerSelectChange;

    var getColumns = function getColumns(columns) {
      var arr = [];

      for (var i = 0, len = columns.length; i < len; i++) {
        var _item$children, _item$children2;

        var item = _objectSpread({}, columns[i]);

        item = formatTreeColumn(item);

        if ((_item$children = item.children) !== null && _item$children !== void 0 && _item$children.length) {
          item.children = getColumns(item.children);
        }

        if (!item.children || (_item$children2 = item.children) !== null && _item$children2 !== void 0 && _item$children2.length) {
          arr.push(item);
        }
      }

      return arr;
    };

    var tColumns = computed(function () {
      var isTreeData = !props.tree || !Object.keys(props.tree).length;
      return isTreeData ? props.columns : getColumns(props.columns);
    });

    var onDragSortChange = function onDragSortChange(params) {
      var _props$onDragSort;

      if (props.beforeDragSort && !props.beforeDragSort(params)) return;
      swapData({
        current: params.current,
        target: params.target,
        currentIndex: params.currentIndex,
        targetIndex: params.targetIndex
      });
      (_props$onDragSort = props.onDragSort) === null || _props$onDragSort === void 0 ? void 0 : _props$onDragSort.call(props, params);
      context.emit("drag-sort", params);
    };

    return _objectSpread({
      store: store,
      dataSource: dataSource,
      tColumns: tColumns,
      onDragSortChange: onDragSortChange,
      onInnerSelectChange: onInnerSelectChange
    }, treeInstanceFunctions);
  },
  methods: {
    getListener: function getListener() {
      var _this = this;

      var listeners = {};
      PRIMARY_ALL_EVENTS.forEach(function (key) {
        listeners[key] = function () {
          for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
            args[_key] = arguments[_key];
          }

          _this.$emit.apply(_this, [key].concat(args));
        };
      });
      return listeners;
    }
  },
  render: function render() {
    var h = arguments[0];

    var props = _objectSpread(_objectSpread({}, this.$props), {}, {
      data: this.dataSource,
      columns: this.tColumns,
      disableDataPage: Boolean(this.tree && Object.keys(this.tree).length)
    });

    var on = _objectSpread(_objectSpread({}, this.getListener()), {}, {
      "select-change": this.onInnerSelectChange,
      "drag-sort": this.onDragSortChange
    });

    return h(_PrimaryTable, helper([{
      "scopedSlots": this.$scopedSlots
    }, {
      "props": props
    }, {}, {
      "on": on
    }, {}, this.$attrs]));
  }
});

export { _EnhancedTable as default };
//# sourceMappingURL=enhanced-table.js.map
