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

import Vue from 'vue';
import TableCell from './table-cell.js';
import baseTableProps from '../base-table-props.js';
import { prefix } from '../../config.js';
import '../../_chunks/dep-42d5c87e.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/defineProperty';
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';

var TableHeader = Vue.extend({
  name: "".concat(prefix, "-table-header"),
  props: {
    columns: baseTableProps.columns,
    bordered: baseTableProps.bordered
  },
  methods: {
    renderHeader: function renderHeader() {
      var h = this.$createElement;
      var trContentList = [];
      this.renderTr(this.columns, 0, trContentList);
      var theadContent = trContentList.map(function (item) {
        return h("tr", [item]);
      });
      return theadContent;
    },
    renderTr: function renderTr(columns, currentRow, trContentList) {
      var _this = this,
          _trContentList$curren;

      var thContent = [];

      if (typeof trContentList[currentRow] === "undefined") {
        trContentList[currentRow] = [];
      }

      var currentColSpan = 0;
      columns.forEach(function (column, index) {
        var children = column.children;

        if (children !== null && children !== void 0 && children.length) {
          var colSpan = _this.renderTr(children, currentRow + 1, trContentList);

          currentColSpan += colSpan;
          thContent[index] = _this.renderCell(column, 1, colSpan, index);
        }
      });
      var rowspan = 1;

      if (trContentList.length >= 1) {
        rowspan = trContentList.length - currentRow;
      }

      columns.forEach(function (column, index) {
        var children = column.children;

        if (!children || (children === null || children === void 0 ? void 0 : children.length) === 0) {
          var withBorder = currentRow > 0 && _this.bordered && thContent.length === 0 && trContentList[currentRow].length === 0;
          thContent[index] = _this.renderCell(column, rowspan, 1, index, withBorder);
          currentColSpan += 1;
        }
      });

      (_trContentList$curren = trContentList[currentRow]).push.apply(_trContentList$curren, thContent);

      return currentColSpan;
    },
    renderCell: function renderCell(column, rowspan, colspan, index, withBorder) {
      var _this2 = this;

      var h = this.$createElement;
      var title = column.title,
          render = column.render,
          scopedSlots = column.scopedSlots;
      var scopedSlotsTitle = scopedSlots === null || scopedSlots === void 0 ? void 0 : scopedSlots.title;
      var customData = {
        type: "title",
        func: "title"
      };
      var customRender;

      if (typeof this.$scopedSlots[scopedSlotsTitle] === "function") {
        customRender = this.$scopedSlots[scopedSlotsTitle];
        console.error("TDesign Table Warn: scopedSlots will be deprecated, please use `cell` and `title` instead.");
      } else if (typeof title === "string") {
        if (typeof this.$scopedSlots[title] === "function") {
          customRender = function customRender(params) {
            return _this2.$scopedSlots[title](params);
          };
        } else {
          customRender = function customRender() {
            return title;
          };
        }
      } else if (typeof title === "function") {
        customRender = function customRender(h, params) {
          return title(h, {
            colIndex: params.colIndex,
            col: params.col
          });
        };
      } else if (typeof render === "function") {
        customRender = render;
        customData.func = "render";
      } else {
        customRender = function customRender() {
          return "";
        };
      }

      var cellData = {
        col: column,
        colIndex: index,
        customData: customData,
        customRender: customRender,
        type: "th",
        withBorder: withBorder
      };
      return h(TableCell, {
        "attrs": {
          "cellData": cellData,
          "colspan": colspan,
          "rowspan": rowspan
        }
      });
    }
  },
  render: function render() {
    var h = arguments[0];
    return h("thead", [this.renderHeader()]);
  }
});

export { TableHeader as default };
//# sourceMappingURL=table-header.js.map
