'use client';
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
import { closestCenter, DndContext, KeyboardSensor, MouseSensor, TouchSensor, useDroppable, useSensor, useSensors } from '@dnd-kit/core';
import { SortableContext, sortableKeyboardCoordinates } from '@dnd-kit/sortable';
import React, { useCallback, useId } from 'react';
export const DraggableSortable = (props)=>{
    const { children, className, ids, onDragEnd, onDragStart } = props;
    const dndContextID = useId();
    const sortableContextID = useId();
    const { setNodeRef } = useDroppable({
        id: dndContextID
    });
    const sensors = useSensors(useSensor(MouseSensor, {
        activationConstraint: {
            distance: 5
        }
    }), useSensor(TouchSensor, {
        activationConstraint: {
            delay: 200,
            tolerance: 5
        }
    }), useSensor(KeyboardSensor, {
        coordinateGetter: sortableKeyboardCoordinates
    }));
    const handleDragEnd = useCallback((event)=>{
        const { active, over } = event;
        event.activatorEvent.stopPropagation();
        if (!active || !over) {
            return;
        }
        if (typeof onDragEnd === 'function') {
            onDragEnd({
                event,
                moveFromIndex: ids.findIndex((_id)=>_id === active.id),
                moveToIndex: ids.findIndex((_id)=>_id === over.id)
            });
        }
    }, [
        onDragEnd,
        ids
    ]);
    const handleDragStart = useCallback((event)=>{
        const { active } = event;
        if (!active) {
            return;
        }
        if (typeof onDragStart === 'function') {
            onDragStart({
                id: active.id,
                event
            });
        }
    }, [
        onDragStart
    ]);
    return /*#__PURE__*/ _jsxDEV(DndContext, {
        collisionDetection: closestCenter,
        // Provide stable ID to fix hydration issues: https://github.com/clauderic/dnd-kit/issues/926
        id: dndContextID,
        onDragEnd: handleDragEnd,
        onDragStart: handleDragStart,
        sensors: sensors,
        children: /*#__PURE__*/ _jsxDEV(SortableContext, {
            // Provide stable ID to fix hydration issues: https://github.com/clauderic/dnd-kit/issues/926
            id: sortableContextID,
            items: ids,
            children: /*#__PURE__*/ _jsxDEV("div", {
                className: className,
                ref: setNodeRef,
                children: children
            }, void 0, false, {
                fileName: "src/elements/DraggableSortable/index.tsx",
                lineNumber: 98,
                columnNumber: 9
            }, this)
        }, void 0, false, {
            fileName: "src/elements/DraggableSortable/index.tsx",
            lineNumber: 93,
            columnNumber: 7
        }, this)
    }, void 0, false, {
        fileName: "src/elements/DraggableSortable/index.tsx",
        lineNumber: 85,
        columnNumber: 5
    }, this);
};

//# sourceMappingURL=index.js.map