"use client";
import { useCallback, useRef } from "react";
import { useIframeOverlay } from "./overlay/IframeOverlayProvider";
import { findBridgeComponentTarget } from "./overlay/geometry";
import { useDragInsertionGesture } from "./useDragInsertionGesture";
/**
 * Parent-DOM drag source for a component grip (the frame-menu header). It owns
 * the pointer via `setPointerCapture` and forwards a "client"-space gesture
 * stream to {@link DragInsertionOverlay} - the very same orchestration the
 * in-iframe whole-component grab uses. The grip therefore gets the continuous
 * insertion line, the cursor-following chip/snapshot, edge auto-scroll, and the
 * shared `droppedInPlaceholder` commit path instead of janky native HTML5 DnD.
 *
 * Below the 6px threshold nothing is dispatched, so a plain click on the grip
 * (or a nested button such as "select parent") still behaves normally.
 */
export function useComponentDragHandle({ component, pageViewContext, enabled, }) {
    const overlay = useIframeOverlay();
    const pvcRef = useRef(pageViewContext);
    pvcRef.current = pageViewContext;
    const componentRef = useRef(component);
    componentRef.current = component;
    const { onPointerDown } = useDragInsertionGesture({
        iframe: overlay.iframe,
        pageViewContext,
        enabled,
        getStartDetail: useCallback(() => {
            const geometry = pvcRef.current?.bridgeGeometry;
            const elementKey = geometry
                ? (findBridgeComponentTarget(geometry, componentRef.current)
                    ?.elementKey ?? "")
                : "";
            return {
                elementKey,
                componentId: componentRef.current.id,
            };
        }, []),
    });
    return { onPointerDown };
}
//# sourceMappingURL=useComponentDragHandle.js.map