import { useEffect, useState } from 'react';
import { runInAction } from 'mobx';
import { gridSizePresets } from '../../state';
import { useScrollableContentContext } from '../../providers';
import { usePageContext } from '@wix/bex-core/react';
export function useGridBaseSyncProps(props) {
    const { state, renderAddItem, preset, dragAndDrop, range, layoutType, imagePlacement, } = props;
    const { scrollableContentRef } = useScrollableContentContext();
    const { modalsContainerRef } = usePageContext();
    useState(() => {
        props.dragAndDrop?.setStateObject({
            state,
            modalsContainerRef,
        });
    });
    const collectionDragAndDropState = state.collectionDragAndDropState;
    if (collectionDragAndDropState) {
        collectionDragAndDropState.dragAndDropCancel = props.dragAndDropCancel;
    }
    useEffect(() => {
        const { collection } = state;
        const scrollableContent = scrollableContentRef?.current;
        if (scrollableContent) {
            collection.scrollableContent = scrollableContent;
        }
        return () => {
            collection.scrollableContent = null;
        };
    }, []);
    useEffect(() => {
        runInAction(() => {
            state.trailingItemsCount = [renderAddItem].filter(Boolean).length;
        });
    }, [renderAddItem]);
    useEffect(() => {
        runInAction(() => {
            state._localLimit = range?.length;
            state._localStart = range?.start ?? 0;
        });
    }, [range]);
    useEffect(() => {
        runInAction(() => {
            state.preset = preset ?? 'title';
        });
    }, [preset]);
    useEffect(() => {
        runInAction(() => {
            state._draggable = dragAndDrop ? 'draggable' : 'none';
        });
    }, [dragAndDrop]);
    useEffect(() => {
        runInAction(() => {
            state.layoutType = layoutType ?? 'grid';
        });
    }, [layoutType]);
    useEffect(() => {
        runInAction(() => {
            const sizePreset = imagePlacement
                ? gridSizePresets[imagePlacement]
                : undefined;
            if (!sizePreset) {
                return;
            }
            state._sizePreset = sizePreset;
        });
    }, [imagePlacement]);
}
//# sourceMappingURL=useGridBaseSyncProps.js.map