"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.TableSectionRow = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireWildcard(require("react"));
var _mobxReactLite = require("mobx-react-lite");
var _CollectionSectionHeader = require("../CollectionSectionHeader");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/TableSections/TableSectionRow.tsx";
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
const _TableSectionRow = /*#__PURE__*/(0, _react.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 /*#__PURE__*/_react.default.createElement("tr", (0, _extends2.default)({}, props, {
      ref: ref,
      className: className,
      style: {
        ...style,
        visibility: 'collapse'
      },
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 40,
        columnNumber: 7
      }
    }));
  }
  if (isSectionRow && Array.isArray(children) && children.length > 0) {
    const result = state.getSectionWithCount(rowData);
    if (!result) {
      return /*#__PURE__*/_react.default.createElement(RegularTrElement, (0, _extends2.default)({}, regularTrElementProps, {
        __self: void 0,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 56,
          columnNumber: 14
        }
      }));
    }
    const {
      sectionId,
      sectionIndex,
      section,
      collapsible
    } = result;
    return /*#__PURE__*/_react.default.createElement("tr", (0, _extends2.default)({}, props, {
      ref: ref,
      className: className,
      style: {
        ...style,
        position: 'relative',
        cursor: 'default'
      },
      "data-hook": "table-section-header-row",
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 62,
        columnNumber: 7
      }
    }), /*#__PURE__*/_react.default.createElement("th", {
      colSpan: children.length,
      scope: "rowgroup",
      style: {
        padding: '0px'
      },
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 73,
        columnNumber: 9
      }
    }, /*#__PURE__*/_react.default.createElement("div", {
      style: {
        position: 'sticky',
        left: 0,
        width: sectionContentWidth
      },
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 78,
        columnNumber: 11
      }
    }, /*#__PURE__*/_react.default.createElement(_CollectionSectionHeader.CollectionSectionHeader, {
      sectionId: sectionId,
      sectionIndex: sectionIndex,
      section: section,
      biComponentType: "TableSections",
      skin: "neutral",
      dataHook: "table-section-header",
      collapsible: collapsible,
      onToggleCollapse: state.toggleSection,
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 85,
        columnNumber: 13
      }
    }))));
  }
  return /*#__PURE__*/_react.default.createElement(RegularTrElement, (0, _extends2.default)({}, regularTrElementProps, {
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 101,
      columnNumber: 10
    }
  }));
});
const TableSectionRow = exports.TableSectionRow = (0, _mobxReactLite.observer)(_TableSectionRow);
//# sourceMappingURL=TableSectionRow.js.map