/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @license MIT
 */

'use strict';

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

var helper = require('../_chunks/dep-c3e1ffac.js');
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var VueCompositionAPI = require('@vue/composition-api');
var table_baseTableProps = require('./base-table-props.js');
var table_primaryTableProps = require('./primary-table-props.js');
var table_enhancedTableProps = require('./enhanced-table-props.js');
var table_primaryTable = require('./primary-table.js');
var table_hooks_useTreeData = require('./hooks/useTreeData.js');
var table_hooks_useTreeSelect = require('./hooks/useTreeSelect.js');
var table_baseTable = require('./base-table.js');
require('lodash/get');
require('lodash/omit');
require('../hooks/tnode.js');
require('lodash/isEmpty');
require('lodash/isFunction');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../hooks/render-tnode.js');
require('lodash/isString');
require('lodash/isObject');
require('./hooks/useColumnController.js');
require('@babel/runtime/helpers/slicedToArray');
require('@babel/runtime/helpers/toConsumableArray');
require('@ldesign/icons-vue');
require('lodash/intersection');
require('../checkbox/index.js');
require('../utils/map-props.js');
require('vue');
require('../utils/withInstall.js');
require('lodash/capitalize');
require('../checkbox/group.js');
require('@babel/runtime/helpers/typeof');
require('../utils/event.js');
require('../utils/helper.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('../_chunks/dep-7c884501.js');
require('dayjs');
require('../utils/mixins.js');
require('../checkbox/checkbox.js');
require('../utils/render-tnode.js');
require('../checkbox/props.js');
require('../checkbox/checkbox-group-props.js');
require('../dialog/plugin.js');
require('../utils/dom.js');
require('raf');
require('../utils/easing.js');
require('../config-provider/config-provider.js');
require('lodash/cloneDeep');
require('../dialog/dialog.js');
require('lodash/isNumber');
require('lodash/throttle');
require('../button/index.js');
require('../button/button.js');
require('../loading/index.js');
require('../loading/directive.js');
require('lodash/mapKeys');
require('lodash/isEqual');
require('../loading/plugin.js');
require('../config.js');
require('../loading/loading.js');
require('../utils/transfer-dom.js');
require('../loading/props.js');
require('../loading/icon/gradient.js');
require('../_common/js/loading/circle-adapter.js');
require('../_common/js/utils/set-style.js');
require('../_common/js/utils/helper.js');
require('lodash/isNull');
require('lodash/isUndefined');
require('lodash/isArray');
require('../utils/ripple.js');
require('../button/props.js');
require('../hooks/useDestroyOnClose.js');
require('../_common/js/utils/getScrollbarWidth.js');
require('../dialog/stack.js');
require('../dialog/props.js');
require('../dialog/actions.js');
require('../config-provider/useConfig.js');
require('../hooks/useDefaultValue.js');
require('../hooks/useGlobalIcon.js');
require('./utils.js');
require('./hooks/useTableHeader.js');
require('./ellipsis.js');
require('lodash/debounce');
require('../tooltip/index.js');
require('../tooltip/tooltip.js');
require('../popup/props.js');
require('../popup/popup.js');
require('@popperjs/core');
require('../popup/container.js');
require('../popup/utils.js');
require('../popup/trigger.js');
require('../tooltip/props.js');
require('../_common/js/log/log.js');
require('./hooks/useClassName.js');
require('./hooks/useMultiHeader.js');
require('./hooks/useRowExpand.js');
require('./hooks/useRowSelect.js');
require('../radio/index.js');
require('../radio/radio.js');
require('../radio/props.js');
require('../radio/group.js');
require('../radio/radio-group-props.js');
require('../radio/radio-button.js');
require('./hooks/useSorter.js');
require('./sorter-button.js');
require('./hooks/useFilter.js');
require('./filter-controller.js');
require('lodash/lowerFirst');
require('../popup/index.js');
require('../popup/plugin.js');
require('../input/index.js');
require('../input/input.js');
require('../input/props.js');
require('../input/input-group.js');
require('./hooks/useDragSort.js');
require('sortablejs');
require('../_common/js/utils/swapDragArrayElement.js');
require('./hooks/useAsyncLoading.js');
require('./hooks/useEditableCell.js');
require('./editable-cell.js');
require('lodash/set');
require('../form/form-model.js');
require('@babel/runtime/helpers/asyncToGenerator');
require('@babel/runtime/regenerator');
require('./tr.js');
require('lodash/upperFirst');
require('lodash/pick');
require('../hooks/useLazyLoad.js');
require('../_common/js/utils/observe.js');
require('./hooks/useFixed.js');
require('./hooks/useRowspanAndColspan.js');
require('./hooks/useEditableRow.js');
require('./hooks/useStyle.js');
require('../hooks/useCommonClassName.js');
require('../hooks/useVirtualScrollNew.js');
require('../hooks/useResizeObserver.js');
require('../affix/index.js');
require('../affix/affix.js');
require('../affix/props.js');
require('./hooks/useColumnResize.js');
require('./hooks/usePagination.js');
require('../pagination/index.js');
require('../pagination/pagination.js');
require('../input-number/index.js');
require('../input-number/input-number.js');
require('../input-number/props.js');
require('../input-number/useInputNumber.js');
require('../hooks/useVModel.js');
require('../_common/js/input-number/number.js');
require('lodash/isNil');
require('../_common/js/input-number/large-number.js');
require('../hooks/useFormDisabled.js');
require('../select/index.js');
require('../select/select.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('../select-input/index.js');
require('../select-input/select-input.js');
require('../select-input/props.js');
require('../select-input/useSingle.js');
require('../hooks/useConfig.js');
require('../select-input/useMultiple.js');
require('../tag-input/index.js');
require('../tag-input/tag-input.js');
require('../tag-input/props.js');
require('../tag-input/hooks/useTagScroll.js');
require('../tag-input/useTagList.js');
require('../tag-input/hooks/useHover.js');
require('../tag-input/hooks/useDragSorter.js');
require('../select-input/useOverlayInnerStyle.js');
require('../common-components/fake-arrow.js');
require('../select/option.js');
require('../select/util.js');
require('../select/option-props.js');
require('../select/select-panel.js');
require('../hooks/useVirtualScroll.js');
require('../select/hooks/useSelectOptions.js');
require('../select/props.js');
require('../select/optionGroup.js');
require('../select/option-group-props.js');
require('../input-adornment/index.js');
require('../input-adornment/input-adornment.js');
require('../input-adornment/props.js');
require('../pagination/props.js');
require('../pagination/pagination-mini.js');
require('../pagination/pagination-mini-props.js');
require('./hooks/useAffix.js');
require('./tbody.js');
require('./thead.js');
require('./tfoot.js');
require('../_common/js/table/tree-store.js');
require('@babel/runtime/helpers/classCallCheck');
require('@babel/runtime/helpers/createClass');
require('../_common/js/table/utils.js');

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

var _objectWithoutProperties__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutProperties);
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);

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__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 PRIMARY_B_EVENTS = ["cell-click", "change", "page-change", "expand-change", "filter-change", "select-change", "sort-change", "data-change", "async-loading-click", "column-change", "column-controller-visible-change", "display-columns-change", "drag-sort", "row-edit", "row-validate", "validate"];
var PRIMARY_ALL_EVENTS = table_baseTable.BASE_TABLE_ALL_EVENTS.concat(PRIMARY_B_EVENTS);
var _EnhancedTable = VueCompositionAPI.defineComponent({
  name: "TEnhancedTable",
  props: _objectSpread(_objectSpread(_objectSpread({}, table_baseTableProps["default"]), table_primaryTableProps["default"]), table_enhancedTableProps["default"]),
  setup: function setup(props, context) {
    var primaryTableRef = VueCompositionAPI.ref();
    var _useTreeData = table_hooks_useTreeData["default"](props, context),
      store = _useTreeData.store,
      dataSource = _useTreeData.dataSource,
      formatTreeColumn = _useTreeData.formatTreeColumn,
      swapData = _useTreeData.swapData,
      treeInstanceFunctions = _objectWithoutProperties__default["default"](_useTreeData, _excluded);
    var treeDataMap = VueCompositionAPI.ref(store.value.treeDataMap);
    var _useTreeSelect = table_hooks_useTreeSelect["default"](props, treeDataMap),
      tIndeterminateSelectedRowKeys = _useTreeSelect.tIndeterminateSelectedRowKeys,
      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 = VueCompositionAPI.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);
    };
    var onEnhancedTableRowClick = function onEnhancedTableRowClick(p) {
      var _props$tree, _props$onRowClick;
      if ((_props$tree = props.tree) !== null && _props$tree !== void 0 && _props$tree.expandTreeNodeOnClick) {
        treeInstanceFunctions.toggleExpandData({
          row: p.row,
          rowIndex: p.index
        }, "row-click");
      }
      (_props$onRowClick = props.onRowClick) === null || _props$onRowClick === void 0 ? void 0 : _props$onRowClick.call(props, p);
      context.emit("row-click", p);
    };
    return _objectSpread({
      store: store,
      dataSource: dataSource,
      tColumns: tColumns,
      tIndeterminateSelectedRowKeys: tIndeterminateSelectedRowKeys,
      enhancedTableRef: primaryTableRef,
      primaryTableRef: primaryTableRef,
      onDragSortChange: onDragSortChange,
      onInnerSelectChange: onInnerSelectChange,
      onEnhancedTableRowClick: onEnhancedTableRowClick
    }, 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));
          if (key === "display-columns-change") _this.$emit.apply(_this, ["update:displayColumns"].concat(args));
        };
      });
      return listeners;
    }
  },
  render: function render() {
    var _this$tree;
    var h = arguments[0];
    var props = _objectSpread(_objectSpread({
      rowKey: this.rowKey || "id"
    }, this.$options.propsData), {}, {
      data: this.dataSource,
      columns: this.tColumns,
      indeterminateSelectedRowKeys: this.tIndeterminateSelectedRowKeys,
      disableDataPage: Boolean(this.tree && Object.keys(this.tree).length)
    });
    var on = _objectSpread(_objectSpread({}, this.getListener()), {}, {
      "select-change": this.onInnerSelectChange,
      "drag-sort": this.onDragSortChange
    });
    if ((_this$tree = this.tree) !== null && _this$tree !== void 0 && _this$tree.expandTreeNodeOnClick) on["row-click"] = this.onEnhancedTableRowClick;
    return h(table_primaryTable["default"], helper.helper([{
      "ref": "primaryTableRef",
      "scopedSlots": this.$scopedSlots
    }, {
      "props": props
    }, {}, {
      "on": on
    }, {}, this.$attrs]));
  }
});

exports["default"] = _EnhancedTable;
//# sourceMappingURL=enhanced-table.js.map
