import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState } from "react";
import { ChevronDown, ChevronUp, Link2, FileText } from "lucide-react";
import { cn } from "../lib/utils";
export function DeleteItemsWarning({ references }) {
    const [expandedItems, setExpandedItems] = useState(new Set());
    // Filter to only items that have references
    const itemsWithReferences = references.filter((ref) => ref.referencingItems.length > 0);
    if (itemsWithReferences.length === 0) {
        return null;
    }
    const toggleExpanded = (itemId) => {
        const newExpanded = new Set(expandedItems);
        if (newExpanded.has(itemId)) {
            newExpanded.delete(itemId);
        }
        else {
            newExpanded.add(itemId);
        }
        setExpandedItems(newExpanded);
    };
    const totalReferences = itemsWithReferences.reduce((sum, ref) => sum + ref.totalReferenceCount, 0);
    return (_jsxs("div", { className: "mt-4 space-y-3", children: [_jsxs("div", { className: "text-feedback-orange flex items-center gap-2", children: [_jsx(Link2, { className: "h-4 w-4" }), _jsx("span", { className: "text-sm font-medium", children: itemsWithReferences.length === 1
                            ? `1 item is referenced by ${totalReferences} other item${totalReferences !== 1 ? "s" : ""}`
                            : `${itemsWithReferences.length} items are referenced by ${totalReferences} other item${totalReferences !== 1 ? "s" : ""}` })] }), _jsx("div", { className: "space-y-2", children: itemsWithReferences.map((ref) => {
                    const isExpanded = expandedItems.has(ref.item.id);
                    const hasMore = ref.totalReferenceCount > ref.referencingItems.length;
                    return (_jsxs("div", { className: "bg-feedback-orange-light/50 overflow-hidden rounded-md border", children: [_jsxs("button", { onClick: () => toggleExpanded(ref.item.id), className: "hover:bg-feedback-orange-light flex w-full items-center justify-between p-3 text-left transition-colors", children: [_jsxs("div", { className: "flex min-w-0 items-center gap-2", children: [_jsx(FileText, { className: "text-feedback-orange h-4 w-4 shrink-0" }), _jsx("span", { className: "truncate text-sm font-medium", children: ref.item.name }), _jsxs("span", { className: "text-muted-foreground shrink-0 text-xs", children: ["(", ref.totalReferenceCount, " reference", ref.totalReferenceCount !== 1 ? "s" : "", ")"] })] }), isExpanded ? (_jsx(ChevronUp, { className: "text-muted-foreground h-4 w-4 shrink-0" })) : (_jsx(ChevronDown, { className: "text-muted-foreground h-4 w-4 shrink-0" }))] }), _jsx("div", { className: cn("overflow-hidden transition-all duration-200", isExpanded ? "max-h-48" : "max-h-0"), children: _jsxs("div", { className: "max-h-48 space-y-2 overflow-y-auto border-t bg-white/50 p-3 pt-0", children: [ref.referencingItems.map((referencingItem, index) => (_jsxs("div", { className: "border-b border-dashed py-1 pl-6 text-sm last:border-0", children: [_jsx("div", { className: "text-feedback-orange text-xs font-medium", children: referencingItem.name }), _jsx("div", { className: "text-muted-foreground truncate text-xs", children: referencingItem.path }), !!referencingItem.fieldNames?.length && (_jsxs("div", { className: "text-muted-foreground text-xs", children: ["Field", referencingItem.fieldNames.length !== 1 && "s", ":", " ", referencingItem.fieldNames.join(", ")] }))] }, `${referencingItem.id}-${index}`))), hasMore && (_jsxs("div", { className: "text-muted-foreground py-1 pl-6 text-xs italic", children: ["... and", " ", ref.totalReferenceCount - ref.referencingItems.length, " ", "more"] }))] }) })] }, ref.item.id));
                }) })] }));
}
//# sourceMappingURL=DeleteItemsWarning.js.map