"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.CollectionTableActionsColumn = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireWildcard(require("react"));
var _state = require("../state");
var _CollectionItemActions = require("./CollectionItemActions");
var _mobxReactLite = require("mobx-react-lite");
var _react2 = require("@wix/bex-core/react");
var _ToolbarCollectionContext = require("./ToolbarCollectionContext");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/CollectionTableActionsColumn.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); }
function _CollectionTableActionsColumn(props) {
  const {
    experiments
  } = (0, _react2.useWixPatternsContainer)();
  const toolbarState = (0, _ToolbarCollectionContext.useToolbarCollectionContext)();
  const isActionCellSizeSmallEnabled = experiments.enabled('specs.cairo.SmallActionCellSize');
  const {
    collection,
    index,
    sticky,
    keyedItem,
    actionCell,
    ...rest
  } = props;
  const [state] = (0, _react.useState)(() => new _state.ItemActionsState({
    keyedItem,
    collection,
    fade: 'static',
    reportBi: toolbarState.reportBi
  }));
  const renderActionCell = (0, _react.useCallback)(() => {
    const actionCellProps = typeof actionCell === 'function' ? actionCell(keyedItem.item, index, state.actionCellAPI) : actionCell;
    return {
      ...actionCellProps,
      size: isActionCellSizeSmallEnabled ? 'small' : actionCellProps.size,
      popoverMenuProps: {
        // Larger zIndex than Page.Sticky https://github.com/wix-private/wix-design-systems/blob/844c42de1fb6e65f62b4b32538c5923869116d3d/packages/wix-style-react/src/Page/Page.st.css#L41
        ...(sticky && {
          zIndex: 1200
        }),
        ...(actionCellProps == null ? void 0 : actionCellProps.popoverMenuProps)
      }
    };
  }, [actionCell, sticky, index, keyedItem]);
  (0, _react.useEffect)(() => {
    state.setItemIfChanged(keyedItem);
  }, [keyedItem]);
  return /*#__PURE__*/_react.default.createElement(_CollectionItemActions.CollectionItemActions, (0, _extends2.default)({}, rest, {
    collection: state.collection,
    renderActionCell: renderActionCell,
    state: state,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 62,
      columnNumber: 5
    }
  }));
}
const CollectionTableActionsColumn = exports.CollectionTableActionsColumn = (0, _mobxReactLite.observer)(_CollectionTableActionsColumn);
//# sourceMappingURL=CollectionTableActionsColumn.js.map