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

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var vue = require('vue');
var get = require('lodash/get');
var omit = require('lodash/omit');
var hooks_tnode = require('../hooks/tnode.js');
var table_baseTableProps = require('./base-table-props.js');
var table_primaryTableProps = require('./primary-table-props.js');
var table_baseTable = require('./base-table.js');
var table_hooks_useColumnController = require('./hooks/useColumnController.js');
var table_hooks_useRowExpand = require('./hooks/useRowExpand.js');
var table_hooks_useTableHeader = require('./hooks/useTableHeader.js');
var table_hooks_useRowSelect = require('./hooks/useRowSelect.js');
var table_hooks_useSorter = require('./hooks/useSorter.js');
var table_hooks_useFilter = require('./hooks/useFilter.js');
var table_hooks_useDragSort = require('./hooks/useDragSort.js');
var table_hooks_useAsyncLoading = require('./hooks/useAsyncLoading.js');
var table_editableCell = require('./editable-cell.js');
var table_hooks_useClassName = require('./hooks/useClassName.js');
var table_hooks_useEditableRow = require('./hooks/useEditableRow.js');
var table_hooks_useStyle = require('./hooks/useStyle.js');
require('lodash/isFunction');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../utils/render-tnode.js');
require('lodash/isEmpty');
require('lodash/isString');
require('lodash/isObject');
require('lodash/pick');
require('../hooks/useVirtualScrollNew.js');
require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/helpers/slicedToArray');
require('../hooks/useResizeObserver.js');
require('../loading/index.js');
require('../utils/withInstall.js');
require('../loading/directive.js');
require('../loading/plugin.js');
require('../utils/dom.js');
require('../_chunks/dep-7f0559c3.js');
require('lodash/isArray');
require('../utils/easing.js');
require('../hooks/useConfig.js');
require('../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('dayjs');
require('../loading/loading.js');
require('../hooks/useTeleport.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('@babel/runtime/helpers/objectWithoutProperties');
require('lodash/isNull');
require('lodash/isUndefined');
require('lodash/isNumber');
require('../affix/index.js');
require('../affix/affix.js');
require('@babel/runtime/helpers/asyncToGenerator');
require('@babel/runtime/regenerator');
require('../affix/props.js');
require('./hooks/useColumnResize.js');
require('./hooks/useFixed.js');
require('lodash/debounce');
require('../_common/js/log/log.js');
require('../_common/js/utils/getScrollbarWidth.js');
require('./hooks/usePagination.js');
require('../pagination/index.js');
require('../pagination/pagination.js');
require('lodash/isNaN');
require('@ldesign/icons-vue-next');
require('../hooks/useGlobalIcon.js');
require('../input-number/index.js');
require('../input-number/input-number.js');
require('../button/index.js');
require('../button/button.js');
require('../hooks/useRipple.js');
require('../utils/set-style.js');
require('../hooks/useKeepAnimation.js');
require('../form/hooks.js');
require('../button/props.js');
require('../input/index.js');
require('../input/input.js');
require('../input/props.js');
require('../input/useInput.js');
require('../form/const.js');
require('../hooks/useVModel.js');
require('../input/useLengthLimit.js');
require('../input/useInputEventHandler.js');
require('../input/useInputWidth.js');
require('../input/input-group.js');
require('../input/input-group-props.js');
require('../input-number/props.js');
require('../input-number/useInputNumber.js');
require('../hooks/useCommonClassName.js');
require('../_common/js/input-number/number.js');
require('lodash/isNil');
require('../_common/js/input-number/large-number.js');
require('../select/index.js');
require('../select/select.js');
require('lodash/intersection');
require('../common-components/fake-arrow.js');
require('../select-input/index.js');
require('../select-input/select-input.js');
require('../popup/index.js');
require('../popup/popup.js');
require('@popperjs/core');
require('../popup/container.js');
require('../popup/props.js');
require('../select-input/props.js');
require('../select-input/useSingle.js');
require('../hooks/useDefaultValue.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/index.js');
require('../tag/tag.js');
require('../tag/props.js');
require('../tag/check-tag.js');
require('../tag/check-tag-props.js');
require('../tag-input/hooks/useHover.js');
require('../tag-input/hooks/useDragSorter.js');
require('../select-input/useOverlayInnerStyle.js');
require('../select/props.js');
require('../select/select-panel.js');
require('../select/option.js');
require('../checkbox/index.js');
require('../checkbox/checkbox.js');
require('../checkbox/props.js');
require('../checkbox/constants.js');
require('../checkbox/group.js');
require('../hooks/slot.js');
require('../checkbox/checkbox-group-props.js');
require('../select/option-props.js');
require('../select/helper.js');
require('../select/optionGroup.js');
require('../select/option-group-props.js');
require('../select/hooks/usePanelVirtualScroll.js');
require('../hooks/useVirtualScroll.js');
require('../select/hooks/useSelectOptions.js');
require('../input-adornment/index.js');
require('../input-adornment/input-adornment.js');
require('../input-adornment/props.js');
require('../pagination/props.js');
require('../pagination/usePaginationClasses.js');
require('../pagination/useMoreAction.js');
require('../pagination/pagination-mini.js');
require('../pagination/pagination-mini-props.js');
require('./hooks/useAffix.js');
require('./tbody.js');
require('./tr.js');
require('lodash/upperFirst');
require('./utils.js');
require('./ellipsis.js');
require('../tooltip/index.js');
require('../tooltip/tooltip.js');
require('../tooltip/util.js');
require('../tooltip/props.js');
require('./hooks/useLazyLoad.js');
require('../_common/js/utils/observe.js');
require('./hooks/useRowspanAndColspan.js');
require('./thead.js');
require('./tfoot.js');
require('./hooks/useMultiHeader.js');
require('../dialog/plugin.js');
require('../dialog/dialog.js');
require('../hooks/useDestroyOnClose.js');
require('../dialog/stack.js');
require('../dialog/hooks.js');
require('../dialog/props.js');
require('../_common/js/table/utils.js');
require('../radio/index.js');
require('../radio/radio.js');
require('../utils/helper.js');
require('../radio/constants.js');
require('../radio/props.js');
require('../radio/group.js');
require('../watermark/hooks.js');
require('../radio/radio-group-props.js');
require('../radio/useKeyboard.js');
require('../radio/radio-button.js');
require('./sorter-button.js');
require('./filter-controller.js');
require('sortablejs');
require('../_common/js/utils/swapDragArrayElement.js');
require('lodash/set');
require('../form/form-model.js');
require('lodash/isBoolean');

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

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var get__default = /*#__PURE__*/_interopDefaultLegacy(get);
var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);

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 OMIT_PROPS = ["hideSortTips", "dragSort", "defaultExpandedRowKeys", "defaultSelectedRowKeys", "columnController", "filterRow", "sortOnRowDraggable", "expandOnRowClick", "multipleSort", "expandIcon", "reserveSelectedRowOnPaginate", "selectOnRowClick", "onChange", "onAsyncLoadingClick", "onColumnChange", "onColumnControllerVisibleChange", "onDataChange", "onDisplayColumnsChange", "onDragSort", "onExpandChange", "onFilterChange", "onSelectChange", "onSortChange"];
var _PrimaryTable = vue.defineComponent({
  name: "TPrimaryTable",
  props: _objectSpread(_objectSpread({}, table_baseTableProps["default"]), table_primaryTableProps["default"]),
  setup: function setup(props, context) {
    var renderTNode = hooks_tnode.useTNodeJSX();
    var _toRefs = vue.toRefs(props),
      columns = _toRefs.columns,
      columnController = _toRefs.columnController;
    var primaryTableRef = vue.ref(null);
    var _useClassName = table_hooks_useClassName["default"](),
      classPrefix = _useClassName.classPrefix,
      tableDraggableClasses = _useClassName.tableDraggableClasses,
      tableBaseClass = _useClassName.tableBaseClass,
      tableSelectedClasses = _useClassName.tableSelectedClasses,
      tableSortClasses = _useClassName.tableSortClasses;
    var _useStyle = table_hooks_useStyle["default"](props),
      sizeClassNames = _useStyle.sizeClassNames;
    var _useColumnController = table_hooks_useColumnController["default"](props, context),
      tDisplayColumns = _useColumnController.tDisplayColumns,
      renderColumnController = _useColumnController.renderColumnController;
    var _useRowExpand = table_hooks_useRowExpand["default"](props, context),
      showExpandedRow = _useRowExpand.showExpandedRow,
      showExpandIconColumn = _useRowExpand.showExpandIconColumn,
      getExpandColumn = _useRowExpand.getExpandColumn,
      renderExpandedRow = _useRowExpand.renderExpandedRow,
      onInnerExpandRowClick = _useRowExpand.onInnerExpandRowClick;
    var _useSorter = table_hooks_useSorter["default"](props, context),
      renderSortIcon = _useSorter.renderSortIcon;
    var _useRowSelect = table_hooks_useRowSelect["default"](props, tableSelectedClasses),
      selectedRowClassNames = _useRowSelect.selectedRowClassNames,
      currentPaginateData = _useRowSelect.currentPaginateData,
      formatToRowSelectColumn = _useRowSelect.formatToRowSelectColumn,
      setTSelectedRowKeys = _useRowSelect.setTSelectedRowKeys,
      onInnerSelectRowClick = _useRowSelect.onInnerSelectRowClick;
    var _useFilter = table_hooks_useFilter["default"](props, context),
      hasEmptyCondition = _useFilter.hasEmptyCondition,
      isTableOverflowHidden = _useFilter.isTableOverflowHidden,
      renderFilterIcon = _useFilter.renderFilterIcon,
      renderFirstFilterRow = _useFilter.renderFirstFilterRow,
      setFilterPrimaryTableRef = _useFilter.setFilterPrimaryTableRef;
    var _useDragSort = table_hooks_useDragSort["default"](props, context),
      isRowHandlerDraggable = _useDragSort.isRowHandlerDraggable,
      isRowDraggable = _useDragSort.isRowDraggable,
      isColDraggable = _useDragSort.isColDraggable,
      setDragSortPrimaryTableRef = _useDragSort.setDragSortPrimaryTableRef,
      setDragSortColumns = _useDragSort.setDragSortColumns;
    var _useTableHeader = table_hooks_useTableHeader["default"](props),
      renderTitleWidthIcon = _useTableHeader.renderTitleWidthIcon;
    var _useAsyncLoading = table_hooks_useAsyncLoading["default"](props),
      renderAsyncLoading = _useAsyncLoading.renderAsyncLoading;
    var _useEditableRow = table_hooks_useEditableRow["default"](props),
      errorListMap = _useEditableRow.errorListMap,
      editableKeysMap = _useEditableRow.editableKeysMap,
      validateRowData = _useEditableRow.validateRowData,
      validateTableData = _useEditableRow.validateTableData,
      onRuleChange = _useEditableRow.onRuleChange,
      clearValidateData = _useEditableRow.clearValidateData,
      onPrimaryTableCellEditChange = _useEditableRow.onPrimaryTableCellEditChange;
    var primaryTableClasses = vue.computed(function () {
      var _ref;
      return _ref = {}, _defineProperty__default["default"](_ref, tableDraggableClasses.colDraggable, isColDraggable.value), _defineProperty__default["default"](_ref, tableDraggableClasses.rowHandlerDraggable, isRowHandlerDraggable.value), _defineProperty__default["default"](_ref, tableDraggableClasses.rowDraggable, isRowDraggable.value), _defineProperty__default["default"](_ref, tableBaseClass.overflowVisible, isTableOverflowHidden.value === false), _defineProperty__default["default"](_ref, tableBaseClass.tableRowEdit, props.editableRowKeys), _ref;
    });
    var tRowClassNames = vue.computed(function () {
      var tClassNames = [props.rowClassName, selectedRowClassNames.value];
      return tClassNames.filter(function (v) {
        return v;
      });
    });
    var tRowAttributes = vue.computed(function () {
      var tAttributes = [props.rowAttributes];
      if (isRowHandlerDraggable.value || isRowDraggable.value) tAttributes.push(function (_ref2) {
        var row = _ref2.row;
        return {
          "data-id": get__default["default"](row, props.rowKey || "id")
        };
      });
      return tAttributes.filter(function (v) {
        return v;
      });
    });
    vue.onMounted(function () {
      setFilterPrimaryTableRef(primaryTableRef.value);
      setDragSortPrimaryTableRef(primaryTableRef.value);
    });
    context.expose({
      validateRowData: validateRowData,
      validateTableData: validateTableData,
      clearValidateData: clearValidateData,
      refreshTable: function refreshTable() {
        primaryTableRef.value.refreshTable();
      },
      scrollToElement: function scrollToElement(data) {
        primaryTableRef.value.virtualConfig.scrollToElement(data);
      },
      scrollColumnIntoView: function scrollColumnIntoView(colKey) {
        primaryTableRef.value.scrollColumnIntoView(colKey);
      },
      baseTableRef: primaryTableRef
    });
    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 = table_hooks_useTableHeader.renderTitle(context.slots, item, i);
          var _item = item,
            ellipsisTitle = _item.ellipsisTitle;
          item.title = function (h2, p) {
            var _primaryTableRef$valu;
            var sortIcon = item.sorter ? renderSortIcon(p) : null;
            var filterIcon = item.filter ? renderFilterIcon(p) : null;
            var attach = (_primaryTableRef$valu = primaryTableRef.value) === null || _primaryTableRef$valu === void 0 ? void 0 : _primaryTableRef$valu.tableContentRef;
            return renderTitleWidthIcon([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: props.onRowEdit,
              onValidate: props.onRowValidate,
              onRuleChange: onRuleChange,
              onEditableChange: onPrimaryTableCellEditChange
            });
            if (props.editableRowKeys) {
              var _errorListMap$value;
              var rowValue = get__default["default"](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 vue.createVNode(table_editableCell["default"], cellProps, context.slots);
          };
        }
        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 = vue.computed(function () {
      var cols = getColumns(columns.value);
      if (showExpandIconColumn.value) cols.unshift(getExpandColumn());
      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);
      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));
      if (!props.reserveSelectedRowOnPaginate) {
        setTSelectedRowKeys([], {
          selectedRowData: [],
          type: "uncheck",
          currentRowKey: "CLEAR_ON_PAGINATE"
        });
      }
    };
    var timer;
    var DURATION = 250;
    var onInnerRowClick = function onInnerRowClick(params) {
      if (!props.onRowDblclick) {
        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 function () {
      var formatNode = function formatNode(api, renderInnerNode, condition, extra) {
        if (!condition) return props[api];
        var innerNode = renderInnerNode(vue.h);
        var propsNode = 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 ? vue.createVNode("div", null, [innerNode, propsNode]) : vue.createVNode("div", null, [propsNode, innerNode]);
          };
        }
        return null;
      };
      var isColumnController = !!(columnController.value && Object.keys(columnController.value).length);
      var placement = isColumnController ? columnController.value.placement || "top-right" : "";
      var isBottomController = isColumnController && (placement === null || placement === void 0 ? void 0 : placement.indexOf("bottom")) !== -1;
      var topContent = formatNode("topContent", renderColumnController, isColumnController && !isBottomController);
      var bottomContent = formatNode("bottomContent", renderColumnController, isBottomController, {
        reverse: true
      });
      var firstFullRow = formatNode("firstFullRow", renderFirstFilterRow, !hasEmptyCondition.value);
      var lastFullRow = formatNode("lastFullRow", renderAsyncLoading, !!props.asyncLoading);
      var baseTableProps2 = _objectSpread(_objectSpread({}, omit__default["default"](props, OMIT_PROPS)), {}, {
        rowClassName: tRowClassNames.value,
        rowAttributes: tRowAttributes.value,
        columns: tColumns.value,
        topContent: topContent,
        bottomContent: bottomContent,
        firstFullRow: firstFullRow,
        lastFullRow: lastFullRow,
        thDraggable: props.dragSort === "col",
        onPageChange: onInnerPageChange,
        renderExpandedRow: showExpandedRow.value ? renderExpandedRow : void 0
      });
      if (props.expandOnRowClick || props.selectOnRowClick) baseTableProps2.onRowClick = onInnerRowClick;
      return vue.createVNode(table_baseTable["default"], vue.mergeProps({
        "ref": primaryTableRef
      }, baseTableProps2, {
        "class": primaryTableClasses.value,
        "onLeafColumnsChange": setDragSortColumns
      }), context.slots);
    };
  }
});

exports.BASE_TABLE_ALL_EVENTS = table_baseTable.BASE_TABLE_ALL_EVENTS;
exports["default"] = _PrimaryTable;
//# sourceMappingURL=primary-table.js.map
