/**
 * tdesign v0.32.0
 * (c) 2021 tdesign
 * @license MIT
 */

import { h as helper } from '../../_chunks/dep-42d5c87e.js';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import Vue from 'vue';
import get from 'lodash/get';
import { prefix } from '../../config.js';
import baseTableProps from '../base-table-props.js';
import TableCell from './table-cell.js';
import { emitEvent } from '../../utils/event.js';
import '@babel/runtime/helpers/toConsumableArray';
import '../../popup/index.js';
import '../../popup/popup.js';
import '@babel/runtime/helpers/typeof';
import '@popperjs/core';
import '../../_chunks/dep-1db5c91c.js';
import '../../utils/classnames.js';
import '../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../utils/easing.js';
import '../../popup/props.js';
import '../../utils/render-tnode.js';
import '../../utils/set-style.js';
import '../../utils/map-props.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '../../utils/withInstall.js';
import 'lodash/capitalize';
import './style/index.js';
import '../../popup/type.js';
import '../util/common.js';
import 'lodash/isFunction';
import '../../utils/helper.js';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/camelCase';

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 eventsName = {
  mouseover: "row-hover",
  mouseleave: "row-mouseleave",
  mouseenter: "row-mouseenter",
  mousedown: "row-mousedown",
  mouseup: "row-mouseup",
  click: "row-click",
  dblclick: "row-db-click",
  dragstart: "row-dragstart",
  dragover: "row-dragover"
};
var TableRow = Vue.extend({
  name: "".concat(prefix, "-table-row"),
  props: {
    rowClass: baseTableProps.rowClassName,
    columns: baseTableProps.columns,
    rowKey: baseTableProps.rowKey,
    rowspanAndColspanProps: {
      type: Object,
      required: false
    },
    rowData: {
      type: Object,
      "default": function _default() {
        return {};
      }
    },
    index: {
      type: Number,
      "default": -1
    },
    current: {
      type: Number,
      "default": 1
    },
    provider: {
      type: Object,
      "default": function _default() {
        return {
          sortOnRowDraggable: false
        };
      }
    }
  },
  methods: {
    renderRow: function renderRow() {
      var _this = this;

      var h = this.$createElement;
      var rowData = this.rowData,
          columns = this.columns,
          rowIndex = this.index,
          rowspanAndColspanProps = this.rowspanAndColspanProps;
      var rowBody = [];
      var flag = true;
      columns.forEach(function (column, index) {
        var customData = {
          type: "cell",
          func: "cell"
        };
        var render = column.render,
            cell = column.cell,
            scopedSlots = column.scopedSlots;
        var scopedSlotsCol = scopedSlots === null || scopedSlots === void 0 ? void 0 : scopedSlots.col;
        var colKey = column.colKey;
        var customRender;

        if (typeof _this.$scopedSlots[scopedSlotsCol] === "function") {
          customRender = function customRender(h, params) {
            return _this.$scopedSlots[scopedSlotsCol](params);
          };

          console.warn("TDesign Table Warn: scopedSlots will be deprecated, please use `cell` and `title` instead.");
        } else if (typeof cell === "function") {
          customRender = cell;
        } else if (typeof cell === "string" && typeof _this.$scopedSlots[cell] === "function") {
          customRender = function customRender(h, params) {
            return _this.$scopedSlots[cell](params);
          };
        } else if (typeof _this.$scopedSlots[colKey] === "function") {
          customRender = function customRender(h, params) {
            return _this.$scopedSlots[colKey](params);
          };
        } else if (typeof render === "function") {
          customRender = render;
          customData.func = "render";
        } else {
          customRender = function customRender() {
            return get(rowData, colKey);
          };
        }

        var attrs = column.attrs || {};

        if (colKey !== "expanded-row" && rowspanAndColspanProps !== null && rowspanAndColspanProps !== void 0 && rowspanAndColspanProps[colKey]) {
          var colspan = 1;
          var rowspan = 1;

          if (rowspanAndColspanProps[colKey]) {
            rowspan = rowspanAndColspanProps[colKey].rowspan || rowspan;
            colspan = rowspanAndColspanProps[colKey].colspan || colspan;
          }

          attrs.colspan = colspan;
          attrs.rowspan = rowspan;

          if (colspan === -1 || rowspan === -1) {
            return;
          }
        }

        var withBorder;
        var withoutBorder;

        if (index > rowBody.length && rowIndex > 0) {
          var _columns;

          if ((_columns = columns[index - 1]) !== null && _columns !== void 0 && _columns.fixed && rowBody.length === 0) {
            withoutBorder = true;
          } else if (flag) {
            withBorder = true;
            flag = false;
          }
        }

        var cellData = {
          col: _objectSpread(_objectSpread({}, column), {}, {
            attrs: attrs
          }),
          withBorder: withBorder,
          withoutBorder: withoutBorder,
          colIndex: index,
          row: rowData,
          rowIndex: rowIndex,
          customData: customData,
          customRender: customRender,
          type: "td"
        };
        rowBody.push(h(TableCell, {
          "attrs": {
            "cellData": cellData,
            "length": columns.length
          }
        }));
      });
      return rowBody;
    }
  },
  render: function render() {
    var _this2 = this;

    var h = arguments[0];
    var rowClass = this.rowClass,
        $attrs = this.$attrs,
        rowData = this.rowData,
        index = this.index,
        rowKey = this.rowKey,
        current = this.current;
    var params = {
      row: rowData,
      index: index
    };
    var on = {};
    Object.keys(eventsName).forEach(function (event) {
      var emitEventName = eventsName[event];

      on[event] = function (e) {
        emitEvent(_this2, emitEventName, _objectSpread(_objectSpread({}, params), {}, {
          e: e
        }));
      };
    });
    var trProps = {
      attrs: _objectSpread(_objectSpread({}, $attrs), {}, {
        "class": rowClass,
        key: rowKey ? get(rowData, rowKey) : index + current
      }),
      on: on
    };

    if (this.provider.sortOnRowDraggable) {
      trProps.attrs.draggable = true;
    }

    return h("tr", helper([{}, trProps]), [this.renderRow()]);
  }
});

export { TableRow as default };
//# sourceMappingURL=table-row.js.map
