import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2022-2026 GoodData Corporation
import { useMemo } from "react";
import { useDashboardComponentsContext } from "../../../dashboardContexts/DashboardComponentsContext.js";
import { DEBUG_SHOW_DROP_ZONES } from "../../../dragAndDrop/debug.js";
import { DefaultMeasureValueFilterDraggingComponent } from "../../../dragAndDrop/draggableMeasureValueFilter/DefaultMeasureValueFilterDraggingComponent.js";
import { DefaultParameterDraggingComponent } from "../../../dragAndDrop/draggableParameterFilter/DefaultParameterDraggingComponent.js";
function getItemStyles(initialOffset, clientOffset) {
    if (!initialOffset || !clientOffset) {
        return {
            display: "none",
        };
    }
    const { x, y } = clientOffset;
    const transform = `translate(${x}px, ${y}px)`;
    return {
        transform,
        WebkitTransform: transform,
    };
}
export function ContentDragPreview({ itemType, item, initialOffset, clientOffset, }) {
    const { AttributeFilterComponentSet, InsightWidgetComponentSet, DateFilterComponentSet, RichTextWidgetComponentSet, VisualizationSwitcherWidgetComponentSet, DashboardLayoutWidgetComponentSet, } = useDashboardComponentsContext();
    const previewComponentsMap = useMemo(() => ({
        attributeFilter: AttributeFilterComponentSet.dragging.DraggingComponent,
        dateFilter: DateFilterComponentSet.dragging.DraggingComponent,
        parameter: DefaultParameterDraggingComponent,
        measureValueFilter: DefaultMeasureValueFilterDraggingComponent,
        insight: InsightWidgetComponentSet.dragging.DraggingComponent,
        richText: RichTextWidgetComponentSet.dragging.DraggingComponent,
        visualizationSwitcher: VisualizationSwitcherWidgetComponentSet.dragging.DraggingComponent,
        dashboardLayout: DashboardLayoutWidgetComponentSet.dragging.DraggingComponent,
    }), [
        AttributeFilterComponentSet.dragging.DraggingComponent,
        InsightWidgetComponentSet.dragging.DraggingComponent,
        DateFilterComponentSet.dragging.DraggingComponent,
        RichTextWidgetComponentSet.dragging.DraggingComponent,
        VisualizationSwitcherWidgetComponentSet.dragging.DraggingComponent,
        DashboardLayoutWidgetComponentSet.dragging.DraggingComponent,
    ]);
    const component = useMemo(() => {
        if (!(itemType in previewComponentsMap)) {
            if (DEBUG_SHOW_DROP_ZONES) {
                console.warn(`DND: dnd item ${itemType} not handled by CustomDragLayer`);
            }
            return null;
        }
        const Component = previewComponentsMap[itemType];
        return _jsx(Component, { itemType: itemType, item: item });
    }, [itemType, previewComponentsMap, item]);
    return (_jsx("div", { className: "drag-preview", style: getItemStyles(initialOffset, clientOffset), children: component }));
}
