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

import { h as helper } from '../_chunks/dep-b6ac6e96.js';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, toRefs, ref, computed, onMounted, watch, h } from '@vue/composition-api';
import get from 'lodash/get';
import omit from 'lodash/omit';
import { useTNodeJSX } from '../hooks/tnode.js';
import baseTableProps from './base-table-props.js';
import primaryTableProps from './primary-table-props.js';
import _BaseTable, { BASE_TABLE_ALL_EVENTS } from './base-table.js';
export { BASE_TABLE_ALL_EVENTS } from './base-table.js';
import useColumnController from './hooks/useColumnController.js';
import useRowExpand from './hooks/useRowExpand.js';
import useTableHeader, { renderTitle } from './hooks/useTableHeader.js';
import useRowSelect from './hooks/useRowSelect.js';
import useSorter from './hooks/useSorter.js';
import useFilter from './hooks/useFilter.js';
import useDragSort from './hooks/useDragSort.js';
import useAsyncLoading from './hooks/useAsyncLoading.js';
import useClassName from './hooks/useClassName.js';
import useEditableCell from './hooks/useEditableCell.js';
import useRowEdit from './hooks/useEditableRow.js';
import useStyle from './hooks/useStyle.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 '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 'vue';
import 'lodash/capitalize';
import '../loading/directive.js';
import 'lodash/mapKeys';
import 'lodash/isEqual';
import '../loading/plugin.js';
import '../config.js';
import '../utils/dom.js';
import 'raf';
import '../utils/easing.js';
import '../loading/loading.js';
import '../utils/render-tnode.js';
import '@babel/runtime/helpers/typeof';
import '../utils/transfer-dom.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 '../_chunks/dep-2cb61c79.js';
import 'dayjs';
import '../utils/mixins.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 '@babel/runtime/helpers/objectWithoutProperties';
import 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';
import 'lodash/isArray';
import '../config-provider/useConfig.js';
import '../affix/index.js';
import '../affix/affix.js';
import '../affix/props.js';
import '../_common/js/log/log.js';
import './hooks/useColumnResize.js';
import './hooks/useFixed.js';
import 'lodash/debounce';
import '../_common/js/utils/getScrollbarWidth.js';
import './hooks/usePagination.js';
import '../pagination/index.js';
import '../utils/map-props.js';
import '../pagination/pagination.js';
import '@ldesign/icons-vue';
import '../input-number/index.js';
import '../input-number/input-number.js';
import '../button/index.js';
import '../button/button.js';
import '../utils/ripple.js';
import '../button/props.js';
import '../input/index.js';
import '../input/input.js';
import '../utils/helper.js';
import '../utils/event.js';
import '../input/props.js';
import '../input/input-group.js';
import '../hooks/useGlobalIcon.js';
import '../input-number/props.js';
import '../input-number/useInputNumber.js';
import '../hooks/useCommonClassName.js';
import '../hooks/useVModel.js';
import '../_common/js/input-number/number.js';
import 'lodash/isNil';
import '../_common/js/input-number/large-number.js';
import '../hooks/useFormDisabled.js';
import '../select/index.js';
import '../select/select.js';
import 'lodash/cloneDeep';
import '../hooks/useDefaultValue.js';
import '../popup/index.js';
import '../popup/popup.js';
import '@popperjs/core';
import '../popup/props.js';
import '../popup/container.js';
import '../popup/utils.js';
import '../popup/trigger.js';
import '../popup/plugin.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 '../select-input/index.js';
import '../select-input/select-input.js';
import '../select-input/props.js';
import '../select-input/useSingle.js';
import '../hooks/useConfig.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-input/hooks/useHover.js';
import '../tag-input/hooks/useDragSorter.js';
import '../select-input/useOverlayInnerStyle.js';
import '../common-components/fake-arrow.js';
import '../select/option.js';
import '../checkbox/index.js';
import '../checkbox/group.js';
import 'lodash/intersection';
import '../checkbox/checkbox.js';
import '../checkbox/props.js';
import '../checkbox/checkbox-group-props.js';
import '../hooks/useLazyLoad.js';
import '../_common/js/utils/observe.js';
import '../select/util.js';
import '../select/option-props.js';
import '../select/select-panel.js';
import '../hooks/useVirtualScroll.js';
import '../select/hooks/useSelectOptions.js';
import '../select/props.js';
import '../select/optionGroup.js';
import '../select/option-group-props.js';
import '../input-adornment/index.js';
import '../input-adornment/input-adornment.js';
import '../input-adornment/props.js';
import '../pagination/props.js';
import '../pagination/pagination-mini.js';
import '../pagination/pagination-mini-props.js';
import './hooks/useAffix.js';
import './tbody.js';
import './tr.js';
import 'lodash/upperFirst';
import './utils.js';
import './ellipsis.js';
import '../tooltip/index.js';
import '../tooltip/tooltip.js';
import '../tooltip/props.js';
import './hooks/useRowspanAndColspan.js';
import './thead.js';
import './tfoot.js';
import './hooks/useMultiHeader.js';
import '../dialog/plugin.js';
import '../config-provider/config-provider.js';
import '../dialog/dialog.js';
import 'lodash/throttle';
import '../hooks/useDestroyOnClose.js';
import '../dialog/stack.js';
import '../dialog/props.js';
import '../dialog/actions.js';
import '../radio/index.js';
import '../radio/radio.js';
import '../radio/props.js';
import '../radio/group.js';
import '../radio/radio-group-props.js';
import '../radio/radio-button.js';
import './sorter-button.js';
import './filter-controller.js';
import 'lodash/lowerFirst';
import 'sortablejs';
import '../_common/js/utils/swapDragArrayElement.js';
import './editable-cell.js';
import 'lodash/set';
import '../form/form-model.js';
import '@babel/runtime/helpers/asyncToGenerator';
import '@babel/runtime/regenerator';

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 OMIT_PROPS = ["hideSortTips", "dragSort", "defaultExpandedRowKeys", "defaultSelectedRowKeys", "columnController", "filterRow", "sortOnRowDraggable", "expandOnRowClick", "multipleSort", "expandIcon", "reserveSelectedRowOnPaginate", "selectOnRowClick", "onChange", "onAsyncLoadingClick", "onChange", "onColumnChange", "onColumnControllerVisibleChange", "onDataChange", "onDisplayColumnsChange", "onDragSort", "onExpandChange", "onFilterChange", "onSelectChange", "onSortChange"];
var _PrimaryTable = defineComponent({
  name: "TPrimaryTable",
  props: _objectSpread(_objectSpread({}, baseTableProps), primaryTableProps),
  setup: function setup(props, context) {
    var renderTNode = useTNodeJSX();
    var _toRefs = toRefs(props),
      columns = _toRefs.columns;
    var primaryTableRef = ref(null);
    var _useClassName = useClassName(),
      classPrefix = _useClassName.classPrefix,
      tableDraggableClasses = _useClassName.tableDraggableClasses,
      tableBaseClass = _useClassName.tableBaseClass,
      tableSelectedClasses = _useClassName.tableSelectedClasses,
      tableSortClasses = _useClassName.tableSortClasses;
    var _useStyle = useStyle(props),
      sizeClassNames = _useStyle.sizeClassNames;
    var _useColumnController = useColumnController(props, context),
      tDisplayColumns = _useColumnController.tDisplayColumns,
      renderColumnController = _useColumnController.renderColumnController;
    var _useRowExpand = useRowExpand(props, context),
      showExpandedRow = _useRowExpand.showExpandedRow,
      showExpandIconColumn = _useRowExpand.showExpandIconColumn,
      getExpandColumn = _useRowExpand.getExpandColumn,
      renderExpandedRow = _useRowExpand.renderExpandedRow,
      onInnerExpandRowClick = _useRowExpand.onInnerExpandRowClick;
    var _useSorter = useSorter(props, context),
      renderSortIcon = _useSorter.renderSortIcon;
    var _useRowSelect = useRowSelect(props, tableSelectedClasses),
      selectedRowClassNames = _useRowSelect.selectedRowClassNames,
      currentPaginateData = _useRowSelect.currentPaginateData,
      formatToRowSelectColumn = _useRowSelect.formatToRowSelectColumn,
      setTSelectedRowKeys = _useRowSelect.setTSelectedRowKeys,
      onInnerSelectRowClick = _useRowSelect.onInnerSelectRowClick;
    var _useFilter = useFilter(props, context),
      hasEmptyCondition = _useFilter.hasEmptyCondition,
      isTableOverflowHidden = _useFilter.isTableOverflowHidden,
      renderFilterIcon = _useFilter.renderFilterIcon,
      renderFirstFilterRow = _useFilter.renderFirstFilterRow,
      setFilterPrimaryTableRef = _useFilter.setFilterPrimaryTableRef;
    var _useDragSort = useDragSort(props, context),
      isRowHandlerDraggable = _useDragSort.isRowHandlerDraggable,
      isRowDraggable = _useDragSort.isRowDraggable,
      isColDraggable = _useDragSort.isColDraggable,
      setDragSortPrimaryTableRef = _useDragSort.setDragSortPrimaryTableRef,
      setDragSortColumns = _useDragSort.setDragSortColumns;
    var _useTableHeader = useTableHeader(props),
      renderTitleWidthIcon = _useTableHeader.renderTitleWidthIcon;
    var _useAsyncLoading = useAsyncLoading(props, context),
      renderAsyncLoading = _useAsyncLoading.renderAsyncLoading;
    var _useEditableCell = useEditableCell(props, context),
      renderEditableCell = _useEditableCell.renderEditableCell;
    var _useEditableRow = useRowEdit(props, context),
      errorListMap = _useEditableRow.errorListMap,
      editableKeysMap = _useEditableRow.editableKeysMap,
      validateRowData = _useEditableRow.validateRowData,
      validateTableData = _useEditableRow.validateTableData,
      onRuleChange = _useEditableRow.onRuleChange,
      clearValidateData = _useEditableRow.clearValidateData,
      onPrimaryTableRowValidate = _useEditableRow.onPrimaryTableRowValidate,
      onPrimaryTableRowEdit = _useEditableRow.onPrimaryTableRowEdit,
      onPrimaryTableCellEditChange = _useEditableRow.onPrimaryTableCellEditChange;
    var primaryTableClasses = computed(function () {
      var _ref;
      return _ref = {}, _defineProperty(_ref, tableDraggableClasses.colDraggable, isColDraggable.value), _defineProperty(_ref, tableDraggableClasses.rowHandlerDraggable, isRowHandlerDraggable.value), _defineProperty(_ref, tableDraggableClasses.rowDraggable, isRowDraggable.value), _defineProperty(_ref, tableBaseClass.overflowVisible, isTableOverflowHidden.value === false), _defineProperty(_ref, tableBaseClass.tableRowEdit, props.editableRowKeys), _ref;
    });
    var tRowClassNames = computed(function () {
      var tClassNames = [props.rowClassName, selectedRowClassNames.value];
      return tClassNames.filter(function (v) {
        return v;
      });
    });
    var tRowAttributes = computed(function () {
      var tAttributes = [props.rowAttributes];
      if (isRowHandlerDraggable.value || isRowDraggable.value) tAttributes.push(function (_ref2) {
        var row = _ref2.row;
        return {
          "data-id": get(row, props.rowKey || "id")
        };
      });
      return tAttributes.filter(function (v) {
        return v;
      });
    });
    onMounted(function () {
      setFilterPrimaryTableRef(primaryTableRef.value);
      setDragSortPrimaryTableRef(primaryTableRef.value);
    });
    watch(primaryTableRef, function () {
      setFilterPrimaryTableRef(primaryTableRef.value);
      setDragSortPrimaryTableRef(primaryTableRef.value);
    });
    var getColumns = function getColumns(columns2) {
      var arr = [];
      var _loop = function _loop() {
        var _item$children, _tDisplayColumns$valu, _item$edit, _item$children2, _item$children3;
        var item = _objectSpread({}, columns2[i]);
        var isDisplayColumn = ((_item$children = item.children) === null || _item$children === void 0 ? void 0 : _item$children.length) || ((_tDisplayColumns$valu = tDisplayColumns.value) === null || _tDisplayColumns$valu === void 0 ? void 0 : _tDisplayColumns$valu.includes(item.colKey));
        if (!isDisplayColumn && props.columnController) return "continue";
        item = formatToRowSelectColumn(item);
        var sort = props.sort;
        if (item.sorter && props.showSortColumnBgColor) {
          var sorts = Array.isArray(sort) ? sort : [sort];
          var sortedColumn = sorts.find(function (sort2) {
            return sort2 && sort2.sortBy === item.colKey && sort2.descending !== void 0;
          });
          if (sortedColumn) {
            item.className = Array.isArray(item.className) ? item.className.concat(tableSortClasses.sortColumn) : [item.className, tableSortClasses.sortColumn];
          }
        }
        if (item.sorter || item.filter) {
          var titleContent = renderTitle(h, context.slots, item, i);
          var _item = item,
            ellipsisTitle = _item.ellipsisTitle;
          item.title = function (h2, p) {
            var _primaryTableRef$valu, _primaryTableRef$valu2;
            var sortIcon = item.sorter ? renderSortIcon(h2, p) : null;
            var filterIcon = item.filter ? renderFilterIcon(h2, p) : null;
            var attach = (_primaryTableRef$valu = primaryTableRef.value) === null || _primaryTableRef$valu === void 0 ? void 0 : (_primaryTableRef$valu2 = _primaryTableRef$valu.$refs) === null || _primaryTableRef$valu2 === void 0 ? void 0 : _primaryTableRef$valu2.tableContentRef;
            return renderTitleWidthIcon(h2, [titleContent, sortIcon, filterIcon], p.col, p.colIndex, ellipsisTitle, attach, {
              classPrefix: classPrefix,
              ellipsisOverlayClassName: props.size !== "medium" ? sizeClassNames[props.size] : ""
            });
          };
          item.ellipsisTitle = false;
        }
        if ((_item$edit = item.edit) !== null && _item$edit !== void 0 && _item$edit.component) {
          var oldCell = item.cell;
          item.cell = function (h2, p) {
            var cellProps = _objectSpread(_objectSpread({}, p), {}, {
              oldCell: oldCell,
              tableBaseClass: tableBaseClass,
              cellEmptyContent: props.cellEmptyContent,
              onChange: onPrimaryTableRowEdit,
              onValidate: onPrimaryTableRowValidate,
              onRuleChange: onRuleChange,
              onEditableChange: onPrimaryTableCellEditChange
            });
            if (props.editableRowKeys) {
              var _errorListMap$value;
              var rowValue = get(p.row, props.rowKey || "id");
              cellProps.editable = editableKeysMap.value[rowValue] || false;
              var key = [rowValue, p.col.colKey].join("__");
              var errorList = (_errorListMap$value = errorListMap.value) === null || _errorListMap$value === void 0 ? void 0 : _errorListMap$value[key];
              errorList && (cellProps.errors = errorList);
            }
            if (props.editableCellState) cellProps.readonly = !props.editableCellState(p);
            return renderEditableCell(h2, cellProps);
          };
        }
        if ((_item$children2 = item.children) !== null && _item$children2 !== void 0 && _item$children2.length) item.children = getColumns(item.children);
        if (!item.children || (_item$children3 = item.children) !== null && _item$children3 !== void 0 && _item$children3.length) arr.push(item);
      };
      for (var i = 0, len = columns2.length; i < len; i++) {
        var _ret = _loop();
        if (_ret === "continue") continue;
      }
      return arr;
    };
    var tColumns = computed(function () {
      var cols = getColumns(columns.value);
      if (showExpandIconColumn.value) cols.unshift(getExpandColumn(h));
      return cols;
    });
    var onInnerPageChange = function onInnerPageChange(pageInfo, newData) {
      var _props$onPageChange, _props$onChange;
      currentPaginateData.value = newData;
      (_props$onPageChange = props.onPageChange) === null || _props$onPageChange === void 0 ? void 0 : _props$onPageChange.call(props, pageInfo, newData);
      context.emit("page-change", pageInfo, newData);
      var changeParams = [{
        pagination: pageInfo
      }, {
        trigger: "pagination",
        currentData: newData
      }];
      (_props$onChange = props.onChange) === null || _props$onChange === void 0 ? void 0 : _props$onChange.call.apply(_props$onChange, [props].concat(changeParams));
      context.emit.apply(context, ["change"].concat(changeParams));
      if (!props.reserveSelectedRowOnPaginate) {
        setTSelectedRowKeys([], {
          selectedRowData: [],
          type: "uncheck",
          currentRowKey: "CLEAR_ON_PAGINATE"
        });
      }
    };
    var timer;
    var DURATION = 250;
    var onInnerRowClick = function onInnerRowClick(params) {
      if (!context.listeners["row-dblclick"]) {
        onInnerExpandRowClick(params);
        onInnerSelectRowClick(params);
        return;
      }
      if (timer) {
        clearTimeout(timer);
        timer = void 0;
      } else {
        timer = setTimeout(function () {
          onInnerExpandRowClick(params);
          onInnerSelectRowClick(params);
          timer = void 0;
        }, DURATION);
      }
    };
    return {
      tColumns: tColumns,
      showExpandedRow: showExpandedRow,
      tRowClassNames: tRowClassNames,
      hasEmptyCondition: hasEmptyCondition,
      primaryTableRef: primaryTableRef,
      tRowAttributes: tRowAttributes,
      primaryTableClasses: primaryTableClasses,
      errorListMap: errorListMap,
      scrollToElement: function scrollToElement(data) {
        primaryTableRef.value.virtualConfig.scrollToElement(data);
      },
      scrollColumnIntoView: function scrollColumnIntoView(colKey) {
        primaryTableRef.value.scrollColumnIntoView(colKey);
      },
      validateRowData: validateRowData,
      validateTableData: validateTableData,
      clearValidateData: clearValidateData,
      renderTNode: renderTNode,
      renderColumnController: renderColumnController,
      renderExpandedRow: renderExpandedRow,
      onInnerExpandRowClick: onInnerExpandRowClick,
      onInnerRowClick: onInnerRowClick,
      renderFirstFilterRow: renderFirstFilterRow,
      renderAsyncLoading: renderAsyncLoading,
      onInnerPageChange: onInnerPageChange,
      setDragSortColumns: setDragSortColumns
    };
  },
  methods: {
    getListener: function getListener() {
      var _this = this;
      var listener = {};
      BASE_TABLE_ALL_EVENTS.forEach(function (key) {
        listener[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 listener;
    },
    formatNode: function formatNode(api, renderInnerNode, condition, extra) {
      var h = this.$createElement;
      if (!condition) return this[api];
      var innerNode = renderInnerNode(h);
      var propsNode = this.renderTNode(api);
      if (innerNode && !propsNode) return function () {
        return innerNode;
      };
      if (propsNode && !innerNode) return function () {
        return propsNode;
      };
      if (innerNode && propsNode) {
        return function () {
          return extra !== null && extra !== void 0 && extra.reverse ? h("div", [innerNode, propsNode]) : h("div", [propsNode, innerNode]);
        };
      }
      return null;
    }
  },
  render: function render() {
    var h = arguments[0];
    var isColumnController = !!(this.columnController && Object.keys(this.columnController).length);
    var placement = isColumnController ? this.columnController.placement || "top-right" : "";
    var isBottomController = isColumnController && (placement === null || placement === void 0 ? void 0 : placement.indexOf("bottom")) !== -1;
    var topContent = this.formatNode("topContent", this.renderColumnController, isColumnController && !isBottomController);
    var bottomContent = this.formatNode("bottomContent", this.renderColumnController, isBottomController, {
      reverse: true
    });
    var firstFullRow = this.formatNode("firstFullRow", this.renderFirstFilterRow, !this.hasEmptyCondition);
    var lastFullRow = this.formatNode("lastFullRow", this.renderAsyncLoading, !!this.asyncLoading);
    var props = _objectSpread(_objectSpread({}, omit(this.$props, OMIT_PROPS)), {}, {
      rowClassName: this.tRowClassNames,
      rowAttributes: this.tRowAttributes,
      columns: this.tColumns,
      topContent: topContent,
      bottomContent: bottomContent,
      firstFullRow: firstFullRow,
      lastFullRow: lastFullRow,
      thDraggable: this.$props.dragSort === "col",
      renderExpandedRow: this.showExpandedRow ? this.renderExpandedRow : void 0
    });
    var on = _objectSpread(_objectSpread({}, this.getListener()), {}, {
      "page-change": this.onInnerPageChange
    });
    if (this.expandOnRowClick || this.selectOnRowClick) on["row-click"] = this.onInnerRowClick;
    on.LeafColumnsChange = this.setDragSortColumns;
    return h(_BaseTable, helper([{
      "ref": "primaryTableRef",
      "scopedSlots": this.$scopedSlots
    }, {
      "props": props
    }, {}, {
      "on": on
    }, {}, this.$attrs, {
      "class": this.primaryTableClasses
    }]));
  }
});

export { _PrimaryTable as default };
//# sourceMappingURL=primary-table.js.map
