"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DragContextProvider = exports.DragContext = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const React = tslib_1.__importStar(require("react"));
const cn_1 = require("../../utils/cn.js");
const b = (0, cn_1.editorCn)('preview');
// Context for drag and drop operations
exports.DragContext = React.createContext({
    draggedItem: null,
    setDraggedItem: () => { },
    previewRef: { current: null },
    showPreview: () => { },
    hidePreview: () => { },
});
// Component for the drag preview
const DragPreview = React.forwardRef((_, ref) => {
    return (0, jsx_runtime_1.jsx)("div", { ref: ref, className: b(), style: { display: 'none' } });
});
DragPreview.displayName = 'DragPreview';
// Provider component for drag context
const DragContextProvider = ({ children }) => {
    const [draggedItem, setDraggedItem] = React.useState(null);
    const previewRef = React.useRef(null);
    const showPreview = React.useCallback((rect, item) => {
        if (!previewRef.current)
            return;
        const previewEl = previewRef.current;
        previewEl.style.display = 'block';
        previewEl.style.width = `${rect.width}px`;
        previewEl.style.top = `${rect.bottom}px`;
        previewEl.style.left = `${rect.left}px`;
        previewEl.innerHTML = `
            <div class="${b('content')}">
                <div class="${b('type')}">${item.type}</div>
                ${item.treeTitle ? `<div class="${b('title')}">${item.treeTitle}</div>` : ''}
            </div>
        `;
    }, []);
    const hidePreview = React.useCallback(() => {
        if (previewRef.current) {
            previewRef.current.style.display = 'none';
        }
    }, []);
    return ((0, jsx_runtime_1.jsxs)(exports.DragContext.Provider, { value: { draggedItem, setDraggedItem, previewRef, showPreview, hidePreview }, children: [children, (0, jsx_runtime_1.jsx)(DragPreview, { ref: previewRef })] }));
};
exports.DragContextProvider = DragContextProvider;
//# sourceMappingURL=DragContext.js.map
