"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.NestedTableRow = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _mobxReactLite = require("mobx-react-lite");
var _react = _interopRequireWildcard(require("react"));
var _NestedTableRowStCss = require("./NestedTableRow.st.css.js");
var _designSystem = require("@wix/design-system");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/NestedTable/NestedTableRow.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 _NestedTableRow = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
  var _item$state$parent;
  const {
    children,
    item,
    className,
    rowData,
    dragAndDrop,
    ...rest
  } = props;
  const [itemState] = (0, _react.useState)(() => {
    return item.state.createNode({
      parent: item.originalKeyedItem
    });
  });
  (0, _react.useEffect)(() => itemState == null ? void 0 : itemState.init(), []);
  const {
    st: dataTableRowSt,
    classes: dataTableRowClasses
  } = _designSystem.Table.dataTableRowStyle;
  const expandable = itemState != null && !itemState._isNotExpandableWhenEmpty && !item.state._isExpandableActionDisabled(item.originalKeyedItem.item);
  const isRowHighlight = item.state.levelDescriptor.isRowHighlight == null ? void 0 : item.state.levelDescriptor.isRowHighlight(item.originalKeyedItem.item);
  const isSameEntityAsOtherLevels = itemState == null ? void 0 : itemState.levelDescriptor.isSameEntityAsOtherLevels;
  let child = /*#__PURE__*/_react.default.createElement("tr", (0, _extends2.default)({}, process.env.NODE_ENV !== 'production' && {
    'data-parent-key': (_item$state$parent = item.state.parent) == null ? void 0 : _item$state$parent.key,
    'data-index-in-parent': item.originalKeyedItem.indexWithinPage
  }, process.env.NODE_ENV === 'test' && {
    'data-virtual-direct-children-count': item.state.collection.result.size,
    'data-level': item.state.childrenDepth,
    'data-indentation-width': item.state.nestedTable._indentationWidth
  }, {
    ref: ref,
    className: (0, _NestedTableRowStCss.st)(_NestedTableRowStCss.classes.root, {
      expandable
    }, isRowHighlight ? dataTableRowClasses.dataTableHighlight : undefined, item.state.showHoverHighlight ? _NestedTableRowStCss.classes.parentHovered : undefined, item.state.childrenDepth === 0 && !isSameEntityAsOtherLevels ? _NestedTableRowStCss.classes.firstLevel : undefined, dataTableRowSt(dataTableRowClasses.root, {
      skin: item.state.childrenDepth === 0 && !isSameEntityAsOtherLevels ? 'neutral' : 'light'
    }), className),
    onMouseEnter: () => {
      itemState == null || itemState._changeHover(true);
    },
    onMouseLeave: () => {
      itemState == null || itemState._changeHover(false);
    }
  }, rest, {
    onClick: ev => {
      rest == null || rest.onClick == null || rest.onClick(ev);
      if (expandable) {
        itemState._toggleExpand();
        itemState.bi.reportExpandCollapse();
      }
    },
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 54,
      columnNumber: 7
    }
  }), children);
  if (dragAndDrop) {
    const {
      NestedTableDragAndDropRow
    } = dragAndDrop;
    child = /*#__PURE__*/_react.default.createElement(NestedTableDragAndDropRow, {
      item: item,
      forwardedRef: ref,
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 106,
        columnNumber: 9
      }
    }, child);
  }
  return child;
});
const NestedTableRow = exports.NestedTableRow = (0, _mobxReactLite.observer)(_NestedTableRow);
//# sourceMappingURL=NestedTableRow.js.map