/**
 * Canvas Drag Subscription Hook
 *
 * Provides reactive access to canvas drag state.
 * Use this to respond to drag operations in your components.
 *
 * @example
 * ```tsx
 * function DragIndicator() {
 *   const { isDragging, draggingNodeId } = useCanvasDrag();
 *   if (!isDragging) return null;
 *   return <div>Dragging: {draggingNodeId}</div>;
 * }
 * ```
 */

import { useAtomValue } from 'jotai';
import { draggingNodeIdAtom } from '../core/graph-store';

export interface CanvasDragState {
	/** ID of the node currently being dragged (null if not dragging) */
	draggingNodeId: string | null;
	/** Whether any node is currently being dragged */
	isDragging: boolean;
}

/**
 * Subscribe to canvas drag state.
 *
 * This hook provides a convenient way to access drag state
 * without needing to know which atoms to import.
 */
export function useCanvasDrag(): CanvasDragState {
	const draggingNodeId = useAtomValue(draggingNodeIdAtom);

	return {
		draggingNodeId,
		isDragging: draggingNodeId !== null,
	};
}
