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

import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, ref, computed, getCurrentInstance, createVNode, mergeProps } from 'vue';
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 'lodash/get';
import 'lodash/omit';
import '../hooks/tnode.js';
import 'lodash/isFunction';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../utils/render-tnode.js';
import 'lodash/isEmpty';
import 'lodash/isString';
import 'lodash/isObject';
import './base-table.js';
import 'lodash/pick';
import '../hooks/useVirtualScrollNew.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/slicedToArray';
import '../hooks/useResizeObserver.js';
import '../loading/index.js';
import '../utils/withInstall.js';
import '../loading/directive.js';
import '../loading/plugin.js';
import '../utils/dom.js';
import '../_chunks/dep-2e5d8948.js';
import 'lodash/isArray';
import '../utils/easing.js';
import '../hooks/useConfig.js';
import '../config-provider/useConfig.js';
import 'lodash/cloneDeep';
import '../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '@babel/runtime/helpers/typeof';
import 'dayjs';
import '../_chunks/dep-4580aabe.js';
import '../config-provider/type.js';
import '../loading/loading.js';
import '../hooks/useTeleport.js';
import '../loading/props.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 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';
import '../loading/style';
import '../loading/type.js';
import '../affix/index.js';
import '../affix/affix.js';
import '@babel/runtime/helpers/asyncToGenerator';
import '@babel/runtime/regenerator';
import '../affix/props.js';
import '../affix/style';
import '../affix/type.js';
import './hooks/useTableHeader.js';
import './ellipsis.js';
import 'lodash/debounce';
import '../tooltip/index.js';
import '../tooltip/tooltip.js';
import '../popup/props.js';
import '../popup/index.js';
import '../popup/popup.js';
import '@popperjs/core';
import '../hooks/index.js';
import '../hooks/icon.js';
import '../hooks/slot.js';
import '../hooks/useCommonClassName.js';
import '../hooks/useDefaultValue.js';
import '../hooks/useDestroyOnClose.js';
import '../hooks/useKeepAnimation.js';
import '../hooks/useRipple.js';
import '../utils/set-style.js';
import '../hooks/useVirtualScroll.js';
import '../hooks/useVModel.js';
import '../popup/container.js';
import '../popup/style';
import '../popup/type.js';
import '../tooltip/util.js';
import '../tooltip/props.js';
import '../tooltip/style';
import '../tooltip/type.js';
import './hooks/useClassName.js';
import './hooks/useMultiHeader.js';
import './hooks/useColumnResize.js';
import './hooks/useFixed.js';
import '../_common/js/log/index.js';
import '../_common/js/log/log.js';
import '../_common/js/utils/getScrollbarWidth.js';
import './hooks/usePagination.js';
import '../pagination/index.js';
import '../pagination/pagination.js';
import 'lodash/isNaN';
import '@ldesign/icons-vue-next';
import '../hooks/useGlobalIcon.js';
import '../input-number/index.js';
import '../input-number/input-number.js';
import '../button/index.js';
import '../button/button.js';
import '../form/hooks.js';
import '../button/props.js';
import '../button/style';
import '../button/type.js';
import '../input/index.js';
import '../input/input.js';
import '../input/props.js';
import '../input/useInput.js';
import '../form/const.js';
import '../input/useLengthLimit.js';
import '../input/useInputEventHandler.js';
import '../input/useInputWidth.js';
import '../input/input-group.js';
import '../input/input-group-props.js';
import '../input/style';
import '../input/type.js';
import '../input-number/props.js';
import '../input-number/useInputNumber.js';
import '../_common/js/input-number/number.js';
import 'lodash/isNil';
import '../_common/js/input-number/large-number.js';
import '../input-number/style';
import '../input-number/type.js';
import '../select/index.js';
import '../select/select.js';
import 'lodash/intersection';
import '../common-components/fake-arrow.js';
import '../select-input/index.js';
import '../select-input/select-input.js';
import '../select-input/props.js';
import '../select-input/useSingle.js';
import '../select-input/useMultiple.js';
import '../tag-input/index.js';
import '../tag-input/tag-input.js';
import '../tag-input/props.js';
import '../tag-input/hooks/useTagScroll.js';
import '../tag-input/useTagList.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/style';
import '../tag/type.js';
import '../tag-input/hooks/useHover.js';
import '../tag-input/hooks/useDragSorter.js';
import '../tag-input/style';
import '../tag-input/type.js';
import '../select-input/useOverlayInnerStyle.js';
import '../select-input/style';
import '../select-input/type.js';
import '../select/props.js';
import '../select/select-panel.js';
import '../select/option.js';
import '../checkbox/index.js';
import '../checkbox/checkbox.js';
import '../checkbox/props.js';
import '../checkbox/constants.js';
import '../checkbox/group.js';
import '../checkbox/checkbox-group-props.js';
import '../checkbox/style';
import '../checkbox/type.js';
import '../select/option-props.js';
import '../select/helper.js';
import '../select/optionGroup.js';
import '../select/option-group-props.js';
import '../select/hooks/usePanelVirtualScroll.js';
import '../select/hooks/useSelectOptions.js';
import '../select/style';
import '../select/type.js';
import '../input-adornment/index.js';
import '../input-adornment/input-adornment.js';
import '../input-adornment/props.js';
import '../input-adornment/style';
import '../input-adornment/type.js';
import '../pagination/props.js';
import '../pagination/usePaginationClasses.js';
import '../pagination/useMoreAction.js';
import '../pagination/pagination-mini.js';
import '../pagination/pagination-mini-props.js';
import '../pagination/style';
import '../pagination/type.js';
import './hooks/useAffix.js';
import './tbody.js';
import './tr.js';
import 'lodash/upperFirst';
import './utils.js';
import './hooks/useLazyLoad.js';
import '../_common/js/utils/observe.js';
import './hooks/useRowspanAndColspan.js';
import './hooks/useStyle.js';
import './thead.js';
import './tfoot.js';
import './hooks/useColumnController.js';
import '../dialog/plugin.js';
import '../dialog/dialog.js';
import '../dialog/stack.js';
import '../dialog/hooks.js';
import '../dialog/props.js';
import './hooks/useRowExpand.js';
import './hooks/useRowSelect.js';
import '../_common/js/table/utils.js';
import '../radio/index.js';
import '../radio/radio.js';
import '../utils/helper.js';
import '../radio/constants.js';
import '../radio/props.js';
import '../radio/group.js';
import '../watermark/hooks.js';
import '../radio/radio-group-props.js';
import '../radio/useKeyboard.js';
import '../radio/radio-button.js';
import '../radio/style';
import '../radio/type.js';
import './hooks/useSorter.js';
import './sorter-button.js';
import './hooks/useFilter.js';
import './filter-controller.js';
import './hooks/useDragSort.js';
import 'sortablejs';
import '../_common/js/utils/swapDragArrayElement.js';
import './hooks/useAsyncLoading.js';
import './editable-cell.js';
import 'lodash/set';
import '../form/form-model.js';
import 'lodash/isBoolean';
import './hooks/useEditableRow.js';
import '../_common/js/table/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 _EnhancedTable = defineComponent({
  name: "TEnhancedTable",
  props: _objectSpread(_objectSpread(_objectSpread({}, baseTableProps), primaryTableProps), enhancedTableProps),
  setup: function setup(props, context) {
    var primaryTableRef = ref(null);
    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),
      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 = 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);
    };
    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.expose(_objectSpread(_objectSpread({
      store: store.value,
      dataSource: dataSource.value
    }, treeInstanceFunctions), {}, {
      primaryTableRef: primaryTableRef,
      validateRowData: function validateRowData(rowValue) {
        return primaryTableRef.value.validateRowData(rowValue);
      },
      validateTableData: function validateTableData() {
        return primaryTableRef.value.validateTableData();
      },
      clearValidateData: function clearValidateData() {
        primaryTableRef.value.clearValidateData();
      },
      refreshTable: function refreshTable() {
        primaryTableRef.value.refreshTable();
      },
      scrollToElement: function scrollToElement(data) {
        primaryTableRef.value.scrollToElement(data);
      }
    }));
    return function () {
      var _props$tree2;
      var _getCurrentInstance = getCurrentInstance(),
        vnode = _getCurrentInstance.vnode;
      var enhancedProps = _objectSpread(_objectSpread({}, vnode.props), {}, {
        rowKey: props.rowKey || "id",
        data: dataSource.value,
        columns: tColumns.value,
        indeterminateSelectedRowKeys: tIndeterminateSelectedRowKeys.value,
        disableDataPage: Boolean(props.tree && Object.keys(props.tree).length),
        onSelectChange: onInnerSelectChange,
        onDragSort: onDragSortChange
      });
      if ((_props$tree2 = props.tree) !== null && _props$tree2 !== void 0 && _props$tree2.expandTreeNodeOnClick) enhancedProps.onRowClick = onEnhancedTableRowClick;
      return createVNode(_PrimaryTable, mergeProps(enhancedProps, {
        "ref": primaryTableRef
      }), context.slots);
    };
  }
});

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