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

'use strict';

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

var helper = require('../_chunks/dep-c3e1ffac.js');
var _typeof = require('@babel/runtime/helpers/typeof');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var VueCompositionAPI = require('@vue/composition-api');
var isFunction = require('lodash/isFunction');
var upperFirst = require('lodash/upperFirst');
var isString = require('lodash/isString');
var pick = require('lodash/pick');
var get = require('lodash/get');
var hooks_useLazyLoad = require('../hooks/useLazyLoad.js');
var table_utils = require('./utils.js');
var table_hooks_useFixed = require('./hooks/useFixed.js');
var table_hooks_useClassName = require('./hooks/useClassName.js');
var table_ellipsis = require('./ellipsis.js');
var table_baseTableProps = require('./base-table-props.js');
var table_hooks_useRowspanAndColspan = require('./hooks/useRowspanAndColspan.js');
require('../_common/js/utils/observe.js');
require('lodash/isObject');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/debounce');
require('../_common/js/log/log.js');
require('../_common/js/utils/getScrollbarWidth.js');
require('../_common/js/utils/helper.js');
require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/helpers/objectWithoutProperties');
require('lodash/isNull');
require('lodash/isUndefined');
require('lodash/isNumber');
require('lodash/isArray');
require('../utils/dom.js');
require('vue');
require('raf');
require('../utils/easing.js');
require('../config-provider/useConfig.js');
require('../config-provider/context.js');
require('lodash/merge');
require('lodash/mergeWith');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('../_chunks/dep-7c884501.js');
require('dayjs');
require('../utils/render-tnode.js');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../tooltip/index.js');
require('../utils/map-props.js');
require('../utils/withInstall.js');
require('lodash/capitalize');
require('../tooltip/tooltip.js');
require('../popup/props.js');
require('../popup/popup.js');
require('@popperjs/core');
require('../utils/helper.js');
require('../_common/js/utils/set-style.js');
require('../config-provider/config-receiver.js');
require('../utils/mixins.js');
require('../utils/event.js');
require('../popup/container.js');
require('../popup/utils.js');
require('../popup/trigger.js');
require('../tooltip/props.js');

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

var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var isFunction__default = /*#__PURE__*/_interopDefaultLegacy(isFunction);
var upperFirst__default = /*#__PURE__*/_interopDefaultLegacy(upperFirst);
var isString__default = /*#__PURE__*/_interopDefaultLegacy(isString);
var pick__default = /*#__PURE__*/_interopDefaultLegacy(pick);
var get__default = /*#__PURE__*/_interopDefaultLegacy(get);

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 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__default["default"](col.cell)) return col.cell(VueCompositionAPI.h, params);
  if (slots[col.colKey]) return slots[col.colKey](params);
  if (isString__default["default"](col.cell) && slots[col.cell]) return slots[col.cell](params);
  if (isFunction__default["default"](col.render)) return col.render(VueCompositionAPI.h, _objectSpread(_objectSpread({}, params), {}, {
    type: "cell"
  }));
  var r = get__default["default"](row, col.colKey);
  if (![void 0, "", null].includes(r)) return r;
  if (extra !== null && extra !== void 0 && extra.cellEmptyContent) return isFunction__default["default"](extra.cellEmptyContent) ? extra.cellEmptyContent(VueCompositionAPI.h, params) : extra.cellEmptyContent;
  var hParams = VueCompositionAPI.h;
  Object.assign(hParams, params || {});
  if (slots.cellEmptyContent) return slots.cellEmptyContent(hParams);
  if (slots["cell-empty-content"]) return slots["cell-empty-content"](hParams);
  return r;
}
var TrElement = VueCompositionAPI.defineComponent({
  name: "TR",
  props: _objectSpread(_objectSpread({
    row: Object,
    rowIndex: Number,
    ellipsisOverlayClassName: String,
    classPrefix: String,
    dataLength: Number,
    rowAndColFixedPosition: Map,
    skipSpansMap: Map,
    virtualConfig: Object
  }, pick__default["default"](table_baseTableProps["default"], TABLE_PROPS)), {}, {
    tableElm: {},
    tableContentElm: {}
  }),
  setup: function setup(props, context) {
    var _toRefs = VueCompositionAPI.toRefs(props),
      tableContentElm = _toRefs.tableContentElm;
    var trRef = VueCompositionAPI.ref(null);
    var _useClassName = table_hooks_useClassName["default"](),
      tdEllipsisClass = _useClassName.tdEllipsisClass,
      tableBaseClass = _useClassName.tableBaseClass,
      tableColFixedClasses = _useClassName.tableColFixedClasses,
      tableRowFixedClasses = _useClassName.tableRowFixedClasses,
      tdAlignClasses = _useClassName.tdAlignClasses,
      tableDraggableClasses = _useClassName.tableDraggableClasses;
    var trStyles = VueCompositionAPI.computed(function () {
      return table_hooks_useFixed.getRowFixedStyles(get__default["default"](props.row, props.rowKey || "id"), props.rowIndex, props.dataLength, props.fixedRows, props.rowAndColFixedPosition, tableRowFixedClasses);
    });
    var trAttributes = VueCompositionAPI.computed(function () {
      return table_utils.formatRowAttributes(props.rowAttributes, {
        row: props.row,
        rowIndex: props.rowIndex,
        type: "body"
      });
    });
    var classes = VueCompositionAPI.computed(function () {
      var _trStyles$value;
      var customClasses = table_utils.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];
    });
    var _useLazyLoad = hooks_useLazyLoad["default"](tableContentElm, trRef, VueCompositionAPI.reactive(_objectSpread({}, props.scroll))),
      hasLazyLoadHolder = _useLazyLoad.hasLazyLoadHolder,
      tRowHeight = _useLazyLoad.tRowHeight;
    var getTrListeners = function getTrListeners(row, rowIndex) {
      var trListeners = {};
      ROW_LISTENERS.forEach(function (eventName) {
        trListeners[eventName] = function (e) {
          var _props;
          var p = {
            e: e,
            row: row,
            index: rowIndex
          };
          (_props = props["onRow".concat(upperFirst__default["default"](eventName))]) === null || _props === void 0 ? void 0 : _props.call(props, p);
          context.emit("row-".concat(eventName), p);
        };
      });
      return trListeners;
    };
    VueCompositionAPI.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,
      tableDraggableClasses: tableDraggableClasses,
      tdEllipsisClass: tdEllipsisClass,
      tableBaseClass: tableBaseClass,
      tdAlignClasses: tdAlignClasses,
      trStyles: trStyles,
      classes: classes,
      trAttributes: trAttributes,
      tRowHeight: tRowHeight,
      hasLazyLoadHolder: hasLazyLoadHolder,
      getTrListeners: getTrListeners
    };
  },
  methods: {
    renderEllipsisCell: function renderEllipsisCell(h2, cellParams, params) {
      var _this = this;
      var h = this.$createElement;
      var cellNode = params.cellNode;
      var col = cellParams.col;
      var content = isFunction__default["default"](col.ellipsis) ? col.ellipsis(h2, cellParams) : void 0;
      if (_typeof__default["default"](col.ellipsis) === "object" && isFunction__default["default"](col.ellipsis.content)) content = col.ellipsis.content(h2, cellParams);
      var tooltipProps = {};
      if (_typeof__default["default"](col.ellipsis) === "object") tooltipProps = "props" in col.ellipsis ? col.ellipsis.props : col.ellipsis || void 0;
      return h(table_ellipsis["default"], {
        "attrs": {
          "placement": "top",
          "attach": this.attach || (this.tableElm ? function () {
            return _this.tableElm;
          } : void 0),
          "tooltipContent": content && function () {
            return content;
          },
          "tooltipProps": tooltipProps,
          "overlayClassName": this.ellipsisOverlayClassName,
          "classPrefix": this.classPrefix
        }
      }, [cellNode]);
    },
    renderTd: function renderTd(h2, params, extra) {
      var _ref2,
        _this2 = this;
      var h = this.$createElement;
      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.$scopedSlots, {
        cellEmptyContent: extra.cellEmptyContent,
        pagination: this.pagination
      });
      var tdStyles = table_hooks_useFixed.getColumnFixedStyles(col, colIndex, rowAndColFixedPosition, this.tableColFixedClasses);
      var customClasses = table_utils.formatClassNames(col.className, _objectSpread(_objectSpread({}, params), {}, {
        type: "td"
      }));
      var classes = [tdStyles.classes, customClasses, (_ref2 = {}, _defineProperty__default["default"](_ref2, this.tdEllipsisClass, col.ellipsis), _defineProperty__default["default"](_ref2, this.tableBaseClass.tdLastRow, rowIndex + cellSpans.rowspan === dataLength), _defineProperty__default["default"](_ref2, this.tableBaseClass.tdFirstCol, colIndex === 0 && this.rowspanAndColspan), _defineProperty__default["default"](_ref2, this.tdAlignClasses[col.align], col.align && col.align !== "left"), _defineProperty__default["default"](_ref2, this.tableDraggableClasses.handle, col.colKey === "drag"), _ref2)];
      var onClick = function onClick(e) {
        var _this2$onCellClick;
        var p = _objectSpread(_objectSpread({}, params), {}, {
          e: e
        });
        if (col.stopPropagation) e.stopPropagation();
        (_this2$onCellClick = _this2.onCellClick) === null || _this2$onCellClick === void 0 ? void 0 : _this2$onCellClick.call(_this2, p);
        _this2.$emit("cell-click", p);
      };
      var normalAttrs = isFunction__default["default"](col.attrs) ? col.attrs(_objectSpread(_objectSpread({}, params), {}, {
        type: "td"
      })) : col.attrs;
      var attrs = _objectSpread(_objectSpread({}, normalAttrs), cellSpans);
      return h("td", helper.helper([{
        "class": classes
      }, {
        "attrs": attrs
      }, {
        "style": _objectSpread(_objectSpread({}, tdStyles.style), attrs.style),
        "on": {
          "click": onClick
        }
      }]), [col.ellipsis ? this.renderEllipsisCell(h2, params, {
        cellNode: cellNode
      }) : cellNode]);
    }
  },
  render: function render(h2) {
    var _this$columns,
      _this3 = this,
      _this$trStyles;
    var h = arguments[0];
    var row = this.row,
      rowIndex = this.rowIndex,
      dataLength = this.dataLength,
      rowAndColFixedPosition = this.rowAndColFixedPosition;
    var columnVNodeList = (_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 (_this3.skipSpansMap.size) {
        var _spanState, _spanState2;
        var cellKey = table_hooks_useRowspanAndColspan.getCellKey(row, _this3.rowKey, col.colKey, colIndex);
        spanState = _this3.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 _this3.renderTd(h2, params, {
        dataLength: dataLength,
        rowAndColFixedPosition: rowAndColFixedPosition,
        columnLength: _this3.columns.length,
        cellSpans: cellSpans,
        cellEmptyContent: _this3.cellEmptyContent
      });
    });
    var attrs = this.trAttributes || {};
    return h("tr", helper.helper([{
      "ref": "trRef"
    }, {
      "attrs": attrs
    }, {
      "style": (_this$trStyles = this.trStyles) === null || _this$trStyles === void 0 ? void 0 : _this$trStyles.style,
      "class": this.classes
    }, {
      "on": this.getTrListeners(row, rowIndex)
    }]), [this.hasLazyLoadHolder ? [h("td", {
      "style": {
        height: "".concat(this.tRowHeight, "px"),
        border: "none"
      }
    })] : columnVNodeList]);
  }
});

exports.ROW_LISTENERS = ROW_LISTENERS;
exports.TABLE_PROPS = TABLE_PROPS;
exports["default"] = TrElement;
exports.renderCell = renderCell;
//# sourceMappingURL=tr.js.map
