import { useScrollableContentContext } from '../../providers';
import { useEffect, useState } from 'react';
import { usePageContext } from '@wix/bex-core/react';
import { useTagsBulkAssignUtils } from '../Tags/useTagsBulkAssignUtils';
import { runInAction } from 'mobx';
export function useTableSyncProps(props) {
    const { state, scrollElement: scrollElementProp } = props;
    const { scrollableContentRef } = useScrollableContentContext();
    const { modalsContainerRef } = usePageContext();
    const [scrollElement, setScrollElement] = useState(() => scrollElementProp ??
        scrollableContentRef?.current);
    useState(() => {
        props.dragAndDrop?.setStateObject({
            state,
            modalsContainerRef,
        });
    });
    const collectionDragAndDropState = state.tableDragAndDropState?.dragAndDrop;
    if (collectionDragAndDropState) {
        collectionDragAndDropState.dragAndDropCancel = props.dragAndDropCancel;
    }
    useTagsBulkAssignUtils({ state });
    useEffect(() => {
        const { collection } = state;
        const scrollableContent = scrollElementProp ?? scrollableContentRef?.current;
        if (scrollableContent) {
            setScrollElement(scrollableContent);
            runInAction(() => {
                collection.scrollableContent =
                    scrollableContent instanceof HTMLElement
                        ? scrollableContent
                        : scrollableContent.current;
            });
        }
        return () => {
            runInAction(() => {
                collection.scrollableContent = null;
            });
        };
    }, [scrollElementProp]);
    return {
        scrollElement,
    };
}
//# sourceMappingURL=useTableSyncProps.js.map