// biome-ignore lint/style/noRestrictedImports: deprecated wrapper, intentional import
import { DropResult } from 'react-beautiful-dnd';

/**
 * @deprecated Use the drag types from SortableList or SortableListComposition from @material-hu/components/composed-components instead.
 */
export type DragProps = Pick<
  DropResult,
  'destination' | 'draggableId' | 'source'
>;
type CallbackFn = (dragProps: DragProps) => void;

/**
 * @deprecated Use SortableList or SortableListComposition from @material-hu/components/composed-components instead.
 */
function useDragEnd(callback: CallbackFn) {
  const handleDragEnd = async ({
    source,
    destination,
    draggableId,
  }: DropResult) => {
    // Dropped outside the droppable zone
    if (!destination) {
      return;
    }
    // Draggable has not been moved
    if (
      source.droppableId === destination.droppableId &&
      source.index === destination.index
    ) {
      return;
    }
    callback({ destination, draggableId, source });
  };

  return { handleDragEnd };
}

export default useDragEnd;
