"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _react = _interopRequireDefault(require("react"));

var _miniStore = require("mini-store");

var _isStickySupport = _interopRequireDefault(require("../../_util/isStickySupport"));

var _excluded = ["column"];

function TableHeaderRow(_ref) {
  var prefixCls = _ref.prefixCls,
      fixed = _ref.fixed,
      row = _ref.row,
      index = _ref.index,
      height = _ref.height,
      components = _ref.components,
      onHeaderRow = _ref.onHeaderRow,
      placeholder = _ref.placeholder,
      rows = _ref.rows;
  var HeaderRow = components.header.row;
  var HeaderCell = components.header.cell;
  var rowProps = onHeaderRow(row.map(function (cell) {
    return cell.column;
  }), index);
  var customStyle = rowProps ? rowProps.style : {};
  var style = (0, _objectSpread2["default"])({
    height: height
  }, customStyle);
  return /*#__PURE__*/_react["default"].createElement(HeaderRow, (0, _extends2["default"])({}, rowProps, {
    style: style
  }), row.map(function (cell, i) {
    var column = cell.column,
        cellProps = (0, _objectWithoutProperties2["default"])(cell, _excluded);
    var customProps = column.onHeaderCell ? column.onHeaderCell(column) : {};

    if (column.width) {
      var addStyle = {
        minWidth: column.width,
        width: column.width,
        maxWidth: column.width
      };
      customProps.style = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, customProps.style), addStyle);
    }

    if (column.align) {
      customProps.style = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, customProps.style), {}, {
        textAlign: column.align
      });
    }

    return /*#__PURE__*/_react["default"].createElement(HeaderCell, (0, _extends2["default"])({}, cellProps, customProps, {
      style: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, column.style), customProps.style),
      key: column.key || column.dataIndex || i
    }));
  }), placeholder && /*#__PURE__*/_react["default"].createElement("th", {
    className: fixed || !(0, _isStickySupport["default"])() ? undefined : "".concat(prefixCls, "-sticky-column"),
    rowSpan: rows.length,
    style: {
      fontSize: 0,
      padding: 0,
      right: 0
    }
  }, "\xA0"));
}

function getRowHeight(state, props) {
  var fixedColumnsHeadRowsHeight = state.fixedColumnsHeadRowsHeight;
  var columns = props.columns,
      rows = props.rows,
      fixed = props.fixed;
  var headerHeight = fixedColumnsHeadRowsHeight[0];

  if (!fixed) {
    return null;
  }

  if (headerHeight && columns) {
    if (headerHeight === 'auto') {
      return 'auto';
    }

    return headerHeight / rows.length;
  }

  return null;
}

var _default = (0, _miniStore.connect)(function (state, props) {
  return {
    height: getRowHeight(state, props)
  };
})(TableHeaderRow);

exports["default"] = _default;
//# sourceMappingURL=TableHeaderRow.js.map
