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

'use strict';

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

var React = require('react');
var index = require('./index.js');
var util = require('./util.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;
function ColGroup(_a) {
    var columns = _a.columns, colWidths = _a.colWidths, isFixed = _a.isFixed, syncTableWidth = _a.syncTableWidth, initTableWidth = _a.initTableWidth, selectable = _a.selectable, expandable = _a.expandable, draggable = _a.draggable, rowSelectionColumnWidth = _a.rowSelectionColumnWidth, expandableColumnWidth = _a.expandableColumnWidth, isRightExpandable = _a.isRightExpandable, isLeftExpandable = _a.isLeftExpandable, showReal = _a.showReal;
    var tdColumns = util.getBuildColumns(columns).tdColumns;
    var domRef = React__default["default"].createRef();
    React__default["default"].useEffect(function () {
        if (domRef.current) {
            initTableWidth();
            syncTableWidth();
        }
    }, []);
    React__default["default"].useEffect(function () {
        var table = domRef.current.parentElement;
        var observer = new MutationObserver(function () {
            syncTableWidth();
        });
        observer.observe(table, {
            attributes: true,
            childList: true,
            subtree: true
        });
        return function () {
            observer.disconnect();
        };
    }, []);
    return (_J$X_("colgroup", { ref: domRef },
        draggable ? _J$X_("col", { style: { width: index.DefaultCellWidth + 'px' } }) : null,
        selectable ? (_J$X_("col", { style: { width: rowSelectionColumnWidth + 'px' } })) : null,
        expandable && isLeftExpandable ? (_J$X_("col", { style: { width: expandableColumnWidth + 'px' } })) : null,
        tdColumns.map(function (col, index) {
            var _a;
            var style = {};
            if ((_a = colWidths[col === null || col === void 0 ? void 0 : col.name]) === null || _a === void 0 ? void 0 : _a.width) {
                style.width = colWidths[col === null || col === void 0 ? void 0 : col.name].width;
            }
            else if (col.width) {
                style.width = col.width;
            }
            else if (showReal) {
                style.width = col.realWidth;
            }
            if (!isFixed && style.width) {
                style.minWidth = style.width;
            }
            return _J$X_("col", { style: style, key: index });
        }),
        expandable && isRightExpandable ? (_J$X_("col", { style: { width: expandableColumnWidth + 'px' } })) : null));
}

exports["default"] = ColGroup;
