import { useCallback, useMemo } from 'react';
import { useSidebarContext } from '../../LibrariesSidebar/context';
import { getReorderedItems } from '../../LibrariesSidebar/utils';
export const useSortableList = (parentId) => {
    const { isSortMode, getOrderedItems, setPendingSort } = useSidebarContext();
    const listItems = useMemo(() => getOrderedItems(parentId), [getOrderedItems, parentId]);
    const handleDragEnd = useCallback((event) => {
        setPendingSort(getReorderedItems(listItems, event.active, event.over), parentId);
    }, [listItems, setPendingSort, parentId]);
    return { isSortMode, listItems, handleDragEnd };
};
