import React, { forwardRef, } from 'react';
import { observer } from 'mobx-react-lite';
import { CollectionSectionHeader } from '../CollectionSectionHeader';
const _TableSectionRow = forwardRef(({ state, RegularTrElement, rowData, ...props }, ref) => {
    const { children, className, style } = props;
    const isSectionRow = state.isSectionRow(rowData);
    const contentWidth = state.table.toolbar.itemsContentRect.rect.width;
    const sectionContentWidth = contentWidth ? `${contentWidth}px` : '100%';
    const regularTrElementProps = {
        ...props,
        rowData,
        className: className || '',
        children: children || [],
    };
    if (state.isInvisibleRow(rowData)) {
        return (React.createElement("tr", { ...props, ref: ref, className: className, style: {
                ...style,
                visibility: 'collapse',
            } }));
    }
    if (isSectionRow && Array.isArray(children) && children.length > 0) {
        const result = state.getSectionWithCount(rowData);
        if (!result) {
            return React.createElement(RegularTrElement, { ...regularTrElementProps });
        }
        const { sectionId, sectionIndex, section, collapsible } = result;
        return (React.createElement("tr", { ...props, ref: ref, className: className, style: {
                ...style,
                position: 'relative',
                cursor: 'default',
            }, "data-hook": "table-section-header-row" },
            React.createElement("th", { colSpan: children.length, scope: "rowgroup", style: { padding: '0px' } },
                React.createElement("div", { style: {
                        position: 'sticky',
                        left: 0,
                        width: sectionContentWidth,
                    } },
                    React.createElement(CollectionSectionHeader, { sectionId: sectionId, sectionIndex: sectionIndex, section: section, biComponentType: "TableSections", skin: "neutral", dataHook: "table-section-header", collapsible: collapsible, onToggleCollapse: state.toggleSection })))));
    }
    return React.createElement(RegularTrElement, { ...regularTrElementProps });
});
export const TableSectionRow = observer(_TableSectionRow);
//# sourceMappingURL=TableSectionRow.js.map