/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

'use strict';

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

var helper = require('../../../chunks/helper.js');
var VueCompositionAPI = require('@vue/composition-api');
var get = require('lodash/get');
var omit = require('lodash/omit');
var hooks_lnode = require('../../../hooks/lnode.js');
var components_table_props = require('../props.js');
var components_table_hooks_useColumnController = require('../hooks/useColumnController.js');
var components_table_hooks_useRowExpand = require('../hooks/useRowExpand.js');
var components_table_hooks_useTableHeader = require('../hooks/useTableHeader.js');
var components_table_hooks_useRowSelect = require('../hooks/useRowSelect.js');
var components_table_hooks_useSorter = require('../hooks/useSorter.js');
var components_table_hooks_useFilter = require('../hooks/useFilter.js');
var components_table_hooks_useDragSort = require('../hooks/useDragSort.js');
var components_table_hooks_useAsyncLoading = require('../hooks/useAsyncLoading.js');
var components_table_hooks_useClassName = require('../hooks/useClassName.js');
var components_table_hooks_useEditableCell = require('../hooks/useEditableCell.js');
var components_table_hooks_useEditableRow = require('../hooks/useEditableRow.js');
var components_table_hooks_useStyle = require('../hooks/useStyle.js');
var components_table_core_baseTable = require('./base-table.js');
require('lodash/isEmpty');
require('lodash/isFunction');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../../../hooks/render-lnode.js');
require('lodash');
require('@ldesign/icons-vue');
require('lodash/intersection');
require('../../checkbox/index.js');
require('../../../utils/map-props.js');
require('vue');
require('../../../utils/with-install.js');
require('../../../config.js');
require('../../checkbox/group.js');
require('../../../chunks/log.js');
require('../../../chunks/_commonjsHelpers-2e6815bd.js');
require('../../../utils/event.js');
require('../../../utils/helper.js');
require('../../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../../config-provider/context.js');
require('../../../chunks/zh_CN.js');
require('../../../utils/mixins.js');
require('../../checkbox/checkbox.js');
require('../../../utils/render-node.js');
require('../../checkbox/props.js');
require('../../dialog/plugin.js');
require('../../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../../utils/easing.js');
require('../../dialog/dialog.js');
require('lodash/isNumber');
require('lodash/throttle');
require('../../button/index.js');
require('../../button/button.js');
require('../../loading/index.js');
require('../../loading/loading.js');
require('../../../utils/transfer-dom.js');
require('../../loading/props.js');
require('../../loading/icon/gradient.js');
require('../../../chunks/defineProperty-838e4192.js');
require('../../../chunks/set-style.js');
require('../../../chunks/helper2.js');
require('../../loading/plugin.js');
require('../../../utils/ripple.js');
require('../../button/props.js');
require('../../../hooks/use-destroy-onclose.js');
require('../../dialog/props.js');
require('../../dialog/mixins/action.js');
require('lodash/isObject');
require('../../dialog/stack.js');
require('../../config-provider/useConfig.js');
require('../../../hooks/use-default-value.js');
require('../../../hooks/use-global-icon.js');
require('../utils.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('../../tooltip/props.js');
require('../hooks/useMultiHeader.js');
require('../../radio/index.js');
require('../../radio/radio.js');
require('../../radio/props.js');
require('../../radio/group.js');
require('../../radio/radio-button.js');
require('./sorter-button.js');
require('./filter-controller.js');
require('lodash/lowerFirst');
require('../../popup/index.js');
require('../../input/index.js');
require('../../input/input.js');
require('../../input/props.js');
require('../../input/group.js');
require('sortablejs');
require('./editable-cell.js');
require('lodash/set');
require('../../form/model.js');
require('../../../chunks/_commonjsHelpers.js');
require('./tr.js');
require('lodash/upperFirst');
require('lodash/pick');
require('../../../hooks/use-lazy-load.js');
require('../../../chunks/observe.js');
require('../hooks/useFixed.js');
require('../hooks/useRowspanAndColspan.js');
require('../../../hooks/use-common-classname.js');
require('../../../hooks/use-virtual-scroll.js');
require('../../affix/index.js');
require('../../affix/affix.js');
require('../../affix/props.js');
require('../hooks/useColumnResize.js');
require('../../../chunks/utils3.js');
require('../../../chunks/isFunction-91acade7.js');
require('../../../chunks/isObjectLike-c22c7e3b.js');
require('../../../chunks/isNumber-c4eb560e.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/hooks/use-input-number.js');
require('../../../chunks/isArray-cd7357b9.js');
require('../../../hooks/use-vmodel.js');
require('../../../hooks/use-form-disabled.js');
require('../../select/index.js');
require('../../select/select.js');
require('lodash/cloneDeep');
require('lodash/isArray');
require('../../tag/index.js');
require('../../tag/tag.js');
require('../../tag/props.js');
require('../../tag/check-tag.js');
require('../../select-input/index.js');
require('../../select-input/select-input.js');
require('../../select-input/props.js');
require('../../select-input/hooks/use-single.js');
require('../../../hooks/use-config.js');
require('../../select-input/hooks/use-multiple.js');
require('../../tag-input/index.js');
require('../../tag-input/tag-input.js');
require('../../tag-input/props.js');
require('../../tag-input/hooks/use-tag-scroll.js');
require('../../tag-input/hooks/use-tag-list.js');
require('../../tag-input/hooks/use-hover.js');
require('../../tag-input/hooks/use-drag-sorter.js');
require('../../select-input/hooks/use-overlay-innerstyle.js');
require('../../common/fake-arrow.js');
require('../../select/option.js');
require('../../select/utils.js');
require('../../select/props.js');
require('../../select/select-panel.js');
require('../../select/hooks/use-select-options.js');
require('../../select/option-group.js');
require('../../input-adornment/index.js');
require('../../input-adornment/input-adornment.js');
require('../../input-adornment/props.js');
require('../../pagination/props.js');
require('../hooks/useAffix.js');
require('./tbody.js');
require('./thead.js');
require('./tfoot.js');

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

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

const OMIT_PROPS = ["hideSortTips", "dragSort", "defaultExpandedRowKeys", "defaultSelectedRowKeys", "columnController", "filterRow", "sortOnRowDraggable", "expandOnRowClick", "multipleSort", "expandIcon", "onChange", "onAsyncLoadingClick", "onChange", "onColumnChange", "onColumnControllerVisibleChange", "onDataChange", "onDisplayColumnsChange", "onDragSort", "onExpandChange", "onFilterChange", "onSelectChange", "onSortChange"];
var _PrimaryTable = VueCompositionAPI.defineComponent({
  name: "TPrimaryTable",
  props: {
    ...components_table_props.BaseTableProps,
    ...components_table_props.PrimaryTableProps
  },
  setup(props, context) {
    const renderLNode = hooks_lnode.useLNodeJSX();
    const {
      columns
    } = VueCompositionAPI.toRefs(props);
    const primaryTableRef = VueCompositionAPI.ref(null);
    const {
      classPrefix,
      tableDraggableClasses,
      tableBaseClass,
      tableSelectedClasses,
      tableSortClasses
    } = components_table_hooks_useClassName["default"]();
    const {
      sizeClassNames
    } = components_table_hooks_useStyle["default"](props);
    const {
      tDisplayColumns,
      renderColumnController
    } = components_table_hooks_useColumnController["default"](props, context);
    const {
      showExpandedRow,
      showExpandIconColumn,
      getExpandColumn,
      renderExpandedRow,
      onInnerExpandRowClick
    } = components_table_hooks_useRowExpand["default"](props, context);
    const {
      renderSortIcon
    } = components_table_hooks_useSorter["default"](props, context);
    const {
      formatToRowSelectColumn,
      selectedRowClassNames
    } = components_table_hooks_useRowSelect["default"](props, tableSelectedClasses);
    const {
      hasEmptyCondition,
      isTableOverflowHidden,
      renderFilterIcon,
      renderFirstFilterRow,
      setFilterPrimaryTableRef
    } = components_table_hooks_useFilter["default"](props, context);
    const {
      isRowHandlerDraggable,
      isRowDraggable,
      isColDraggable,
      setDragSortPrimaryTableRef,
      setDragSortColumns
    } = components_table_hooks_useDragSort["default"](props, context);
    const {
      renderTitleWidthIcon
    } = components_table_hooks_useTableHeader["default"](props);
    const {
      renderAsyncLoading
    } = components_table_hooks_useAsyncLoading["default"](props, context);
    const {
      renderEditableCell
    } = components_table_hooks_useEditableCell["default"](props, context);
    const {
      errorListMap,
      editableKeysMap,
      validateRowData,
      validateTableData,
      onRuleChange,
      clearValidateData,
      onPrimaryTableRowValidate,
      onPrimaryTableRowEdit
    } = components_table_hooks_useEditableRow["default"](props, context);
    const primaryTableClasses = VueCompositionAPI.computed(() => ({
      [tableDraggableClasses.colDraggable]: isColDraggable.value,
      [tableDraggableClasses.rowHandlerDraggable]: isRowHandlerDraggable.value,
      [tableDraggableClasses.rowDraggable]: isRowDraggable.value,
      [tableBaseClass.overflowVisible]: isTableOverflowHidden.value === false,
      [tableBaseClass.tableRowEdit]: props.editableRowKeys
    }));
    const tRowClassNames = VueCompositionAPI.computed(() => {
      const tClassNames = [props.rowClassName, selectedRowClassNames.value];
      return tClassNames.filter(v => v);
    });
    const tRowAttributes = VueCompositionAPI.computed(() => {
      const tAttributes = [props.rowAttributes];
      if (isRowHandlerDraggable.value || isRowDraggable.value) tAttributes.push(_ref => {
        let {
          row
        } = _ref;
        return {
          "data-id": get__default["default"](row, props.rowKey || "id")
        };
      });
      return tAttributes.filter(v => v);
    });
    VueCompositionAPI.onMounted(() => {
      setFilterPrimaryTableRef(primaryTableRef.value);
      setDragSortPrimaryTableRef(primaryTableRef.value);
    });
    VueCompositionAPI.watch(primaryTableRef, () => {
      setFilterPrimaryTableRef(primaryTableRef.value);
      setDragSortPrimaryTableRef(primaryTableRef.value);
    });
    const getColumns = columns2 => {
      const arr = [];
      for (let i = 0, len = columns2.length; i < len; i++) {
        var _item$children, _tDisplayColumns$valu, _item$edit, _item$children2, _item$children3;
        let item = {
          ...columns2[i]
        };
        const 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) continue;
        item = formatToRowSelectColumn(item);
        const {
          sort
        } = props;
        if (item.sorter && props.showSortColumnBgColor) {
          const sorts = Array.isArray(sort) ? sort : [sort];
          const sortedColumn = sorts.find(sort2 => 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) {
          const titleContent = components_table_hooks_useTableHeader.renderTitle(VueCompositionAPI.h, context.slots, item, i);
          const {
            ellipsisTitle
          } = item;
          item.title = (h2, p) => {
            var _primaryTableRef$valu, _primaryTableRef$valu2;
            const sortIcon = item.sorter ? renderSortIcon(h2, p) : null;
            const filterIcon = item.filter ? renderFilterIcon(h2, p) : null;
            const 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,
              ellipsisOverlayClassName: props.size !== "medium" ? sizeClassNames[props.size] : ""
            });
          };
          item.ellipsisTitle = false;
        }
        if ((_item$edit = item.edit) !== null && _item$edit !== void 0 && _item$edit.component) {
          const oldCell = item.cell;
          item.cell = (h2, p) => {
            const cellProps = {
              ...p,
              oldCell,
              tableBaseClass,
              cellEmptyContent: props.cellEmptyContent,
              onChange: onPrimaryTableRowEdit,
              onValidate: onPrimaryTableRowValidate,
              onRuleChange
            };
            if (props.editableRowKeys) {
              var _errorListMap$value;
              const rowValue = get__default["default"](p.row, props.rowKey || "id");
              cellProps.editable = editableKeysMap.value[rowValue] || false;
              const key = [rowValue, p.col.colKey].join("__");
              const 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);
      }
      return arr;
    };
    const tColumns = VueCompositionAPI.computed(() => {
      const cols = getColumns(columns.value);
      if (showExpandIconColumn.value) cols.unshift(getExpandColumn(VueCompositionAPI.h));
      return cols;
    });
    const onInnerPageChange = (pageInfo, newData) => {
      var _props$onPageChange, _props$onChange;
      (_props$onPageChange = props.onPageChange) === null || _props$onPageChange === void 0 ? void 0 : _props$onPageChange.call(props, pageInfo, newData);
      context.emit("page-change", pageInfo, newData);
      const changeParams = [{
        pagination: pageInfo
      }, {
        trigger: "pagination",
        currentData: newData
      }];
      (_props$onChange = props.onChange) === null || _props$onChange === void 0 ? void 0 : _props$onChange.call(props, ...changeParams);
      context.emit("change", ...changeParams);
    };
    return {
      tColumns,
      showExpandedRow,
      tRowClassNames,
      hasEmptyCondition,
      primaryTableRef,
      tRowAttributes,
      primaryTableClasses,
      errorListMap,
      validateRowData,
      validateTableData,
      clearValidateData,
      renderLNode,
      renderColumnController,
      renderExpandedRow,
      onInnerExpandRowClick,
      renderFirstFilterRow,
      renderAsyncLoading,
      onInnerPageChange,
      setDragSortColumns
    };
  },
  methods: {
    getListener() {
      var _this = this;
      const listener = {};
      components_table_core_baseTable.BASE_TABLE_ALL_EVENTS.forEach(key => {
        listener[key] = function () {
          for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
            args[_key] = arguments[_key];
          }
          _this.$emit(key, ...args);
        };
      });
      return listener;
    },
    formatNode(api, renderInnerNode, condition, extra) {
      const h = this.$createElement;
      if (!condition) return this[api];
      const innerNode = renderInnerNode(h);
      const propsNode = this.renderLNode(api);
      if (innerNode && !propsNode) return () => innerNode;
      if (propsNode && !innerNode) return () => propsNode;
      if (innerNode && propsNode) {
        return () => extra !== null && extra !== void 0 && extra.reverse ? h("div", [innerNode, propsNode]) : h("div", [propsNode, innerNode]);
      }
      return null;
    }
  },
  render() {
    const h = arguments[0];
    const isColumnController = !!(this.columnController && Object.keys(this.columnController).length);
    const placement = isColumnController ? this.columnController.placement || "top-right" : "";
    const isBottomController = isColumnController && (placement === null || placement === void 0 ? void 0 : placement.indexOf("bottom")) !== -1;
    const topContent = this.formatNode("topContent", this.renderColumnController, isColumnController && !isBottomController);
    const bottomContent = this.formatNode("bottomContent", this.renderColumnController, isBottomController, {
      reverse: true
    });
    const firstFullRow = this.formatNode("firstFullRow", this.renderFirstFilterRow, !this.hasEmptyCondition);
    const lastFullRow = this.formatNode("lastFullRow", this.renderAsyncLoading, !!this.asyncLoading);
    const props = {
      ...omit__default["default"](this.$props, OMIT_PROPS),
      rowClassName: this.tRowClassNames,
      rowAttributes: this.tRowAttributes,
      columns: this.tColumns,
      topContent,
      bottomContent,
      firstFullRow,
      lastFullRow,
      renderExpandedRow: this.showExpandedRow ? this.renderExpandedRow : void 0
    };
    const on = {
      ...this.getListener(),
      "page-change": this.onInnerPageChange
    };
    if (this.expandOnRowClick) on["row-click"] = this.onInnerExpandRowClick;
    on.LeafColumnsChange = this.setDragSortColumns;
    return h(components_table_core_baseTable["default"], helper.helper([{
      "ref": "primaryTableRef",
      "scopedSlots": this.$scopedSlots
    }, {
      "props": props
    }, {}, {
      "on": on
    }, {}, this.$attrs, {
      "class": this.primaryTableClasses
    }]));
  }
});

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