import React, { useCallback, useEffect, useState } from 'react';
import { ItemActionsState } from '../state';
import { CollectionItemActions } from './CollectionItemActions';
import { observer } from 'mobx-react-lite';
import { useWixPatternsContainer } from '@wix/bex-core/react';
import { useToolbarCollectionContext } from './ToolbarCollectionContext';
function _CollectionTableActionsColumn(props) {
    const { experiments } = useWixPatternsContainer();
    const toolbarState = useToolbarCollectionContext();
    const isActionCellSizeSmallEnabled = experiments.enabled('specs.cairo.SmallActionCellSize');
    const { collection, index, sticky, keyedItem, actionCell, ...rest } = props;
    const [state] = useState(() => new ItemActionsState({
        keyedItem,
        collection,
        fade: 'static',
        reportBi: toolbarState.reportBi,
    }));
    const renderActionCell = 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?.popoverMenuProps,
            },
        };
    }, [actionCell, sticky, index, keyedItem]);
    useEffect(() => {
        state.setItemIfChanged(keyedItem);
    }, [keyedItem]);
    return (React.createElement(CollectionItemActions, { ...rest, collection: state.collection, renderActionCell: renderActionCell, state: state }));
}
export const CollectionTableActionsColumn = observer(_CollectionTableActionsColumn);
//# sourceMappingURL=CollectionTableActionsColumn.js.map