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

'use strict';

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

var helper = require('../../_chunks/dep-44e6bdf6.js');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var Vue = require('vue');
var get = require('lodash/get');
var config = require('../../config.js');
var table_baseTableProps = require('../base-table-props.js');
var table_baseTable_tableCell = require('./table-cell.js');
var utils_event = require('../../utils/event.js');
require('@babel/runtime/helpers/toConsumableArray');
require('../../popup/index.js');
require('../../popup/popup.js');
require('@babel/runtime/helpers/typeof');
require('@popperjs/core');
require('../../_chunks/dep-939cdc39.js');
require('../../utils/classnames.js');
require('../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../utils/easing.js');
require('../../popup/props.js');
require('../../utils/render-tnode.js');
require('../../utils/set-style.js');
require('../../utils/map-props.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('../../utils/withInstall.js');
require('lodash/capitalize');
require('../util/common.js');
require('lodash/isFunction');
require('../../utils/helper.js');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/camelCase');

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

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue);
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 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__default["default"].extend({
  name: "".concat(config.prefix, "-table-row"),
  props: {
    rowClass: table_baseTableProps["default"].rowClassName,
    columns: table_baseTableProps["default"].columns,
    rowKey: table_baseTableProps["default"].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__default["default"](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(table_baseTable_tableCell["default"], {
          "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) {
        utils_event.emitEvent(_this2, emitEventName, _objectSpread(_objectSpread({}, params), {}, {
          e: e
        }));
      };
    });
    var trProps = {
      attrs: _objectSpread(_objectSpread({}, $attrs), {}, {
        "class": rowClass,
        key: rowKey ? get__default["default"](rowData, rowKey) : index + current
      }),
      on: on
    };

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

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

exports["default"] = TableRow;
//# sourceMappingURL=table-row.js.map
