/**
 * amis-ui v6.12.0-beta.0
 * Copyright 2018-2025 fex
 */

'use strict';

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

var tslib = require('tslib');
var React = require('react');
var util = require('./util.js');
var Cell = require('./Cell.js');

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

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);

var __react_jsx__ = require('react');
var _J$X_ = (__react_jsx__["default"] || __react_jsx__).createElement;
(__react_jsx__["default"] || __react_jsx__).Fragment;
var SummaryRow = /** @class */ (function (_super) {
    tslib.__extends(SummaryRow, _super);
    function SummaryRow() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.domRef = React__default["default"].createRef();
        return _this;
    }
    SummaryRow.prototype.updateFixedRow = function () {
        var _a = this.props, cx = _a.classnames, row = _a.row;
        if (row && util.hasFixedColumn(row)) {
            var tr = this.domRef.current;
            util.updateFixedRow(tr, row || [], cx);
        }
    };
    SummaryRow.prototype.componentDidMount = function () {
        this.updateFixedRow();
    };
    SummaryRow.prototype.componentDidUpdate = function () {
        this.updateFixedRow();
    };
    SummaryRow.prototype.render = function () {
        var _a = this.props, cx = _a.classnames, dataSource = _a.dataSource, classPrefix = _a.classPrefix, row = _a.row, colCount = _a.colCount, isRightExpandable = _a.isRightExpandable, onMouseEnter = _a.onMouseEnter, onMouseLeave = _a.onMouseLeave;
        var cells = [];
        var extraCount = isRightExpandable ? 1 : 0;
        row === null || row === void 0 ? void 0 : row.forEach(function (s, index) {
            cells.push(_J$X_(Cell["default"], { classnames: cx, classPrefix: classPrefix, className: s.cellClassName, key: 'summary-cell-' + index, fixed: s.fixed, colSpan: cells.length === 0
                    ? (s.colSpan || 1) + colCount - extraCount
                    : index === row.length - 1
                        ? (s.colSpan || 1) + extraCount
                        : s.colSpan }, typeof s.render === 'function' ? s.render(dataSource) : s.render));
        });
        return (_J$X_("tr", { ref: this.domRef, onMouseEnter: function (e) { return onMouseEnter && onMouseEnter(e); }, onMouseLeave: function (e) { return onMouseLeave && onMouseLeave(e); }, className: cx('Table-summary-row') }, cells));
    };
    return SummaryRow;
}(React__default["default"].PureComponent));
var SummaryRows = /** @class */ (function (_super) {
    tslib.__extends(SummaryRows, _super);
    function SummaryRows() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    SummaryRows.prototype.render = function () {
        var _a = this.props, summary = _a.summary, rest = tslib.__rest(_a, ["summary"]);
        var rows = [[]];
        if (Array.isArray(summary)) {
            summary.forEach(function (s) {
                if (Array.isArray(s)) {
                    rows.push(s);
                }
                else {
                    rows[0].push(s);
                }
            });
        }
        return rows.map(function (row, index) { return (_J$X_(SummaryRow, tslib.__assign({ key: "summary-".concat(index) }, rest, { row: row }))); });
    };
    return SummaryRows;
}(React__default["default"].PureComponent));

exports.SummaryRow = SummaryRow;
exports["default"] = SummaryRows;
