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

import { _ as _typeof } from '../_chunks/dep-b4041200.mjs';
import { _ as _defineProperty } from '../_chunks/dep-eb20e23f.mjs';
import { isVNode, h, defineComponent, toRefs, ref, computed, reactive, watch, createVNode, mergeProps } from 'vue';
import { i as isFunction_1 } from '../_chunks/dep-6b22dd27.mjs';
import { u as upperFirst_1 } from '../_chunks/dep-1fe0ad42.mjs';
import { i as isString_1 } from '../_chunks/dep-1cf2b129.mjs';
import { p as pick_1 } from '../_chunks/dep-e9bfe96d.mjs';
import { g as get_1 } from '../_chunks/dep-4c3e8dd5.mjs';
import { formatRowAttributes, formatRowClassNames, formatClassNames } from './utils.mjs';
import { getRowFixedStyles, getColumnFixedStyles } from './hooks/useFixed.mjs';
import useClassName from './hooks/useClassName.mjs';
import TEllipsis from './ellipsis.mjs';
import baseTableProps from './base-table-props.mjs';
import useLazyLoad from './hooks/useLazyLoad.mjs';
import { getCellKey } from './hooks/useRowspanAndColspan.mjs';
import '../_chunks/dep-a0b4a044.mjs';
import '../_chunks/dep-c959a6fb.mjs';
import '../_chunks/dep-0f0c89ff.mjs';
import '../_chunks/dep-d54f2690.mjs';
import '../_chunks/dep-59c8420d.mjs';
import '../_chunks/dep-37ba476d.mjs';
import '../_chunks/dep-e3b14d70.mjs';
import '../_chunks/dep-66d6733b.mjs';
import '../_chunks/dep-be27d184.mjs';
import '../_chunks/dep-c31e1d9e.mjs';
import '../_chunks/dep-7acc11cb.mjs';
import '../_chunks/dep-0bfbf721.mjs';
import '../_chunks/dep-39cc276d.mjs';
import '../_chunks/dep-8f777748.mjs';
import '../_chunks/dep-ae357f26.mjs';
import '../_chunks/dep-ea5448a5.mjs';
import '../_chunks/dep-352691c2.mjs';
import '../_chunks/dep-2cfd5b3a.mjs';
import '../_chunks/dep-c852a61a.mjs';
import '../_chunks/dep-05fa17c9.mjs';
import '../_chunks/dep-10085c61.mjs';
import '../_chunks/dep-774ac2d0.mjs';
import '../_chunks/dep-23a0f453.mjs';
import '../_chunks/dep-3afa94cf.mjs';
import '../_chunks/dep-55846619.mjs';
import '../_chunks/dep-cfcedf47.mjs';
import '../_chunks/dep-96bb54d5.mjs';
import '../_chunks/dep-6205fc47.mjs';
import '../_common/js/log/index.mjs';
import '../_common/js/log/log.mjs';
import '../_common/js/utils/getScrollbarWidth.mjs';
import '../_common/js/utils/helper.mjs';
import '../_chunks/dep-e091cfd9.mjs';
import '../_chunks/dep-b6a73f93.mjs';
import '../_chunks/dep-6f89b77e.mjs';
import '../_chunks/dep-30451c48.mjs';
import '../_chunks/dep-6eea369f.mjs';
import '../utils/dom.mjs';
import '../utils/easing.mjs';
import '../hooks/useConfig.mjs';
import '../config-provider/useConfig.mjs';
import '../_chunks/dep-44417261.mjs';
import '../_chunks/dep-bf74f1c2.mjs';
import '../_chunks/dep-79821ff2.mjs';
import '../_chunks/dep-a9c8a5d5.mjs';
import '../_chunks/dep-1b058de3.mjs';
import '../_chunks/dep-92e7085e.mjs';
import '../_chunks/dep-44f056cd.mjs';
import '../_chunks/dep-99920870.mjs';
import '../_chunks/dep-c7e9ce16.mjs';
import '../_chunks/dep-ba3c0b2e.mjs';
import '../_chunks/dep-ee57d235.mjs';
import '../_common/js/global-config/default-config.mjs';
import '../_common/js/global-config/locale/zh_CN.mjs';
import '../_chunks/dep-6b4aa943.mjs';
import '../_chunks/dep-d52291a9.mjs';
import '../config-provider/type.mjs';
import '../utils/render-tnode.mjs';
import '../_chunks/dep-bd03960e.mjs';
import '../_chunks/dep-f6649a46.mjs';
import '../_chunks/dep-74848b92.mjs';
import '../_chunks/dep-c4e1a112.mjs';
import '../tooltip/index.mjs';
import '../utils/withInstall.mjs';
import '../tooltip/tooltip.mjs';
import '../_chunks/dep-b2af48ba.mjs';
import '../popup/props.mjs';
import '../popup/index.mjs';
import '../popup/popup.mjs';
import '@popperjs/core';
import '../hooks/index.mjs';
import '../hooks/icon.mjs';
import '../hooks/slot.mjs';
import '../hooks/tnode.mjs';
import '../hooks/useCommonClassName.mjs';
import '../hooks/useDefaultValue.mjs';
import '../hooks/useDestroyOnClose.mjs';
import '../hooks/useKeepAnimation.mjs';
import '../hooks/useRipple.mjs';
import '../utils/set-style.mjs';
import '../hooks/useVirtualScroll.mjs';
import '../hooks/useVModel.mjs';
import '../_common/js/utils/set-style.mjs';
import '../popup/container.mjs';
import '../hooks/useResizeObserver.mjs';
import '../popup/style/css.mjs';
import '../popup/type.mjs';
import '../tooltip/util.mjs';
import '../tooltip/props.mjs';
import '../tooltip/style/css.mjs';
import '../tooltip/type.mjs';
import '../_common/js/utils/observe.mjs';

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; }
function _isSlot(s) {
  return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !isVNode(s);
}
var TABLE_PROPS = ["rowKey", "rowClassName", "columns", "fixedRows", "footData", "rowAttributes", "rowspanAndColspan", "scroll", "cellEmptyContent", "pagination", "attach", "onCellClick", "onRowClick", "onRowDblclick", "onRowMouseover", "onRowMousedown", "onRowMouseenter", "onRowMouseleave", "onRowMouseup"];
var ROW_LISTENERS = ["click", "dblclick", "mouseover", "mousedown", "mouseenter", "mouseleave", "mouseup"];
function renderCell(params, slots, extra) {
  var col = params.col,
    row = params.row,
    rowIndex = params.rowIndex;
  if (col.colKey === "serial-number") {
    var _ref = (extra === null || extra === void 0 ? void 0 : extra.pagination) || {},
      current = _ref.current,
      pageSize = _ref.pageSize,
      defaultCurrent = _ref.defaultCurrent,
      defaultPageSize = _ref.defaultPageSize;
    var tCurrent = current || defaultCurrent;
    var tPageSize = pageSize || defaultPageSize;
    if (tPageSize && tCurrent) return tPageSize * (tCurrent - 1) + rowIndex + 1;
    return rowIndex + 1;
  }
  if (isFunction_1(col.cell)) return col.cell(h, params);
  if (slots[col.colKey]) return slots[col.colKey](params);
  if (isString_1(col.cell) && slots[col.cell]) return slots[col.cell](params);
  if (isFunction_1(col.render)) return col.render(h, _objectSpread(_objectSpread({}, params), {}, {
    type: "cell"
  }));
  var r = get_1(row, col.colKey);
  if (![void 0, "", null].includes(r)) return r;
  if (extra !== null && extra !== void 0 && extra.cellEmptyContent) return isFunction_1(extra.cellEmptyContent) ? extra.cellEmptyContent(h, params) : extra.cellEmptyContent;
  if (slots.cellEmptyContent) return slots.cellEmptyContent(params);
  return r;
}
var TrElement = defineComponent({
  name: "TR",
  props: _objectSpread(_objectSpread({
    row: Object,
    rowIndex: Number,
    dataLength: Number,
    ellipsisOverlayClassName: String,
    classPrefix: String,
    rowAndColFixedPosition: Map,
    skipSpansMap: Map,
    virtualConfig: Object
  }, pick_1(baseTableProps, TABLE_PROPS)), {}, {
    tableElm: {},
    tableContentElm: {}
  }),
  emits: ["row-mounted"],
  setup: function setup(props, context) {
    var _toRefs = toRefs(props),
      tableContentElm = _toRefs.tableContentElm;
    var trRef = ref(null);
    var _useClassName = useClassName(),
      tdEllipsisClass = _useClassName.tdEllipsisClass,
      tableBaseClass = _useClassName.tableBaseClass,
      tableColFixedClasses = _useClassName.tableColFixedClasses,
      tableRowFixedClasses = _useClassName.tableRowFixedClasses,
      tdAlignClasses = _useClassName.tdAlignClasses,
      tableDraggableClasses = _useClassName.tableDraggableClasses;
    var trStyles = computed(function () {
      return getRowFixedStyles(get_1(props.row, props.rowKey || "id"), props.rowIndex, props.dataLength, props.fixedRows, props.rowAndColFixedPosition, tableRowFixedClasses);
    });
    var trAttributes = computed(function () {
      return formatRowAttributes(props.rowAttributes, {
        row: props.row,
        rowIndex: props.rowIndex,
        type: "body"
      }) || {};
    });
    var classes = computed(function () {
      var _trStyles$value;
      var customClasses = formatRowClassNames(props.rowClassName, {
        row: props.row,
        rowIndex: props.rowIndex,
        type: "body"
      }, props.rowKey || "id");
      return [(_trStyles$value = trStyles.value) === null || _trStyles$value === void 0 ? void 0 : _trStyles$value.classes, customClasses].filter(function (v) {
        return v;
      });
    });
    var _useLazyLoad = useLazyLoad(tableContentElm, trRef, reactive(_objectSpread(_objectSpread({}, props.scroll), {}, {
        rowIndex: props.rowIndex
      }))),
      hasLazyLoadHolder = _useLazyLoad.hasLazyLoadHolder,
      tRowHeight = _useLazyLoad.tRowHeight;
    var getTrListeners = function getTrListeners(row, rowIndex) {
      var trListeners = {};
      ROW_LISTENERS.forEach(function (eventName) {
        trListeners["on".concat(upperFirst_1(eventName))] = function (e) {
          var _props;
          var p = {
            e: e,
            row: row,
            index: rowIndex
          };
          (_props = props["onRow".concat(upperFirst_1(eventName))]) === null || _props === void 0 ? void 0 : _props.call(props, p);
        };
      });
      return trListeners;
    };
    watch([trRef], function () {
      var _props$virtualConfig;
      if ((_props$virtualConfig = props.virtualConfig) !== null && _props$virtualConfig !== void 0 && _props$virtualConfig.isVirtualScroll.value) {
        context.emit("row-mounted", {
          ref: trRef,
          data: props.row
        });
      }
    });
    return {
      trRef: trRef,
      tableColFixedClasses: tableColFixedClasses,
      tdEllipsisClass: tdEllipsisClass,
      tableBaseClass: tableBaseClass,
      tdAlignClasses: tdAlignClasses,
      tableDraggableClasses: tableDraggableClasses,
      trStyles: trStyles,
      classes: classes,
      trAttributes: trAttributes,
      tRowHeight: tRowHeight,
      hasLazyLoadHolder: hasLazyLoadHolder,
      getTrListeners: getTrListeners
    };
  },
  methods: {
    renderEllipsisCell: function renderEllipsisCell(cellParams, params) {
      var cellNode = params.cellNode;
      var col = cellParams.col,
        colIndex = cellParams.colIndex;
      var content = isFunction_1(col.ellipsis) ? col.ellipsis(h, cellParams) : void 0;
      if (_typeof(col.ellipsis) === "object" && isFunction_1(col.ellipsis.content)) content = col.ellipsis.content(h, cellParams);
      var tooltipProps = {};
      if (_typeof(col.ellipsis) === "object") tooltipProps = "props" in col.ellipsis ? col.ellipsis.props : col.ellipsis || void 0;
      var tableElement = this.tableElm;
      var placement = colIndex === 0 ? "top-left" : "top";
      placement = colIndex === this.columns.length - 1 ? "top-right" : placement;
      return createVNode(TEllipsis, {
        "placement": placement,
        "attach": tableElement ? function () {
          return tableElement;
        } : void 0,
        "tooltipContent": content && function () {
          return content;
        },
        "tooltipProps": tooltipProps,
        "overlayClassName": this.ellipsisOverlayClassName,
        "classPrefix": this.classPrefix
      }, _isSlot(cellNode) ? cellNode : {
        "default": function _default() {
          return [cellNode];
        }
      });
    },
    renderTd: function renderTd(params, extra) {
      var _ref2,
        _this = this;
      var col = params.col,
        colIndex = params.colIndex,
        rowIndex = params.rowIndex;
      var cellSpans = extra.cellSpans,
        dataLength = extra.dataLength,
        rowAndColFixedPosition = extra.rowAndColFixedPosition;
      var cellNode = renderCell(params, this.$slots, {
        cellEmptyContent: extra.cellEmptyContent,
        pagination: this.pagination
      });
      var tdStyles = getColumnFixedStyles(col, colIndex, rowAndColFixedPosition, this.tableColFixedClasses);
      var customClasses = formatClassNames(col.className, _objectSpread(_objectSpread({}, params), {}, {
        type: "td"
      }));
      var classes = [tdStyles.classes, customClasses, (_ref2 = {}, _defineProperty(_ref2, this.tdEllipsisClass, col.ellipsis), _defineProperty(_ref2, this.tableBaseClass.tdLastRow, rowIndex + cellSpans.rowspan === dataLength), _defineProperty(_ref2, this.tableBaseClass.tdFirstCol, colIndex === 0 && this.rowspanAndColspan), _defineProperty(_ref2, this.tdAlignClasses[col.align], col.align && col.align !== "left"), _defineProperty(_ref2, this.tableDraggableClasses.handle, col.colKey === "drag"), _ref2)];
      var onClick = function onClick(e) {
        var _this$onCellClick;
        var p = _objectSpread(_objectSpread({}, params), {}, {
          e: e
        });
        if (col.stopPropagation) e.stopPropagation();
        (_this$onCellClick = _this.onCellClick) === null || _this$onCellClick === void 0 ? void 0 : _this$onCellClick.call(_this, p);
      };
      var normalAttrs = isFunction_1(col.attrs) ? col.attrs(_objectSpread(_objectSpread({}, params), {}, {
        type: "td"
      })) : col.attrs;
      var attrs = _objectSpread(_objectSpread({}, normalAttrs), cellSpans);
      return createVNode("td", mergeProps({
        "key": col.colKey || colIndex,
        "class": classes,
        "style": tdStyles.style
      }, attrs, {
        "onClick": onClick
      }), [col.ellipsis ? this.renderEllipsisCell(params, {
        cellNode: cellNode
      }) : cellNode]);
    }
  },
  render: function render() {
    var _this$columns,
      _this2 = this,
      _this$trStyles;
    var row = this.row,
      rowIndex = this.rowIndex,
      dataLength = this.dataLength,
      rowAndColFixedPosition = this.rowAndColFixedPosition;
    var columVNodeList = (_this$columns = this.columns) === null || _this$columns === void 0 ? void 0 : _this$columns.map(function (col, colIndex) {
      var cellSpans = {};
      var params = {
        row: row,
        col: col,
        rowIndex: rowIndex,
        colIndex: colIndex
      };
      var spanState = null;
      if (_this2.skipSpansMap.size) {
        var _spanState, _spanState2;
        var cellKey = getCellKey(row, _this2.rowKey, col.colKey, colIndex);
        spanState = _this2.skipSpansMap.get(cellKey) || {};
        ((_spanState = spanState) === null || _spanState === void 0 ? void 0 : _spanState.rowspan) > 1 && (cellSpans.rowspan = spanState.rowspan);
        ((_spanState2 = spanState) === null || _spanState2 === void 0 ? void 0 : _spanState2.colspan) > 1 && (cellSpans.colspan = spanState.colspan);
        if (spanState.skipped) return null;
      }
      return _this2.renderTd(params, {
        dataLength: dataLength,
        rowAndColFixedPosition: rowAndColFixedPosition,
        columnLength: _this2.columns.length,
        cellSpans: cellSpans,
        cellEmptyContent: _this2.cellEmptyContent
      });
    });
    return createVNode("tr", mergeProps({
      "ref": "trRef"
    }, this.trAttributes, {
      "style": (_this$trStyles = this.trStyles) === null || _this$trStyles === void 0 ? void 0 : _this$trStyles.style,
      "class": this.classes
    }, this.getTrListeners(row, rowIndex)), [this.hasLazyLoadHolder ? [createVNode("td", {
      "style": {
        height: "".concat(this.tRowHeight, "px"),
        border: "none"
      }
    }, null)] : columVNodeList]);
  }
});

export { ROW_LISTENERS, TABLE_PROPS, TrElement as default, renderCell };
//# sourceMappingURL=tr.mjs.map
